refactor: merge FieldType and FieldMetadataType (#4504)
* refactor: merge FieldType and FieldMetadataType * fix: fix args passed to assertFieldMetadata * fix: omit RawJson from supported types in settings
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
import { ApolloClient, useMutation } from '@apollo/client';
|
||||
import { getOperationName } from '@apollo/client/utilities';
|
||||
|
||||
import { FieldType } from '@/object-record/record-field/types/FieldType';
|
||||
import {
|
||||
CreateFieldInput,
|
||||
CreateOneFieldMetadataItemMutation,
|
||||
CreateOneFieldMetadataItemMutationVariables,
|
||||
FieldMetadataType,
|
||||
} from '~/generated-metadata/graphql';
|
||||
|
||||
import { CREATE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations';
|
||||
@ -13,13 +12,6 @@ import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';
|
||||
|
||||
import { useApolloMetadataClient } from './useApolloMetadataClient';
|
||||
|
||||
type CreateOneFieldMetadataItemArgs = Omit<
|
||||
CreateOneFieldMetadataItemMutationVariables['input']['field'],
|
||||
'type'
|
||||
> & {
|
||||
type: FieldType;
|
||||
};
|
||||
|
||||
export const useCreateOneFieldMetadataItem = () => {
|
||||
const apolloMetadataClient = useApolloMetadataClient();
|
||||
|
||||
@ -30,16 +22,11 @@ export const useCreateOneFieldMetadataItem = () => {
|
||||
client: apolloMetadataClient ?? ({} as ApolloClient<any>),
|
||||
});
|
||||
|
||||
const createOneFieldMetadataItem = async (
|
||||
input: CreateOneFieldMetadataItemArgs,
|
||||
) => {
|
||||
const createOneFieldMetadataItem = async (input: CreateFieldInput) => {
|
||||
return await mutate({
|
||||
variables: {
|
||||
input: {
|
||||
field: {
|
||||
...input,
|
||||
type: input.type as FieldMetadataType, // Todo improve typing once we have aligned backend and frontend
|
||||
},
|
||||
field: input,
|
||||
},
|
||||
},
|
||||
awaitRefetchQueries: true,
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { FieldType } from '@/object-record/record-field/types/FieldType';
|
||||
import { Field } from '~/generated/graphql';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
@ -29,7 +28,7 @@ export const useFieldMetadataItem = () => {
|
||||
...formatFieldMetadataItemInput(input),
|
||||
defaultValue: input.defaultValue,
|
||||
objectMetadataId: input.objectMetadataId,
|
||||
type: input.type as FieldType,
|
||||
type: input.type,
|
||||
});
|
||||
|
||||
const editMetadataField = (
|
||||
|
||||
@ -3,8 +3,6 @@ import { parseFieldRelationType } from '@/object-metadata/utils/parseFieldRelati
|
||||
|
||||
import { FieldMetadataItem } from '../types/FieldMetadataItem';
|
||||
|
||||
import { parseFieldType } from './parseFieldType';
|
||||
|
||||
export type FieldMetadataItemAsFieldDefinitionProps = {
|
||||
field: FieldMetadataItem;
|
||||
objectMetadataItem: ObjectMetadataItem;
|
||||
@ -31,7 +29,7 @@ export const formatFieldMetadataItemAsFieldDefinition = ({
|
||||
label: field.label,
|
||||
showLabel,
|
||||
labelWidth,
|
||||
type: parseFieldType(field.type),
|
||||
type: field.type,
|
||||
metadata: {
|
||||
fieldName: field.name,
|
||||
placeHolder: field.label,
|
||||
|
||||
@ -1,14 +0,0 @@
|
||||
import { FieldType } from '@/object-record/record-field/types/FieldType';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
export const parseFieldType = (fieldType: FieldMetadataType): FieldType => {
|
||||
if (fieldType === FieldMetadataType.Link) {
|
||||
return 'LINK';
|
||||
}
|
||||
|
||||
if (fieldType === FieldMetadataType.Currency) {
|
||||
return 'CURRENCY';
|
||||
}
|
||||
|
||||
return fieldType as FieldType;
|
||||
};
|
||||
@ -1,6 +1,6 @@
|
||||
import { isUndefined } from '@sniptt/guards';
|
||||
|
||||
import { FieldType } from '@/object-record/record-field/types/FieldType';
|
||||
import { FieldMetadataType } from '~/generated-metadata/graphql';
|
||||
|
||||
import { FieldMetadataItem } from '../types/FieldMetadataItem';
|
||||
|
||||
@ -13,18 +13,20 @@ export const shouldFieldBeQueried = ({
|
||||
depth?: number;
|
||||
eagerLoadedRelations?: Record<string, boolean>;
|
||||
}): any => {
|
||||
const fieldType = field.type as FieldType;
|
||||
|
||||
if (!isUndefined(depth) && depth < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isUndefined(depth) && depth < 1 && fieldType === 'RELATION') {
|
||||
if (
|
||||
!isUndefined(depth) &&
|
||||
depth < 1 &&
|
||||
field.type === FieldMetadataType.Relation
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
fieldType === 'RELATION' &&
|
||||
field.type === FieldMetadataType.Relation &&
|
||||
!isUndefined(eagerLoadedRelations) &&
|
||||
(isUndefined(eagerLoadedRelations[field.name]) ||
|
||||
!eagerLoadedRelations[field.name])
|
||||
|
||||
Reference in New Issue
Block a user