add share page options enable filtering and enforce theme
This commit is contained in:
1 parent
5ccfb6d0a5
commit
9b099408c2
75 files changed
+450
-172
No files matched your search
@@ -1,27 +1,32 @@
|
||||
import { useMemo } from 'react';
|
||||
import { FILTER_COLUMNS } from '@/lib/constants';
|
||||
import { useShare } from './context/useShare';
|
||||
import { useNavigation } from './useNavigation';
|
||||
|
||||
export function useFilterParameters({ includePagination = true }: { includePagination?: boolean } = {}) {
|
||||
const { query } = useNavigation();
|
||||
const share = useShare();
|
||||
const allowFilter = share?.parameters?.allowFilter !== false;
|
||||
|
||||
return useMemo(() => {
|
||||
const filterParams: Record<string, any> = {};
|
||||
|
||||
for (const key of Object.keys(query)) {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
filterParams[key] = query[key];
|
||||
if (allowFilter) {
|
||||
for (const key of Object.keys(query)) {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
filterParams[key] = query[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const params = {
|
||||
...filterParams,
|
||||
search: query.search,
|
||||
segment: query.segment,
|
||||
cohort: query.cohort,
|
||||
excludeBounce: query.excludeBounce,
|
||||
match: query.match,
|
||||
segment: allowFilter ? query.segment : undefined,
|
||||
cohort: allowFilter ? query.cohort : undefined,
|
||||
excludeBounce: allowFilter ? query.excludeBounce : undefined,
|
||||
match: allowFilter ? query.match : undefined,
|
||||
} as Record<string, any>;
|
||||
|
||||
if (includePagination) {
|
||||
@@ -30,5 +35,5 @@ export function useFilterParameters({ includePagination = true }: { includePagin
|
||||
}
|
||||
|
||||
return params;
|
||||
}, [query, includePagination]);
|
||||
}, [allowFilter, includePagination, query]);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { FILTER_COLUMNS, OPERATORS } from '@/lib/constants';
|
||||
import { safeDecodeURIComponent } from '@/lib/url';
|
||||
import { useShare } from './context/useShare';
|
||||
import { useFields } from './useFields';
|
||||
import { useMessages } from './useMessages';
|
||||
import { useNavigation } from './useNavigation';
|
||||
@@ -10,6 +11,8 @@ export function useFilters() {
|
||||
const { query } = useNavigation();
|
||||
const { fields } = useFields();
|
||||
const operatorLabels = useOperatorLabels();
|
||||
const share = useShare();
|
||||
const allowFilter = share?.parameters?.allowFilter !== false;
|
||||
|
||||
const operators = [
|
||||
{ name: 'eq', type: 'string', label: t(labels.is) },
|
||||
@@ -56,30 +59,32 @@ export function useFilters() {
|
||||
uuid: [OPERATORS.equals],
|
||||
};
|
||||
|
||||
const filters = Object.keys(query).reduce((arr, key) => {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
let operator = 'eq';
|
||||
let value = safeDecodeURIComponent(query[key]);
|
||||
const label = fields.find(({ name }) => name === baseName)?.label;
|
||||
const filters = allowFilter
|
||||
? Object.keys(query).reduce((arr, key) => {
|
||||
const baseName = key.replace(/\d+$/, '');
|
||||
if (FILTER_COLUMNS[baseName]) {
|
||||
let operator = 'eq';
|
||||
let value = safeDecodeURIComponent(query[key]);
|
||||
const label = fields.find(({ name }) => name === baseName)?.label;
|
||||
|
||||
const match = value.match(/^([a-z]+)\.(.*)/);
|
||||
const match = value.match(/^([a-z]+)\.(.*)/);
|
||||
|
||||
if (match) {
|
||||
operator = match[1];
|
||||
value = match[2];
|
||||
}
|
||||
if (match) {
|
||||
operator = match[1];
|
||||
value = match[2];
|
||||
}
|
||||
|
||||
return arr.concat({
|
||||
name: key,
|
||||
type: baseName,
|
||||
operator,
|
||||
value,
|
||||
label,
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
}, []);
|
||||
return arr.concat({
|
||||
name: key,
|
||||
type: baseName,
|
||||
operator,
|
||||
value,
|
||||
label,
|
||||
});
|
||||
}
|
||||
return arr;
|
||||
}, [])
|
||||
: [];
|
||||
|
||||
const getFilters = (type: string) => {
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user