feat(collection-manager): more options

This commit is contained in:
chenos 2022-12-14 16:38:08 +08:00
parent db346688f5
commit 26e27c814b
3 changed files with 95 additions and 82 deletions

View File

@ -9,15 +9,5 @@ export const general: ICollectionTemplate = {
default: { default: {
fields: [], fields: [],
}, },
configurableProperties: getConfigurableProperties( configurableProperties: getConfigurableProperties('title', 'name', 'inherits', 'moreOptions'),
'title',
'name',
'inherits',
'autoGenId',
'createdAt',
'updatedAt',
'createdBy',
'updatedBy',
'sortable',
),
}; };

View File

@ -1,3 +1,75 @@
import { css } from '@emotion/css';
const moreOptions = {
autoGenId: {
type: 'boolean',
'x-content': '{{t("Generate ID field automatically")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
'x-reactions': [
{
target: 'sortable',
when: '{{createOnly&&!$self.value}}',
fulfill: {
state: {
value: false,
},
schema: {
'x-disabled': true,
},
},
otherwise: {
schema: {
'x-disabled': '{{!createOnly}}',
},
},
},
],
},
createdBy: {
type: 'boolean',
'x-content': '{{t("Store the creation user of each record")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
},
updatedBy: {
type: 'boolean',
'x-content': '{{t("Store the last update user of each record")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
},
createdAt: {
type: 'boolean',
'x-content': '{{t("Store the creation time of each record")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
},
updatedAt: {
type: 'boolean',
'x-content': '{{t("Store the last update time of each record")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
},
sortable: {
type: 'boolean',
'x-content': '{{t("Records can be sorted")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
},
};
export const defaultConfigurableProperties = { export const defaultConfigurableProperties = {
title: { title: {
type: 'string', type: 'string',
@ -30,72 +102,21 @@ export const defaultConfigurableProperties = {
'x-visible': '{{ enableInherits}}', 'x-visible': '{{ enableInherits}}',
'x-reactions': ['{{useAsyncDataSource(loadCollections)}}'], 'x-reactions': ['{{useAsyncDataSource(loadCollections)}}'],
}, },
autoGenId: { ...moreOptions,
type: 'boolean', moreOptions: {
'x-content': '{{t("AutoGenId")}}', title: '{{t("More options")}}',
default: true, type: 'void',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Checkbox', 'x-decorator-props': {
'x-disabled': '{{ !createOnly }}', className: css`
'x-reactions': [ .ant-formily-item {
{ margin-bottom: 0;
target: 'sortable', }
when: '{{createOnly&&!$self.value}}', `,
fulfill: { },
state: { properties: {
value: false, ...moreOptions,
}, },
schema: {
'x-disabled': true,
},
},
otherwise: {
schema: {
'x-disabled': '{{!createOnly}}',
},
},
},
],
},
createdBy: {
type: 'boolean',
'x-content': '{{t("CreatedBy")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
},
updatedBy: {
type: 'boolean',
'x-content': '{{t("UpdatedBy")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
},
createdAt: {
type: 'boolean',
'x-content': '{{t("CreatedAt")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
},
updatedAt: {
type: 'boolean',
'x-content': '{{t("UpdatedAt")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
},
sortable: {
type: 'boolean',
'x-content': '{{t("Records can be sorted")}}',
default: true,
'x-decorator': 'FormItem',
'x-component': 'Checkbox',
'x-disabled': '{{ !createOnly }}',
}, },
}; };
@ -108,7 +129,8 @@ export type DefaultConfigurableKeys =
| 'updatedBy' | 'updatedBy'
| 'createdAt' | 'createdAt'
| 'updatedAt' | 'updatedAt'
| 'sortable'; | 'sortable'
| 'moreOptions';
export const getConfigurableProperties = (...keys: DefaultConfigurableKeys[]) => { export const getConfigurableProperties = (...keys: DefaultConfigurableKeys[]) => {
const props = {}; const props = {};

View File

@ -118,11 +118,12 @@ export default {
"Collection display name": "数据表名称", "Collection display name": "数据表名称",
"Collection name": "数据表标识", "Collection name": "数据表标识",
"Inherits":"继承", "Inherits":"继承",
"AutoGenId":"自动生成 ID 字段", "Generate ID field automatically":"自动生成 ID 字段",
"CreatedBy":"记录创建人", "Store the creation user of each record":"记录创建人",
"UpdatedBy":"记录最后更新人", "Store the last update user of each record":"记录最后更新人",
"CreatedAt":"记录创建时间", "Store the creation time of each record":"记录创建时间",
"UpdatedAt":"记录最后更新时间", "Store the last update time of each record":"记录最后更新时间",
"More options": "更多选项",
"Records can be sorted":"可以对行记录进行排序", "Records can be sorted":"可以对行记录进行排序",
"Collection template":"数据表模板", "Collection template":"数据表模板",
"Calendar collection":"日历数据表", "Calendar collection":"日历数据表",