fix: fix T-2749 (#3194)
This commit is contained in:
parent
f6fdec1226
commit
33779d3da2
@ -12,6 +12,7 @@ import {
|
|||||||
useCompile,
|
useCompile,
|
||||||
useDesignable,
|
useDesignable,
|
||||||
SchemaSettingsSelectItem,
|
SchemaSettingsSelectItem,
|
||||||
|
CollectionFieldOptions,
|
||||||
} from '@nocobase/client';
|
} from '@nocobase/client';
|
||||||
import { useChartsTranslation } from '../locale';
|
import { useChartsTranslation } from '../locale';
|
||||||
import { Schema, useField, useFieldSchema } from '@formily/react';
|
import { Schema, useField, useFieldSchema } from '@formily/react';
|
||||||
@ -22,6 +23,7 @@ import { getPropsSchemaByComponent, setDefaultValue } from './utils';
|
|||||||
import { ChartFilterVariableInput } from './FilterVariableInput';
|
import { ChartFilterVariableInput } from './FilterVariableInput';
|
||||||
import { useChartFilter, useCollectionJoinFieldTitle } from '../hooks';
|
import { useChartFilter, useCollectionJoinFieldTitle } from '../hooks';
|
||||||
import { Typography } from 'antd';
|
import { Typography } from 'antd';
|
||||||
|
import { getFormulaInterface } from '../utils';
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
const EditTitle = () => {
|
const EditTitle = () => {
|
||||||
@ -76,9 +78,19 @@ const EditOperator = () => {
|
|||||||
const { dn } = useDesignable();
|
const { dn } = useDesignable();
|
||||||
const { setField } = useContext(ChartFilterContext);
|
const { setField } = useContext(ChartFilterContext);
|
||||||
const { getInterface, getCollectionJoinField } = useCollectionManager();
|
const { getInterface, getCollectionJoinField } = useCollectionManager();
|
||||||
|
|
||||||
|
const getOperators = (props: CollectionFieldOptions) => {
|
||||||
|
let fieldInterface = props?.interface;
|
||||||
|
if (fieldInterface === 'formula') {
|
||||||
|
fieldInterface = getFormulaInterface(props.dataType) || props.dataType;
|
||||||
|
}
|
||||||
|
const interfaceConfig = getInterface(fieldInterface);
|
||||||
|
const operatorList = interfaceConfig?.filterable?.operators || [];
|
||||||
|
return { operatorList, interfaceConfig };
|
||||||
|
};
|
||||||
|
|
||||||
let props = getCollectionJoinField(fieldName);
|
let props = getCollectionJoinField(fieldName);
|
||||||
let interfaceConfig = getInterface(props?.interface);
|
let { operatorList, interfaceConfig } = getOperators(props);
|
||||||
let operatorList = interfaceConfig?.filterable?.operators || [];
|
|
||||||
if (!operatorList.length) {
|
if (!operatorList.length) {
|
||||||
const names = fieldName.split('.');
|
const names = fieldName.split('.');
|
||||||
const name = names.pop();
|
const name = names.pop();
|
||||||
@ -86,7 +98,9 @@ const EditOperator = () => {
|
|||||||
if (!props) {
|
if (!props) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
interfaceConfig = getInterface(props.interface);
|
const res = getOperators(props);
|
||||||
|
operatorList = res.operatorList;
|
||||||
|
interfaceConfig = res.interfaceConfig;
|
||||||
if (!interfaceConfig) {
|
if (!interfaceConfig) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,13 @@ import { useMemoizedFn } from 'ahooks';
|
|||||||
import { FormLayout, FormItem } from '@formily/antd-v5';
|
import { FormLayout, FormItem } from '@formily/antd-v5';
|
||||||
import { uid } from '@formily/shared';
|
import { uid } from '@formily/shared';
|
||||||
import { useChartData, useChartFilter, useChartFilterSourceFields, useFieldComponents } from '../hooks/filter';
|
import { useChartData, useChartFilter, useChartFilterSourceFields, useFieldComponents } from '../hooks/filter';
|
||||||
import { Alert } from 'antd';
|
import { Alert, Typography } from 'antd';
|
||||||
import { getPropsSchemaByComponent } from './utils';
|
import { getPropsSchemaByComponent } from './utils';
|
||||||
import { Field, onFieldValueChange } from '@formily/core';
|
import { Field, onFieldValueChange } from '@formily/core';
|
||||||
import { css, cx } from '@emotion/css';
|
import { css, cx } from '@emotion/css';
|
||||||
import { ConfigProvider } from 'antd';
|
import { ConfigProvider } from 'antd';
|
||||||
|
import { ErrorBoundary } from 'react-error-boundary';
|
||||||
|
const { Paragraph, Text } = Typography;
|
||||||
|
|
||||||
const FieldComponentProps: React.FC = observer((props) => {
|
const FieldComponentProps: React.FC = observer((props) => {
|
||||||
const form = useForm();
|
const form = useForm();
|
||||||
@ -32,6 +34,16 @@ const FieldComponentProps: React.FC = observer((props) => {
|
|||||||
return schema ? <SchemaComponent schema={schema} {...props} /> : null;
|
return schema ? <SchemaComponent schema={schema} {...props} /> : null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ErrorFallback = ({ error }) => {
|
||||||
|
return (
|
||||||
|
<Paragraph copyable>
|
||||||
|
<Text type="danger" style={{ whiteSpace: 'pre-line', textAlign: 'center', padding: '5px' }}>
|
||||||
|
{error.message}
|
||||||
|
</Text>
|
||||||
|
</Paragraph>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const ChartFilterFormItem = observer(
|
export const ChartFilterFormItem = observer(
|
||||||
(props: any) => {
|
(props: any) => {
|
||||||
const field = useField<Field>();
|
const field = useField<Field>();
|
||||||
@ -68,7 +80,9 @@ export const ChartFilterFormItem = observer(
|
|||||||
return (
|
return (
|
||||||
<ACLCollectionFieldProvider>
|
<ACLCollectionFieldProvider>
|
||||||
<BlockItem className={'nb-form-item'}>
|
<BlockItem className={'nb-form-item'}>
|
||||||
<FormItem className={className} {...props} extra={extra} />
|
<ErrorBoundary onError={(err) => console.log(err)} FallbackComponent={ErrorFallback}>
|
||||||
|
<FormItem className={className} {...props} extra={extra} />
|
||||||
|
</ErrorBoundary>
|
||||||
</BlockItem>
|
</BlockItem>
|
||||||
</ACLCollectionFieldProvider>
|
</ACLCollectionFieldProvider>
|
||||||
);
|
);
|
||||||
|
@ -8,7 +8,7 @@ import { ChartFilterContext } from '../filter/FilterProvider';
|
|||||||
import { useMemoizedFn } from 'ahooks';
|
import { useMemoizedFn } from 'ahooks';
|
||||||
import { parse } from '@nocobase/utils/client';
|
import { parse } from '@nocobase/utils/client';
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
import { getValuesByPath } from '../utils';
|
import { getFormulaComponent, getValuesByPath } from '../utils';
|
||||||
import deepmerge from 'deepmerge';
|
import deepmerge from 'deepmerge';
|
||||||
|
|
||||||
export const useCustomFieldInterface = () => {
|
export const useCustomFieldInterface = () => {
|
||||||
@ -88,9 +88,10 @@ export const useChartFilter = () => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (field.interface === 'formula') {
|
if (field.interface === 'formula') {
|
||||||
|
const component = getFormulaComponent(field.dataType) || 'Input';
|
||||||
schema = {
|
schema = {
|
||||||
...schema,
|
...schema,
|
||||||
'x-component': 'InputNumber',
|
'x-component': component,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (['oho', 'o2m'].includes(field.interface)) {
|
if (['oho', 'o2m'].includes(field.interface)) {
|
||||||
|
@ -133,3 +133,27 @@ export const getValuesByPath = (values: any, path: string) => {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getFormulaComponent = (type: string) => {
|
||||||
|
return {
|
||||||
|
boolean: 'Checkbox',
|
||||||
|
integer: 'InputNumber',
|
||||||
|
bigInt: 'InputNumber',
|
||||||
|
double: 'InputNumber',
|
||||||
|
decimal: 'InputNumber',
|
||||||
|
date: 'DatePicker',
|
||||||
|
string: 'Input',
|
||||||
|
}[type];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getFormulaInterface = (type: string) => {
|
||||||
|
return {
|
||||||
|
boolean: 'boolean',
|
||||||
|
integer: 'integer',
|
||||||
|
bigInt: 'integer',
|
||||||
|
double: 'number',
|
||||||
|
decimal: 'number',
|
||||||
|
date: 'datetime',
|
||||||
|
string: 'input',
|
||||||
|
}[type];
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user