From b88d500e16013b37f290f21821c1cb0c63484ee8 Mon Sep 17 00:00:00 2001 From: arpitnath Date: Tue, 7 Nov 2023 11:14:09 +0530 Subject: [PATCH] cherrypicked ee/00195c064 --- .../1688977149516-ListviewDefaultMode.ts | 29 ++++++----------- .../1692973078520-CellSizeRegularCondensed.ts | 32 +++++++------------ .../1692974311591-TableRowCellStyle.ts | 22 +++---------- 3 files changed, 25 insertions(+), 58 deletions(-) diff --git a/server/data-migrations/1688977149516-ListviewDefaultMode.ts b/server/data-migrations/1688977149516-ListviewDefaultMode.ts index d8e1d503cd..672774fcf3 100644 --- a/server/data-migrations/1688977149516-ListviewDefaultMode.ts +++ b/server/data-migrations/1688977149516-ListviewDefaultMode.ts @@ -6,39 +6,28 @@ export class ListviewDefaultMode1688977149516 implements MigrationInterface { const entityManager = queryRunner.manager; const appVersions = await entityManager.find(AppVersion); for (const version of appVersions) { - const definition = version['definition']; + const definition = JSON.parse(JSON.stringify(version?.definition)); if (definition) { const pages = definition['pages']; - if (pages) { + if (Object.keys(pages).length > 0) { for (const pageId of Object.keys(pages)) { const components = definition['pages'][pageId]['components']; - if (components) { + if (Object.keys(components).length > 0) { for (const componentId of Object.keys(components)) { const component = components[componentId]; - if (component?.component?.component === 'Listview') { - component['component']['definition']['properties']['mode'] = { - value: 'list', - }; - - components[componentId] = { - ...component, - component: { - ...component.component, - definition: { - ...component.component.definition, - }, - }, - }; + if ( + component?.component?.component === 'Listview' && + component.component?.definition?.properties?.mode + ) { + component.component.definition.properties.mode['value'] = 'list'; } } } - - definition['components'] = components; - version.definition = definition; } } + version.definition = definition; await entityManager.update(AppVersion, { id: version.id }, { definition }); } } diff --git a/server/data-migrations/1692973078520-CellSizeRegularCondensed.ts b/server/data-migrations/1692973078520-CellSizeRegularCondensed.ts index 0833ebb753..76709c348b 100644 --- a/server/data-migrations/1692973078520-CellSizeRegularCondensed.ts +++ b/server/data-migrations/1692973078520-CellSizeRegularCondensed.ts @@ -4,25 +4,23 @@ import { AppVersion } from '../src/entities/app_version.entity'; export class CellSizeRegularCondensed1692973078520 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { 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']; + const definition = JSON.parse(JSON.stringify(version?.definition)); if (definition) { const pages = definition?.['pages']; - if (pages) { + if (Object.keys(pages).length > 0) { for (const pageId of Object.keys(pages)) { - const components = pages?.[pageId]?.['components']; - if (components) { + const components = pages[pageId]?.['components']; + + if (Object.keys(components).length > 0) { for (const componentId of Object.keys(components)) { const component = components[componentId]; - if (component?.component?.component === 'Table') { - component.component.definition.styles.cellSize = { - value: 'regular', - }; + if (component?.component?.component === 'Table' && component.component?.definition?.styles?.cellSize) { component.component.styles.cellSize = { ...component.component.styles.cellSize, options: [ @@ -30,27 +28,19 @@ export class CellSizeRegularCondensed1692973078520 implements MigrationInterface { name: 'Regular', value: 'regular' }, ], }; - components[componentId] = { - ...component, - component: { - ...component.component, - definition: { - ...component.component.definition, - }, - }, + + component.component.definition.styles.cellSize = { + value: 'regular', }; } } - pages[pageId]['components'] = components; } } } - definition['pages'] = pages; - version.definition = definition; - await queryBuilder.update(AppVersion).set({ definition }).where('id = :id', { id: version.id }).execute(); + await entityManager.update(AppVersion, { id: version.id }, { definition }); } } } diff --git a/server/data-migrations/1692974311591-TableRowCellStyle.ts b/server/data-migrations/1692974311591-TableRowCellStyle.ts index 114152b059..ca79b042e1 100644 --- a/server/data-migrations/1692974311591-TableRowCellStyle.ts +++ b/server/data-migrations/1692974311591-TableRowCellStyle.ts @@ -4,20 +4,20 @@ import { AppVersion } from '../src/entities/app_version.entity'; export class TableRowCellStyle1692974311591 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { 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']; + const definition = JSON.parse(JSON.stringify(version?.definition)); if (definition) { const pages = definition['pages']; - if (pages) { + if (Object.keys(pages).length > 0) { for (const pageId of Object.keys(pages)) { const components = pages[pageId]['components']; - if (components) { + if (Object.keys(components).length > 0) { for (const componentId of Object.keys(components)) { const component = components[componentId]; if (component?.component?.component === 'Table') { @@ -32,27 +32,15 @@ export class TableRowCellStyle1692974311591 implements MigrationInterface { { name: 'Striped', value: 'table-striped' }, ], }; - components[componentId] = { - ...component, - component: { - ...component.component, - definition: { - ...component.component.definition, - }, - }, - }; } } } - pages[pageId]['components'] = components; } } - definition['pages'] = pages; - version.definition = definition; - await queryBuilder.update(AppVersion).set({ definition }).where('id = :id', { id: version.id }).execute(); + await entityManager.update(AppVersion, { id: version.id }, { definition }); } } }