ToolJet/server/data-migrations/1636372753632-RebaseWidgetWidthAndLeftOffsetForResponsiveCanvas.ts
gsmithun4 f40be5b1b5 feat(logging): integrate transaction logging across various guards and services
- Updated `AbilityGuard` to utilize `TransactionLogger` for logging execution time and errors.
- Enhanced `ResponseInterceptor` to include transaction metadata in logs.
- Modified `QueryAuthGuard`, `ValidateQueryAppGuard`, and `ValidateQuerySourceGuard` to log completion times and transaction IDs.
- Introduced `TransactionLogger` service for structured logging with transaction context.
- Added transaction ID and route information to request context in `RequestContextMiddleware`.
- Updated `JwtStrategy` to log validation completion times.
- Refactored logging configuration in `AppModuleLoader` to support pretty printing in non-production environments.
- Removed console logs in favor of structured logging for better traceability.
2025-09-19 02:08:49 +05:30

101 lines
3.6 KiB
TypeScript

import { MigrationInterface, QueryRunner } from 'typeorm';
import { AppVersion } from '@entities/app_version.entity';
export class RebaseWidgetWidthAndLeftOffsetForResponsiveCanvas1636372753632 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
const entityManager = queryRunner.manager;
const queryBuilder = queryRunner.connection.createQueryBuilder();
const appVersionRepository = entityManager.getRepository(AppVersion);
const appVersions = await appVersionRepository.find();
for (const version of appVersions) {
const definition = version['definition'];
if (definition) {
const components = definition['components'];
const changesRequired: {
component: any;
componentId: string;
layout: string;
newWidth: number;
newLeft: number;
}[] = [];
for (const componentId of Object.keys(components)) {
const component = components[componentId];
const layouts = component.layouts;
for (const layoutIndex in layouts) {
const layout = layouts[layoutIndex];
let containerWidth = 1292;
if (layoutIndex === 'mobile') containerWidth = 450;
if (component.parent) {
const parentComponentCandidates: any = Object.entries(components).filter(
(entry) => entry[0] === component.parent
);
if (parentComponentCandidates.length > 0) {
const parentComponent = parentComponentCandidates[0][1];
const parentLayoutCandidateEntries: any = Object.entries(parentComponent.layouts).filter(
(entry) => entry[0] === layoutIndex
);
if (parentLayoutCandidateEntries.length > 0) {
containerWidth = parentLayoutCandidateEntries[0][1].width;
if (parentComponent.component.component === 'Modal') {
switch (parentComponent.component.definition.properties?.size?.value ?? 'lg') {
case 'lg':
containerWidth = 718;
break;
case 'md':
containerWidth = 538;
break;
case 'sm':
containerWidth = 378;
break;
}
}
}
}
}
const width = layout.width;
const newWidth = (width * 43) / containerWidth;
// component.layouts[layoutIndex].width = newWidth;
const left = layout.left;
const newLeft = (left * 100) / containerWidth;
// component.layouts[layoutIndex].left = newLeft;
changesRequired.push({ component, componentId, layout: layoutIndex, newWidth, newLeft });
}
}
for (const change of changesRequired) {
change.component.layouts[change.layout].left = change.newLeft;
change.component.layouts[change.layout].width = change.newWidth;
components[change.componentId] = {
...change.component,
component: {
...change.component.component,
},
layouts: {
...change.component.layouts,
},
};
}
definition['components'] = components;
version.definition = definition;
await queryBuilder.update(AppVersion).set({ definition }).where('id = :id', { id: version.id }).execute();
}
}
}
public async down(queryRunner: QueryRunner): Promise<void> {}
}