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:
@ -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 &&
|
||||
[
|
||||
|
||||
@ -203,6 +203,10 @@ export const SettingsObjectNewFieldStep2 = () => {
|
||||
onChange={handleFormChange}
|
||||
/>
|
||||
<SettingsObjectFieldTypeSelectSection
|
||||
excludedFieldTypes={[
|
||||
FieldMetadataType.Enum,
|
||||
FieldMetadataType.Relation,
|
||||
]}
|
||||
fieldMetadata={{
|
||||
icon: formValues.icon,
|
||||
label: formValues.label || 'Employees',
|
||||
|
||||
Reference in New Issue
Block a user