Skip to content

The open alternative to Salesforce, designed for AI.

Keep hidden creation form fields hidden and list only supported fields in the form settings (#27493)

Thomas Trompettee7c7933290f7
diff --git a/packages/twenty-front/src/modules/object-record/record-form/utils/__tests__/computeRecordFormFields.test.ts b/packages/twenty-front/src/modules/object-record/record-form/utils/__tests__/computeRecordFormFields.test.ts
index 9adb0839efd..498831ce305 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/utils/__tests__/computeRecordFormFields.test.ts
+++ b/packages/twenty-front/src/modules/object-record/record-form/utils/__tests__/computeRecordFormFields.test.ts
@@ -169,7 +169,7 @@ describe('computeRecordFormFields', () => {
]);
});
- it('should merge the widgets of a field into one entry, placed at its first visible widget', () => {
+ it('should merge the widgets of a field into one entry at its first widget, visible only when all of them are', () => {
const result = computeRecordFormFields({
recordFormPageLayout: buildPageLayout([
{
@@ -183,15 +183,10 @@ describe('computeRecordFormFields', () => {
}),
buildFormFieldWidget({ fieldMetadataId: 'field-code', index: 1 }),
buildFormFieldWidget({ fieldMetadataId: 'field-name', index: 2 }),
- buildFormFieldWidget({
- fieldMetadataId: 'field-city',
- index: 3,
- isActive: false,
- }),
+ buildFormFieldWidget({ fieldMetadataId: 'field-city', index: 3 }),
buildFormFieldWidget({
fieldMetadataId: 'field-city',
index: 4,
- isActive: false,
id: 'second-city-widget',
}),
],
@@ -201,31 +196,31 @@ describe('computeRecordFormFields', () => {
});
expect(summarize(result)).toEqual([
- {
- name: 'code',
- widgets: [['widget-field-code', true]],
- isVisible: true,
- },
{
name: 'name',
widgets: [
['hidden-name-widget', false],
['widget-field-name', true],
],
+ isVisible: false,
+ },
+ {
+ name: 'code',
+ widgets: [['widget-field-code', true]],
isVisible: true,
},
{
name: 'city',
widgets: [
- ['widget-field-city', false],
- ['second-city-widget', false],
+ ['widget-field-city', true],
+ ['second-city-widget', true],
],
- isVisible: false,
+ isVisible: true,
},
]);
});
- it('should merge the widgets of every morph target into the morph field', () => {
+ it('should keep a hidden morph field hidden when a widget is added for a new target', () => {
const ownerField = buildFieldMetadataItem('field-owner-person', 'owner', {
type: FieldMetadataType.MORPH_RELATION,
settings: { relationType: RelationType.MANY_TO_ONE },
@@ -242,6 +237,12 @@ describe('computeRecordFormFields', () => {
name: 'ownerCompany',
},
},
+ {
+ sourceFieldMetadata: {
+ id: 'field-owner-opportunity',
+ name: 'ownerOpportunity',
+ },
+ },
],
});
@@ -250,17 +251,21 @@ describe('computeRecordFormFields', () => {
{
position: 10,
widgets: [
- buildFormFieldWidget({ fieldMetadataId: 'field-name', index: 0 }),
buildFormFieldWidget({
fieldMetadataId: 'field-owner-person',
- index: 1,
+ index: 0,
isActive: false,
}),
buildFormFieldWidget({
fieldMetadataId: 'field-owner-company',
- index: 2,
+ index: 1,
isActive: false,
}),
+ buildFormFieldWidget({ fieldMetadataId: 'field-name', index: 2 }),
+ buildFormFieldWidget({
+ fieldMetadataId: 'field-owner-opportunity',
+ index: 3,
+ }),
],
},
]),
@@ -268,19 +273,20 @@ describe('computeRecordFormFields', () => {
});
expect(summarize(result)).toEqual([
- {
- name: 'name',
- widgets: [['widget-field-name', true]],
- isVisible: true,
- },
{
name: 'owner',
widgets: [
['widget-field-owner-person', false],
['widget-field-owner-company', false],
+ ['widget-field-owner-opportunity', true],
],
isVisible: false,
},
+ {
+ name: 'name',
+ widgets: [['widget-field-name', true]],
+ isVisible: true,
+ },
]);
});
diff --git a/packages/twenty-front/src/modules/object-record/record-form/utils/computeRecordFormFields.ts b/packages/twenty-front/src/modules/object-record/record-form/utils/computeRecordFormFields.ts
index 915ba172b59..4f0c0fc4cba 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/utils/computeRecordFormFields.ts
+++ b/packages/twenty-front/src/modules/object-record/record-form/utils/computeRecordFormFields.ts
@@ -1,14 +1,12 @@
import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
import { type FieldMetadataItemRelation } from '@/object-metadata/types/FieldMetadataItemRelation';
import { type RecordFormField } from '@/object-record/record-form/types/RecordFormField';
+import { isFieldMetadataItemEligibleForRecordForm } from '@/object-record/record-form/utils/isFieldMetadataItemEligibleForRecordForm';
import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
import groupBy from 'lodash.groupby';
import uniqBy from 'lodash.uniqby';
-import {
- isDefined,
- isFieldMetadataEligibleForRecordForm,
-} from 'twenty-shared/utils';
+import { isDefined } from 'twenty-shared/utils';
import {
PageLayoutTabLayoutMode,
WidgetConfigurationType,
@@ -56,18 +54,6 @@ const getFormFieldMetadataId = (
: undefined;
};
-const isFieldMetadataItemEligibleForRecordForm = (
- fieldMetadataItem: RecordFormFieldMetadataItem,
-): boolean =>
- isFieldMetadataEligibleForRecordForm({
- fieldName: fieldMetadataItem.name,
- fieldType: fieldMetadataItem.type,
- isActive: fieldMetadataItem.isActive === true,
- isSystem: fieldMetadataItem.isSystem === true,
- isUIEditable: fieldMetadataItem.isUIEditable !== false,
- relationType: fieldMetadataItem.settings?.relationType,
- });
-
export const computeRecordFormFields = <
TFieldMetadataItem extends RecordFormFieldMetadataItem,
>({
@@ -129,27 +115,21 @@ export const computeRecordFormFields = <
({ fieldMetadataItem }) => fieldMetadataItem.id,
);
- const visibleFieldMetadataIds = new Set(
- formFieldWidgetEntries
- .filter(({ pageLayoutWidget }) => pageLayoutWidget.isActive)
- .map(({ fieldMetadataItem }) => fieldMetadataItem.id),
- );
-
return uniqBy(
- formFieldWidgetEntries.filter(
- ({ pageLayoutWidget, fieldMetadataItem }) =>
- pageLayoutWidget.isActive ||
- !visibleFieldMetadataIds.has(fieldMetadataItem.id),
- ),
+ formFieldWidgetEntries,
({ fieldMetadataItem }) => fieldMetadataItem.id,
)
- .map(({ pageLayoutWidget, fieldMetadataItem }) => ({
- fieldMetadataItem,
- widgets: formFieldWidgetEntriesByFieldMetadataId[
+ .map(({ fieldMetadataItem }) => {
+ const widgets = formFieldWidgetEntriesByFieldMetadataId[
fieldMetadataItem.id
- ].map((formFieldWidgetEntry) => formFieldWidgetEntry.pageLayoutWidget),
- isVisible: pageLayoutWidget.isActive,
- }))
+ ].map((formFieldWidgetEntry) => formFieldWidgetEntry.pageLayoutWidget);
+
+ return {
+ fieldMetadataItem,
+ widgets,
+ isVisible: widgets.every((widget) => widget.isActive),
+ };
+ })
.filter(
({ fieldMetadataItem, isVisible }) =>
isVisible ||
diff --git a/packages/twenty-front/src/modules/object-record/record-form/utils/isFieldMetadataItemEligibleForRecordForm.ts b/packages/twenty-front/src/modules/object-record/record-form/utils/isFieldMetadataItemEligibleForRecordForm.ts
new file mode 100644
index 00000000000..bd4ce5139f9
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/utils/isFieldMetadataItemEligibleForRecordForm.ts
@@ -0,0 +1,17 @@
+import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
+import { isFieldMetadataEligibleForRecordForm } from 'twenty-shared/utils';
+
+export const isFieldMetadataItemEligibleForRecordForm = (
+ fieldMetadataItem: Pick<
+ FieldMetadataItem,
+ 'name' | 'type' | 'isActive' | 'isSystem' | 'isUIEditable' | 'settings'
+ >,
+): boolean =>
+ isFieldMetadataEligibleForRecordForm({
+ fieldName: fieldMetadataItem.name,
+ fieldType: fieldMetadataItem.type,
+ isActive: fieldMetadataItem.isActive === true,
+ isSystem: fieldMetadataItem.isSystem === true,
+ isUIEditable: fieldMetadataItem.isUIEditable !== false,
+ relationType: fieldMetadataItem.settings?.relationType,
+ });
diff --git a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form-settings/components/SidePanelRecordCreationFormSettingsPage.tsx b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form-settings/components/SidePanelRecordCreationFormSettingsPage.tsx
index d80ed110b86..c64ade969e5 100644
--- a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form-settings/components/SidePanelRecordCreationFormSettingsPage.tsx
+++ b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form-settings/components/SidePanelRecordCreationFormSettingsPage.tsx
@@ -1,6 +1,7 @@
import { useObjectMetadataItemById } from '@/object-metadata/hooks/useObjectMetadataItemById';
import { useRecordFormFields } from '@/object-record/record-form/hooks/useRecordFormFields';
import { type RecordFormField } from '@/object-record/record-form/types/RecordFormField';
+import { isFieldMetadataItemEligibleForRecordForm } from '@/object-record/record-form/utils/isFieldMetadataItemEligibleForRecordForm';
import { useUpdatePageLayoutWidgetsIsActive } from '@/page-layout/hooks/useUpdatePageLayoutWidgetsIsActive';
import { getSettingsFieldTypeConfig } from '@/settings/data-model/utils/getSettingsFieldTypeConfig';
import { isFieldTypeSupportedInSettings } from '@/settings/data-model/utils/isFieldTypeSupportedInSettings';
@@ -64,6 +65,10 @@ const SidePanelRecordCreationFormSettings = ({
objectId: objectMetadataId,
});
const { recordFormFields } = useRecordFormFields({ objectMetadataItem });
+ const configurableRecordFormFields = recordFormFields.filter(
+ ({ fieldMetadataItem }) =>
+ isFieldMetadataItemEligibleForRecordForm(fieldMetadataItem),
+ );
const { goBackFromSidePanel, removePageFromSidePanelHistory } =
useSidePanelHistory();
const sidePanelPageId = useAvailableComponentInstanceIdOrThrow(
@@ -100,7 +105,7 @@ const SidePanelRecordCreationFormSettings = ({
const pageLayoutWidgetIsActiveUpdates =
computePageLayoutWidgetIsActiveUpdates({
- recordFormFields,
+ recordFormFields: configurableRecordFormFields,
isVisibleByFieldMetadataId,
});
@@ -121,7 +126,7 @@ const SidePanelRecordCreationFormSettings = ({
<StyledContainer>
<StyledContent>
<SidePanelGroup heading={t`Fields`}>
- {recordFormFields.map((recordFormField) => {
+ {configurableRecordFormFields.map((recordFormField) => {
const { fieldMetadataItem } = recordFormField;
const isVisible = isRecordFormFieldVisible(recordFormField);
diff --git a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form-settings/components/__tests__/SidePanelRecordCreationFormSettingsPage.test.tsx b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form-settings/components/__tests__/SidePanelRecordCreationFormSettingsPage.test.tsx
index aa04d39f811..71efa140635 100644
--- a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form-settings/components/__tests__/SidePanelRecordCreationFormSettingsPage.test.tsx
+++ b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form-settings/components/__tests__/SidePanelRecordCreationFormSettingsPage.test.tsx
@@ -47,11 +47,21 @@ const NAME_FIELD = buildTextField('name', 'Name');
const DOMAIN_FIELD = buildTextField('domain', 'Domain');
const NICKNAME_FIELD = buildTextField('nickname', 'Nickname');
const SECRET_FIELD = buildTextField('secret', 'Secret');
+const RATING_FIELD = {
+ ...buildTextField('rating', 'Rating'),
+ type: FieldMetadataType.RATING,
+};
const COMPANY_OBJECT = {
id: OBJECT_METADATA_ID,
labelSingular: 'Company',
- fields: [NAME_FIELD, DOMAIN_FIELD, NICKNAME_FIELD, SECRET_FIELD],
+ fields: [
+ NAME_FIELD,
+ DOMAIN_FIELD,
+ NICKNAME_FIELD,
+ SECRET_FIELD,
+ RATING_FIELD,
+ ],
};
const updatePageLayoutWidgetsIsActive = jest.fn();
@@ -149,6 +159,7 @@ const seedRecordFormPageLayout = () => {
buildFormFieldWidget(DOMAIN_FIELD.id, 1, true),
buildFormFieldWidget(NICKNAME_FIELD.id, 2, false),
buildFormFieldWidget(SECRET_FIELD.id, 3, false),
+ buildFormFieldWidget(RATING_FIELD.id, 4, true),
],
draft: [],
status: 'up-to-date',
@@ -200,7 +211,7 @@ describe('SidePanelRecordCreationFormSettingsPage', () => {
);
});
- it('lists the form fields in form order with their visibility, whatever the viewer can update', () => {
+ it('lists the supported form fields in form order with their visibility, whatever the viewer can update', () => {
renderPage();
expect(