mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2025-04-06 21:40:23 +08:00
Merge pull request #682 from smartxworks/feat/extract-module
fix module related bugs
This commit is contained in:
commit
96b971a1a2
@ -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]}}'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user