mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:38:13 +00:00
feat: getParentJsonSchema in ui schema repository (#3690)
* feat: getParentJsonSchema in ui schema repository * chore: ui schema snippet * chore: method name * chore: test * chore: test * fix: getParentProperty --------- Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
parent
ac1e07ff52
commit
dfcf7671d3
@ -1,5 +1,5 @@
|
||||
import { Database } from '@nocobase/database';
|
||||
import { MockServer, createMockServer } from '@nocobase/test';
|
||||
import { createMockServer, MockServer } from '@nocobase/test';
|
||||
|
||||
describe('action test', () => {
|
||||
let app: MockServer;
|
||||
@ -17,6 +17,35 @@ describe('action test', () => {
|
||||
await app.destroy();
|
||||
});
|
||||
|
||||
test('get parent property', async () => {
|
||||
await app
|
||||
.agent()
|
||||
.resource('uiSchemas')
|
||||
.insert({
|
||||
values: {
|
||||
'x-uid': 'n1',
|
||||
name: 'a',
|
||||
type: 'object',
|
||||
properties: {
|
||||
b: {
|
||||
'x-uid': 'n2',
|
||||
type: 'object',
|
||||
properties: {
|
||||
c: { 'x-uid': 'n3' },
|
||||
},
|
||||
},
|
||||
d: { 'x-uid': 'n4' },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const response = await app.agent().resource('uiSchemas').getParentProperty({
|
||||
filterByTk: 'n2',
|
||||
});
|
||||
|
||||
expect(response.body.data['x-uid']).toEqual('n1');
|
||||
});
|
||||
|
||||
test('insert action', async () => {
|
||||
const response = await app
|
||||
.agent()
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { Collection, Database } from '@nocobase/database';
|
||||
import { createMockServer, MockServer } from '@nocobase/test';
|
||||
import { MockServer, createMockServer } from '@nocobase/test';
|
||||
import { SchemaNode } from '../dao/ui_schema_node_dao';
|
||||
import UiSchemaRepository from '../repository';
|
||||
|
||||
@ -366,6 +366,48 @@ describe('ui_schema repository', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should get parent json schema', async () => {
|
||||
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' },
|
||||
},
|
||||
});
|
||||
|
||||
const parentSchema = await repository.getParentJsonSchema('n2');
|
||||
expect(parentSchema['x-uid']).toBe('n1');
|
||||
});
|
||||
|
||||
it('should get parent property', async () => {
|
||||
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' },
|
||||
},
|
||||
});
|
||||
|
||||
const parentProperty = await repository.getParentProperty('n2');
|
||||
expect(parentProperty['x-uid']).toBe('n1');
|
||||
});
|
||||
|
||||
it('should getJsonSchema by subTree', async () => {
|
||||
await repository.insert({
|
||||
'x-uid': 'n1',
|
||||
|
@ -50,6 +50,10 @@ export const uiSchemaActions = {
|
||||
readFromCache: true,
|
||||
}) as GetPropertiesOptions,
|
||||
),
|
||||
|
||||
getParentJsonSchema: callRepositoryMethod('getParentJsonSchema', 'resourceIndex'),
|
||||
getParentProperty: callRepositoryMethod('getParentProperty', 'resourceIndex'),
|
||||
|
||||
insert: callRepositoryMethod('insert', 'values'),
|
||||
insertNewSchema: callRepositoryMethod('insertNewSchema', 'values'),
|
||||
remove: callRepositoryMethod('remove', 'resourceIndex'),
|
||||
|
@ -189,6 +189,26 @@ export class UiSchemaRepository extends Repository {
|
||||
return this.doGetProperties(uid, options);
|
||||
}
|
||||
|
||||
async getParentJsonSchema(uid: string, options: GetJsonSchemaOptions = {}) {
|
||||
const parentUid = await this.findParentUid(uid, options.transaction);
|
||||
|
||||
if (!parentUid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.getJsonSchema(parentUid, options);
|
||||
}
|
||||
|
||||
async getParentProperty(uid: string, options: GetPropertiesOptions = {}) {
|
||||
const parentUid = await this.findParentUid(uid, options.transaction);
|
||||
|
||||
if (!parentUid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.getJsonSchema(parentUid, options);
|
||||
}
|
||||
|
||||
async getJsonSchema(uid: string, options?: GetJsonSchemaOptions): Promise<any> {
|
||||
if (options?.readFromCache && this.cache) {
|
||||
return this.cache.wrap(`s_${uid}`, () => {
|
||||
|
@ -33,20 +33,7 @@ export class UiSchemaStoragePlugin extends Plugin {
|
||||
|
||||
this.app.acl.registerSnippet({
|
||||
name: 'ui.uiSchemas',
|
||||
actions: [
|
||||
'uiSchemas:insert',
|
||||
'uiSchemas:insertNewSchema',
|
||||
'uiSchemas:remove',
|
||||
'uiSchemas:patch',
|
||||
'uiSchemas:batchPatch',
|
||||
'uiSchemas:clearAncestor',
|
||||
'uiSchemas:insertBeforeBegin',
|
||||
'uiSchemas:insertAfterBegin',
|
||||
'uiSchemas:insertBeforeEnd',
|
||||
'uiSchemas:insertAfterEnd',
|
||||
'uiSchemas:insertAdjacent',
|
||||
'uiSchemas:saveAsTemplate',
|
||||
],
|
||||
actions: ['uiSchemas:*'],
|
||||
});
|
||||
|
||||
db.on('uiSchemas.beforeCreate', function setUid(model) {
|
||||
|
Loading…
Reference in New Issue
Block a user