Fix page layout seeding for record page layouts (#17871)
## Context Fix broken record page layout seeding. This was not detected by the CI because it doesn't have the env variable yet. Following the same mechanism as labelIdentifier in object for circular dependency resolution
This commit is contained in:
+43
-2
@@ -3,6 +3,7 @@ import { assertUnreachable, isDefined } from 'twenty-shared/utils';
|
||||
|
||||
import { type UniversalCreateFieldAction } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-builder/builders/field/types/workspace-migration-field-action';
|
||||
import { type UniversalCreateObjectAction } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-builder/builders/object/types/workspace-migration-object-action';
|
||||
import { type UniversalCreatePageLayoutAction } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-builder/builders/page-layout/types/workspace-migration-page-layout-action.type';
|
||||
import { type WorkspaceMigration } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-builder/types/workspace-migration';
|
||||
|
||||
export type IdByUniversalIdentifierByMetadataName = {
|
||||
@@ -40,6 +41,25 @@ const buildFieldIdByUniversalIdentifier = ({
|
||||
return fieldIdByUniversalIdentifier;
|
||||
};
|
||||
|
||||
const buildTabIdByUniversalIdentifier = ({
|
||||
action,
|
||||
pageLayoutTabIdByUniversalIdentifier,
|
||||
}: {
|
||||
action: UniversalCreatePageLayoutAction;
|
||||
pageLayoutTabIdByUniversalIdentifier: Record<string, string>;
|
||||
}): Record<string, string> | undefined => {
|
||||
const tabIdByUniversalIdentifier = {
|
||||
...action.tabIdByUniversalIdentifier,
|
||||
...pageLayoutTabIdByUniversalIdentifier,
|
||||
};
|
||||
|
||||
if (Object.keys(tabIdByUniversalIdentifier).length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return tabIdByUniversalIdentifier;
|
||||
};
|
||||
|
||||
export const enrichCreateWorkspaceMigrationActionsWithIds = ({
|
||||
workspaceMigration,
|
||||
idByUniversalIdentifierByMetadataName,
|
||||
@@ -49,6 +69,8 @@ export const enrichCreateWorkspaceMigrationActionsWithIds = ({
|
||||
}): WorkspaceMigration => {
|
||||
const fieldMetadataIdByUniversalIdentifier =
|
||||
idByUniversalIdentifierByMetadataName.fieldMetadata;
|
||||
const pageLayoutTabIdByUniversalIdentifier =
|
||||
idByUniversalIdentifierByMetadataName.pageLayoutTab;
|
||||
|
||||
const enrichedActions = workspaceMigration.actions.map((action) => {
|
||||
if (action.type !== 'create') {
|
||||
@@ -60,7 +82,8 @@ export const enrichCreateWorkspaceMigrationActionsWithIds = ({
|
||||
|
||||
if (
|
||||
!isDefined(idByUniversalIdentifier) &&
|
||||
!isDefined(fieldMetadataIdByUniversalIdentifier)
|
||||
!isDefined(fieldMetadataIdByUniversalIdentifier) &&
|
||||
!isDefined(pageLayoutTabIdByUniversalIdentifier)
|
||||
) {
|
||||
return action;
|
||||
}
|
||||
@@ -98,6 +121,25 @@ export const enrichCreateWorkspaceMigrationActionsWithIds = ({
|
||||
}),
|
||||
};
|
||||
}
|
||||
case 'pageLayout': {
|
||||
const id = isDefined(idByUniversalIdentifier)
|
||||
? idByUniversalIdentifier[action.flatEntity.universalIdentifier]
|
||||
: undefined;
|
||||
const tabIdByUniversalIdentifier = isDefined(
|
||||
pageLayoutTabIdByUniversalIdentifier,
|
||||
)
|
||||
? buildTabIdByUniversalIdentifier({
|
||||
action,
|
||||
pageLayoutTabIdByUniversalIdentifier,
|
||||
})
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
...action,
|
||||
id,
|
||||
tabIdByUniversalIdentifier,
|
||||
};
|
||||
}
|
||||
case 'view':
|
||||
case 'viewField':
|
||||
case 'viewGroup':
|
||||
@@ -111,7 +153,6 @@ export const enrichCreateWorkspaceMigrationActionsWithIds = ({
|
||||
case 'roleTarget':
|
||||
case 'agent':
|
||||
case 'skill':
|
||||
case 'pageLayout':
|
||||
case 'pageLayoutWidget':
|
||||
case 'pageLayoutTab':
|
||||
case 'commandMenuItem':
|
||||
|
||||
Reference in New Issue
Block a user