|
|
@@ -22,15 +22,14 @@ export type FilterField<S extends Record<string, unknown>> =
|
|
|
options: {label: string; value: string}[];
|
|
|
multiple?: boolean;
|
|
|
hideClear?: boolean;
|
|
|
+ loading?: boolean;
|
|
|
};
|
|
|
|
|
|
-export type FilterGroupMap<S extends Record<string, unknown>> = Map<
|
|
|
-string,
|
|
|
-FilterField<S>
|
|
|
->;
|
|
|
+export type FilterFieldObject<S extends Record<string, unknown>>
|
|
|
+= Record<string, FilterField<S>>;
|
|
|
|
|
|
type Props<S extends Record<string, string | string[]>> = {
|
|
|
- fieldsMap?: FilterGroupMap<S>;
|
|
|
+ fieldsObject?: FilterFieldObject<S>;
|
|
|
fixedFields: FilterField<S>[];
|
|
|
fields: Record<string, string | string[]>;
|
|
|
isSearching: boolean;
|
|
|
@@ -56,7 +55,7 @@ function LDFilterTool<S extends Record<string, string | string[]>>(
|
|
|
onDatesChange,
|
|
|
fixedFields,
|
|
|
onSearch,
|
|
|
- fieldsMap,
|
|
|
+ fieldsObject,
|
|
|
onScreen,
|
|
|
onReset,
|
|
|
isSearching,
|
|
|
@@ -78,16 +77,16 @@ function LDFilterTool<S extends Record<string, string | string[]>>(
|
|
|
|
|
|
const list = useMemo<FilterField<S>[]>(
|
|
|
function() {
|
|
|
- if (!conditions || !fieldsMap) return fixedFields;
|
|
|
+ if (!conditions || !fieldsObject) return fixedFields;
|
|
|
|
|
|
const arr = conditions.split(',').filter(Boolean);
|
|
|
|
|
|
const els = arr
|
|
|
.map(function(id) {
|
|
|
- if (!fieldsMap.has(id))
|
|
|
+ if (!fieldsObject[id])
|
|
|
return;
|
|
|
|
|
|
- return {...fieldsMap.get(id)!, id: Number(id)};
|
|
|
+ return {...fieldsObject[id]!, id: Number(id)};
|
|
|
})
|
|
|
.filter(Boolean)
|
|
|
.sort((a, b) => a.id - b.id);
|
|
|
@@ -96,7 +95,7 @@ function LDFilterTool<S extends Record<string, string | string[]>>(
|
|
|
|
|
|
return nextEls;
|
|
|
},
|
|
|
- [conditions, fixedFields, fieldsMap],
|
|
|
+ [conditions, fixedFields, fieldsObject],
|
|
|
);
|
|
|
|
|
|
const onSearchFn = useLatest(onSearch);
|
|
|
@@ -178,6 +177,7 @@ function LDFilterTool<S extends Record<string, string | string[]>>(
|
|
|
options={state.options}
|
|
|
hideClear={state.hideClear}
|
|
|
multiple={state.multiple}
|
|
|
+ loading={state.loading}
|
|
|
/>
|
|
|
);
|
|
|
}
|
|
|
@@ -194,7 +194,7 @@ function LDFilterTool<S extends Record<string, string | string[]>>(
|
|
|
{onScreen && <LDFilterSelectorModal
|
|
|
visible={modalVisible!}
|
|
|
onClose={onCloseModal!}
|
|
|
- filtermap={fieldsMap!}
|
|
|
+ filtermap={fieldsObject!}
|
|
|
source={conditions}
|
|
|
onConfirm={onScreenConfirm}
|
|
|
/>}
|