mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-27 13:49:10 +02:00
Fix
This commit is contained in:
parent
82aa78f442
commit
64ed460f98
@ -22,37 +22,39 @@ export const useEventLogFilters = (
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const [availableFilters, setAvailableFilters] = useState<IFilterItem[]>([]);
|
const [availableFilters, setAvailableFilters] = useState<IFilterItem[]>([]);
|
||||||
|
|
||||||
|
const createRemovableFilterOptions = (
|
||||||
|
searchParams: URLSearchParams,
|
||||||
|
paramNames: string[],
|
||||||
|
) => {
|
||||||
|
return paramNames.reduce(
|
||||||
|
(acc, paramName) => {
|
||||||
|
const hasParam = searchParams.has(paramName);
|
||||||
|
const paramValue = searchParams.get(paramName);
|
||||||
|
|
||||||
|
acc[paramName] =
|
||||||
|
hasParam && paramValue
|
||||||
|
? (() => {
|
||||||
|
const parsed = FilterItemParam.decode(paramValue);
|
||||||
|
return parsed
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
label: parsed.values[0],
|
||||||
|
value: parsed.values[0],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: [];
|
||||||
|
})()
|
||||||
|
: [];
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{} as Record<string, Array<{ label: string; value: string }>>,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const searchParams = new URLSearchParams(location.search);
|
const searchParams = new URLSearchParams(location.search);
|
||||||
|
|
||||||
const createRemovableFilterOptions = (paramNames: string[]) => {
|
const removableOptions = createRemovableFilterOptions(searchParams, [
|
||||||
return paramNames.reduce(
|
|
||||||
(acc, paramName) => {
|
|
||||||
const hasParam = searchParams.has(paramName);
|
|
||||||
const paramValue = searchParams.get(paramName);
|
|
||||||
|
|
||||||
acc[paramName] =
|
|
||||||
hasParam && paramValue
|
|
||||||
? (() => {
|
|
||||||
const parsed =
|
|
||||||
FilterItemParam.decode(paramValue);
|
|
||||||
return parsed
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
label: parsed.values[0],
|
|
||||||
value: parsed.values[0],
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [];
|
|
||||||
})()
|
|
||||||
: [];
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
{} as Record<string, Array<{ label: string; value: string }>>,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const removableOptions = createRemovableFilterOptions([
|
|
||||||
'id',
|
'id',
|
||||||
'groupId',
|
'groupId',
|
||||||
]);
|
]);
|
||||||
|
Loading…
Reference in New Issue
Block a user