The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Write pulled page layouts and standalone page layout tabs as define files (#25655)
Weiko8d31a9572548
diff --git a/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdx b/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdxindex 357f6b78942..26ef08965e5 100644--- a/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdx+++ b/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdx@@ -59,6 +59,7 @@ export default definePageLayout({- Each `widget` inside a tab can render a [front component](/developers/extend/apps/layout/front-components), a relation list, or other built-in widget types.- A `FRONT_COMPONENT` widget can set `headerCommandMenuItemUniversalIdentifiers` to an ordered array of command menu item universal identifiers from the same app. These actions appear as icon buttons in the widget card header and keep their command-level availability and permission checks. Identifiers must be unique and must resolve when the app is installed.- `position` on tabs controls their order. Use higher values (e.g., 50) to place custom tabs after built-in ones.+- `yarn twenty pull` writes page layouts back with their tabs and widgets inline. A widget the export cannot carry yet, such as one showing your app's own front component or one of the deprecated `VIEW` type, is reported by pull instead of written; see [what pull does not write](/developers/extend/apps/operations/sync-and-recovery#pulling-an-installed-app-back-to-source).### Field widgets@@ -182,3 +183,4 @@ export default definePageLayoutTab({- `widgets` are scoped to this tab only — they reference [front components](/developers/extend/apps/layout/front-components), views, etc. exactly like widgets defined inline in `definePageLayout`.- `position` controls ordering against existing tabs on the targeted layout. Pick a value that places your tab where you want it relative to built-in tabs.- Use this instead of `definePageLayout` when you only want to add to an existing layout. Use `definePageLayout` when you own the entire layout.+- `yarn twenty pull` writes a tab you added to a page layout you do not own back as a `definePageLayoutTab()` file, with its widgets inline, under the same limits as widgets of a `definePageLayout()`.diff --git a/packages/twenty-docs/developers/extend/apps/operations/sync-and-recovery.mdx b/packages/twenty-docs/developers/extend/apps/operations/sync-and-recovery.mdxindex 263afaaf460..8bdbb77d70f 100644--- a/packages/twenty-docs/developers/extend/apps/operations/sync-and-recovery.mdx+++ b/packages/twenty-docs/developers/extend/apps/operations/sync-and-recovery.mdx@@ -117,15 +117,19 @@ Pull needs an existing project — scaffold one with `npx create-twenty-app@late- authored indexes;- views, with their fields, field groups, filters, filter groups, sorts and groups inline;- view fields your app added to views it does not own, as standalone `defineViewField()` files;+- page layouts, with their tabs and widgets inline;+- tabs your app added to page layouts it does not own, as standalone `definePageLayoutTab()` files;- published translations, as `locales/<locale>.json` for the strings pull can read back from the pulled metadata and source, and `locales/compiled/<locale>.json` for the rest.Each entity goes to the file that already defines it, so a second pull rewrites only what changed on the server. New entities are placed beside existing files of their kind, and a generated name that would land on an unrelated file is qualified rather than overwriting it.**What it does not write:**-- **Not exported yet** — roles and permissions, page layouts, navigation, command menu items, logic functions and front components, and the stored source of your functions.-- **Derived by the engine** — system fields, default relations, default views and backing indexes. The server rebuilds them on apply. An object may still point its label identifier at one of them, as junction objects created in the UI do; the pointer is written and the build resolves it without adding a field.+- **Not exported yet** — roles and permissions, navigation, command menu items, logic functions and front components, and the stored source of your functions.+- **Derived by the engine** — system fields, default relations, default views and backing indexes, and the default page layouts of each object. The server rebuilds them on apply. An object may still point its label identifier at one of them, as junction objects created in the UI do; the pointer is written and the build resolves it without adding a field.- **Placed on a default or foreign view** — filters, filter groups, sorts, groups and field groups added to an engine default view, or to a view owned by another application, have no source form yet and are reported. View fields added there are written as standalone files, since the view's identifier is known.+- **Placed on a default or foreign page layout** — widgets added to a tab of an engine default page layout, or of a page layout owned by another application, have no source form yet and are reported. Tabs added there are written as standalone files, since the layout's identifier is known.+- **Widgets the export cannot carry yet** — on any layout, including your own, a widget of the deprecated `VIEW` type, a widget showing one of your app's own front components or command menu items, or a widget without a position for its tab's layout mode is reported, and the layout or tab is written without it.- **Workspace runtime state** — member and API-key role assignments, webhooks and per-user navigation, all excluded by design.- **Owned by another application** — reported, never pulled.diff --git a/packages/twenty-sdk/src/cli/utilities/pull/__integration__/pull-round-trip.integration.spec.ts b/packages/twenty-sdk/src/cli/utilities/pull/__integration__/pull-round-trip.integration.spec.tsindex f97b79c5163..71c8a286f6c 100644--- a/packages/twenty-sdk/src/cli/utilities/pull/__integration__/pull-round-trip.integration.spec.ts+++ b/packages/twenty-sdk/src/cli/utilities/pull/__integration__/pull-round-trip.integration.spec.ts@@ -1,19 +1,24 @@import { buildManifest } from '@/cli/utilities/build/manifest/manifest-build';import { buildPullEntities } from '@/cli/utilities/pull/build-pull-entities';import { planTranslationWrites } from '@/cli/utilities/pull/plan-translation-writes';+import { stripGraphqlTypename } from '@/cli/utilities/pull/strip-graphql-typename';import { compileApplicationTranslations } from '@/cli/utilities/translations/compile-application-translations';import { writeDefineFile } from '@/cli/utilities/pull/write-define-file';import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';import { dirname, join, resolve } from 'node:path';import {getFieldUniversalIdentifier,+ getSystemRecordPageLayoutUniversalIdentifier,getSystemViewUniversalIdentifier,type Manifest,SYSTEM_VIEW_KEYS,TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,} from 'twenty-shared/application';import { generateMessageId } from 'twenty-shared/i18n';-import { STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS } from 'twenty-shared/metadata';+import {+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS,+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS,+} from 'twenty-shared/metadata';import { afterAll, beforeAll, describe, expect, it } from 'vitest';const PACKAGE_ROOT = resolve(__dirname, '../../../../..');@@ -40,6 +45,25 @@ const VIEW_SORT_UID = '16161616-1616-4161-8161-161616161616';const VIEW_GROUP_UID = '17171717-1717-4171-8171-171717171717';const VIEW_FIELD_GROUP_UID = '18181818-1818-4181-8181-181818181818';const COMPANY_INDEX_VIEW_FIELD_UID = '19191919-1919-4191-8191-191919191919';+const PET_PAGE_LAYOUT_UID = '21212121-2121-4212-8212-212121212121';+const PET_OVERVIEW_TAB_UID = '23232323-2323-4232-8232-232323232323';+const PET_FIELDS_WIDGET_UID = '24242424-2424-4242-8242-242424242424';+const DOCS_PAGE_LAYOUT_UID = '25252525-2525-4252-8252-252525252525';+const DOCS_TAB_UID = '26262626-2626-4262-8262-262626262626';+const DOCS_WIDGET_UID = '27272727-2727-4272-8272-272727272727';+const DASHBOARD_PAGE_LAYOUT_UID = '28282828-2828-4282-8282-282828282828';+const DASHBOARD_TAB_UID = '29292929-2929-4292-8292-292929292929';+const AGE_CHART_WIDGET_UID = '30303030-3030-4303-8303-303030303030';+const PET_RECORD_PAGE_EXTRA_TAB_UID = '31313131-3131-4313-8313-313131313131';+const PET_EXTRA_NOTES_WIDGET_UID = '32323232-3232-4323-8323-323232323232';+const COMPANY_TAGLINE_TAB_UID = '34343434-3434-4343-8343-343434343434';++const PET_RECORD_PAGE_LAYOUT_UID = getSystemRecordPageLayoutUniversalIdentifier(+ {+ objectMetadataApplicationUniversalIdentifier: APP_UID,+ objectUniversalIdentifier: PET_UID,+ },+);const COMPANY_INDEX_VIEW_UID = getSystemViewUniversalIdentifier({objectMetadataApplicationUniversalIdentifier:@@ -311,6 +335,145 @@ const EXPORTED_MANIFEST = {position: 3,},],+ pageLayouts: [+ {+ universalIdentifier: PET_PAGE_LAYOUT_UID,+ name: 'Pet page',+ type: 'RECORD_PAGE',+ objectUniversalIdentifier: PET_UID,+ defaultTabToFocusOnMobileAndSidePanelUniversalIdentifier:+ PET_OVERVIEW_TAB_UID,+ tabs: [+ {+ universalIdentifier: PET_OVERVIEW_TAB_UID,+ title: 'Overview',+ position: 0,+ icon: 'IconHome',+ layoutMode: 'VERTICAL_LIST',+ widgets: [+ {+ universalIdentifier: PET_FIELDS_WIDGET_UID,+ title: 'Fields',+ type: 'FIELDS',+ objectUniversalIdentifier: PET_UID,+ position: { layoutMode: 'VERTICAL_LIST', index: 0 },+ configuration: {+ configurationType: 'FIELDS',+ viewUniversalIdentifier: VIEW_UID,+ newFieldDefaultVisibility: true,+ },+ },+ ],+ },+ ],+ },+ {+ universalIdentifier: DOCS_PAGE_LAYOUT_UID,+ name: 'Pet docs',+ type: 'STANDALONE_PAGE',+ tabs: [+ {+ universalIdentifier: DOCS_TAB_UID,+ title: 'Docs',+ position: 0,+ layoutMode: 'GRID',+ widgets: [+ {+ universalIdentifier: DOCS_WIDGET_UID,+ title: 'Docs',+ type: 'IFRAME',+ position: {+ layoutMode: 'GRID',+ row: 0,+ column: 0,+ rowSpan: 4,+ columnSpan: 6,+ },+ configuration: {+ __typename: 'IframeConfiguration',+ configurationType: 'IFRAME',+ url: 'https://example.com/pets',+ },+ },+ ],+ },+ ],+ },+ {+ universalIdentifier: DASHBOARD_PAGE_LAYOUT_UID,+ name: 'Pet dashboard',+ type: 'DASHBOARD',+ tabs: [+ {+ universalIdentifier: DASHBOARD_TAB_UID,+ title: 'Charts',+ position: 0,+ layoutMode: 'GRID',+ widgets: [+ {+ universalIdentifier: AGE_CHART_WIDGET_UID,+ title: 'Age by status',+ type: 'GRAPH',+ objectUniversalIdentifier: PET_UID,+ position: {+ layoutMode: 'GRID',+ row: 0,+ column: 0,+ rowSpan: 6,+ columnSpan: 12,+ },+ configuration: {+ configurationType: 'BAR_CHART',+ aggregateFieldMetadataUniversalIdentifier: PET_AGE_FIELD_UID,+ aggregateOperation: 'AVG',+ primaryAxisGroupByFieldMetadataUniversalIdentifier:+ PET_STATUS_FIELD_UID,+ primaryAxisDateGranularity: 'MONTH',+ secondaryAxisGroupByFieldMetadataUniversalIdentifier: null,+ filter: {+ recordFilters: [+ {+ fieldMetadataUniversalIdentifier: PET_NAME_FIELD_UID,+ operand: 'contains',+ value: 'Rex',+ },+ ],+ },+ },+ },+ ],+ },+ ],+ },+ ],+ pageLayoutTabs: [+ {+ universalIdentifier: PET_RECORD_PAGE_EXTRA_TAB_UID,+ pageLayoutUniversalIdentifier: PET_RECORD_PAGE_LAYOUT_UID,+ title: 'Extra',+ position: 60,+ layoutMode: 'VERTICAL_LIST',+ widgets: [+ {+ universalIdentifier: PET_EXTRA_NOTES_WIDGET_UID,+ title: 'Notes',+ type: 'NOTES',+ objectUniversalIdentifier: PET_UID,+ position: { layoutMode: 'VERTICAL_LIST', index: 0 },+ configuration: { configurationType: 'NOTES' },+ },+ ],+ },+ {+ universalIdentifier: COMPANY_TAGLINE_TAB_UID,+ pageLayoutUniversalIdentifier:+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.companyRecordPage+ .universalIdentifier,+ title: 'Tagline',+ position: 60,+ layoutMode: 'VERTICAL_LIST',+ },+ ],} as unknown as Manifest;const canonicalize = (value: unknown): unknown =>@@ -465,6 +628,31 @@ describe('pull round trip', () => {);});+ it('should rebuild the exported page layouts with their tabs and widgets in order, without the GraphQL typename a UI-saved widget carries', () => {+ expect(+ canonicalize(sortByUniversalIdentifier(builtManifest?.pageLayouts ?? [])),+ ).toEqual(+ canonicalize(+ sortByUniversalIdentifier(+ stripGraphqlTypename(EXPORTED_MANIFEST.pageLayouts),+ ),+ ),+ );+ expect(JSON.stringify(builtManifest?.pageLayouts)).not.toContain(+ '__typename',+ );+ });++ it('should rebuild the standalone tabs on the pet record page and the company record page unchanged', () => {+ expect(+ canonicalize(+ sortByUniversalIdentifier(builtManifest?.pageLayoutTabs ?? []),+ ),+ ).toEqual(+ canonicalize(sortByUniversalIdentifier(EXPORTED_MANIFEST.pageLayoutTabs)),+ );+ });+it('should keep a junction object without adding a name field to it', () => {const junctionObject = (builtManifest?.objects ?? []).find((objectManifest) => objectManifest.universalIdentifier === JUNCTION_UID,diff --git a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/build-pull-entities.spec.ts b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/build-pull-entities.spec.tsindex c9508a5b304..2f92ecba94f 100644--- a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/build-pull-entities.spec.ts+++ b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/build-pull-entities.spec.ts@@ -1,19 +1,26 @@import { buildPullEntities } from '@/cli/utilities/pull/build-pull-entities';import {+ PAGE_LAYOUT_ENUM_BINDINGS,+ PAGE_LAYOUT_TAB_ENUM_BINDINGS,VIEW_ENUM_BINDINGS,VIEW_FIELD_ENUM_BINDINGS,} from '@/cli/utilities/pull/write-define-file';import {+ getSystemRecordPageLayoutUniversalIdentifier,type Manifest,+ type PageLayoutManifest,+ type PageLayoutTabManifest,type StandaloneViewFieldManifest,type ViewManifest,} from 'twenty-shared/application';import {STANDARD_OBJECT_FIELDS,STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS,+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS,} from 'twenty-shared/metadata';import {AggregateOperations,+ PageLayoutTabLayoutMode,ViewSortDirection,ViewType,} from 'twenty-shared/types';@@ -30,6 +37,10 @@ const VIEW_UID = '88888888-8888-4888-8888-888888888888';const VIEW_FIELD_UID = '99999999-9999-4999-8999-999999999999';const VIEW_SORT_UID = 'aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa';const INLINE_VIEW_FIELD_UID = 'bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb';+const PAGE_LAYOUT_UID = 'cccccccc-cccc-4ccc-8ccc-cccccccccccc';+const PAGE_LAYOUT_TAB_UID = 'dddddddd-dddd-4ddd-8ddd-dddddddddddd';+const WIDGET_UID = 'eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee';+const STANDALONE_TAB_UID = 'ffffffff-ffff-4fff-8fff-ffffffffffff';const buildManifest = (overrides: Partial<Manifest> = {}): Manifest =>({@@ -111,6 +122,50 @@ const buildViewFieldManifest = (...overrides,});+const buildPageLayoutManifest = (+ overrides: Partial<PageLayoutManifest> = {},+): PageLayoutManifest => ({+ universalIdentifier: PAGE_LAYOUT_UID,+ name: 'Pet page',+ type: 'RECORD_PAGE',+ objectUniversalIdentifier: PET_UID,+ tabs: [+ {+ universalIdentifier: PAGE_LAYOUT_TAB_UID,+ title: 'Overview',+ position: 0,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgets: [+ {+ universalIdentifier: WIDGET_UID,+ title: 'Notes',+ type: 'NOTES',+ objectUniversalIdentifier: PET_UID,+ position: {+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ index: 0,+ },+ configuration: { configurationType: 'NOTES' },+ },+ ],+ },+ ],+ ...overrides,+});++const buildPageLayoutTabManifest = (+ overrides: Partial<PageLayoutTabManifest> = {},+): PageLayoutTabManifest => ({+ universalIdentifier: STANDALONE_TAB_UID,+ pageLayoutUniversalIdentifier:+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.companyRecordPage+ .universalIdentifier,+ title: 'Extra',+ position: 60,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ ...overrides,+});+describe('buildPullEntities', () => {it('should strip the checksums the build recomputes from the application config', () => {const { entities } = buildPullEntities(buildManifest());@@ -344,14 +399,206 @@ describe('buildPullEntities', () => {expect(viewField?.fileBaseName).toBe('99999999');});- it('should build a manifest that has no views and viewFields properties without producing view entities', () => {+ it('should write a page layout verbatim into src/page-layouts with the page layout enum bindings and its object as parent', () => {+ const pageLayoutManifest = buildPageLayoutManifest();+ const { entities, skipped } = buildPullEntities(+ buildManifest({ pageLayouts: [pageLayoutManifest] }),+ );+ const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');++ expect(skipped).toEqual([]);+ expect(pageLayout?.universalIdentifier).toBe(PAGE_LAYOUT_UID);+ expect(pageLayout?.definer).toBe('definePageLayout');+ expect(pageLayout?.config).toEqual(pageLayoutManifest);+ expect(pageLayout?.enumBindings).toEqual(PAGE_LAYOUT_ENUM_BINDINGS);+ expect(pageLayout?.parentName).toBe('pet');+ expect(+ `${pageLayout?.defaultFolder}/${pageLayout?.fileBaseName}${pageLayout?.fileSuffix}`,+ ).toBe('src/page-layouts/pet-page.page-layout.ts');+ });++ it('should drop the GraphQL typename keys a widget configuration saved from the UI carries', () => {+ const pageLayoutManifest = buildPageLayoutManifest();+ const widgetWithTypename = {+ ...pageLayoutManifest.tabs![0].widgets![0],+ configuration: {+ __typename: 'RecordTableConfiguration',+ configurationType: 'RECORD_TABLE',+ recordLimit: null,+ viewUniversalIdentifier: VIEW_UID,+ },+ };+ const { entities } = buildPullEntities(+ buildManifest({+ pageLayouts: [+ {+ ...pageLayoutManifest,+ tabs: [+ { ...pageLayoutManifest.tabs![0], widgets: [widgetWithTypename] },+ ],+ },+ ] as unknown as PageLayoutManifest[],+ pageLayoutTabs: [+ buildPageLayoutTabManifest({+ widgets: [widgetWithTypename],+ } as unknown as Partial<PageLayoutTabManifest>),+ ],+ }),+ );+ const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');+ const pageLayoutTab = entities.find(+ (entity) => entity.kind === 'pageLayoutTab',+ );+ const expectedConfiguration = {+ configurationType: 'RECORD_TABLE',+ recordLimit: null,+ viewUniversalIdentifier: VIEW_UID,+ };++ expect(+ (pageLayout?.config as PageLayoutManifest).tabs?.[0].widgets?.[0]+ .configuration,+ ).toEqual(expectedConfiguration);+ expect(+ (pageLayoutTab?.config as PageLayoutTabManifest).widgets?.[0]+ .configuration,+ ).toEqual(expectedConfiguration);+ });++ it('should give a page layout on a standard object that object as parent', () => {+ const { entities } = buildPullEntities(+ buildManifest({+ pageLayouts: [+ buildPageLayoutManifest({+ objectUniversalIdentifier:+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.person,+ }),+ ],+ }),+ );+ const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');++ expect(pageLayout?.parentName).toBe('person');+ });++ it('should give a page layout without an object no parent', () => {+ const {+ objectUniversalIdentifier: _objectUniversalIdentifier,+ ...standalonePageManifest+ } = buildPageLayoutManifest({ name: 'Pet docs', type: 'STANDALONE_PAGE' });+ const { entities, skipped } = buildPullEntities(+ buildManifest({ pageLayouts: [standalonePageManifest] }),+ );+ const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');++ expect(skipped).toEqual([]);+ expect(pageLayout?.parentName).toBeNull();+ expect(pageLayout?.fileBaseName).toBe('pet-docs');+ });++ it('should name a page layout whose name has no kebab-case form after its identifier prefix', () => {+ const { entities } = buildPullEntities(+ buildManifest({+ pageLayouts: [buildPageLayoutManifest({ name: '!!!' })],+ }),+ );+ const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');++ expect(pageLayout?.fileBaseName).toBe('cccccccc');+ });++ it('should write a standalone page layout tab into src/page-layout-tabs with the tab enum bindings and its standard page layout as parent', () => {+ const pageLayoutTabManifest = buildPageLayoutTabManifest();+ const { entities, skipped } = buildPullEntities(+ buildManifest({ pageLayoutTabs: [pageLayoutTabManifest] }),+ );+ const pageLayoutTab = entities.find(+ (entity) => entity.kind === 'pageLayoutTab',+ );++ expect(skipped).toEqual([]);+ expect(pageLayoutTab?.universalIdentifier).toBe(STANDALONE_TAB_UID);+ expect(pageLayoutTab?.definer).toBe('definePageLayoutTab');+ expect(pageLayoutTab?.config).toEqual(pageLayoutTabManifest);+ expect(pageLayoutTab?.enumBindings).toEqual(PAGE_LAYOUT_TAB_ENUM_BINDINGS);+ expect(pageLayoutTab?.parentName).toBe('companyRecordPage');+ expect(+ `${pageLayoutTab?.defaultFolder}/${pageLayoutTab?.fileBaseName}${pageLayoutTab?.fileSuffix}`,+ ).toBe('src/page-layout-tabs/extra.page-layout-tab.ts');+ });++ it('should give a standalone tab on the record page of a manifest object that page as parent', () => {+ const { entities } = buildPullEntities(+ buildManifest({+ pageLayoutTabs: [+ buildPageLayoutTabManifest({+ pageLayoutUniversalIdentifier:+ getSystemRecordPageLayoutUniversalIdentifier({+ objectMetadataApplicationUniversalIdentifier: APP_UID,+ objectUniversalIdentifier: PET_UID,+ }),+ }),+ ],+ }),+ );+ const pageLayoutTab = entities.find(+ (entity) => entity.kind === 'pageLayoutTab',+ );++ expect(pageLayoutTab?.parentName).toBe('petRecordPage');+ });++ it('should give a standalone tab on a page layout of the manifest that layout as parent', () => {+ const { entities } = buildPullEntities(+ buildManifest({+ pageLayouts: [buildPageLayoutManifest()],+ pageLayoutTabs: [+ buildPageLayoutTabManifest({+ pageLayoutUniversalIdentifier: PAGE_LAYOUT_UID,+ }),+ ],+ }),+ );+ const pageLayoutTab = entities.find(+ (entity) => entity.kind === 'pageLayoutTab',+ );++ expect(pageLayoutTab?.parentName).toBe('Pet page');+ });++ it('should skip a standalone tab that does not name its page layout', () => {+ const {+ pageLayoutUniversalIdentifier: _pageLayoutUniversalIdentifier,+ ...tabWithoutPageLayout+ } = buildPageLayoutTabManifest();+ const { entities, skipped } = buildPullEntities(+ buildManifest({ pageLayoutTabs: [tabWithoutPageLayout] }),+ );++ expect(entities.some((entity) => entity.kind === 'pageLayoutTab')).toBe(+ false,+ );+ expect(skipped).toEqual([+ {+ kind: 'pageLayoutTab',+ universalIdentifier: STANDALONE_TAB_UID,+ reason: 'it does not name the page layout it belongs to',+ },+ ]);+ });++ it('should build a manifest that has no views, view fields, page layouts and page layout tabs properties without producing their entities', () => {const {views: _views,viewFields: _viewFields,+ pageLayouts: _pageLayouts,+ pageLayoutTabs: _pageLayoutTabs,...manifestWithoutViews} = buildManifest({views: [buildViewManifest()],viewFields: [buildViewFieldManifest()],+ pageLayouts: [buildPageLayoutManifest()],+ pageLayoutTabs: [buildPageLayoutTabManifest()],});const { entities, skipped } = buildPullEntities(@@ -366,7 +613,7 @@ describe('buildPullEntities', () => {]);});- it('should never skip a view or a view field, even when their object or field is unknown', () => {+ it('should never skip a view, a view field, a page layout or a page layout tab, even when their parent is unknown', () => {const { entities, skipped } = buildPullEntities(buildManifest({objects: [],@@ -380,14 +627,36 @@ describe('buildPullEntities', () => {fieldMetadataUniversalIdentifier: 'a-field-of-another-application',}),],+ pageLayouts: [+ buildPageLayoutManifest({+ objectUniversalIdentifier: 'an-object-of-another-application',+ }),+ ],+ pageLayoutTabs: [+ buildPageLayoutTabManifest({+ pageLayoutUniversalIdentifier:+ 'a-page-layout-of-another-application',+ }),+ ],}),);const view = entities.find((entity) => entity.kind === 'view');+ const pageLayout = entities.find((entity) => entity.kind === 'pageLayout');+ const pageLayoutTab = entities.find(+ (entity) => entity.kind === 'pageLayoutTab',+ );expect(skipped).toEqual([]);expect(entities.map((entity) => entity.kind)).toEqual(- expect.arrayContaining(['view', 'viewField']),+ expect.arrayContaining([+ 'view',+ 'viewField',+ 'pageLayout',+ 'pageLayoutTab',+ ]),);expect(view?.parentName).toBeNull();+ expect(pageLayout?.parentName).toBeNull();+ expect(pageLayoutTab?.parentName).toBeNull();});});diff --git a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/plan-pull-writes.spec.ts b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/plan-pull-writes.spec.tsindex 9ad04210f7b..4e8d4a9e36b 100644--- a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/plan-pull-writes.spec.ts+++ b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/plan-pull-writes.spec.ts@@ -3,11 +3,17 @@ import { planPullWrites } from '@/cli/utilities/pull/plan-pull-writes';import { type ScannedDefineFile } from '@/cli/utilities/pull/scan-project-define-files';import {type Manifest,+ type PageLayoutManifest,+ type PageLayoutTabManifest,type StandaloneViewFieldManifest,type ViewFilterManifest,type ViewManifest,} from 'twenty-shared/application';-import { ViewFilterOperand } from 'twenty-shared/types';+import { STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS } from 'twenty-shared/metadata';+import {+ PageLayoutTabLayoutMode,+ ViewFilterOperand,+} from 'twenty-shared/types';import { describe, expect, it } from 'vitest';const APP_UID = '11111111-1111-4111-8111-111111111111';@@ -25,6 +31,12 @@ const THIRD_OVERVIEW_VIEW_UID = 'ffffffff-ffff-4fff-8fff-ffffffffffff';const HEALTHY_PETS_FILTER_UID = 'cccccccc-cccc-4ccc-8ccc-cccccccccccc';const PET_NAME_VIEW_FIELD_UID = 'dddddddd-dddd-4ddd-8ddd-dddddddddddd';const ROCKET_NAME_VIEW_FIELD_UID = 'eeeeeeee-eeee-4eee-8eee-eeeeeeeeeeee';+const PET_PAGE_LAYOUT_UID = '12121212-1212-4121-8121-121212121212';+const ROCKET_PAGE_LAYOUT_UID = '13131313-1313-4131-8131-131313131313';+const SECOND_PET_PAGE_LAYOUT_UID = '14141414-1414-4141-8141-141414141414';+const COMPANY_EXTRA_TAB_UID = '15151515-1515-4151-8151-151515151515';+const PERSON_EXTRA_TAB_UID = '16161616-1616-4161-8161-161616161616';+const DOCS_WIDGET_UID = '17171717-1717-4171-8171-171717171717';const buildObject = ({universalIdentifier,@@ -93,6 +105,72 @@ const buildViewField = (...overrides,});+const buildPageLayout = (+ overrides: Partial<PageLayoutManifest> & { universalIdentifier: string },+): PageLayoutManifest => ({+ name: 'Overview',+ type: 'RECORD_PAGE',+ objectUniversalIdentifier: PET_UID,+ ...overrides,+});++const buildPageLayoutTab = (+ overrides: Partial<PageLayoutTabManifest> & { universalIdentifier: string },+): PageLayoutTabManifest => ({+ pageLayoutUniversalIdentifier:+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.companyRecordPage+ .universalIdentifier,+ title: 'Extra',+ position: 60,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ ...overrides,+});++const buildManifestWithDocsPageLayout = (url: string): Manifest => ({+ ...buildManifest([+ buildObject({+ universalIdentifier: PET_UID,+ nameSingular: 'pet',+ labelIdentifierFieldMetadataUniversalIdentifier: NAME_FIELD_UID,+ }),+ buildObject({+ universalIdentifier: ROCKET_UID,+ nameSingular: 'rocket',+ labelIdentifierFieldMetadataUniversalIdentifier: ROCKET_NAME_FIELD_UID,+ }),+ ]),+ pageLayouts: [+ buildPageLayout({+ universalIdentifier: ROCKET_PAGE_LAYOUT_UID,+ name: 'Board',+ objectUniversalIdentifier: ROCKET_UID,+ }),+ buildPageLayout({+ universalIdentifier: PET_PAGE_LAYOUT_UID,+ tabs: [+ {+ universalIdentifier: COMPANY_EXTRA_TAB_UID,+ title: 'Docs',+ position: 0,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgets: [+ {+ universalIdentifier: DOCS_WIDGET_UID,+ title: 'Docs',+ type: 'IFRAME',+ position: {+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ index: 0,+ },+ configuration: { configurationType: 'IFRAME', url },+ },+ ],+ },+ ],+ }),+ ],+});+const buildNameFilter = (value: string): ViewFilterManifest => ({universalIdentifier: HEALTHY_PETS_FILTER_UID,fieldMetadataUniversalIdentifier: NAME_FIELD_UID,@@ -675,4 +753,217 @@ describe('planPullWrites', () => {expect(plan.writes[0].content).toContain("value: 'Max',");expect(plan.writes[0].content).toContain('operand: ViewFilterOperand.IS,');});++ it('should place a new page layout beside existing page layout files', () => {+ const plan = planPullWrites({+ manifest: {+ ...MANIFEST,+ pageLayouts: [+ buildPageLayout({ universalIdentifier: ROCKET_PAGE_LAYOUT_UID }),+ buildPageLayout({+ universalIdentifier: PET_PAGE_LAYOUT_UID,+ name: 'Pet page',+ }),+ ],+ },+ baseManifest: null,+ scannedFiles: [+ {+ relativePath: 'app/screens/overview.page-layout.ts',+ entityKey: ManifestEntityKey.PageLayouts,+ universalIdentifier: ROCKET_PAGE_LAYOUT_UID,+ isReadable: true,+ },+ ],+ });++ expect(+ plan.writes.find(+ (write) => write.universalIdentifier === PET_PAGE_LAYOUT_UID,+ )?.relativePath,+ ).toBe('app/screens/pet-page.page-layout.ts');+ });++ it('should place a new standalone page layout tab beside existing page layout tab files', () => {+ const plan = planPullWrites({+ manifest: {+ ...MANIFEST,+ pageLayoutTabs: [+ buildPageLayoutTab({ universalIdentifier: COMPANY_EXTRA_TAB_UID }),+ buildPageLayoutTab({+ universalIdentifier: PERSON_EXTRA_TAB_UID,+ pageLayoutUniversalIdentifier:+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.personRecordPage+ .universalIdentifier,+ title: 'Insights',+ }),+ ],+ },+ baseManifest: null,+ scannedFiles: [+ {+ relativePath: 'app/screens/tabs/extra.page-layout-tab.ts',+ entityKey: ManifestEntityKey.PageLayoutTabs,+ universalIdentifier: COMPANY_EXTRA_TAB_UID,+ isReadable: true,+ },+ ],+ });++ expect(+ plan.writes.find(+ (write) => write.universalIdentifier === PERSON_EXTRA_TAB_UID,+ )?.relativePath,+ ).toBe('app/screens/tabs/insights.page-layout-tab.ts');+ });++ it('should qualify colliding page layout file names with the kebab-cased name of each object', () => {+ const plan = planPullWrites({+ manifest: {+ ...buildManifest([+ buildObject({+ universalIdentifier: JUNCTION_UID,+ nameSingular: 'petCareAgreement',+ labelIdentifierFieldMetadataUniversalIdentifier:+ JUNCTION_ID_FIELD_UID,+ }),+ buildObject({+ universalIdentifier: ROCKET_UID,+ nameSingular: 'rocket',+ labelIdentifierFieldMetadataUniversalIdentifier:+ ROCKET_NAME_FIELD_UID,+ }),+ ]),+ pageLayouts: [+ buildPageLayout({+ universalIdentifier: PET_PAGE_LAYOUT_UID,+ objectUniversalIdentifier: JUNCTION_UID,+ }),+ buildPageLayout({+ universalIdentifier: ROCKET_PAGE_LAYOUT_UID,+ objectUniversalIdentifier: ROCKET_UID,+ }),+ ],+ },+ baseManifest: null,+ scannedFiles: [],+ });++ expect(+ plan.writes+ .filter((write) => write.kind === 'pageLayout')+ .map((write) => write.relativePath)+ .sort(),+ ).toEqual([+ 'src/page-layouts/pet-care-agreement-overview.page-layout.ts',+ 'src/page-layouts/rocket-overview.page-layout.ts',+ ]);+ });++ it('should qualify colliding standalone tab file names with the kebab-cased name of each page layout', () => {+ const plan = planPullWrites({+ manifest: {+ ...MANIFEST,+ pageLayoutTabs: [+ buildPageLayoutTab({ universalIdentifier: COMPANY_EXTRA_TAB_UID }),+ buildPageLayoutTab({+ universalIdentifier: PERSON_EXTRA_TAB_UID,+ pageLayoutUniversalIdentifier:+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.personRecordPage+ .universalIdentifier,+ }),+ ],+ },+ baseManifest: null,+ scannedFiles: [],+ });++ expect(+ plan.writes+ .filter((write) => write.kind === 'pageLayoutTab')+ .map((write) => write.relativePath)+ .sort(),+ ).toEqual([+ 'src/page-layout-tabs/company-record-page-extra.page-layout-tab.ts',+ 'src/page-layout-tabs/person-record-page-extra.page-layout-tab.ts',+ ]);+ });++ it('should fall back to identifier-prefixed names when two page layouts of one object share a name', () => {+ const plan = planPullWrites({+ manifest: {+ ...MANIFEST,+ pageLayouts: [+ buildPageLayout({ universalIdentifier: PET_PAGE_LAYOUT_UID }),+ buildPageLayout({ universalIdentifier: SECOND_PET_PAGE_LAYOUT_UID }),+ ],+ },+ baseManifest: null,+ scannedFiles: [],+ });++ expect(+ plan.writes+ .filter((write) => write.kind === 'pageLayout')+ .map((write) => write.relativePath)+ .sort(),+ ).toEqual([+ `src/page-layouts/${PET_PAGE_LAYOUT_UID.slice(0, 8)}-pet-overview.page-layout.ts`,+ `src/page-layouts/${SECOND_PET_PAGE_LAYOUT_UID.slice(0, 8)}-pet-overview.page-layout.ts`,+ ]);+ });++ it('should leave an unchanged page layout untouched and regenerate the page layout whose widget changed on the server', () => {+ const scannedFiles: ScannedDefineFile[] = [+ {+ relativePath: 'src/application.config.ts',+ entityKey: ManifestEntityKey.Application,+ universalIdentifier: APP_UID,+ isReadable: true,+ },+ {+ relativePath: 'src/objects/pet.object.ts',+ entityKey: ManifestEntityKey.Objects,+ universalIdentifier: PET_UID,+ isReadable: true,+ },+ {+ relativePath: 'src/objects/rocket.object.ts',+ entityKey: ManifestEntityKey.Objects,+ universalIdentifier: ROCKET_UID,+ isReadable: true,+ },+ {+ relativePath: 'src/page-layouts/board.page-layout.ts',+ entityKey: ManifestEntityKey.PageLayouts,+ universalIdentifier: ROCKET_PAGE_LAYOUT_UID,+ isReadable: true,+ },+ {+ relativePath: 'src/page-layouts/overview.page-layout.ts',+ entityKey: ManifestEntityKey.PageLayouts,+ universalIdentifier: PET_PAGE_LAYOUT_UID,+ isReadable: true,+ },+ ];++ const plan = planPullWrites({+ manifest: buildManifestWithDocsPageLayout('https://example.com/new'),+ baseManifest: buildManifestWithDocsPageLayout('https://example.com/old'),+ scannedFiles,+ });++ expect(+ plan.unchanged.map((entity) => entity.universalIdentifier),+ ).toContain(ROCKET_PAGE_LAYOUT_UID);+ expect(plan.writes.map((write) => write.relativePath)).toEqual([+ 'src/page-layouts/overview.page-layout.ts',+ ]);+ expect(plan.writes[0].isRegeneration).toBe(true);+ expect(plan.writes[0].content).toContain("url: 'https://example.com/new',");+ expect(plan.writes[0].content).toContain(+ 'layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,',+ );+ expect(plan.writes[0].content).toContain('type: WidgetType.IFRAME,');+ });});diff --git a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/pull-base-file.spec.ts b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/pull-base-file.spec.tsindex 06574f5ea56..7ea1efcf4f7 100644--- a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/pull-base-file.spec.ts+++ b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/pull-base-file.spec.ts@@ -14,6 +14,8 @@ const PET_UID = '22222222-2222-4222-8222-222222222222';const NAME_FIELD_UID = '33333333-3333-4333-8333-333333333333';const VIEW_UID = '44444444-4444-4444-8444-444444444444';const VIEW_FIELD_UID = '55555555-5555-4555-8555-555555555555';+const PAGE_LAYOUT_UID = '66666666-6666-4666-8666-666666666666';+const PAGE_LAYOUT_TAB_UID = '77777777-7777-4777-8777-777777777777';const MANIFEST = {application: {@@ -57,6 +59,22 @@ const MANIFEST = {position: 0,},],+ pageLayouts: [+ {+ universalIdentifier: PAGE_LAYOUT_UID,+ name: 'Overview',+ type: 'RECORD_PAGE',+ objectUniversalIdentifier: PET_UID,+ },+ ],+ pageLayoutTabs: [+ {+ universalIdentifier: PAGE_LAYOUT_TAB_UID,+ pageLayoutUniversalIdentifier: 'a-page-layout-of-another-application',+ title: 'Extra',+ position: 60,+ },+ ],} as unknown as Manifest;describe('pull base file', () => {@@ -152,6 +170,54 @@ describe('pull base file', () => {expect(await readBase()).toBeNull();});+ it('should read back a base whose manifest has no page layouts and no page layout tabs', async () => {+ const {+ pageLayouts: _pageLayouts,+ pageLayoutTabs: _pageLayoutTabs,+ ...manifestWithoutPageLayouts+ } = MANIFEST;++ await writeRawBaseFile(+ JSON.stringify({+ version: 1,+ applicationUniversalIdentifier: APP_UID,+ manifest: manifestWithoutPageLayouts,+ }),+ );++ expect(await readBase()).toEqual(manifestWithoutPageLayouts);+ });++ it('should ignore a base whose page layouts contain an entry without a universal identifier', async () => {+ await writeRawBaseFile(+ JSON.stringify({+ version: 1,+ applicationUniversalIdentifier: APP_UID,+ manifest: {+ ...MANIFEST,+ pageLayouts: [{ name: 'Overview', type: 'RECORD_PAGE' }],+ },+ }),+ );++ expect(await readBase()).toBeNull();+ });++ it('should ignore a base whose page layout tabs are not a list', async () => {+ await writeRawBaseFile(+ JSON.stringify({+ version: 1,+ applicationUniversalIdentifier: APP_UID,+ manifest: {+ ...MANIFEST,+ pageLayoutTabs: { universalIdentifier: PAGE_LAYOUT_TAB_UID },+ },+ }),+ );++ expect(await readBase()).toBeNull();+ });+it('should return null when no base file has been written', async () => {expect(await readBase()).toBeNull();});diff --git a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/strip-graphql-typename.spec.ts b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/strip-graphql-typename.spec.tsnew file mode 100644index 00000000000..4194bf1783e--- /dev/null+++ b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/strip-graphql-typename.spec.ts@@ -0,0 +1,36 @@+import { stripGraphqlTypename } from '@/cli/utilities/pull/strip-graphql-typename';+import { describe, expect, it } from 'vitest';++describe('stripGraphqlTypename', () => {+ it('should drop __typename keys at every depth and keep everything else, nulls included', () => {+ expect(+ stripGraphqlTypename({+ __typename: 'PageLayoutWidget',+ title: 'People',+ configuration: {+ __typename: 'RecordTableConfiguration',+ configurationType: 'RECORD_TABLE',+ recordLimit: null,+ filter: {+ recordFilters: [+ { __typename: 'ChartFilter', value: null, operand: 'is' },+ ],+ },+ },+ }),+ ).toEqual({+ title: 'People',+ configuration: {+ configurationType: 'RECORD_TABLE',+ recordLimit: null,+ filter: { recordFilters: [{ value: null, operand: 'is' }] },+ },+ });+ });++ it('should return scalars and arrays unchanged', () => {+ expect(stripGraphqlTypename('People')).toBe('People');+ expect(stripGraphqlTypename(null)).toBeNull();+ expect(stripGraphqlTypename([1, 'two', null])).toEqual([1, 'two', null]);+ });+});diff --git a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/write-define-file.spec.ts b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/write-define-file.spec.tsindex efbdfb4fb84..ef4e3defe67 100644--- a/packages/twenty-sdk/src/cli/utilities/pull/__tests__/write-define-file.spec.ts+++ b/packages/twenty-sdk/src/cli/utilities/pull/__tests__/write-define-file.spec.ts@@ -2,6 +2,8 @@ import {FIELD_ENUM_BINDINGS,INDEX_ENUM_BINDINGS,OBJECT_ENUM_BINDINGS,+ PAGE_LAYOUT_ENUM_BINDINGS,+ PAGE_LAYOUT_TAB_ENUM_BINDINGS,VIEW_ENUM_BINDINGS,VIEW_FIELD_ENUM_BINDINGS,writeDefineFile,@@ -256,4 +258,161 @@ describe('writeDefineFile', () => {"import { defineViewField, AggregateOperations } from 'twenty-sdk/define';",);});++ it('should write every bound page layout property as its enum symbol and import each symbol on its own line', () => {+ const file = writeDefineFile({+ definer: 'definePageLayout',+ config: {+ universalIdentifier: 'page-layout-uid',+ name: 'Pet dashboard',+ type: 'DASHBOARD',+ tabs: [+ {+ universalIdentifier: 'tab-uid',+ title: 'Charts',+ position: 0,+ layoutMode: 'GRID',+ widgets: [+ {+ universalIdentifier: 'chart-widget-uid',+ title: 'Age by status',+ type: 'GRAPH',+ objectUniversalIdentifier: 'object-uid',+ position: {+ layoutMode: 'GRID',+ row: 0,+ column: 0,+ rowSpan: 4,+ columnSpan: 6,+ },+ configuration: {+ configurationType: 'BAR_CHART',+ aggregateFieldMetadataUniversalIdentifier: 'age-field-uid',+ aggregateOperation: 'AVG',+ primaryAxisGroupByFieldMetadataUniversalIdentifier:+ 'status-field-uid',+ primaryAxisDateGranularity: 'MONTH',+ secondaryAxisGroupByFieldMetadataUniversalIdentifier: null,+ groupMode: 'STACKED',+ },+ },+ {+ universalIdentifier: 'fields-widget-uid',+ title: 'Fields',+ type: 'FIELDS',+ position: { layoutMode: 'VERTICAL_LIST', index: 1 },+ configuration: {+ configurationType: 'FIELDS',+ viewUniversalIdentifier: null,+ fieldDisplayMode: 'CARD',+ },+ },+ ],+ },+ ],+ },+ enumBindings: PAGE_LAYOUT_ENUM_BINDINGS,+ });++ expect(+ file.startsWith(+ 'import {\n' ++ ' definePageLayout,\n' ++ ' AggregateOperations,\n' ++ ' ObjectRecordGroupByDateGranularity,\n' ++ ' PageLayoutTabLayoutMode,\n' ++ ' PageLayoutType,\n' ++ ' WidgetType,\n' ++ "} from 'twenty-sdk/define';\n",+ ),+ ).toBe(true);+ expect(file).toContain('type: PageLayoutType.DASHBOARD,');+ expect(file).toContain('layoutMode: PageLayoutTabLayoutMode.GRID,');+ expect(file).toContain('type: WidgetType.GRAPH,');+ expect(file).toContain('type: WidgetType.FIELDS,');+ expect(file).toContain(+ 'layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,',+ );+ expect(file).toContain('aggregateOperation: AggregateOperations.AVG,');+ expect(file).toContain(+ 'primaryAxisDateGranularity: ObjectRecordGroupByDateGranularity.MONTH,',+ );+ expect(file).toContain("configurationType: 'BAR_CHART',");+ expect(file).toContain("groupMode: 'STACKED',");+ expect(file).toContain("fieldDisplayMode: 'CARD',");+ expect(file).toContain(+ 'secondaryAxisGroupByFieldMetadataUniversalIdentifier: null,',+ );+ expect(file).toContain('viewUniversalIdentifier: null,');+ });++ it('should not bind a layout mode that sits on the page layout itself rather than on its tabs', () => {+ const file = writeDefineFile({+ definer: 'definePageLayout',+ config: { universalIdentifier: 'page-layout-uid', layoutMode: 'GRID' },+ enumBindings: PAGE_LAYOUT_ENUM_BINDINGS,+ });++ expect(file).toContain("layoutMode: 'GRID',");+ expect(file).toContain(+ "import { definePageLayout } from 'twenty-sdk/define';",+ );+ });++ it('should write a standalone page layout tab with its widgets under the tab enum bindings', () => {+ const file = writeDefineFile({+ definer: 'definePageLayoutTab',+ config: {+ universalIdentifier: 'tab-uid',+ pageLayoutUniversalIdentifier: 'page-layout-uid',+ title: 'Extra',+ position: 60,+ layoutMode: 'VERTICAL_LIST',+ widgets: [+ {+ universalIdentifier: 'widget-uid',+ title: 'Docs',+ type: 'IFRAME',+ position: { layoutMode: 'VERTICAL_LIST', index: 0 },+ configuration: {+ configurationType: 'IFRAME',+ url: 'https://example.com/docs',+ },+ },+ ],+ },+ enumBindings: PAGE_LAYOUT_TAB_ENUM_BINDINGS,+ });++ expect(file).toBe(+ 'import {\n' ++ ' definePageLayoutTab,\n' ++ ' PageLayoutTabLayoutMode,\n' ++ ' WidgetType,\n' ++ "} from 'twenty-sdk/define';\n" ++ '\n' ++ 'export default definePageLayoutTab({\n' ++ " universalIdentifier: 'tab-uid',\n" ++ " pageLayoutUniversalIdentifier: 'page-layout-uid',\n" ++ " title: 'Extra',\n" ++ ' position: 60,\n' ++ ' layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,\n' ++ ' widgets: [\n' ++ ' {\n' ++ " universalIdentifier: 'widget-uid',\n" ++ " title: 'Docs',\n" ++ ' type: WidgetType.IFRAME,\n' ++ ' position: {\n' ++ ' layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,\n' ++ ' index: 0,\n' ++ ' },\n' ++ ' configuration: {\n' ++ " configurationType: 'IFRAME',\n" ++ " url: 'https://example.com/docs',\n" ++ ' },\n' ++ ' },\n' ++ ' ],\n' ++ '});\n',+ );+ });});diff --git a/packages/twenty-sdk/src/cli/utilities/pull/build-pull-entities.ts b/packages/twenty-sdk/src/cli/utilities/pull/build-pull-entities.tsindex 6b07249b672..415c7da03f5 100644--- a/packages/twenty-sdk/src/cli/utilities/pull/build-pull-entities.ts+++ b/packages/twenty-sdk/src/cli/utilities/pull/build-pull-entities.ts@@ -2,6 +2,8 @@ import {FIELD_ENUM_BINDINGS,INDEX_ENUM_BINDINGS,OBJECT_ENUM_BINDINGS,+ PAGE_LAYOUT_ENUM_BINDINGS,+ PAGE_LAYOUT_TAB_ENUM_BINDINGS,VIEW_ENUM_BINDINGS,VIEW_FIELD_ENUM_BINDINGS,type EnumBinding,@@ -12,12 +14,19 @@ import {type FieldLocation,toFileBaseName,} from '@/cli/utilities/pull/pull-file-base-name';+import { stripGraphqlTypename } from '@/cli/utilities/pull/strip-graphql-typename';import { kebabCase } from '@/cli/utilities/string/kebab-case';import {type ApplicationManifest,+ getSystemRecordFormPageLayoutUniversalIdentifier,+ getSystemRecordPageLayoutUniversalIdentifier,type Manifest,} from 'twenty-shared/application';-import { STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS } from 'twenty-shared/metadata';+import {+ STANDARD_OBJECT_UNIVERSAL_IDENTIFIERS,+ STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS,+} from 'twenty-shared/metadata';+import { isDefined } from 'twenty-shared/utils';export const PULL_ENTITY_KINDS = ['application',@@ -26,6 +35,8 @@ export const PULL_ENTITY_KINDS = ['index','view','viewField',+ 'pageLayout',+ 'pageLayoutTab',] as const;export type PullEntityKind = (typeof PULL_ENTITY_KINDS)[number];@@ -75,6 +86,15 @@ const STANDARD_OBJECT_NAME_BY_UNIVERSAL_IDENTIFIER = new Map<string, string>(),);+const STANDARD_PAGE_LAYOUT_NAME_BY_UNIVERSAL_IDENTIFIER = new Map<+ string,+ string+>(+ Object.entries(STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS).map(+ ([name, { universalIdentifier }]) => [universalIdentifier, name] as const,+ ),+);+const buildApplicationConfig = (manifest: Manifest,): Partial<ApplicationManifest> => {@@ -114,6 +134,60 @@ const getObjectName = ({STANDARD_OBJECT_NAME_BY_UNIVERSAL_IDENTIFIER.get(objectUniversalIdentifier) ??null;+const getPageLayoutName = ({+ pageLayoutUniversalIdentifier,+ manifest,+}: {+ pageLayoutUniversalIdentifier: string;+ manifest: Manifest;+}): string | null => {+ const pageLayoutManifest = manifest.pageLayouts?.find(+ (candidate) =>+ candidate.universalIdentifier === pageLayoutUniversalIdentifier,+ );++ if (isDefined(pageLayoutManifest)) {+ return pageLayoutManifest.name;+ }++ const standardPageLayoutName =+ STANDARD_PAGE_LAYOUT_NAME_BY_UNIVERSAL_IDENTIFIER.get(+ pageLayoutUniversalIdentifier,+ );++ if (isDefined(standardPageLayoutName)) {+ return standardPageLayoutName;+ }++ const objectMetadataApplicationUniversalIdentifier =+ manifest.application.universalIdentifier;++ for (const objectManifest of manifest.objects) {+ const systemPageLayoutUniversalIdentifiers = {+ objectMetadataApplicationUniversalIdentifier,+ objectUniversalIdentifier: objectManifest.universalIdentifier,+ };++ if (+ getSystemRecordPageLayoutUniversalIdentifier(+ systemPageLayoutUniversalIdentifiers,+ ) === pageLayoutUniversalIdentifier+ ) {+ return `${objectManifest.nameSingular}RecordPage`;+ }++ if (+ getSystemRecordFormPageLayoutUniversalIdentifier(+ systemPageLayoutUniversalIdentifiers,+ ) === pageLayoutUniversalIdentifier+ ) {+ return `${objectManifest.nameSingular}RecordForm`;+ }+ }++ return null;+};+export const buildPullEntities = (manifest: Manifest,): { entities: PullEntity[]; skipped: SkippedPullEntity[] } => {@@ -260,5 +334,59 @@ export const buildPullEntities = (});}+ for (const pageLayoutManifest of manifest.pageLayouts ?? []) {+ entities.push({+ kind: 'pageLayout',+ universalIdentifier: pageLayoutManifest.universalIdentifier,+ definer: 'definePageLayout',+ config: stripGraphqlTypename(pageLayoutManifest),+ enumBindings: PAGE_LAYOUT_ENUM_BINDINGS,+ defaultFolder: 'src/page-layouts',+ fileSuffix: '.page-layout.ts',+ fileBaseName: toFileBaseName({+ segments: [pageLayoutManifest.name],+ universalIdentifier: pageLayoutManifest.universalIdentifier,+ }),+ parentName: isDefined(pageLayoutManifest.objectUniversalIdentifier)+ ? getObjectName({+ objectUniversalIdentifier:+ pageLayoutManifest.objectUniversalIdentifier,+ manifest,+ })+ : null,+ });+ }++ for (const pageLayoutTabManifest of manifest.pageLayoutTabs ?? []) {+ const { pageLayoutUniversalIdentifier } = pageLayoutTabManifest;++ if (!isDefined(pageLayoutUniversalIdentifier)) {+ skipped.push({+ kind: 'pageLayoutTab',+ universalIdentifier: pageLayoutTabManifest.universalIdentifier,+ reason: 'it does not name the page layout it belongs to',+ });+ continue;+ }++ entities.push({+ kind: 'pageLayoutTab',+ universalIdentifier: pageLayoutTabManifest.universalIdentifier,+ definer: 'definePageLayoutTab',+ config: stripGraphqlTypename(pageLayoutTabManifest),+ enumBindings: PAGE_LAYOUT_TAB_ENUM_BINDINGS,+ defaultFolder: 'src/page-layout-tabs',+ fileSuffix: '.page-layout-tab.ts',+ fileBaseName: toFileBaseName({+ segments: [pageLayoutTabManifest.title],+ universalIdentifier: pageLayoutTabManifest.universalIdentifier,+ }),+ parentName: getPageLayoutName({+ pageLayoutUniversalIdentifier,+ manifest,+ }),+ });+ }+return { entities, skipped };};diff --git a/packages/twenty-sdk/src/cli/utilities/pull/plan-pull-writes.ts b/packages/twenty-sdk/src/cli/utilities/pull/plan-pull-writes.tsindex bc5234afeb1..17cd73cbd7f 100644--- a/packages/twenty-sdk/src/cli/utilities/pull/plan-pull-writes.ts+++ b/packages/twenty-sdk/src/cli/utilities/pull/plan-pull-writes.ts@@ -44,6 +44,8 @@ const ENTITY_KEY_BY_KIND: Record<PullEntityKind, ManifestEntityKey> = {index: ManifestEntityKey.Indexes,view: ManifestEntityKey.Views,viewField: ManifestEntityKey.ViewFields,+ pageLayout: ManifestEntityKey.PageLayouts,+ pageLayoutTab: ManifestEntityKey.PageLayoutTabs,};const toPosixPath = (value: string): string => value.split('\\').join('/');diff --git a/packages/twenty-sdk/src/cli/utilities/pull/pull-base-file.ts b/packages/twenty-sdk/src/cli/utilities/pull/pull-base-file.tsindex c9a7e68e6bb..4573ba58b7f 100644--- a/packages/twenty-sdk/src/cli/utilities/pull/pull-base-file.ts+++ b/packages/twenty-sdk/src/cli/utilities/pull/pull-base-file.ts@@ -40,8 +40,16 @@ const isUsableBaseManifest = (manifest: unknown): manifest is Manifest => {return false;}- const { application, objects, fields, indexes, views, viewFields } =- manifest as Partial<Manifest>;+ const {+ application,+ objects,+ fields,+ indexes,+ views,+ viewFields,+ pageLayouts,+ pageLayoutTabs,+ } = manifest as Partial<Manifest>;return (hasUniversalIdentifier(application) &&@@ -50,7 +58,9 @@ const isUsableBaseManifest = (manifest: unknown): manifest is Manifest => {fields.every(hasUniversalIdentifier) &&(!isDefined(indexes) || isEntityListWithFields(indexes)) &&(!isDefined(views) || isEntityList(views)) &&- (!isDefined(viewFields) || isEntityList(viewFields))+ (!isDefined(viewFields) || isEntityList(viewFields)) &&+ (!isDefined(pageLayouts) || isEntityList(pageLayouts)) &&+ (!isDefined(pageLayoutTabs) || isEntityList(pageLayoutTabs)));};diff --git a/packages/twenty-sdk/src/cli/utilities/pull/strip-graphql-typename.ts b/packages/twenty-sdk/src/cli/utilities/pull/strip-graphql-typename.tsnew file mode 100644index 00000000000..ee2214ee6e5--- /dev/null+++ b/packages/twenty-sdk/src/cli/utilities/pull/strip-graphql-typename.ts@@ -0,0 +1,17 @@+const GRAPHQL_TYPENAME_KEY = '__typename';++export const stripGraphqlTypename = <TValue>(value: TValue): TValue => {+ if (Array.isArray(value)) {+ return value.map(stripGraphqlTypename) as TValue;+ }++ if (value === null || typeof value !== 'object') {+ return value;+ }++ return Object.fromEntries(+ Object.entries(value)+ .filter(([key]) => key !== GRAPHQL_TYPENAME_KEY)+ .map(([key, entry]) => [key, stripGraphqlTypename(entry)]),+ ) as TValue;+};diff --git a/packages/twenty-sdk/src/cli/utilities/pull/write-define-file.ts b/packages/twenty-sdk/src/cli/utilities/pull/write-define-file.tsindex c3e9b0649a1..202c3ae7461 100644--- a/packages/twenty-sdk/src/cli/utilities/pull/write-define-file.ts+++ b/packages/twenty-sdk/src/cli/utilities/pull/write-define-file.ts@@ -10,6 +10,9 @@ import {MetadataWritability,NumberDataType,ObjectOpenRecordIn,+ ObjectRecordGroupByDateGranularity,+ PageLayoutTabLayoutMode,+ PageLayoutType,RelationOnDeleteAction,RelationType,ViewCalendarLayout,@@ -19,6 +22,7 @@ import {ViewSortDirection,ViewType,ViewVisibility,+ WidgetType,} from 'twenty-shared/types';import { isDefined } from 'twenty-shared/utils';@@ -125,6 +129,46 @@ export const VIEW_ENUM_BINDINGS: EnumBinding[] = [},];+const buildPageLayoutWidgetEnumBindings = (prefix: string[]): EnumBinding[] => [+ { path: [...prefix, 'type'], symbol: 'WidgetType', members: WidgetType },+ {+ path: [...prefix, 'position', 'layoutMode'],+ symbol: 'PageLayoutTabLayoutMode',+ members: PageLayoutTabLayoutMode,+ },+ buildAggregateOperationBinding([+ ...prefix,+ 'configuration',+ 'aggregateOperation',+ ]),+ ...[+ 'dateGranularity',+ 'primaryAxisDateGranularity',+ 'secondaryAxisGroupByDateGranularity',+ ].map((key) => ({+ path: [...prefix, 'configuration', key],+ symbol: 'ObjectRecordGroupByDateGranularity',+ members: ObjectRecordGroupByDateGranularity,+ })),+];++const buildPageLayoutTabEnumBindings = (prefix: string[]): EnumBinding[] => [+ {+ path: [...prefix, 'layoutMode'],+ symbol: 'PageLayoutTabLayoutMode',+ members: PageLayoutTabLayoutMode,+ },+ ...buildPageLayoutWidgetEnumBindings([...prefix, 'widgets', '[]']),+];++export const PAGE_LAYOUT_TAB_ENUM_BINDINGS: EnumBinding[] =+ buildPageLayoutTabEnumBindings([]);++export const PAGE_LAYOUT_ENUM_BINDINGS: EnumBinding[] = [+ { path: ['type'], symbol: 'PageLayoutType', members: PageLayoutType },+ ...buildPageLayoutTabEnumBindings(['tabs', '[]']),+];+const isSamePath = (left: string[], right: string[]): boolean =>left.length === right.length &&left.every((segment, index) => segment === right[index]);diff --git a/packages/twenty-sdk/src/cli/utilities/translations/__tests__/application-translations.spec.ts b/packages/twenty-sdk/src/cli/utilities/translations/__tests__/application-translations.spec.tsindex 6d8c944d76d..ab482c74d7f 100644--- a/packages/twenty-sdk/src/cli/utilities/translations/__tests__/application-translations.spec.ts+++ b/packages/twenty-sdk/src/cli/utilities/translations/__tests__/application-translations.spec.ts@@ -99,7 +99,9 @@ describe('collectTranslatableStrings', () => {],fields: [{ label: 'Thrust', description: 'Newtons' }],views: [{ name: 'All Rockets' }],- pageLayoutTabs: [{ title: 'Telemetry' }],+ pageLayoutTabs: [+ { title: 'Telemetry', widgets: [{ title: 'Trip log' }] },+ ],commandMenuItems: [{ label: 'Launch Rocket', shortLabel: 'Launch' }],navigationMenuItems: [{ name: 'Missions' }],timelineActivityTypes: [{ label: 'Launched a rocket' }],@@ -120,6 +122,7 @@ describe('collectTranslatableStrings', () => {{ message: 'Newtons', context: 'fieldMetadata.description' },{ message: 'All Rockets', context: 'view.name' },{ message: 'Telemetry', context: 'pageLayoutTab.title' },+ { message: 'Trip log', context: 'pageLayoutWidget.title' },{ message: 'Launch Rocket', context: 'commandMenuItem.label' },{ message: 'Launch', context: 'commandMenuItem.shortLabel' },{ message: 'Missions', context: 'navigationMenuItem.name' },diff --git a/packages/twenty-sdk/src/cli/utilities/translations/collect-translatable-strings.ts b/packages/twenty-sdk/src/cli/utilities/translations/collect-translatable-strings.tsindex efebf8814c1..8e6217f2bdf 100644--- a/packages/twenty-sdk/src/cli/utilities/translations/collect-translatable-strings.ts+++ b/packages/twenty-sdk/src/cli/utilities/translations/collect-translatable-strings.ts@@ -88,5 +88,11 @@ export const collectTranslatableStrings = (}}+ for (const pageLayoutTab of manifest.pageLayoutTabs ?? []) {+ for (const widget of pageLayoutTab.widgets ?? []) {+ addEntityStrings(widget, 'pageLayoutWidget');+ }+ }+return [...descriptorByKey.values()];};