fix(ui-schema-storage): duplicate of empty schema

This commit is contained in:
chenos 2024-01-02 14:44:54 +08:00
parent 29b47c1d40
commit 5de28cd4c4
2 changed files with 8 additions and 0 deletions

View File

@ -225,6 +225,11 @@ describe('ui_schema repository', () => {
expect(s2['x-uid']).not.toEqual(s['x-uid']); expect(s2['x-uid']).not.toEqual(s['x-uid']);
}); });
it('should be null', async () => {
const s2 = await repository.duplicate('test-null');
expect(s2).toBeNull();
});
describe('schema', () => { describe('schema', () => {
let schema; let schema;
beforeEach(() => { beforeEach(() => {

View File

@ -445,6 +445,9 @@ export class UiSchemaRepository extends Repository {
@transaction() @transaction()
async duplicate(uid: string, options?: Transactionable) { async duplicate(uid: string, options?: Transactionable) {
const s = await this.getJsonSchema(uid, { ...options, includeAsyncNode: true }); const s = await this.getJsonSchema(uid, { ...options, includeAsyncNode: true });
if (!s?.['x-uid']) {
return null;
}
this.regenerateUid(s); this.regenerateUid(s);
return this.insert(s, options); return this.insert(s, options);
} }