fix: hide Select field type + display Relation field type only for ed… (#2603)

fix: hide Select field type + display Relation field type only for edition

Fixes #2585
This commit is contained in:
Thaïs
2023-11-21 00:14:58 +01:00
committed by GitHub
parent 1e79d4351e
commit b3c1723638
2 changed files with 15 additions and 9 deletions

View File

@ -24,9 +24,10 @@ export type SettingsObjectFieldTypeSelectSectionFormValues = Partial<{
}>; }>;
type SettingsObjectFieldTypeSelectSectionProps = { type SettingsObjectFieldTypeSelectSectionProps = {
excludedFieldTypes?: FieldMetadataType[];
fieldMetadata: Pick<Field, 'icon' | 'label'> & { id?: string }; fieldMetadata: Pick<Field, 'icon' | 'label'> & { id?: string };
relationFieldMetadataId?: string;
onChange: (values: SettingsObjectFieldTypeSelectSectionFormValues) => void; onChange: (values: SettingsObjectFieldTypeSelectSectionFormValues) => void;
relationFieldMetadataId?: string;
values?: SettingsObjectFieldTypeSelectSectionFormValues; values?: SettingsObjectFieldTypeSelectSectionFormValues;
} & Pick<SettingsObjectFieldPreviewProps, 'objectMetadataId'>; } & Pick<SettingsObjectFieldPreviewProps, 'objectMetadataId'>;
@ -45,17 +46,21 @@ const StyledRelationImage = styled.img<{ flip?: boolean }>`
`; `;
export const SettingsObjectFieldTypeSelectSection = ({ export const SettingsObjectFieldTypeSelectSection = ({
excludedFieldTypes,
fieldMetadata, fieldMetadata,
relationFieldMetadataId,
objectMetadataId, objectMetadataId,
onChange, onChange,
relationFieldMetadataId,
values, values,
}: SettingsObjectFieldTypeSelectSectionProps) => { }: SettingsObjectFieldTypeSelectSectionProps) => {
const relationFormConfig = values?.relation; const relationFormConfig = values?.relation;
const allowedFieldTypes = Object.entries(dataTypes).filter( const fieldTypeOptions = Object.entries(dataTypes)
([key]) => key !== FieldMetadataType.Relation, .filter(([key]) => !excludedFieldTypes?.includes(key as FieldMetadataType))
); .map(([key, dataType]) => ({
value: key as FieldMetadataType,
...dataType,
}));
return ( return (
<Section> <Section>
@ -68,10 +73,7 @@ export const SettingsObjectFieldTypeSelectSection = ({
dropdownScopeId="object-field-type-select" dropdownScopeId="object-field-type-select"
value={values?.type} value={values?.type}
onChange={(value) => onChange({ type: value })} onChange={(value) => onChange({ type: value })}
options={allowedFieldTypes.map(([key, dataType]) => ({ options={fieldTypeOptions}
value: key as FieldMetadataType,
...dataType,
}))}
/> />
{!!values?.type && {!!values?.type &&
[ [

View File

@ -203,6 +203,10 @@ export const SettingsObjectNewFieldStep2 = () => {
onChange={handleFormChange} onChange={handleFormChange}
/> />
<SettingsObjectFieldTypeSelectSection <SettingsObjectFieldTypeSelectSection
excludedFieldTypes={[
FieldMetadataType.Enum,
FieldMetadataType.Relation,
]}
fieldMetadata={{ fieldMetadata={{
icon: formValues.icon, icon: formValues.icon,
label: formValues.label || 'Employees', label: formValues.label || 'Employees',