diff --git a/packages/plugins/@hera/plugin-core/src/client/components/FormFilter/SchemaSettingsRemove.tsx b/packages/plugins/@hera/plugin-core/src/client/components/FormFilter/SchemaSettingsRemove.tsx index a96bb3342..74054df68 100644 --- a/packages/plugins/@hera/plugin-core/src/client/components/FormFilter/SchemaSettingsRemove.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/components/FormFilter/SchemaSettingsRemove.tsx @@ -40,11 +40,11 @@ export const SchemaSettingsRemove: FC = (props) => { } await dn.remove(null, options); await confirm?.onOk?.(); - delete form.values[fieldSchema.name]; + delete form.values['custom'][fieldSchema['collectionName']]; const name = fieldSchema.name as string; const title = fieldSchema.title; for (const key in form.fields) { - if (key.includes(name) && form.fields[key].title == title) { + if (key.includes(name) && form.fields[key].title === title) { delete form.fields[key]; } } diff --git a/packages/plugins/@hera/plugin-core/src/client/components/FormFilter/VariableInput.tsx b/packages/plugins/@hera/plugin-core/src/client/components/FormFilter/VariableInput.tsx index 4b3197b2c..f66f6d87d 100644 --- a/packages/plugins/@hera/plugin-core/src/client/components/FormFilter/VariableInput.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/components/FormFilter/VariableInput.tsx @@ -377,42 +377,11 @@ export const useFilterVariable = (fields) => { .filter((value) => value?.props?.name.includes('custom.')) .map((custom) => { const value = custom?.props?.name.replace(/^custom\./, ''); - const collection = collections.filter((collection) => collection.name === value)[0]; - let children = collection.fields.map((collectionField) => { - if ( - collectionField.interface !== 'o2o' && - collectionField.interface !== 'oho' && - collectionField.interface !== 'm2o' && - collectionField.interface !== 'createdBy' && - collectionField.interface !== 'updatedBy' && - collectionField.interface !== 'o2m' && - collectionField.interface !== 'm2m' && - collectionField.interface !== 'linkTo' && - collectionField.interface !== 'chinaRegion' && - collectionField.interface !== 'obo' && - collectionField.interface !== 'createdAt' && - collectionField.interface !== 'updatedAt' - ) { - return { - key: collectionField.key, - value: collectionField.name, - label: compile(collectionField.uiSchema.title), - }; - } - }); - children = children.filter(Boolean); - return children.length - ? { - key: custom?.props?.name, - value, - label: custom.title, - children, - } - : { - key: custom?.props?.name, - value, - label: custom.title, - }; + return { + key: custom?.props?.name, + value, + label: custom.title, + }; }); const result = useMemo( () => ({ diff --git a/packages/plugins/@hera/plugin-core/src/client/hooks/useFilterBlockActionProps.tsx b/packages/plugins/@hera/plugin-core/src/client/hooks/useFilterBlockActionProps.tsx index e2af18059..2134cc7e0 100644 --- a/packages/plugins/@hera/plugin-core/src/client/hooks/useFilterBlockActionProps.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/hooks/useFilterBlockActionProps.tsx @@ -20,7 +20,6 @@ export const removeNullCondition = (filter, fieldSchema?) => { if (filterSchema && (filterSchema.$and?.length || filterSchema.$or?.length)) { for (const key in items) { for (const filterItems in filterSchemaItem) { - const match = filterSchemaItem[filterItems].slice(11, -2); if (key.includes(filterItems)) { isFilterCustom = true; break; @@ -38,8 +37,10 @@ export const removeNullCondition = (filter, fieldSchema?) => { for (const key in items) { if (key.includes(collection)) { if (key.includes(match)) { - filterSchemaItem[filterKey] = items[key]; - filterItem[match] = items[key]; + if (Object.keys(items[key]).length) { + filterSchemaItem[filterKey] = items[key]; + filterItem[match] = items[key]; + } } if (key.includes(collection)) delete items[key]; else { diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/AutoComplete/AutoComplete.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/AutoComplete/AutoComplete.tsx index 42c2e2621..f0175d922 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-components/AutoComplete/AutoComplete.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-components/AutoComplete/AutoComplete.tsx @@ -57,11 +57,10 @@ export const AutoComplete = (props) => { } const valueLabel = options.filter((item) => item.value === data)[0]; if (valueLabel) { - form.values.custom[fieldSchema['collectionName']] = valueLabel; + form.values.custom[fieldSchema['collectionName']] = valueLabel.label; setValue(valueLabel.label); } else { - form.values.custom[fieldSchema['collectionName']] = {}; - form.values.custom[fieldSchema['collectionName']][fieldNames.label] = data; + form.values.custom[fieldSchema['collectionName']] = data; setValue(data); } } else { diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent.tsx deleted file mode 100644 index 6d7184a9a..000000000 --- a/packages/plugins/@hera/plugin-core/src/client/schema-components/SchemaSettingsFieldComponent.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import { useField, useFieldSchema } from '@formily/react'; -import { SchemaSettingsSelectItem, useCollectionManager, useDesignable } from '@nocobase/client'; -import { useFieldComponents } from '../schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom'; -import React from 'react'; - -export const SchemaSettingComponent = () => { - const fieldSchema = useFieldSchema(); - const field = useField(); - const { options } = useFieldComponents(); - const { dn } = useDesignable(); - return ( - { - const schema = { - ['x-uid']: fieldSchema['x-uid'], - ['x-component']: mode, - }; - field.component = mode; - void dn.emit('patch', { - schema, - }); - dn.refresh(); - }} - /> - ); -}; - -export const SchemaSettingCollection = () => { - const fieldSchema = useFieldSchema(); - const field = useField(); - const collections = useCollectionManager(); - const options = collections?.dataSource['options']?.collections.map((value) => { - return { - label: value.name, - value: value.name, - }; - }); - const { dn } = useDesignable(); - return ( - { - fieldSchema['collectionName'] = name; - fieldSchema['name'] = 'custom.' + name; - const schema = { - ['x-uid']: fieldSchema['x-uid'], - collectionName: name, - name: 'custom.' + name, - }; - void dn.emit('patch', { schema }); - dn.refresh(); - }} - /> - ); -}; diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-components/select/Select.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-components/select/Select.tsx index 7c84c7bf1..72ea0f868 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-components/select/Select.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-components/select/Select.tsx @@ -86,21 +86,29 @@ const ObjectSelect = (props: Props) => { showSearch popupMatchSelectWidth={false} filterOption={(input, option) => (option?.[fieldNames.label || 'label'] ?? '').includes(input)} - filterSort={(optionA, optionB) => - (optionA?.[fieldNames.label || 'label'] ?? '') - .toLowerCase() - .localeCompare((optionB?.[fieldNames.label || 'label'] ?? '').toLowerCase()) - } + filterSort={(optionA, optionB) => { + if (typeof optionA[fieldNames.label] === 'number') { + return optionA[fieldNames.label] - optionB[fieldNames.label]; + } else if (typeof optionA[fieldNames.label] === 'string') { + return (optionA?.[fieldNames.label || 'label'] ?? '') + .toLowerCase() + .localeCompare((optionB?.[fieldNames.label || 'label'] ?? '').toLowerCase()); + } + }} onChange={(changed) => { const current = getCurrentOptions( toArr(changed).map((v) => v.value), rawOptions || options, fieldNames, ); - if (['tags', 'multiple'].includes(mode as string) || props.multiple) { - onChange?.(current); + if (fieldSchema.name.toString().includes('custom')) { + onChange?.(changed ? changed['label'] : changed); } else { - onChange?.(current.shift() || null); + if (['tags', 'multiple'].includes(mode as string) || props.multiple) { + onChange?.(current); + } else { + onChange?.(current.shift() || null); + } } }} mode={mode} diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx index cfc1cb8b7..45df0fe3f 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-initializer/FilterFormItemCustomInitializer/FilterFormItemCustom.tsx @@ -30,11 +30,16 @@ import { Schema, SchemaOptionsContext, observer, useField, useFieldSchema } from import { FormLayout } from '@formily/antd-v5'; import { uid } from '@formily/shared'; import { Field } from '@formily/core'; -import { EditFormulaTitleField, EditTitle, EditTitleField } from '../../schema-settings'; +import { + EditFormulaTitleField, + EditTitle, + EditTitleField, + SchemaSettingCollection, + SchemaSettingComponent, +} from '../../schema-settings'; import _ from 'lodash'; import { SchemaSettingsRemove } from '../../components/FormFilter/SchemaSettingsRemove'; import { useTranslation } from '../../locale'; -import { SchemaSettingComponent, SchemaSettingCollection } from '../../schema-components/SchemaSettingsFieldComponent'; export const useFieldComponents = () => { const { t } = useTranslation(); diff --git a/packages/plugins/@hera/plugin-core/src/client/schema-settings/index.tsx b/packages/plugins/@hera/plugin-core/src/client/schema-settings/index.tsx index 41ddac3dc..e52900ab3 100644 --- a/packages/plugins/@hera/plugin-core/src/client/schema-settings/index.tsx +++ b/packages/plugins/@hera/plugin-core/src/client/schema-settings/index.tsx @@ -5,6 +5,7 @@ import { SchemaSettingsSelectItem, SchemaSettingsSwitchItem, useCollection_deprecated, + useCollectionManager, useCollectionManager_deprecated, useCompile, useDesignable, @@ -20,6 +21,7 @@ import _ from 'lodash'; import React, { useCallback, useMemo } from 'react'; import { useTranslation } from '../locale'; import { FormFilterScope } from '../components/FormFilter/FormFilterScope'; +import { useFieldComponents } from '../schema-initializer'; export const useFormulaTitleOptions = () => { const compile = useCompile(); @@ -495,3 +497,61 @@ export function SessionUpdate() { /> ); } + +export const SchemaSettingComponent = () => { + const fieldSchema = useFieldSchema(); + const field = useField(); + const { options } = useFieldComponents(); + const { dn } = useDesignable(); + return ( + { + const schema = { + ['x-uid']: fieldSchema['x-uid'], + ['x-component']: mode, + }; + field.component = mode; + void dn.emit('patch', { + schema, + }); + dn.refresh(); + }} + /> + ); +}; + +export const SchemaSettingCollection = () => { + const fieldSchema = useFieldSchema(); + const field = useField(); + const collections = useCollectionManager(); + const options = collections?.dataSource['options']?.collections.map((value) => { + return { + label: value.name, + value: value.name, + }; + }); + const { dn } = useDesignable(); + return ( + { + fieldSchema['collectionName'] = name; + fieldSchema['name'] = 'custom.' + name; + const schema = { + ['x-uid']: fieldSchema['x-uid'], + collectionName: name, + name: 'custom.' + name, + }; + void dn.emit('patch', { schema }); + dn.refresh(); + }} + /> + ); +};