From 28da6a5f82220de999b990df659e47e309bf52c0 Mon Sep 17 00:00:00 2001 From: chenos Date: Sat, 16 Apr 2022 17:07:00 +0800 Subject: [PATCH] feat: create system fields by default --- .../Configuration/AddFieldAction.tsx | 2 +- .../Configuration/AddSubFieldAction.tsx | 2 +- .../Configuration/ConfigurationTable.tsx | 75 +++++++++++++++++++ .../src/collection-manager/interfaces/id.ts | 47 ++++++++++++ .../collection-manager/interfaces/index.ts | 1 + 5 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 packages/client/src/collection-manager/interfaces/id.ts diff --git a/packages/client/src/collection-manager/Configuration/AddFieldAction.tsx b/packages/client/src/collection-manager/Configuration/AddFieldAction.tsx index 43b59a504..dd61ddb14 100644 --- a/packages/client/src/collection-manager/Configuration/AddFieldAction.tsx +++ b/packages/client/src/collection-manager/Configuration/AddFieldAction.tsx @@ -20,9 +20,9 @@ const getSchema = (schema: IField): ISchema => { } const properties = cloneDeep(schema.properties) as any; const initialValue = { + name: `f_${uid()}`, ...cloneDeep(schema.default), interface: schema.name, - name: `f_${uid()}`, }; initialValue.uiSchema.title = schema.title; return { diff --git a/packages/client/src/collection-manager/Configuration/AddSubFieldAction.tsx b/packages/client/src/collection-manager/Configuration/AddSubFieldAction.tsx index 6d9eb1c75..ebd2953b3 100644 --- a/packages/client/src/collection-manager/Configuration/AddSubFieldAction.tsx +++ b/packages/client/src/collection-manager/Configuration/AddSubFieldAction.tsx @@ -19,9 +19,9 @@ const getSchema = (schema: IField): ISchema => { } const properties = cloneDeep(schema.properties) as any; const initialValue = { + name: `f_${uid()}`, ...cloneDeep(schema.default), interface: schema.name, - name: `f_${uid()}`, }; initialValue.uiSchema.title = schema.title; console.log('initialValue', initialValue); diff --git a/packages/client/src/collection-manager/Configuration/ConfigurationTable.tsx b/packages/client/src/collection-manager/Configuration/ConfigurationTable.tsx index 75d860a6d..a71fe52dd 100644 --- a/packages/client/src/collection-manager/Configuration/ConfigurationTable.tsx +++ b/packages/client/src/collection-manager/Configuration/ConfigurationTable.tsx @@ -30,6 +30,81 @@ const useCollectionValues = (options) => { createdBy: true, updatedBy: true, sortable: true, + fields: [ + { + name: 'id', + type: 'integer', + autoIncrement: true, + primaryKey: true, + allowNull: false, + uiSchema: { type: 'number', title: '{{t("ID")}}', 'x-component': 'InputNumber', 'x-read-pretty': true }, + interface: 'id', + }, + { + interface: 'createdAt', + type: 'date', + field: 'createdAt', + name: 'createdAt', + uiSchema: { + type: 'datetime', + title: '{{t("Created at")}}', + 'x-component': 'DatePicker', + 'x-component-props': {}, + 'x-read-pretty': true, + }, + }, + { + interface: 'createdBy', + type: 'belongsTo', + target: 'users', + foreignKey: 'createdById', + name: 'createdBy', + uiSchema: { + type: 'object', + title: '{{t("Created by")}}', + 'x-component': 'RecordPicker', + 'x-component-props': { + fieldNames: { + value: 'id', + label: 'nickname', + }, + }, + 'x-read-pretty': true, + }, + }, + { + type: 'date', + field: 'updatedAt', + name: 'updatedAt', + interface: 'updatedAt', + uiSchema: { + type: 'string', + title: '{{t("Last updated at")}}', + 'x-component': 'DatePicker', + 'x-component-props': {}, + 'x-read-pretty': true, + }, + }, + { + type: 'belongsTo', + target: 'users', + foreignKey: 'updatedById', + name: 'updatedBy', + interface: 'updatedBy', + uiSchema: { + type: 'object', + title: '{{t("Last updated by")}}', + 'x-component': 'RecordPicker', + 'x-component-props': { + fieldNames: { + value: 'id', + label: 'nickname', + }, + }, + 'x-read-pretty': true, + }, + }, + ], }, }), { diff --git a/packages/client/src/collection-manager/interfaces/id.ts b/packages/client/src/collection-manager/interfaces/id.ts new file mode 100644 index 000000000..671906ac1 --- /dev/null +++ b/packages/client/src/collection-manager/interfaces/id.ts @@ -0,0 +1,47 @@ +import { operators } from './properties'; +import { IField } from './types'; + +export const id: IField = { + name: 'id', + type: 'object', + group: 'systemInfo', + order: 0, + title: '{{t("ID")}}', + sortable: true, + default: { + name: 'id', + type: 'integer', + autoIncrement: true, + primaryKey: true, + allowNull: false, + uiSchema: { + type: 'number', + title: '{{t("ID")}}', + 'x-component': 'InputNumber', + 'x-read-pretty': true, + }, + }, + properties: { + 'uiSchema.title': { + type: 'string', + title: '{{t("Field display name")}}', + required: true, + default: 'ID', + 'x-decorator': 'FormItem', + 'x-component': 'Input', + }, + name: { + type: 'string', + title: '{{t("Field name")}}', + required: true, + 'x-disabled': true, + 'x-decorator': 'FormItem', + 'x-component': 'Input', + description: + "{{t('Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.')}}", + }, + }, + filterable: { + operators: operators.number, + }, +}; diff --git a/packages/client/src/collection-manager/interfaces/index.ts b/packages/client/src/collection-manager/interfaces/index.ts index 6eed8587b..87e7b3b82 100644 --- a/packages/client/src/collection-manager/interfaces/index.ts +++ b/packages/client/src/collection-manager/interfaces/index.ts @@ -7,6 +7,7 @@ export * from './createdBy'; export * from './datetime'; export * from './email'; export * from './icon'; +export * from './id'; export * from './input'; export * from './linkTo'; export * from './markdown';