mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
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:
commit
80e36034de
5 changed files with 32 additions and 9 deletions
2
.version
2
.version
|
|
@ -1 +1 @@
|
||||||
2.26.2
|
2.27.0
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
2.26.2
|
2.27.0
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
2.26.2
|
2.27.0
|
||||||
|
|
|
||||||
|
|
@ -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');
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue