From b63012d85ab1c330923ebf4bf6700c82882a9346 Mon Sep 17 00:00:00 2001 From: Junyi Date: Fri, 14 Jul 2023 13:16:44 +0700 Subject: [PATCH] refactor(client): change isTitleField check to interface property titleUsable (#2250) --- .../collection-manager/Configuration/CollectionFields.tsx | 7 ++----- .../client/src/collection-manager/interfaces/createdAt.ts | 1 + .../client/src/collection-manager/interfaces/datetime.ts | 1 + .../core/client/src/collection-manager/interfaces/email.ts | 1 + .../core/client/src/collection-manager/interfaces/id.ts | 1 + .../core/client/src/collection-manager/interfaces/input.ts | 1 + .../client/src/collection-manager/interfaces/integer.ts | 1 + .../client/src/collection-manager/interfaces/number.ts | 1 + .../client/src/collection-manager/interfaces/percent.ts | 1 + .../core/client/src/collection-manager/interfaces/phone.ts | 1 + .../client/src/collection-manager/interfaces/radioGroup.ts | 1 + .../client/src/collection-manager/interfaces/select.ts | 1 + .../core/client/src/collection-manager/interfaces/time.ts | 1 + .../core/client/src/collection-manager/interfaces/types.ts | 2 ++ .../client/src/collection-manager/interfaces/updatedAt.ts | 1 + .../core/client/src/collection-manager/interfaces/url.ts | 1 + .../formula-field/src/client/interfaces/formula.tsx | 1 + packages/plugins/sequence-field/src/client/sequence.tsx | 7 ++++--- 18 files changed, 23 insertions(+), 8 deletions(-) diff --git a/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx b/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx index c6d911f7d..7d5cda3ed 100644 --- a/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx +++ b/packages/core/client/src/collection-manager/Configuration/CollectionFields.tsx @@ -57,14 +57,11 @@ const tableContainer = css` `; const titlePrompt = 'Default title for each record'; -// 只有下面类型的字段才可以设置为标题字段 -const expectTypes = ['string', 'integer', 'bigInt', 'float', 'double', 'decimal', 'date', 'dateonly', 'time']; -const excludeInterfaces = ['icon']; // 是否可以作为标题字段 export const isTitleField = (field) => { - if (!field) return false; - return !field.isForeignKey && expectTypes.includes(field.type) && !excludeInterfaces.includes(field.interface); + const { getInterface } = useCollectionManager(); + return !field.isForeignKey && getInterface(field.interface)?.titleUsable; }; const CurrentFields = (props) => { diff --git a/packages/core/client/src/collection-manager/interfaces/createdAt.ts b/packages/core/client/src/collection-manager/interfaces/createdAt.ts index 70c2d5e88..0685842e0 100644 --- a/packages/core/client/src/collection-manager/interfaces/createdAt.ts +++ b/packages/core/client/src/collection-manager/interfaces/createdAt.ts @@ -28,4 +28,5 @@ export const createdAt: IField = { filterable: { operators: operators.datetime, }, + titleUsable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/datetime.ts b/packages/core/client/src/collection-manager/interfaces/datetime.ts index d6fc31c06..05c5d03e6 100644 --- a/packages/core/client/src/collection-manager/interfaces/datetime.ts +++ b/packages/core/client/src/collection-manager/interfaces/datetime.ts @@ -37,4 +37,5 @@ export const datetime: IField = { filterable: { operators: operators.datetime, }, + titleUsable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/email.ts b/packages/core/client/src/collection-manager/interfaces/email.ts index 2f026d015..43af521b8 100644 --- a/packages/core/client/src/collection-manager/interfaces/email.ts +++ b/packages/core/client/src/collection-manager/interfaces/email.ts @@ -28,6 +28,7 @@ export const email: IField = { filterable: { operators: operators.string, }, + titleUsable: true, schemaInitialize(schema: ISchema, { block }) { if (['Table', 'Kanban'].includes(block)) { schema['x-component-props'] = schema['x-component-props'] || {}; diff --git a/packages/core/client/src/collection-manager/interfaces/id.ts b/packages/core/client/src/collection-manager/interfaces/id.ts index 5ed3f9849..ebdbbcace 100644 --- a/packages/core/client/src/collection-manager/interfaces/id.ts +++ b/packages/core/client/src/collection-manager/interfaces/id.ts @@ -45,4 +45,5 @@ export const id: IField = { filterable: { operators: operators.id, }, + titleUsable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/input.ts b/packages/core/client/src/collection-manager/interfaces/input.ts index c309ead56..ed27f637c 100644 --- a/packages/core/client/src/collection-manager/interfaces/input.ts +++ b/packages/core/client/src/collection-manager/interfaces/input.ts @@ -27,6 +27,7 @@ export const input: IField = { filterable: { operators: operators.string, }, + titleUsable: true, schemaInitialize(schema: ISchema, { block }) { if (['Table', 'Kanban'].includes(block)) { schema['x-component-props'] = schema['x-component-props'] || {}; diff --git a/packages/core/client/src/collection-manager/interfaces/integer.ts b/packages/core/client/src/collection-manager/interfaces/integer.ts index baf8c32c9..a78be8564 100644 --- a/packages/core/client/src/collection-manager/interfaces/integer.ts +++ b/packages/core/client/src/collection-manager/interfaces/integer.ts @@ -38,6 +38,7 @@ export const integer: IField = { filterable: { operators: operators.number, }, + titleUsable: true, validateSchema(fieldSchema) { return { maximum: { diff --git a/packages/core/client/src/collection-manager/interfaces/number.ts b/packages/core/client/src/collection-manager/interfaces/number.ts index 525dc17d8..9b6d45574 100644 --- a/packages/core/client/src/collection-manager/interfaces/number.ts +++ b/packages/core/client/src/collection-manager/interfaces/number.ts @@ -46,6 +46,7 @@ export const number: IField = { filterable: { operators: operators.number, }, + titleUsable: true, validateSchema(fieldSchema) { return { maximum: { diff --git a/packages/core/client/src/collection-manager/interfaces/percent.ts b/packages/core/client/src/collection-manager/interfaces/percent.ts index 38e316ecd..ca5035153 100644 --- a/packages/core/client/src/collection-manager/interfaces/percent.ts +++ b/packages/core/client/src/collection-manager/interfaces/percent.ts @@ -99,6 +99,7 @@ export const percent: IField = { filterable: { operators: operators.number, }, + titleUsable: true, validateSchema(fieldSchema) { return { maxValue: { diff --git a/packages/core/client/src/collection-manager/interfaces/phone.ts b/packages/core/client/src/collection-manager/interfaces/phone.ts index 4a6ec90f2..bfed90a51 100644 --- a/packages/core/client/src/collection-manager/interfaces/phone.ts +++ b/packages/core/client/src/collection-manager/interfaces/phone.ts @@ -30,4 +30,5 @@ export const phone: IField = { filterable: { operators: operators.string, }, + titleUsable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/radioGroup.ts b/packages/core/client/src/collection-manager/interfaces/radioGroup.ts index 5a097c732..efabeb522 100644 --- a/packages/core/client/src/collection-manager/interfaces/radioGroup.ts +++ b/packages/core/client/src/collection-manager/interfaces/radioGroup.ts @@ -26,4 +26,5 @@ export const radioGroup: IField = { filterable: { operators: operators.enumType, }, + titleUsable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/select.ts b/packages/core/client/src/collection-manager/interfaces/select.ts index d332f03f4..f83b246db 100644 --- a/packages/core/client/src/collection-manager/interfaces/select.ts +++ b/packages/core/client/src/collection-manager/interfaces/select.ts @@ -28,6 +28,7 @@ export const select: IField = { filterable: { operators: operators.enumType, }, + titleUsable: true, schemaInitialize(schema: ISchema, { block }) { const props = (schema['x-component-props'] = schema['x-component-props'] || {}); props.style = { diff --git a/packages/core/client/src/collection-manager/interfaces/time.ts b/packages/core/client/src/collection-manager/interfaces/time.ts index e1d6b08ea..d733c2f54 100644 --- a/packages/core/client/src/collection-manager/interfaces/time.ts +++ b/packages/core/client/src/collection-manager/interfaces/time.ts @@ -41,4 +41,5 @@ export const time: IField = { filterable: { operators: operators.time, }, + titleUsable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/types.ts b/packages/core/client/src/collection-manager/interfaces/types.ts index c2fbb51b3..744f3c720 100644 --- a/packages/core/client/src/collection-manager/interfaces/types.ts +++ b/packages/core/client/src/collection-manager/interfaces/types.ts @@ -12,5 +12,7 @@ export interface IField extends ISchema { filterable?: any; /** 不支持使用变量的值进行设置 */ invariable?: boolean; + // NOTE: set to `true` means field could be used as a title field + titleUsable?: boolean; [key: string]: any; } diff --git a/packages/core/client/src/collection-manager/interfaces/updatedAt.ts b/packages/core/client/src/collection-manager/interfaces/updatedAt.ts index 56bae4897..8a637dd4f 100644 --- a/packages/core/client/src/collection-manager/interfaces/updatedAt.ts +++ b/packages/core/client/src/collection-manager/interfaces/updatedAt.ts @@ -28,4 +28,5 @@ export const updatedAt: IField = { filterable: { operators: operators.datetime, }, + titleUsable: true, }; diff --git a/packages/core/client/src/collection-manager/interfaces/url.ts b/packages/core/client/src/collection-manager/interfaces/url.ts index 528b31eaa..81cd3e025 100644 --- a/packages/core/client/src/collection-manager/interfaces/url.ts +++ b/packages/core/client/src/collection-manager/interfaces/url.ts @@ -19,4 +19,5 @@ export const url: IField = { properties: { ...defaultProps, }, + titleUsable: true, }; diff --git a/packages/plugins/formula-field/src/client/interfaces/formula.tsx b/packages/plugins/formula-field/src/client/interfaces/formula.tsx index c011ff3cc..0b107ea7c 100644 --- a/packages/plugins/formula-field/src/client/interfaces/formula.tsx +++ b/packages/plugins/formula-field/src/client/interfaces/formula.tsx @@ -197,4 +197,5 @@ export default { filterable: { operators: operators.number, }, + titleUsable: true, } as IField; diff --git a/packages/plugins/sequence-field/src/client/sequence.tsx b/packages/plugins/sequence-field/src/client/sequence.tsx index c69424991..686b7c528 100644 --- a/packages/plugins/sequence-field/src/client/sequence.tsx +++ b/packages/plugins/sequence-field/src/client/sequence.tsx @@ -280,6 +280,10 @@ export const sequence: IField = { }, }, hasDefaultValue: false, + filterable: { + operators: interfacesProperties.operators.string, + }, + titleUsable: true, schemaInitialize(schema: ISchema, { block, field }) { if (block === 'Form') { Object.assign(schema['x-component-props'], { @@ -405,7 +409,4 @@ export const sequence: IField = { }, }, }, - filterable: { - operators: interfacesProperties.operators.string, - }, };