fix(filter-block): fix association fields not being filtered (#1758)
This commit is contained in:
parent
95e4e7e7b0
commit
00b3c8c257
@ -24,20 +24,13 @@ export function useRequest<P>(
|
||||
// 缓存用途
|
||||
const [state, setState] = useSetState({});
|
||||
const api = useContext(APIClientContext);
|
||||
|
||||
let tempOptions,tempService
|
||||
|
||||
if (typeof service === 'function') {
|
||||
const result = useReq(service, {
|
||||
...options,
|
||||
onSuccess(...args) {
|
||||
options.onSuccess?.(...args);
|
||||
if (options.uid) {
|
||||
api.services[options.uid] = result;
|
||||
}
|
||||
},
|
||||
});
|
||||
return { ...result, state, setState };
|
||||
}
|
||||
const result = useReq(
|
||||
async (params = {}) => {
|
||||
tempService = service
|
||||
}else {
|
||||
tempService = async (params = {}) => {
|
||||
const { resource } = service as ResourceActionOptions;
|
||||
let args = cloneDeep(service);
|
||||
if (resource) {
|
||||
@ -48,16 +41,21 @@ export function useRequest<P>(
|
||||
}
|
||||
const response = await api.request(args);
|
||||
return response?.data;
|
||||
}
|
||||
}
|
||||
|
||||
tempOptions = {
|
||||
...options,
|
||||
onSuccess(...args) {
|
||||
// @ts-ignore
|
||||
options.onSuccess?.(...args)
|
||||
if (options.uid) {
|
||||
api.services[options.uid] = result;
|
||||
}
|
||||
},
|
||||
{
|
||||
...options,
|
||||
onSuccess(...args) {
|
||||
options.onSuccess?.(...args);
|
||||
if (options.uid) {
|
||||
api.services[options.uid] = result;
|
||||
}
|
||||
},
|
||||
},
|
||||
);
|
||||
return { ...result, state, setState };
|
||||
}
|
||||
|
||||
const result:any = useReq(tempService, tempOptions)
|
||||
|
||||
return { ...result, state, setState }
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import parse from 'json-templates';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import get from 'lodash/get';
|
||||
import omit from 'lodash/omit';
|
||||
import { ChangeEvent, useContext } from 'react';
|
||||
import { ChangeEvent, useContext, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useReactToPrint } from 'react-to-print';
|
||||
@ -891,9 +891,38 @@ export const useAssociationFilterBlockProps = () => {
|
||||
const optionalFieldList = useOptionalFieldList();
|
||||
const { getDataBlocks } = useFilterBlock();
|
||||
const collectionFieldName = collectionField.name;
|
||||
const field = useField();
|
||||
|
||||
let list, onSelected, handleSearchInput, params, run, data, valueKey, labelKey, filterKey;
|
||||
|
||||
valueKey = collectionField?.targetKey || 'id';
|
||||
labelKey = fieldSchema['x-component-props']?.fieldNames?.label || valueKey;
|
||||
|
||||
({ data, params, run } = useRequest(
|
||||
{
|
||||
resource: collectionField?.target,
|
||||
action: 'list',
|
||||
params: {
|
||||
fields: [labelKey, valueKey],
|
||||
pageSize: 200,
|
||||
page: 1,
|
||||
...field.componentProps?.params
|
||||
},
|
||||
},
|
||||
{
|
||||
// 由于 选项字段不需要触发当前请求,所以当前请求更改为手动触发
|
||||
manual: true,
|
||||
debounceWait: 300,
|
||||
},
|
||||
));
|
||||
|
||||
useEffect(() => {
|
||||
// 由于 选项字段不需要触发当前请求,所以请求单独在 关系字段的时候触发
|
||||
if (!isOptionalField(fieldSchema)) {
|
||||
run()
|
||||
}
|
||||
},[labelKey, valueKey, JSON.stringify(field.componentProps?.params || {}), isOptionalField(fieldSchema)])
|
||||
|
||||
if (isOptionalField(fieldSchema)) {
|
||||
const field = optionalFieldList.find((field) => field.name === fieldSchema.name);
|
||||
const operatorMap = {
|
||||
@ -919,27 +948,8 @@ export const useAssociationFilterBlockProps = () => {
|
||||
list = (_list as any[]).filter((item) => item.label.includes(value));
|
||||
};
|
||||
} else {
|
||||
valueKey = collectionField?.targetKey || 'id';
|
||||
labelKey = fieldSchema['x-component-props']?.fieldNames?.label || valueKey;
|
||||
({ data, params, run } = useRequest(
|
||||
{
|
||||
resource: collectionField.target,
|
||||
action: 'list',
|
||||
params: {
|
||||
fields: [labelKey, valueKey],
|
||||
pageSize: 200,
|
||||
page: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
refreshDeps: [labelKey, valueKey],
|
||||
debounceWait: 300,
|
||||
},
|
||||
));
|
||||
filterKey = `${collectionFieldName}.${valueKey}.$in`;
|
||||
|
||||
list = data?.data || [];
|
||||
|
||||
handleSearchInput = (e: ChangeEvent<any>) => {
|
||||
run({
|
||||
...params?.[0],
|
||||
|
@ -210,7 +210,7 @@ export default {
|
||||
"Association fields filter": "Association fields filter",
|
||||
"PK & FK fields": "PK & FK fields",
|
||||
"Association fields": "Association fields",
|
||||
"Optional fields": "Optional fields",
|
||||
"Choices fields": "Choices fields",
|
||||
"System fields": "System fields",
|
||||
"General fields": "General fields",
|
||||
"Inherited fields": "Inherited fields",
|
||||
|
@ -577,7 +577,7 @@ export default {
|
||||
"Enable SMS authentication": "SMS認証を有効にする",
|
||||
"Display association fields": "関連付けられたコレクションのフィールドを表示",
|
||||
"Set default value": "デフォルト値を設定",
|
||||
"Optional fields": "オプションフィールド",
|
||||
"Choices fields": "チョイスフィールド",
|
||||
"Editable": "編集可能",
|
||||
"Readonly": "読み取り専用(編集不可)",
|
||||
"Easy-reading": "読取り専用(読取りモード)",
|
||||
|
@ -170,7 +170,7 @@ export default {
|
||||
"Association fields filter": "Filtro de campos de associação",
|
||||
"PK & FK fields": "Campos PK & FK",
|
||||
"Association fields": "Campos de associação",
|
||||
"Optional fields": "Campos opcionais",
|
||||
"Choices fields": "Campos de opções",
|
||||
"System fields": "Campos do sistema",
|
||||
"General fields": "Campos gerais",
|
||||
"Inherited fields": "Campos herdados",
|
||||
|
@ -224,7 +224,7 @@ export default {
|
||||
"Association fields filter": "关系筛选",
|
||||
"PK & FK fields": "主外键字段",
|
||||
"Association fields": "关系字段",
|
||||
"Optional fields": "可选字段",
|
||||
"Choices fields": "选项字段",
|
||||
"System fields": "系统字段",
|
||||
"General fields": "普通字段",
|
||||
"Inherited fields": "继承字段",
|
||||
|
@ -58,10 +58,10 @@ export const AssociationFilterFilterBlockInitializer = () => {
|
||||
children,
|
||||
};
|
||||
|
||||
// 可选项字段
|
||||
// 选项字段
|
||||
const optionalFieldGroup: SchemaInitializerItemOptions = {
|
||||
type: 'itemGroup',
|
||||
title: t('Optional fields'),
|
||||
title: t('Choices fields'),
|
||||
children: optionalChildren,
|
||||
};
|
||||
|
||||
|
@ -161,7 +161,7 @@
|
||||
"Association fields filter": "Association fields filter",
|
||||
"PK & FK fields": "PK & FK fields",
|
||||
"Association fields": "Association fields",
|
||||
"Optional fields": "Optional fields",
|
||||
"Choices fields": "Choices fields",
|
||||
"System fields": "System fields",
|
||||
"General fields": "General fields",
|
||||
"Inherited fields": "Inherited fields",
|
||||
|
@ -146,7 +146,7 @@
|
||||
"Association fields filter": "Filtro de campos de associação",
|
||||
"PK & FK fields": "Campos PK & FK",
|
||||
"Association fields": "Campos de associação",
|
||||
"Optional fields": "Campos opcionais",
|
||||
"Choices fields": "Campos de opções",
|
||||
"System fields": "Campos do sistema",
|
||||
"General fields": "Campos gerais",
|
||||
"Inherited fields": "Campos herdados",
|
||||
|
@ -161,7 +161,7 @@
|
||||
"Association fields filter": "关系筛选",
|
||||
"PK & FK fields": "主外键字段",
|
||||
"Association fields": "关系字段",
|
||||
"Optional fields": "可选字段",
|
||||
"Choices fields": "选项字段",
|
||||
"System fields": "系统字段",
|
||||
"General fields": "普通字段",
|
||||
"Inherited fields": "继承字段",
|
||||
|
@ -6,7 +6,7 @@ export default {
|
||||
'Create Collection': 'Create Collection',
|
||||
'All Fields': 'All Fields',
|
||||
'Association Fields': 'Association Fields',
|
||||
'Optional fields': 'Optional fields',
|
||||
'Choices fields': 'Choices fields',
|
||||
'All relationships': 'All relationships',
|
||||
'Entity relationship only': 'Entity relationship only',
|
||||
'Inheritance relationship only': 'Inheritance relationship only',
|
||||
|
@ -6,7 +6,7 @@ export default {
|
||||
'Create Collection': 'Criar Coleção',
|
||||
'All Fields': 'Todos os Campos',
|
||||
'Association Fields': 'Campos de Associação',
|
||||
'Optional fields': 'Campos Opcionais',
|
||||
'Choices fields': 'Campos de opções',
|
||||
'All relationships': 'Todos os relacionamentos',
|
||||
'Entity relationship only': 'Somente relação de Entidade',
|
||||
'Inheritance relationship only': 'Somente relação de Herança',
|
||||
|
@ -6,7 +6,7 @@ export default {
|
||||
'Create Collection': '创建数据表',
|
||||
'All Fields': '全部',
|
||||
'Association Fields': '关系字段',
|
||||
'Optional fields': '可选字段',
|
||||
'Choices fields': '选项字段',
|
||||
'All relationships': '所有关系',
|
||||
'Entity relationship only': '实体关系',
|
||||
'Inheritance relationship only': '继承关系',
|
||||
|
Loading…
Reference in New Issue
Block a user