refactor(client): change isTitleField check to interface property titleUsable (#2250)

This commit is contained in:
Junyi 2023-07-14 13:16:44 +07:00 committed by GitHub
parent 9b5e923e91
commit b63012d85a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 23 additions and 8 deletions

View File

@ -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) => {

View File

@ -28,4 +28,5 @@ export const createdAt: IField = {
filterable: {
operators: operators.datetime,
},
titleUsable: true,
};

View File

@ -37,4 +37,5 @@ export const datetime: IField = {
filterable: {
operators: operators.datetime,
},
titleUsable: true,
};

View File

@ -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'] || {};

View File

@ -45,4 +45,5 @@ export const id: IField = {
filterable: {
operators: operators.id,
},
titleUsable: true,
};

View File

@ -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'] || {};

View File

@ -38,6 +38,7 @@ export const integer: IField = {
filterable: {
operators: operators.number,
},
titleUsable: true,
validateSchema(fieldSchema) {
return {
maximum: {

View File

@ -46,6 +46,7 @@ export const number: IField = {
filterable: {
operators: operators.number,
},
titleUsable: true,
validateSchema(fieldSchema) {
return {
maximum: {

View File

@ -99,6 +99,7 @@ export const percent: IField = {
filterable: {
operators: operators.number,
},
titleUsable: true,
validateSchema(fieldSchema) {
return {
maxValue: {

View File

@ -30,4 +30,5 @@ export const phone: IField = {
filterable: {
operators: operators.string,
},
titleUsable: true,
};

View File

@ -26,4 +26,5 @@ export const radioGroup: IField = {
filterable: {
operators: operators.enumType,
},
titleUsable: true,
};

View File

@ -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 = {

View File

@ -41,4 +41,5 @@ export const time: IField = {
filterable: {
operators: operators.time,
},
titleUsable: true,
};

View File

@ -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;
}

View File

@ -28,4 +28,5 @@ export const updatedAt: IField = {
filterable: {
operators: operators.datetime,
},
titleUsable: true,
};

View File

@ -19,4 +19,5 @@ export const url: IField = {
properties: {
...defaultProps,
},
titleUsable: true,
};

View File

@ -197,4 +197,5 @@ export default {
filterable: {
operators: operators.number,
},
titleUsable: true,
} as IField;

View File

@ -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,
},
};