Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add field isLabelSyncedWithName #8829

Merged
merged 12 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/twenty-front/src/generated-metadata/gql.ts

Large diffs are not rendered by default.

80 changes: 76 additions & 4 deletions packages/twenty-front/src/generated-metadata/graphql.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/twenty-front/src/generated/graphql.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,7 @@ export type Field = {
id: Scalars['UUID'];
isActive?: Maybe<Scalars['Boolean']>;
isCustom?: Maybe<Scalars['Boolean']>;
isLabelSyncedWithName: Scalars['Boolean'];
isNullable?: Maybe<Scalars['Boolean']>;
isSystem?: Maybe<Scalars['Boolean']>;
isUnique?: Maybe<Scalars['Boolean']>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const UPDATE_ONE_FIELD_METADATA_ITEM = gql`
createdAt
updatedAt
settings
isLabelSyncedWithName
}
}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const FIND_MANY_OBJECT_METADATA_ITEMS = gql`
defaultValue
options
settings
isLabelSyncedWithName
relationDefinition {
relationId
direction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const baseFields = `
isCustom
isActive
isNullable
isLabelSyncedWithName
createdAt
updatedAt
settings
Expand Down Expand Up @@ -95,6 +96,7 @@ export const queries = {
settings
defaultValue
options
isLabelSyncedWithName
}
}
`,
Expand All @@ -121,6 +123,7 @@ export const variables = {
settings: undefined,
objectMetadataId,
type: 'TEXT',
isLabelSyncedWithName: false,
},
},
},
Expand All @@ -140,6 +143,7 @@ const defaultResponseData = {
isCustom: false,
isActive: true,
isNullable: false,
isLabelSyncedWithName: false,
createdAt: '1977-09-28T13:56:55.157Z',
updatedAt: '1996-10-10T08:27:57.117Z',
settings: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const query = gql`
isNullable
createdAt
updatedAt
isLabelSyncedWithName
relationDefinition {
relationId
direction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const fieldMetadataItem: FieldMetadataItem = {
name: 'name',
type: FieldMetadataType.Text,
updatedAt: '',
isLabelSyncedWithName: false,
};

const fieldRelationMetadataItem: FieldMetadataItem = {
Expand All @@ -32,6 +33,7 @@ const fieldRelationMetadataItem: FieldMetadataItem = {
name: 'name',
type: FieldMetadataType.Relation,
updatedAt: '',
isLabelSyncedWithName: false,
relationDefinition: {
relationId: RELATION_METADATA_ID,
direction: RelationDefinitionType.OneToMany,
Expand Down Expand Up @@ -171,6 +173,8 @@ describe('useFieldMetadataItem', () => {
label: 'fieldLabel',
objectMetadataId,
type: FieldMetadataType.Text,
isLabelSyncedWithName: true,
name: 'fieldName',
});

expect(res.data).toEqual({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useDeleteOneRelationMetadataItem } from '@/object-metadata/hooks/useDeleteOneRelationMetadataItem';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import { Field } from '~/generated/graphql';
import { Field, FieldMetadataType } from '~/generated-metadata/graphql';

import { FieldMetadataItem } from '../types/FieldMetadataItem';
import { formatFieldMetadataItemInput } from '../utils/formatFieldMetadataItemInput';
Expand All @@ -18,13 +17,15 @@ export const useFieldMetadataItem = () => {
const createMetadataField = (
input: Pick<
Field,
| 'name'
| 'label'
| 'icon'
| 'description'
| 'defaultValue'
| 'type'
| 'options'
| 'settings'
| 'isLabelSyncedWithName'
> & {
objectMetadataId: string;
},
Expand All @@ -37,6 +38,7 @@ export const useFieldMetadataItem = () => {
type: input.type,
label: formattedInput.label ?? '',
name: formattedInput.name ?? '',
isLabelSyncedWithName: formattedInput.isLabelSyncedWithName ?? true,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,28 @@ import {
import { UPDATE_ONE_FIELD_METADATA_ITEM } from '../graphql/mutations';
import { FIND_MANY_OBJECT_METADATA_ITEMS } from '../graphql/queries';

import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import { useFindManyRecordsQuery } from '@/object-record/hooks/useFindManyRecordsQuery';
import { useSetRecoilState } from 'recoil';
import { isDefined } from 'twenty-ui';
import { useGetCurrentUserQuery } from '~/generated/graphql';
import { useApolloMetadataClient } from './useApolloMetadataClient';

export const useUpdateOneFieldMetadataItem = () => {
const apolloMetadataClient = useApolloMetadataClient();
const apolloClient = useApolloClient();

const setCurrentWorkspace = useSetRecoilState(currentWorkspaceState);

const { refetch: refetchCurrentUser } = useGetCurrentUserQuery({
onCompleted: (data) => {
if (isDefined(data?.currentUser?.defaultWorkspace)) {
setCurrentWorkspace(data.currentUser.defaultWorkspace);
}
},
});

const { findManyRecordsQuery } = useFindManyRecordsQuery({
objectNameSingular: CoreObjectNameSingular.View,
recordGqlFields: {
Expand Down Expand Up @@ -54,6 +68,7 @@ export const useUpdateOneFieldMetadataItem = () => {
| 'name'
| 'defaultValue'
| 'options'
| 'isLabelSyncedWithName'
>;
}) => {
const result = await mutate({
Expand All @@ -68,6 +83,8 @@ export const useUpdateOneFieldMetadataItem = () => {
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
});

await refetchCurrentUser();

await apolloClient.query({
Weiko marked this conversation as resolved.
Show resolved Hide resolved
query: findManyRecordsQuery,
variables: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ export type FieldMetadataItem = Omit<
settings?: {
displayAsRelativeDate?: boolean;
};
isLabelSyncedWithName?: boolean;
};
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { computeMetadataNameFromLabel } from '~/pages/settings/data-model/utils/compute-metadata-name-from-label.utils';

export const formatFieldMetadataItemInput = (
input: Partial<
Pick<
FieldMetadataItem,
| 'type'
| 'name'
| 'label'
| 'defaultValue'
| 'icon'
| 'description'
| 'defaultValue'
| 'type'
| 'options'
| 'settings'
| 'isLabelSyncedWithName'
>
>,
) => {
const label = input.label?.trim();

return {
defaultValue: input.defaultValue,
description: input.description?.trim() ?? null,
icon: input.icon,
label,
name: label ? computeMetadataNameFromLabel(label) : undefined,
label: input.label?.trim(),
name: input.name?.trim(),
options: input.options,
settings: input.settings,
isLabelSyncedWithName: input.isLabelSyncedWithName,
};
Weiko marked this conversation as resolved.
Show resolved Hide resolved
};
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const fieldMetadataItemSchema = (existingLabels?: string[]) => {
isUnique: z.boolean(),
isSystem: z.boolean(),
label: metadataLabelSchema(existingLabels),
isLabelSyncedWithName: z.boolean(),
Weiko marked this conversation as resolved.
Show resolved Hide resolved
name: camelCaseStringSchema,
options: z
.array(
Expand Down
Loading
Loading