5cd8b7899d
## Context Deprecating shouldIncludeRecordPageLayouts in preparation for page layout release. See new workspace with standard page layout from standard app <img width="570" height="682" alt="Screenshot 2026-04-16 at 18 35 23" src="https://github.com/user-attachments/assets/bf7fa621-d40d-4c29-8d96-537c58b3eb40" />
140 lines
5.3 KiB
TypeScript
140 lines
5.3 KiB
TypeScript
import { Command } from 'nest-commander';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
import { ActiveOrSuspendedWorkspaceCommandRunner } from 'src/database/commands/command-runners/active-or-suspended-workspace.command-runner';
|
|
import { WorkspaceIteratorService } from 'src/database/commands/command-runners/workspace-iterator.service';
|
|
import { type RunOnWorkspaceArgs } from 'src/database/commands/command-runners/workspace.command-runner';
|
|
import { RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-workspace-command.decorator';
|
|
import { ApplicationService } from 'src/engine/core-modules/application/application.service';
|
|
import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';
|
|
import { STANDARD_COMMAND_MENU_ITEMS } from 'src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant';
|
|
import { computeTwentyStandardApplicationAllFlatEntityMaps } from 'src/engine/workspace-manager/twenty-standard-application/utils/twenty-standard-application-all-flat-entity-maps.constant';
|
|
import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';
|
|
|
|
const UNIVERSAL_IDENTIFIERS_TO_FIX = new Set<string>([
|
|
STANDARD_COMMAND_MENU_ITEMS.mergeMultipleRecords.universalIdentifier,
|
|
]);
|
|
|
|
@RegisteredWorkspaceCommand('1.22.0', 1780000003000)
|
|
@Command({
|
|
name: 'upgrade:1-22:fix-merge-command-select-all',
|
|
description:
|
|
'Fix merge command menu item to not appear in select-all (exclusion) mode',
|
|
})
|
|
export class FixMergeCommandSelectAllCommand extends ActiveOrSuspendedWorkspaceCommandRunner {
|
|
constructor(
|
|
protected readonly workspaceIteratorService: WorkspaceIteratorService,
|
|
private readonly applicationService: ApplicationService,
|
|
private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,
|
|
private readonly workspaceCacheService: WorkspaceCacheService,
|
|
) {
|
|
super(workspaceIteratorService);
|
|
}
|
|
|
|
override async runOnWorkspace({
|
|
workspaceId,
|
|
options,
|
|
}: RunOnWorkspaceArgs): Promise<void> {
|
|
const isDryRun = options.dryRun ?? false;
|
|
|
|
this.logger.log(
|
|
`${isDryRun ? '[DRY RUN] ' : ''}Starting merge command select-all expression fix for workspace ${workspaceId}`,
|
|
);
|
|
|
|
const { twentyStandardFlatApplication } =
|
|
await this.applicationService.findWorkspaceTwentyStandardAndCustomApplicationOrThrow(
|
|
{ workspaceId },
|
|
);
|
|
|
|
const { flatCommandMenuItemMaps: existingFlatCommandMenuItemMaps } =
|
|
await this.workspaceCacheService.getOrRecompute(workspaceId, [
|
|
'flatCommandMenuItemMaps',
|
|
]);
|
|
|
|
const { allFlatEntityMaps: standardAllFlatEntityMaps } =
|
|
computeTwentyStandardApplicationAllFlatEntityMaps({
|
|
now: new Date().toISOString(),
|
|
workspaceId,
|
|
twentyStandardApplicationId: twentyStandardFlatApplication.id,
|
|
});
|
|
|
|
const itemsToUpdate = [...UNIVERSAL_IDENTIFIERS_TO_FIX]
|
|
.map((universalIdentifier) => {
|
|
const standardItem =
|
|
standardAllFlatEntityMaps.flatCommandMenuItemMaps
|
|
.byUniversalIdentifier[universalIdentifier];
|
|
const existingItem =
|
|
existingFlatCommandMenuItemMaps.byUniversalIdentifier[
|
|
universalIdentifier
|
|
];
|
|
|
|
if (
|
|
!isDefined(standardItem) ||
|
|
!isDefined(existingItem) ||
|
|
existingItem.conditionalAvailabilityExpression ===
|
|
standardItem.conditionalAvailabilityExpression
|
|
) {
|
|
return undefined;
|
|
}
|
|
|
|
return {
|
|
...existingItem,
|
|
conditionalAvailabilityExpression:
|
|
standardItem.conditionalAvailabilityExpression,
|
|
updatedAt: new Date().toISOString(),
|
|
};
|
|
})
|
|
.filter(isDefined);
|
|
|
|
if (itemsToUpdate.length === 0) {
|
|
this.logger.log(
|
|
`Merge command menu item expression already up to date for workspace ${workspaceId}`,
|
|
);
|
|
|
|
return;
|
|
}
|
|
|
|
this.logger.log(
|
|
`Found ${itemsToUpdate.length} command menu item(s) to update for workspace ${workspaceId}`,
|
|
);
|
|
|
|
if (isDryRun) {
|
|
this.logger.log(
|
|
`[DRY RUN] Would update ${itemsToUpdate.length} command menu item expression(s) for workspace ${workspaceId}`,
|
|
);
|
|
|
|
return;
|
|
}
|
|
|
|
const validateAndBuildResult =
|
|
await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunWorkspaceMigration(
|
|
{
|
|
allFlatEntityOperationByMetadataName: {
|
|
commandMenuItem: {
|
|
flatEntityToCreate: [],
|
|
flatEntityToDelete: [],
|
|
flatEntityToUpdate: itemsToUpdate,
|
|
},
|
|
},
|
|
workspaceId,
|
|
applicationUniversalIdentifier:
|
|
twentyStandardFlatApplication.universalIdentifier,
|
|
},
|
|
);
|
|
|
|
if (validateAndBuildResult.status === 'fail') {
|
|
this.logger.error(
|
|
`Failed to fix merge command expression:\n${JSON.stringify(validateAndBuildResult, null, 2)}`,
|
|
);
|
|
|
|
throw new Error(
|
|
`Failed to fix merge command menu item expression for workspace ${workspaceId}`,
|
|
);
|
|
}
|
|
|
|
this.logger.log(
|
|
`Successfully updated ${itemsToUpdate.length} command menu item expression(s) for workspace ${workspaceId}`,
|
|
);
|
|
}
|
|
}
|