The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Export page layouts, tabs and widgets from an installed application (#25624)
Weikoa51ce1926fde
diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-page-layout-tab-to-page-layout-tab-manifest.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-page-layout-tab-to-page-layout-tab-manifest.util.spec.tsnew file mode 100644index 00000000000..d3bfef2251a--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-page-layout-tab-to-page-layout-tab-manifest.util.spec.ts@@ -0,0 +1,112 @@+import {+ type PageLayoutTabManifest,+ type PageLayoutWidgetManifest,+} from 'twenty-shared/application';+import { PageLayoutTabLayoutMode, PageLayoutType } from 'twenty-shared/types';++import { fromFlatPageLayoutTabToPageLayoutTabManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-page-layout-tab-manifest.util';+import { fromFlatPageLayoutTabToStandalonePageLayoutTabManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-standalone-page-layout-tab-manifest.util';+import { fromPageLayoutTabManifestToUniversalFlatPageLayoutTab } from 'src/engine/core-modules/application/application-manifest/converters/from-page-layout-tab-manifest-to-universal-flat-page-layout-tab.util';+import { compareTwoFlatEntity } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/compare-two-universal-flat-entity.util';++const APP_UID = '11111111-1111-4111-8111-111111111111';+const PAGE_LAYOUT_UID = '33333333-3333-4333-8333-333333333333';+const TAB_UID = '44444444-4444-4444-8444-444444444444';+const WIDGET_UID = '55555555-5555-4555-8555-555555555555';+const NOW = '2026-09-08T10:00:00.000Z';++const WIDGET_MANIFEST: PageLayoutWidgetManifest = {+ universalIdentifier: WIDGET_UID,+ title: 'Notes',+ type: 'NOTES',+ position: { layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST, index: 0 },+ configuration: { configurationType: 'NOTES' },+};++const TAB_MANIFEST: Required<+ Omit<PageLayoutTabManifest, 'widgets' | 'pageLayoutUniversalIdentifier'>+> = {+ universalIdentifier: TAB_UID,+ title: 'Overview',+ position: 10,+ icon: 'IconHome',+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+};++const MINIMAL_TAB_MANIFEST: PageLayoutTabManifest = {+ universalIdentifier: TAB_UID,+ title: 'Board',+ position: 0,+};++const forward = (+ pageLayoutTabManifest: PageLayoutTabManifest,+ pageLayoutType?: PageLayoutType,+) =>+ fromPageLayoutTabManifestToUniversalFlatPageLayoutTab({+ pageLayoutTabManifest,+ pageLayoutUniversalIdentifier: PAGE_LAYOUT_UID,+ pageLayoutType,+ applicationUniversalIdentifier: APP_UID,+ now: NOW,+ });++describe('fromFlatPageLayoutTabToPageLayoutTabManifest', () => {+ it('should reproduce the manifest after a forward then an inverse conversion', () => {+ expect(+ fromFlatPageLayoutTabToPageLayoutTabManifest({+ flatPageLayoutTab: forward(TAB_MANIFEST),+ widgets: [WIDGET_MANIFEST],+ }),+ ).toEqual({ ...TAB_MANIFEST, widgets: [WIDGET_MANIFEST] });+ });++ it('should write the layout mode the forward converter applied to a minimal manifest', () => {+ expect(+ fromFlatPageLayoutTabToPageLayoutTabManifest({+ flatPageLayoutTab: forward(MINIMAL_TAB_MANIFEST),+ }),+ ).toEqual({+ ...MINIMAL_TAB_MANIFEST,+ layoutMode: PageLayoutTabLayoutMode.GRID,+ });+ expect(+ fromFlatPageLayoutTabToPageLayoutTabManifest({+ flatPageLayoutTab: forward(+ MINIMAL_TAB_MANIFEST,+ PageLayoutType.STANDALONE_PAGE,+ ),+ }),+ ).toEqual({+ ...MINIMAL_TAB_MANIFEST,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ });+ });++ it('should reproduce the flat entity after an inverse then a forward conversion', () => {+ const flatPageLayoutTab = forward(TAB_MANIFEST);++ expect(+ compareTwoFlatEntity({+ fromUniversalFlatEntity: flatPageLayoutTab,+ toUniversalFlatEntity: forward(+ fromFlatPageLayoutTabToPageLayoutTabManifest({ flatPageLayoutTab }),+ ),+ metadataName: 'pageLayoutTab',+ }),+ ).toBeUndefined();+ });++ it('should add the page layout identifier right after the universal identifier of a standalone tab', () => {+ expect(+ Object.entries(+ fromFlatPageLayoutTabToStandalonePageLayoutTabManifest({+ flatPageLayoutTab: forward(TAB_MANIFEST),+ }),+ ).slice(0, 2),+ ).toEqual([+ ['universalIdentifier', TAB_UID],+ ['pageLayoutUniversalIdentifier', PAGE_LAYOUT_UID],+ ]);+ });+});diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-page-layout-to-page-layout-manifest.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-page-layout-to-page-layout-manifest.util.spec.tsnew file mode 100644index 00000000000..870f65017b5--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/__tests__/from-flat-page-layout-to-page-layout-manifest.util.spec.ts@@ -0,0 +1,76 @@+import {+ type PageLayoutManifest,+ type PageLayoutTabManifest,+} from 'twenty-shared/application';+import { PageLayoutTabLayoutMode } from 'twenty-shared/types';++import { fromFlatPageLayoutToPageLayoutManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-to-page-layout-manifest.util';+import { fromPageLayoutManifestToUniversalFlatPageLayout } from 'src/engine/core-modules/application/application-manifest/converters/from-page-layout-manifest-to-universal-flat-page-layout.util';+import { compareTwoFlatEntity } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/compare-two-universal-flat-entity.util';++const APP_UID = '11111111-1111-4111-8111-111111111111';+const OBJECT_UID = '22222222-2222-4222-8222-222222222222';+const PAGE_LAYOUT_UID = '33333333-3333-4333-8333-333333333333';+const TAB_UID = '44444444-4444-4444-8444-444444444444';+const NOW = '2026-09-08T10:00:00.000Z';++const TAB_MANIFEST: PageLayoutTabManifest = {+ universalIdentifier: TAB_UID,+ title: 'Overview',+ position: 0,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+};++const PAGE_LAYOUT_MANIFEST: Required<Omit<PageLayoutManifest, 'tabs'>> = {+ universalIdentifier: PAGE_LAYOUT_UID,+ name: 'Pet page',+ type: 'RECORD_PAGE',+ objectUniversalIdentifier: OBJECT_UID,+ defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier: TAB_UID,+};++const MINIMAL_PAGE_LAYOUT_MANIFEST: PageLayoutManifest = {+ universalIdentifier: PAGE_LAYOUT_UID,+ name: 'Pet board',+ type: 'STANDALONE_PAGE',+};++const forward = (pageLayoutManifest: PageLayoutManifest) =>+ fromPageLayoutManifestToUniversalFlatPageLayout({+ pageLayoutManifest,+ applicationUniversalIdentifier: APP_UID,+ now: NOW,+ });++describe('fromFlatPageLayoutToPageLayoutManifest', () => {+ it('should reproduce the manifest after a forward then an inverse conversion', () => {+ expect(+ fromFlatPageLayoutToPageLayoutManifest({+ flatPageLayout: forward(PAGE_LAYOUT_MANIFEST),+ tabs: [TAB_MANIFEST],+ }),+ ).toEqual({ ...PAGE_LAYOUT_MANIFEST, tabs: [TAB_MANIFEST] });+ });++ it('should omit the null slots and the empty tab list of a minimal manifest', () => {+ expect(+ fromFlatPageLayoutToPageLayoutManifest({+ flatPageLayout: forward(MINIMAL_PAGE_LAYOUT_MANIFEST),+ }),+ ).toEqual(MINIMAL_PAGE_LAYOUT_MANIFEST);+ });++ it('should reproduce the flat entity after an inverse then a forward conversion', () => {+ const flatPageLayout = forward(PAGE_LAYOUT_MANIFEST);++ expect(+ compareTwoFlatEntity({+ fromUniversalFlatEntity: flatPageLayout,+ toUniversalFlatEntity: forward(+ fromFlatPageLayoutToPageLayoutManifest({ flatPageLayout }),+ ),+ metadataName: 'pageLayout',+ }),+ ).toBeUndefined();+ });+});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.tsnew file mode 100644index 00000000000..563a098c75d--- /dev/null+++ 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@@ -0,0 +1,116 @@+import { type PageLayoutWidgetManifest } from 'twenty-shared/application';+import { PageLayoutTabLayoutMode } from 'twenty-shared/types';++import { fromFlatPageLayoutWidgetToPageLayoutWidgetManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-widget-to-page-layout-widget-manifest.util';+import { fromPageLayoutWidgetManifestToUniversalFlatPageLayoutWidget } from 'src/engine/core-modules/application/application-manifest/converters/from-page-layout-widget-manifest-to-universal-flat-page-layout-widget.util';+import { compareTwoFlatEntity } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/utils/compare-two-universal-flat-entity.util';++const APP_UID = '11111111-1111-4111-8111-111111111111';+const OBJECT_UID = '22222222-2222-4222-8222-222222222222';+const VIEW_UID = '33333333-3333-4333-8333-333333333333';+const TAB_UID = '44444444-4444-4444-8444-444444444444';+const WIDGET_UID = '55555555-5555-4555-8555-555555555555';+const NOW = '2026-09-08T10:00:00.000Z';++const WIDGET_MANIFEST: Required<PageLayoutWidgetManifest> = {+ universalIdentifier: WIDGET_UID,+ title: 'Fields',+ type: 'FIELDS',+ objectUniversalIdentifier: OBJECT_UID,+ conditionalDisplay: { device: 'DESKTOP' },+ position: { layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST, index: 2 },+ configuration: {+ configurationType: 'FIELDS',+ viewUniversalIdentifier: VIEW_UID,+ newFieldDefaultVisibility: true,+ },+};++const MINIMAL_WIDGET_MANIFEST: PageLayoutWidgetManifest = {+ universalIdentifier: WIDGET_UID,+ title: 'Notes',+ type: 'NOTES',+ configuration: { configurationType: 'NOTES' },+};++const forward = (+ pageLayoutWidgetManifest: PageLayoutWidgetManifest,+ pageLayoutTabLayoutMode = PageLayoutTabLayoutMode.VERTICAL_LIST,+) =>+ fromPageLayoutWidgetManifestToUniversalFlatPageLayoutWidget({+ pageLayoutWidgetManifest,+ pageLayoutTabUniversalIdentifier: TAB_UID,+ pageLayoutTabLayoutMode,+ widgetIndex: 3,+ applicationUniversalIdentifier: APP_UID,+ now: NOW,+ });++describe('fromFlatPageLayoutWidgetToPageLayoutWidgetManifest', () => {+ it('should reproduce the manifest after a forward then an inverse conversion', () => {+ expect(+ fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({+ flatPageLayoutWidget: forward(WIDGET_MANIFEST),+ }),+ ).toEqual(WIDGET_MANIFEST);+ });++ it('should write the position the forward converter derived from the tab for a minimal manifest', () => {+ expect(+ fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({+ flatPageLayoutWidget: forward(MINIMAL_WIDGET_MANIFEST),+ }),+ ).toEqual({+ ...MINIMAL_WIDGET_MANIFEST,+ position: { layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST, index: 3 },+ });+ expect(+ fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({+ flatPageLayoutWidget: forward(+ MINIMAL_WIDGET_MANIFEST,+ PageLayoutTabLayoutMode.GRID,+ ),+ }).position,+ ).toEqual({+ layoutMode: PageLayoutTabLayoutMode.GRID,+ row: 0,+ column: 0,+ rowSpan: 4,+ columnSpan: 4,+ });+ });++ it('should keep an explicit null view reference inside the configuration', () => {+ const viewlessFieldsWidgetManifest: PageLayoutWidgetManifest = {+ ...MINIMAL_WIDGET_MANIFEST,+ type: 'FIELDS',+ configuration: {+ configurationType: 'FIELDS',+ viewUniversalIdentifier: null,+ newFieldDefaultVisibility: true,+ },+ };++ expect(+ fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({+ flatPageLayoutWidget: forward(viewlessFieldsWidgetManifest),+ }).configuration,+ ).toEqual(viewlessFieldsWidgetManifest.configuration);+ });++ it('should reproduce the flat entity after an inverse then a forward conversion', () => {+ const flatPageLayoutWidget = forward(WIDGET_MANIFEST);++ expect(+ compareTwoFlatEntity({+ fromUniversalFlatEntity: flatPageLayoutWidget,+ toUniversalFlatEntity: forward(+ fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({+ flatPageLayoutWidget,+ }),+ ),+ metadataName: 'pageLayoutWidget',+ }),+ ).toBeUndefined();+ });+});diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-page-layout-tab-manifest.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-page-layout-tab-manifest.util.tsnew file mode 100644index 00000000000..dd2c82930c3--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-page-layout-tab-manifest.util.ts@@ -0,0 +1,24 @@+import {+ type PageLayoutTabManifest,+ type PageLayoutWidgetManifest,+} from 'twenty-shared/application';+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';++import { type UniversalFlatPageLayoutTab } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-page-layout-tab.type';++export const fromFlatPageLayoutTabToPageLayoutTabManifest = ({+ flatPageLayoutTab,+ widgets = [],+}: {+ flatPageLayoutTab: UniversalFlatPageLayoutTab;+ widgets?: PageLayoutWidgetManifest[];+}): PageLayoutTabManifest => ({+ universalIdentifier: flatPageLayoutTab.universalIdentifier,+ title: flatPageLayoutTab.title,+ position: flatPageLayoutTab.position,+ ...(isDefined(flatPageLayoutTab.icon)+ ? { icon: flatPageLayoutTab.icon }+ : {}),+ layoutMode: flatPageLayoutTab.layoutMode,+ ...(isNonEmptyArray(widgets) ? { widgets } : {}),+});diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-standalone-page-layout-tab-manifest.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-standalone-page-layout-tab-manifest.util.tsnew file mode 100644index 00000000000..b4ed9d8460e--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-standalone-page-layout-tab-manifest.util.ts@@ -0,0 +1,28 @@+import {+ type PageLayoutTabManifest,+ type PageLayoutWidgetManifest,+} from 'twenty-shared/application';++import { fromFlatPageLayoutTabToPageLayoutTabManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-page-layout-tab-manifest.util';+import { type UniversalFlatPageLayoutTab } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-page-layout-tab.type';++export const fromFlatPageLayoutTabToStandalonePageLayoutTabManifest = ({+ flatPageLayoutTab,+ widgets,+}: {+ flatPageLayoutTab: UniversalFlatPageLayoutTab;+ widgets?: PageLayoutWidgetManifest[];+}): PageLayoutTabManifest => {+ const { universalIdentifier, ...pageLayoutTabManifest } =+ fromFlatPageLayoutTabToPageLayoutTabManifest({+ flatPageLayoutTab,+ widgets,+ });++ return {+ universalIdentifier,+ pageLayoutUniversalIdentifier:+ flatPageLayoutTab.pageLayoutUniversalIdentifier,+ ...pageLayoutTabManifest,+ };+};diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-to-page-layout-manifest.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-to-page-layout-manifest.util.tsnew file mode 100644index 00000000000..230a2d72243--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-to-page-layout-manifest.util.ts@@ -0,0 +1,34 @@+import {+ type PageLayoutManifest,+ type PageLayoutTabManifest,+} from 'twenty-shared/application';+import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';++import { type UniversalFlatPageLayout } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-page-layout.type';++export const fromFlatPageLayoutToPageLayoutManifest = ({+ flatPageLayout,+ tabs = [],+}: {+ flatPageLayout: UniversalFlatPageLayout;+ tabs?: PageLayoutTabManifest[];+}): PageLayoutManifest => ({+ universalIdentifier: flatPageLayout.universalIdentifier,+ name: flatPageLayout.name,+ type: flatPageLayout.type,+ ...(isDefined(flatPageLayout.objectMetadataUniversalIdentifier)+ ? {+ objectUniversalIdentifier:+ flatPageLayout.objectMetadataUniversalIdentifier,+ }+ : {}),+ ...(isDefined(+ flatPageLayout.defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier,+ )+ ? {+ defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier:+ flatPageLayout.defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier,+ }+ : {}),+ ...(isNonEmptyArray(tabs) ? { tabs } : {}),+});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.tsnew file mode 100644index 00000000000..aeff4a4bbd5--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-widget-to-page-layout-widget-manifest.util.ts@@ -0,0 +1,27 @@+import { type PageLayoutWidgetManifest } from 'twenty-shared/application';+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 fromFlatPageLayoutWidgetToPageLayoutWidgetManifest = ({+ flatPageLayoutWidget,+}: {+ flatPageLayoutWidget: UniversalFlatPageLayoutWidget;+}): PageLayoutWidgetManifest => ({+ universalIdentifier: flatPageLayoutWidget.universalIdentifier,+ title: flatPageLayoutWidget.title,+ type: flatPageLayoutWidget.type,+ ...(isDefined(flatPageLayoutWidget.objectMetadataUniversalIdentifier)+ ? {+ objectUniversalIdentifier:+ flatPageLayoutWidget.objectMetadataUniversalIdentifier,+ }+ : {}),+ ...(isDefined(flatPageLayoutWidget.conditionalDisplay)+ ? { conditionalDisplay: flatPageLayoutWidget.conditionalDisplay }+ : {}),+ ...(isDefined(flatPageLayoutWidget.position)+ ? { position: flatPageLayoutWidget.position }+ : {}),+ configuration: flatPageLayoutWidget.universalConfiguration,+});diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/services/application-manifest-export.service.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/services/application-manifest-export.service.tsindex 9f1d8cde79e..f5dfccbe982 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/services/application-manifest-export.service.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/services/application-manifest-export.service.ts@@ -10,6 +10,7 @@ import { assertFlatApplicationIsExportable } from 'src/engine/core-modules/appliimport { classifyApplicationFlatEntities } from 'src/engine/core-modules/application/application-manifest/utils/classify-application-flat-entities.util';import { getApplicationSubAllFlatEntityMaps } from 'src/engine/core-modules/application/application-manifest/utils/get-application-sub-all-flat-entity-maps.util';import { reconstructDataModelManifest } from 'src/engine/core-modules/application/application-manifest/utils/reconstruct-data-model-manifest.util';+import { reconstructPageLayoutsManifest } from 'src/engine/core-modules/application/application-manifest/utils/reconstruct-page-layouts-manifest.util';import { reconstructViewsManifest } from 'src/engine/core-modules/application/application-manifest/utils/reconstruct-views-manifest.util';import { ApplicationTranslationCacheService } from 'src/engine/core-modules/application/application-translation/application-translation-cache.service';import {@@ -78,6 +79,9 @@ export class ApplicationManifestExportService {indexes,coverage: dataModelCoverage,} = reconstructDataModelManifest({ applicationAllFlatEntityMaps });+ const exportedObjectUniversalIdentifiers = new Set(+ objects.map(({ universalIdentifier }) => universalIdentifier),+ );const {views,viewFields,@@ -85,9 +89,16 @@ export class ApplicationManifestExportService {} = reconstructViewsManifest({applicationAllFlatEntityMaps,allFlatEntityMaps,- exportedObjectUniversalIdentifiers: new Set(- objects.map(({ universalIdentifier }) => universalIdentifier),- ),+ exportedObjectUniversalIdentifiers,+ });+ const {+ pageLayouts,+ pageLayoutTabs,+ coverage: pageLayoutsCoverage,+ } = reconstructPageLayoutsManifest({+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,});const translations = isDefined(flatApplication.applicationRegistrationId)? await this.applicationTranslationCacheService.getCatalogsByLocale(@@ -117,8 +128,8 @@ export class ApplicationManifestExportService {views,viewFields,navigationMenuItems: [],- pageLayouts: [],- pageLayoutTabs: [],+ pageLayouts,+ pageLayoutTabs,commandMenuItems: [],timelineActivityTypes: [],...(isDefined(translations) ? { translations } : {}),@@ -135,7 +146,11 @@ export class ApplicationManifestExportService {flatApplication,applicationAllFlatEntityMaps,allFlatEntityMaps,- reconstructedCoverage: [...dataModelCoverage, ...viewsCoverage],+ reconstructedCoverage: [+ ...dataModelCoverage,+ ...viewsCoverage,+ ...pageLayoutsCoverage,+ ],}),files: [],};diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/types/view-export-classification.type.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/types/export-classification.type.tssimilarity index 54%rename from packages/twenty-server/src/engine/core-modules/application/application-manifest/types/view-export-classification.type.tsrename to packages/twenty-server/src/engine/core-modules/application/application-manifest/types/export-classification.type.tsindex f5b3fb04f26..93d09e1ba62 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/types/view-export-classification.type.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/types/export-classification.type.ts@@ -1,12 +1,12 @@import { type AllMetadataName } from 'twenty-shared/metadata';-export type ParentViewStatus =+export type ParentStatus =| 'exported'| 'engineDerived'| 'unsupported'| 'outside';-export type ViewChildMetadataName = Extract<+export type ChildMetadataName = Extract<AllMetadataName,| 'viewField'| 'viewFieldGroup'@@ -14,4 +14,11 @@ export type ViewChildMetadataName = Extract<| 'viewFilterGroup'| 'viewGroup'| 'viewSort'+ | 'pageLayoutTab'+ | 'pageLayoutWidget'+>;++export type ParentMetadataName = Extract<+ AllMetadataName,+ 'view' | 'pageLayout' | 'pageLayoutTab'>;diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/add-all-flat-entities-to-flat-entity-maps.test-util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/add-all-flat-entities-to-flat-entity-maps.test-util.tsnew file mode 100644index 00000000000..6977c4e3328--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/add-all-flat-entities-to-flat-entity-maps.test-util.ts@@ -0,0 +1,21 @@+import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-from.type';+import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';+import { addFlatEntityToFlatEntityMapsOrThrow } from 'src/engine/metadata-modules/flat-entity/utils/add-flat-entity-to-flat-entity-maps-or-throw.util';++export const addAllFlatEntitiesToFlatEntityMaps = <+ TFlatEntity extends SyncableFlatEntity,+>({+ flatEntities,+ flatEntityMaps,+}: {+ flatEntities: TFlatEntity[];+ flatEntityMaps: FlatEntityMaps<TFlatEntity>;+}): FlatEntityMaps<TFlatEntity> =>+ flatEntities.reduce(+ (maps, flatEntity) =>+ addFlatEntityToFlatEntityMapsOrThrow({+ flatEntity,+ flatEntityMaps: maps,+ }),+ flatEntityMaps,+ );diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/export-covers-compared-properties.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/export-covers-compared-properties.spec.tsindex 486f341b5d7..896986d1059 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/export-covers-compared-properties.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/export-covers-compared-properties.spec.ts@@ -1,4 +1,7 @@import {+ type PageLayoutManifest,+ type PageLayoutTabManifest,+ type PageLayoutWidgetManifest,type StandaloneViewFieldManifest,type ViewFieldGroupManifest,type ViewFieldManifest,@@ -11,6 +14,8 @@ import {import {AggregateOperations,FieldMetadataType,+ PageLayoutTabLayoutMode,+ PageLayoutType,ViewCalendarLayout,ViewFilterGroupLogicalOperator,ViewFilterOperand,@@ -23,6 +28,12 @@ import {import { fromFlatFieldMetadataToFieldManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-field-metadata-to-field-manifest.util';import { fromFlatIndexMetadataToIndexManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-index-metadata-to-index-manifest.util';import { fromFlatObjectMetadataToObjectManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-object-metadata-to-object-manifest.util';+import { fromFlatPageLayoutTabToPageLayoutTabManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-page-layout-tab-manifest.util';+import { fromFlatPageLayoutToPageLayoutManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-to-page-layout-manifest.util';+import { fromFlatPageLayoutWidgetToPageLayoutWidgetManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-widget-to-page-layout-widget-manifest.util';+import { fromPageLayoutManifestToUniversalFlatPageLayout } from 'src/engine/core-modules/application/application-manifest/converters/from-page-layout-manifest-to-universal-flat-page-layout.util';+import { fromPageLayoutTabManifestToUniversalFlatPageLayoutTab } from 'src/engine/core-modules/application/application-manifest/converters/from-page-layout-tab-manifest-to-universal-flat-page-layout-tab.util';+import { fromPageLayoutWidgetManifestToUniversalFlatPageLayoutWidget } from 'src/engine/core-modules/application/application-manifest/converters/from-page-layout-widget-manifest-to-universal-flat-page-layout-widget.util';import { fromFlatViewFieldGroupToViewFieldGroupManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-view-field-group-to-view-field-group-manifest.util';import { fromFlatViewFieldToStandaloneViewFieldManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-view-field-to-standalone-view-field-manifest.util';import { fromFlatViewFilterGroupToViewFilterGroupManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-view-filter-group-to-view-filter-group-manifest.util';@@ -137,6 +148,47 @@ const VIEW_CHILD_CONVERSION_CONTEXT = {now: NOW,};+const PAGE_LAYOUT_UID = 'dddddddd-dddd-4ddd-8ddd-dddddddddddd';+const PAGE_LAYOUT_TAB_UID = 'eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee';+const PAGE_LAYOUT_WIDGET_UID = 'ffffffff-ffff-4fff-8fff-ffffffffffff';++const PAGE_LAYOUT_WIDGET_MANIFEST: PageLayoutWidgetManifest = {+ universalIdentifier: PAGE_LAYOUT_WIDGET_UID,+ title: 'Fields',+ type: 'FIELDS',+ objectUniversalIdentifier: OBJECT_UID,+ conditionalDisplay: { device: 'DESKTOP' },+ position: { layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST, index: 0 },+ configuration: {+ configurationType: 'FIELDS',+ viewUniversalIdentifier: VIEW_UID,+ newFieldDefaultVisibility: true,+ },+};++const PAGE_LAYOUT_TAB_MANIFEST: PageLayoutTabManifest = {+ universalIdentifier: PAGE_LAYOUT_TAB_UID,+ title: 'Overview',+ position: 0,+ icon: 'IconHome',+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgets: [PAGE_LAYOUT_WIDGET_MANIFEST],+};++const PAGE_LAYOUT_MANIFEST: PageLayoutManifest = {+ universalIdentifier: PAGE_LAYOUT_UID,+ name: 'Pet page',+ type: 'RECORD_PAGE',+ objectUniversalIdentifier: OBJECT_UID,+ defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier: PAGE_LAYOUT_TAB_UID,+ tabs: [PAGE_LAYOUT_TAB_MANIFEST],+};++const PAGE_LAYOUT_KIND_GAPS = {+ deletedAt:+ 'page layouts, tabs and widgets are never soft-deleted; the column is scheduled for removal',+};+const VIEW_KIND_GAPS = {deletedAt:'views and their children are never soft-deleted; the column is scheduled for removal',@@ -335,6 +387,74 @@ const EXPORTED_KINDS: ExportedKind[] = [workspaceLocalProperties: [],knownGaps: NESTED_VIEW_CHILD_GAPS,},+ {+ metadataName: 'pageLayout',+ emittedProperties: Object.keys(+ fromFlatPageLayoutToPageLayoutManifest({+ flatPageLayout: fromPageLayoutManifestToUniversalFlatPageLayout({+ pageLayoutManifest: PAGE_LAYOUT_MANIFEST,+ applicationUniversalIdentifier: APP_UID,+ now: NOW,+ }),+ tabs: [PAGE_LAYOUT_TAB_MANIFEST],+ }),+ ),+ renamedProperties: {+ objectMetadataUniversalIdentifier: 'objectUniversalIdentifier',+ },+ workspaceLocalProperties: [],+ knownGaps: {+ ...PAGE_LAYOUT_KIND_GAPS,+ isFirstTabPinned:+ 'workspace-owned: the sync keeps the live value, so the forward default never diffs',+ },+ },+ {+ metadataName: 'pageLayoutTab',+ emittedProperties: Object.keys(+ fromFlatPageLayoutTabToPageLayoutTabManifest({+ flatPageLayoutTab:+ fromPageLayoutTabManifestToUniversalFlatPageLayoutTab({+ pageLayoutTabManifest: PAGE_LAYOUT_TAB_MANIFEST,+ pageLayoutUniversalIdentifier: PAGE_LAYOUT_UID,+ pageLayoutType: PageLayoutType.RECORD_PAGE,+ applicationUniversalIdentifier: APP_UID,+ now: NOW,+ }),+ widgets: [PAGE_LAYOUT_WIDGET_MANIFEST],+ }),+ ),+ renamedProperties: {},+ workspaceLocalProperties: ['isActive', 'overrides'],+ knownGaps: PAGE_LAYOUT_KIND_GAPS,+ },+ {+ metadataName: 'pageLayoutWidget',+ emittedProperties: Object.keys(+ fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({+ flatPageLayoutWidget:+ fromPageLayoutWidgetManifestToUniversalFlatPageLayoutWidget({+ pageLayoutWidgetManifest: PAGE_LAYOUT_WIDGET_MANIFEST,+ pageLayoutTabUniversalIdentifier: PAGE_LAYOUT_TAB_UID,+ pageLayoutTabLayoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ applicationUniversalIdentifier: APP_UID,+ now: NOW,+ }),+ }),+ ),+ renamedProperties: {+ objectMetadataUniversalIdentifier: 'objectUniversalIdentifier',+ universalConfiguration: 'configuration',+ },+ workspaceLocalProperties: ['isActive', 'universalOverrides'],+ knownGaps: {+ ...PAGE_LAYOUT_KIND_GAPS,+ pageLayoutTabUniversalIdentifier:+ 'a widget is written under its tab; there is no standalone widget slot',+ conditionalAvailabilityExpression:+ 'no manifest slot; a widget carrying one is reported as unsupported',+ },+ },];describe('export coverage of the compared properties', () => {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.tsnew file mode 100644index 00000000000..44729990f1e--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/reconstruct-page-layouts-manifest.util.spec.ts@@ -0,0 +1,953 @@+import {+ type PageLayoutManifest,+ type PageLayoutTabManifest,+ type PageLayoutWidgetManifest,+} from 'twenty-shared/application';+import {+ AggregateOperations,+ FieldMetadataType,+ PageLayoutTabLayoutMode,+ PageLayoutType,+} from 'twenty-shared/types';+import { isDefined } from 'twenty-shared/utils';++import { fromPageLayoutManifestToUniversalFlatPageLayout } from 'src/engine/core-modules/application/application-manifest/converters/from-page-layout-manifest-to-universal-flat-page-layout.util';+import { fromPageLayoutTabManifestToUniversalFlatPageLayoutTab } from 'src/engine/core-modules/application/application-manifest/converters/from-page-layout-tab-manifest-to-universal-flat-page-layout-tab.util';+import { fromFrontComponentManifestToUniversalFlatFrontComponent } from 'src/engine/core-modules/application/application-manifest/converters/from-front-component-manifest-to-universal-flat-front-component.util';+import { fromPageLayoutWidgetManifestToUniversalFlatPageLayoutWidget } from 'src/engine/core-modules/application/application-manifest/converters/from-page-layout-widget-manifest-to-universal-flat-page-layout-widget.util';+import { fromViewManifestToUniversalFlatView } from 'src/engine/core-modules/application/application-manifest/converters/from-view-manifest-to-universal-flat-view.util';+import { reconstructPageLayoutsManifest } from 'src/engine/core-modules/application/application-manifest/utils/reconstruct-page-layouts-manifest.util';+import { ApplicationExportCoverageStatus } from 'src/engine/core-modules/application/enums/application-export-coverage-status.enum';+import { createEmptyAllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/constant/create-empty-all-flat-entity-maps.constant';+import { type AllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-maps.type';+import { addAllFlatEntitiesToFlatEntityMaps } from 'src/engine/core-modules/application/application-manifest/utils/__tests__/add-all-flat-entities-to-flat-entity-maps.test-util';+import { getFlatFieldMetadataMock } from 'src/engine/metadata-modules/flat-field-metadata/__mocks__/get-flat-field-metadata.mock';+import { type FlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata.type';+import { getFlatObjectMetadataMock } from 'src/engine/metadata-modules/flat-object-metadata/__mocks__/get-flat-object-metadata.mock';+import { type FlatObjectMetadata } from 'src/engine/metadata-modules/flat-object-metadata/types/flat-object-metadata.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';+import { type FlatFrontComponent } from 'src/engine/metadata-modules/flat-front-component/types/flat-front-component.type';+import { type FlatView } from 'src/engine/metadata-modules/flat-view/types/flat-view.type';+import { WidgetConfigurationType } from 'src/engine/metadata-modules/page-layout-widget/enums/widget-configuration-type.type';++const APP_ID = 'application-id';+const WORKSPACE_ID = 'workspace-id';+const NOW = '2026-09-08T10:00:00.000Z';+const APP_UID = '11111111-1111-4111-8111-111111111111';+const PET_UID = '22222222-2222-4222-8222-222222222222';+const NAME_FIELD_UID = '33333333-3333-4333-8333-333333333333';+const FRONT_COMPONENT_UID = '44444444-4444-4444-8444-444444444444';+const MISSING_UID = '55555555-5555-4555-8555-555555555555';+const ALL_PETS_VIEW_UID = '66666666-6666-4666-8666-666666666666';+const PET_PAGE_UID = '77777777-7777-4777-8777-777777777777';+const ENGINE_PAGE_UID = '88888888-8888-4888-8888-888888888888';+const COMPANY_PAGE_UID = '99999999-9999-4999-8999-999999999999';+const NAMELESS_PAGE_UID = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';+const DETAILS_TAB_UID = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';+const OVERVIEW_TAB_UID = 'cccccccc-cccc-4ccc-8ccc-cccccccccccc';+const ENGINE_TAB_UID = 'dddddddd-dddd-4ddd-8ddd-dddddddddddd';+const EXTRA_TAB_UID = 'eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee';+const COMPANY_TAB_UID = 'ffffffff-ffff-4fff-8fff-ffffffffffff';+const EXPORTED_OBJECT_UNIVERSAL_IDENTIFIERS = new Set([PET_UID]);+const UNKNOWN_REFERENCE: Record<string, string> = {+ workflowUniversalIdentifier: MISSING_UID,+};++const buildMaps = ({+ objects = [],+ fields = [],+ views = [],+ frontComponents = [],+ pageLayouts = [],+ pageLayoutTabs = [],+ pageLayoutWidgets = [],+}: {+ objects?: FlatObjectMetadata[];+ fields?: FlatFieldMetadata[];+ views?: FlatView[];+ frontComponents?: FlatFrontComponent[];+ pageLayouts?: FlatPageLayout[];+ pageLayoutTabs?: FlatPageLayoutTab[];+ pageLayoutWidgets?: FlatPageLayoutWidget[];+}): AllFlatEntityMaps => {+ const maps = createEmptyAllFlatEntityMaps();++ return {+ ...maps,+ flatObjectMetadataMaps: addAllFlatEntitiesToFlatEntityMaps({+ flatEntities: objects,+ flatEntityMaps: maps.flatObjectMetadataMaps,+ }),+ flatFieldMetadataMaps: addAllFlatEntitiesToFlatEntityMaps({+ flatEntities: fields,+ flatEntityMaps: maps.flatFieldMetadataMaps,+ }),+ flatViewMaps: addAllFlatEntitiesToFlatEntityMaps({+ flatEntities: views,+ flatEntityMaps: maps.flatViewMaps,+ }),+ flatFrontComponentMaps: addAllFlatEntitiesToFlatEntityMaps({+ flatEntities: frontComponents,+ flatEntityMaps: maps.flatFrontComponentMaps,+ }),+ flatPageLayoutMaps: addAllFlatEntitiesToFlatEntityMaps({+ flatEntities: pageLayouts,+ flatEntityMaps: maps.flatPageLayoutMaps,+ }),+ flatPageLayoutTabMaps: addAllFlatEntitiesToFlatEntityMaps({+ flatEntities: pageLayoutTabs,+ flatEntityMaps: maps.flatPageLayoutTabMaps,+ }),+ flatPageLayoutWidgetMaps: addAllFlatEntitiesToFlatEntityMaps({+ flatEntities: pageLayoutWidgets,+ flatEntityMaps: maps.flatPageLayoutWidgetMaps,+ }),+ };+};++const petObject = getFlatObjectMetadataMock({+ universalIdentifier: PET_UID,+ applicationId: APP_ID,+ applicationUniversalIdentifier: APP_UID,+ nameSingular: 'pet',+ namePlural: 'pets',+ labelIdentifierFieldMetadataUniversalIdentifier: NAME_FIELD_UID,+});++const nameField = getFlatFieldMetadataMock({+ universalIdentifier: NAME_FIELD_UID,+ name: 'name',+ objectMetadataId: petObject.id,+ objectMetadataUniversalIdentifier: PET_UID,+ applicationId: APP_ID,+ applicationUniversalIdentifier: APP_UID,+ type: FieldMetadataType.TEXT,+});++const allPetsView: FlatView = {+ ...fromViewManifestToUniversalFlatView({+ viewManifest: {+ universalIdentifier: ALL_PETS_VIEW_UID,+ name: 'All pets',+ objectUniversalIdentifier: PET_UID,+ },+ applicationUniversalIdentifier: APP_UID,+ now: NOW,+ }),+ id: `${ALL_PETS_VIEW_UID}-id`,+ workspaceId: WORKSPACE_ID,+ applicationId: APP_ID,+ objectMetadataId: petObject.id,+ kanbanAggregateOperationFieldMetadataId: null,+ calendarFieldMetadataId: null,+ calendarEndFieldMetadataId: null,+ mainGroupByFieldMetadataId: null,+ overrides: null,+ viewFieldIds: [],+ viewFieldGroupIds: [],+ viewFilterIds: [],+ viewGroupIds: [],+ viewFilterGroupIds: [],+ viewSortIds: [],+};++const frontComponent: FlatFrontComponent = {+ ...fromFrontComponentManifestToUniversalFlatFrontComponent({+ frontComponentManifest: {+ universalIdentifier: FRONT_COMPONENT_UID,+ sourceComponentPath: 'src/components/pet-card.tsx',+ builtComponentPath: 'dist/pet-card.js',+ builtComponentChecksum: 'checksum',+ componentName: 'PetCard',+ },+ applicationUniversalIdentifier: APP_UID,+ isSettingsFrontComponent: false,+ now: NOW,+ }),+ id: `${FRONT_COMPONENT_UID}-id`,+ workspaceId: WORKSPACE_ID,+ applicationId: APP_ID,+};++const allFlatEntityMaps = buildMaps({+ objects: [petObject],+ fields: [nameField],+ views: [allPetsView],+ frontComponents: [frontComponent],+});++const buildFlatPageLayout = ({+ pageLayoutManifest,+ ...flatPageLayoutProperties+}: {+ pageLayoutManifest: PageLayoutManifest;+} & Partial<FlatPageLayout>): FlatPageLayout => ({+ ...fromPageLayoutManifestToUniversalFlatPageLayout({+ pageLayoutManifest,+ applicationUniversalIdentifier: APP_UID,+ now: NOW,+ }),+ id: `${pageLayoutManifest.universalIdentifier}-id`,+ workspaceId: WORKSPACE_ID,+ applicationId: APP_ID,+ objectMetadataId: isDefined(pageLayoutManifest.objectUniversalIdentifier)+ ? `${pageLayoutManifest.objectUniversalIdentifier}-id`+ : null,+ defaultTabToFocusOnMobileAndSidePanelId: null,+ tabIds: [],+ ...flatPageLayoutProperties,+});++const buildFlatPageLayoutTab = ({+ pageLayoutTabManifest,+ pageLayoutUniversalIdentifier,+ ...flatPageLayoutTabProperties+}: {+ pageLayoutTabManifest: PageLayoutTabManifest;+ pageLayoutUniversalIdentifier: string;+} & Partial<FlatPageLayoutTab>): FlatPageLayoutTab => ({+ ...fromPageLayoutTabManifestToUniversalFlatPageLayoutTab({+ pageLayoutTabManifest,+ pageLayoutUniversalIdentifier,+ pageLayoutType: PageLayoutType.RECORD_PAGE,+ applicationUniversalIdentifier: APP_UID,+ now: NOW,+ }),+ id: `${pageLayoutTabManifest.universalIdentifier}-id`,+ workspaceId: WORKSPACE_ID,+ applicationId: APP_ID,+ pageLayoutId: `${pageLayoutUniversalIdentifier}-id`,+ widgetIds: [],+ ...flatPageLayoutTabProperties,+});++const buildFlatPageLayoutWidget = ({+ pageLayoutWidgetManifest,+ pageLayoutTabUniversalIdentifier,+ ...flatPageLayoutWidgetProperties+}: {+ pageLayoutWidgetManifest: PageLayoutWidgetManifest;+ pageLayoutTabUniversalIdentifier: string;+} & Partial<FlatPageLayoutWidget>): FlatPageLayoutWidget => ({+ ...fromPageLayoutWidgetManifestToUniversalFlatPageLayoutWidget({+ pageLayoutWidgetManifest,+ pageLayoutTabUniversalIdentifier,+ pageLayoutTabLayoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ applicationUniversalIdentifier: APP_UID,+ now: NOW,+ }),+ id: `${pageLayoutWidgetManifest.universalIdentifier}-id`,+ workspaceId: WORKSPACE_ID,+ applicationId: APP_ID,+ pageLayoutTabId: `${pageLayoutTabUniversalIdentifier}-id`,+ objectMetadataId: null,+ configuration: { configurationType: WidgetConfigurationType.NOTES },+ overrides: null,+ ...flatPageLayoutWidgetProperties,+});++const PET_PAGE_MANIFEST: PageLayoutManifest = {+ universalIdentifier: PET_PAGE_UID,+ name: 'Pet page',+ type: 'RECORD_PAGE',+ objectUniversalIdentifier: PET_UID,+};++const ENGINE_PAGE_MANIFEST: PageLayoutManifest = {+ universalIdentifier: ENGINE_PAGE_UID,+ name: 'Default Pet Layout',+ type: 'RECORD_PAGE',+ objectUniversalIdentifier: PET_UID,+};++const OVERVIEW_TAB_MANIFEST: PageLayoutTabManifest = {+ universalIdentifier: OVERVIEW_TAB_UID,+ title: 'Overview',+ position: 0,+ icon: 'IconHome',+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+};++const DETAILS_TAB_MANIFEST: PageLayoutTabManifest = {+ universalIdentifier: DETAILS_TAB_UID,+ title: 'Details',+ position: 10,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+};++const buildNotesWidgetManifest = (+ universalIdentifier: string,+): PageLayoutWidgetManifest => ({+ universalIdentifier,+ title: 'Notes',+ type: 'NOTES',+ objectUniversalIdentifier: PET_UID,+ position: { layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST, index: 0 },+ configuration: { configurationType: 'NOTES' },+});++const FIELDS_WIDGET_MANIFEST: PageLayoutWidgetManifest = {+ universalIdentifier: 'fields-widget',+ title: 'Fields',+ type: 'FIELDS',+ objectUniversalIdentifier: PET_UID,+ position: { layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST, index: 1 },+ configuration: {+ configurationType: 'FIELDS',+ viewUniversalIdentifier: ALL_PETS_VIEW_UID,+ newFieldDefaultVisibility: true,+ },+};++const statusOf = (+ coverage: ReturnType<typeof reconstructPageLayoutsManifest>['coverage'],+ universalIdentifier: string,+) =>+ coverage.find((entry) => entry.universalIdentifier === universalIdentifier);++const reasonOf = (+ coverage: ReturnType<typeof reconstructPageLayoutsManifest>['coverage'],+ universalIdentifier: string,+) => statusOf(coverage, universalIdentifier)?.reason;++describe('reconstructPageLayoutsManifest', () => {+ it('should nest tabs and widgets under an exported page layout and order every collection by universal identifier', () => {+ const { pageLayouts, pageLayoutTabs, coverage } =+ reconstructPageLayoutsManifest({+ applicationAllFlatEntityMaps: buildMaps({+ objects: [petObject],+ pageLayouts: [+ buildFlatPageLayout({ pageLayoutManifest: PET_PAGE_MANIFEST }),+ ],+ pageLayoutTabs: [+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: OVERVIEW_TAB_MANIFEST,+ pageLayoutUniversalIdentifier: PET_PAGE_UID,+ }),+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: DETAILS_TAB_MANIFEST,+ pageLayoutUniversalIdentifier: PET_PAGE_UID,+ }),+ ],+ pageLayoutWidgets: [+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest:+ buildNotesWidgetManifest('notes-widget'),+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: FIELDS_WIDGET_MANIFEST,+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ ],+ }),+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers:+ EXPORTED_OBJECT_UNIVERSAL_IDENTIFIERS,+ });++ expect(pageLayouts).toEqual([+ {+ ...PET_PAGE_MANIFEST,+ tabs: [+ DETAILS_TAB_MANIFEST,+ {+ ...OVERVIEW_TAB_MANIFEST,+ widgets: [+ FIELDS_WIDGET_MANIFEST,+ buildNotesWidgetManifest('notes-widget'),+ ],+ },+ ],+ },+ ]);+ expect(pageLayoutTabs).toEqual([]);+ expect(coverage).toHaveLength(5);+ expect(+ coverage.every(+ ({ status }) => status === ApplicationExportCoverageStatus.EXPORTED,+ ),+ ).toBe(true);+ });++ it('should hide an engine-derived page layout, export a tab added to it standalone with its widgets, and refuse a widget added to an engine-derived tab', () => {+ const { pageLayouts, pageLayoutTabs, coverage } =+ reconstructPageLayoutsManifest({+ applicationAllFlatEntityMaps: buildMaps({+ objects: [petObject],+ pageLayouts: [+ buildFlatPageLayout({+ pageLayoutManifest: ENGINE_PAGE_MANIFEST,+ isSystemSideEffect: true,+ }),+ ],+ pageLayoutTabs: [+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: {+ universalIdentifier: ENGINE_TAB_UID,+ title: 'Home',+ position: 10,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ },+ pageLayoutUniversalIdentifier: ENGINE_PAGE_UID,+ isSystemSideEffect: true,+ }),+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: {+ universalIdentifier: EXTRA_TAB_UID,+ title: 'Extra',+ position: 60,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ },+ pageLayoutUniversalIdentifier: ENGINE_PAGE_UID,+ }),+ ],+ pageLayoutWidgets: [+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest:+ buildNotesWidgetManifest('extra-widget'),+ pageLayoutTabUniversalIdentifier: EXTRA_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: buildNotesWidgetManifest('home-widget'),+ pageLayoutTabUniversalIdentifier: ENGINE_TAB_UID,+ }),+ ],+ }),+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers:+ EXPORTED_OBJECT_UNIVERSAL_IDENTIFIERS,+ });++ expect(pageLayouts).toEqual([]);+ expect(pageLayoutTabs).toEqual([+ {+ universalIdentifier: EXTRA_TAB_UID,+ pageLayoutUniversalIdentifier: ENGINE_PAGE_UID,+ title: 'Extra',+ position: 60,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgets: [buildNotesWidgetManifest('extra-widget')],+ },+ ]);+ expect(statusOf(coverage, ENGINE_PAGE_UID)?.status).toBe(+ ApplicationExportCoverageStatus.ENGINE_DERIVED,+ );+ expect(statusOf(coverage, ENGINE_TAB_UID)?.status).toBe(+ ApplicationExportCoverageStatus.ENGINE_DERIVED,+ );+ expect(statusOf(coverage, EXTRA_TAB_UID)?.status).toBe(+ ApplicationExportCoverageStatus.EXPORTED,+ );+ expect(statusOf(coverage, 'extra-widget')?.status).toBe(+ ApplicationExportCoverageStatus.EXPORTED,+ );+ expect(statusOf(coverage, 'home-widget')).toEqual({+ metadataName: 'pageLayoutWidget',+ universalIdentifier: 'home-widget',+ status: ApplicationExportCoverageStatus.UNSUPPORTED,+ reason: 'page layout widget on an engine-derived page layout tab',+ });+ });++ it('should export a tab on a page layout outside the application standalone and refuse a widget on a tab outside the application', () => {+ const { pageLayoutTabs, coverage } = reconstructPageLayoutsManifest({+ applicationAllFlatEntityMaps: buildMaps({+ objects: [petObject],+ pageLayoutTabs: [+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: {+ universalIdentifier: COMPANY_TAB_UID,+ title: 'Tagline',+ position: 60,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ },+ pageLayoutUniversalIdentifier: COMPANY_PAGE_UID,+ }),+ ],+ pageLayoutWidgets: [+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest:+ buildNotesWidgetManifest('company-widget'),+ pageLayoutTabUniversalIdentifier: COMPANY_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest:+ buildNotesWidgetManifest('foreign-widget'),+ pageLayoutTabUniversalIdentifier: 'foreign-tab',+ }),+ ],+ }),+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers: EXPORTED_OBJECT_UNIVERSAL_IDENTIFIERS,+ });++ expect(+ pageLayoutTabs.map(({ universalIdentifier }) => universalIdentifier),+ ).toEqual([COMPANY_TAB_UID]);+ expect(pageLayoutTabs[0].pageLayoutUniversalIdentifier).toBe(+ COMPANY_PAGE_UID,+ );+ expect(pageLayoutTabs[0].widgets).toEqual([+ buildNotesWidgetManifest('company-widget'),+ ]);+ expect(statusOf(coverage, 'company-widget')?.status).toBe(+ ApplicationExportCoverageStatus.EXPORTED,+ );+ expect(reasonOf(coverage, 'foreign-widget')).toBe(+ 'page layout widget on a page layout tab outside the application',+ );+ });++ it('should refuse an unsupported page layout together with its tab and widget', () => {+ const { pageLayouts, pageLayoutTabs, coverage } =+ reconstructPageLayoutsManifest({+ applicationAllFlatEntityMaps: buildMaps({+ objects: [petObject],+ pageLayouts: [+ buildFlatPageLayout({+ pageLayoutManifest: {+ ...PET_PAGE_MANIFEST,+ universalIdentifier: NAMELESS_PAGE_UID,+ name: '',+ },+ }),+ ],+ pageLayoutTabs: [+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: OVERVIEW_TAB_MANIFEST,+ pageLayoutUniversalIdentifier: NAMELESS_PAGE_UID,+ }),+ ],+ pageLayoutWidgets: [+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest:+ buildNotesWidgetManifest('nameless-widget'),+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ ],+ }),+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers:+ EXPORTED_OBJECT_UNIVERSAL_IDENTIFIERS,+ });++ expect(pageLayouts).toEqual([]);+ expect(pageLayoutTabs).toEqual([]);+ expect(reasonOf(coverage, NAMELESS_PAGE_UID)).toBe(+ 'page layout without a name',+ );+ expect(reasonOf(coverage, OVERVIEW_TAB_UID)).toBe(+ 'page layout tab of an unsupported page layout',+ );+ expect(reasonOf(coverage, 'nameless-widget')).toBe(+ 'page layout widget of an unsupported page layout tab',+ );+ });++ it('should tell the page layout reasons apart', () => {+ const { coverage } = reconstructPageLayoutsManifest({+ applicationAllFlatEntityMaps: buildMaps({+ objects: [petObject],+ pageLayouts: [+ buildFlatPageLayout({+ pageLayoutManifest: {+ ...PET_PAGE_MANIFEST,+ universalIdentifier: 'unsupported-object-page',+ },+ }),+ buildFlatPageLayout({+ pageLayoutManifest: {+ ...PET_PAGE_MANIFEST,+ universalIdentifier: 'missing-object-page',+ objectUniversalIdentifier: MISSING_UID,+ },+ }),+ buildFlatPageLayout({+ pageLayoutManifest: {+ ...PET_PAGE_MANIFEST,+ universalIdentifier: 'engine-default-tab-page',+ objectUniversalIdentifier: undefined,+ defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier:+ ENGINE_TAB_UID,+ },+ }),+ buildFlatPageLayout({+ pageLayoutManifest: {+ ...PET_PAGE_MANIFEST,+ universalIdentifier: 'foreign-default-tab-page',+ objectUniversalIdentifier: undefined,+ defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier:+ OVERVIEW_TAB_UID,+ },+ }),+ buildFlatPageLayout({+ pageLayoutManifest: {+ ...PET_PAGE_MANIFEST,+ universalIdentifier: 'missing-default-tab-page',+ objectUniversalIdentifier: undefined,+ defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier:+ MISSING_UID,+ },+ }),+ ],+ pageLayoutTabs: [+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: {+ universalIdentifier: ENGINE_TAB_UID,+ title: 'Home',+ position: 10,+ },+ pageLayoutUniversalIdentifier: 'engine-default-tab-page',+ isSystemSideEffect: true,+ }),+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: OVERVIEW_TAB_MANIFEST,+ pageLayoutUniversalIdentifier: PET_PAGE_UID,+ }),+ ],+ }),+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers: new Set<string>(),+ });++ expect(reasonOf(coverage, 'unsupported-object-page')).toBe(+ 'page layout on an unsupported object',+ );+ expect(reasonOf(coverage, 'missing-object-page')).toBe(+ 'page layout on an object that does not exist',+ );+ expect(reasonOf(coverage, 'engine-default-tab-page')).toBe(+ 'page layout whose default tab is not exported',+ );+ expect(reasonOf(coverage, 'foreign-default-tab-page')).toBe(+ 'page layout whose default tab is not exported',+ );+ expect(reasonOf(coverage, 'missing-default-tab-page')).toBe(+ 'page layout whose default tab is not exported',+ );+ });++ it('should order exported page layouts and standalone tabs by universal identifier', () => {+ const { pageLayouts, pageLayoutTabs } = reconstructPageLayoutsManifest({+ applicationAllFlatEntityMaps: buildMaps({+ objects: [petObject],+ pageLayouts: [+ buildFlatPageLayout({+ pageLayoutManifest: {+ ...PET_PAGE_MANIFEST,+ universalIdentifier: 'z-page',+ },+ }),+ buildFlatPageLayout({+ pageLayoutManifest: ENGINE_PAGE_MANIFEST,+ isSystemSideEffect: true,+ }),+ buildFlatPageLayout({+ pageLayoutManifest: {+ ...PET_PAGE_MANIFEST,+ universalIdentifier: 'a-page',+ },+ }),+ ],+ pageLayoutTabs: [+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: {+ universalIdentifier: 'z-tab',+ title: 'Z',+ position: 1,+ },+ pageLayoutUniversalIdentifier: ENGINE_PAGE_UID,+ }),+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: {+ universalIdentifier: 'a-tab',+ title: 'A',+ position: 2,+ },+ pageLayoutUniversalIdentifier: COMPANY_PAGE_UID,+ }),+ ],+ }),+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers: EXPORTED_OBJECT_UNIVERSAL_IDENTIFIERS,+ });++ expect(+ pageLayouts.map(({ universalIdentifier }) => universalIdentifier),+ ).toEqual(['a-page', 'z-page']);+ expect(+ pageLayoutTabs.map(({ universalIdentifier }) => universalIdentifier),+ ).toEqual(['a-tab', 'z-tab']);+ });++ it('should refuse the widgets the manifest cannot carry', () => {+ const { coverage } = reconstructPageLayoutsManifest({+ applicationAllFlatEntityMaps: buildMaps({+ objects: [+ petObject,+ getFlatObjectMetadataMock({+ universalIdentifier: 'unsupported-object',+ applicationId: APP_ID,+ applicationUniversalIdentifier: APP_UID,+ nameSingular: 'toy',+ namePlural: 'toys',+ }),+ ],+ frontComponents: [frontComponent],+ pageLayouts: [+ buildFlatPageLayout({ pageLayoutManifest: PET_PAGE_MANIFEST }),+ ],+ pageLayoutTabs: [+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: OVERVIEW_TAB_MANIFEST,+ pageLayoutUniversalIdentifier: PET_PAGE_UID,+ }),+ ],+ pageLayoutWidgets: [+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: {+ ...buildNotesWidgetManifest('view-widget'),+ type: 'VIEW',+ },+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: buildNotesWidgetManifest(+ 'unpositioned-widget',+ ),+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ position: null,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: {+ ...buildNotesWidgetManifest('grid-widget'),+ position: {+ layoutMode: PageLayoutTabLayoutMode.GRID,+ row: 0,+ column: 0,+ rowSpan: 4,+ columnSpan: 4,+ },+ },+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest:+ buildNotesWidgetManifest('conditional-widget'),+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ conditionalAvailabilityExpression: 'device === "mobile"',+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: {+ ...buildNotesWidgetManifest('missing-object-widget'),+ objectUniversalIdentifier: MISSING_UID,+ },+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: {+ ...FIELDS_WIDGET_MANIFEST,+ universalIdentifier: 'missing-view-widget',+ configuration: {+ configurationType: 'FIELDS',+ viewUniversalIdentifier: MISSING_UID,+ newFieldDefaultVisibility: true,+ },+ },+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: {+ ...buildNotesWidgetManifest('missing-field-widget'),+ type: 'FORM_FIELD',+ configuration: {+ configurationType: 'FORM_FIELD',+ fieldMetadataId: MISSING_UID,+ },+ },+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: {+ ...buildNotesWidgetManifest('chart-widget'),+ type: 'GRAPH',+ configuration: {+ configurationType: 'AGGREGATE_CHART',+ aggregateFieldMetadataUniversalIdentifier: null,+ aggregateOperation: AggregateOperations.COUNT,+ },+ },+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: {+ ...buildNotesWidgetManifest('grouped-chart-widget'),+ type: 'GRAPH',+ configuration: {+ configurationType: 'PIE_CHART',+ aggregateFieldMetadataUniversalIdentifier: NAME_FIELD_UID,+ aggregateOperation: AggregateOperations.COUNT,+ groupByFieldMetadataUniversalIdentifier: NAME_FIELD_UID,+ },+ },+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: {+ ...buildNotesWidgetManifest('unsupported-object-widget'),+ objectUniversalIdentifier: 'unsupported-object',+ },+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: {+ ...buildNotesWidgetManifest('owned-front-component-widget'),+ type: 'FRONT_COMPONENT',+ configuration: {+ configurationType: 'FRONT_COMPONENT',+ frontComponentUniversalIdentifier: FRONT_COMPONENT_UID,+ },+ },+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: buildNotesWidgetManifest(+ 'unknown-reference-widget',+ ),+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ universalConfiguration: {+ ...UNKNOWN_REFERENCE,+ configurationType: WidgetConfigurationType.NOTES,+ },+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: {+ ...buildNotesWidgetManifest('missing-front-component-widget'),+ type: 'FRONT_COMPONENT',+ configuration: {+ configurationType: 'FRONT_COMPONENT',+ frontComponentUniversalIdentifier: MISSING_UID,+ },+ },+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ ],+ }),+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers: EXPORTED_OBJECT_UNIVERSAL_IDENTIFIERS,+ });++ expect(reasonOf(coverage, 'view-widget')).toBe(+ 'page layout widget of the VIEW type, which the sync does not support yet',+ );+ expect(reasonOf(coverage, 'unpositioned-widget')).toBe(+ 'page layout widget without a position',+ );+ expect(reasonOf(coverage, 'grid-widget')).toBe(+ 'page layout widget positioned for another layout mode than its tab',+ );+ expect(reasonOf(coverage, 'conditional-widget')).toBe(+ 'page layout widget with a conditional availability expression',+ );+ expect(reasonOf(coverage, 'missing-object-widget')).toBe(+ 'page layout widget on an object that does not exist',+ );+ expect(reasonOf(coverage, 'missing-view-widget')).toBe(+ 'page layout widget referencing a view that does not exist',+ );+ expect(reasonOf(coverage, 'missing-field-widget')).toBe(+ 'page layout widget referencing a field that does not exist',+ );+ expect(reasonOf(coverage, 'chart-widget')).toBe(+ 'page layout widget referencing a field that does not exist',+ );+ expect(reasonOf(coverage, 'unsupported-object-widget')).toBe(+ 'page layout widget on an unsupported object',+ );+ expect(reasonOf(coverage, 'owned-front-component-widget')).toBe(+ 'page layout widget referencing a front component that is not exported yet',+ );+ expect(reasonOf(coverage, 'missing-front-component-widget')).toBe(+ 'page layout widget referencing a front component that does not exist',+ );+ expect(statusOf(coverage, 'grouped-chart-widget')?.status).toBe(+ ApplicationExportCoverageStatus.EXPORTED,+ );+ expect(reasonOf(coverage, 'unknown-reference-widget')).toBe(+ 'page layout widget referencing metadata this export cannot resolve (workflowUniversalIdentifier)',+ );+ });++ it('should report exactly one coverage entry per input row', () => {+ const pageLayouts = [+ buildFlatPageLayout({ pageLayoutManifest: PET_PAGE_MANIFEST }),+ buildFlatPageLayout({+ pageLayoutManifest: ENGINE_PAGE_MANIFEST,+ isSystemSideEffect: true,+ }),+ ];+ const pageLayoutTabs = [+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: OVERVIEW_TAB_MANIFEST,+ pageLayoutUniversalIdentifier: PET_PAGE_UID,+ }),+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: {+ universalIdentifier: EXTRA_TAB_UID,+ title: 'Extra',+ position: 60,+ },+ pageLayoutUniversalIdentifier: ENGINE_PAGE_UID,+ }),+ buildFlatPageLayoutTab({+ pageLayoutTabManifest: {+ universalIdentifier: ENGINE_TAB_UID,+ title: 'Home',+ position: 10,+ },+ pageLayoutUniversalIdentifier: ENGINE_PAGE_UID,+ isSystemSideEffect: true,+ }),+ ];+ const pageLayoutWidgets = [+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: buildNotesWidgetManifest('nested-widget'),+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: buildNotesWidgetManifest('engine-widget'),+ pageLayoutTabUniversalIdentifier: ENGINE_TAB_UID,+ isSystemSideEffect: true,+ }),+ buildFlatPageLayoutWidget({+ pageLayoutWidgetManifest: buildNotesWidgetManifest(+ 'unpositioned-widget',+ ),+ pageLayoutTabUniversalIdentifier: OVERVIEW_TAB_UID,+ position: null,+ }),+ ];+ const rows = [...pageLayouts, ...pageLayoutTabs, ...pageLayoutWidgets];++ const { coverage } = reconstructPageLayoutsManifest({+ applicationAllFlatEntityMaps: buildMaps({+ objects: [petObject],+ pageLayouts,+ pageLayoutTabs,+ pageLayoutWidgets,+ }),+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers: EXPORTED_OBJECT_UNIVERSAL_IDENTIFIERS,+ });++ expect(coverage).toHaveLength(rows.length);+ expect(+ coverage.map(({ universalIdentifier }) => universalIdentifier).sort(),+ ).toEqual(+ rows.map(({ universalIdentifier }) => universalIdentifier).sort(),+ );+ });+});diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/reconstruct-views-manifest.util.spec.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/reconstruct-views-manifest.util.spec.tsindex 5cf5578f710..dba3a513c78 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/reconstruct-views-manifest.util.spec.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/__tests__/reconstruct-views-manifest.util.spec.ts@@ -31,9 +31,7 @@ import { reconstructViewsManifest } from 'src/engine/core-modules/application/apimport { ApplicationExportCoverageStatus } from 'src/engine/core-modules/application/enums/application-export-coverage-status.enum';import { createEmptyAllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/constant/create-empty-all-flat-entity-maps.constant';import { type AllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-maps.type';-import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-from.type';-import { type FlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-maps.type';-import { addFlatEntityToFlatEntityMapsOrThrow } from 'src/engine/metadata-modules/flat-entity/utils/add-flat-entity-to-flat-entity-maps-or-throw.util';+import { addAllFlatEntitiesToFlatEntityMaps } from 'src/engine/core-modules/application/application-manifest/utils/__tests__/add-all-flat-entities-to-flat-entity-maps.test-util';import { getFlatFieldMetadataMock } from 'src/engine/metadata-modules/flat-field-metadata/__mocks__/get-flat-field-metadata.mock';import { type FlatFieldMetadata } from 'src/engine/metadata-modules/flat-field-metadata/types/flat-field-metadata.type';import { getFlatObjectMetadataMock } from 'src/engine/metadata-modules/flat-object-metadata/__mocks__/get-flat-object-metadata.mock';@@ -67,24 +65,6 @@ const OTHER_ALL_PETS_VIEW_UID = '00000000-0000-4000-8000-000000000000';const STANDARD_APP_ID = 'standard-application-id';const EXPORTED_OBJECT_UNIVERSAL_IDENTIFIERS = new Set([PET_UID]);-const addAllFlatEntitiesToFlatEntityMaps = <- TFlatEntity extends SyncableFlatEntity,->({- flatEntities,- flatEntityMaps,-}: {- flatEntities: TFlatEntity[];- flatEntityMaps: FlatEntityMaps<TFlatEntity>;-}): FlatEntityMaps<TFlatEntity> =>- flatEntities.reduce(- (maps, flatEntity) =>- addFlatEntityToFlatEntityMapsOrThrow({- flatEntity,- flatEntityMaps: maps,- }),- flatEntityMaps,- );-const buildMaps = ({objects = [],fields = [],diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/create-view-child-decider.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/create-child-decider.util.tssimilarity index 62%rename from packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/create-view-child-decider.util.tsrename to packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/create-child-decider.util.tsindex cf5cbcfd1f7..01986828c86 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/create-view-child-decider.util.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/create-child-decider.util.ts@@ -2,31 +2,32 @@ import { isDefined } from 'twenty-shared/utils';import { type ApplicationExportCoverageEntry } from 'src/engine/core-modules/application/application-manifest/types/application-export.type';import {- type ParentViewStatus,- type ViewChildMetadataName,-} from 'src/engine/core-modules/application/application-manifest/types/view-export-classification.type';+ type ChildMetadataName,+ type ParentMetadataName,+ type ParentStatus,+} from 'src/engine/core-modules/application/application-manifest/types/export-classification.type';import { buildExportedCoverageEntry } from 'src/engine/core-modules/application/application-manifest/utils/build-exported-coverage-entry.util';-import { getParentViewReason } from 'src/engine/core-modules/application/application-manifest/utils/get-parent-view-reason.util';+import { getParentReason } from 'src/engine/core-modules/application/application-manifest/utils/get-parent-reason.util';import { type WorkspaceLocalStateProperties } from 'src/engine/core-modules/application/application-manifest/utils/get-workspace-local-state-reason.util';import { ApplicationExportCoverageStatus } from 'src/engine/core-modules/application/enums/application-export-coverage-status.enum';-type FlatViewChild = {+export type FlatChild = {universalIdentifier: string;- viewUniversalIdentifier: string;} & Partial<WorkspaceLocalStateProperties>;-export type ViewChildDecision = 'nested' | 'standalone';+export type ChildDecision = 'nested' | 'standalone';-export const createViewChildDecider =- ({+export const createChildDecider =+ <TFlatChild extends FlatChild>({coverage,- parentViewStatusByUniversalIdentifier,+ parentMetadataName,+ parentStatusByUniversalIdentifier,+ getParentUniversalIdentifier,}: {coverage: ApplicationExportCoverageEntry[];- parentViewStatusByUniversalIdentifier: ReadonlyMap<- string,- ParentViewStatus- >;+ parentMetadataName: ParentMetadataName;+ parentStatusByUniversalIdentifier: ReadonlyMap<string, ParentStatus>;+ getParentUniversalIdentifier: (flatEntity: TFlatChild) => string;}) =>({metadataName,@@ -35,12 +36,12 @@ export const createViewChildDecider =unsupportedReason,canStandAlone = false,}: {- metadataName: ViewChildMetadataName;- flatEntity: FlatViewChild;+ metadataName: ChildMetadataName;+ flatEntity: TFlatChild;isEngineDerived?: boolean;unsupportedReason?: string;canStandAlone?: boolean;- }): ViewChildDecision | undefined => {+ }): ChildDecision | undefined => {if (isEngineDerived) {coverage.push({metadataName,@@ -51,20 +52,24 @@ export const createViewChildDecider =return undefined;}- const parentViewStatus =- parentViewStatusByUniversalIdentifier.get(- flatEntity.viewUniversalIdentifier,+ const parentStatus =+ parentStatusByUniversalIdentifier.get(+ getParentUniversalIdentifier(flatEntity),) ?? 'outside';if (- parentViewStatus !== 'exported' &&- (parentViewStatus === 'unsupported' || !canStandAlone)+ parentStatus !== 'exported' &&+ (parentStatus === 'unsupported' || !canStandAlone)) {coverage.push({metadataName,universalIdentifier: flatEntity.universalIdentifier,status: ApplicationExportCoverageStatus.UNSUPPORTED,- reason: getParentViewReason({ metadataName, parentViewStatus }),+ reason: getParentReason({+ metadataName,+ parentMetadataName,+ parentStatus,+ }),});return undefined;@@ -83,5 +88,5 @@ export const createViewChildDecider =coverage.push(buildExportedCoverageEntry({ metadataName, flatEntity }));- return parentViewStatus === 'exported' ? 'nested' : 'standalone';+ return parentStatus === 'exported' ? 'nested' : 'standalone';};diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-parent-reason.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-parent-reason.util.tsnew file mode 100644index 00000000000..9703acd8d15--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-parent-reason.util.ts@@ -0,0 +1,28 @@+import {+ type ChildMetadataName,+ type ParentMetadataName,+ type ParentStatus,+} from 'src/engine/core-modules/application/application-manifest/types/export-classification.type';+import { MANIFEST_ENTITY_REGISTRY } from 'src/engine/core-modules/application/application-manifest/utils/find-manifest-entity-descriptor-by-universal-identifier.util';++export const getParentReason = ({+ metadataName,+ parentMetadataName,+ parentStatus,+}: {+ metadataName: ChildMetadataName;+ parentMetadataName: ParentMetadataName;+ parentStatus: Exclude<ParentStatus, 'exported'>;+}): string => {+ const label = MANIFEST_ENTITY_REGISTRY[metadataName].entityKind;+ const parentLabel = MANIFEST_ENTITY_REGISTRY[parentMetadataName].entityKind;++ switch (parentStatus) {+ case 'unsupported':+ return `${label} of an unsupported ${parentLabel}`;+ case 'engineDerived':+ return `${label} on an engine-derived ${parentLabel}`;+ case 'outside':+ return `${label} on a ${parentLabel} outside the application`;+ }+};diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-parent-view-reason.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-parent-view-reason.util.tsdeleted file mode 100644index 0221b39c1e0..00000000000--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-parent-view-reason.util.ts+++ /dev/null@@ -1,24 +0,0 @@-import { MANIFEST_ENTITY_REGISTRY } from 'src/engine/core-modules/application/application-manifest/utils/find-manifest-entity-descriptor-by-universal-identifier.util';-import {- type ParentViewStatus,- type ViewChildMetadataName,-} from 'src/engine/core-modules/application/application-manifest/types/view-export-classification.type';--export const getParentViewReason = ({- metadataName,- parentViewStatus,-}: {- metadataName: ViewChildMetadataName;- parentViewStatus: Exclude<ParentViewStatus, 'exported'>;-}): string => {- const label = MANIFEST_ENTITY_REGISTRY[metadataName].entityKind;-- switch (parentViewStatus) {- case 'unsupported':- return `${label} of an unsupported view`;- case 'engineDerived':- return `${label} on an engine-derived view`;- case 'outside':- return `${label} on a view outside the application`;- }-};diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unexported-view-field-group-reason.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unexported-view-field-group-reason.util.tsindex 7e07c36d9bb..821a409a060 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unexported-view-field-group-reason.util.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unexported-view-field-group-reason.util.ts@@ -1,6 +1,6 @@import { isDefined } from 'twenty-shared/utils';-import { type ParentViewStatus } from 'src/engine/core-modules/application/application-manifest/types/view-export-classification.type';+import { type ParentStatus } from 'src/engine/core-modules/application/application-manifest/types/export-classification.type';import { type AllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-maps.type';export const getUnexportedViewFieldGroupReason = ({@@ -10,7 +10,7 @@ export const getUnexportedViewFieldGroupReason = ({}: {viewFieldGroupUniversalIdentifier: string | null;applicationAllFlatEntityMaps: AllFlatEntityMaps;- parentViewStatusByUniversalIdentifier: ReadonlyMap<string, ParentViewStatus>;+ parentViewStatusByUniversalIdentifier: ReadonlyMap<string, ParentStatus>;}): string | undefined => {if (!isDefined(viewFieldGroupUniversalIdentifier)) {return undefined;diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unresolvable-field-reason.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unresolvable-field-reason.util.tsindex 1791de42a5e..8d1c5cfb640 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unresolvable-field-reason.util.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unresolvable-field-reason.util.ts@@ -1,7 +1,7 @@import { isDefined } from 'twenty-shared/utils';import { MANIFEST_ENTITY_REGISTRY } from 'src/engine/core-modules/application/application-manifest/utils/find-manifest-entity-descriptor-by-universal-identifier.util';-import { type ViewChildMetadataName } from 'src/engine/core-modules/application/application-manifest/types/view-export-classification.type';+import { type ChildMetadataName } from 'src/engine/core-modules/application/application-manifest/types/export-classification.type';import { type AllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-maps.type';export const getUnresolvableFieldReason = ({@@ -9,7 +9,7 @@ export const getUnresolvableFieldReason = ({fieldMetadataUniversalIdentifier,allFlatEntityMaps,}: {- metadataName: ViewChildMetadataName;+ metadataName: ChildMetadataName;fieldMetadataUniversalIdentifier: string;allFlatEntityMaps: AllFlatEntityMaps;}): string | undefined =>diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unresolvable-object-reason.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unresolvable-object-reason.util.tsnew file mode 100644index 00000000000..a5c034d0990--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unresolvable-object-reason.util.ts@@ -0,0 +1,48 @@+import { type AllMetadataName } from 'twenty-shared/metadata';+import { isDefined } from 'twenty-shared/utils';++import { MANIFEST_ENTITY_REGISTRY } from 'src/engine/core-modules/application/application-manifest/utils/find-manifest-entity-descriptor-by-universal-identifier.util';+import { type AllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-maps.type';++export const getUnresolvableObjectReason = ({+ metadataName,+ objectUniversalIdentifier,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,+}: {+ metadataName: AllMetadataName;+ objectUniversalIdentifier: string | null;+ applicationAllFlatEntityMaps: AllFlatEntityMaps;+ allFlatEntityMaps: AllFlatEntityMaps;+ exportedObjectUniversalIdentifiers: ReadonlySet<string>;+}): string | undefined => {+ if (!isDefined(objectUniversalIdentifier)) {+ return undefined;+ }++ const label = MANIFEST_ENTITY_REGISTRY[metadataName].entityKind;++ if (+ isDefined(+ applicationAllFlatEntityMaps.flatObjectMetadataMaps.byUniversalIdentifier[+ objectUniversalIdentifier+ ],+ ) &&+ !exportedObjectUniversalIdentifiers.has(objectUniversalIdentifier)+ ) {+ return `${label} on an unsupported object`;+ }++ if (+ !isDefined(+ allFlatEntityMaps.flatObjectMetadataMaps.byUniversalIdentifier[+ objectUniversalIdentifier+ ],+ )+ ) {+ return `${label} on an object that does not exist`;+ }++ return undefined;+};diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unsupported-page-layout-reason.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unsupported-page-layout-reason.util.tsnew file mode 100644index 00000000000..04d4f604d37--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unsupported-page-layout-reason.util.ts@@ -0,0 +1,55 @@+import { isNonEmptyString } from '@sniptt/guards';+import { isDefined } from 'twenty-shared/utils';++import { getUnresolvableObjectReason } from 'src/engine/core-modules/application/application-manifest/utils/get-unresolvable-object-reason.util';+import { type AllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-maps.type';+import { type FlatPageLayout } from 'src/engine/metadata-modules/flat-page-layout/types/flat-page-layout.type';++export const getUnsupportedPageLayoutReason = ({+ flatPageLayout,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,+}: {+ flatPageLayout: FlatPageLayout;+ applicationAllFlatEntityMaps: AllFlatEntityMaps;+ allFlatEntityMaps: AllFlatEntityMaps;+ exportedObjectUniversalIdentifiers: ReadonlySet<string>;+}): string | undefined => {+ if (!isNonEmptyString(flatPageLayout.name)) {+ return 'page layout without a name';+ }++ const unresolvableObjectReason = getUnresolvableObjectReason({+ metadataName: 'pageLayout',+ objectUniversalIdentifier: flatPageLayout.objectMetadataUniversalIdentifier,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,+ });++ if (isDefined(unresolvableObjectReason)) {+ return unresolvableObjectReason;+ }++ const defaultTabUniversalIdentifier =+ flatPageLayout.defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier;++ if (isDefined(defaultTabUniversalIdentifier)) {+ const defaultTab =+ applicationAllFlatEntityMaps.flatPageLayoutTabMaps.byUniversalIdentifier[+ defaultTabUniversalIdentifier+ ];++ if (+ !isDefined(defaultTab) ||+ defaultTab.isSystemSideEffect ||+ defaultTab.pageLayoutUniversalIdentifier !==+ flatPageLayout.universalIdentifier+ ) {+ return 'page layout whose default tab is not exported';+ }+ }++ return undefined;+};diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unsupported-page-layout-widget-reason.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unsupported-page-layout-widget-reason.util.tsnew file mode 100644index 00000000000..23a0bea7a96--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unsupported-page-layout-widget-reason.util.ts@@ -0,0 +1,224 @@+import { WidgetType } from 'twenty-shared/types';+import { isDefined } from 'twenty-shared/utils';++import { MANIFEST_ENTITY_REGISTRY } from 'src/engine/core-modules/application/application-manifest/utils/find-manifest-entity-descriptor-by-universal-identifier.util';+import { getUnresolvableObjectReason } from 'src/engine/core-modules/application/application-manifest/utils/get-unresolvable-object-reason.util';+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';++type ReferencedMetadataName =+ | 'fieldMetadata'+ | 'view'+ | 'frontComponent'+ | 'commandMenuItem';++const UNIVERSAL_IDENTIFIER_KEY_PATTERN = /UniversalIdentifiers?$/;++const NULLABLE_REFERENCE_KEYS = new Set([+ 'viewId',+ 'viewUniversalIdentifier',+ 'nestedRelationFieldMetadataId',+ 'secondaryAxisGroupByFieldMetadataUniversalIdentifier',+ 'relationTargetFieldMetadataUniversalIdentifier',+]);++const NOT_EXPORTED_YET_METADATA_NAMES: ReferencedMetadataName[] = [+ 'frontComponent',+ 'commandMenuItem',+];++const getReferencedMetadataName = (+ key: string,+): ReferencedMetadataName | 'unknown' | undefined => {+ if (+ key === 'fieldMetadataId' ||+ key === 'nestedRelationFieldMetadataId' ||+ key === 'fieldMetadataUniversalIdentifier' ||+ key.endsWith('FieldMetadataUniversalIdentifier')+ ) {+ return 'fieldMetadata';+ }++ if (key === 'viewId' || key === 'viewUniversalIdentifier') {+ return 'view';+ }++ if (key === 'frontComponentUniversalIdentifier') {+ return 'frontComponent';+ }++ if (key === 'headerCommandMenuItemUniversalIdentifiers') {+ return 'commandMenuItem';+ }++ return UNIVERSAL_IDENTIFIER_KEY_PATTERN.test(key) ? 'unknown' : undefined;+};++const getFlatEntityMaps = ({+ metadataName,+ allFlatEntityMaps,+}: {+ metadataName: ReferencedMetadataName;+ allFlatEntityMaps: AllFlatEntityMaps;+}) => {+ switch (metadataName) {+ case 'fieldMetadata':+ return allFlatEntityMaps.flatFieldMetadataMaps;+ case 'view':+ return allFlatEntityMaps.flatViewMaps;+ case 'frontComponent':+ return allFlatEntityMaps.flatFrontComponentMaps;+ case 'commandMenuItem':+ return allFlatEntityMaps.flatCommandMenuItemMaps;+ }+};++const getUnresolvableReferenceReason = ({+ key,+ metadataName,+ universalIdentifier,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+}: {+ key: string;+ metadataName: ReferencedMetadataName;+ universalIdentifier: unknown;+ applicationAllFlatEntityMaps: AllFlatEntityMaps;+ allFlatEntityMaps: AllFlatEntityMaps;+}): string | undefined => {+ const label = MANIFEST_ENTITY_REGISTRY[metadataName].entityKind;++ if (!isDefined(universalIdentifier)) {+ return NULLABLE_REFERENCE_KEYS.has(key)+ ? undefined+ : `page layout widget referencing a ${label} that does not exist`;+ }++ if (typeof universalIdentifier !== 'string') {+ return undefined;+ }++ if (+ NOT_EXPORTED_YET_METADATA_NAMES.includes(metadataName) &&+ isDefined(+ getFlatEntityMaps({+ metadataName,+ allFlatEntityMaps: applicationAllFlatEntityMaps,+ }).byUniversalIdentifier[universalIdentifier],+ )+ ) {+ return `page layout widget referencing a ${label} that is not exported yet`;+ }++ return isDefined(+ getFlatEntityMaps({ metadataName, allFlatEntityMaps })+ .byUniversalIdentifier[universalIdentifier],+ )+ ? undefined+ : `page layout widget referencing a ${label} that does not exist`;+};++const findUnresolvableReferenceReason = ({+ value,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+}: {+ value: unknown;+ applicationAllFlatEntityMaps: AllFlatEntityMaps;+ allFlatEntityMaps: AllFlatEntityMaps;+}): string | undefined => {+ if (!isDefined(value) || typeof value !== 'object') {+ return undefined;+ }++ for (const [key, child] of Object.entries(value)) {+ const metadataName = getReferencedMetadataName(key);++ if (!isDefined(metadataName)) {+ const nestedReason = findUnresolvableReferenceReason({+ value: child,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ });++ if (isDefined(nestedReason)) {+ return nestedReason;+ }++ continue;+ }++ if (metadataName === 'unknown') {+ return `page layout widget referencing metadata this export cannot resolve (${key})`;+ }++ for (const universalIdentifier of Array.isArray(child) ? child : [child]) {+ const reason = getUnresolvableReferenceReason({+ key,+ metadataName,+ universalIdentifier,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ });++ if (isDefined(reason)) {+ return reason;+ }+ }+ }++ return undefined;+};++export const getUnsupportedPageLayoutWidgetReason = ({+ flatPageLayoutWidget,+ flatPageLayoutTab,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,+}: {+ flatPageLayoutWidget: FlatPageLayoutWidget;+ flatPageLayoutTab: FlatPageLayoutTab | undefined;+ applicationAllFlatEntityMaps: AllFlatEntityMaps;+ allFlatEntityMaps: AllFlatEntityMaps;+ exportedObjectUniversalIdentifiers: ReadonlySet<string>;+}): string | undefined => {+ if (flatPageLayoutWidget.type === WidgetType.VIEW) {+ return 'page layout widget of the VIEW type, which the sync does not support yet';+ }++ if (!isDefined(flatPageLayoutWidget.position)) {+ return 'page layout widget without a position';+ }++ if (+ isDefined(flatPageLayoutTab) &&+ flatPageLayoutWidget.position.layoutMode !== flatPageLayoutTab.layoutMode+ ) {+ return 'page layout widget positioned for another layout mode than its tab';+ }++ if (isDefined(flatPageLayoutWidget.conditionalAvailabilityExpression)) {+ return 'page layout widget with a conditional availability expression';+ }++ const unresolvableObjectReason = getUnresolvableObjectReason({+ metadataName: 'pageLayoutWidget',+ objectUniversalIdentifier:+ flatPageLayoutWidget.objectMetadataUniversalIdentifier,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,+ });++ if (isDefined(unresolvableObjectReason)) {+ return unresolvableObjectReason;+ }++ return findUnresolvableReferenceReason({+ value: flatPageLayoutWidget.universalConfiguration,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ });+};diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unsupported-view-reason.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unsupported-view-reason.util.tsindex 29da17de3ba..8cf652827ed 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unsupported-view-reason.util.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/get-unsupported-view-reason.util.ts@@ -1,6 +1,7 @@import { isNonEmptyString } from '@sniptt/guards';import { isDefined } from 'twenty-shared/utils';+import { getUnresolvableObjectReason } from 'src/engine/core-modules/application/application-manifest/utils/get-unresolvable-object-reason.util';import { type AllFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/types/all-flat-entity-maps.type';import { type FlatView } from 'src/engine/metadata-modules/flat-view/types/flat-view.type';@@ -13,26 +14,29 @@ const VIEW_FIELD_REFERENCE_PROPERTIES = [export const getUnsupportedViewReason = ({flatView,- applicationObjectUniversalIdentifiers,- exportedObjectUniversalIdentifiers,+ applicationAllFlatEntityMaps,allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,}: {flatView: FlatView;- applicationObjectUniversalIdentifiers: ReadonlySet<string>;- exportedObjectUniversalIdentifiers: ReadonlySet<string>;+ applicationAllFlatEntityMaps: AllFlatEntityMaps;allFlatEntityMaps: AllFlatEntityMaps;+ exportedObjectUniversalIdentifiers: ReadonlySet<string>;}): string | undefined => {if (!isNonEmptyString(flatView.name)) {return 'view without a name';}- const objectUniversalIdentifier = flatView.objectMetadataUniversalIdentifier;+ const unresolvableObjectReason = getUnresolvableObjectReason({+ metadataName: 'view',+ objectUniversalIdentifier: flatView.objectMetadataUniversalIdentifier,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,+ });- if (- applicationObjectUniversalIdentifiers.has(objectUniversalIdentifier) &&- !exportedObjectUniversalIdentifiers.has(objectUniversalIdentifier)- ) {- return 'view on an unsupported object';+ if (isDefined(unresolvableObjectReason)) {+ return unresolvableObjectReason;}const referencesMissingField = VIEW_FIELD_REFERENCE_PROPERTIES.some(diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-data-model-manifest.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-data-model-manifest.util.tsindex 7546bd14c63..584d0da73ef 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-data-model-manifest.util.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-data-model-manifest.util.ts@@ -11,7 +11,7 @@ import { fromFlatIndexMetadataToIndexManifest } from 'src/engine/core-modules/apimport { fromFlatObjectMetadataToObjectManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-object-metadata-to-object-manifest.util';import { type ApplicationExportCoverageEntry } from 'src/engine/core-modules/application/application-manifest/types/application-export.type';import { buildExportedCoverageEntry } from 'src/engine/core-modules/application/application-manifest/utils/build-exported-coverage-entry.util';-import { compareByUniversalIdentifier } from 'src/engine/core-modules/application/application-manifest/utils/compare-by-universal-identifier.util';+import { sortFlatEntitiesByUniversalIdentifier } from 'src/engine/core-modules/application/application-manifest/utils/sort-flat-entities-by-universal-identifier.util';import { getUnsupportedRelationFieldReason } from 'src/engine/core-modules/application/application-manifest/utils/get-unsupported-relation-field-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';@@ -90,11 +90,9 @@ export const reconstructDataModelManifest = ({applicationAllFlatEntityMaps;const coverage: ApplicationExportCoverageEntry[] = [];- const flatObjectMetadatas = Object.values(- flatObjectMetadataMaps.byUniversalIdentifier,- )- .filter(isDefined)- .sort(compareByUniversalIdentifier);+ const flatObjectMetadatas = sortFlatEntitiesByUniversalIdentifier(+ flatObjectMetadataMaps,+ );const exportableObjects = flatObjectMetadatas.flatMap((flatObjectMetadata) => {const labelIdentifierFieldMetadataUniversalIdentifier =@@ -130,11 +128,9 @@ export const reconstructDataModelManifest = ({const fieldManifestByUniversalIdentifier = new Map<string, FieldManifest>();- for (const flatFieldMetadata of Object.values(- flatFieldMetadataMaps.byUniversalIdentifier,- )- .filter(isDefined)- .sort(compareByUniversalIdentifier)) {+ for (const flatFieldMetadata of sortFlatEntitiesByUniversalIdentifier(+ flatFieldMetadataMaps,+ )) {const flatObjectMetadata =flatObjectMetadataMaps.byUniversalIdentifier[flatFieldMetadata.objectMetadataUniversalIdentifier@@ -231,11 +227,9 @@ export const reconstructDataModelManifest = ({const indexes: IndexManifest[] = [];- for (const flatIndexMetadata of Object.values(- flatIndexMaps.byUniversalIdentifier,- )- .filter(isDefined)- .sort(compareByUniversalIdentifier)) {+ for (const flatIndexMetadata of sortFlatEntitiesByUniversalIdentifier(+ flatIndexMaps,+ )) {if (flatIndexMetadata.isSystemSideEffect) {coverage.push({metadataName: 'index',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.tsnew file mode 100644index 00000000000..b2fc5eb02b0--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-page-layouts-manifest.util.ts@@ -0,0 +1,235 @@+import {+ type PageLayoutManifest,+ type PageLayoutTabManifest,+ type PageLayoutWidgetManifest,+} from 'twenty-shared/application';+import { isDefined } from 'twenty-shared/utils';++import { fromFlatPageLayoutTabToPageLayoutTabManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-page-layout-tab-manifest.util';+import { fromFlatPageLayoutTabToStandalonePageLayoutTabManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-tab-to-standalone-page-layout-tab-manifest.util';+import { fromFlatPageLayoutToPageLayoutManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-to-page-layout-manifest.util';+import { fromFlatPageLayoutWidgetToPageLayoutWidgetManifest } from 'src/engine/core-modules/application/application-manifest/converters/from-flat-page-layout-widget-to-page-layout-widget-manifest.util';+import { type ApplicationExportCoverageEntry } from 'src/engine/core-modules/application/application-manifest/types/application-export.type';+import { type ParentStatus } from 'src/engine/core-modules/application/application-manifest/types/export-classification.type';+import { buildExportedCoverageEntry } from 'src/engine/core-modules/application/application-manifest/utils/build-exported-coverage-entry.util';+import { sortFlatEntitiesByUniversalIdentifier } from 'src/engine/core-modules/application/application-manifest/utils/sort-flat-entities-by-universal-identifier.util';+import {+ createChildDecider,+ type FlatChild,+} from 'src/engine/core-modules/application/application-manifest/utils/create-child-decider.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 FlatPageLayout } from 'src/engine/metadata-modules/flat-page-layout/types/flat-page-layout.type';++type FlatPageLayoutChild = FlatChild & {+ pageLayoutUniversalIdentifier: string;+};+type FlatPageLayoutTabChild = FlatChild & {+ pageLayoutTabUniversalIdentifier: string;+};++export const reconstructPageLayoutsManifest = ({+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,+}: {+ applicationAllFlatEntityMaps: AllFlatEntityMaps;+ allFlatEntityMaps: AllFlatEntityMaps;+ exportedObjectUniversalIdentifiers: Set<string>;+}): {+ pageLayouts: PageLayoutManifest[];+ pageLayoutTabs: PageLayoutTabManifest[];+ coverage: ApplicationExportCoverageEntry[];+} => {+ const coverage: ApplicationExportCoverageEntry[] = [];+ const pageLayoutStatusByUniversalIdentifier = new Map<string, ParentStatus>();+ const exportedFlatPageLayouts: FlatPageLayout[] = [];++ for (const flatPageLayout of sortFlatEntitiesByUniversalIdentifier(+ applicationAllFlatEntityMaps.flatPageLayoutMaps,+ )) {+ if (flatPageLayout.isSystemSideEffect) {+ coverage.push({+ metadataName: 'pageLayout',+ universalIdentifier: flatPageLayout.universalIdentifier,+ status: ApplicationExportCoverageStatus.ENGINE_DERIVED,+ });+ pageLayoutStatusByUniversalIdentifier.set(+ flatPageLayout.universalIdentifier,+ 'engineDerived',+ );+ continue;+ }++ const unsupportedReason = getUnsupportedPageLayoutReason({+ flatPageLayout,+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,+ });++ if (isDefined(unsupportedReason)) {+ coverage.push({+ metadataName: 'pageLayout',+ universalIdentifier: flatPageLayout.universalIdentifier,+ status: ApplicationExportCoverageStatus.UNSUPPORTED,+ reason: unsupportedReason,+ });+ pageLayoutStatusByUniversalIdentifier.set(+ flatPageLayout.universalIdentifier,+ 'unsupported',+ );+ continue;+ }++ exportedFlatPageLayouts.push(flatPageLayout);+ pageLayoutStatusByUniversalIdentifier.set(+ flatPageLayout.universalIdentifier,+ 'exported',+ );+ }++ const decidePageLayoutTab = createChildDecider<FlatPageLayoutChild>({+ coverage,+ parentMetadataName: 'pageLayout',+ parentStatusByUniversalIdentifier: pageLayoutStatusByUniversalIdentifier,+ getParentUniversalIdentifier: ({ pageLayoutUniversalIdentifier }) =>+ pageLayoutUniversalIdentifier,+ });+ const pageLayoutTabStatusByUniversalIdentifier = new Map<+ string,+ ParentStatus+ >();+ const nestedFlatPageLayoutTabs: FlatPageLayoutTab[] = [];+ const standaloneFlatPageLayoutTabs: FlatPageLayoutTab[] = [];++ for (const flatPageLayoutTab of sortFlatEntitiesByUniversalIdentifier(+ applicationAllFlatEntityMaps.flatPageLayoutTabMaps,+ )) {+ const decision = decidePageLayoutTab({+ metadataName: 'pageLayoutTab',+ flatEntity: flatPageLayoutTab,+ isEngineDerived: flatPageLayoutTab.isSystemSideEffect,+ canStandAlone: true,+ });++ if (decision === 'nested') {+ nestedFlatPageLayoutTabs.push(flatPageLayoutTab);+ } else if (decision === 'standalone') {+ standaloneFlatPageLayoutTabs.push(flatPageLayoutTab);+ }++ pageLayoutTabStatusByUniversalIdentifier.set(+ flatPageLayoutTab.universalIdentifier,+ isDefined(decision)+ ? 'exported'+ : flatPageLayoutTab.isSystemSideEffect+ ? 'engineDerived'+ : 'unsupported',+ );+ }++ const decidePageLayoutWidget = createChildDecider<FlatPageLayoutTabChild>({+ coverage,+ parentMetadataName: 'pageLayoutTab',+ parentStatusByUniversalIdentifier: pageLayoutTabStatusByUniversalIdentifier,+ getParentUniversalIdentifier: ({ pageLayoutTabUniversalIdentifier }) =>+ pageLayoutTabUniversalIdentifier,+ });+ const widgetsByPageLayoutTabUniversalIdentifier = new Map<+ string,+ PageLayoutWidgetManifest[]+ >();++ for (const flatPageLayoutWidget of sortFlatEntitiesByUniversalIdentifier(+ applicationAllFlatEntityMaps.flatPageLayoutWidgetMaps,+ )) {+ if (+ decidePageLayoutWidget({+ metadataName: 'pageLayoutWidget',+ flatEntity: flatPageLayoutWidget,+ isEngineDerived: flatPageLayoutWidget.isSystemSideEffect,+ unsupportedReason: getUnsupportedPageLayoutWidgetReason({+ flatPageLayoutWidget,+ flatPageLayoutTab:+ applicationAllFlatEntityMaps.flatPageLayoutTabMaps+ .byUniversalIdentifier[+ flatPageLayoutWidget.pageLayoutTabUniversalIdentifier+ ],+ applicationAllFlatEntityMaps,+ allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,+ }),+ }) === 'nested'+ ) {+ const widgets =+ widgetsByPageLayoutTabUniversalIdentifier.get(+ flatPageLayoutWidget.pageLayoutTabUniversalIdentifier,+ ) ?? [];++ widgets.push(+ fromFlatPageLayoutWidgetToPageLayoutWidgetManifest({+ flatPageLayoutWidget,+ }),+ );+ widgetsByPageLayoutTabUniversalIdentifier.set(+ flatPageLayoutWidget.pageLayoutTabUniversalIdentifier,+ widgets,+ );+ }+ }++ const tabsByPageLayoutUniversalIdentifier = new Map<+ string,+ PageLayoutTabManifest[]+ >();++ for (const flatPageLayoutTab of nestedFlatPageLayoutTabs) {+ const tabs =+ tabsByPageLayoutUniversalIdentifier.get(+ flatPageLayoutTab.pageLayoutUniversalIdentifier,+ ) ?? [];++ tabs.push(+ fromFlatPageLayoutTabToPageLayoutTabManifest({+ flatPageLayoutTab,+ widgets: widgetsByPageLayoutTabUniversalIdentifier.get(+ flatPageLayoutTab.universalIdentifier,+ ),+ }),+ );+ tabsByPageLayoutUniversalIdentifier.set(+ flatPageLayoutTab.pageLayoutUniversalIdentifier,+ tabs,+ );+ }++ const pageLayouts = exportedFlatPageLayouts.map((flatPageLayout) => {+ coverage.push(+ buildExportedCoverageEntry({+ metadataName: 'pageLayout',+ flatEntity: flatPageLayout,+ }),+ );++ return fromFlatPageLayoutToPageLayoutManifest({+ flatPageLayout,+ tabs: tabsByPageLayoutUniversalIdentifier.get(+ flatPageLayout.universalIdentifier,+ ),+ });+ });+ const pageLayoutTabs = standaloneFlatPageLayoutTabs.map((flatPageLayoutTab) =>+ fromFlatPageLayoutTabToStandalonePageLayoutTabManifest({+ flatPageLayoutTab,+ widgets: widgetsByPageLayoutTabUniversalIdentifier.get(+ flatPageLayoutTab.universalIdentifier,+ ),+ }),+ );++ return { pageLayouts, pageLayoutTabs, coverage };+};diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-views-manifest.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-views-manifest.util.tsindex 5b9f6865fed..204b524dee4 100644--- a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-views-manifest.util.ts+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/reconstruct-views-manifest.util.ts@@ -16,28 +16,25 @@ import {type ViewChildrenManifests,} from 'src/engine/core-modules/application/application-manifest/converters/from-flat-view-to-view-manifest.util';import { type ApplicationExportCoverageEntry } from 'src/engine/core-modules/application/application-manifest/types/application-export.type';-import { type ParentViewStatus } from 'src/engine/core-modules/application/application-manifest/types/view-export-classification.type';+import { type ParentStatus } from 'src/engine/core-modules/application/application-manifest/types/export-classification.type';import { buildExportedCoverageEntry } from 'src/engine/core-modules/application/application-manifest/utils/build-exported-coverage-entry.util';import { compareByUniversalIdentifier } from 'src/engine/core-modules/application/application-manifest/utils/compare-by-universal-identifier.util';-import { createViewChildDecider } from 'src/engine/core-modules/application/application-manifest/utils/create-view-child-decider.util';+import { sortFlatEntitiesByUniversalIdentifier } from 'src/engine/core-modules/application/application-manifest/utils/sort-flat-entities-by-universal-identifier.util';+import {+ createChildDecider,+ type FlatChild,+} from 'src/engine/core-modules/application/application-manifest/utils/create-child-decider.util';import { getUnexportedViewFieldGroupReason } from 'src/engine/core-modules/application/application-manifest/utils/get-unexported-view-field-group-reason.util';import { getUnresolvableFieldReason } from 'src/engine/core-modules/application/application-manifest/utils/get-unresolvable-field-reason.util';import { getUnsupportedViewFilterReason } from 'src/engine/core-modules/application/application-manifest/utils/get-unsupported-view-filter-reason.util';import { getUnsupportedViewReason } from 'src/engine/core-modules/application/application-manifest/utils/get-unsupported-view-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 SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-from.type';import { type FlatView } from 'src/engine/metadata-modules/flat-view/types/flat-view.type';-import { type UniversalFlatEntityMaps } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-entity-maps.type';type ViewChildren = Required<ViewChildrenManifests>;-const sortedFlatEntities = <TFlatEntity extends SyncableFlatEntity>(- flatEntityMaps: UniversalFlatEntityMaps<TFlatEntity>,-): TFlatEntity[] =>- Object.values(flatEntityMaps.byUniversalIdentifier)- .filter(isDefined)- .sort(compareByUniversalIdentifier);+type FlatViewChild = FlatChild & { viewUniversalIdentifier: string };export const reconstructViewsManifest = ({applicationAllFlatEntityMaps,@@ -53,21 +50,10 @@ export const reconstructViewsManifest = ({coverage: ApplicationExportCoverageEntry[];} => {const coverage: ApplicationExportCoverageEntry[] = [];- const applicationObjectUniversalIdentifiers = new Set(- Object.values(- applicationAllFlatEntityMaps.flatObjectMetadataMaps.byUniversalIdentifier,- )- .filter(isDefined)- .map(({ universalIdentifier }) => universalIdentifier),- );-- const parentViewStatusByUniversalIdentifier = new Map<- string,- ParentViewStatus- >();+ const parentViewStatusByUniversalIdentifier = new Map<string, ParentStatus>();const exportedFlatViews: FlatView[] = [];- for (const flatView of sortedFlatEntities(+ for (const flatView of sortFlatEntitiesByUniversalIdentifier(applicationAllFlatEntityMaps.flatViewMaps,)) {if (flatView.isSystemSideEffect) {@@ -85,9 +71,9 @@ export const reconstructViewsManifest = ({const unsupportedReason = getUnsupportedViewReason({flatView,- applicationObjectUniversalIdentifiers,- exportedObjectUniversalIdentifiers,+ applicationAllFlatEntityMaps,allFlatEntityMaps,+ exportedObjectUniversalIdentifiers,});if (isDefined(unsupportedReason)) {@@ -125,16 +111,19 @@ export const reconstructViewsManifest = ({]),);const viewFields: StandaloneViewFieldManifest[] = [];- const decideViewChild = createViewChildDecider({+ const decideViewChild = createChildDecider<FlatViewChild>({coverage,- parentViewStatusByUniversalIdentifier,+ parentMetadataName: 'view',+ parentStatusByUniversalIdentifier: parentViewStatusByUniversalIdentifier,+ getParentUniversalIdentifier: ({ viewUniversalIdentifier }) =>+ viewUniversalIdentifier,});const childrenOf = (viewUniversalIdentifier: string,): ViewChildren | undefined =>childrenByViewUniversalIdentifier.get(viewUniversalIdentifier);- for (const flatViewField of sortedFlatEntities(+ for (const flatViewField of sortFlatEntitiesByUniversalIdentifier(applicationAllFlatEntityMaps.flatViewFieldMaps,)) {const decision = decideViewChild({@@ -168,7 +157,7 @@ export const reconstructViewsManifest = ({}}- for (const flatViewFieldGroup of sortedFlatEntities(+ for (const flatViewFieldGroup of sortFlatEntitiesByUniversalIdentifier(applicationAllFlatEntityMaps.flatViewFieldGroupMaps,)) {if (@@ -184,7 +173,7 @@ export const reconstructViewsManifest = ({}}- for (const flatViewFilterGroup of sortedFlatEntities(+ for (const flatViewFilterGroup of sortFlatEntitiesByUniversalIdentifier(applicationAllFlatEntityMaps.flatViewFilterGroupMaps,)) {if (@@ -203,7 +192,7 @@ export const reconstructViewsManifest = ({}}- for (const flatViewFilter of sortedFlatEntities(+ for (const flatViewFilter of sortFlatEntitiesByUniversalIdentifier(applicationAllFlatEntityMaps.flatViewFilterMaps,)) {if (@@ -222,7 +211,7 @@ export const reconstructViewsManifest = ({}}- for (const flatViewGroup of sortedFlatEntities(+ for (const flatViewGroup of sortFlatEntitiesByUniversalIdentifier(applicationAllFlatEntityMaps.flatViewGroupMaps,)) {if (@@ -237,7 +226,7 @@ export const reconstructViewsManifest = ({}}- for (const flatViewSort of sortedFlatEntities(+ for (const flatViewSort of sortFlatEntitiesByUniversalIdentifier(applicationAllFlatEntityMaps.flatViewSortMaps,)) {if (diff --git a/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/sort-flat-entities-by-universal-identifier.util.ts b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/sort-flat-entities-by-universal-identifier.util.tsnew file mode 100644index 00000000000..b938c3ccbab--- /dev/null+++ b/packages/twenty-server/src/engine/core-modules/application/application-manifest/utils/sort-flat-entities-by-universal-identifier.util.ts@@ -0,0 +1,14 @@+import { isDefined } from 'twenty-shared/utils';++import { compareByUniversalIdentifier } from 'src/engine/core-modules/application/application-manifest/utils/compare-by-universal-identifier.util';+import { type SyncableFlatEntity } from 'src/engine/metadata-modules/flat-entity/types/flat-entity-from.type';+import { type UniversalFlatEntityMaps } from 'src/engine/workspace-manager/workspace-migration/universal-flat-entity/types/universal-flat-entity-maps.type';++export const sortFlatEntitiesByUniversalIdentifier = <+ TFlatEntity extends SyncableFlatEntity,+>(+ flatEntityMaps: UniversalFlatEntityMaps<TFlatEntity>,+): TFlatEntity[] =>+ Object.values(flatEntityMaps.byUniversalIdentifier)+ .filter(isDefined)+ .sort(compareByUniversalIdentifier);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.snapindex edc7f500525..228dd7211db 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@@ -262,6 +262,18 @@ exports[`Application export - data model exports the whole application as a stab"status": "ENGINE_DERIVED","universalIdentifier": "<PROJECT_RECORD_PAGE_LAYOUT>",},+ {+ "metadataName": "pageLayout",+ "reason": null,+ "status": "EXPORTED",+ "universalIdentifier": "<TICKET_BOARD_LAYOUT>",+ },+ {+ "metadataName": "pageLayout",+ "reason": null,+ "status": "EXPORTED",+ "universalIdentifier": "<TICKET_PAGE_LAYOUT>",+ },{"metadataName": "pageLayout","reason": null,@@ -310,12 +322,36 @@ exports[`Application export - data model exports the whole application as a stab"status": "ENGINE_DERIVED","universalIdentifier": "<PROJECT_RECORD_PAGE_TAB_Timeline>",},+ {+ "metadataName": "pageLayoutTab",+ "reason": null,+ "status": "EXPORTED",+ "universalIdentifier": "<STANDARD_COMPANY_RECORD_PAGE_TAGLINE_TAB>",+ },+ {+ "metadataName": "pageLayoutTab",+ "reason": null,+ "status": "EXPORTED",+ "universalIdentifier": "<TICKET_BOARD_TAB>",+ },+ {+ "metadataName": "pageLayoutTab",+ "reason": null,+ "status": "EXPORTED",+ "universalIdentifier": "<TICKET_PAGE_OVERVIEW_TAB>",+ },{"metadataName": "pageLayoutTab","reason": null,"status": "ENGINE_DERIVED","universalIdentifier": "<TICKET_RECORD_FORM_TAB>",},+ {+ "metadataName": "pageLayoutTab",+ "reason": null,+ "status": "EXPORTED",+ "universalIdentifier": "<TICKET_RECORD_PAGE_EXTRA_TAB>",+ },{"metadataName": "pageLayoutTab","reason": null,@@ -382,6 +418,18 @@ exports[`Application export - data model exports the whole application as a stab"status": "ENGINE_DERIVED","universalIdentifier": "<STANDARD_COMPANY_RECORD_FORM_WIDGET_tagline>",},+ {+ "metadataName": "pageLayoutWidget",+ "reason": null,+ "status": "EXPORTED",+ "universalIdentifier": "<TICKET_BOARD_DOCS_WIDGET>",+ },+ {+ "metadataName": "pageLayoutWidget",+ "reason": null,+ "status": "EXPORTED",+ "universalIdentifier": "<TICKET_PAGE_FIELDS_WIDGET>",+ },{"metadataName": "pageLayoutWidget","reason": null,@@ -394,6 +442,12 @@ exports[`Application export - data model exports the whole application as a stab"status": "ENGINE_DERIVED","universalIdentifier": "<TICKET_RECORD_FORM_WIDGET_title>",},+ {+ "metadataName": "pageLayoutWidget",+ "reason": null,+ "status": "EXPORTED",+ "universalIdentifier": "<TICKET_RECORD_PAGE_EXTRA_NOTES_WIDGET>",+ },{"metadataName": "pageLayoutWidget","reason": null,@@ -817,8 +871,103 @@ exports[`Application export - data model exports the whole application as a stab"writability": "OPEN",},],- "pageLayoutTabs": [],- "pageLayouts": [],+ "pageLayoutTabs": [+ {+ "layoutMode": "VERTICAL_LIST",+ "pageLayoutUniversalIdentifier": "<TICKET_RECORD_PAGE_LAYOUT>",+ "position": 60,+ "title": "Extra",+ "universalIdentifier": "<TICKET_RECORD_PAGE_EXTRA_TAB>",+ "widgets": [+ {+ "configuration": {+ "configurationType": "NOTES",+ },+ "objectUniversalIdentifier": "<TICKET_OBJECT>",+ "position": {+ "index": 0,+ "layoutMode": "VERTICAL_LIST",+ },+ "title": "Notes",+ "type": "NOTES",+ "universalIdentifier": "<TICKET_RECORD_PAGE_EXTRA_NOTES_WIDGET>",+ },+ ],+ },+ {+ "layoutMode": "VERTICAL_LIST",+ "pageLayoutUniversalIdentifier": "<STANDARD_COMPANY_RECORD_PAGE_LAYOUT>",+ "position": 60,+ "title": "Tagline",+ "universalIdentifier": "<STANDARD_COMPANY_RECORD_PAGE_TAGLINE_TAB>",+ },+ ],+ "pageLayouts": [+ {+ "defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier": "<TICKET_PAGE_OVERVIEW_TAB>",+ "name": "Ticket page",+ "objectUniversalIdentifier": "<TICKET_OBJECT>",+ "tabs": [+ {+ "icon": "IconHome",+ "layoutMode": "VERTICAL_LIST",+ "position": 0,+ "title": "Overview",+ "universalIdentifier": "<TICKET_PAGE_OVERVIEW_TAB>",+ "widgets": [+ {+ "configuration": {+ "configurationType": "FIELDS",+ "newFieldDefaultVisibility": true,+ "viewUniversalIdentifier": "<OPEN_TICKETS_VIEW>",+ },+ "objectUniversalIdentifier": "<TICKET_OBJECT>",+ "position": {+ "index": 0,+ "layoutMode": "VERTICAL_LIST",+ },+ "title": "Fields",+ "type": "FIELDS",+ "universalIdentifier": "<TICKET_PAGE_FIELDS_WIDGET>",+ },+ ],+ },+ ],+ "type": "RECORD_PAGE",+ "universalIdentifier": "<TICKET_PAGE_LAYOUT>",+ },+ {+ "name": "Ticket board",+ "tabs": [+ {+ "layoutMode": "GRID",+ "position": 0,+ "title": "Board",+ "universalIdentifier": "<TICKET_BOARD_TAB>",+ "widgets": [+ {+ "configuration": {+ "configurationType": "IFRAME",+ "url": "https://example.com/tickets",+ },+ "position": {+ "column": 0,+ "columnSpan": 6,+ "layoutMode": "GRID",+ "row": 0,+ "rowSpan": 4,+ },+ "title": "Docs",+ "type": "IFRAME",+ "universalIdentifier": "<TICKET_BOARD_DOCS_WIDGET>",+ },+ ],+ },+ ],+ "type": "STANDALONE_PAGE",+ "universalIdentifier": "<TICKET_BOARD_LAYOUT>",+ },+ ],"permissionFlags": [],"publicAssets": [],"roles": [],diff --git a/packages/twenty-server/test/integration/metadata/suites/application/successful-export-application-data-model.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/successful-export-application-data-model.integration-spec.tsindex fea1af9fe30..deeba2141c3 100644--- a/packages/twenty-server/test/integration/metadata/suites/application/successful-export-application-data-model.integration-spec.ts+++ b/packages/twenty-server/test/integration/metadata/suites/application/successful-export-application-data-model.integration-spec.ts@@ -24,6 +24,8 @@ import {getSystemViewFieldUniversalIdentifier,getSystemViewUniversalIdentifier,type ObjectManifest,+ type PageLayoutManifest,+ type PageLayoutTabManifest,type StandaloneViewFieldManifest,SYSTEM_VIEW_KEYS,type TranslationsManifest,@@ -34,6 +36,7 @@ import { STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS } from 'twenty-shared/metadata';import {AggregateOperations,FieldMetadataType,+ PageLayoutTabLayoutMode,RelationOnDeleteAction,RelationType,ViewFilterGroupLogicalOperator,@@ -69,6 +72,17 @@ const VIEW_FILTER_ID = '7e3d1c2b-0015-4a7b-8c9d-0e1f2a3b4c5d';const VIEW_SORT_ID = '7e3d1c2b-0016-4a7b-8c9d-0e1f2a3b4c5d';const VIEW_GROUP_ID = '7e3d1c2b-0017-4a7b-8c9d-0e1f2a3b4c5d';const PROJECT_INDEX_VIEW_FIELD_ID = '7e3d1c2b-0018-4a7b-8c9d-0e1f2a3b4c5d';+const TICKET_PAGE_LAYOUT_ID = '7e3d1c2b-0019-4a7b-8c9d-0e1f2a3b4c5d';+const TICKET_PAGE_OVERVIEW_TAB_ID = '7e3d1c2b-0020-4a7b-8c9d-0e1f2a3b4c5d';+const TICKET_PAGE_FIELDS_WIDGET_ID = '7e3d1c2b-0021-4a7b-8c9d-0e1f2a3b4c5d';+const TICKET_BOARD_LAYOUT_ID = '7e3d1c2b-0022-4a7b-8c9d-0e1f2a3b4c5d';+const TICKET_BOARD_TAB_ID = '7e3d1c2b-0023-4a7b-8c9d-0e1f2a3b4c5d';+const TICKET_BOARD_DOCS_WIDGET_ID = '7e3d1c2b-0024-4a7b-8c9d-0e1f2a3b4c5d';+const TICKET_RECORD_PAGE_EXTRA_TAB_ID = '7e3d1c2b-0025-4a7b-8c9d-0e1f2a3b4c5d';+const TICKET_RECORD_PAGE_EXTRA_NOTES_WIDGET_ID =+ '7e3d1c2b-0026-4a7b-8c9d-0e1f2a3b4c5d';+const COMPANY_RECORD_PAGE_TAGLINE_TAB_ID =+ '7e3d1c2b-0027-4a7b-8c9d-0e1f2a3b4c5d';const ENGINE_DERIVED_FIELD_NAMES = ['id',@@ -125,6 +139,21 @@ const buildIdentifierNames = (): Map<string, string> => {[VIEW_SORT_ID, 'OPEN_TICKETS_TITLE_SORT'],[VIEW_GROUP_ID, 'OPEN_TICKETS_OPEN_GROUP'],[PROJECT_INDEX_VIEW_FIELD_ID, 'PROJECT_INDEX_DELETED_AT_VIEW_FIELD'],+ [TICKET_PAGE_LAYOUT_ID, 'TICKET_PAGE_LAYOUT'],+ [TICKET_PAGE_OVERVIEW_TAB_ID, 'TICKET_PAGE_OVERVIEW_TAB'],+ [TICKET_PAGE_FIELDS_WIDGET_ID, 'TICKET_PAGE_FIELDS_WIDGET'],+ [TICKET_BOARD_LAYOUT_ID, 'TICKET_BOARD_LAYOUT'],+ [TICKET_BOARD_TAB_ID, 'TICKET_BOARD_TAB'],+ [TICKET_BOARD_DOCS_WIDGET_ID, 'TICKET_BOARD_DOCS_WIDGET'],+ [TICKET_RECORD_PAGE_EXTRA_TAB_ID, 'TICKET_RECORD_PAGE_EXTRA_TAB'],+ [+ TICKET_RECORD_PAGE_EXTRA_NOTES_WIDGET_ID,+ 'TICKET_RECORD_PAGE_EXTRA_NOTES_WIDGET',+ ],+ [+ COMPANY_RECORD_PAGE_TAGLINE_TAB_ID,+ 'STANDARD_COMPANY_RECORD_PAGE_TAGLINE_TAB',+ ],[getIndexFieldUniversalIdentifier({applicationUniversalIdentifier: TEST_APP_ID,@@ -529,6 +558,109 @@ const projectIndexViewField: StandaloneViewFieldManifest = {size: 180,};+const ticketPageLayout: PageLayoutManifest = {+ universalIdentifier: TICKET_PAGE_LAYOUT_ID,+ name: 'Ticket page',+ type: 'RECORD_PAGE',+ objectUniversalIdentifier: TICKET_OBJECT_ID,+ defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier:+ TICKET_PAGE_OVERVIEW_TAB_ID,+ tabs: [+ {+ universalIdentifier: TICKET_PAGE_OVERVIEW_TAB_ID,+ title: 'Overview',+ position: 0,+ icon: 'IconHome',+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgets: [+ {+ universalIdentifier: TICKET_PAGE_FIELDS_WIDGET_ID,+ title: 'Fields',+ type: 'FIELDS',+ objectUniversalIdentifier: TICKET_OBJECT_ID,+ position: {+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ index: 0,+ },+ configuration: {+ configurationType: 'FIELDS',+ viewUniversalIdentifier: OPEN_TICKETS_VIEW_ID,+ newFieldDefaultVisibility: true,+ },+ },+ ],+ },+ ],+};++const ticketBoardLayout: PageLayoutManifest = {+ universalIdentifier: TICKET_BOARD_LAYOUT_ID,+ name: 'Ticket board',+ type: 'STANDALONE_PAGE',+ tabs: [+ {+ universalIdentifier: TICKET_BOARD_TAB_ID,+ title: 'Board',+ position: 0,+ layoutMode: PageLayoutTabLayoutMode.GRID,+ widgets: [+ {+ universalIdentifier: TICKET_BOARD_DOCS_WIDGET_ID,+ title: 'Docs',+ type: 'IFRAME',+ position: {+ layoutMode: PageLayoutTabLayoutMode.GRID,+ row: 0,+ column: 0,+ rowSpan: 4,+ columnSpan: 6,+ },+ configuration: {+ configurationType: 'IFRAME',+ url: 'https://example.com/tickets',+ },+ },+ ],+ },+ ],+};++const TICKET_RECORD_PAGE_LAYOUT_ID =+ getSystemRecordPageLayoutUniversalIdentifier({+ objectMetadataApplicationUniversalIdentifier: TEST_APP_ID,+ objectUniversalIdentifier: TICKET_OBJECT_ID,+ });++const ticketRecordPageExtraTab: PageLayoutTabManifest = {+ universalIdentifier: TICKET_RECORD_PAGE_EXTRA_TAB_ID,+ pageLayoutUniversalIdentifier: TICKET_RECORD_PAGE_LAYOUT_ID,+ title: 'Extra',+ position: 60,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgets: [+ {+ universalIdentifier: TICKET_RECORD_PAGE_EXTRA_NOTES_WIDGET_ID,+ title: 'Notes',+ type: 'NOTES',+ objectUniversalIdentifier: TICKET_OBJECT_ID,+ position: { layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST, index: 0 },+ configuration: { configurationType: 'NOTES' },+ },+ ],+};++const companyRecordPageTaglineTab: PageLayoutTabManifest = {+ universalIdentifier: COMPANY_RECORD_PAGE_TAGLINE_TAB_ID,+ pageLayoutUniversalIdentifier: getSystemRecordPageLayoutUniversalIdentifier({+ objectMetadataApplicationUniversalIdentifier:+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,+ objectUniversalIdentifier: STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.company,+ }),+ title: 'Tagline',+ position: 60,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+};+const manifest = buildBaseManifest({appId: TEST_APP_ID,roleId: TEST_ROLE_ID,@@ -550,6 +682,8 @@ const manifest = buildBaseManifest({],views: [openTicketsView],viewFields: [projectIndexViewField],+ pageLayouts: [ticketPageLayout, ticketBoardLayout],+ pageLayoutTabs: [ticketRecordPageExtraTab, companyRecordPageTaglineTab],},});@@ -695,6 +829,12 @@ describe('Application export - data model', () => {expect(statusOf(PROJECT_INDEX_VIEW_FIELD_ID)).toBe(ApplicationExportCoverageStatus.EXPORTED,);+ expect(statusOf(TICKET_RECORD_PAGE_LAYOUT_ID)).toBe(+ ApplicationExportCoverageStatus.ENGINE_DERIVED,+ );+ expect(statusOf(TICKET_RECORD_PAGE_EXTRA_TAB_ID)).toBe(+ ApplicationExportCoverageStatus.EXPORTED,+ );}, 60000);it('round-trips the raw export through an additive dry-run sync without any action', async () => {