[BREAKING-CHANGE] Centralize system View viewField side effect (#23081)
# Introduction Closes https://github.com/twentyhq/core-team-issues/issues/2669 Part of the `isSystemSideEffect` engine-ownership effort. Until now, a custom object's default **INDEX** table view (`All {objectLabelPlural}`) and its view fields were built imperatively in `ObjectMetadataService` with random `v4()` identifiers, while `twenty-standard` authored its own copies with hardcoded literals. The two never converged, an object rename could drift the view, and nothing marked these rows as engine-owned. This PR makes the metadata side-effect engine the **single owner** of the INDEX view and its view fields, on name-free deterministic identifiers, for custom and standard objects alike. ## Core design - **Name-free deterministic identity.** The INDEX view identifier derives from `object identifier + ViewKey.INDEX` (`getSystemViewUniversalIdentifier`); each view-field identifier derives from `view identifier + field identifier` (`getViewFieldUniversalIdentifier`). An object rename (with a pinned object identifier) keeps the same view, losslessly. - **`isSystemSideEffect: true` is provenance.** Every INDEX view / view field the engine emits is flagged system-owned, so manifest deletion inference never drops it. The flag follows the view: a view field inherits its parent view's flag. - **The engine is the sole owner of the INDEX view.** It always emits it; a caller providing one with the same derived identifier is a genuine conflict surfaced by the engine's reserved-identifier collision, not silently deferred. ## Changes ### Shared (`twenty-shared`) - `getIndexViewUniversalIdentifier` → `getSystemViewUniversalIdentifier`, now taking a `viewKey` (generalizes to any singleton engine-owned view). - Standard field identifiers extracted into a new `STANDARD_OBJECT_FIELDS` constant, so both an object's `fields` and its INDEX view read the same field identifiers. - `buildStandardObjectIndexView` derives the standard INDEX view + view-field identifiers from `STANDARD_OBJECT_FIELDS`, replacing the hardcoded literals in `standard-object.constant.ts`. ### Metadata side-effect engine (custom objects) - **`objectSystemFieldsAndIndexViewOnCreate`** (replaces `objectSystemFieldsOnCreate`): on object creation, provisions the 7 reserved system fields **and** the INDEX view with one view field per displayable system field, all `isSystemSideEffect: true`. - **`fieldIndexViewFieldOnCreate`** (new): on field creation, provisions the field's INDEX view field. Object created in the same batch → visible, positioned before the system view fields; pre-existing object → hidden, appended (preserving the historical `createOneField` behavior). Both branches resolve the INDEX view by its derived identifier (single map access, never a scan). - **`fieldSystemViewFieldsOnDelete`** (new): on field deletion, cascade-deletes every engine-owned view field displaying it. - **`objectSystemSideEffectsOnDelete`** (extended): now also cascade-deletes the object's engine-owned views and their view fields (in addition to system fields, indexes, searchFieldMetadata). Every lookup walks a foreign-key aggregator down from the deleted object, so the work is proportional to what the object owns, never to workspace size. - Object-create and field-create positions are derived from the same caller-input field list, so the INDEX view layout is contiguous with no handler-ordering dependency. - `view` / `viewField` added to the side-effect companion metadata names for `fieldMetadata` and `objectMetadata`. ### Reserved-identifier invariant A caller can never define an entity whose identifier collides with one a system side effect produces: caller inputs are forced `isSystemSideEffect: false` at every entry point (API and app-manifest transpilers), and the engine raises `RESERVED_SYSTEM_UNIVERSAL_IDENTIFIER`, aborting the operation, when a system emission lands on a caller-claimed identifier. Covered by a new engine-level test. ### Caller-side provisioning removed The imperative INDEX view + view-field provisioning is removed from `ObjectMetadataService.createOneObject`. The record-page `FIELDS_WIDGET` view is intentionally left caller-side and deferred to the follow-up (see below). ### `twenty-standard` convergence Standard INDEX views and their view fields converge on the same derived-identifier + `isSystemSideEffect: true` scheme as the engine. `twenty-standard` syncs through the from/to migration path (which never runs the side-effect engine), so it authors this INDEX surface itself, matching what the engine produces for custom objects. ## Rollout Two `2.26.0` workspace commands, running after the `2.25` messageCampaign commands: - `upgrade:2-26:reconcile-index-view-universal-identifier` re-owns the INDEX views of the **twenty-standard and workspace-custom applications** and all their view fields to the derived identifiers with `isSystemSideEffect: true`, in a single per-workspace transaction. Each view field identifier is keyed on the application of the **displayed field** (an app or user column on a standard INDEX view converges too). Soft-deleted views and view fields are skipped: one can coexist with an active successor on the same derivation inputs and both would derive the same identifier. Children reference the view by primary key, so the re-own is lossless. - `upgrade:2-26:demote-and-backfill-application-index-view` handles **manifest-installed applications**, which never had their INDEX view auto-provisioned: every caller-authored INDEX view of another application is demoted to `key: null` (a plain additional view under its manifest identifier), then every application object gets the engine-owned INDEX view and its full view-field layout backfilled through the migration pipeline's legacy path (no side-effect expansion), views committed before view fields across applications since a view field belongs to the application owning its field. Idempotent and retry-safe: engine-owned INDEX views are neither demoted nor re-backfilled, and view creation and view-field creation are gated independently, so a retry after a partial failure still backfills the missing view fields of an already-committed view. Both support `--dry-run` and invalidate the full flat-maps closure (parents aggregate the re-owned identifiers, children resolve them as universal foreign keys, and page-layout widget universal configurations resolve view PKs at cache-build time). The `2.25` `upgrade:2-25:add-message-campaign-name-field` command is adapted to resolve the campaign INDEX view by its INDEX key on the object instead of by universal identifier: it now runs before the reconcile, on workspaces still holding legacy identifiers. ## ⚠️ Breaking change This PR **mutates 187 previously hardcoded universal identifiers** — the standard objects' INDEX views and their view fields (the literals removed from `standard-object.constant.ts`), now derived. - **Handled by the `2.26` commands above** for all existing workspaces. - **The INDEX key is now engine-reserved.** The flat view validator rejects caller-created INDEX views (API and manifest inputs are forced `isSystemSideEffect: false`) and enforces a single non-deleted INDEX view per object; `view.key` is no longer a comparable/updatable property, so no writer can promote or demote a view after creation. `ViewManifest.key` is deprecated and ignored (manifest views are always additional views, so old apps keep syncing and demoted views are not promoted back); the REST/GraphQL create path now rejects `key: INDEX`. In-repo example apps (`hello-world`, `document-generator`) no longer declare it. - **12 declared-but-never-seeded standard INDEX view field identifiers deleted** (the former `preservedViewFields` on `timelineActivity`, `workflowRun` and `workspaceMember`): after the reconcile, no workspace row references them. - **`computeFlatViewFieldsToCreate` now derives view field identifiers** instead of drawing `v4()` ones, which also changes what the committed `1-23` record-page backfill produces going forward (deliberate, documented in-code). - **Record-page views and view fields are not affected** (identifiers unchanged). - **In-repo apps: `twenty-last-contact` updated.** It was the only app declaring explicit INDEX view fields (10 columns across `allPeople` / `allCompanies` / `allOpportunities`) through manifest `viewFields`. Those target identifiers are now engine-owned and derived, so the manifest inputs no longer resolve and install failed with `View not found`. The app now declares only its fields; the engine's `fieldIndexViewFieldOnCreate` provisions the matching INDEX view field automatically. No other app under `packages/twenty-apps` references any of the 187 mutated identifiers, and apps that target standard views point at record-page views (e.g. `real-estate` → `opportunityRecordPageFields`) or their own objects (`twenty-partners`), all unchanged. ### Loss of granularity for app maintainers The engine now owns the INDEX view field of every field a caller adds to an object, so app maintainers lose direct control over those columns. Previously an app could target the engine-owned INDEX view with an explicit manifest `viewField` and set its `position` and `isVisible`. Now `fieldIndexViewFieldOnCreate` appends a **hidden** view field in caller-input order on field creation, so: - Columns an app previously showed at a **dedicated position** and **visible** (e.g. `twenty-last-contact`'s last-contact columns) become **hidden** and **appended in input order** after install. - There is currently **no manifest way to override** the engine-provisioned INDEX view field's position, visibility, or size. This is a deliberate regression accepted for the sake of single-ownership, and app maintainers should expect their INDEX columns to move/hide after upgrading. A follow-up override API will let maintainers reclaim per-field control over the engine-provisioned INDEX view field. ## Testing - Unit specs for each handler: object create (system fields + INDEX view/view fields, override, position offset), field create (same-batch vs existing-object, non-displayable noop, no-INDEX-view noop), field delete, object delete (fields/indexes/searchFieldMetadata/views/view fields cascade, reverse-relation view field on another object). - Engine-level test for the reserved-identifier collision. - `twenty-standard` guard test that its INDEX views/view fields stay on the derived scheme and stay system-owned. - Integration test: full engine provisioning of the INDEX view/view fields on object creation, same view id preserved across an object rename, and cascade delete on object deletion. ## Follow-up The full record-page stack (record-page view, its view fields, view field groups, page layout / tab / widget) is still built imperatively and moves into the engine in https://github.com/twentyhq/core-team-issues/issues/2721.
This commit is contained in:
+75
@@ -0,0 +1,75 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Failing manifest update - standalone view fields on existing views rejects a standalone view field whose target view does not exist 1`] = `
|
||||
{
|
||||
"extensions": {
|
||||
"code": "METADATA_VALIDATION_FAILED",
|
||||
"errors": {
|
||||
"viewField": [
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": "INVALID_VIEW_DATA",
|
||||
"message": "View not found",
|
||||
"userFriendlyMessage": "View not found",
|
||||
},
|
||||
],
|
||||
"flatEntityMinimalInformation": {
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"universalIdentifier": Any<String>,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"status": "fail",
|
||||
"type": "create",
|
||||
},
|
||||
],
|
||||
},
|
||||
"message": "Validation failed for 1 viewField",
|
||||
"summary": {
|
||||
"totalErrors": 1,
|
||||
"viewField": 1,
|
||||
},
|
||||
"userFriendlyMessage": "View not found",
|
||||
},
|
||||
"message": "Validation errors occurred while syncing application manifest metadata",
|
||||
"name": "GraphQLError",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`Failing manifest update - standalone view fields on existing views rejects two standalone view fields targeting the same field on the same view 1`] = `
|
||||
{
|
||||
"extensions": {
|
||||
"code": "METADATA_VALIDATION_FAILED",
|
||||
"errors": {
|
||||
"viewField": [
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": "INVALID_VIEW_DATA",
|
||||
"message": "View field with same fieldMetadataUniversalIdentifier and viewUniversalIdentifier already exists",
|
||||
"userFriendlyMessage": "View field already exists",
|
||||
},
|
||||
],
|
||||
"flatEntityMinimalInformation": {
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"universalIdentifier": Any<String>,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"status": "fail",
|
||||
"type": "create",
|
||||
},
|
||||
],
|
||||
},
|
||||
"message": "Validation failed for 1 viewField",
|
||||
"summary": {
|
||||
"totalErrors": 1,
|
||||
"viewField": 1,
|
||||
},
|
||||
"userFriendlyMessage": "View field already exists",
|
||||
},
|
||||
"message": "Validation errors occurred while syncing application manifest metadata",
|
||||
"name": "GraphQLError",
|
||||
}
|
||||
`;
|
||||
+23
-3
@@ -62,13 +62,33 @@ exports[`Sync application should reject hijacking the searchVector system field
|
||||
"type": "create",
|
||||
},
|
||||
],
|
||||
"viewField": [
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": "INVALID_VIEW_DATA",
|
||||
"message": "Field metadata not found",
|
||||
"userFriendlyMessage": "Field metadata not found",
|
||||
},
|
||||
],
|
||||
"flatEntityMinimalInformation": {
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"universalIdentifier": Any<String>,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"status": "fail",
|
||||
"type": "create",
|
||||
},
|
||||
],
|
||||
},
|
||||
"message": "Validation failed for 1 fieldMetadata",
|
||||
"message": "Validation failed for 1 fieldMetadata, 1 viewField",
|
||||
"summary": {
|
||||
"fieldMetadata": 1,
|
||||
"totalErrors": 1,
|
||||
"totalErrors": 2,
|
||||
"viewField": 1,
|
||||
},
|
||||
"userFriendlyMessage": "Name "searchVector" is not available as it is already used by another field",
|
||||
"userFriendlyMessage": "Many validation errors",
|
||||
},
|
||||
"message": "Validation errors occurred while syncing application manifest metadata",
|
||||
"name": "GraphQLError",
|
||||
|
||||
+391
-1
@@ -35,6 +35,27 @@ exports[`syncApplication should create a TEXT field on the standard Company obje
|
||||
"metadataName": "fieldMetadata",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": false,
|
||||
"position": 14,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
@@ -738,6 +759,168 @@ exports[`syncApplication should delete old field and create equivalent one when
|
||||
"metadataName": "index",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"anyFieldFilterValue": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"calendarEndFieldMetadataUniversalIdentifier": null,
|
||||
"calendarFieldMetadataUniversalIdentifier": null,
|
||||
"calendarLayout": null,
|
||||
"createdAt": Any<String>,
|
||||
"createdByUserWorkspaceId": null,
|
||||
"deletedAt": null,
|
||||
"icon": "IconList",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
"isCompact": false,
|
||||
"isCustom": true,
|
||||
"isSystemSideEffect": true,
|
||||
"kanbanAggregateOperation": null,
|
||||
"kanbanAggregateOperationFieldMetadataUniversalIdentifier": null,
|
||||
"kanbanColumnWidth": null,
|
||||
"key": "INDEX",
|
||||
"mainGroupByFieldMetadataUniversalIdentifier": null,
|
||||
"name": "All {objectLabelPlural}",
|
||||
"objectMetadataUniversalIdentifier": Any<String>,
|
||||
"openRecordIn": "SIDE_PANEL",
|
||||
"position": 0,
|
||||
"shouldHideEmptyGroups": false,
|
||||
"type": "TABLE",
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"visibility": "WORKSPACE",
|
||||
},
|
||||
"id": Any<String>,
|
||||
"metadataName": "view",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 1,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 0,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 2,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 3,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 4,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 5,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
@@ -803,7 +986,9 @@ exports[`syncApplication should delete old field and create equivalent one when
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalSettings": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldUniversalIdentifiers": [],
|
||||
"viewFieldUniversalIdentifiers": [
|
||||
"da099a9e-dfb5-5eb3-bc29-e7a789e4b765",
|
||||
],
|
||||
"viewFilterUniversalIdentifiers": [],
|
||||
"viewSortUniversalIdentifiers": [],
|
||||
},
|
||||
@@ -842,6 +1027,49 @@ exports[`syncApplication should delete old field and create equivalent one when
|
||||
"metadataName": "fieldMetadata",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 1,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "delete",
|
||||
"universalIdentifier": Any<String>,
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": false,
|
||||
"position": 6,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
],
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
},
|
||||
@@ -1522,6 +1750,168 @@ exports[`syncApplication should return workspace migration actions on initial sy
|
||||
"metadataName": "index",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"anyFieldFilterValue": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"calendarEndFieldMetadataUniversalIdentifier": null,
|
||||
"calendarFieldMetadataUniversalIdentifier": null,
|
||||
"calendarLayout": null,
|
||||
"createdAt": Any<String>,
|
||||
"createdByUserWorkspaceId": null,
|
||||
"deletedAt": null,
|
||||
"icon": "IconList",
|
||||
"id": Any<String>,
|
||||
"isActive": true,
|
||||
"isCompact": false,
|
||||
"isCustom": true,
|
||||
"isSystemSideEffect": true,
|
||||
"kanbanAggregateOperation": null,
|
||||
"kanbanAggregateOperationFieldMetadataUniversalIdentifier": null,
|
||||
"kanbanColumnWidth": null,
|
||||
"key": "INDEX",
|
||||
"mainGroupByFieldMetadataUniversalIdentifier": null,
|
||||
"name": "All {objectLabelPlural}",
|
||||
"objectMetadataUniversalIdentifier": Any<String>,
|
||||
"openRecordIn": "SIDE_PANEL",
|
||||
"position": 0,
|
||||
"shouldHideEmptyGroups": false,
|
||||
"type": "TABLE",
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"visibility": "WORKSPACE",
|
||||
},
|
||||
"id": Any<String>,
|
||||
"metadataName": "view",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 1,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 0,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 2,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 3,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 4,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"aggregateOperation": null,
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
"createdAt": Any<String>,
|
||||
"deletedAt": null,
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"isActive": true,
|
||||
"isSystemSideEffect": true,
|
||||
"isVisible": true,
|
||||
"position": 5,
|
||||
"size": 180,
|
||||
"universalIdentifier": Any<String>,
|
||||
"universalOverrides": null,
|
||||
"updatedAt": Any<String>,
|
||||
"viewFieldGroupUniversalIdentifier": null,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"flatEntity": {
|
||||
"applicationUniversalIdentifier": Any<String>,
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
import { expectOneNotInternalServerErrorSnapshot } from 'test/integration/graphql/utils/expect-one-not-internal-server-error-snapshot.util';
|
||||
import { buildBaseManifest } from 'test/integration/metadata/suites/application/utils/build-base-manifest.util';
|
||||
import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
|
||||
import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';
|
||||
import { syncApplication } from 'test/integration/metadata/suites/application/utils/sync-application.util';
|
||||
import { type FieldManifest, type Manifest } from 'twenty-shared/application';
|
||||
import { STANDARD_OBJECTS } from 'twenty-shared/metadata';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const TEST_APP_ID = uuidv4();
|
||||
const TEST_ROLE_ID = uuidv4();
|
||||
const TEST_FIELD_ID = uuidv4();
|
||||
const TEST_VIEW_FIELD_ID = uuidv4();
|
||||
const TEST_SECOND_VIEW_FIELD_ID = uuidv4();
|
||||
|
||||
const PERSON_OBJECT_UNIVERSAL_IDENTIFIER =
|
||||
STANDARD_OBJECTS.person.universalIdentifier;
|
||||
const PERSON_RECORD_PAGE_VIEW_UNIVERSAL_IDENTIFIER =
|
||||
STANDARD_OBJECTS.person.views.personRecordPageFields.universalIdentifier;
|
||||
const PERSON_RECORD_PAGE_GENERAL_GROUP_UNIVERSAL_IDENTIFIER =
|
||||
STANDARD_OBJECTS.person.views.personRecordPageFields.viewFieldGroups.general
|
||||
.universalIdentifier;
|
||||
|
||||
const CUSTOM_FIELD_NAME = 'integrationContributedColumn';
|
||||
|
||||
const personFieldManifest: FieldManifest = {
|
||||
universalIdentifier: TEST_FIELD_ID,
|
||||
type: FieldMetadataType.TEXT,
|
||||
name: CUSTOM_FIELD_NAME,
|
||||
label: 'Integration Contributed Column',
|
||||
description: 'Custom field contributed to the standard Person object',
|
||||
icon: 'IconStar',
|
||||
objectUniversalIdentifier: PERSON_OBJECT_UNIVERSAL_IDENTIFIER,
|
||||
};
|
||||
|
||||
const buildManifest = (
|
||||
overrides?: Partial<Pick<Manifest, 'fields' | 'viewFields'>>,
|
||||
) =>
|
||||
buildBaseManifest({
|
||||
appId: TEST_APP_ID,
|
||||
roleId: TEST_ROLE_ID,
|
||||
overrides,
|
||||
});
|
||||
|
||||
describe('Failing manifest update - standalone view fields on existing views', () => {
|
||||
beforeEach(async () => {
|
||||
await setupApplicationForSync({
|
||||
applicationUniversalIdentifier: TEST_APP_ID,
|
||||
name: 'Test Application',
|
||||
description: 'App for testing standalone view field manifest updates',
|
||||
sourcePath: 'test-manifest-update-view-field',
|
||||
});
|
||||
}, 60000);
|
||||
|
||||
afterEach(async () => {
|
||||
await cleanupApplicationAndAppRegistration({
|
||||
applicationUniversalIdentifier: TEST_APP_ID,
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects two standalone view fields targeting the same field on the same view', async () => {
|
||||
const { errors } = await syncApplication({
|
||||
manifest: buildManifest({
|
||||
fields: [personFieldManifest],
|
||||
viewFields: [
|
||||
{
|
||||
universalIdentifier: TEST_VIEW_FIELD_ID,
|
||||
viewUniversalIdentifier:
|
||||
PERSON_RECORD_PAGE_VIEW_UNIVERSAL_IDENTIFIER,
|
||||
viewFieldGroupUniversalIdentifier:
|
||||
PERSON_RECORD_PAGE_GENERAL_GROUP_UNIVERSAL_IDENTIFIER,
|
||||
fieldMetadataUniversalIdentifier: TEST_FIELD_ID,
|
||||
position: 10,
|
||||
isVisible: true,
|
||||
},
|
||||
{
|
||||
universalIdentifier: TEST_SECOND_VIEW_FIELD_ID,
|
||||
viewUniversalIdentifier:
|
||||
PERSON_RECORD_PAGE_VIEW_UNIVERSAL_IDENTIFIER,
|
||||
viewFieldGroupUniversalIdentifier:
|
||||
PERSON_RECORD_PAGE_GENERAL_GROUP_UNIVERSAL_IDENTIFIER,
|
||||
fieldMetadataUniversalIdentifier: TEST_FIELD_ID,
|
||||
position: 11,
|
||||
isVisible: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
expectToFail: true,
|
||||
});
|
||||
|
||||
expectOneNotInternalServerErrorSnapshot({ errors });
|
||||
}, 60000);
|
||||
|
||||
it('rejects a standalone view field whose target view does not exist', async () => {
|
||||
const { errors } = await syncApplication({
|
||||
manifest: buildManifest({
|
||||
fields: [personFieldManifest],
|
||||
viewFields: [
|
||||
{
|
||||
universalIdentifier: TEST_VIEW_FIELD_ID,
|
||||
viewUniversalIdentifier: uuidv4(),
|
||||
fieldMetadataUniversalIdentifier: TEST_FIELD_ID,
|
||||
position: 10,
|
||||
isVisible: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
expectToFail: true,
|
||||
});
|
||||
|
||||
expectOneNotInternalServerErrorSnapshot({ errors });
|
||||
}, 60000);
|
||||
});
|
||||
+72
-1
@@ -1,11 +1,14 @@
|
||||
import { VIEW_FIELD_GQL_FIELDS } from 'test/integration/constants/view-gql-fields.constants';
|
||||
import { buildBaseManifest } from 'test/integration/metadata/suites/application/utils/build-base-manifest.util';
|
||||
import { buildDefaultObjectManifest } from 'test/integration/metadata/suites/application/utils/build-default-object-manifest.util';
|
||||
import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
|
||||
import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';
|
||||
import { syncApplication } from 'test/integration/metadata/suites/application/utils/sync-application.util';
|
||||
import { findManyObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/find-many-object-metadata.util';
|
||||
import { findViewFields } from 'test/integration/metadata/suites/view-field/utils/find-view-fields.util';
|
||||
import { findViews } from 'test/integration/metadata/suites/view/utils/find-views.util';
|
||||
import { type ObjectManifest } from 'twenty-shared/application';
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { FieldMetadataType, ViewKey } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
@@ -80,6 +83,54 @@ const findTicketObject = async () => {
|
||||
);
|
||||
};
|
||||
|
||||
// The label identifier view field on the INDEX view must be visible and
|
||||
// strictly lowest, whatever provisioned it (fieldIndexViewFieldOnCreate on
|
||||
// creation, objectIndexViewLabelIdentifierOnUpdate on relabel).
|
||||
const expectLabelIdentifierIndexViewFieldVisibleAndLowest = async ({
|
||||
objectMetadataId,
|
||||
labelFieldMetadataId,
|
||||
}: {
|
||||
objectMetadataId: string;
|
||||
labelFieldMetadataId: string;
|
||||
}) => {
|
||||
const { data: viewsData } = await findViews({
|
||||
objectMetadataId,
|
||||
gqlFields: 'id key',
|
||||
expectToFail: false,
|
||||
});
|
||||
|
||||
const indexView = viewsData?.getViews.find(
|
||||
(view) => view.key === ViewKey.INDEX,
|
||||
);
|
||||
|
||||
if (!isDefined(indexView)) {
|
||||
throw new Error('expected an INDEX view for the ticket object');
|
||||
}
|
||||
|
||||
const { data: viewFieldsData } = await findViewFields({
|
||||
viewId: indexView.id,
|
||||
gqlFields: VIEW_FIELD_GQL_FIELDS,
|
||||
expectToFail: false,
|
||||
});
|
||||
|
||||
const viewFields = viewFieldsData?.getViewFields ?? [];
|
||||
const labelViewField = viewFields.find(
|
||||
(viewField) => viewField.fieldMetadataId === labelFieldMetadataId,
|
||||
);
|
||||
|
||||
if (!isDefined(labelViewField)) {
|
||||
throw new Error('expected an INDEX view field for the label identifier');
|
||||
}
|
||||
|
||||
expect(labelViewField.isVisible).toBe(true);
|
||||
|
||||
for (const viewField of viewFields) {
|
||||
if (viewField.id !== labelViewField.id) {
|
||||
expect(labelViewField.position).toBeLessThan(viewField.position);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
describe('Manifest sync - relabel label identifier onto a newly introduced field', () => {
|
||||
beforeEach(async () => {
|
||||
await setupApplicationForSync({
|
||||
@@ -120,6 +171,17 @@ describe('Manifest sync - relabel label identifier onto a newly introduced field
|
||||
nameField?.id,
|
||||
);
|
||||
|
||||
// Object created with a custom label identifier backed by a field created
|
||||
// in the same sync: its INDEX view field is visible and strictly lowest.
|
||||
if (!isDefined(ticketAfterFirstSync) || !isDefined(nameField)) {
|
||||
throw new Error('expected the ticket object and its name field');
|
||||
}
|
||||
|
||||
await expectLabelIdentifierIndexViewFieldVisibleAndLowest({
|
||||
objectMetadataId: ticketAfterFirstSync.id,
|
||||
labelFieldMetadataId: nameField.id,
|
||||
});
|
||||
|
||||
await syncApplication({
|
||||
manifest: buildManifest(
|
||||
buildTicketObject({
|
||||
@@ -139,6 +201,15 @@ describe('Manifest sync - relabel label identifier onto a newly introduced field
|
||||
expect(ticketAfterSecondSync?.labelIdentifierFieldMetadataId).toBe(
|
||||
codeField?.id,
|
||||
);
|
||||
|
||||
if (!isDefined(ticketAfterSecondSync) || !isDefined(codeField)) {
|
||||
throw new Error('expected the ticket object and its code field');
|
||||
}
|
||||
|
||||
await expectLabelIdentifierIndexViewFieldVisibleAndLowest({
|
||||
objectMetadataId: ticketAfterSecondSync.id,
|
||||
labelFieldMetadataId: codeField.id,
|
||||
});
|
||||
}, 60000);
|
||||
|
||||
it('should relabel onto a newly introduced field when introduction and relabel are split across two syncs, exposing the enriched labelIdentifierFieldMetadataId through the metadata API', async () => {
|
||||
|
||||
+38
-79
@@ -1,3 +1,4 @@
|
||||
import { VIEW_FIELD_GQL_FIELDS } from 'test/integration/constants/view-gql-fields.constants';
|
||||
import { buildBaseManifest } from 'test/integration/metadata/suites/application/utils/build-base-manifest.util';
|
||||
import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/suites/application/utils/cleanup-application-and-app-registration.util';
|
||||
import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';
|
||||
@@ -6,23 +7,23 @@ import { uninstallApplication } from 'test/integration/metadata/suites/applicati
|
||||
import { findManyObjectMetadataWithIndexes } from 'test/integration/metadata/suites/object-metadata/utils/find-many-object-metadata-with-indexes.util';
|
||||
import { findViewFields } from 'test/integration/metadata/suites/view-field/utils/find-view-fields.util';
|
||||
import { findViews } from 'test/integration/metadata/suites/view/utils/find-views.util';
|
||||
import { VIEW_FIELD_GQL_FIELDS } from 'test/integration/constants/view-gql-fields.constants';
|
||||
import type { FieldManifest } from 'twenty-shared/application';
|
||||
import { type Manifest } from 'twenty-shared/application';
|
||||
import { type FieldManifest, type Manifest } from 'twenty-shared/application';
|
||||
import { STANDARD_OBJECTS } from 'twenty-shared/metadata';
|
||||
import { FieldMetadataType, ViewKey } from 'twenty-shared/types';
|
||||
import { FieldMetadataType, ViewType } from 'twenty-shared/types';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const TEST_APP_ID = uuidv4();
|
||||
const TEST_ROLE_ID = uuidv4();
|
||||
const TEST_FIELD_ID = uuidv4();
|
||||
const TEST_VIEW_FIELD_ID = uuidv4();
|
||||
const TEST_SECOND_VIEW_FIELD_ID = uuidv4();
|
||||
|
||||
const PERSON_OBJECT_UNIVERSAL_IDENTIFIER =
|
||||
STANDARD_OBJECTS.person.universalIdentifier;
|
||||
const ALL_PEOPLE_VIEW_UNIVERSAL_IDENTIFIER =
|
||||
STANDARD_OBJECTS.person.views.allPeople.universalIdentifier;
|
||||
const PERSON_RECORD_PAGE_VIEW_UNIVERSAL_IDENTIFIER =
|
||||
STANDARD_OBJECTS.person.views.personRecordPageFields.universalIdentifier;
|
||||
const PERSON_RECORD_PAGE_GENERAL_GROUP_UNIVERSAL_IDENTIFIER =
|
||||
STANDARD_OBJECTS.person.views.personRecordPageFields.viewFieldGroups.general
|
||||
.universalIdentifier;
|
||||
|
||||
const CUSTOM_FIELD_NAME = 'integrationContributedColumn';
|
||||
|
||||
@@ -62,25 +63,25 @@ const findPersonObject = async () => {
|
||||
return person;
|
||||
};
|
||||
|
||||
const findAllPeopleViewId = async (personObjectId: string) => {
|
||||
const findRecordPageViewId = async (personObjectId: string) => {
|
||||
const { data } = await findViews({
|
||||
objectMetadataId: personObjectId,
|
||||
gqlFields: 'id key name',
|
||||
gqlFields: 'id key name type',
|
||||
expectToFail: false,
|
||||
});
|
||||
|
||||
const allPeopleView = data?.getViews.find(
|
||||
(view) => view.key === ViewKey.INDEX,
|
||||
const recordPageView = data?.getViews.find(
|
||||
(view) => view.type === ViewType.FIELDS_WIDGET,
|
||||
);
|
||||
|
||||
if (!allPeopleView) {
|
||||
throw new Error('Standard allPeople (INDEX) view not found for Person');
|
||||
if (!recordPageView) {
|
||||
throw new Error('Standard record-page view not found for Person');
|
||||
}
|
||||
|
||||
return allPeopleView.id;
|
||||
return recordPageView.id;
|
||||
};
|
||||
|
||||
const findAllPeopleViewFields = async (viewId: string) => {
|
||||
const findRecordPageViewFields = async (viewId: string) => {
|
||||
const { data } = await findViewFields({
|
||||
viewId,
|
||||
gqlFields: VIEW_FIELD_GQL_FIELDS,
|
||||
@@ -106,10 +107,10 @@ describe('Manifest update - standalone view fields on existing views', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('attaches a standalone view field to the standard allPeople view without recreating the view', async () => {
|
||||
it('attaches a standalone view field to the standard record-page view without recreating the view', async () => {
|
||||
const person = await findPersonObject();
|
||||
const allPeopleViewId = await findAllPeopleViewId(person.id);
|
||||
const standardViewFields = await findAllPeopleViewFields(allPeopleViewId);
|
||||
const recordPageViewId = await findRecordPageViewId(person.id);
|
||||
const standardViewFields = await findRecordPageViewFields(recordPageViewId);
|
||||
const standardViewFieldIds = standardViewFields.map(
|
||||
(viewField) => viewField.id,
|
||||
);
|
||||
@@ -122,7 +123,10 @@ describe('Manifest update - standalone view fields on existing views', () => {
|
||||
viewFields: [
|
||||
{
|
||||
universalIdentifier: TEST_VIEW_FIELD_ID,
|
||||
viewUniversalIdentifier: ALL_PEOPLE_VIEW_UNIVERSAL_IDENTIFIER,
|
||||
viewUniversalIdentifier:
|
||||
PERSON_RECORD_PAGE_VIEW_UNIVERSAL_IDENTIFIER,
|
||||
viewFieldGroupUniversalIdentifier:
|
||||
PERSON_RECORD_PAGE_GENERAL_GROUP_UNIVERSAL_IDENTIFIER,
|
||||
fieldMetadataUniversalIdentifier: TEST_FIELD_ID,
|
||||
position: 10,
|
||||
isVisible: true,
|
||||
@@ -143,7 +147,8 @@ describe('Manifest update - standalone view fields on existing views', () => {
|
||||
|
||||
expect(customField).toBeDefined();
|
||||
|
||||
const viewFieldsAfterSync = await findAllPeopleViewFields(allPeopleViewId);
|
||||
const viewFieldsAfterSync =
|
||||
await findRecordPageViewFields(recordPageViewId);
|
||||
|
||||
const contributedViewField = viewFieldsAfterSync.find(
|
||||
(viewField) => viewField.fieldMetadataId === customField?.id,
|
||||
@@ -151,7 +156,7 @@ describe('Manifest update - standalone view fields on existing views', () => {
|
||||
|
||||
expect(contributedViewField).toBeDefined();
|
||||
expect(contributedViewField).toMatchObject({
|
||||
viewId: allPeopleViewId,
|
||||
viewId: recordPageViewId,
|
||||
position: 10,
|
||||
isVisible: true,
|
||||
size: 150,
|
||||
@@ -169,8 +174,8 @@ describe('Manifest update - standalone view fields on existing views', () => {
|
||||
|
||||
it('removes the contributed view field on uninstall while keeping the standard view intact', async () => {
|
||||
const person = await findPersonObject();
|
||||
const allPeopleViewId = await findAllPeopleViewId(person.id);
|
||||
const standardViewFields = await findAllPeopleViewFields(allPeopleViewId);
|
||||
const recordPageViewId = await findRecordPageViewId(person.id);
|
||||
const standardViewFields = await findRecordPageViewFields(recordPageViewId);
|
||||
const standardViewFieldIds = standardViewFields.map(
|
||||
(viewField) => viewField.id,
|
||||
);
|
||||
@@ -181,7 +186,10 @@ describe('Manifest update - standalone view fields on existing views', () => {
|
||||
viewFields: [
|
||||
{
|
||||
universalIdentifier: TEST_VIEW_FIELD_ID,
|
||||
viewUniversalIdentifier: ALL_PEOPLE_VIEW_UNIVERSAL_IDENTIFIER,
|
||||
viewUniversalIdentifier:
|
||||
PERSON_RECORD_PAGE_VIEW_UNIVERSAL_IDENTIFIER,
|
||||
viewFieldGroupUniversalIdentifier:
|
||||
PERSON_RECORD_PAGE_GENERAL_GROUP_UNIVERSAL_IDENTIFIER,
|
||||
fieldMetadataUniversalIdentifier: TEST_FIELD_ID,
|
||||
position: 10,
|
||||
isVisible: true,
|
||||
@@ -199,7 +207,7 @@ describe('Manifest update - standalone view fields on existing views', () => {
|
||||
|
||||
expect(customFieldId).toBeDefined();
|
||||
expect(
|
||||
(await findAllPeopleViewFields(allPeopleViewId)).some(
|
||||
(await findRecordPageViewFields(recordPageViewId)).some(
|
||||
(viewField) => viewField.fieldMetadataId === customFieldId,
|
||||
),
|
||||
).toBe(true);
|
||||
@@ -209,12 +217,14 @@ describe('Manifest update - standalone view fields on existing views', () => {
|
||||
expectToFail: false,
|
||||
});
|
||||
|
||||
const allPeopleViewIdAfterUninstall = await findAllPeopleViewId(person.id);
|
||||
const recordPageViewIdAfterUninstall = await findRecordPageViewId(
|
||||
person.id,
|
||||
);
|
||||
|
||||
expect(allPeopleViewIdAfterUninstall).toBe(allPeopleViewId);
|
||||
expect(recordPageViewIdAfterUninstall).toBe(recordPageViewId);
|
||||
|
||||
const viewFieldsAfterUninstall =
|
||||
await findAllPeopleViewFields(allPeopleViewId);
|
||||
await findRecordPageViewFields(recordPageViewId);
|
||||
|
||||
expect(
|
||||
viewFieldsAfterUninstall.some(
|
||||
@@ -230,55 +240,4 @@ describe('Manifest update - standalone view fields on existing views', () => {
|
||||
).toBe(true);
|
||||
}
|
||||
}, 60000);
|
||||
|
||||
it('rejects two standalone view fields targeting the same field on the same view', async () => {
|
||||
const { errors } = await syncApplication({
|
||||
manifest: buildManifest({
|
||||
fields: [personFieldManifest],
|
||||
viewFields: [
|
||||
{
|
||||
universalIdentifier: TEST_VIEW_FIELD_ID,
|
||||
viewUniversalIdentifier: ALL_PEOPLE_VIEW_UNIVERSAL_IDENTIFIER,
|
||||
fieldMetadataUniversalIdentifier: TEST_FIELD_ID,
|
||||
position: 10,
|
||||
isVisible: true,
|
||||
},
|
||||
{
|
||||
universalIdentifier: TEST_SECOND_VIEW_FIELD_ID,
|
||||
viewUniversalIdentifier: ALL_PEOPLE_VIEW_UNIVERSAL_IDENTIFIER,
|
||||
fieldMetadataUniversalIdentifier: TEST_FIELD_ID,
|
||||
position: 11,
|
||||
isVisible: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
expectToFail: true,
|
||||
});
|
||||
|
||||
expect(errors).toBeDefined();
|
||||
expect(errors.length).toBeGreaterThan(0);
|
||||
expect(errors[0].extensions.code).toBe('METADATA_VALIDATION_FAILED');
|
||||
}, 60000);
|
||||
|
||||
it('rejects a standalone view field whose target view does not exist', async () => {
|
||||
const { errors } = await syncApplication({
|
||||
manifest: buildManifest({
|
||||
fields: [personFieldManifest],
|
||||
viewFields: [
|
||||
{
|
||||
universalIdentifier: TEST_VIEW_FIELD_ID,
|
||||
viewUniversalIdentifier: uuidv4(),
|
||||
fieldMetadataUniversalIdentifier: TEST_FIELD_ID,
|
||||
position: 10,
|
||||
isVisible: true,
|
||||
},
|
||||
],
|
||||
}),
|
||||
expectToFail: true,
|
||||
});
|
||||
|
||||
expect(errors).toBeDefined();
|
||||
expect(errors.length).toBeGreaterThan(0);
|
||||
expect(errors[0].extensions.code).toBe('METADATA_VALIDATION_FAILED');
|
||||
}, 60000);
|
||||
});
|
||||
|
||||
+4
-3
@@ -20,7 +20,7 @@ import {
|
||||
import { FieldMetadataType } from 'twenty-shared/types';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
const TEST_APP_ID = uuidv4();
|
||||
const TEST_APP_ID = '0c17e907-f32a-4526-98e4-9addd4302b1a';
|
||||
const TEST_ROLE_ID = uuidv4();
|
||||
const TEST_FIELD_ID = uuidv4();
|
||||
const TEST_SKILL_ID = uuidv4();
|
||||
@@ -317,11 +317,12 @@ describe('syncApplication', () => {
|
||||
}, 60000);
|
||||
|
||||
it('should delete old field and create equivalent one when field universalIdentifier changes', async () => {
|
||||
const originalFieldId = uuidv4();
|
||||
const updatedFieldId = uuidv4();
|
||||
const originalFieldId = '8abbef24-f8c3-41d5-826b-73a02825e712';
|
||||
const updatedFieldId = 'a4262080-673d-430a-883b-c5d04610abf1';
|
||||
|
||||
const testObject = buildDefaultObjectManifest({
|
||||
applicationUniversalIdentifier: TEST_APP_ID,
|
||||
universalIdentifier: '8fc4bfec-01d8-4404-bd1a-dc90fe8e7699',
|
||||
nameSingular: 'ticket',
|
||||
namePlural: 'tickets',
|
||||
labelSingular: 'Ticket',
|
||||
|
||||
+79
-5
@@ -1,4 +1,4 @@
|
||||
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`updateOne FieldMetadataService morph relation fields v2 - Add one target Should fail adding one object metadata target to pre-existing morph relation where object is already a target 1`] = `
|
||||
{
|
||||
@@ -71,12 +71,49 @@ exports[`updateOne FieldMetadataService morph relation fields v2 - Add one targe
|
||||
"type": "create",
|
||||
},
|
||||
],
|
||||
"viewField": [
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": "INVALID_VIEW_DATA",
|
||||
"message": "Field metadata not found",
|
||||
"userFriendlyMessage": "Field metadata not found",
|
||||
},
|
||||
],
|
||||
"flatEntityMinimalInformation": {
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"universalIdentifier": Any<String>,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"status": "fail",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": "INVALID_VIEW_DATA",
|
||||
"message": "Field metadata not found",
|
||||
"userFriendlyMessage": "Field metadata not found",
|
||||
},
|
||||
],
|
||||
"flatEntityMinimalInformation": {
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"universalIdentifier": Any<String>,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"status": "fail",
|
||||
"type": "create",
|
||||
},
|
||||
],
|
||||
},
|
||||
"message": "Validation failed for 2 fieldMetadata, 1 index",
|
||||
"message": "Validation failed for 2 fieldMetadata, 2 viewFields, 1 index",
|
||||
"summary": {
|
||||
"fieldMetadata": 2,
|
||||
"index": 1,
|
||||
"totalErrors": 3,
|
||||
"totalErrors": 5,
|
||||
"viewField": 2,
|
||||
},
|
||||
"userFriendlyMessage": "Many validation errors",
|
||||
},
|
||||
@@ -144,12 +181,49 @@ exports[`updateOne FieldMetadataService morph relation fields v2 - Add one targe
|
||||
"type": "create",
|
||||
},
|
||||
],
|
||||
"viewField": [
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": "INVALID_VIEW_DATA",
|
||||
"message": "Field metadata not found",
|
||||
"userFriendlyMessage": "Field metadata not found",
|
||||
},
|
||||
],
|
||||
"flatEntityMinimalInformation": {
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"universalIdentifier": Any<String>,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"status": "fail",
|
||||
"type": "create",
|
||||
},
|
||||
{
|
||||
"errors": [
|
||||
{
|
||||
"code": "INVALID_VIEW_DATA",
|
||||
"message": "Field metadata not found",
|
||||
"userFriendlyMessage": "Field metadata not found",
|
||||
},
|
||||
],
|
||||
"flatEntityMinimalInformation": {
|
||||
"fieldMetadataUniversalIdentifier": Any<String>,
|
||||
"universalIdentifier": Any<String>,
|
||||
"viewUniversalIdentifier": Any<String>,
|
||||
},
|
||||
"metadataName": "viewField",
|
||||
"status": "fail",
|
||||
"type": "create",
|
||||
},
|
||||
],
|
||||
},
|
||||
"message": "Validation failed for 2 fieldMetadata, 1 index",
|
||||
"message": "Validation failed for 2 fieldMetadata, 2 viewFields, 1 index",
|
||||
"summary": {
|
||||
"fieldMetadata": 2,
|
||||
"index": 1,
|
||||
"totalErrors": 3,
|
||||
"totalErrors": 5,
|
||||
"viewField": 2,
|
||||
},
|
||||
"userFriendlyMessage": "Many validation errors",
|
||||
},
|
||||
|
||||
+106
-16
@@ -5,6 +5,7 @@ import { deleteOneObjectMetadata } from 'test/integration/metadata/suites/object
|
||||
import { updateOneObjectMetadata } from 'test/integration/metadata/suites/object-metadata/utils/update-one-object-metadata.util';
|
||||
import { findViewFields } from 'test/integration/metadata/suites/view-field/utils/find-view-fields.util';
|
||||
import { findViews } from 'test/integration/metadata/suites/view/utils/find-views.util';
|
||||
import { ViewType } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { type FlatView } from 'src/engine/metadata-modules/flat-view/types/flat-view.type';
|
||||
@@ -33,7 +34,18 @@ describe('View side effect on object creation', () => {
|
||||
|
||||
createdObjectMetadataId = undefined;
|
||||
});
|
||||
it('should create a view and view field for default custom objects standard fields on object metadata creation', async () => {
|
||||
const objectCreationGqlFields = `
|
||||
id
|
||||
labelPlural
|
||||
description
|
||||
labelSingular
|
||||
namePlural
|
||||
nameSingular
|
||||
icon
|
||||
isLabelSyncedWithName
|
||||
`;
|
||||
|
||||
const createDishesObject = async () => {
|
||||
const {
|
||||
labelPlural,
|
||||
description,
|
||||
@@ -50,16 +62,6 @@ describe('View side effect on object creation', () => {
|
||||
icon: 'IconBuildingSkyscraper',
|
||||
isLabelSyncedWithName: false,
|
||||
};
|
||||
const objectCreationGqlFields = `
|
||||
id
|
||||
labelPlural
|
||||
description
|
||||
labelSingular
|
||||
namePlural
|
||||
nameSingular
|
||||
icon
|
||||
isLabelSyncedWithName
|
||||
`;
|
||||
|
||||
const {
|
||||
data: { createOneObject },
|
||||
@@ -69,6 +71,20 @@ describe('View side effect on object creation', () => {
|
||||
gqlFields: objectCreationGqlFields,
|
||||
});
|
||||
|
||||
return createOneObject;
|
||||
};
|
||||
|
||||
const findIndexView = async (objectMetadataId: string) => {
|
||||
const {
|
||||
data: { getViews },
|
||||
} = await findViews({ objectMetadataId, expectToFail: false });
|
||||
|
||||
return getViews.find((view) => view.key === 'INDEX');
|
||||
};
|
||||
|
||||
it('should engine-provision the INDEX view and its view fields on object metadata creation', async () => {
|
||||
const createOneObject = await createDishesObject();
|
||||
|
||||
createdObjectMetadataId = createOneObject.id;
|
||||
|
||||
const {
|
||||
@@ -80,19 +96,93 @@ describe('View side effect on object creation', () => {
|
||||
|
||||
expect(createdViews).toBeDefined();
|
||||
expect(createdViews.length).toBe(2);
|
||||
const [firstView] = createdViews;
|
||||
|
||||
expect(firstView).toMatchObject<Partial<FlatView>>({
|
||||
const indexView = createdViews.find((view) => view.key === 'INDEX');
|
||||
|
||||
if (!isDefined(indexView)) {
|
||||
throw new Error('expected an INDEX view to be provisioned');
|
||||
}
|
||||
|
||||
expect(indexView).toMatchObject<Partial<FlatView>>({
|
||||
objectMetadataId: createdObjectMetadataId,
|
||||
type: ViewType.TABLE,
|
||||
});
|
||||
|
||||
const {
|
||||
data: { getViewFields: createdViewFields },
|
||||
data: { getViewFields: indexViewFields },
|
||||
} = await findViewFields({
|
||||
viewId: firstView.id,
|
||||
viewId: indexView.id,
|
||||
expectToFail: false,
|
||||
});
|
||||
|
||||
expect(createdViewFields.length).toBe(5);
|
||||
expect(indexViewFields.length).toBe(5);
|
||||
});
|
||||
|
||||
it('should keep the same INDEX view when the object is renamed (lossless, deterministic identifier)', async () => {
|
||||
const createOneObject = await createDishesObject();
|
||||
|
||||
createdObjectMetadataId = createOneObject.id;
|
||||
|
||||
const indexViewBeforeRename = await findIndexView(createdObjectMetadataId);
|
||||
|
||||
if (!isDefined(indexViewBeforeRename)) {
|
||||
throw new Error('expected an INDEX view to be provisioned');
|
||||
}
|
||||
|
||||
await updateOneObjectMetadata({
|
||||
expectToFail: false,
|
||||
input: {
|
||||
idToUpdate: createdObjectMetadataId,
|
||||
updatePayload: {
|
||||
labelPlural: 'Renamed dishes',
|
||||
labelSingular: 'Renamed dish',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const indexViewAfterRename = await findIndexView(createdObjectMetadataId);
|
||||
|
||||
if (!isDefined(indexViewAfterRename)) {
|
||||
throw new Error('expected the INDEX view to survive the rename');
|
||||
}
|
||||
|
||||
expect(indexViewAfterRename.id).toBe(indexViewBeforeRename.id);
|
||||
|
||||
const {
|
||||
data: { getViewFields: indexViewFieldsAfterRename },
|
||||
} = await findViewFields({
|
||||
viewId: indexViewAfterRename.id,
|
||||
expectToFail: false,
|
||||
});
|
||||
|
||||
expect(indexViewFieldsAfterRename.length).toBe(5);
|
||||
});
|
||||
|
||||
it('should cascade-delete the INDEX view and its view fields when the object is deleted', async () => {
|
||||
const createOneObject = await createDishesObject();
|
||||
const objectMetadataId = createOneObject.id;
|
||||
|
||||
const indexView = await findIndexView(objectMetadataId);
|
||||
|
||||
expect(isDefined(indexView)).toBe(true);
|
||||
|
||||
await updateOneObjectMetadata({
|
||||
expectToFail: false,
|
||||
input: {
|
||||
idToUpdate: objectMetadataId,
|
||||
updatePayload: { isActive: false },
|
||||
},
|
||||
});
|
||||
|
||||
await deleteOneObjectMetadata({
|
||||
input: { idToDelete: objectMetadataId },
|
||||
expectToFail: false,
|
||||
});
|
||||
|
||||
const {
|
||||
data: { getViews: viewsAfterDelete },
|
||||
} = await findViews({ objectMetadataId, expectToFail: false });
|
||||
|
||||
expect(viewsAfterDelete.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,8 +13,6 @@ import { generateRecordName } from 'test/integration/utils/generate-record-name'
|
||||
import { assertViewStructure } from 'test/integration/utils/view-test.util';
|
||||
import { ViewOpenRecordIn, ViewType } from 'twenty-shared/types';
|
||||
|
||||
import { ViewKey } from 'twenty-shared/types';
|
||||
|
||||
describe('View REST API', () => {
|
||||
let testObjectMetadataId: string;
|
||||
let testSelectFieldMetadataId: string;
|
||||
@@ -107,7 +105,7 @@ describe('View REST API', () => {
|
||||
name: viewName,
|
||||
icon: 'IconTable',
|
||||
type: ViewType.TABLE,
|
||||
key: ViewKey.INDEX,
|
||||
key: null,
|
||||
position: 0,
|
||||
isCompact: false,
|
||||
openRecordIn: ViewOpenRecordIn.SIDE_PANEL,
|
||||
@@ -121,7 +119,7 @@ describe('View REST API', () => {
|
||||
objectMetadataId: testObjectMetadataId,
|
||||
icon: 'IconTable',
|
||||
type: ViewType.TABLE,
|
||||
key: ViewKey.INDEX,
|
||||
key: null,
|
||||
position: 0,
|
||||
isCompact: false,
|
||||
openRecordIn: ViewOpenRecordIn.SIDE_PANEL,
|
||||
@@ -161,7 +159,7 @@ describe('View REST API', () => {
|
||||
name: viewName,
|
||||
icon: 'IconTable',
|
||||
type: ViewType.TABLE,
|
||||
key: ViewKey.INDEX,
|
||||
key: null,
|
||||
position: 0,
|
||||
isCompact: false,
|
||||
openRecordIn: ViewOpenRecordIn.SIDE_PANEL,
|
||||
@@ -202,7 +200,7 @@ describe('View REST API', () => {
|
||||
name: viewName,
|
||||
icon: 'IconTable',
|
||||
type: ViewType.TABLE,
|
||||
key: ViewKey.INDEX,
|
||||
key: null,
|
||||
position: 0,
|
||||
isCompact: false,
|
||||
openRecordIn: ViewOpenRecordIn.SIDE_PANEL,
|
||||
@@ -262,7 +260,7 @@ describe('View REST API', () => {
|
||||
name: viewName,
|
||||
icon: 'IconTable',
|
||||
type: ViewType.TABLE,
|
||||
key: ViewKey.INDEX,
|
||||
key: null,
|
||||
position: 0,
|
||||
isCompact: false,
|
||||
openRecordIn: ViewOpenRecordIn.SIDE_PANEL,
|
||||
|
||||
@@ -56,7 +56,7 @@ export const createTestViewWithRestApi = async (
|
||||
objectMetadataId,
|
||||
icon: 'IconTable',
|
||||
type: ViewType.TABLE,
|
||||
key: 'INDEX',
|
||||
key: null,
|
||||
position: 0,
|
||||
isCompact: false,
|
||||
openRecordIn: ViewOpenRecordIn.SIDE_PANEL,
|
||||
|
||||
Reference in New Issue
Block a user