({
includePagination = true,
}: {
includePagination?: boolean;
} = {})
| 4 | import { useNavigation } from './useNavigation'; |
| 5 | |
| 6 | export function useFilterParameters({ |
| 7 | includePagination = true, |
| 8 | }: { |
| 9 | includePagination?: boolean; |
| 10 | } = {}) { |
| 11 | const { query } = useNavigation(); |
| 12 | const share = useShare(); |
| 13 | const allowFilter = share?.parameters?.allowFilter !== false; |
| 14 | |
| 15 | return useMemo(() => { |
| 16 | const filterParams: Record<string, any> = {}; |
| 17 | |
| 18 | if (allowFilter) { |
| 19 | for (const key of Object.keys(query)) { |
| 20 | const baseName = key.replace(/\d+$/, ''); |
| 21 | if (FILTER_COLUMNS[baseName]) { |
| 22 | filterParams[key] = query[key]; |
| 23 | } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | const params = { |
| 28 | ...filterParams, |
| 29 | search: query.search, |
| 30 | segment: allowFilter ? query.segment : undefined, |
| 31 | cohort: allowFilter ? query.cohort : undefined, |
| 32 | excludeBounce: allowFilter ? query.excludeBounce : undefined, |
| 33 | match: allowFilter ? query.match : undefined, |
| 34 | } as Record<string, any>; |
| 35 | |
| 36 | if (includePagination) { |
| 37 | params.page = query.page; |
| 38 | params.pageSize = query.pageSize; |
| 39 | } |
| 40 | |
| 41 | return params; |
| 42 | }, [allowFilter, includePagination, query]); |
| 43 | } |
no test coverage detected