MCPcopy
hub / github.com/umami-software/umami / WebsiteFilterButton

Function WebsiteFilterButton

src/components/input/WebsiteFilterButton.tsx:9–68  ·  view source on GitHub ↗
({
  websiteId,
  allowBounceFilter,
}: {
  websiteId?: string;
  allowBounceFilter?: boolean;
  position?: 'bottom' | 'top' | 'left' | 'right';
  alignment?: 'end' | 'center' | 'start';
})

Source from the content-addressed store, hash-verified

7import { filtersArrayToObject } from '@/lib/params';
8
9export function WebsiteFilterButton({
10 websiteId,
11 allowBounceFilter,
12}: {
13 websiteId?: string;
14 allowBounceFilter?: boolean;
15 position?: 'bottom' | 'top' | 'left' | 'right';
16 alignment?: 'end' | 'center' | 'start';
17}) {
18 const { t, labels } = useMessages();
19 const { updateParams, pathname, router, query } = useNavigation();
20 const { filters: currentFilters } = useFilters();
21 const [excludeBounce, setExcludeBounce] = useState(!!query.excludeBounce);
22 const isOverview =
23 /^\/teams\/[^/]+\/websites\/[^/]+$/.test(pathname) || /^\/share\/[^/]+$/.test(pathname);
24
25 const handleChange = ({ filters, segment, cohort, match }: any) => {
26 const params = filtersArrayToObject(filters);
27 const cleared = Object.fromEntries(currentFilters.map(f => [f.name, undefined]));
28
29 const url = updateParams({
30 ...cleared,
31 ...params,
32 segment,
33 cohort,
34 match,
35 excludeBounce: excludeBounce ? 'true' : undefined,
36 });
37
38 router.push(url);
39 };
40
41 return (
42 <DialogButton
43 icon={<ListFilter />}
44 label={t(labels.filter)}
45 variant="outline"
46 height="min(80dvh, calc(100dvh - 40px))"
47 >
48 {({ close }) => {
49 return (
50 <>
51 {(isOverview || allowBounceFilter) && (
52 <Row position="absolute" top="30px" right="30px">
53 <Checkbox
54 value={excludeBounce ? 'true' : ''}
55 onChange={setExcludeBounce}
56 style={{ marginTop: '3px' }}
57 >
58 {t(labels.excludeBounce)}
59 </Checkbox>
60 </Row>
61 )}
62 <FilterEditForm websiteId={websiteId} onChange={handleChange} onClose={close} />
63 </>
64 );
65 }}
66 </DialogButton>

Callers

nothing calls this directly

Calls 3

useMessagesFunction · 0.90
useNavigationFunction · 0.90
useFiltersFunction · 0.90

Tested by

no test coverage detected