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

View File

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