({
websiteId,
allowBounceFilter,
}: {
websiteId?: string;
allowBounceFilter?: boolean;
position?: 'bottom' | 'top' | 'left' | 'right';
alignment?: 'end' | 'center' | 'start';
})
| 7 | import { filtersArrayToObject } from '@/lib/params'; |
| 8 | |
| 9 | export 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> |
nothing calls this directly
no test coverage detected