Merge pull request #8386 from ToolJet/fix-grid/import-export

[grid] Add support for importing apps With Normalized AppDefinition Schema and legacy imports
This commit is contained in:
Johnson Cherian 2024-01-08 11:31:35 +05:30 committed by GitHub
commit 80e36034de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 9 deletions

View file

@ -1 +1 @@
2.26.2 2.27.0

View file

@ -1 +1 @@
2.26.2 2.27.0

View file

@ -1 +1 @@
2.26.2 2.27.0

View file

@ -235,3 +235,11 @@ export function extractMajorVersion(version) {
export function isTooljetVersionWithNormalizedAppDefinitionSchem(version) { export function isTooljetVersionWithNormalizedAppDefinitionSchem(version) {
return semver.satisfies(semver.coerce(version), '>= 2.24.0'); return semver.satisfies(semver.coerce(version), '>= 2.24.0');
} }
/**
* Checks if a given Tooljet version is compatible with the grid compatibility fix.
*/
export function shouldApplyGridCompatibilityFix(version) {
return semver.satisfies(semver.coerce(version), '>= 2.24.0 < 2.27.0');
}

View file

@ -17,6 +17,7 @@ import {
catchDbException, catchDbException,
extractMajorVersion, extractMajorVersion,
isTooljetVersionWithNormalizedAppDefinitionSchem, isTooljetVersionWithNormalizedAppDefinitionSchem,
shouldApplyGridCompatibilityFix,
} from 'src/helpers/utils.helper'; } from 'src/helpers/utils.helper';
import { AppEnvironmentService } from './app_environments.service'; import { AppEnvironmentService } from './app_environments.service';
import { convertAppDefinitionFromSinglePageToMultiPage } from '../../lib/single-page-to-and-from-multipage-definition-conversion'; import { convertAppDefinitionFromSinglePageToMultiPage } from '../../lib/single-page-to-and-from-multipage-definition-conversion';
@ -58,6 +59,11 @@ const DefaultDataSourceNames: DefaultDataSourceName[] = [
]; ];
const DefaultDataSourceKinds: DefaultDataSourceKind[] = ['restapi', 'runjs', 'runpy', 'tooljetdb', 'workflows']; const DefaultDataSourceKinds: DefaultDataSourceKind[] = ['restapi', 'runjs', 'runpy', 'tooljetdb', 'workflows'];
function resolveGridPositionForComponent(dimension: number, type: string) {
const numberOfGrids = type === 'desktop' ? 43 : 12;
return Math.round((dimension * numberOfGrids) / 100);
}
@Injectable() @Injectable()
export class AppImportExportService { export class AppImportExportService {
constructor( constructor(
@ -228,6 +234,9 @@ export class AppImportExportService {
? true ? true
: isTooljetVersionWithNormalizedAppDefinitionSchem(importedAppTooljetVersion); : isTooljetVersionWithNormalizedAppDefinitionSchem(importedAppTooljetVersion);
const shouldUpdateForGridCompatibility: boolean =
!cloning && shouldApplyGridCompatibilityFix(importedAppTooljetVersion);
const importedApp = await this.createImportedAppForUser(this.entityManager, schemaUnifiedAppParams, user); const importedApp = await this.createImportedAppForUser(this.entityManager, schemaUnifiedAppParams, user);
await this.setupImportedAppAssociations( await this.setupImportedAppAssociations(
@ -236,7 +245,8 @@ export class AppImportExportService {
schemaUnifiedAppParams, schemaUnifiedAppParams,
user, user,
externalResourceMappings, externalResourceMappings,
isNormalizedAppDefinitionSchema isNormalizedAppDefinitionSchema,
shouldUpdateForGridCompatibility
); );
await this.createAdminGroupPermissions(this.entityManager, importedApp); await this.createAdminGroupPermissions(this.entityManager, importedApp);
@ -314,7 +324,8 @@ export class AppImportExportService {
appParams: any, appParams: any,
user: User, user: User,
externalResourceMappings: Record<string, unknown>, externalResourceMappings: Record<string, unknown>,
isNormalizedAppDefinitionSchema: boolean isNormalizedAppDefinitionSchema: boolean,
shouldUpdateForGridCompatibility: boolean
) { ) {
// Old version without app version // Old version without app version
// Handle exports prior to 0.12.0 // Handle exports prior to 0.12.0
@ -377,7 +388,8 @@ export class AppImportExportService {
importingDefaultAppEnvironmentId, importingDefaultAppEnvironmentId,
importingPages, importingPages,
importingComponents, importingComponents,
importingEvents importingEvents,
shouldUpdateForGridCompatibility
); );
if (!isNormalizedAppDefinitionSchema) { if (!isNormalizedAppDefinitionSchema) {
@ -438,7 +450,7 @@ export class AppImportExportService {
const newLayout = new Layout(); const newLayout = new Layout();
newLayout.type = type; newLayout.type = type;
newLayout.top = layout.top; newLayout.top = layout.top;
newLayout.left = layout.left; newLayout.left = resolveGridPositionForComponent(layout.left, type);
newLayout.width = layout.width; newLayout.width = layout.width;
newLayout.height = layout.height; newLayout.height = layout.height;
newLayout.componentId = appResourceMappings.componentsMapping[componentId]; newLayout.componentId = appResourceMappings.componentsMapping[componentId];
@ -574,7 +586,8 @@ export class AppImportExportService {
importingDefaultAppEnvironmentId: string, importingDefaultAppEnvironmentId: string,
importingPages: Page[], importingPages: Page[],
importingComponents: Component[], importingComponents: Component[],
importingEvents: EventHandler[] importingEvents: EventHandler[],
shouldUpdateForGridCompatibility: boolean
): Promise<AppResourceMappings> { ): Promise<AppResourceMappings> {
appResourceMappings = { ...appResourceMappings }; appResourceMappings = { ...appResourceMappings };
@ -740,7 +753,9 @@ export class AppImportExportService {
const newLayout = new Layout(); const newLayout = new Layout();
newLayout.type = layout.type; newLayout.type = layout.type;
newLayout.top = layout.top; newLayout.top = layout.top;
newLayout.left = layout.left; newLayout.left = shouldUpdateForGridCompatibility
? resolveGridPositionForComponent(layout.left, layout.type)
: layout.left;
newLayout.width = layout.width; newLayout.width = layout.width;
newLayout.height = layout.height; newLayout.height = layout.height;
newLayout.component = savedComponent; newLayout.component = savedComponent;