Page Layout Customization
Relevant source files
The following files were used as context for generating this wiki page:
- packages/twenty-server/src/engine/metadata-modules/page-layout/entities/page-layout.entity.ts
- packages/twenty-server/src/engine/metadata-modules/page-layout/services/tests/page-layout.service.spec.ts
- packages/twenty-server/test/integration/graphql/suites/page-layout/page-layout-resolver.integration-spec.ts
- packages/twenty-server/test/integration/graphql/suites/page-layout/page-layout-update-with-tabs-and-widgets.integration-spec.ts
- packages/twenty-server/test/integration/rest/suites/page-layout.integration-spec.ts
- packages/twenty-server/test/integration/rest/suites/page-layout-widget.integration-spec.ts
- packages/twenty-front/src/modules/command-menu/components/CommandMenuPageLayoutInfo.tsx
- README.md
Page Layout Customization is a core feature of Twenty that allows users to create and personalize the structure and content of different pages within the CRM. Inspired by the flexibility of modern tools, this system enables the arrangement of information through a hierarchical structure of layouts, tabs, and widgets. This provides a tailored user experience for viewing and interacting with CRM data, such as on record detail pages, index pages, and dashboards.
The system is designed with a clear separation between the backend, which manages the data structure and business logic, and the frontend, which handles rendering and user interaction. The backend exposes both REST and GraphQL APIs for comprehensive management of layouts and their components.
Backend Architecture
The backend is responsible for storing, managing, and serving page layout configurations. It uses a set of TypeORM entities to model the layout structure and provides services and controllers to handle business logic and API requests.
Data Model
The page layout system is built around three primary entities: PageLayout, PageLayoutTab, and PageLayoutWidget. These entities are linked in a hierarchical relationship.
The diagram below illustrates the relationship between the core page layout entities.
PageLayout Entity
This is the top-level entity that defines a layout.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the page layout. |
name | string | The user-defined name of the layout. |
type | PageLayoutType | The type of layout. See PageLayoutType Enum table below. |
objectMetadataId | string (nullable) | A foreign key linking the layout to a specific object type (e.g., Company, Deal). Can be null for global layouts like dashboards. |
workspaceId | string | The workspace this layout belongs to. |
tabs | PageLayoutTab[] | A one-to-many relation to the tabs contained within this layout. |
Sources: packages/twenty-server/src/engine/metadata-modules/page-layout/entities/page-layout.entity.ts:16-49
PageLayoutType Enum
This enum specifies the context in which a page layout is used.
| Value | Description |
|---|---|
RECORD_PAGE | For the detail view of a single record. |
RECORD_INDEX | For the list or index view of multiple records. |
DASHBOARD | For a dashboard page. |
Sources: packages/twenty-server/src/engine/metadata-modules/page-layout/entities/page-layout.entity.ts:8-12
PageLayoutWidget Entity
Widgets are the individual content blocks within a tab.
| Field | Type | Description |
|---|---|---|
id | string | Unique identifier for the widget. |
pageLayoutTabId | string | Foreign key to the parent PageLayoutTab. |
title | string | The display title of the widget. |
type | WidgetType | The type of widget. See WidgetType Enum table below. |
gridPosition | jsonb | An object defining the widget's position and size on a grid (e.g., { row, column, rowSpan, columnSpan }). |
configuration | jsonb (nullable) | Type-specific configuration for the widget (e.g., a URL for an IFRAME widget). |
Sources: packages/twenty-server/test/integration/rest/suites/page-layout-widget.integration-spec.ts:192-203, packages/twenty-server/test/integration/graphql/suites/page-layout/page-layout-update-with-tabs-and-widgets.integration-spec.ts:205-219
WidgetType Enum
This enum defines the different kinds of widgets available.
| Value | Description |
|---|---|
VIEW | Displays a view of records. |
GRAPH | Displays a chart or graph visualization. |
IFRAME | Embeds external content via an iframe. |
FIELDS | Displays a set of fields for a record. |
Sources: packages/twenty-server/src/engine/metadata-modules/page-layout/enums/widget-type.enum.ts, packages/twenty-server/test/integration/graphql/suites/page-layout/page-layout-update-with-tabs-and-widgets.integration-spec.ts:42-43
Services
Business logic for managing page layouts and their components is encapsulated in services.
PageLayoutService: Handles all CRUD (Create, Read, Update, Delete) operations forPageLayoutentities. It includes methods likecreate,update,delete,destroy,restore, and various finders (findByWorkspaceId,findByObjectMetadataId).PageLayoutWidgetService: ManagesPageLayoutWidgetentities. It contains logic for creating, updating, and deleting widgets, and includes validation to ensure that a widget is associated with a valid, existing tab.
Sources: packages/twenty-server/src/engine/metadata-modules/page-layout/services/tests/page-layout.service.spec.ts, packages/twenty-server/src/engine/metadata-modules/page-layout/services/tests/page-layout-widget.service.spec.ts
API Endpoints
The backend provides both GraphQL and RESTful APIs for interacting with the page layout system.
GraphQL API
The GraphQL API offers powerful mutations for complex, transactional updates, as well as queries for fetching layout data.
| Operation | Type | Description |
|---|---|---|
getPageLayouts | Query | Retrieves a list of page layouts, optionally filtered by objectMetadataId. |
getPageLayout | Query | Retrieves a single page layout by its ID. |
createPageLayout | Mutation | Creates a new page layout. |
updatePageLayout | Mutation | Updates the properties of an existing page layout. |
updatePageLayoutWithTabsAndWidgets | Mutation | A transactional mutation to create, update, and delete a page layout, its tabs, and its widgets in a single operation. |
deletePageLayout | Mutation | Soft-deletes a page layout. |
destroyPageLayout | Mutation | Permanently deletes a page layout and its associated components. |
restorePageLayout | Mutation | Restores a soft-deleted page layout. |
Sources: packages/twenty-server/test/integration/graphql/suites/page-layout/page-layout-resolver.integration-spec.ts, packages/twenty-server/test/integration/graphql/suites/page-layout/page-layout-update-with-tabs-and-widgets.integration-spec.ts
The sequence diagram below shows the flow for the updatePageLayoutWithTabsAndWidgets mutation, highlighting its transactional nature.
REST API
A set of REST endpoints is available for more traditional client-server interactions.
Page Layouts
| Method | Endpoint | Description |
|---|---|---|
GET | /rest/metadata/pageLayouts | Get all layouts. Can be filtered by objectMetadataId. |
POST | /rest/metadata/pageLayouts | Create a new layout. |
GET | /rest/metadata/pageLayouts/:id | Get a specific layout by ID. |
PATCH | /rest/metadata/pageLayouts/:id | Update a layout. |
DELETE | /rest/metadata/pageLayouts/:id | Delete a layout. |
Sources: packages/twenty-server/test/integration/rest/suites/page-layout.integration-spec.ts
Page Layout Widgets
| Method | Endpoint | Description |
|---|---|---|
GET | /rest/metadata/pageLayoutWidgets | Get all widgets for a given pageLayoutTabId (required query param). |
POST | /rest/metadata/pageLayoutWidgets | Create a new widget. |
GET | /rest/metadata/pageLayoutWidgets/:id | Get a specific widget by ID. |
PATCH | /rest/metadata/pageLayoutWidgets/:id | Update a widget. |
DELETE | /rest/metadata/pageLayoutWidgets/:id | Delete a widget. |
Sources: packages/twenty-server/test/integration/rest/suites/page-layout-widget.integration-spec.ts
Frontend Architecture
The frontend is responsible for rendering the layouts defined by the backend and providing the user interface for customization.
State Management
The frontend uses Recoil for state management, particularly during the editing process. This allows for a non-destructive editing experience where changes are held in a draft state before being saved.
pageLayoutDraftComponentState: Holds the draft version of the page layout being edited.pageLayoutEditingWidgetIdComponentState: Tracks the ID of the widget currently being edited.pageLayoutTabSettingsOpenTabIdComponentState: Keeps track of which tab's settings are currently open.
Sources: packages/twenty-front/src/modules/command-menu/components/CommandMenuPageLayoutInfo.tsx:13-24
Key Components and Hooks
PageLayoutRenderer: A React component responsible for taking the page layout data structure and rendering the corresponding tabs and widgets.CommandMenuPageLayoutInfo: A component within the command menu that displays information about the current layout, tab, or widget being edited. It allows users to change titles directly from the command menu.useUpdatePageLayoutTab: A React hook that provides a function to update the properties of a specific tab (e.g., its title).useUpdatePageLayoutWidget: A React hook that provides a function to update the properties of a specific widget.
Sources: packages/twenty-front/src/modules/command-menu/components/CommandMenuPageLayoutInfo.tsx:8-11, 29-30
The following diagram shows the flow of updating a widget's title from the frontend.
Summary
The Page Layout Customization feature is a cornerstone of Twenty's flexible and user-centric design. It employs a robust, three-tiered data model on the backend (PageLayout, PageLayoutTab, PageLayoutWidget) and provides comprehensive management through both GraphQL and REST APIs. The frontend leverages a component-based architecture with Recoil for state management, enabling a dynamic and responsive editing experience. This combination allows users to effectively personalize how they view and interact with their data, fulfilling a key goal of the Twenty project.
Sources: README.md:27-28