Add reusable website value combobox to attribution and journey filters

This commit is contained in:
Mike Cao committed 2026-08-03 13:03:58 -07:00
1 parent 928c0c7ea1
commit fbc4e86bb9
4 files changed
+207 -45

No files matched your search

@@ -1,42 +1,23 @@
'use client';
import { Column, Grid, ListItem, Select } from '@umami/react-zen';
import { useMemo, useState } from 'react';
import { useState } from 'react';
import { WebsiteControls } from '@/app/(main)/websites/[websiteId]/WebsiteControls';
import { Empty } from '@/components/common/Empty';
import { useDateRange, useMessages, useWebsiteValuesQuery } from '@/components/hooks';
import { useDateRange, useMessages } from '@/components/hooks';
import { WebsiteValueComboBox } from '@/components/input/WebsiteValueComboBox';
import { Attribution } from './Attribution';
const stepPlaceholder = 'Select an item';
export function AttributionPage({ websiteId }: { websiteId: string }) {
const [model, setModel] = useState('first-click');
const [type, setType] = useState('path');
const [step, setStep] = useState('');
const [search, setSearch] = useState('');
const { t, labels } = useMessages();
const {
dateRange: { startDate, endDate },
} = useDateRange();
const { data, isLoading } = useWebsiteValuesQuery({
websiteId,
type,
search,
startDate,
endDate,
});
const items = data?.filter(({ value }) => value) || [];
const stepItems = useMemo(() => {
if (!step || items.some(({ value }) => value === step)) {
return items;
}
return [{ value: step }, ...items];
}, [items, step]);
const handleTypeChange = (value: any) => {
setType(value as string);
setStep('');
setSearch('');
};
return (
@@ -66,24 +47,15 @@ export function AttributionPage({ websiteId }: { websiteId: string }) {
</Select>
</Column>
<Column>
<Select
<WebsiteValueComboBox
label={t(labels.conversionStep)}
websiteId={websiteId}
type={type}
startDate={startDate}
endDate={endDate}
value={step}
onChange={value => setStep(value?.toString() ?? '')}
placeholder={stepPlaceholder}
renderValue={({ defaultChildren }) => (step ? defaultChildren : stepPlaceholder)}
isLoading={isLoading}
searchValue={search}
onSearch={setSearch}
maxHeight={320}
allowSearch
>
{stepItems.map(({ value }) => (
<ListItem key={value} id={value}>
{value}
</ListItem>
))}
</Select>
onChange={setStep}
/>
</Column>
</Grid>
{step ? (
@@ -1,10 +1,11 @@
'use client';
import { Column, Grid, ListItem, Row, SearchField, Select } from '@umami/react-zen';
import { Column, Grid, ListItem, Row, Select } from '@umami/react-zen';
import { useState } from 'react';
import { WebsiteControls } from '@/app/(main)/websites/[websiteId]/WebsiteControls';
import { Panel } from '@/components/common/Panel';
import { useDateRange, useMessages } from '@/components/hooks';
import { FilterButtons } from '@/components/input/FilterButtons';
import { WebsiteValueComboBox } from '@/components/input/WebsiteValueComboBox';
import { Journey } from './Journey';
const JOURNEY_STEPS = [2, 3, 4, 5, 6, 7];
@@ -19,6 +20,8 @@ export function JourneysPage({ websiteId }: { websiteId: string }) {
const [steps, setSteps] = useState(DEFAULT_STEP);
const [startStep, setStartStep] = useState('');
const [endStep, setEndStep] = useState('');
const stepType = view === 'events' ? 'event' : 'path';
const additionalStepType = view === 'all' ? 'event' : undefined;
const buttons = [
{
@@ -52,19 +55,27 @@ export function JourneysPage({ websiteId }: { websiteId: string }) {
))}
</Select>
<Column>
<SearchField
<WebsiteValueComboBox
label={t(labels.startStep)}
websiteId={websiteId}
type={stepType}
additionalType={additionalStepType}
startDate={startDate}
endDate={endDate}
value={startStep}
onSearch={setStartStep}
delay={1000}
onChange={setStartStep}
/>
</Column>
<Column>
<SearchField
<WebsiteValueComboBox
label={t(labels.endStep)}
websiteId={websiteId}
type={stepType}
additionalType={additionalStepType}
startDate={startDate}
endDate={endDate}
value={endStep}
onSearch={setEndStep}
delay={1000}
onChange={setEndStep}
/>
</Column>
</Grid>