implement OR logic to filters, segments, cohorts

This commit is contained in:
Francis Cao committed 2026-02-21 20:00:43 -08:00
1 parent 79c06787cd
commit cc1e4438d0
64 files changed
+343 -54

No files matched your search

@@ -21,6 +21,7 @@ export function useFilterParameters() {
segment: query.segment,
cohort: query.cohort,
excludeBounce: query.excludeBounce,
match: query.match,
page: query.page,
pageSize: query.pageSize,
};
+24 -2
View File
@@ -3,6 +3,7 @@ import {
Column,
Grid,
Icon,
Label,
List,
ListItem,
ListSection,
@@ -12,6 +13,7 @@ import {
MenuTrigger,
Popover,
Row,
Select,
} from '@umami/react-zen';
import { endOfDay, subMonths } from 'date-fns';
import type { Key } from 'react';
@@ -24,11 +26,20 @@ export interface FieldFiltersProps {
websiteId: string;
value?: { name: string; operator: string; value: string }[];
exclude?: string[];
match?: string;
onChange?: (data: any) => void;
onMatchChange?: (match: string) => void;
}
export function FieldFilters({ websiteId, value, exclude = [], onChange }: FieldFiltersProps) {
const { t, messages } = useMessages();
export function FieldFilters({
websiteId,
value,
exclude = [],
match = 'all',
onChange,
onMatchChange,
}: FieldFiltersProps) {
const { t, labels, messages } = useMessages();
const { fields, groupLabels } = useFields();
const startDate = subMonths(endOfDay(new Date()), 6);
const endDate = endOfDay(new Date());
@@ -126,6 +137,17 @@ export function FieldFilters({ websiteId, value, exclude = [], onChange }: Field
</List>
</Column>
<Column overflow="auto" gapY="4" style={{ contain: 'layout' }}>
{onMatchChange && (
<Row alignItems="center" gap>
<Column gap="1">
<Label>{t(labels.match)}</Label>
<Select value={match} onChange={onMatchChange} style={{ width: 150 }}>
<ListItem id="all">{t(labels.matchAll)}</ListItem>
<ListItem id="any">{t(labels.matchAny)}</ListItem>
</Select>
</Column>
</Row>
)}
{value.map((filter, index) => {
return (
<FilterRecord
+19 -3
View File
@@ -6,13 +6,18 @@ import { SegmentFilters } from '@/components/input/SegmentFilters';
export interface FilterEditFormProps {
websiteId?: string;
onChange?: (params: { filters: any[]; segment?: string; cohort?: string }) => void;
onChange?: (params: {
filters: any[];
segment?: string;
cohort?: string;
match?: string;
}) => void;
onClose?: () => void;
}
export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormProps) {
const {
query: { segment, cohort },
query: { segment, cohort, match },
pathname,
} = useNavigation();
const { filters } = useFilters();
@@ -20,6 +25,7 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
const [currentFilters, setCurrentFilters] = useState(filters);
const [currentSegment, setCurrentSegment] = useState(segment);
const [currentCohort, setCurrentCohort] = useState(cohort);
const [currentMatch, setCurrentMatch] = useState<string>(match || 'all');
const { isMobile } = useMobile();
const excludeFilters = pathname.includes('/pixels') || pathname.includes('/links');
const excludeEvent = !pathname.endsWith('/events');
@@ -28,6 +34,7 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
setCurrentFilters([]);
setCurrentSegment(undefined);
setCurrentCohort(undefined);
setCurrentMatch('all');
};
const handleSave = () => {
@@ -35,6 +42,7 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
filters: currentFilters.filter(f => f.value),
segment: currentSegment,
cohort: currentCohort,
match: currentMatch !== 'all' ? currentMatch : undefined,
});
onClose?.();
};
@@ -61,7 +69,9 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
<FieldFilters
websiteId={websiteId}
value={currentFilters}
match={currentMatch}
onChange={setCurrentFilters}
onMatchChange={setCurrentMatch}
exclude={
excludeFilters
? ['path', 'title', 'hostname', 'distinctId', 'tag', 'event']
@@ -92,7 +102,13 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
<Button onPress={handleReset}>{t(labels.reset)}</Button>
<Row alignItems="center" justifyContent="flex-end" gridColumn="span 2" gap>
<Button onPress={onClose}>{t(labels.cancel)}</Button>
<Button variant="primary" onPress={handleSave}>
<Button
variant="primary"
onPress={handleSave}
isDisabled={
currentFilters.filter(f => f.value).length === 0 && !currentSegment && !currentCohort
}
>
{t(labels.apply)}
</Button>
</Row>
+2 -1
View File
@@ -19,13 +19,14 @@ export function WebsiteFilterButton({
const isOverview =
/^\/teams\/[^/]+\/websites\/[^/]+$/.test(pathname) || /^\/share\/[^/]+$/.test(pathname);
const handleChange = ({ filters, segment, cohort }: any) => {
const handleChange = ({ filters, segment, cohort, match }: any) => {
const params = filtersArrayToObject(filters);
const url = updateParams({
...params,
segment,
cohort,
match,
excludeBounce: excludeBounce ? 'true' : undefined,
});
+3
View File
@@ -305,6 +305,9 @@ export const labels: Record<string, string> = {
other: 'label.other',
boards: 'label.boards',
apply: 'label.apply',
match: 'label.match',
matchAll: 'label.match-all',
matchAny: 'label.match-any',
link: 'label.link',
links: 'label.links',
pixel: 'label.pixel',