fix: reset issue that reverts filter button title to default (#5635)

* fix: reset issue that reverts filter button title to default

* fix: bug
This commit is contained in:
Katherine 2024-11-12 20:21:30 +08:00 committed by GitHub
parent b7495a7757
commit 586c515ff7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 6 deletions

View File

@ -21,6 +21,7 @@ import { useProps } from '../../hooks/useProps';
import { Action, ActionProps } from '../action';
import { DatePickerProvider } from '../date-picker/DatePicker';
import { StablePopover } from '../popover';
import { useCompile } from '../../';
export const FilterActionContext = createContext<any>(null);
FilterActionContext.displayName = 'FilterActionContext';
@ -50,6 +51,8 @@ export const FilterAction = withDynamicSchemaProps(
const [visible, setVisible] = useState(false);
const { designable, dn } = useDesignable();
const fieldSchema = useFieldSchema();
const compile = useCompile();
const form = useMemo<Form>(() => props.form || createForm(), []);
// 新版 UISchema1.0 之后)中已经废弃了 useProps这里之所以继续保留是为了兼容旧版的 UISchema
@ -58,7 +61,6 @@ export const FilterAction = withDynamicSchemaProps(
const onOpenChange = useCallback((visible: boolean): void => {
setVisible(visible);
}, []);
return (
<FilterActionContext.Provider value={{ field, fieldSchema, designable, dn }}>
<Container
@ -99,7 +101,7 @@ export const FilterAction = withDynamicSchemaProps(
onClick={async () => {
await form.reset();
onReset?.(form.values);
field.title = t('Filter');
field.title = compile(fieldSchema.title) || t('Filter');
setVisible(false);
}}
>

View File

@ -16,7 +16,7 @@ import { useBlockRequestContext } from '../../../block-provider';
import { useCollectionManager_deprecated, useCollection_deprecated } from '../../../collection-manager';
import { mergeFilter } from '../../../filter-provider/utils';
import { useDataLoadingMode } from '../../../modules/blocks/data-blocks/details-multi/setDataLoadingModeSettingsItem';
import { useCompile } from '../../';
export const useGetFilterOptions = () => {
const { getCollectionFields } = useCollectionManager_deprecated();
const getFilterFieldOptions = useGetFilterFieldOptions();
@ -182,6 +182,8 @@ export const useFilterFieldProps = ({ options, service, params }) => {
const { t } = useTranslation();
const field = useField<Field>();
const dataLoadingMode = useDataLoadingMode();
const fieldSchema = useFieldSchema();
const compile = useCompile();
return {
options,
@ -205,7 +207,7 @@ export const useFilterFieldProps = ({ options, service, params }) => {
if (items?.length) {
field.title = t('{{count}} filter items', { count: items?.length || 0 });
} else {
field.title = t('Filter');
field.title = compile(fieldSchema.title) || t('Filter');
}
},
onReset() {
@ -222,8 +224,6 @@ export const useFilterFieldProps = ({ options, service, params }) => {
{ filters },
];
field.title = t('Filter');
if (dataLoadingMode === 'manual') {
service.params = newParams;
return service.mutate(undefined);