2c9f50ecb1
This PR fixes several issues:
- enum naming should be: {tableName}_{fieldName}_enum and respecting the
case
- defaultValue format handled in the FE should respect the one in the BE
In my opinion we should refactor the defaultValue:
- we should respect backend format: "'myDefault'" for constant default
and "0" for float, "now" for expressions, "true" for booleans. we can
rename it to defaultValueExpression if it is more clear but we should
not maintain a parallel system
- we should deprecate option: isDefaultValue which is confusing
- we should re-work backend to have a more unified approach between
fields and avoid having if everywhere about select, multiselect, and
currency cases. one unified "computeDefaultValue" function should do the
job
What is still broken:
- currency default Value on creation. I think we should do the refactor
first
- select default value edition.
These cases do not break the schema but are ignored currently
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { useMutation } from '@apollo/client';
|
|
import { getOperationName } from '@apollo/client/utilities';
|
|
|
|
import {
|
|
UpdateOneFieldMetadataItemMutation,
|
|
UpdateOneFieldMetadataItemMutationVariables,
|
|
} from '~/generated-metadata/graphql';
|
|
|
|
import { UPDATE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations';
|
|
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
|
|
|
|
import { useApolloMetadataClient } from './useApolloMetadataClient';
|
|
|
|
export const useUpdateOneFieldMetadataItem = () => {
|
|
const apolloMetadataClient = useApolloMetadataClient();
|
|
|
|
const [mutate] = useMutation<
|
|
UpdateOneFieldMetadataItemMutation,
|
|
UpdateOneFieldMetadataItemMutationVariables
|
|
>(UPDATE_ONE_FIELD_METADATA_ITEM, {
|
|
client: apolloMetadataClient ?? undefined,
|
|
});
|
|
|
|
const updateOneFieldMetadataItem = async ({
|
|
fieldMetadataIdToUpdate,
|
|
updatePayload,
|
|
}: {
|
|
fieldMetadataIdToUpdate: UpdateOneFieldMetadataItemMutationVariables['idToUpdate'];
|
|
updatePayload: Pick<
|
|
UpdateOneFieldMetadataItemMutationVariables['updatePayload'],
|
|
| 'description'
|
|
| 'icon'
|
|
| 'isActive'
|
|
| 'label'
|
|
| 'name'
|
|
| 'defaultValue'
|
|
| 'options'
|
|
>;
|
|
}) => {
|
|
return await mutate({
|
|
variables: {
|
|
idToUpdate: fieldMetadataIdToUpdate,
|
|
updatePayload: {
|
|
...updatePayload,
|
|
label: updatePayload.label ?? undefined,
|
|
},
|
|
},
|
|
awaitRefetchQueries: true,
|
|
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
|
|
});
|
|
};
|
|
|
|
return {
|
|
updateOneFieldMetadataItem,
|
|
};
|
|
};
|