Skip to content

The open alternative to Salesforce, designed for AI.

Export vertical-list widgets without the deprecated position form (#26290)

Weiko04cb24700619
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-page-layout-widget-to-page-layout-widget-manifest.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-page-layout-widget-to-page-layout-widget-manifest.util.spec.ts
index 084fb9aa80d..061d813bd24 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-page-layout-widget-to-page-layout-widget-manifest.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-page-layout-widget-to-page-layout-widget-manifest.util.spec.ts
@@ -90,6 +90,47 @@ describe('fromFlatPageLayoutWidgetToPageLayoutWidgetManifest', () => {
});
});
+ it('should leave the position out and hoist its height behavior when the order of the widgets carries it', () => {
+ const viewportWidgetManifest: PageLayoutWidgetManifest = {
+ ...MINIMAL_WIDGET_MANIFEST,
+ heightBehavior: 'TAB_VIEWPORT',
+ };
+ const flatPageLayoutWidget = forward(viewportWidgetManifest);
+
+ expect(flatPageLayoutWidget.position).toEqual({
+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,
+ index: 0,
+ heightBehavior: 'TAB_VIEWPORT',
+ });
+
+ const pageLayoutWidgetManifest =
+ fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({
+ flatPageLayoutWidget,
+ isPositionImpliedByOrder: true,
+ });
+
+ expect(pageLayoutWidgetManifest).toEqual(viewportWidgetManifest);
+ expect(
+ compareTwoFlatEntity({
+ fromUniversalFlatEntity: flatPageLayoutWidget,
+ toUniversalFlatEntity: forward(pageLayoutWidgetManifest),
+ metadataName: 'pageLayoutWidget',
+ }),
+ ).toBeUndefined();
+ });
+
+ it('should keep a grid position even when the order of the widgets is said to carry it', () => {
+ expect(
+ fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({
+ flatPageLayoutWidget: forward(
+ MINIMAL_WIDGET_MANIFEST,
+ PageLayoutTabLayoutMode.GRID,
+ ),
+ isPositionImpliedByOrder: true,
+ }).position?.layoutMode,
+ ).toBe(PageLayoutTabLayoutMode.GRID);
+ });
+
it('should keep an explicit null view reference inside the configuration', () => {
const viewlessFieldsWidgetManifest: PageLayoutWidgetManifest = {
...MINIMAL_WIDGET_MANIFEST,
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-widget-to-page-layout-widget-manifest.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-widget-to-page-layout-widget-manifest.util.ts
index aeff4a4bbd5..1e87898deb1 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-widget-to-page-layout-widget-manifest.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-widget-to-page-layout-widget-manifest.util.ts
@@ -1,12 +1,38 @@
import { type PageLayoutWidgetManifest } from 'twenty-shared/application';
+import { PageLayoutTabLayoutMode } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { type UniversalFlatPageLayoutWidget } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-page-layout-widget.type';
+const getPositionProperties = ({
+ position,
+ isPositionImpliedByOrder,
+}: {
+ position: UniversalFlatPageLayoutWidget['position'];
+ isPositionImpliedByOrder: boolean;
+}): Pick<PageLayoutWidgetManifest, 'position' | 'heightBehavior'> => {
+ if (!isDefined(position)) {
+ return {};
+ }
+
+ if (
+ !isPositionImpliedByOrder ||
+ position.layoutMode !== PageLayoutTabLayoutMode.VERTICAL_LIST
+ ) {
+ return { position };
+ }
+
+ return isDefined(position.heightBehavior)
+ ? { heightBehavior: position.heightBehavior }
+ : {};
+};
+
export const fromFlatPageLayoutWidgetToPageLayoutWidgetManifest = ({
flatPageLayoutWidget,
+ isPositionImpliedByOrder = false,
}: {
flatPageLayoutWidget: UniversalFlatPageLayoutWidget;
+ isPositionImpliedByOrder?: boolean;
}): PageLayoutWidgetManifest => ({
universalIdentifier: flatPageLayoutWidget.universalIdentifier,
title: flatPageLayoutWidget.title,
@@ -20,8 +46,9 @@ export const fromFlatPageLayoutWidgetToPageLayoutWidgetManifest = ({
...(isDefined(flatPageLayoutWidget.conditionalDisplay)
? { conditionalDisplay: flatPageLayoutWidget.conditionalDisplay }
: {}),
- ...(isDefined(flatPageLayoutWidget.position)
- ? { position: flatPageLayoutWidget.position }
- : {}),
+ ...getPositionProperties({
+ position: flatPageLayoutWidget.position,
+ isPositionImpliedByOrder,
+ }),
configuration: flatPageLayoutWidget.universalConfiguration,
});
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/get-vertical-list-flat-page-layout-widgets-in-order.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/get-vertical-list-flat-page-layout-widgets-in-order.util.spec.ts
new file mode 100644
index 00000000000..5d7e61cfd63
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/get-vertical-list-flat-page-layout-widgets-in-order.util.spec.ts
@@ -0,0 +1,73 @@
+import { PageLayoutTabLayoutMode } from 'twenty-shared/types';
+
+import { getVerticalListFlatPageLayoutWidgetsInOrder } from 'src/engine/core-modules/application/application-manifest/utils/get-vertical-list-flat-page-layout-widgets-in-order.util';
+
+const buildVerticalListWidget = (
+ universalIdentifier: string,
+ index: number,
+) => ({
+ universalIdentifier,
+ position: {
+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST as const,
+ index,
+ },
+});
+
+describe('getVerticalListFlatPageLayoutWidgetsInOrder', () => {
+ it('should sort the widgets by index when the indices are exactly 0 to n - 1', () => {
+ expect(
+ getVerticalListFlatPageLayoutWidgetsInOrder([
+ buildVerticalListWidget('third', 2),
+ buildVerticalListWidget('first', 0),
+ buildVerticalListWidget('second', 1),
+ ])?.map(({ universalIdentifier }) => universalIdentifier),
+ ).toEqual(['first', 'second', 'third']);
+ });
+
+ it('should return undefined when the indices have a gap, do not start at 0 or repeat', () => {
+ expect(
+ getVerticalListFlatPageLayoutWidgetsInOrder([
+ buildVerticalListWidget('first', 0),
+ buildVerticalListWidget('third', 2),
+ ]),
+ ).toBeUndefined();
+ expect(
+ getVerticalListFlatPageLayoutWidgetsInOrder([
+ buildVerticalListWidget('second', 1),
+ ]),
+ ).toBeUndefined();
+ expect(
+ getVerticalListFlatPageLayoutWidgetsInOrder([
+ buildVerticalListWidget('first', 0),
+ buildVerticalListWidget('also-first', 0),
+ ]),
+ ).toBeUndefined();
+ });
+
+ it('should return undefined when a widget is not positioned in a vertical list', () => {
+ expect(
+ getVerticalListFlatPageLayoutWidgetsInOrder([
+ buildVerticalListWidget('first', 0),
+ {
+ universalIdentifier: 'grid',
+ position: {
+ layoutMode: PageLayoutTabLayoutMode.GRID as const,
+ row: 0,
+ column: 0,
+ rowSpan: 2,
+ columnSpan: 2,
+ },
+ },
+ ]),
+ ).toBeUndefined();
+ expect(
+ getVerticalListFlatPageLayoutWidgetsInOrder([
+ { universalIdentifier: 'unpositioned', position: null },
+ ]),
+ ).toBeUndefined();
+ });
+
+ it('should return an empty list for a tab without widgets', () => {
+ expect(getVerticalListFlatPageLayoutWidgetsInOrder([])).toEqual([]);
+ });
+});
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/reconstruct-page-layouts-manifest.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/reconstruct-page-layouts-manifest.util.spec.ts
index cc62758d92d..a5965483b2e 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/reconstruct-page-layouts-manifest.util.spec.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/reconstruct-page-layouts-manifest.util.spec.ts
@@ -377,6 +377,11 @@ const FIELDS_WIDGET_MANIFEST: PageLayoutWidgetManifest = {
},
};
+const withoutPosition = ({
+ position: _position,
+ ...pageLayoutWidgetManifest
+}: PageLayoutWidgetManifest) => pageLayoutWidgetManifest;
+
const statusOf = (
coverage: ReturnType<typeof reconstructPageLayoutsManifest>['coverage'],
universalIdentifier: string,
@@ -389,7 +394,7 @@ const reasonOf = (
) => statusOf(coverage, universalIdentifier)?.reason;
describe('reconstructPageLayoutsManifest', () => {
- it('should nest tabs and widgets under an exported page layout and order every collection by universal identifier', () => {
+ it('should nest tabs and widgets under an exported page layout, order tabs by universal identifier and let the order of vertical-list widgets carry their position', () => {
const { pageLayouts, pageLayoutTabs, pageLayoutWidgets, coverage } =
reconstruct({
applicationAllFlatEntityMaps: buildMaps({
@@ -429,8 +434,8 @@ describe('reconstructPageLayoutsManifest', () => {
{
...OVERVIEW_TAB_MANIFEST,
widgets: [
- FIELDS_WIDGET_MANIFEST,
- buildNotesWidgetManifest('notes-widget'),
+ withoutPosition(buildNotesWidgetManifest('notes-widget')),
+ withoutPosition(FIELDS_WIDGET_MANIFEST),
],
},
],
@@ -446,6 +451,43 @@ describe('reconstructPageLayoutsManifest', () => {
).toBe(true);
});
+ it('should keep explicit positions when the vertical-list indices of a tab have a gap', () => {
+ const lastWidgetManifest: PageLayoutWidgetManifest = {
+ ...buildNotesWidgetManifest('a-last-widget'),
+ position: { layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST, index: 2 },
+ };
+
+ const { pageLayouts } = reconstruct({
+ applicationAllFlatEntityMaps: buildMaps({
+ objects: [petObject],
+ pageLayouts: [
+ buildFlatPageLayout({ pageLayoutManifest: PET_PAGE_MANIFEST }),
+ ],
+ pageLayoutTabs: [
+ buildFlatPageLayoutTab({
+ pageLayoutTabManifest: OVERVIEW_TAB_MANIFEST,
+ pageLayoutUniversalIdentifier: PET_PAGE_UID,
+ }),
+ ],
+ pageLayoutWidgets: [
+ buildFlatPageLayoutWidget({
+ pageLayoutWidgetManifest: buildNotesWidgetManifest('notes-widget'),
+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,
+ }),
+ buildFlatPageLayoutWidget({
+ pageLayoutWidgetManifest: lastWidgetManifest,
+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,
+ }),
+ ],
+ }),
+ });
+
+ expect(pageLayouts[0].tabs?.[0].widgets).toEqual([
+ lastWidgetManifest,
+ buildNotesWidgetManifest('notes-widget'),
+ ]);
+ });
+
it('should hide an engine-derived page layout, export a tab added to it standalone with its widgets, and export a widget added to an engine-derived tab standalone', () => {
const { pageLayouts, pageLayoutTabs, pageLayoutWidgets, coverage } =
reconstruct({
@@ -500,7 +542,7 @@ describe('reconstructPageLayoutsManifest', () => {
title: 'Extra',
position: 60,
layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,
- widgets: [buildNotesWidgetManifest('extra-widget')],
+ widgets: [withoutPosition(buildNotesWidgetManifest('extra-widget'))],
},
]);
expect(statusOf(coverage, ENGINE_PAGE_UID)?.status).toBe(
@@ -575,7 +617,7 @@ describe('reconstructPageLayoutsManifest', () => {
COMPANY_PAGE_UID,
);
expect(pageLayoutTabs[0].widgets).toEqual([
- buildNotesWidgetManifest('company-widget'),
+ withoutPosition(buildNotesWidgetManifest('company-widget')),
]);
expect(statusOf(coverage, 'company-widget')?.status).toBe(
ApplicationExportCoverageStatus.EXPORTED,
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-vertical-list-flat-page-layout-widgets-in-order.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-vertical-list-flat-page-layout-widgets-in-order.util.ts
new file mode 100644
index 00000000000..6387b49c9ef
--- /dev/null
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-vertical-list-flat-page-layout-widgets-in-order.util.ts
@@ -0,0 +1,40 @@
+import { PageLayoutTabLayoutMode } from 'twenty-shared/types';
+import { isDefined } from 'twenty-shared/utils';
+
+import { type UniversalFlatPageLayoutWidget } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-page-layout-widget.type';
+
+export const getVerticalListFlatPageLayoutWidgetsInOrder = <
+ TFlatPageLayoutWidget extends Pick<UniversalFlatPageLayoutWidget, 'position'>,
+>(
+ flatPageLayoutWidgets: TFlatPageLayoutWidget[],
+): TFlatPageLayoutWidget[] | undefined => {
+ const indexedFlatPageLayoutWidgets = flatPageLayoutWidgets.flatMap(
+ (flatPageLayoutWidget) =>
+ isDefined(flatPageLayoutWidget.position) &&
+ flatPageLayoutWidget.position.layoutMode ===
+ PageLayoutTabLayoutMode.VERTICAL_LIST
+ ? [
+ {
+ flatPageLayoutWidget,
+ index: flatPageLayoutWidget.position.index,
+ },
+ ]
+ : [],
+ );
+
+ if (indexedFlatPageLayoutWidgets.length !== flatPageLayoutWidgets.length) {
+ return undefined;
+ }
+
+ const orderedFlatPageLayoutWidgets = indexedFlatPageLayoutWidgets
+ .slice()
+ .sort((left, right) => left.index - right.index);
+
+ return orderedFlatPageLayoutWidgets.every(
+ ({ index }, expectedIndex) => index === expectedIndex,
+ )
+ ? orderedFlatPageLayoutWidgets.map(
+ ({ flatPageLayoutWidget }) => flatPageLayoutWidget,
+ )
+ : undefined;
+};
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-page-layouts-manifest.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-page-layouts-manifest.util.ts
index 5f92b7273f5..6570ff177a7 100644
--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-page-layouts-manifest.util.ts
+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-page-layouts-manifest.util.ts
@@ -19,11 +19,13 @@ import {
createChildDecider,
type FlatChild,
} from 'src/engine/core-modules/application/application-manifest/utils/create-child-decider.util';
+import { getVerticalListFlatPageLayoutWidgetsInOrder } from 'src/engine/core-modules/application/application-manifest/utils/get-vertical-list-flat-page-layout-widgets-in-order.util';
import { getUnsupportedPageLayoutReason } from 'src/engine/core-modules/application/application-manifest/utils/get-unsupported-page-layout-reason.util';
import { getUnsupportedPageLayoutWidgetReason } from 'src/engine/core-modules/application/application-manifest/utils/get-unsupported-page-layout-widget-reason.util';
import { ApplicationExportCoverageStatus } from 'src/engine/core-modules/application/enums/application-export-coverage-status.enum';
import { type AllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-maps.type';
import { type FlatPageLayoutTab } from 'src/engine/metadata-modules/flat-page-layout-tab/types/flat-page-layout-tab.type';
+import { type FlatPageLayoutWidget } from 'src/engine/metadata-modules/flat-page-layout-widget/types/flat-page-layout-widget.type';
import { type FlatPageLayout } from 'src/engine/metadata-modules/flat-page-layout/types/flat-page-layout.type';
type FlatPageLayoutChild = FlatChild & {
@@ -149,9 +151,9 @@ export const reconstructPageLayoutsManifest = ({
getParentUniversalIdentifier: ({ pageLayoutTabUniversalIdentifier }) =>
pageLayoutTabUniversalIdentifier,
});
- const widgetsByPageLayoutTabUniversalIdentifier = new Map<
+ const nestedFlatPageLayoutWidgetsByPageLayoutTabUniversalIdentifier = new Map<
string,
- PageLayoutWidgetManifest[]
+ FlatPageLayoutWidget[]
>();
const pageLayoutWidgets: StandalonePageLayoutWidgetManifest[] = [];
@@ -179,19 +181,15 @@ export const reconstructPageLayoutsManifest = ({
});
if (decision === 'nested') {
- const widgets =
- widgetsByPageLayoutTabUniversalIdentifier.get(
+ const nestedFlatPageLayoutWidgets =
+ nestedFlatPageLayoutWidgetsByPageLayoutTabUniversalIdentifier.get(
flatPageLayoutWidget.pageLayoutTabUniversalIdentifier,
) ?? [];
- widgets.push(
- fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({
- flatPageLayoutWidget,
- }),
- );
- widgetsByPageLayoutTabUniversalIdentifier.set(
+ nestedFlatPageLayoutWidgets.push(flatPageLayoutWidget);
+ nestedFlatPageLayoutWidgetsByPageLayoutTabUniversalIdentifier.set(
flatPageLayoutWidget.pageLayoutTabUniversalIdentifier,
- widgets,
+ nestedFlatPageLayoutWidgets,
);
} else if (
decision === 'standalone' &&
@@ -206,6 +204,30 @@ export const reconstructPageLayoutsManifest = ({
}
}
+ const widgetsByPageLayoutTabUniversalIdentifier = new Map<
+ string,
+ PageLayoutWidgetManifest[]
+ >();
+
+ for (const [
+ pageLayoutTabUniversalIdentifier,
+ nestedFlatPageLayoutWidgets,
+ ] of nestedFlatPageLayoutWidgetsByPageLayoutTabUniversalIdentifier) {
+ const orderedFlatPageLayoutWidgets =
+ getVerticalListFlatPageLayoutWidgetsInOrder(nestedFlatPageLayoutWidgets);
+
+ widgetsByPageLayoutTabUniversalIdentifier.set(
+ pageLayoutTabUniversalIdentifier,
+ (orderedFlatPageLayoutWidgets ?? nestedFlatPageLayoutWidgets).map(
+ (flatPageLayoutWidget) =>
+ fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({
+ flatPageLayoutWidget,
+ isPositionImpliedByOrder: isDefined(orderedFlatPageLayoutWidgets),
+ }),
+ ),
+ );
+ }
+
const tabsByPageLayoutUniversalIdentifier = new Map<
string,
PageLayoutTabManifest[]
diff --git a/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/successful-export-application-data-model.integration-spec.ts.snap b/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/successful-export-application-data-model.integration-spec.ts.snap
index a654f32073c..dd95b2c2886 100644
--- a/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/successful-export-application-data-model.integration-spec.ts.snap
+++ b/packages/twenty-server/test/integration/metadata/suites/application/__snapshots__/successful-export-application-data-model.integration-spec.ts.snap
@@ -987,10 +987,6 @@ exports[`Application export - data model exports the whole application as a stab
"configurationType": "NOTES",
},
"objectUniversalIdentifier": "<TICKET_OBJECT>",
- "position": {
- "index": 0,
- "layoutMode": "VERTICAL_LIST",
- },
"title": "Notes",
"type": "NOTES",
"universalIdentifier": "<TICKET_RECORD_PAGE_EXTRA_NOTES_WIDGET>",
@@ -1041,10 +1037,6 @@ exports[`Application export - data model exports the whole application as a stab
"viewUniversalIdentifier": "<OPEN_TICKETS_VIEW>",
},
"objectUniversalIdentifier": "<TICKET_OBJECT>",
- "position": {
- "index": 0,
- "layoutMode": "VERTICAL_LIST",
- },
"title": "Fields",
"type": "FIELDS",
"universalIdentifier": "<TICKET_PAGE_FIELDS_WIDGET>",