Merge pull request 'fix: 修改自定义筛选为字段内容本身' (#425) from fix_filterCuston into @hera/dev

Reviewed-on: daoyoucloud/tachycode#425
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
This commit is contained in:
sealday 2024-03-19 15:41:23 +08:00
commit 629eb576f1
8 changed files with 96 additions and 116 deletions

View File

@ -40,11 +40,11 @@ export const SchemaSettingsRemove: FC<SchemaSettingsRemoveProps> = (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];
}
}

View File

@ -377,38 +377,7 @@ 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,

View File

@ -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,9 +37,11 @@ export const removeNullCondition = (filter, fieldSchema?) => {
for (const key in items) {
if (key.includes(collection)) {
if (key.includes(match)) {
if (Object.keys(items[key]).length) {
filterSchemaItem[filterKey] = items[key];
filterItem[match] = items[key];
}
}
if (key.includes(collection)) delete items[key];
else {
const value = items[key];

View File

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

View File

@ -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 (
<SchemaSettingsSelectItem
key="component-field"
title="Field Component"
options={options}
value={fieldSchema['x-component']}
onChange={(mode) => {
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 (
<SchemaSettingsSelectItem
key="component-field"
title="Edit Collection"
options={options}
value={fieldSchema['collectionName']}
onChange={(name) => {
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();
}}
/>
);
};

View File

@ -86,22 +86,30 @@ const ObjectSelect = (props: Props) => {
showSearch
popupMatchSelectWidth={false}
filterOption={(input, option) => (option?.[fieldNames.label || 'label'] ?? '').includes(input)}
filterSort={(optionA, optionB) =>
(optionA?.[fieldNames.label || 'label'] ?? '')
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())
.localeCompare((optionB?.[fieldNames.label || 'label'] ?? '').toLowerCase());
}
}}
onChange={(changed) => {
const current = getCurrentOptions(
toArr(changed).map((v) => v.value),
rawOptions || options,
fieldNames,
);
if (fieldSchema.name.toString().includes('custom')) {
onChange?.(changed ? changed['label'] : changed);
} else {
if (['tags', 'multiple'].includes(mode as string) || props.multiple) {
onChange?.(current);
} else {
onChange?.(current.shift() || null);
}
}
}}
mode={mode}
tagRender={(props) => {

View File

@ -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();

View File

@ -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 (
<SchemaSettingsSelectItem
key="component-field"
title="Field Component"
options={options}
value={fieldSchema['x-component']}
onChange={(mode) => {
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 (
<SchemaSettingsSelectItem
key="component-field"
title="Edit Collection"
options={options}
value={fieldSchema['collectionName']}
onChange={(name) => {
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();
}}
/>
);
};