feat: save Select field options (#2869)

Closes #2704
This commit is contained in:
Thaïs
2023-12-08 11:15:52 +01:00
committed by GitHub
parent 1f40c45140
commit 56a93d2ead
29 changed files with 211 additions and 105 deletions

View File

@@ -34,6 +34,7 @@
"lodash.camelcase": "^4.3.0",
"lodash.debounce": "^4.0.8",
"lodash.kebabcase": "^4.1.1",
"lodash.snakecase": "^4.1.1",
"luxon": "^3.3.0",
"react": "^18.2.0",
"react-data-grid": "7.0.0-beta.13",
@@ -138,6 +139,7 @@
"@types/lodash.camelcase": "^4.3.7",
"@types/lodash.debounce": "^4.0.7",
"@types/lodash.kebabcase": "^4.1.7",
"@types/lodash.snakecase": "^4.1.9",
"@types/luxon": "^3.3.0",
"@types/react-datepicker": "^4.11.2",
"@types/scroll-into-view": "^1.16.0",

View File

@@ -14,13 +14,13 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/
*/
const documents = {
"\n mutation CreateOneObjectMetadataItem($input: CreateOneObjectInput!) {\n createOneObject(input: $input) {\n id\n dataSourceId\n nameSingular\n namePlural\n labelSingular\n labelPlural\n description\n icon\n isCustom\n isActive\n createdAt\n updatedAt\n }\n }\n": types.CreateOneObjectMetadataItemDocument,
"\n mutation CreateOneFieldMetadataItem($input: CreateOneFieldInput!) {\n createOneField(input: $input) {\n id\n type\n name\n label\n description\n icon\n placeholder\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n": types.CreateOneFieldMetadataItemDocument,
"\n mutation CreateOneFieldMetadataItem($input: CreateOneFieldMetadataInput!) {\n createOneField(input: $input) {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n defaultValue\n options\n }\n }\n": types.CreateOneFieldMetadataItemDocument,
"\n mutation CreateOneRelationMetadata($input: CreateOneRelationInput!) {\n createOneRelation(input: $input) {\n id\n relationType\n fromObjectMetadataId\n toObjectMetadataId\n fromFieldMetadataId\n toFieldMetadataId\n createdAt\n updatedAt\n }\n }\n": types.CreateOneRelationMetadataDocument,
"\n mutation UpdateOneFieldMetadataItem(\n $idToUpdate: ID!\n $updatePayload: UpdateFieldInput!\n ) {\n updateOneField(input: { id: $idToUpdate, update: $updatePayload }) {\n id\n type\n name\n label\n description\n icon\n placeholder\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n": types.UpdateOneFieldMetadataItemDocument,
"\n mutation UpdateOneFieldMetadataItem(\n $idToUpdate: ID!\n $updatePayload: UpdateFieldInput!\n ) {\n updateOneField(input: { id: $idToUpdate, update: $updatePayload }) {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n": types.UpdateOneFieldMetadataItemDocument,
"\n mutation UpdateOneObjectMetadataItem(\n $idToUpdate: ID!\n $updatePayload: UpdateObjectInput!\n ) {\n updateOneObject(input: { id: $idToUpdate, update: $updatePayload }) {\n id\n dataSourceId\n nameSingular\n namePlural\n labelSingular\n labelPlural\n description\n icon\n isCustom\n isActive\n createdAt\n updatedAt\n }\n }\n": types.UpdateOneObjectMetadataItemDocument,
"\n mutation DeleteOneObjectMetadataItem($idToDelete: ID!) {\n deleteOneObject(input: { id: $idToDelete }) {\n id\n dataSourceId\n nameSingular\n namePlural\n labelSingular\n labelPlural\n description\n icon\n isCustom\n isActive\n createdAt\n updatedAt\n }\n }\n": types.DeleteOneObjectMetadataItemDocument,
"\n mutation DeleteOneFieldMetadataItem($idToDelete: ID!) {\n deleteOneField(input: { id: $idToDelete }) {\n id\n type\n name\n label\n description\n icon\n placeholder\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n": types.DeleteOneFieldMetadataItemDocument,
"\n query ObjectMetadataItems(\n $objectFilter: objectFilter\n $fieldFilter: fieldFilter\n ) {\n objects(paging: { first: 1000 }, filter: $objectFilter) {\n edges {\n node {\n id\n dataSourceId\n nameSingular\n namePlural\n labelSingular\n labelPlural\n description\n icon\n isCustom\n isActive\n isSystem\n createdAt\n updatedAt\n fields(paging: { first: 1000 }, filter: $fieldFilter) {\n edges {\n node {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isSystem\n isNullable\n createdAt\n updatedAt\n fromRelationMetadata {\n id\n relationType\n toObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n toFieldMetadataId\n }\n toRelationMetadata {\n id\n relationType\n fromObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n fromFieldMetadataId\n }\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n": types.ObjectMetadataItemsDocument,
"\n mutation DeleteOneFieldMetadataItem($idToDelete: ID!) {\n deleteOneField(input: { id: $idToDelete }) {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n": types.DeleteOneFieldMetadataItemDocument,
"\n query ObjectMetadataItems(\n $objectFilter: objectFilter\n $fieldFilter: fieldFilter\n ) {\n objects(paging: { first: 1000 }, filter: $objectFilter) {\n edges {\n node {\n id\n dataSourceId\n nameSingular\n namePlural\n labelSingular\n labelPlural\n description\n icon\n isCustom\n isActive\n isSystem\n createdAt\n updatedAt\n fields(paging: { first: 1000 }, filter: $fieldFilter) {\n edges {\n node {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isSystem\n isNullable\n createdAt\n updatedAt\n fromRelationMetadata {\n id\n relationType\n toObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n toFieldMetadataId\n }\n toRelationMetadata {\n id\n relationType\n fromObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n fromFieldMetadataId\n }\n defaultValue\n options\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n": types.ObjectMetadataItemsDocument,
};
/**
@@ -44,7 +44,7 @@ export function graphql(source: "\n mutation CreateOneObjectMetadataItem($input
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n mutation CreateOneFieldMetadataItem($input: CreateOneFieldInput!) {\n createOneField(input: $input) {\n id\n type\n name\n label\n description\n icon\n placeholder\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n"): (typeof documents)["\n mutation CreateOneFieldMetadataItem($input: CreateOneFieldInput!) {\n createOneField(input: $input) {\n id\n type\n name\n label\n description\n icon\n placeholder\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n"];
export function graphql(source: "\n mutation CreateOneFieldMetadataItem($input: CreateOneFieldMetadataInput!) {\n createOneField(input: $input) {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n defaultValue\n options\n }\n }\n"): (typeof documents)["\n mutation CreateOneFieldMetadataItem($input: CreateOneFieldMetadataInput!) {\n createOneField(input: $input) {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n defaultValue\n options\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
@@ -52,7 +52,7 @@ export function graphql(source: "\n mutation CreateOneRelationMetadata($input:
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n mutation UpdateOneFieldMetadataItem(\n $idToUpdate: ID!\n $updatePayload: UpdateFieldInput!\n ) {\n updateOneField(input: { id: $idToUpdate, update: $updatePayload }) {\n id\n type\n name\n label\n description\n icon\n placeholder\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n"): (typeof documents)["\n mutation UpdateOneFieldMetadataItem(\n $idToUpdate: ID!\n $updatePayload: UpdateFieldInput!\n ) {\n updateOneField(input: { id: $idToUpdate, update: $updatePayload }) {\n id\n type\n name\n label\n description\n icon\n placeholder\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n"];
export function graphql(source: "\n mutation UpdateOneFieldMetadataItem(\n $idToUpdate: ID!\n $updatePayload: UpdateFieldInput!\n ) {\n updateOneField(input: { id: $idToUpdate, update: $updatePayload }) {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n"): (typeof documents)["\n mutation UpdateOneFieldMetadataItem(\n $idToUpdate: ID!\n $updatePayload: UpdateFieldInput!\n ) {\n updateOneField(input: { id: $idToUpdate, update: $updatePayload }) {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
@@ -64,11 +64,11 @@ export function graphql(source: "\n mutation DeleteOneObjectMetadataItem($idToD
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n mutation DeleteOneFieldMetadataItem($idToDelete: ID!) {\n deleteOneField(input: { id: $idToDelete }) {\n id\n type\n name\n label\n description\n icon\n placeholder\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n"): (typeof documents)["\n mutation DeleteOneFieldMetadataItem($idToDelete: ID!) {\n deleteOneField(input: { id: $idToDelete }) {\n id\n type\n name\n label\n description\n icon\n placeholder\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n"];
export function graphql(source: "\n mutation DeleteOneFieldMetadataItem($idToDelete: ID!) {\n deleteOneField(input: { id: $idToDelete }) {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n"): (typeof documents)["\n mutation DeleteOneFieldMetadataItem($idToDelete: ID!) {\n deleteOneField(input: { id: $idToDelete }) {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isNullable\n createdAt\n updatedAt\n }\n }\n"];
/**
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
*/
export function graphql(source: "\n query ObjectMetadataItems(\n $objectFilter: objectFilter\n $fieldFilter: fieldFilter\n ) {\n objects(paging: { first: 1000 }, filter: $objectFilter) {\n edges {\n node {\n id\n dataSourceId\n nameSingular\n namePlural\n labelSingular\n labelPlural\n description\n icon\n isCustom\n isActive\n isSystem\n createdAt\n updatedAt\n fields(paging: { first: 1000 }, filter: $fieldFilter) {\n edges {\n node {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isSystem\n isNullable\n createdAt\n updatedAt\n fromRelationMetadata {\n id\n relationType\n toObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n toFieldMetadataId\n }\n toRelationMetadata {\n id\n relationType\n fromObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n fromFieldMetadataId\n }\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n"): (typeof documents)["\n query ObjectMetadataItems(\n $objectFilter: objectFilter\n $fieldFilter: fieldFilter\n ) {\n objects(paging: { first: 1000 }, filter: $objectFilter) {\n edges {\n node {\n id\n dataSourceId\n nameSingular\n namePlural\n labelSingular\n labelPlural\n description\n icon\n isCustom\n isActive\n isSystem\n createdAt\n updatedAt\n fields(paging: { first: 1000 }, filter: $fieldFilter) {\n edges {\n node {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isSystem\n isNullable\n createdAt\n updatedAt\n fromRelationMetadata {\n id\n relationType\n toObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n toFieldMetadataId\n }\n toRelationMetadata {\n id\n relationType\n fromObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n fromFieldMetadataId\n }\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n"];
export function graphql(source: "\n query ObjectMetadataItems(\n $objectFilter: objectFilter\n $fieldFilter: fieldFilter\n ) {\n objects(paging: { first: 1000 }, filter: $objectFilter) {\n edges {\n node {\n id\n dataSourceId\n nameSingular\n namePlural\n labelSingular\n labelPlural\n description\n icon\n isCustom\n isActive\n isSystem\n createdAt\n updatedAt\n fields(paging: { first: 1000 }, filter: $fieldFilter) {\n edges {\n node {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isSystem\n isNullable\n createdAt\n updatedAt\n fromRelationMetadata {\n id\n relationType\n toObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n toFieldMetadataId\n }\n toRelationMetadata {\n id\n relationType\n fromObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n fromFieldMetadataId\n }\n defaultValue\n options\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n"): (typeof documents)["\n query ObjectMetadataItems(\n $objectFilter: objectFilter\n $fieldFilter: fieldFilter\n ) {\n objects(paging: { first: 1000 }, filter: $objectFilter) {\n edges {\n node {\n id\n dataSourceId\n nameSingular\n namePlural\n labelSingular\n labelPlural\n description\n icon\n isCustom\n isActive\n isSystem\n createdAt\n updatedAt\n fields(paging: { first: 1000 }, filter: $fieldFilter) {\n edges {\n node {\n id\n type\n name\n label\n description\n icon\n isCustom\n isActive\n isSystem\n isNullable\n createdAt\n updatedAt\n fromRelationMetadata {\n id\n relationType\n toObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n toFieldMetadataId\n }\n toRelationMetadata {\n id\n relationType\n fromObjectMetadata {\n id\n dataSourceId\n nameSingular\n namePlural\n }\n fromFieldMetadataId\n }\n defaultValue\n options\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n }\n pageInfo {\n hasNextPage\n hasPreviousPage\n startCursor\n endCursor\n }\n totalCount\n }\n }\n"];
export function graphql(source: string) {
return (documents as any)[source] ?? {};

File diff suppressed because one or more lines are too long

View File

@@ -125,6 +125,7 @@ export type FieldConnection = {
export type FieldDeleteResponse = {
__typename?: 'FieldDeleteResponse';
createdAt?: Maybe<Scalars['DateTime']>;
defaultValue?: Maybe<Scalars['JSON']>;
description?: Maybe<Scalars['String']>;
icon?: Maybe<Scalars['String']>;
id?: Maybe<Scalars['ID']>;
@@ -134,8 +135,7 @@ export type FieldDeleteResponse = {
isSystem?: Maybe<Scalars['Boolean']>;
label?: Maybe<Scalars['String']>;
name?: Maybe<Scalars['String']>;
/** @deprecated Use label name instead */
placeholder?: Maybe<Scalars['String']>;
options?: Maybe<Scalars['JSON']>;
type?: Maybe<FieldMetadataType>;
updatedAt?: Maybe<Scalars['DateTime']>;
};
@@ -146,14 +146,16 @@ export enum FieldMetadataType {
Currency = 'CURRENCY',
DateTime = 'DATE_TIME',
Email = 'EMAIL',
Enum = 'ENUM',
FullName = 'FULL_NAME',
Link = 'LINK',
MultiSelect = 'MULTI_SELECT',
Number = 'NUMBER',
Numeric = 'NUMERIC',
Phone = 'PHONE',
Probability = 'PROBABILITY',
Rating = 'RATING',
Relation = 'RELATION',
Select = 'SELECT',
Text = 'TEXT',
Uuid = 'UUID'
}
@@ -191,20 +193,15 @@ export type Mutation = {
__typename?: 'Mutation';
challenge: LoginToken;
createEvent: Analytics;
createOneField: Field;
createOneObject: Object;
createOneRefreshToken: RefreshToken;
createOneRelation: Relation;
deleteCurrentWorkspace: Workspace;
deleteOneField: FieldDeleteResponse;
deleteOneObject: ObjectDeleteResponse;
deleteOneRelation: RelationDeleteResponse;
deleteUser: User;
generateApiKeyToken: ApiKeyToken;
impersonate: Verify;
renewToken: AuthTokens;
signUp: LoginToken;
updateOneField: Field;
updateOneObject: Object;
updateWorkspace: Workspace;
uploadFile: Scalars['String'];
@@ -342,13 +339,9 @@ export type Query = {
clientConfig: ClientConfig;
currentUser: User;
currentWorkspace: Workspace;
field: Field;
fields: FieldConnection;
findWorkspaceFromInviteHash: Workspace;
object: Object;
objects: ObjectConnection;
relation: Relation;
relations: RelationConnection;
};
@@ -531,18 +524,18 @@ export type WorkspaceInviteHashValid = {
export type Field = {
__typename?: 'field';
createdAt: Scalars['DateTime'];
defaultValue?: Maybe<Scalars['JSON']>;
description?: Maybe<Scalars['String']>;
fromRelationMetadata?: Maybe<Relation>;
icon?: Maybe<Scalars['String']>;
id: Scalars['ID'];
isActive: Scalars['Boolean'];
isCustom: Scalars['Boolean'];
isNullable: Scalars['Boolean'];
isSystem: Scalars['Boolean'];
isActive?: Maybe<Scalars['Boolean']>;
isCustom?: Maybe<Scalars['Boolean']>;
isNullable?: Maybe<Scalars['Boolean']>;
isSystem?: Maybe<Scalars['Boolean']>;
label: Scalars['String'];
name: Scalars['String'];
/** @deprecated Use label name instead */
placeholder?: Maybe<Scalars['String']>;
options?: Maybe<Scalars['JSON']>;
toRelationMetadata?: Maybe<Relation>;
type: FieldMetadataType;
updatedAt: Scalars['DateTime'];

View File

@@ -20,7 +20,7 @@ export const CREATE_ONE_OBJECT_METADATA_ITEM = gql`
`;
export const CREATE_ONE_FIELD_METADATA_ITEM = gql`
mutation CreateOneFieldMetadataItem($input: CreateOneFieldInput!) {
mutation CreateOneFieldMetadataItem($input: CreateOneFieldMetadataInput!) {
createOneField(input: $input) {
id
type
@@ -28,12 +28,13 @@ export const CREATE_ONE_FIELD_METADATA_ITEM = gql`
label
description
icon
placeholder
isCustom
isActive
isNullable
createdAt
updatedAt
defaultValue
options
}
}
`;
@@ -65,7 +66,6 @@ export const UPDATE_ONE_FIELD_METADATA_ITEM = gql`
label
description
icon
placeholder
isCustom
isActive
isNullable
@@ -125,7 +125,6 @@ export const DELETE_ONE_FIELD_METADATA_ITEM = gql`
label
description
icon
placeholder
isCustom
isActive
isNullable

View File

@@ -58,6 +58,8 @@ export const FIND_MANY_OBJECT_METADATA_ITEMS = gql`
}
fromFieldMetadataId
}
defaultValue
options
}
}
pageInfo {

View File

@@ -1,8 +1,11 @@
import { v4 } from 'uuid';
import { FieldType } from '@/object-record/field/types/FieldType';
import { Field } from '~/generated/graphql';
import { FieldMetadataType } from '~/generated-metadata/graphql';
import { FieldMetadataItem } from '../types/FieldMetadataItem';
import { FieldMetadataOption } from '../types/FieldMetadataOption';
import { formatFieldMetadataItemInput } from '../utils/formatFieldMetadataItemInput';
import { useCreateOneFieldMetadataItem } from './useCreateOneFieldMetadataItem';
@@ -17,6 +20,7 @@ export const useFieldMetadataItem = () => {
const createMetadataField = (
input: Pick<Field, 'label' | 'icon' | 'description'> & {
objectMetadataId: string;
options?: Omit<FieldMetadataOption, 'id'>[];
type: FieldMetadataType;
},
) =>
@@ -27,11 +31,20 @@ export const useFieldMetadataItem = () => {
});
const editMetadataField = (
input: Pick<Field, 'id' | 'label' | 'icon' | 'description'>,
input: Pick<Field, 'id' | 'label' | 'icon' | 'description'> & {
options?: FieldMetadataOption[];
},
) =>
updateOneFieldMetadataItem({
fieldMetadataIdToUpdate: input.id,
updatePayload: formatFieldMetadataItemInput(input),
updatePayload: formatFieldMetadataItemInput({
...input,
// In Edit mode, all options need an id,
// so we generate an id for newly created options.
options: input.options?.map((option) =>
option.id ? option : { ...option, id: v4() },
),
}),
});
const activateMetadataField = (metadataField: FieldMetadataItem) =>

View File

@@ -1,8 +1,9 @@
import { ThemeColor } from '@/ui/theme/constants/colors';
import { Field, Relation } from '~/generated-metadata/graphql';
export type FieldMetadataItem = Omit<
Field,
'fromRelationMetadata' | 'toRelationMetadata'
'fromRelationMetadata' | 'toRelationMetadata' | 'defaultValue' | 'options'
> & {
fromRelationMetadata?:
| (Pick<Relation, 'id' | 'toFieldMetadataId' | 'relationType'> & {
@@ -20,4 +21,12 @@ export type FieldMetadataItem = Omit<
>;
})
| null;
defaultValue?: string;
options?: {
color: ThemeColor;
id: string;
label: string;
position: number;
value: string;
}[];
};

View File

@@ -0,0 +1,8 @@
import { ThemeColor } from '@/ui/theme/constants/colors';
export type FieldMetadataOption = {
color?: ThemeColor;
id?: string;
isDefault?: boolean;
label: string;
};

View File

@@ -1,12 +1,34 @@
import toCamelCase from 'lodash.camelcase';
import toSnakeCase from 'lodash.snakecase';
import { Field } from '~/generated-metadata/graphql';
import { FieldMetadataOption } from '../types/FieldMetadataOption';
const getOptionValueFromLabel = (label: string) =>
toSnakeCase(label.trim()).toUpperCase();
export const formatFieldMetadataItemInput = (
input: Pick<Field, 'label' | 'icon' | 'description'>,
) => ({
description: input.description?.trim() ?? null,
icon: input.icon,
label: input.label.trim(),
name: toCamelCase(input.label.trim()),
});
input: Pick<Field, 'label' | 'icon' | 'description' | 'defaultValue'> & {
options?: FieldMetadataOption[];
},
) => {
const defaultOption = input.options?.find((option) => option.isDefault);
return {
defaultValue: defaultOption
? getOptionValueFromLabel(defaultOption.label)
: undefined,
description: input.description?.trim() ?? null,
icon: input.icon,
label: input.label.trim(),
name: toCamelCase(input.label.trim()),
options: input.options?.map((option, index) => ({
color: option.color,
id: option.id,
label: option.label.trim(),
position: index,
value: getOptionValueFromLabel(option.label),
})),
};
};

View File

@@ -12,11 +12,7 @@ import { isFieldRating } from '../../types/guards/isFieldRating';
export const useRatingField = () => {
const { entityId, fieldDefinition, hotkeyScope } = useContext(FieldContext);
assertFieldMetadata(
FieldMetadataType.Probability,
isFieldRating,
fieldDefinition,
);
assertFieldMetadata(FieldMetadataType.Rating, isFieldRating, fieldDefinition);
const fieldName = fieldDefinition.metadata.fieldName;

View File

@@ -2,6 +2,7 @@ import { useContext } from 'react';
import { useRecoilState } from 'recoil';
import { ThemeColor } from '@/ui/theme/constants/colors';
import { FieldMetadataType } from '~/generated/graphql';
import { FieldContext } from '../../contexts/FieldContext';
import { useFieldInitialValue } from '../../hooks/useFieldInitialValue';
@@ -14,7 +15,7 @@ import { isFieldSelectValue } from '../../types/guards/isFieldSelectValue';
export const useSelectField = () => {
const { entityId, fieldDefinition, hotkeyScope } = useContext(FieldContext);
assertFieldMetadata('ENUM', isFieldSelect, fieldDefinition);
assertFieldMetadata(FieldMetadataType.Select, isFieldSelect, fieldDefinition);
const { fieldName } = fieldDefinition.metadata;

View File

@@ -46,7 +46,7 @@ const RatingFieldInputWithContext = ({
fieldDefinition={{
fieldMetadataId: 'rating',
label: 'Rating',
type: FieldMetadataType.Probability,
type: FieldMetadataType.Rating,
iconName: 'Icon123',
metadata: {
fieldName: 'Rating',

View File

@@ -2,6 +2,7 @@ import { selectorFamily } from 'recoil';
import { isFieldFullName } from '@/object-record/field/types/guards/isFieldFullName';
import { isFieldFullNameValue } from '@/object-record/field/types/guards/isFieldFullNameValue';
import { isFieldSelect } from '@/object-record/field/types/guards/isFieldSelect';
import { isFieldUuid } from '@/object-record/field/types/guards/isFieldUuid';
import { assertNotNull } from '~/utils/assert';
@@ -42,7 +43,8 @@ export const isEntityFieldEmptyFamilySelector = selectorFamily({
isFieldNumber(fieldDefinition) ||
isFieldRating(fieldDefinition) ||
isFieldEmail(fieldDefinition) ||
isFieldBoolean(fieldDefinition)
isFieldBoolean(fieldDefinition) ||
isFieldSelect(fieldDefinition)
//|| isFieldPhone(fieldDefinition)
) {
const fieldValue = get(entityFieldsFamilyState(entityId))?.[

View File

@@ -1,18 +1,18 @@
export type FieldType =
| 'BOOLEAN'
| 'UUID'
| 'TEXT'
| 'RELATION'
| 'CHIP'
| 'CURRENCY'
| 'DATE_TIME'
| 'DOUBLE_TEXT_CHIP'
| 'DOUBLE_TEXT'
| 'EMAIL'
| 'ENUM'
| 'FULL_NAME'
| 'LINK'
| 'NUMBER'
| 'PHONE'
| 'PROBABILITY'
| 'RATING'
| 'RELATION'
| 'SELECT'
| 'TEXT'
| 'URL'
| 'LINK'
| 'CURRENCY'
| 'FULL_NAME';
| 'UUID';

View File

@@ -29,7 +29,7 @@ type AssertFieldMetadataFunction = <
? FieldDateTimeMetadata
: E extends 'EMAIL'
? FieldEmailMetadata
: E extends 'ENUM'
: E extends 'SELECT'
? FieldSelectMetadata
: E extends 'LINK'
? FieldLinkMetadata
@@ -37,7 +37,7 @@ type AssertFieldMetadataFunction = <
? FieldNumberMetadata
: E extends 'PHONE'
? FieldPhoneMetadata
: E extends 'PROBABILITY'
: E extends 'RATING'
? FieldRatingMetadata
: E extends 'RELATION'
? FieldRelationMetadata

View File

@@ -6,4 +6,4 @@ import { FieldMetadata, FieldRatingMetadata } from '../FieldMetadata';
export const isFieldRating = (
field: Pick<FieldDefinition<FieldMetadata>, 'type'>,
): field is FieldDefinition<FieldRatingMetadata> =>
field.type === FieldMetadataType.Probability;
field.type === FieldMetadataType.Rating;

View File

@@ -1,6 +1,9 @@
import { FieldMetadataType } from '~/generated/graphql';
import { FieldDefinition } from '../FieldDefinition';
import { FieldMetadata, FieldSelectMetadata } from '../FieldMetadata';
export const isFieldSelect = (
field: FieldDefinition<FieldMetadata>,
): field is FieldDefinition<FieldSelectMetadata> => field.type === 'ENUM';
field: Pick<FieldDefinition<FieldMetadata>, 'type'>,
): field is FieldDefinition<FieldSelectMetadata> =>
field.type === FieldMetadataType.Select;

View File

@@ -148,7 +148,7 @@ export const SettingsObjectFieldPreview = ({
>
{fieldMetadata.type === FieldMetadataType.Boolean ? (
<BooleanFieldInput readonly />
) : fieldMetadata.type === FieldMetadataType.Probability ? (
) : fieldMetadata.type === FieldMetadataType.Rating ? (
<RatingFieldInput readonly />
) : (
<FieldDisplay />

View File

@@ -88,10 +88,10 @@ export const SettingsObjectFieldTypeSelectSection = ({
FieldMetadataType.Boolean,
FieldMetadataType.Currency,
FieldMetadataType.DateTime,
FieldMetadataType.Enum,
FieldMetadataType.Select,
FieldMetadataType.Link,
FieldMetadataType.Number,
FieldMetadataType.Probability,
FieldMetadataType.Rating,
FieldMetadataType.Relation,
FieldMetadataType.Text,
].includes(values.type) && (
@@ -151,7 +151,7 @@ export const SettingsObjectFieldTypeSelectSection = ({
})
}
/>
) : values.type === FieldMetadataType.Enum ? (
) : values.type === FieldMetadataType.Select ? (
<SettingsObjectFieldSelectForm
values={selectFormConfig}
onChange={(nextValues) => onChange({ select: nextValues })}

View File

@@ -95,7 +95,7 @@ export const Rating: Story = {
fieldMetadata: {
icon: 'IconHandClick',
label: 'Engagement',
type: FieldMetadataType.Probability,
type: FieldMetadataType.Rating,
},
},
};

View File

@@ -108,7 +108,7 @@ export const WithSelectForm: Story = {
fieldMetadata: { label: 'Industry', icon: 'IconBuildingFactory2' },
values: {
...fieldMetadataFormDefaultValues,
type: FieldMetadataType.Enum,
type: FieldMetadataType.Select,
select: [
{
color: 'pink',

View File

@@ -59,10 +59,14 @@ export const settingsFieldMetadataTypes: Record<
Icon: IconCalendarEvent,
defaultValue: defaultDateValue.toISOString(),
},
[FieldMetadataType.Enum]: {
[FieldMetadataType.Select]: {
label: 'Select',
Icon: IconTag,
},
[FieldMetadataType.MultiSelect]: {
label: 'Multi-Select',
Icon: IconTag,
},
[FieldMetadataType.Currency]: {
label: 'Currency',
Icon: IconCoins,
@@ -79,5 +83,10 @@ export const settingsFieldMetadataTypes: Record<
Icon: IconTwentyStar,
defaultValue: '3',
},
[FieldMetadataType.Rating]: {
label: 'Rating',
Icon: IconTwentyStar,
defaultValue: '3',
},
[FieldMetadataType.FullName]: { label: 'Full Name', Icon: IconUser },
};

View File

@@ -56,11 +56,12 @@ const relationSchema = fieldSchema.merge(
const selectSchema = fieldSchema.merge(
z.object({
type: z.literal(FieldMetadataType.Enum),
type: z.literal(FieldMetadataType.Select),
select: z
.array(
z.object({
color: themeColorSchema,
id: z.string().optional(),
isDefault: z.boolean().optional(),
label: z.string().min(1),
}),
@@ -70,18 +71,20 @@ const selectSchema = fieldSchema.merge(
);
const {
Enum: _Enum,
Select: _Select,
Relation: _Relation,
...otherFieldTypes
} = FieldMetadataType;
type OtherFieldType = Exclude<
FieldMetadataType,
FieldMetadataType.Relation | FieldMetadataType.Select
>;
const otherFieldTypesSchema = fieldSchema.merge(
z.object({
type: z.enum(
Object.values(otherFieldTypes) as [
Exclude<FieldMetadataType, FieldMetadataType.Relation>,
...Exclude<FieldMetadataType, FieldMetadataType.Relation>[],
],
Object.values(otherFieldTypes) as [OtherFieldType, ...OtherFieldType[]],
),
}),
);
@@ -165,7 +168,7 @@ export const useFieldMetadataForm = () => {
!isDeeplyEqual(initialRelationFormValues, nextRelationFormValues),
);
setHasSelectFormChanged(
nextFieldFormValues.type === FieldMetadataType.Enum &&
nextFieldFormValues.type === FieldMetadataType.Select &&
!isDeeplyEqual(initialSelectFormValues, nextSelectFormValues),
);
};
@@ -177,6 +180,7 @@ export const useFieldMetadataForm = () => {
hasFormChanged:
hasFieldFormChanged || hasRelationFormChanged || hasSelectFormChanged,
hasRelationFormChanged,
hasSelectFormChanged,
initForm,
isInitialized,
isValid: validationResult.success,

View File

@@ -48,7 +48,7 @@ export const useFieldPreview = ({
const defaultSelectValue = selectOptions?.[0];
const selectValue =
fieldMetadata.type === FieldMetadataType.Enum &&
fieldMetadata.type === FieldMetadataType.Select &&
typeof firstRecordFieldValue === 'string'
? selectOptions?.find(
(selectOption) => selectOption.value === firstRecordFieldValue,
@@ -65,7 +65,7 @@ export const useFieldPreview = ({
value:
fieldMetadata.type === FieldMetadataType.Relation
? relationValue
: fieldMetadata.type === FieldMetadataType.Enum
: fieldMetadata.type === FieldMetadataType.Select
? selectValue || defaultSelectValue
: firstRecordFieldValue || defaultValue,
};

View File

@@ -97,7 +97,7 @@ export const SettingsObjectDetail = () => {
fieldMetadataItem={activeMetadataField}
ActionIcon={
<SettingsObjectFieldActiveActionDropdown
isCustomField={activeMetadataField.isCustom}
isCustomField={!!activeMetadataField.isCustom}
scopeKey={activeMetadataField.id}
onEdit={() =>
navigate(`./${getFieldSlug(activeMetadataField)}`)
@@ -119,7 +119,7 @@ export const SettingsObjectDetail = () => {
fieldMetadataItem={disabledMetadataField}
ActionIcon={
<SettingsObjectFieldDisabledActionDropdown
isCustomField={disabledMetadataField.isCustom}
isCustomField={!!disabledMetadataField.isCustom}
scopeKey={disabledMetadataField.id}
onActivate={() =>
activateMetadataField(disabledMetadataField)

View File

@@ -53,6 +53,7 @@ export const SettingsObjectFieldEdit = () => {
hasFieldFormChanged,
hasFormChanged,
hasRelationFormChanged,
hasSelectFormChanged,
initForm,
isInitialized,
isValid,
@@ -65,6 +66,14 @@ export const SettingsObjectFieldEdit = () => {
return;
}
const selectOptions = activeMetadataField.options?.map((option) => ({
...option,
isDefault: activeMetadataField.defaultValue === option.value,
}));
selectOptions?.sort(
(optionA, optionB) => optionA.position - optionB.position,
);
initForm({
icon: activeMetadataField.icon ?? undefined,
label: activeMetadataField.label,
@@ -78,6 +87,7 @@ export const SettingsObjectFieldEdit = () => {
objectMetadataId: relationObjectMetadataItem?.id || '',
type: relationType || RelationMetadataType.OneToMany,
},
...(selectOptions?.length ? { select: selectOptions } : {}),
});
}, [
activeMetadataField,
@@ -111,12 +121,16 @@ export const SettingsObjectFieldEdit = () => {
});
}
if (hasFieldFormChanged) {
if (hasFieldFormChanged || hasSelectFormChanged) {
await editMetadataField({
description: validatedFormValues.description,
icon: validatedFormValues.icon,
id: activeMetadataField.id,
label: validatedFormValues.label,
options:
validatedFormValues.type === FieldMetadataType.Select
? validatedFormValues.select
: undefined,
});
}

View File

@@ -171,6 +171,10 @@ export const SettingsObjectNewFieldStep2 = () => {
label: validatedFormValues.label,
objectMetadataId: activeObjectMetadataItem.id,
type: validatedFormValues.type,
options:
validatedFormValues.type === FieldMetadataType.Select
? validatedFormValues.select
: undefined,
});
}
@@ -185,12 +189,14 @@ export const SettingsObjectNewFieldStep2 = () => {
const excludedFieldTypes = [
FieldMetadataType.Currency,
FieldMetadataType.Email,
FieldMetadataType.Enum,
FieldMetadataType.Numeric,
FieldMetadataType.FullName,
FieldMetadataType.Link,
FieldMetadataType.MultiSelect,
FieldMetadataType.Numeric,
FieldMetadataType.Phone,
FieldMetadataType.Probability,
FieldMetadataType.Rating,
FieldMetadataType.Select,
FieldMetadataType.Uuid,
];

View File

@@ -5654,6 +5654,13 @@
dependencies:
"@types/lodash" "*"
"@types/lodash.snakecase@^4.1.9":
version "4.1.9"
resolved "https://registry.yarnpkg.com/@types/lodash.snakecase/-/lodash.snakecase-4.1.9.tgz#2d2b3313a44500cb6d8a1c598e0353778d4420d2"
integrity sha512-emBZJUiNlo+QPXr1junMKXwzHJK9zbFvTVdyAoorFcm1YRsbzkZCYPTVMM9AW+dlnA6utG7vpfvOs8alxv/TMw==
dependencies:
"@types/lodash" "*"
"@types/lodash@*", "@types/lodash@^4.14.167":
version "4.14.202"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.202.tgz#f09dbd2fb082d507178b2f2a5c7e74bd72ff98f8"
@@ -13725,6 +13732,11 @@ lodash.mergewith@4.6.2:
resolved "https://registry.yarnpkg.com/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz#617121f89ac55f59047c7aec1ccd6654c6590f55"
integrity sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==
lodash.snakecase@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.snakecase/-/lodash.snakecase-4.1.1.tgz#39d714a35357147837aefd64b5dcbb16becd8f8d"
integrity sha512-QZ1d4xoBHYUeuouhEq3lk3Uq7ldgyFXGBhg04+oRLnIz8o9T65Eh+8YdroUwn846zchkA9yDsDl5CVVaV2nqYw==
lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"