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:
commit
629eb576f1
@ -40,11 +40,11 @@ export const SchemaSettingsRemove: FC<SchemaSettingsRemoveProps> = (props) => {
|
|||||||
}
|
}
|
||||||
await dn.remove(null, options);
|
await dn.remove(null, options);
|
||||||
await confirm?.onOk?.();
|
await confirm?.onOk?.();
|
||||||
delete form.values[fieldSchema.name];
|
delete form.values['custom'][fieldSchema['collectionName']];
|
||||||
const name = fieldSchema.name as string;
|
const name = fieldSchema.name as string;
|
||||||
const title = fieldSchema.title;
|
const title = fieldSchema.title;
|
||||||
for (const key in form.fields) {
|
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];
|
delete form.fields[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -377,42 +377,11 @@ export const useFilterVariable = (fields) => {
|
|||||||
.filter((value) => value?.props?.name.includes('custom.'))
|
.filter((value) => value?.props?.name.includes('custom.'))
|
||||||
.map((custom) => {
|
.map((custom) => {
|
||||||
const value = custom?.props?.name.replace(/^custom\./, '');
|
const value = custom?.props?.name.replace(/^custom\./, '');
|
||||||
const collection = collections.filter((collection) => collection.name === value)[0];
|
return {
|
||||||
let children = collection.fields.map((collectionField) => {
|
key: custom?.props?.name,
|
||||||
if (
|
value,
|
||||||
collectionField.interface !== 'o2o' &&
|
label: custom.title,
|
||||||
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,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
const result = useMemo(
|
const result = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
|
@ -20,7 +20,6 @@ export const removeNullCondition = (filter, fieldSchema?) => {
|
|||||||
if (filterSchema && (filterSchema.$and?.length || filterSchema.$or?.length)) {
|
if (filterSchema && (filterSchema.$and?.length || filterSchema.$or?.length)) {
|
||||||
for (const key in items) {
|
for (const key in items) {
|
||||||
for (const filterItems in filterSchemaItem) {
|
for (const filterItems in filterSchemaItem) {
|
||||||
const match = filterSchemaItem[filterItems].slice(11, -2);
|
|
||||||
if (key.includes(filterItems)) {
|
if (key.includes(filterItems)) {
|
||||||
isFilterCustom = true;
|
isFilterCustom = true;
|
||||||
break;
|
break;
|
||||||
@ -38,8 +37,10 @@ export const removeNullCondition = (filter, fieldSchema?) => {
|
|||||||
for (const key in items) {
|
for (const key in items) {
|
||||||
if (key.includes(collection)) {
|
if (key.includes(collection)) {
|
||||||
if (key.includes(match)) {
|
if (key.includes(match)) {
|
||||||
filterSchemaItem[filterKey] = items[key];
|
if (Object.keys(items[key]).length) {
|
||||||
filterItem[match] = items[key];
|
filterSchemaItem[filterKey] = items[key];
|
||||||
|
filterItem[match] = items[key];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (key.includes(collection)) delete items[key];
|
if (key.includes(collection)) delete items[key];
|
||||||
else {
|
else {
|
||||||
|
@ -57,11 +57,10 @@ export const AutoComplete = (props) => {
|
|||||||
}
|
}
|
||||||
const valueLabel = options.filter((item) => item.value === data)[0];
|
const valueLabel = options.filter((item) => item.value === data)[0];
|
||||||
if (valueLabel) {
|
if (valueLabel) {
|
||||||
form.values.custom[fieldSchema['collectionName']] = valueLabel;
|
form.values.custom[fieldSchema['collectionName']] = valueLabel.label;
|
||||||
setValue(valueLabel.label);
|
setValue(valueLabel.label);
|
||||||
} else {
|
} else {
|
||||||
form.values.custom[fieldSchema['collectionName']] = {};
|
form.values.custom[fieldSchema['collectionName']] = data;
|
||||||
form.values.custom[fieldSchema['collectionName']][fieldNames.label] = data;
|
|
||||||
setValue(data);
|
setValue(data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -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();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
@ -86,21 +86,29 @@ const ObjectSelect = (props: Props) => {
|
|||||||
showSearch
|
showSearch
|
||||||
popupMatchSelectWidth={false}
|
popupMatchSelectWidth={false}
|
||||||
filterOption={(input, option) => (option?.[fieldNames.label || 'label'] ?? '').includes(input)}
|
filterOption={(input, option) => (option?.[fieldNames.label || 'label'] ?? '').includes(input)}
|
||||||
filterSort={(optionA, optionB) =>
|
filterSort={(optionA, optionB) => {
|
||||||
(optionA?.[fieldNames.label || 'label'] ?? '')
|
if (typeof optionA[fieldNames.label] === 'number') {
|
||||||
.toLowerCase()
|
return optionA[fieldNames.label] - optionB[fieldNames.label];
|
||||||
.localeCompare((optionB?.[fieldNames.label || 'label'] ?? '').toLowerCase())
|
} else if (typeof optionA[fieldNames.label] === 'string') {
|
||||||
}
|
return (optionA?.[fieldNames.label || 'label'] ?? '')
|
||||||
|
.toLowerCase()
|
||||||
|
.localeCompare((optionB?.[fieldNames.label || 'label'] ?? '').toLowerCase());
|
||||||
|
}
|
||||||
|
}}
|
||||||
onChange={(changed) => {
|
onChange={(changed) => {
|
||||||
const current = getCurrentOptions(
|
const current = getCurrentOptions(
|
||||||
toArr(changed).map((v) => v.value),
|
toArr(changed).map((v) => v.value),
|
||||||
rawOptions || options,
|
rawOptions || options,
|
||||||
fieldNames,
|
fieldNames,
|
||||||
);
|
);
|
||||||
if (['tags', 'multiple'].includes(mode as string) || props.multiple) {
|
if (fieldSchema.name.toString().includes('custom')) {
|
||||||
onChange?.(current);
|
onChange?.(changed ? changed['label'] : changed);
|
||||||
} else {
|
} else {
|
||||||
onChange?.(current.shift() || null);
|
if (['tags', 'multiple'].includes(mode as string) || props.multiple) {
|
||||||
|
onChange?.(current);
|
||||||
|
} else {
|
||||||
|
onChange?.(current.shift() || null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
mode={mode}
|
mode={mode}
|
||||||
|
@ -30,11 +30,16 @@ import { Schema, SchemaOptionsContext, observer, useField, useFieldSchema } from
|
|||||||
import { FormLayout } from '@formily/antd-v5';
|
import { FormLayout } from '@formily/antd-v5';
|
||||||
import { uid } from '@formily/shared';
|
import { uid } from '@formily/shared';
|
||||||
import { Field } from '@formily/core';
|
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 _ from 'lodash';
|
||||||
import { SchemaSettingsRemove } from '../../components/FormFilter/SchemaSettingsRemove';
|
import { SchemaSettingsRemove } from '../../components/FormFilter/SchemaSettingsRemove';
|
||||||
import { useTranslation } from '../../locale';
|
import { useTranslation } from '../../locale';
|
||||||
import { SchemaSettingComponent, SchemaSettingCollection } from '../../schema-components/SchemaSettingsFieldComponent';
|
|
||||||
|
|
||||||
export const useFieldComponents = () => {
|
export const useFieldComponents = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
SchemaSettingsSelectItem,
|
SchemaSettingsSelectItem,
|
||||||
SchemaSettingsSwitchItem,
|
SchemaSettingsSwitchItem,
|
||||||
useCollection_deprecated,
|
useCollection_deprecated,
|
||||||
|
useCollectionManager,
|
||||||
useCollectionManager_deprecated,
|
useCollectionManager_deprecated,
|
||||||
useCompile,
|
useCompile,
|
||||||
useDesignable,
|
useDesignable,
|
||||||
@ -20,6 +21,7 @@ import _ from 'lodash';
|
|||||||
import React, { useCallback, useMemo } from 'react';
|
import React, { useCallback, useMemo } from 'react';
|
||||||
import { useTranslation } from '../locale';
|
import { useTranslation } from '../locale';
|
||||||
import { FormFilterScope } from '../components/FormFilter/FormFilterScope';
|
import { FormFilterScope } from '../components/FormFilter/FormFilterScope';
|
||||||
|
import { useFieldComponents } from '../schema-initializer';
|
||||||
|
|
||||||
export const useFormulaTitleOptions = () => {
|
export const useFormulaTitleOptions = () => {
|
||||||
const compile = useCompile();
|
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();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user