Some form fields aren't parsed
opened this issue · comments
Deleted user commented
The form:
const edit = (props) => {
const editObject = {
...props,
mutationMode: 'pessimistic',
transform: updateTransformer,
}
const AutocompleteParser = (value) => {
if (value === '') {
return null;
}
return value;
}
const SelectParser = (value) => {
if (value === '') {
return null;
}
return value;
}
return (
<Edit {...editObject}>
<SimpleForm>
<ReferenceInput source="subsidiary_of_id" reference='organizations' sort={{ field: 'updated_at', order: 'DESC' }}>
<AutocompleteInput label="Subsidiary of" size="large" filterToQuery={search => ({ name: search })} fullWidth parse={AutocompleteParser} />
</ReferenceInput>
<ReferenceInput source="successor_of_id" reference='organizations' sort={{ field: 'updated_at', order: 'DESC' }}>
<AutocompleteInput label="Successor of" size="large" filterToQuery={search => ({ name: search })} fullWidth parse={AutocompleteParser} />
</ReferenceInput>
<TextInput source="name" fullWidth required />
<TextInput source="shortname" fullWidth required />
<SelectInput source="priority" choices={Enums.Weight} fullWidth required parse={SelectParser} />
<ReferenceManyInput label="Details" reference="organization_details" target="organization_id">
<SimpleFormIterator inline>
<SelectInput source="type" choices={Enums.OrganizationDetailTypes} required />
<TextInput source="value" required />
</SimpleFormIterator>
</ReferenceManyInput>
</SimpleForm>
</Edit>
);
};
The generated mutation:
{
"operationName": "update_organizations",
"variables": {
"_set": {
"updated_at": "2022-10-12T06:57:59.311Z",
"updated_by": "f0bf6875-3a23-48d8-b625-6b69b45c0928"
},
"where": {
"id": {
"_eq": "4c0888d8-6ac2-4d1f-a035-db85ee1959d6"
}
}
},
"query": "mutation update_organizations($_set: organizations_set_input, $where: organizations_bool_exp!) {\n data: update_organizations(_set: $_set, where: $where) {\n returning {\n created_at\n created_by\n id\n name\n published_at\n published_by\n shortname\n size\n source_system\n subsidiary_of_id\n successor_of_id\n updated_at\n updated_by\n __typename\n }\n __typename\n }\n}"
}
Between the 2 states, all the inputs have been touched/updated. The updateTransformer
referenced in the edit()
merely adds the the updated_at
and updated_by
fields and sets the empty strings to be null
.
This is what the form state looks like according to RA after running the updateTransformer
:
{
"created_at": "2022-09-05T08:21:06.001458+00:00",
"created_by": "7bf35b8d-c822-410c-81b7-642f38d54ce1",
"id": "4c0888d8-6ac2-4d1f-a035-db85ee1959d6",
"name": "23 Code Street",
"published_at": "2022-09-05",
"published_by": "7bf35b8d-c822-410c-81b7-642f38d54ce1",
"shortname": "23 Code Street",
"size": "s",
"source_system": "9a11cf1a-a684-44a7-ac27-7018b8e1727f",
"subsidiary_of_id": null,
"successor_of_id": null,
"updated_at": "2022-10-12T07:19:02.646+00:00",
"updated_by": "f0bf6875-3a23-48d8-b625-6b69b45c0928",
"priority": "m",
"@@ra-many/organizations/organization_details/organization_id": [
{
"organization_details": [
{
"created_at": "2022-09-05T08:21:06.001458+00:00",
"created_by": "7bf35b8d-c822-410c-81b7-642f38d54ce1",
"id": "99dd27b3-60bf-45c4-9181-d67fcc21112c",
"organization_id": "4c0888d8-6ac2-4d1f-a035-db85ee1959d6",
"published_at": "2022-09-05",
"published_by": "7bf35b8d-c822-410c-81b7-642f38d54ce1",
"type": "domain",
"updated_at": "2022-09-05T08:21:06.001458+00:00",
"updated_by": "7bf35b8d-c822-410c-81b7-642f38d54ce1",
"value": "23codestreet.com"
}
],
"updated_at": "2022-10-12T07:20:56.074Z"
}
]
}
Deleted user commented
The data fell in between the cracks... some columns were removed and neither Hasura nor React Admin flagged that data was going nowhere...