Merge pull request #682 from smartxworks/feat/extract-module

fix module related bugs
This commit is contained in:
tanbowensg 2023-01-20 13:44:21 +08:00 committed by GitHub
commit 96b971a1a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 8 deletions

View File

@ -1,5 +1,9 @@
import { Type } from '@sinclair/typebox';
import { addModuleId, removeModuleId } from '../src/utils/addModuleId';
import {
addModuleId,
removeModuleId,
replaceIdsInProperty,
} from '../src/utils/addModuleId';
describe('format to module schema', () => {
it('will add module id to the expression', () => {
@ -170,3 +174,14 @@ describe('format to module schema', () => {
).toEqual({ value: 'input1.value' });
});
});
describe('test replaceIdsInProperty', () => {
it('works when there is \n in expression', () => {
const exp = '{{ \nlicense_type_map.value[license.value.info.licenseType]}}';
const ids = ['license_type_map'];
const result = replaceIdsInProperty(exp, ids);
expect(result).toBe(
'{{ \n{{ $moduleId }}__license_type_map.value[license.value.info.licenseType]}}'
);
});
});

View File

@ -96,13 +96,18 @@ export class EditorStore {
if (target.name) {
this.setCurrentComponentsVersion(0);
this.setLastSavedComponentsVersion(0);
// clear currrent components and store
this.clearSunmaoGlobalState();
this.eventBus.send('stateRefresh');
this.eventBus.send('componentsRefresh', this.originComponents);
this.setComponents(this.originComponents);
this.setSelectedComponentId(this.originComponents[0]?.id || '');
this.setModuleDependencies(target.metadata?.exampleProperties);
this.eventBus.send('componentsRefresh', []);
this.setComponents([]);
setTimeout(() => {
// set new components
this.setSelectedComponentId(this.originComponents[0]?.id || '');
this.setModuleDependencies(target.metadata?.exampleProperties);
this.eventBus.send('componentsRefresh', this.originComponents);
this.setComponents(this.originComponents);
}, 0);
}
}
);

View File

@ -76,8 +76,8 @@ export function removeModuleId(originModule: Module): Module {
}
// example: replaceIdsInExp('{{input1.value}} + {{input2.value}}', ids: ['input1']])
function replaceIdsInProperty(property: string, ids: string[]): string {
const matches = [...property.matchAll(/{{(.*?)}}/g)];
export function replaceIdsInProperty(property: string, ids: string[]): string {
const matches = [...property.matchAll(/{{((.|\n)*?)}}/g)];
if (matches.length === 0) return property;