View Controllers
The ModelShow, ModelIndex, ModelCreate and ModelEdit top level view components are driven by view controllers that provide the data to power a React context. These controllers are created with hooks. The basic pattern for the components is:
The Base version of the component will take the arguments for the controller as props and pass them to the controller hook. The Provider version of the component will take the results of the controller hook and set them as the value for the view Context. The context can then be access via a useModelViewContext and will provide the results of the controller hook.
const MyCustomComponent = () => {
const { resource } = useModelIndexContext();
return <div>{resource.name}</div>;
};
<ModelIndexBase defaultFilter={{ category: 6 }}>
<MyCustomComponent />
</ModelIndexBase>;
useModelShowController
useModelShowController takes an options object for configuration.
const { model, resource } = useModelShowController(options);
modela string for the model name or an already existing model object (from useModel or getModel) (required)modelIda value for the id of the object to fetch (omitted or null for singular models) (required)pathsthe paths to render for the create view (default: all viewable paths except for the parent)- All options for useModelShow
and in addition to the useModelShow returns, useModelShowController returns:
modelIdthe id of the model object being fetchedrenderPathsthe elementized paths for the show viewcreatethe return values of useModelCreateupdatethe return values of useModelUpdatedestroythe return values of useModelDestroy
useModelShowContext
Returns the context for the model show view.
ModelShowContext
The model show context.
ModelShowProvider
Injects the results of the model show controller into the context.
useModelIndexController
useModelIndexController takes an options object for configuration.
const { page, resources } = useModelIndexController(options);
modela string for the model name or an already existing model object (from useModel or getModel) (required)syncUrla boolean indicating whether to sync the url with the query parameters (default: true)defaultFiltersBaseOwnera boolean indicating whether to include a filter by the base owner (default: true)defaultFilterthe default filterdefaultOrderthe default orderdefaultLimitthe default limitdefaultOffsetthe default offsetdefaultSearchthe default searchqueryOptionsas per useModelIndexnetworkOptionsas per useModelIndex
and in addition to the useModelIndex returns, useModelIndex returns:
defaultStatethe default state of the model index controller - before any URL parameters are appliedinitialStatethe current state of the model index controller - after any URL parameters are appliedorderthe current order of the resourcessetOrdera function to set the order of the resourcesfilterthe current filter of the resourcessetFiltera function to set the filter of the resourcestotalFiltersthe total number of dynamic filtersfullFilterthe current full filter of the resources (default plus dynamic filters)totalFullFiltersthe total number of full filterssetDefaultFiltera function to set the default filter of the resourcessearchthe current search of the resourcessetSearcha function to set the search of the resourceslimitthe current limit of the resourcessetLimita function to set the limit of the resourcesoffsetthe current offset of the resourcessetOffseta function to set the offset of the resourcestotalPagesthe total number of pages of resources base on current limitpagethe current page of the resourcessetPagea function to set the page of the resourceshasNextPagea boolean indicating whether there is a next page of resourceshasPrevPagea boolean indicating whether there is a previous page of resourcesfirstPagea function to set the page to the first page of resourceslastPagea function to set the page to the last page of resourcescreatethe return values of useModelCreateupdatethe return values of useModelUpdatedestroythe return values of useModelDestroy
useModelIndexContext
Returns the context for the model index view.
ModelIndexContext
The model index context.
ModelIndexProvider
Injects the results of the model index controller into the context.
useModelCreateController
useModelCreateController takes an options object for configuration.
const {
mutation,
showParent: { resource: blog },
} = useModelCreateController(options);
modela string for the model name or an already existing model object (from useModel or getModel) (required)parentIdthe id of the parent (required)disableda boolean indicating whether the form elements in the view should be disabled (default: false)extraDefaultValuesvalues to augment the default values for the create viewpathsthe paths to render for the create view (default: all creatable paths except for the parent)queryOptionsoptions to pass to the query for the parent model
and in addition to the useModelCreate returns, useModelCreateController returns:
parentModela memoized version of the parent modelparentIdthe id of the parent model object being fetchedresolverthe yup resolver for the model uses for form validationschemathe yup schema for the model uses for form validationmethodsthe output ofuseFormfrom react-hook-formshowParentthe return values of useModelShow for the parent object
useModelCreateContext
Returns the context for the model create view.
ModelCreateContext
The model edit context.
ModelCreateProvider
Injects the results of the model edit controller into the context.
useModelEditController
useModelEditController takes an options object for configuration.
const {
mutation,
show: { resource: blog },
} = useModelEditController(options);
modela string for the model name or an already existing model object (from useModel or getModel) (required)modelIdthe id of the resource to be edited (required)disableda boolean indicating whether the form elements in the view should be disabled (default: false)extraDefaultValuesvalues to augment the default values for the create viewdebounceDelaythe delay in ms to debounce the mutation (default: 2000)pathsthe paths to render for the create view (default: all creatable paths except for the parent)queryOptionsoptions to pass to the query for the model object (passed to useModelShow)
and in addition to the useModelUpdate returns, useModelEditController returns:
modelIdthe id of the model object being fetchedresolverthe yup resolver for the model uses for form validationschemathe yup schema for the model uses for form validationmethodsthe output ofuseFormfrom react-hook-formdebouncedMutatea debounced mutate function delayed bydebounceDelayshowthe return values of useModelShow
useModelEditContext
Returns the context for the model edit view.
ModelEditContext
The model edit context.
ModelEditProvider
Injects the results of the model edit controller into the context.