feat(ui-schema-storage): support duplicate
This commit is contained in:
parent
dc97149164
commit
f603242e38
@ -1,5 +1,5 @@
|
|||||||
import { Collection, Database } from '@nocobase/database';
|
import { Collection, Database } from '@nocobase/database';
|
||||||
import { mockServer, MockServer } from '@nocobase/test';
|
import { MockServer, mockServer } from '@nocobase/test';
|
||||||
import { SchemaNode } from '../dao/ui_schema_node_dao';
|
import { SchemaNode } from '../dao/ui_schema_node_dao';
|
||||||
import UiSchemaRepository from '../repository';
|
import UiSchemaRepository from '../repository';
|
||||||
import PluginUiSchema from '../server';
|
import PluginUiSchema from '../server';
|
||||||
@ -196,6 +196,34 @@ describe('ui_schema repository', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should create a copy', async () => {
|
||||||
|
const s = await repository.insert({
|
||||||
|
'x-uid': 'n1',
|
||||||
|
name: 'a',
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
b: {
|
||||||
|
'x-uid': 'n2',
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
c: { 'x-uid': 'n3' },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
d: {
|
||||||
|
'x-uid': 'n4',
|
||||||
|
properties: {
|
||||||
|
e: {
|
||||||
|
'x-uid': 'n5',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const s2 = await repository.duplicate(s['x-uid']);
|
||||||
|
expect(s2.name).toEqual(s.name);
|
||||||
|
expect(s2['x-uid']).not.toEqual(s['x-uid']);
|
||||||
|
});
|
||||||
|
|
||||||
describe('schema', () => {
|
describe('schema', () => {
|
||||||
let schema;
|
let schema;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -744,6 +744,20 @@ export class UiSchemaRepository extends Repository {
|
|||||||
return insertedNodes;
|
return insertedNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private regenerateUid(s: any) {
|
||||||
|
s['x-uid'] = uid();
|
||||||
|
Object.keys(s.properties || {}).forEach((key) => {
|
||||||
|
this.regenerateUid(s.properties[key]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@transaction()
|
||||||
|
async duplicate(uid: string, options?: Transactionable) {
|
||||||
|
const s = await this.getJsonSchema(uid, { ...options, includeAsyncNode: true });
|
||||||
|
this.regenerateUid(s);
|
||||||
|
return this.insert(s, options);
|
||||||
|
}
|
||||||
|
|
||||||
@transaction()
|
@transaction()
|
||||||
async insert(schema: any, options?: Transactionable) {
|
async insert(schema: any, options?: Transactionable) {
|
||||||
const nodes = UiSchemaRepository.schemaToSingleNodes(schema);
|
const nodes = UiSchemaRepository.schemaToSingleNodes(schema);
|
||||||
|
Loading…
Reference in New Issue
Block a user