Inferencer Issue

When I want to user inferencer for list or show, the inferencer supposes the "title" field is relation. How can I solve the problem? You can look at the code generated by inferencer: https://pastes.io/raw/vvi27lngcf
No description
No description
12 Replies
kapa.ai
kapa.ai13mo ago
Hi @rasitcolakel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
kapa.ai
kapa.ai13mo ago
---------------------- To customize the output of the Inferencer and prevent it from considering the "title" field as a relation, you can use the fieldTransformer prop in Inferencer components. The fieldTransformer is a function that takes the field as an argument and returns the modified field. If undefined | false | null is returned, the field will be removed from the output, both for the preview and the code. Here's an example of how you can use the fieldTransformer prop to modify the "title" field:
<AntdListInferencer
fieldTransformer={(field) => {
if (field.name === "title") {
return {
...field,
type: "text", // Set the type to "text" or any other suitable type
};
}
return field;
}}
/>
<AntdListInferencer
fieldTransformer={(field) => {
if (field.name === "title") {
return {
...field,
type: "text", // Set the type to "text" or any other suitable type
};
}
return field;
}}
/>
For more information, you can refer to the Modifying the inferred fields (https://refine.dev/docs/packages/documentation/inferencer#modifying-the-inferred-fields) section in the documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
Inferencer | refine
@refinedev/inferencer is a package that provides a way to automatically generate views for resources based on the data structure. The aim is to reduce the amount of time spent on creating views for resources by generating the code automatically that can be customized easily.
kapa.ai
kapa.ai13mo ago
<@698992415486246944> kapa.ai is still learning and improving, please let us how it did by reacting below
unwilling-turquoise
unwilling-turquoise13mo ago
Ohh thanks!
optimistic-gold
optimistic-gold13mo ago
Hi, bot is right. You can customize inferenced fields. But tomorrow i will report this case with the core team. This seems wrong 🤔
unwilling-turquoise
unwilling-turquoise13mo ago
Thanks for the reply Alican! Also I want to change the option label for multiple items with fieldTransformer. How can i do that? @kapa.ai
kapa.ai
kapa.ai13mo ago
Let me check the knowledge base for you. One moment! :books: Sorry @rasitcolakel, I seem to be having a bit of trouble. Don't worry though, I've pinged my supprt and they will try to fix me up! :technologist: Perhaps try again in 15mins?
unwilling-turquoise
unwilling-turquoise13mo ago
Okay
optimistic-gold
optimistic-gold13mo ago
you need to copy inferenced code and implement this yourself
unwilling-turquoise
unwilling-turquoise13mo ago
thanks
optimistic-gold
optimistic-gold13mo ago
Hey @rasitcolakel, do you have multiple types of title in the response array? Like one of them is object and the other is text. Or do you have a resource named title ? 🤔 That's an interesting issue, we'll look into it if you can provide some info about your resources and the response of the request 🙏
unwilling-turquoise
unwilling-turquoise13mo ago
Hey @aliemirs, I do not have any resource called "title" or "titles". I have solved the issue by using fieldTransformer. But I have a problem about fieldTransformer. I want to override the title value if there is no accessor key in the relationInfer field. I tried to manipulate the property but I did not. Manipulated field:
{
key: 'tags',
multiple: true,
type: 'relation',
relation: true,
priority: 1,
accessor: 'id',
resource: {
name: 'tags',
route: '/tags',
},
relationInfer: {
key: 'name',
accessor: 'name',
},
},
{
key: 'tags',
multiple: true,
type: 'relation',
relation: true,
priority: 1,
accessor: 'id',
resource: {
name: 'tags',
route: '/tags',
},
relationInfer: {
key: 'name',
accessor: 'name',
},
},
Auto generated getOptionLabel prop:
getOptionLabel={(item) => {
return (
tagsAutocompleteProps?.options?.find(
(p) =>
p?.id?.toString() ===
item?.id?.toString(),
)?.title ?? ""
);
}}
getOptionLabel={(item) => {
return (
tagsAutocompleteProps?.options?.find(
(p) =>
p?.id?.toString() ===
item?.id?.toString(),
)?.title ?? ""
);
}}
I guess it is all about the code shown below: the path of the code below:
node_modules/@refinedev/inferencer/src/inferencers/mui/edit.tsx
node_modules/@refinedev/inferencer/src/inferencers/mui/edit.tsx
const optionLabelProperty = field.relationInfer
? field.relationInfer.accessor
? typeof field.relationInfer.accessor === "string"
? field.relationInfer.accessor
: field.relationInfer.accessor[0]
: "title"
: "title";
const optionLabelProperty = field.relationInfer
? field.relationInfer.accessor
? typeof field.relationInfer.accessor === "string"
? field.relationInfer.accessor
: field.relationInfer.accessor[0]
: "title"
: "title";