The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Write pulled standalone page layout widgets as define files (#25743)
Weiko1f7050e917f8
diff --git a/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdx b/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdxindex a0c9858d333..b4b6ab45f9e 100644--- a/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdx+++ b/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdx@@ -238,4 +238,4 @@ export default definePageLayoutWidget({- `position` is **required**, since the tab is not part of your manifest and its layout mode cannot be inferred. Match the tab's layout mode: record page tabs are vertical lists, so use `{ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST, index }` with an index above the built-in widgets (the Fields widget sits at 0).- `configuration` works exactly like a widget defined inline in `definePageLayout` or `definePageLayoutTab`: it references [front components](/developers/extend/apps/layout/front-components), views, fields and so on.- Use this instead of `definePageLayoutTab` when the tab already exists and you only want to place one widget on it. Use `definePageLayoutTab` when you want a tab of your own.-- `yarn twenty pull` does not write `definePageLayoutWidget()` files yet. A widget on a tab your app does not own is carried by the export but reported rather than written, so keep pushing such a tree with `yarn twenty apply --no-delete`; see [what pull does not write](/developers/extend/apps/operations/sync-and-recovery#pulling-an-installed-app-back-to-source).+- `yarn twenty pull` writes a widget you added to a tab you do not own back as a `definePageLayoutWidget()` file, 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 df199352e23..4f54af4eeb3 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@@ -120,6 +120,7 @@ Pull needs an existing project — scaffold one with `npx create-twenty-app@late- page layouts, with their tabs and widgets inline;- tabs your app added to page layouts it does not own, as standalone `definePageLayoutTab()` files;- navigation menu items, as `defineNavigationMenuItem()` files, folders included;+- widgets your app added to tabs it does not own, as standalone `definePageLayoutWidget()` 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.@@ -129,7 +130,7 @@ Each entity goes to the file that already defines it, so a second pull rewrites- **Not exported yet** — roles and permissions, 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** — a widget added to a tab of an engine default page layout, or of a page layout owned by another application, has a source form, `definePageLayoutWidget()`, and the export carries it, but this version of pull does not write it to a file yet, so it is reported. Tabs added there are written as standalone files, since the layout's identifier is known.+- **Placed on a default or foreign page layout** — tabs and widgets added to an engine default page layout, or to one owned by another application, are written as standalone `definePageLayoutTab()` and `definePageLayoutWidget()` files, since the identifier they attach to 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, per-user navigation and navigation items pinned to a record, 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 fcad03a2da7..06c5d05030e 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@@ -57,6 +57,8 @@ 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 COMPANY_HOME_STANDALONE_WIDGET_UID =+ '38383838-3838-4383-8383-383838383838';const CARE_FOLDER_MENU_ITEM_UID = '35353535-3535-4353-8353-353535353535';const PET_MENU_ITEM_UID = '36363636-3636-4363-8363-363636363636';const HANDBOOK_MENU_ITEM_UID = '37373737-3737-4373-8373-373737373737';@@ -472,6 +474,19 @@ const EXPORTED_MANIFEST = {],},],+ pageLayoutWidgets: [+ {+ universalIdentifier: COMPANY_HOME_STANDALONE_WIDGET_UID,+ pageLayoutTabUniversalIdentifier: COMPANY_TAGLINE_TAB_UID,+ title: 'Care notes',+ type: 'IFRAME',+ position: { layoutMode: 'VERTICAL_LIST', index: 1000 },+ configuration: {+ configurationType: 'IFRAME',+ url: 'https://example.com/care-notes',+ },+ },+ ],pageLayoutTabs: [{universalIdentifier: PET_RECORD_PAGE_EXTRA_TAB_UID,@@ -681,6 +696,18 @@ describe('pull round trip', () => {);});+ it('should rebuild the standalone page layout widget unchanged', () => {+ expect(+ canonicalize(+ sortByUniversalIdentifier(builtManifest?.pageLayoutWidgets ?? []),+ ),+ ).toEqual(+ canonicalize(+ sortByUniversalIdentifier(EXPORTED_MANIFEST.pageLayoutWidgets),+ ),+ );+ });+it('should rebuild the standalone tabs on the pet record page and the company record page unchanged', () => {expect(canonicalize(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 8d649f519e3..b69882a1af9 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@@ -868,6 +868,43 @@ describe('buildPullEntities', () => {expect(navigationMenuItem?.parentName).toBeNull();});+ it('should write a standalone page layout widget into src/page-layout-widgets, named after its title', () => {+ const { entities, skipped } = buildPullEntities(+ buildManifest({+ pageLayoutWidgets: [+ {+ universalIdentifier: WIDGET_UID,+ pageLayoutTabUniversalIdentifier: PAGE_LAYOUT_TAB_UID,+ title: 'Care notes',+ type: 'IFRAME',+ objectUniversalIdentifier: PET_UID,+ position: {+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ index: 1000,+ },+ configuration: {+ configurationType: 'IFRAME',+ url: 'https://example.com/docs',+ __typename: 'IframeConfiguration',+ },+ },+ ],+ } as unknown as Partial<Manifest>),+ );+ const widget = entities.find(+ (entity) => entity.kind === 'pageLayoutWidget',+ );++ expect(skipped).toEqual([]);+ expect(widget?.definer).toBe('definePageLayoutWidget');+ expect(+ `${widget?.defaultFolder}/${widget?.fileBaseName}${widget?.fileSuffix}`,+ ).toBe('src/page-layout-widgets/care-notes.page-layout-widget.ts');+ expect(widget?.parentName).toBe('pet');+ expect(widget?.config).not.toHaveProperty('configuration.__typename');+ expect(JSON.stringify(widget?.config)).not.toContain('__typename');+ });+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,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 a49ae7e7952..7acb71b1dce 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@@ -282,6 +282,21 @@ describe('pull base file', () => {expect(await readBase()).toBeNull();});+ it('should ignore a base whose page layout widgets are not a list', async () => {+ await writeRawBaseFile(+ JSON.stringify({+ version: 1,+ applicationUniversalIdentifier: APP_UID,+ manifest: {+ ...MANIFEST,+ pageLayoutWidgets: { 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/build-pull-entities.ts b/packages/twenty-sdk/src/cli/utilities/pull/build-pull-entities.tsindex 5b0868bbb5e..a0e519bdf2f 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,7 @@ import {FIELD_ENUM_BINDINGS,INDEX_ENUM_BINDINGS,NAVIGATION_MENU_ITEM_ENUM_BINDINGS,+ PAGE_LAYOUT_WIDGET_ENUM_BINDINGS,OBJECT_ENUM_BINDINGS,PAGE_LAYOUT_ENUM_BINDINGS,PAGE_LAYOUT_TAB_ENUM_BINDINGS,@@ -43,6 +44,7 @@ export const PULL_ENTITY_KINDS = ['pageLayout','pageLayoutTab','navigationMenuItem',+ 'pageLayoutWidget',] as const;export type PullEntityKind = (typeof PULL_ENTITY_KINDS)[number];@@ -503,5 +505,26 @@ export const buildPullEntities = (});}+ for (const pageLayoutWidgetManifest of manifest.pageLayoutWidgets ?? []) {+ const { objectUniversalIdentifier } = pageLayoutWidgetManifest;++ entities.push({+ kind: 'pageLayoutWidget',+ universalIdentifier: pageLayoutWidgetManifest.universalIdentifier,+ definer: 'definePageLayoutWidget',+ config: stripGraphqlTypename(pageLayoutWidgetManifest),+ enumBindings: PAGE_LAYOUT_WIDGET_ENUM_BINDINGS,+ defaultFolder: 'src/page-layout-widgets',+ fileSuffix: '.page-layout-widget.ts',+ fileBaseName: toFileBaseName({+ segments: [pageLayoutWidgetManifest.title],+ universalIdentifier: pageLayoutWidgetManifest.universalIdentifier,+ }),+ parentName: isDefined(objectUniversalIdentifier)+ ? getObjectName({ objectUniversalIdentifier, manifest })+ : null,+ });+ }+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 f2723f179e3..8835fdbeeef 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@@ -47,6 +47,7 @@ const ENTITY_KEY_BY_KIND: Record<PullEntityKind, ManifestEntityKey> = {pageLayout: ManifestEntityKey.PageLayouts,pageLayoutTab: ManifestEntityKey.PageLayoutTabs,navigationMenuItem: ManifestEntityKey.NavigationMenuItems,+ pageLayoutWidget: ManifestEntityKey.PageLayoutWidgets,};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 3222210b942..9e9b6d1ba94 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@@ -49,6 +49,7 @@ const isUsableBaseManifest = (manifest: unknown): manifest is Manifest => {viewFields,pageLayouts,pageLayoutTabs,+ pageLayoutWidgets,navigationMenuItems,} = manifest as Partial<Manifest>;@@ -62,6 +63,7 @@ const isUsableBaseManifest = (manifest: unknown): manifest is Manifest => {(!isDefined(viewFields) || isEntityList(viewFields)) &&(!isDefined(pageLayouts) || isEntityList(pageLayouts)) &&(!isDefined(pageLayoutTabs) || isEntityList(pageLayoutTabs)) &&+ (!isDefined(pageLayoutWidgets) || isEntityList(pageLayoutWidgets)) &&(!isDefined(navigationMenuItems) || isEntityList(navigationMenuItems)));};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 32e946db96b..cf43b3c7a04 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@@ -162,6 +162,9 @@ const buildPageLayoutTabEnumBindings = (prefix: string[]): EnumBinding[] => [...buildPageLayoutWidgetEnumBindings([...prefix, 'widgets', '[]']),];+export const PAGE_LAYOUT_WIDGET_ENUM_BINDINGS: EnumBinding[] =+ buildPageLayoutWidgetEnumBindings([]);+export const PAGE_LAYOUT_TAB_ENUM_BINDINGS: EnumBinding[] =buildPageLayoutTabEnumBindings([]);