Minor Changes
-
#4141
e7188abba8b
Thanks @aliemir! - ##meta
property for inferencer componentsAdded
meta
property to the inferencer components. This allows you to passmeta
to the data hooks included in the inferencer's generated code. This is useful when your data provider relies on themeta
property which made@refinedev/inferencer
unusable before. Now you will be able to passmeta
properties and generate code that will work with your data provider.meta
property of the inferencer components has a nested structure unlike the rest of the refine codebase. This is because the inferencer components are designed to infer the relational data as well which may require differentmeta
values for each of their methods (such asgetList
andgetOne
).Type
<AntdListInferencer meta={{ [resourceNameOrIdentifier: string]: { [methodName: "default" | "getList" | "getMany" | "getOne" | "update"]: Record<string, unknown>, } }} />
default
is the defaultmeta
value for all the methods. In the absence of a specificmeta
value for a method for a resource, thedefault
value will be used.Example Usage
<AntdListInferencer meta={{ posts: { getList: { fields: [ "id", "title", "content", "category_id", "created_at", ], }, }, categories: { default: { fields: ["id", "title"], }, }, }} />
Using the appropriate method to infer the relational data
The inferencer components were using the
getOne
method of the data providers to infer the relational field data in a record. This has a chance of breaking the generated code and the preview if the data provider implements agetMany
andgetOne
in a different manner which may not be compatible with each other.In the generated code, fields with multiple values are handled via
useMany
hook but the inference was using thegetOne
method regardless of the field's cardinality. This has been fixed and the inferencer components will now use thegetMany
method for fields with multiple values andgetOne
method for fields with single values.Redesigned code viewer components
Updated the code viewers components and the bottom buttons and unified the design. The code viewers now use the same components.
Sortable actions in Material UI list inferencer
Fixed the actions column in the Material UI list inferencer to be sortable.
Repeated relational fields
Added a check for repeated relational fields and excluded the duplicate fields from the generated code according to the context of the inferencer. In
list
andshow
actions fields with displayable values are preferred over the fields with relational values. Inedit
andcreate
actions, fields with relational values are preferred over the fields with displayable values.For example, if a
posts
resource item has bothcategory_id
(number
orstring
) andcategory
(record with keytitle
andid
) fields. Thelist
andshow
actions will use thecategory
field and theedit
andcreate
actions will use thecategory_id
field.Ability to hide code viewer in production
Added an option
hideCodeViewerInProduction
to hide code viewer components in production environments. This is added for presentational purposes and keep in mind that the Inferencer components are not meant for production use and may generate broken code.