refactor: only numerical formula fields support format (#3962)

This commit is contained in:
katherinehhh 2024-04-08 14:30:50 +08:00 committed by GitHub
parent 9f72b4e1ef
commit c735664ea9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,6 @@
import { useFieldSchema } from '@formily/react';
import { SchemaSettings, SchemaSettingsNumberFormat, useColumnSchema, useIsFieldReadPretty } from '@nocobase/client';
import { useTargetCollectionField } from './components/Formula/Result';
export const FormulaComponentFieldSettings = new SchemaSettings({
name: 'fieldSettings:component:Formula.Result',
items: [
@ -16,8 +16,13 @@ export const FormulaComponentFieldSettings = new SchemaSettings({
};
},
useVisible() {
const schema = useFieldSchema();
const { fieldSchema: tableColumnSchema } = useColumnSchema();
const fieldSchema = tableColumnSchema || schema;
const { dataType } = useTargetCollectionField(fieldSchema) || {};
const isNumberFormat = ['integer', 'bigInt', 'double', 'decimal'].includes(dataType);
const isFieldReadPretty = useIsFieldReadPretty();
return isFieldReadPretty;
return isFieldReadPretty && isNumberFormat;
},
},
],

View File

@ -28,8 +28,9 @@ const TypedComponents = {
string: InputString.ReadPretty,
};
function useTargetCollectionField() {
const fieldSchema = useFieldSchema();
export function useTargetCollectionField(schema?) {
const targetSchema = useFieldSchema();
const fieldSchema = schema || targetSchema;
const providedCollection = useCollection_deprecated();
const { getCollection, getCollectionField } = useCollectionManager_deprecated();
const paths = (fieldSchema.name as string).split('.');