feat: create custom object field (#2225)

Closes #2171
This commit is contained in:
Thaïs
2023-10-26 11:34:26 +02:00
committed by GitHub
parent fc4075b372
commit 00dd046798
15 changed files with 91 additions and 193 deletions

View File

@ -0,0 +1,17 @@
import toCamelCase from 'lodash.camelcase';
import upperFirst from 'lodash.upperfirst';
import { ObjectFieldDataType } from '@/settings/data-model/types/ObjectFieldDataType';
import { Field } from '~/generated-metadata/graphql';
export const formatMetadataFieldInput = (
input: Pick<Field, 'label' | 'icon' | 'description'> & {
type: ObjectFieldDataType;
},
) => ({
description: input.description?.trim() ?? null,
icon: input.icon,
label: input.label.trim(),
name: upperFirst(toCamelCase(input.label.trim())),
type: input.type,
});

View File

@ -0,0 +1,4 @@
const metadataLabelValidationPattern = /^[a-zA-Z][a-zA-Z0-9 ]*$/;
export const validateMetadataLabel = (value: string) =>
!!value.match(metadataLabelValidationPattern);

View File

@ -1,4 +0,0 @@
const metadataObjectLabelValidationPattern = /^[a-zA-Z][a-zA-Z0-9 ]*$/;
export const validateMetadataObjectLabel = (value: string) =>
!!value.match(metadataObjectLabelValidationPattern);