Commit 04405918 authored by chenos's avatar chenos
Browse files

feat: rename ui_schemas to uiSchemas

parent 99bfd757
Showing with 86 additions and 63 deletions
+86 -63
......@@ -13,6 +13,11 @@ if (yargs.argv.dbDialect) {
process.env.DB_DIALECT = yargs.argv.dbDialect;
}
console.log('DB_DIALECT: ', process.env.DB_DIALECT);
if (yargs.argv.dbPort) {
process.env.DB_PORT = yargs.argv.dbPort;
}
console.log('DB_DIALECT:', process.env.DB_DIALECT);
console.log('DB_PORT:', process.env.DB_PORT);
require('jest-cli/bin/jest');
......@@ -13,7 +13,7 @@
"start-server": "ts-node-dev -r dotenv/config -r tsconfig-paths/register ./packages/api/src/index.ts",
"build": "lerna run build",
"build-docs": "dumi build",
"test": "node ./jest.cli.js",
"test": "node ./jest.cli.js -i",
"lint": "eslint ."
},
"resolutions": {
......
......@@ -108,7 +108,7 @@ export default (apiClient: APIClient) => {
},
};
mock.onGet(/\/ui_schemas\:getJsonSchema\/(\w+)/).reply(function (config) {
mock.onGet(/\/uiSchemas\:getJsonSchema\/(\w+)/).reply(function (config) {
const name = config?.url?.split('/')?.pop();
if (name && jsonSchema[name]) {
......
......@@ -108,7 +108,7 @@ export default (apiClient: APIClient) => {
},
};
mock.onGet(/\/ui_schemas\:getJsonSchema\/(\w+)/).reply(function (config) {
mock.onGet(/\/uiSchemas\:getJsonSchema\/(\w+)/).reply(function (config) {
const name = config.url.split('/').pop();
console.log(name);
if (jsonSchema[name]) {
......@@ -135,7 +135,7 @@ export default (apiClient: APIClient) => {
return [200, response];
});
mock.onGet(/\/ui_schemas\:getProperties\/(\w+)/).reply(function (config) {
mock.onGet(/\/uiSchemas\:getProperties\/(\w+)/).reply(function (config) {
// const name = config.url.split('/').pop();
// console.log(name);
// if (jsonSchema[name]) {
......
......@@ -21,7 +21,7 @@ const RequestSchemaComponent: React.FC<RemoteSchemaComponentProps> = (props) =>
const { onlyRenderProperties, hidden, scope, uid, onSuccess, schemaTransform = defaultTransform } = props;
const { reset } = useSchemaComponentContext();
const conf = {
url: `/ui_schemas:${onlyRenderProperties ? 'getProperties' : 'getJsonSchema'}/${uid}`,
url: `/uiSchemas:${onlyRenderProperties ? 'getProperties' : 'getJsonSchema'}/${uid}`,
};
const { data, loading } = useRequest(conf, {
refreshDeps: [uid],
......
......@@ -82,13 +82,13 @@ export class Designable {
this.on('insertAdjacent', async ({ current, position, schema, removed }) => {
refresh();
await api.request({
url: `/ui_schemas:insertAdjacent/${current['x-uid']}?position=${position}`,
url: `/uiSchemas:insertAdjacent/${current['x-uid']}?position=${position}`,
method: 'post',
data: schema.toJSON(),
});
if (removed?.['x-uid']) {
await api.request({
url: `/ui_schemas:remove/${removed['x-uid']}`,
url: `/uiSchemas:remove/${removed['x-uid']}`,
method: 'post',
});
}
......@@ -97,7 +97,7 @@ export class Designable {
refresh();
if (removed?.['x-uid']) {
await api.request({
url: `/ui_schemas:remove/${removed['x-uid']}`,
url: `/uiSchemas:remove/${removed['x-uid']}`,
method: 'post',
});
}
......
......@@ -42,7 +42,7 @@ export default {
{
type: 'belongsToMany',
name: 'menuUiSchemas',
target: 'ui_schemas',
target: 'uiSchemas',
},
{
type: 'hasMany',
......
......@@ -53,7 +53,7 @@ export default {
{
type: 'belongsTo',
name: 'uiSchema',
target: 'ui_schemas',
target: 'uiSchemas',
foreignKey: 'uiSchemaUid'
},
{
......
......@@ -30,7 +30,7 @@ export default defineCollection({
{
type: 'belongsTo',
name: 'uiSchema',
target: 'ui_schemas',
target: 'uiSchemas',
foreignKey: 'uiSchemaUid'
},
{
......
import { MockServer, mockServer } from '@nocobase/test';
import { Database } from '@nocobase/database';
import { MockServer, mockServer } from '@nocobase/test';
import PluginUiSchema from '../server';
describe('action test', () => {
......@@ -34,7 +34,7 @@ describe('action test', () => {
test('insert action', async () => {
const response = await app
.agent()
.resource('ui_schemas')
.resource('uiSchemas')
.insert({
values: {
'x-uid': 'n1',
......@@ -59,7 +59,7 @@ describe('action test', () => {
test('getJsonSchema', async () => {
await app
.agent()
.resource('ui_schemas')
.resource('uiSchemas')
.insert({
values: {
'x-uid': 'n1',
......@@ -78,7 +78,7 @@ describe('action test', () => {
},
});
const response = await app.agent().resource('ui_schemas').getJsonSchema({
const response = await app.agent().resource('uiSchemas').getJsonSchema({
resourceIndex: 'n1',
});
......@@ -87,7 +87,7 @@ describe('action test', () => {
});
test('getJsonSchema when uid not exists', async () => {
const response = await app.agent().resource('ui_schemas').getJsonSchema({
const response = await app.agent().resource('uiSchemas').getJsonSchema({
resourceIndex: 'not-exists',
});
......@@ -95,7 +95,7 @@ describe('action test', () => {
});
test('get properties when uid not exists', async () => {
const response = await app.agent().resource('ui_schemas').getProperties({
const response = await app.agent().resource('uiSchemas').getProperties({
resourceIndex: 'not-exists',
});
......@@ -105,7 +105,7 @@ describe('action test', () => {
test('remove', async () => {
await app
.agent()
.resource('ui_schemas')
.resource('uiSchemas')
.insert({
values: {
'x-uid': 'n1',
......@@ -124,13 +124,13 @@ describe('action test', () => {
},
});
let response = await app.agent().resource('ui_schemas').remove({
let response = await app.agent().resource('uiSchemas').remove({
resourceIndex: 'n2',
});
expect(response.statusCode).toEqual(200);
response = await app.agent().resource('ui_schemas').getJsonSchema({
response = await app.agent().resource('uiSchemas').getJsonSchema({
resourceIndex: 'n1',
});
......@@ -141,7 +141,7 @@ describe('action test', () => {
test('patch', async () => {
await app
.agent()
.resource('ui_schemas')
.resource('uiSchemas')
.insert({
values: {
'x-uid': 'n1',
......@@ -162,7 +162,7 @@ describe('action test', () => {
let response = await app
.agent()
.resource('ui_schemas')
.resource('uiSchemas')
.patch({
values: {
'x-uid': 'n1',
......@@ -179,7 +179,7 @@ describe('action test', () => {
});
expect(response.statusCode).toEqual(200);
response = await app.agent().resource('ui_schemas').getJsonSchema({
response = await app.agent().resource('uiSchemas').getJsonSchema({
resourceIndex: 'n1',
});
......@@ -190,7 +190,7 @@ describe('action test', () => {
test('insert adjacent', async () => {
await app
.agent()
.resource('ui_schemas')
.resource('uiSchemas')
.insert({
values: {
'x-uid': 'n1',
......@@ -211,7 +211,7 @@ describe('action test', () => {
let response = await app
.agent()
.resource('ui_schemas')
.resource('uiSchemas')
.insertAdjacent({
resourceIndex: 'n2',
position: 'beforeBegin',
......@@ -222,7 +222,7 @@ describe('action test', () => {
});
expect(response.statusCode).toEqual(200);
response = await app.agent().resource('ui_schemas').getJsonSchema({
response = await app.agent().resource('uiSchemas').getJsonSchema({
resourceIndex: 'n1',
});
......
import { mockServer, MockServer } from '@nocobase/test';
import { BelongsToManyRepository, Database, HasManyRepository } from '@nocobase/database';
import UiSchemaStoragePlugin, { UiSchemaRepository } from '@nocobase/plugin-ui-schema-storage';
import PluginCollectionManager from '@nocobase/plugin-collection-manager';
import { BelongsToManyRepository, Database } from '@nocobase/database';
import PluginACL from '@nocobase/plugin-acl';
import PluginCollectionManager from '@nocobase/plugin-collection-manager';
import UiSchemaStoragePlugin, { UiSchemaRepository } from '@nocobase/plugin-ui-schema-storage';
import { mockServer, MockServer } from '@nocobase/test';
describe('server hooks', () => {
let app: MockServer;
......@@ -27,7 +27,7 @@ describe('server hooks', () => {
await app.loadAndInstall();
uiSchemaRepository = db.getRepository('ui_schemas');
uiSchemaRepository = db.getRepository('uiSchemas');
uiSchemaPlugin = app.getPlugin<UiSchemaStoragePlugin>('UiSchemaStoragePlugin');
});
......
import { mockServer, MockServer } from '@nocobase/test';
import { Database } from '@nocobase/database';
import UiSchemaStoragePlugin, { UiSchemaRepository } from '@nocobase/plugin-ui-schema-storage';
import PluginCollectionManager from '@nocobase/plugin-collection-manager';
import UiSchemaStoragePlugin, { UiSchemaRepository } from '@nocobase/plugin-ui-schema-storage';
import { mockServer, MockServer } from '@nocobase/test';
describe('server hooks', () => {
let app: MockServer;
......@@ -65,7 +65,7 @@ describe('server hooks', () => {
await app.loadAndInstall();
uiSchemaRepository = db.getRepository('ui_schemas');
uiSchemaRepository = db.getRepository('uiSchemas');
await uiSchemaRepository.insert(schema);
uiSchemaPlugin = app.getPlugin<UiSchemaStoragePlugin>('UiSchemaStoragePlugin');
......
import { mockServer, MockServer } from '@nocobase/test';
import { Collection, Database } from '@nocobase/database';
import { mockServer, MockServer } from '@nocobase/test';
import PluginUiSchema, { UiSchemaRepository } from '..';
describe('ui schema model', () => {
......@@ -32,7 +32,7 @@ describe('ui schema model', () => {
{
type: 'belongsTo',
name: 'uiSchema',
target: 'ui_schemas',
target: 'uiSchemas',
},
],
});
......@@ -41,7 +41,7 @@ describe('ui schema model', () => {
});
it('should create schema tree after ui_schema created', async () => {
const uiSchemaRepository = db.getCollection('ui_schemas').repository as UiSchemaRepository;
const uiSchemaRepository = db.getCollection('uiSchemas').repository as UiSchemaRepository;
await RelatedCollection.repository.create({
values: {
......@@ -82,7 +82,7 @@ describe('ui schema model', () => {
});
it('should update schema tree after ui_schema updated', async () => {
const uiSchemaRepository = db.getCollection('ui_schemas').repository as UiSchemaRepository;
const uiSchemaRepository = db.getCollection('uiSchemas').repository as UiSchemaRepository;
const relatedInstance = await RelatedCollection.repository.create({
values: {
......
import { mockServer, MockServer } from '@nocobase/test';
import { Collection, Database } from '@nocobase/database';
import PluginUiSchema from '../server';
import UiSchemaRepository from '../repository';
import { mockServer, MockServer } from '@nocobase/test';
import { SchemaNode } from '../dao/ui_schema_node_dao';
import UiSchemaRepository from '../repository';
import PluginUiSchema from '../server';
describe('ui_schema repository', () => {
let app: MockServer;
......@@ -34,12 +34,12 @@ describe('ui_schema repository', () => {
drop: false,
},
});
repository = db.getCollection('ui_schemas').repository as UiSchemaRepository;
repository = db.getCollection('uiSchemas').repository as UiSchemaRepository;
treePathCollection = db.getCollection('ui_schema_tree_path');
});
it('should be registered', async () => {
expect(db.getCollection('ui_schemas').repository).toBeInstanceOf(UiSchemaRepository);
expect(db.getCollection('uiSchemas').repository).toBeInstanceOf(UiSchemaRepository);
});
it('should insert single ui schema node', async () => {
......
import { ISchema } from '@formily/json-schema';
import { Database } from '@nocobase/database';
import { mockServer, MockServer } from '@nocobase/test';
import { Collection, Database } from '@nocobase/database';
import PluginUiSchema, { UiSchemaRepository } from '..';
describe('ui-schema', () => {
......@@ -25,7 +25,7 @@ describe('ui-schema', () => {
app.plugin(PluginUiSchema);
await app.loadAndInstall();
uiSchemaRepository = db.getCollection('ui_schemas').repository as UiSchemaRepository;
uiSchemaRepository = db.getCollection('uiSchemas').repository as UiSchemaRepository;
});
type SchemaProperties = Record<string, ISchema>;
......
......@@ -2,7 +2,7 @@ import { Context } from '@nocobase/actions';
import UiSchemaRepository from '../repository';
const getRepositoryFromCtx = (ctx: Context) => {
return ctx.db.getCollection('ui_schemas').repository as UiSchemaRepository;
return ctx.db.getCollection('uiSchemas').repository as UiSchemaRepository;
};
export const uiSchemaActions = {
......
......@@ -6,7 +6,7 @@ export default {
// autoGenId: false,
timestamps: false,
fields: [
{ type: 'belongsTo', name: 'uiSchema', target: 'ui_schemas', foreignKey: 'uid', onDelete: 'CASCADE' },
{ type: 'belongsTo', name: 'uiSchema', target: 'uiSchemas', foreignKey: 'uid', onDelete: 'CASCADE' },
{ type: 'string', name: 'type' },
{
type: 'string',
......
import { CollectionOptions } from '@nocobase/database';
export default {
name: 'ui_schemas',
name: 'uiSchemas',
title: '字段配置',
autoGenId: false,
timestamps: false,
......
......@@ -12,6 +12,22 @@ interface GetJsonSchemaOptions {
const nodeKeys = ['properties', 'definitions', 'patternProperties', 'additionalProperties', 'items'];
export class UiSchemaRepository extends Repository {
get uiSchemasTableName() {
if (this.database.sequelize.getDialect() === 'postgres') {
return `"${this.model.tableName}"`;
}
return this.model.tableName;
}
get uiSchemaTreePathTableName() {
const model = this.database.getCollection('ui_schema_tree_path').model;
if (this.database.sequelize.getDialect() === 'postgres') {
return `"${model.tableName}"`;
}
return model.tableName;
}
static schemaToSingleNodes(schema: any, carry: SchemaNode[] = [], childOptions: ChildOptions = null): SchemaNode[] {
const node = lodash.cloneDeep(
lodash.isString(schema)
......@@ -71,16 +87,19 @@ export class UiSchemaRepository extends Repository {
async getProperties(uid: string) {
const db = this.database;
const treeCollection = db.getCollection('ui_schema_tree_path');
const rawSql = `
SELECT SchemaTable.uid as uid, SchemaTable.name as name, SchemaTable.schema as "schema",
TreePath.depth as depth,
NodeInfo.type as type, NodeInfo.async as async, ParentPath.ancestor as parent, ParentPath.sort as sort
FROM ${treeCollection.model.tableName} as TreePath
LEFT JOIN ${this.model.tableName} as SchemaTable ON SchemaTable.uid = TreePath.descendant
LEFT JOIN ${treeCollection.model.tableName} as NodeInfo ON NodeInfo.descendant = SchemaTable.uid and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0
LEFT JOIN ${treeCollection.model.tableName} as ParentPath ON (ParentPath.descendant = SchemaTable.uid AND ParentPath.depth = 1)
FROM ${this.uiSchemaTreePathTableName} as TreePath
LEFT JOIN ${this.uiSchemasTableName} as SchemaTable ON SchemaTable.uid = TreePath.descendant
LEFT JOIN ${
this.uiSchemaTreePathTableName
} as NodeInfo ON NodeInfo.descendant = SchemaTable.uid and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0
LEFT JOIN ${
this.uiSchemaTreePathTableName
} as ParentPath ON (ParentPath.descendant = SchemaTable.uid AND ParentPath.depth = 1)
WHERE TreePath.ancestor = :ancestor AND (NodeInfo.async = false or TreePath.depth = 1)`;
const nodes = await db.sequelize.query(rawSql, {
......@@ -99,16 +118,15 @@ export class UiSchemaRepository extends Repository {
async getJsonSchema(uid: string, options?: GetJsonSchemaOptions) {
const db = this.database;
const treeCollection = db.getCollection('ui_schema_tree_path');
const treeTable = treeCollection.model.tableName;
const treeTable = this.uiSchemaTreePathTableName;
const rawSql = `
SELECT SchemaTable.uid as uid, SchemaTable.name as name, SchemaTable.schema as "schema" ,
TreePath.depth as depth,
NodeInfo.type as type, NodeInfo.async as async, ParentPath.ancestor as parent, ParentPath.sort as sort
FROM ${treeTable} as TreePath
LEFT JOIN ${this.model.tableName} as SchemaTable ON SchemaTable.uid = TreePath.descendant
LEFT JOIN ${this.uiSchemasTableName} as SchemaTable ON SchemaTable.uid = TreePath.descendant
LEFT JOIN ${treeTable} as NodeInfo ON NodeInfo.descendant = SchemaTable.uid and NodeInfo.descendant = NodeInfo.ancestor and NodeInfo.depth = 0
LEFT JOIN ${treeTable} as ParentPath ON (ParentPath.descendant = SchemaTable.uid AND ParentPath.depth = 1)
WHERE TreePath.ancestor = :ancestor ${options?.includeAsyncNode ? '' : 'AND (NodeInfo.async != true )'}
......@@ -269,7 +287,7 @@ export class UiSchemaRepository extends Repository {
const parentChildrenCount = countResult[0]['count'];
if (parentChildrenCount == 1) {
const schema = await db.getRepository('ui_schemas').findOne({
const schema = await db.getRepository('uiSchemas').findOne({
filter: {
uid: parent.get('ancestor') as string,
},
......@@ -311,11 +329,11 @@ export class UiSchemaRepository extends Repository {
transaction = await this.database.sequelize.transaction();
}
const treePathTable = this.treeCollection().model.tableName;
const treePathTable = this.uiSchemaTreePathTableName;
try {
await this.database.sequelize.query(
`DELETE FROM ${this.model.tableName} WHERE uid IN (
`DELETE FROM ${this.uiSchemasTableName} WHERE uid IN (
SELECT descendant FROM ${treePathTable} WHERE ancestor = :uid
)
`,
......@@ -362,7 +380,7 @@ export class UiSchemaRepository extends Repository {
});
const db = this.database;
const treeTable = this.treeCollection().model.tableName;
const treeTable = this.uiSchemaTreePathTableName;
const typeQuery = await db.sequelize.query(`SELECT type from ${treeTable} WHERE ancestor = :uid AND depth = 0;`, {
type: 'SELECT',
replacements: {
......@@ -503,7 +521,7 @@ export class UiSchemaRepository extends Repository {
transaction,
});
const treeTable = treeCollection.model.tableName;
const treeTable = this.uiSchemaTreePathTableName;
if (existsNode) {
savedNode = existsNode;
......
......@@ -2,7 +2,7 @@ import { UiSchemaRepository } from '../../repository';
export async function removeSchema({ schemaInstance, options, db, params }) {
const { transaction } = options;
const uiSchemaRepository: UiSchemaRepository = db.getRepository('ui_schemas');
const uiSchemaRepository: UiSchemaRepository = db.getRepository('uiSchemas');
const uid = schemaInstance.get('uid') as string;
if (params?.removeEmptyParents) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment