Merge branch 'dev' into master
This commit is contained in:
583 files changed
+35879
-142817
No files matched your search
@@ -7,12 +7,12 @@ export interface ActionSelectProps {
|
||||
}
|
||||
|
||||
export function ActionSelect({ value = 'path', onChange }: ActionSelectProps) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<Select value={value} onChange={onChange}>
|
||||
<ListItem id="path">{formatMessage(labels.viewedPage)}</ListItem>
|
||||
<ListItem id="event">{formatMessage(labels.triggeredEvent)}</ListItem>
|
||||
<ListItem id="path">{t(labels.viewedPage)}</ListItem>
|
||||
<ListItem id="event">{t(labels.triggeredEvent)}</ListItem>
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { Icon, ListItem, Row, Select, type SelectProps, Text } from '@umami/react-zen';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { useBoardQuery, useBoardsQuery, useMessages } from '@/components/hooks';
|
||||
import { LayoutDashboard } from '@/components/icons';
|
||||
|
||||
export function BoardSelect({
|
||||
boardId,
|
||||
teamId,
|
||||
onChange,
|
||||
isCollapsed,
|
||||
buttonProps,
|
||||
listProps,
|
||||
...props
|
||||
}: {
|
||||
boardId?: string;
|
||||
teamId?: string;
|
||||
isCollapsed?: boolean;
|
||||
} & SelectProps) {
|
||||
const { t, messages } = useMessages();
|
||||
const { data: board } = useBoardQuery(boardId);
|
||||
const [name, setName] = useState<string>(board?.name);
|
||||
const [search, setSearch] = useState('');
|
||||
const { data, isLoading } = useBoardsQuery({ teamId }, { search, pageSize: 20 });
|
||||
const listItems: { id: string; name: string }[] = data?.data || [];
|
||||
|
||||
useEffect(() => {
|
||||
setName(board?.name);
|
||||
}, [board?.name]);
|
||||
|
||||
const handleOpenChange = () => {
|
||||
setSearch('');
|
||||
};
|
||||
|
||||
const handleChange = (id: string) => {
|
||||
setName(listItems.find(item => item.id === id)?.name);
|
||||
onChange?.(id);
|
||||
};
|
||||
|
||||
const renderValue = () => {
|
||||
if (isCollapsed) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return (
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<LayoutDashboard />
|
||||
</Icon>
|
||||
<Text truncate>{name}</Text>
|
||||
</Row>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Select
|
||||
{...props}
|
||||
value={boardId}
|
||||
isLoading={isLoading}
|
||||
allowSearch={true}
|
||||
searchValue={search}
|
||||
onSearch={setSearch}
|
||||
onChange={handleChange}
|
||||
onOpenChange={handleOpenChange}
|
||||
renderValue={renderValue}
|
||||
buttonProps={{
|
||||
...buttonProps,
|
||||
style: {
|
||||
minHeight: 40,
|
||||
gap: 0,
|
||||
justifyContent: isCollapsed ? 'start' : undefined,
|
||||
...buttonProps?.style,
|
||||
},
|
||||
}}
|
||||
listProps={{
|
||||
...listProps,
|
||||
renderEmptyState:
|
||||
listProps?.renderEmptyState || (() => <Empty message={t(messages.noResultsFound)} />),
|
||||
style: {
|
||||
maxHeight: 'calc(42vh - 65px)',
|
||||
width: 280,
|
||||
...listProps?.style,
|
||||
},
|
||||
}}
|
||||
>
|
||||
{listItems.map(({ id, name }) => (
|
||||
<ListItem key={id} id={id}>
|
||||
{name}
|
||||
</ListItem>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
'use client';
|
||||
import { Checkbox, Row } from '@umami/react-zen';
|
||||
import { useMessages } from '@/components/hooks/useMessages';
|
||||
import { useNavigation } from '@/components/hooks/useNavigation';
|
||||
|
||||
export function BounceFilter() {
|
||||
const { router, query, updateParams } = useNavigation();
|
||||
const { t, labels } = useMessages();
|
||||
const isSelected = query.excludeBounce === 'true';
|
||||
|
||||
const handleChange = (value: boolean) => {
|
||||
if (value) {
|
||||
router.push(updateParams({ excludeBounce: 'true' }));
|
||||
} else {
|
||||
router.push(updateParams({ excludeBounce: undefined }));
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Row alignItems="center" gap>
|
||||
<Checkbox isSelected={isSelected} onChange={handleChange}>
|
||||
{t(labels.excludeBounce)}
|
||||
</Checkbox>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
@@ -4,13 +4,12 @@ import { useMessages } from '@/components/hooks';
|
||||
import { CURRENCIES } from '@/lib/constants';
|
||||
|
||||
export function CurrencySelect({ value, onChange }) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const [search, setSearch] = useState('');
|
||||
|
||||
return (
|
||||
<Select
|
||||
items={CURRENCIES}
|
||||
label={formatMessage(labels.currency)}
|
||||
label={t(labels.currency)}
|
||||
value={value}
|
||||
defaultValue={value}
|
||||
onChange={onChange}
|
||||
|
||||
@@ -22,56 +22,56 @@ export function DateFilter({
|
||||
placement = 'bottom',
|
||||
...props
|
||||
}: DateFilterProps) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const [showPicker, setShowPicker] = useState(false);
|
||||
const { startDate, endDate } = parseDateRange(value) || {};
|
||||
const { isMobile } = useMobile();
|
||||
|
||||
const options = [
|
||||
{ label: formatMessage(labels.today), value: '0day' },
|
||||
{ label: t(labels.today), value: '0day' },
|
||||
{
|
||||
label: formatMessage(labels.lastHours, { x: '24' }),
|
||||
label: t(labels.lastHours, { x: '24' }),
|
||||
value: '24hour',
|
||||
},
|
||||
{
|
||||
label: formatMessage(labels.thisWeek),
|
||||
label: t(labels.thisWeek),
|
||||
value: '0week',
|
||||
divider: true,
|
||||
},
|
||||
{
|
||||
label: formatMessage(labels.lastDays, { x: '7' }),
|
||||
label: t(labels.lastDays, { x: '7' }),
|
||||
value: '7day',
|
||||
},
|
||||
{
|
||||
label: formatMessage(labels.thisMonth),
|
||||
label: t(labels.thisMonth),
|
||||
value: '0month',
|
||||
divider: true,
|
||||
},
|
||||
{
|
||||
label: formatMessage(labels.lastDays, { x: '30' }),
|
||||
label: t(labels.lastDays, { x: '30' }),
|
||||
value: '30day',
|
||||
},
|
||||
{
|
||||
label: formatMessage(labels.lastDays, { x: '90' }),
|
||||
label: t(labels.lastDays, { x: '90' }),
|
||||
value: '90day',
|
||||
},
|
||||
{ label: formatMessage(labels.thisYear), value: '0year' },
|
||||
{ label: t(labels.thisYear), value: '0year' },
|
||||
{
|
||||
label: formatMessage(labels.lastMonths, { x: '6' }),
|
||||
label: t(labels.lastMonths, { x: '6' }),
|
||||
value: '6month',
|
||||
divider: true,
|
||||
},
|
||||
{
|
||||
label: formatMessage(labels.lastMonths, { x: '12' }),
|
||||
label: t(labels.lastMonths, { x: '12' }),
|
||||
value: '12month',
|
||||
},
|
||||
showAllTime && {
|
||||
label: formatMessage(labels.allTime),
|
||||
label: t(labels.allTime),
|
||||
value: 'all',
|
||||
divider: true,
|
||||
},
|
||||
{
|
||||
label: formatMessage(labels.customRange),
|
||||
label: t(labels.customRange),
|
||||
value: 'custom',
|
||||
divider: true,
|
||||
},
|
||||
@@ -107,10 +107,10 @@ export function DateFilter({
|
||||
<Select
|
||||
{...props}
|
||||
value={selectedValue}
|
||||
placeholder={formatMessage(labels.selectDate)}
|
||||
placeholder={t(labels.selectDate)}
|
||||
onChange={handleChange}
|
||||
renderValue={renderValue}
|
||||
popoverProps={{ placement }}
|
||||
popoverProps={{ placement, style: { minWidth: 200 } }}
|
||||
isFullscreen={isMobile}
|
||||
>
|
||||
{options.map(({ label, value, divider }: any) => {
|
||||
|
||||
@@ -4,10 +4,10 @@ import {
|
||||
Dialog,
|
||||
type DialogProps,
|
||||
DialogTrigger,
|
||||
IconLabel,
|
||||
Modal,
|
||||
} from '@umami/react-zen';
|
||||
import type { CSSProperties, ReactNode } from 'react';
|
||||
import { IconLabel } from '@/components/common/IconLabel';
|
||||
import { useMobile } from '@/components/hooks';
|
||||
|
||||
export interface DialogButtonProps extends Omit<ButtonProps, 'children'> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Button, Icon, Tooltip, TooltipTrigger } from '@umami/react-zen';
|
||||
import { Button, Icon, Text, Tooltip, TooltipTrigger } from '@umami/react-zen';
|
||||
import Papa from 'papaparse';
|
||||
import { useMessages } from '@/components/hooks';
|
||||
import { Download } from '@/components/icons';
|
||||
@@ -11,7 +11,7 @@ export function DownloadButton({
|
||||
data?: any;
|
||||
onClick?: () => void;
|
||||
}) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
const handleClick = async () => {
|
||||
downloadCsv(`${filename}.csv`, Papa.unparse(data));
|
||||
@@ -24,7 +24,9 @@ export function DownloadButton({
|
||||
<Download />
|
||||
</Icon>
|
||||
</Button>
|
||||
<Tooltip>{formatMessage(labels.download)}</Tooltip>
|
||||
<Tooltip>
|
||||
<Text size="sm">{t(labels.download)}</Text>
|
||||
</Tooltip>
|
||||
</TooltipTrigger>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import { useFilterParameters } from '@/components/hooks/useFilterParameters';
|
||||
import { Download } from '@/components/icons';
|
||||
|
||||
export function ExportButton({ websiteId }: { websiteId: string }) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const date = useDateParameters();
|
||||
const filters = useFilterParameters();
|
||||
@@ -41,7 +41,7 @@ export function ExportButton({ websiteId }: { websiteId: string }) {
|
||||
<Download />
|
||||
</Icon>
|
||||
</LoadingButton>
|
||||
<Tooltip>{formatMessage(labels.download)}</Tooltip>
|
||||
<Tooltip>{t(labels.download)}</Tooltip>
|
||||
</TooltipTrigger>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,58 +3,85 @@ import {
|
||||
Column,
|
||||
Grid,
|
||||
Icon,
|
||||
Label,
|
||||
List,
|
||||
ListItem,
|
||||
ListSection,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuSection,
|
||||
MenuTrigger,
|
||||
Popover,
|
||||
Row,
|
||||
Select,
|
||||
} from '@umami/react-zen';
|
||||
import { endOfDay, subMonths } from 'date-fns';
|
||||
import type { Key } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { FilterRecord } from '@/components/common/FilterRecord';
|
||||
import { useFields, useMessages, useMobile } from '@/components/hooks';
|
||||
import { type FieldGroup, useFields, useMessages, useMobile } from '@/components/hooks';
|
||||
import { Plus } from '@/components/icons';
|
||||
|
||||
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 { formatMessage, messages } = useMessages();
|
||||
const { fields } = useFields();
|
||||
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());
|
||||
const { isMobile } = useMobile();
|
||||
|
||||
const updateFilter = (name: string, props: Record<string, any>) => {
|
||||
onChange(value.map(filter => (filter.name === name ? { ...filter, ...props } : filter)));
|
||||
const groupedFields = fields
|
||||
.filter(({ name }) => !exclude.includes(name))
|
||||
.reduce(
|
||||
(acc, field) => {
|
||||
const group = field.group;
|
||||
if (!acc[group]) {
|
||||
acc[group] = [];
|
||||
}
|
||||
acc[group].push(field);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<FieldGroup, typeof fields>,
|
||||
);
|
||||
|
||||
const updateFilter = (index: number, props: Record<string, any>) => {
|
||||
onChange(value.map((filter, i) => (i === index ? { ...filter, ...props } : filter)));
|
||||
};
|
||||
|
||||
const handleAdd = (name: Key) => {
|
||||
onChange(value.concat({ name: name.toString(), operator: 'eq', value: '' }));
|
||||
};
|
||||
|
||||
const handleChange = (name: string, value: Key) => {
|
||||
updateFilter(name, { value });
|
||||
const handleChange = (index: number, val: Key) => {
|
||||
updateFilter(index, { value: val });
|
||||
};
|
||||
|
||||
const handleSelect = (name: string, operator: Key) => {
|
||||
updateFilter(name, { operator });
|
||||
const handleSelect = (index: number, operator: Key) => {
|
||||
updateFilter(index, { operator });
|
||||
};
|
||||
|
||||
const handleRemove = (name: string) => {
|
||||
onChange(value.filter(filter => filter.name !== name));
|
||||
const handleRemove = (index: number) => {
|
||||
onChange(value.filter((_, i) => i !== index));
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid columns={{ xs: '1fr', md: '180px 1fr' }} overflow="hidden" gapY="6">
|
||||
<Row display={{ xs: 'flex', md: 'none' }}>
|
||||
<Grid columns={{ base: '1fr', md: '180px 1fr' }} overflow="hidden" gapY="6">
|
||||
<Row display={{ base: 'flex', md: 'none' }}>
|
||||
<MenuTrigger>
|
||||
<Button>
|
||||
<Icon>
|
||||
@@ -66,51 +93,77 @@ export function FieldFilters({ websiteId, value, exclude = [], onChange }: Field
|
||||
onAction={handleAdd}
|
||||
style={{ maxHeight: 'calc(100vh - 2rem)', overflowY: 'auto' }}
|
||||
>
|
||||
{fields
|
||||
.filter(({ name }) => !exclude.includes(name))
|
||||
.map(field => {
|
||||
const isDisabled = !!value.find(({ name }) => name === field.name);
|
||||
return (
|
||||
<MenuItem key={field.name} id={field.name} isDisabled={isDisabled}>
|
||||
{field.label}
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
{groupLabels.map(({ key: groupKey, label }) => {
|
||||
const groupFields = groupedFields[groupKey];
|
||||
return (
|
||||
<MenuSection key={groupKey} title={label}>
|
||||
{groupFields.map(field => {
|
||||
return (
|
||||
<MenuItem key={field.name} id={field.name}>
|
||||
{field.filterLabel}
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</MenuSection>
|
||||
);
|
||||
})}
|
||||
</Menu>
|
||||
</Popover>
|
||||
</MenuTrigger>
|
||||
</Row>
|
||||
<Column display={{ xs: 'none', md: 'flex' }} border="right" paddingRight="3" marginRight="6">
|
||||
<Column
|
||||
display={{ base: 'none', md: 'flex' }}
|
||||
border="right"
|
||||
paddingRight="3"
|
||||
marginRight="6"
|
||||
>
|
||||
<List onAction={handleAdd}>
|
||||
{fields
|
||||
.filter(({ name }) => !exclude.includes(name))
|
||||
.map(field => {
|
||||
const isDisabled = !!value.find(({ name }) => name === field.name);
|
||||
return (
|
||||
<ListItem key={field.name} id={field.name} isDisabled={isDisabled}>
|
||||
{field.label}
|
||||
</ListItem>
|
||||
);
|
||||
})}
|
||||
{groupLabels.map(({ key: groupKey, label }) => {
|
||||
const groupFields = groupedFields[groupKey];
|
||||
if (!groupFields || groupFields.length === 0) return null;
|
||||
|
||||
return (
|
||||
<ListSection key={groupKey} title={label}>
|
||||
{groupFields.map(field => {
|
||||
return (
|
||||
<ListItem key={field.name} id={field.name}>
|
||||
{field.filterLabel}
|
||||
</ListItem>
|
||||
);
|
||||
})}
|
||||
</ListSection>
|
||||
);
|
||||
})}
|
||||
</List>
|
||||
</Column>
|
||||
<Column overflow="auto" gapY="4" style={{ contain: 'layout' }}>
|
||||
{value.map(filter => {
|
||||
{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
|
||||
key={filter.name}
|
||||
key={`${filter.name}-${index}`}
|
||||
websiteId={websiteId}
|
||||
type={filter.name}
|
||||
startDate={startDate}
|
||||
endDate={endDate}
|
||||
{...filter}
|
||||
onSelect={handleSelect}
|
||||
onRemove={handleRemove}
|
||||
onChange={handleChange}
|
||||
onSelect={(_name, operator) => handleSelect(index, operator)}
|
||||
onRemove={() => handleRemove(index)}
|
||||
onChange={(_name, val) => handleChange(index, val)}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{!value.length && <Empty message={formatMessage(messages.nothingSelected)} />}
|
||||
{!value.length && <Empty message={t(messages.nothingSelected)} />}
|
||||
</Column>
|
||||
</Grid>
|
||||
);
|
||||
|
||||
@@ -21,7 +21,7 @@ import { Bookmark, X } from '@/components/icons';
|
||||
import { isSearchOperator } from '@/lib/params';
|
||||
|
||||
export function FilterBar({ websiteId }: { websiteId: string }) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { formatValue } = useFormat();
|
||||
const {
|
||||
router,
|
||||
@@ -51,12 +51,18 @@ export function FilterBar({ websiteId }: { websiteId: string }) {
|
||||
}
|
||||
|
||||
return (
|
||||
<Row gap alignItems="center" justifyContent="space-between" padding="2" backgroundColor="3">
|
||||
<Row
|
||||
gap
|
||||
alignItems="center"
|
||||
justifyContent="space-between"
|
||||
padding="2"
|
||||
backgroundColor="surface-sunken"
|
||||
>
|
||||
<Row alignItems="center" gap="2" wrap="wrap">
|
||||
{segment && !isLoading && (
|
||||
<FilterItem
|
||||
name="segment"
|
||||
label={formatMessage(labels.segment)}
|
||||
label={t(labels.segment)}
|
||||
value={data?.name || segment}
|
||||
operator={operatorLabels.eq}
|
||||
onRemove={() => handleSegmentRemove('segment')}
|
||||
@@ -65,15 +71,20 @@ export function FilterBar({ websiteId }: { websiteId: string }) {
|
||||
{cohort && !isLoading && (
|
||||
<FilterItem
|
||||
name="cohort"
|
||||
label={formatMessage(labels.cohort)}
|
||||
label={t(labels.cohort)}
|
||||
value={data?.name || cohort}
|
||||
operator={operatorLabels.eq}
|
||||
onRemove={() => handleSegmentRemove('cohort')}
|
||||
/>
|
||||
)}
|
||||
{filters.map(filter => {
|
||||
const { name, label, operator, value } = filter;
|
||||
const paramValue = isSearchOperator(operator) ? value : formatValue(value, name);
|
||||
const { name, type, label, operator, value } = filter;
|
||||
const paramValue = isSearchOperator(operator)
|
||||
? value
|
||||
: String(value)
|
||||
.split(',')
|
||||
.map(v => formatValue(v, type || name))
|
||||
.join(', ');
|
||||
|
||||
return (
|
||||
<FilterItem
|
||||
@@ -97,12 +108,12 @@ export function FilterBar({ websiteId }: { websiteId: string }) {
|
||||
</Icon>
|
||||
</Button>
|
||||
<Tooltip>
|
||||
<Text>{formatMessage(labels.saveSegment)}</Text>
|
||||
<Text>{t(labels.saveSegment)}</Text>
|
||||
</Tooltip>
|
||||
</TooltipTrigger>
|
||||
)}
|
||||
<Modal>
|
||||
<Dialog title={formatMessage(labels.segment)} style={{ width: 800, minHeight: 300 }}>
|
||||
<Dialog title={t(labels.segment)} style={{ width: 800, minHeight: 300 }}>
|
||||
{({ close }) => {
|
||||
return <SegmentEditForm websiteId={websiteId} onClose={close} filters={filters} />;
|
||||
}}
|
||||
@@ -116,7 +127,7 @@ export function FilterBar({ websiteId }: { websiteId: string }) {
|
||||
</Icon>
|
||||
</Button>
|
||||
<Tooltip>
|
||||
<Text>{formatMessage(labels.clearAll)}</Text>
|
||||
<Text>{t(labels.clearAll)}</Text>
|
||||
</Tooltip>
|
||||
</TooltipTrigger>
|
||||
</Row>
|
||||
|
||||
@@ -6,27 +6,35 @@ 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();
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
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');
|
||||
|
||||
const handleReset = () => {
|
||||
setCurrentFilters([]);
|
||||
setCurrentSegment(undefined);
|
||||
setCurrentCohort(undefined);
|
||||
setCurrentMatch('all');
|
||||
};
|
||||
|
||||
const handleSave = () => {
|
||||
@@ -34,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?.();
|
||||
};
|
||||
@@ -48,11 +57,11 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
|
||||
<Column minHeight="500px">
|
||||
<Tabs>
|
||||
<TabList>
|
||||
<Tab id="fields">{formatMessage(labels.fields)}</Tab>
|
||||
<Tab id="fields">{t(labels.fields)}</Tab>
|
||||
{!excludeFilters && (
|
||||
<>
|
||||
<Tab id="segments">{formatMessage(labels.segments)}</Tab>
|
||||
<Tab id="cohorts">{formatMessage(labels.cohorts)}</Tab>
|
||||
<Tab id="segments">{t(labels.segments)}</Tab>
|
||||
<Tab id="cohorts">{t(labels.cohorts)}</Tab>
|
||||
</>
|
||||
)}
|
||||
</TabList>
|
||||
@@ -60,8 +69,16 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
|
||||
<FieldFilters
|
||||
websiteId={websiteId}
|
||||
value={currentFilters}
|
||||
match={currentMatch}
|
||||
onChange={setCurrentFilters}
|
||||
exclude={excludeFilters ? ['path', 'title', 'hostname', 'tag', 'event'] : []}
|
||||
onMatchChange={setCurrentMatch}
|
||||
exclude={
|
||||
excludeFilters
|
||||
? ['path', 'title', 'hostname', 'distinctId', 'tag', 'event']
|
||||
: excludeEvent
|
||||
? ['event']
|
||||
: []
|
||||
}
|
||||
/>
|
||||
</TabPanel>
|
||||
<TabPanel id="segments">
|
||||
@@ -82,11 +99,11 @@ export function FilterEditForm({ websiteId, onChange, onClose }: FilterEditFormP
|
||||
</Tabs>
|
||||
</Column>
|
||||
<Row alignItems="center" justifyContent="space-between" gap>
|
||||
<Button onPress={handleReset}>{formatMessage(labels.reset)}</Button>
|
||||
<Button onPress={handleReset}>{t(labels.reset)}</Button>
|
||||
<Row alignItems="center" justifyContent="flex-end" gridColumn="span 2" gap>
|
||||
<Button onPress={onClose}>{formatMessage(labels.cancel)}</Button>
|
||||
<Button onPress={onClose}>{t(labels.cancel)}</Button>
|
||||
<Button variant="primary" onPress={handleSave}>
|
||||
{formatMessage(labels.apply)}
|
||||
{t(labels.apply)}
|
||||
</Button>
|
||||
</Row>
|
||||
</Row>
|
||||
|
||||
@@ -14,12 +14,12 @@ export function LanguageButton() {
|
||||
return (
|
||||
<MenuTrigger key="language">
|
||||
<Button variant="quiet">
|
||||
<Icon>
|
||||
<Icon color="primary">
|
||||
<Globe />
|
||||
</Icon>
|
||||
</Button>
|
||||
<Popover placement="bottom end">
|
||||
<Dialog variant="menu">
|
||||
<Dialog>
|
||||
<Grid columns="repeat(3, minmax(200px, 1fr))" overflow="hidden">
|
||||
{items.map(({ value, label }) => {
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import { Icon, ListItem, Row, Select, type SelectProps, Text } from '@umami/react-zen';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { useLinkQuery, useLinksQuery, useMessages } from '@/components/hooks';
|
||||
import { Link } from '@/components/icons';
|
||||
|
||||
export function LinkSelect({
|
||||
linkId,
|
||||
teamId,
|
||||
onChange,
|
||||
isCollapsed,
|
||||
buttonProps,
|
||||
listProps,
|
||||
...props
|
||||
}: {
|
||||
linkId?: string;
|
||||
teamId?: string;
|
||||
isCollapsed?: boolean;
|
||||
} & SelectProps) {
|
||||
const { t, messages } = useMessages();
|
||||
const { data: link } = useLinkQuery(linkId);
|
||||
const [name, setName] = useState<string>(link?.name);
|
||||
const [search, setSearch] = useState('');
|
||||
const { data, isLoading } = useLinksQuery({ teamId }, { search, pageSize: 20 });
|
||||
const listItems: { id: string; name: string }[] = data?.data || [];
|
||||
|
||||
useEffect(() => {
|
||||
setName(link?.name);
|
||||
}, [link?.name]);
|
||||
|
||||
const handleOpenChange = () => {
|
||||
setSearch('');
|
||||
};
|
||||
|
||||
const handleChange = (id: string) => {
|
||||
setName(listItems.find(item => item.id === id)?.name);
|
||||
onChange?.(id);
|
||||
};
|
||||
|
||||
const renderValue = () => {
|
||||
if (isCollapsed) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return (
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<Link />
|
||||
</Icon>
|
||||
<Text truncate>{name}</Text>
|
||||
</Row>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Select
|
||||
{...props}
|
||||
value={linkId}
|
||||
isLoading={isLoading}
|
||||
allowSearch={true}
|
||||
searchValue={search}
|
||||
onSearch={setSearch}
|
||||
onChange={handleChange}
|
||||
onOpenChange={handleOpenChange}
|
||||
renderValue={renderValue}
|
||||
buttonProps={{
|
||||
...buttonProps,
|
||||
style: {
|
||||
minHeight: 40,
|
||||
gap: 0,
|
||||
justifyContent: isCollapsed ? 'start' : undefined,
|
||||
...buttonProps?.style,
|
||||
},
|
||||
}}
|
||||
listProps={{
|
||||
...listProps,
|
||||
renderEmptyState:
|
||||
listProps?.renderEmptyState || (() => <Empty message={t(messages.noResultsFound)} />),
|
||||
style: {
|
||||
maxHeight: 'calc(42vh - 65px)',
|
||||
width: 280,
|
||||
...listProps?.style,
|
||||
},
|
||||
}}
|
||||
>
|
||||
{listItems.map(({ id, name }) => (
|
||||
<ListItem key={id} id={id}>
|
||||
{name}
|
||||
</ListItem>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ export interface LookupFieldProps extends ComboBoxProps {
|
||||
}
|
||||
|
||||
export function LookupField({ websiteId, type, value, onChange, ...props }: LookupFieldProps) {
|
||||
const { formatMessage, messages } = useMessages();
|
||||
const { t, messages } = useMessages();
|
||||
const [search, setSearch] = useState(value);
|
||||
const searchValue = useDebounce(search, 300);
|
||||
const startDate = subMonths(endOfDay(new Date()), 6);
|
||||
@@ -51,7 +51,7 @@ export function LookupField({ websiteId, type, value, onChange, ...props }: Look
|
||||
isLoading ? (
|
||||
<Loading placement="center" icon="dots" />
|
||||
) : (
|
||||
<Empty message={formatMessage(messages.noResultsFound)} />
|
||||
<Empty message={t(messages.noResultsFound)} />
|
||||
)
|
||||
}
|
||||
>
|
||||
|
||||
@@ -10,7 +10,7 @@ export function MobileMenuButton(props: DialogProps) {
|
||||
</Icon>
|
||||
</Button>
|
||||
<Modal placement="left" offset="80px">
|
||||
<Dialog variant="sheet" {...props} />
|
||||
<Dialog variant="sheet" {...props} style={{ width: 'auto' }} />
|
||||
</Modal>
|
||||
</DialogTrigger>
|
||||
);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {
|
||||
Column,
|
||||
Icon,
|
||||
IconLabel,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuSection,
|
||||
@@ -15,26 +14,11 @@ import {
|
||||
} from '@umami/react-zen';
|
||||
import { ArrowRight } from 'lucide-react';
|
||||
import type { Key } from 'react';
|
||||
import {
|
||||
useConfig,
|
||||
useLoginQuery,
|
||||
useMessages,
|
||||
useMobile,
|
||||
useNavigation,
|
||||
} from '@/components/hooks';
|
||||
import {
|
||||
BookText,
|
||||
ChevronRight,
|
||||
ExternalLink,
|
||||
LifeBuoy,
|
||||
LockKeyhole,
|
||||
LogOut,
|
||||
Settings,
|
||||
User,
|
||||
Users,
|
||||
} from '@/components/icons';
|
||||
import { IconLabel } from '@/components/common/IconLabel';
|
||||
import { useLoginQuery, useMessages, useMobile, useNavigation } from '@/components/hooks';
|
||||
import { ChevronRight, User, Users } from '@/components/icons';
|
||||
import { Switch } from '@/components/svg';
|
||||
import { DOCS_URL, LAST_TEAM_CONFIG } from '@/lib/constants';
|
||||
import { LAST_TEAM_CONFIG } from '@/lib/constants';
|
||||
import { removeItem } from '@/lib/storage';
|
||||
|
||||
export interface TeamsButtonProps {
|
||||
@@ -44,13 +28,13 @@ export interface TeamsButtonProps {
|
||||
|
||||
export function NavButton({ showText = true }: TeamsButtonProps) {
|
||||
const { user } = useLoginQuery();
|
||||
const { cloudMode } = useConfig();
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { teamId, router } = useNavigation();
|
||||
const { isMobile } = useMobile();
|
||||
const team = user?.teams?.find(({ id }) => id === teamId);
|
||||
const selectedKeys = new Set([teamId || 'user']);
|
||||
const label = teamId ? team?.name : user.username;
|
||||
const cloudMode = !!process.env.cloudMode;
|
||||
|
||||
const getUrl = (url: string) => {
|
||||
return cloudMode ? `${process.env.cloudUrl}${url}` : url;
|
||||
@@ -77,8 +61,8 @@ export function NavButton({ showText = true }: TeamsButtonProps) {
|
||||
padding
|
||||
border
|
||||
borderRadius
|
||||
shadow="1"
|
||||
maxHeight="40px"
|
||||
shadow="sm"
|
||||
minHeight="40px"
|
||||
role="button"
|
||||
style={{ cursor: 'pointer', textWrap: 'nowrap', overflow: 'hidden', outline: 'none' }}
|
||||
>
|
||||
@@ -98,18 +82,18 @@ export function NavButton({ showText = true }: TeamsButtonProps) {
|
||||
<Menu autoFocus="last">
|
||||
<SubmenuTrigger>
|
||||
<MenuItem id="teams" showChecked={false} showSubMenuIcon>
|
||||
<IconLabel icon={<Switch />} label={formatMessage(labels.switchAccount)} />
|
||||
<IconLabel icon={<Switch />} label={t(labels.switchAccount)} />
|
||||
</MenuItem>
|
||||
<Popover placement={isMobile ? 'bottom start' : 'right top'}>
|
||||
<Column minWidth="300px">
|
||||
<Menu selectionMode="single" selectedKeys={selectedKeys} onAction={handleAction}>
|
||||
<MenuSection title={formatMessage(labels.myAccount)}>
|
||||
<MenuSection title={t(labels.myAccount)}>
|
||||
<MenuItem id="user">
|
||||
<IconLabel icon={<User />} label={user.username} />
|
||||
</MenuItem>
|
||||
</MenuSection>
|
||||
<MenuSeparator />
|
||||
<MenuSection title={formatMessage(labels.teams)}>
|
||||
<MenuSection title={t(labels.teams)}>
|
||||
{user?.teams?.map(({ id, name }) => (
|
||||
<MenuItem key={id} id={id} href={getUrl(`/teams/${id}`)}>
|
||||
<IconLabel icon={<Users />}>
|
||||
@@ -134,52 +118,6 @@ export function NavButton({ showText = true }: TeamsButtonProps) {
|
||||
</Column>
|
||||
</Popover>
|
||||
</SubmenuTrigger>
|
||||
<MenuSeparator />
|
||||
<MenuItem
|
||||
id="settings"
|
||||
href={getUrl('/settings')}
|
||||
icon={<Settings />}
|
||||
label={formatMessage(labels.settings)}
|
||||
/>
|
||||
{cloudMode && (
|
||||
<>
|
||||
<MenuItem
|
||||
id="docs"
|
||||
href={DOCS_URL}
|
||||
target="_blank"
|
||||
icon={<BookText />}
|
||||
label={formatMessage(labels.documentation)}
|
||||
>
|
||||
<Icon color="muted">
|
||||
<ExternalLink />
|
||||
</Icon>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
id="support"
|
||||
href={getUrl('/settings/support')}
|
||||
icon={<LifeBuoy />}
|
||||
label={formatMessage(labels.support)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{!cloudMode && user.isAdmin && (
|
||||
<>
|
||||
<MenuSeparator />
|
||||
<MenuItem
|
||||
id="/admin"
|
||||
href="/admin"
|
||||
icon={<LockKeyhole />}
|
||||
label={formatMessage(labels.admin)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<MenuSeparator />
|
||||
<MenuItem
|
||||
id="logout"
|
||||
href={getUrl('/logout')}
|
||||
icon={<LogOut />}
|
||||
label={formatMessage(labels.logout)}
|
||||
/>
|
||||
</Menu>
|
||||
</Column>
|
||||
</Popover>
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import { Icon, ListItem, Row, Select, type SelectProps, Text } from '@umami/react-zen';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { useMessages, usePixelQuery, usePixelsQuery } from '@/components/hooks';
|
||||
import { Grid2x2 } from '@/components/icons';
|
||||
|
||||
export function PixelSelect({
|
||||
pixelId,
|
||||
teamId,
|
||||
onChange,
|
||||
isCollapsed,
|
||||
buttonProps,
|
||||
listProps,
|
||||
...props
|
||||
}: {
|
||||
pixelId?: string;
|
||||
teamId?: string;
|
||||
isCollapsed?: boolean;
|
||||
} & SelectProps) {
|
||||
const { t, messages } = useMessages();
|
||||
const { data: pixel } = usePixelQuery(pixelId);
|
||||
const [name, setName] = useState<string>(pixel?.name);
|
||||
const [search, setSearch] = useState('');
|
||||
const { data, isLoading } = usePixelsQuery({ teamId }, { search, pageSize: 20 });
|
||||
const listItems: { id: string; name: string }[] = data?.data || [];
|
||||
|
||||
useEffect(() => {
|
||||
setName(pixel?.name);
|
||||
}, [pixel?.name]);
|
||||
|
||||
const handleOpenChange = () => {
|
||||
setSearch('');
|
||||
};
|
||||
|
||||
const handleChange = (id: string) => {
|
||||
setName(listItems.find(item => item.id === id)?.name);
|
||||
onChange?.(id);
|
||||
};
|
||||
|
||||
const renderValue = () => {
|
||||
if (isCollapsed) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return (
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<Grid2x2 />
|
||||
</Icon>
|
||||
<Text truncate>{name}</Text>
|
||||
</Row>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Select
|
||||
{...props}
|
||||
value={pixelId}
|
||||
isLoading={isLoading}
|
||||
allowSearch={true}
|
||||
searchValue={search}
|
||||
onSearch={setSearch}
|
||||
onChange={handleChange}
|
||||
onOpenChange={handleOpenChange}
|
||||
renderValue={renderValue}
|
||||
buttonProps={{
|
||||
...buttonProps,
|
||||
style: {
|
||||
minHeight: 40,
|
||||
gap: 0,
|
||||
justifyContent: isCollapsed ? 'start' : undefined,
|
||||
...buttonProps?.style,
|
||||
},
|
||||
}}
|
||||
listProps={{
|
||||
...listProps,
|
||||
renderEmptyState:
|
||||
listProps?.renderEmptyState || (() => <Empty message={t(messages.noResultsFound)} />),
|
||||
style: {
|
||||
maxHeight: 'calc(42vh - 65px)',
|
||||
width: 280,
|
||||
...listProps?.style,
|
||||
},
|
||||
}}
|
||||
>
|
||||
{listItems.map(({ id, name }) => (
|
||||
<ListItem key={id} id={id}>
|
||||
{name}
|
||||
</ListItem>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import { useMessages } from '@/components/hooks';
|
||||
import { Settings } from '@/components/icons';
|
||||
|
||||
export function PreferencesButton() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<DialogTrigger>
|
||||
@@ -18,11 +18,11 @@ export function PreferencesButton() {
|
||||
<Popover placement="bottom end">
|
||||
<Panel gap="3">
|
||||
<Column>
|
||||
<Label>{formatMessage(labels.timezone)}</Label>
|
||||
<Label>{t(labels.timezone)}</Label>
|
||||
<TimezoneSetting />
|
||||
</Column>
|
||||
<Column>
|
||||
<Label>{formatMessage(labels.defaultDateRange)}</Label>
|
||||
<Label>{t(labels.defaultDateRange)}</Label>
|
||||
<DateRangeSetting />
|
||||
</Column>
|
||||
</Panel>
|
||||
|
||||
@@ -15,27 +15,27 @@ import { useLoginQuery, useMessages, useNavigation } from '@/components/hooks';
|
||||
import { LockKeyhole, LogOut, UserCircle } from '@/components/icons';
|
||||
|
||||
export function ProfileButton() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { user } = useLoginQuery();
|
||||
const { renderUrl } = useNavigation();
|
||||
|
||||
const items = [
|
||||
{
|
||||
id: 'settings',
|
||||
label: formatMessage(labels.profile),
|
||||
label: t(labels.profile),
|
||||
path: renderUrl('/settings/profile'),
|
||||
icon: <UserCircle />,
|
||||
},
|
||||
user.isAdmin &&
|
||||
!process.env.cloudMode && {
|
||||
id: 'admin',
|
||||
label: formatMessage(labels.admin),
|
||||
label: t(labels.admin),
|
||||
path: '/admin',
|
||||
icon: <LockKeyhole />,
|
||||
},
|
||||
{
|
||||
id: 'logout',
|
||||
label: formatMessage(labels.logout),
|
||||
label: t(labels.logout),
|
||||
path: '/logout',
|
||||
icon: <LogOut />,
|
||||
separator: true,
|
||||
|
||||
@@ -10,7 +10,7 @@ export function RefreshButton({
|
||||
websiteId: string;
|
||||
isLoading?: boolean;
|
||||
}) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { dateRange } = useDateRange();
|
||||
|
||||
function handleClick() {
|
||||
@@ -26,7 +26,7 @@ export function RefreshButton({
|
||||
<RefreshCw />
|
||||
</Icon>
|
||||
</LoadingButton>
|
||||
<Tooltip>{formatMessage(labels.refresh)}</Tooltip>
|
||||
<Tooltip>{t(labels.refresh)}</Tooltip>
|
||||
</TooltipTrigger>
|
||||
);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ export function ReportEditButton({
|
||||
onDelete?: () => void;
|
||||
children: ({ close }: { close: () => void }) => ReactNode;
|
||||
}) {
|
||||
const { formatMessage, labels, messages } = useMessages();
|
||||
const { t, labels, messages } = useMessages();
|
||||
const [showEdit, setShowEdit] = useState(false);
|
||||
const [showDelete, setShowDelete] = useState(false);
|
||||
const { mutateAsync, touch } = useDeleteQuery(`/reports/${id}`);
|
||||
@@ -70,13 +70,13 @@ export function ReportEditButton({
|
||||
<Icon>
|
||||
<Edit />
|
||||
</Icon>
|
||||
<Text>{formatMessage(labels.edit)}</Text>
|
||||
<Text>{t(labels.edit)}</Text>
|
||||
</MenuItem>
|
||||
<MenuItem id="delete">
|
||||
<Icon>
|
||||
<Trash />
|
||||
</Icon>
|
||||
<Text>{formatMessage(labels.delete)}</Text>
|
||||
<Text>{t(labels.delete)}</Text>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</Popover>
|
||||
@@ -85,12 +85,12 @@ export function ReportEditButton({
|
||||
{showEdit && children({ close: handleClose })}
|
||||
{showDelete && (
|
||||
<AlertDialog
|
||||
title={formatMessage(labels.delete)}
|
||||
title={t(labels.delete)}
|
||||
onConfirm={handleDelete}
|
||||
onCancel={handleClose}
|
||||
isDanger
|
||||
>
|
||||
<Row gap="1">{formatMessage(messages.confirmDelete, { target: name })}</Row>
|
||||
<Row gap="1">{t(messages.confirmDelete, { target: name })}</Row>
|
||||
</AlertDialog>
|
||||
)}
|
||||
</Modal>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { IconLabel, List, ListItem } from '@umami/react-zen';
|
||||
import { List, ListItem } from '@umami/react-zen';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { IconLabel } from '@/components/common/IconLabel';
|
||||
import { LoadingPanel } from '@/components/common/LoadingPanel';
|
||||
import { useWebsiteSegmentsQuery } from '@/components/hooks';
|
||||
import { ChartPie, UserPlus } from '@/components/icons';
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useMessages } from '@/components/hooks';
|
||||
import { Plus } from '@/components/icons';
|
||||
|
||||
export function SegmentSaveButton({ websiteId }: { websiteId: string }) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
|
||||
return (
|
||||
<DialogTrigger>
|
||||
@@ -12,10 +12,10 @@ export function SegmentSaveButton({ websiteId }: { websiteId: string }) {
|
||||
<Icon>
|
||||
<Plus />
|
||||
</Icon>
|
||||
<Text>{formatMessage(labels.segment)}</Text>
|
||||
<Text>{t(labels.segment)}</Text>
|
||||
</Button>
|
||||
<Modal>
|
||||
<Dialog title={formatMessage(labels.segment)} style={{ width: 800 }}>
|
||||
<Dialog title={t(labels.segment)} style={{ width: 800 }}>
|
||||
{({ close }) => {
|
||||
return <SegmentEditForm websiteId={websiteId} onClose={close} />;
|
||||
}}
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
import { DOCS_URL } from '@/lib/constants';
|
||||
|
||||
export function SettingsButton() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const { user } = useLoginQuery();
|
||||
const { router } = useNavigation();
|
||||
const { cloudMode } = useConfig();
|
||||
@@ -52,30 +52,22 @@ export function SettingsButton() {
|
||||
<Menu autoFocus="last" onAction={handleAction}>
|
||||
<MenuSection title={user.username}>
|
||||
<MenuSeparator />
|
||||
<MenuItem id="/settings" icon={<Settings />} label={formatMessage(labels.settings)} />
|
||||
<MenuItem id="/settings" icon={<Settings />} label={t(labels.settings)} />
|
||||
{!cloudMode && user.isAdmin && (
|
||||
<MenuItem id="/admin" icon={<LockKeyhole />} label={formatMessage(labels.admin)} />
|
||||
<MenuItem id="/admin" icon={<LockKeyhole />} label={t(labels.admin)} />
|
||||
)}
|
||||
{cloudMode && (
|
||||
<>
|
||||
<MenuItem
|
||||
id="/docs"
|
||||
icon={<BookText />}
|
||||
label={formatMessage(labels.documentation)}
|
||||
>
|
||||
<MenuItem id="/docs" icon={<BookText />} label={t(labels.documentation)}>
|
||||
<Icon color="muted">
|
||||
<ExternalLink />
|
||||
</Icon>
|
||||
</MenuItem>
|
||||
<MenuItem
|
||||
id="/settings/support"
|
||||
icon={<LifeBuoy />}
|
||||
label={formatMessage(labels.support)}
|
||||
/>
|
||||
<MenuItem id="/settings/support" icon={<LifeBuoy />} label={t(labels.support)} />
|
||||
</>
|
||||
)}
|
||||
<MenuSeparator />
|
||||
<MenuItem id="/logout" icon={<LogOut />} label={formatMessage(labels.logout)} />
|
||||
<MenuItem id="/logout" icon={<LogOut />} label={t(labels.logout)} />
|
||||
</MenuSection>
|
||||
</Menu>
|
||||
</Popover>
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
import {
|
||||
Button,
|
||||
Column,
|
||||
Icon,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuSection,
|
||||
MenuSeparator,
|
||||
MenuTrigger,
|
||||
Popover,
|
||||
Row,
|
||||
Text,
|
||||
} from '@umami/react-zen';
|
||||
import { ArrowRight } from 'lucide-react';
|
||||
import type { Key } from 'react';
|
||||
import { IconLabel } from '@/components/common/IconLabel';
|
||||
import { useLoginQuery, useMessages, useMobile, useNavigation } from '@/components/hooks';
|
||||
import { ChevronRight, User, Users } from '@/components/icons';
|
||||
import { LAST_TEAM_CONFIG } from '@/lib/constants';
|
||||
import { removeItem } from '@/lib/storage';
|
||||
|
||||
export function TeamsButton() {
|
||||
const { user } = useLoginQuery();
|
||||
const { t, labels } = useMessages();
|
||||
const { teamId, router } = useNavigation();
|
||||
const { isPhone } = useMobile();
|
||||
const team = user?.teams?.find(({ id }) => id === teamId);
|
||||
const selectedKeys = new Set([teamId || 'user']);
|
||||
const label = teamId ? team?.name : user.username;
|
||||
|
||||
const cloudMode = !!process.env.cloudMode;
|
||||
|
||||
const getUrl = (url: string) => {
|
||||
return cloudMode ? `${process.env.cloudUrl}${url}` : url;
|
||||
};
|
||||
|
||||
const handleAction = async (key: Key) => {
|
||||
if (key === 'user') {
|
||||
removeItem(LAST_TEAM_CONFIG);
|
||||
if (cloudMode) {
|
||||
window.location.href = '/';
|
||||
} else {
|
||||
router.push('/');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<MenuTrigger>
|
||||
<Button variant="quiet">
|
||||
<Row
|
||||
alignItems="center"
|
||||
position="relative"
|
||||
gap
|
||||
maxHeight="40px"
|
||||
minWidth={isPhone ? '100px' : '200px'}
|
||||
maxWidth="200px"
|
||||
>
|
||||
<Icon>{teamId ? <Users /> : <User />}</Icon>
|
||||
<Text truncate>{label}</Text>
|
||||
</Row>
|
||||
<Icon rotate={90} size="sm">
|
||||
<ChevronRight />
|
||||
</Icon>
|
||||
</Button>
|
||||
<Popover placement="bottom start">
|
||||
<Column minWidth="300px">
|
||||
<Menu selectionMode="single" selectedKeys={selectedKeys} onAction={handleAction}>
|
||||
<MenuSection title={t(labels.myAccount)}>
|
||||
<MenuItem id="user">
|
||||
<IconLabel icon={<User />} label={user.username} />
|
||||
</MenuItem>
|
||||
</MenuSection>
|
||||
<MenuSeparator />
|
||||
<MenuSection title={t(labels.teams)}>
|
||||
{user?.teams?.map(({ id, name }) => (
|
||||
<MenuItem key={id} id={id} href={getUrl(`/teams/${id}`)}>
|
||||
<IconLabel icon={<Users />}>
|
||||
<Text wrap="nowrap">{name}</Text>
|
||||
</IconLabel>
|
||||
</MenuItem>
|
||||
))}
|
||||
<MenuSeparator />
|
||||
<MenuItem id="manage-teams">
|
||||
<a href="/settings/teams" style={{ width: '100%' }}>
|
||||
<Row alignItems="center" justifyContent="space-between" gap>
|
||||
<Text align="center">Manage teams</Text>
|
||||
<Icon>
|
||||
<ArrowRight />
|
||||
</Icon>
|
||||
</Row>
|
||||
</a>
|
||||
</MenuItem>
|
||||
</MenuSection>
|
||||
</Menu>
|
||||
</Column>
|
||||
</Popover>
|
||||
</MenuTrigger>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import { ListItem, Row, Select } from '@umami/react-zen';
|
||||
import { useMessages, useNavigation } from '@/components/hooks';
|
||||
import { DATE_RANGE_CONFIG, DEFAULT_DATE_RANGE_VALUE } from '@/lib/constants';
|
||||
import { getItem } from '@/lib/storage';
|
||||
|
||||
export function UnitFilter() {
|
||||
const { t, labels } = useMessages();
|
||||
const { router, query, updateParams } = useNavigation();
|
||||
|
||||
const DATE_RANGE_UNIT_CONFIG = {
|
||||
'0week': {
|
||||
defaultUnit: 'day',
|
||||
availableUnits: ['day', 'hour'],
|
||||
},
|
||||
'7day': {
|
||||
defaultUnit: 'day',
|
||||
availableUnits: ['day', 'hour'],
|
||||
},
|
||||
'0month': {
|
||||
defaultUnit: 'day',
|
||||
availableUnits: ['day', 'hour'],
|
||||
},
|
||||
'30day': {
|
||||
defaultUnit: 'day',
|
||||
availableUnits: ['day', 'hour'],
|
||||
},
|
||||
'90day': {
|
||||
defaultUnit: 'day',
|
||||
availableUnits: ['day', 'month'],
|
||||
},
|
||||
'6month': {
|
||||
defaultUnit: 'month',
|
||||
availableUnits: ['month', 'day'],
|
||||
},
|
||||
};
|
||||
|
||||
const unitConfig =
|
||||
DATE_RANGE_UNIT_CONFIG[query.date || getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE_VALUE];
|
||||
|
||||
if (!unitConfig) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleChange = (value: string) => {
|
||||
router.push(updateParams({ unit: value }));
|
||||
};
|
||||
|
||||
const options = unitConfig.availableUnits.map(unit => ({
|
||||
id: unit,
|
||||
label: t(labels[unit]),
|
||||
}));
|
||||
|
||||
const selectedUnit = query.unit ?? unitConfig.defaultUnit;
|
||||
|
||||
return (
|
||||
<Row>
|
||||
<Select
|
||||
value={selectedUnit}
|
||||
onChange={handleChange}
|
||||
popoverProps={{ placement: 'bottom right' }}
|
||||
style={{ width: 100 }}
|
||||
>
|
||||
{options.map(({ id, label }) => (
|
||||
<ListItem key={id} id={id}>
|
||||
{label}
|
||||
</ListItem>
|
||||
))}
|
||||
</Select>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
import {
|
||||
Column,
|
||||
Icon,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuSeparator,
|
||||
MenuTrigger,
|
||||
Popover,
|
||||
Pressable,
|
||||
Row,
|
||||
SubmenuTrigger,
|
||||
Text,
|
||||
Tooltip,
|
||||
TooltipTrigger,
|
||||
useTheme,
|
||||
} from '@umami/react-zen';
|
||||
import { useConfig, useLocale, useLoginQuery, useMessages, useMobile } from '@/components/hooks';
|
||||
import {
|
||||
BookText,
|
||||
ExternalLink,
|
||||
Globe,
|
||||
LifeBuoy,
|
||||
LockKeyhole,
|
||||
LogOut,
|
||||
Moon,
|
||||
Settings,
|
||||
Sun,
|
||||
SunMoon,
|
||||
UserCircle,
|
||||
} from '@/components/icons';
|
||||
import { DOCS_URL } from '@/lib/constants';
|
||||
import { languages } from '@/lib/lang';
|
||||
|
||||
export interface UserButtonProps {
|
||||
showText?: boolean;
|
||||
onClose?: () => void;
|
||||
}
|
||||
|
||||
export function UserButton({ showText = true, onClose }: UserButtonProps) {
|
||||
const { user } = useLoginQuery();
|
||||
const { cloudMode } = useConfig();
|
||||
const { t, labels } = useMessages();
|
||||
const { locale, saveLocale } = useLocale();
|
||||
const { theme, setTheme } = useTheme();
|
||||
const { isMobile } = useMobile();
|
||||
|
||||
const getUrl = (url: string) => {
|
||||
return cloudMode ? `${process.env.cloudUrl}${url}` : url;
|
||||
};
|
||||
|
||||
const languageItems = Object.keys(languages).map(key => ({
|
||||
value: key,
|
||||
label: languages[key].label,
|
||||
}));
|
||||
|
||||
const items = [
|
||||
cloudMode && {
|
||||
id: 'docs',
|
||||
label: t(labels.documentation),
|
||||
path: DOCS_URL,
|
||||
icon: <BookText />,
|
||||
target: '_blank',
|
||||
external: true,
|
||||
},
|
||||
cloudMode && {
|
||||
id: 'support',
|
||||
label: t(labels.support),
|
||||
path: getUrl('/settings/support'),
|
||||
icon: <LifeBuoy />,
|
||||
},
|
||||
!cloudMode &&
|
||||
user.isAdmin && {
|
||||
id: 'admin',
|
||||
label: t(labels.admin),
|
||||
path: '/admin',
|
||||
icon: <LockKeyhole />,
|
||||
},
|
||||
{
|
||||
id: 'separator',
|
||||
separator: true,
|
||||
},
|
||||
{
|
||||
id: 'logout',
|
||||
label: t(labels.logout),
|
||||
path: getUrl('/logout'),
|
||||
icon: <LogOut />,
|
||||
},
|
||||
].filter(Boolean);
|
||||
|
||||
return (
|
||||
<MenuTrigger>
|
||||
<TooltipTrigger isDisabled={showText} delay={0}>
|
||||
<Pressable>
|
||||
<Row
|
||||
alignItems="center"
|
||||
flexGrow={1}
|
||||
hover={{ backgroundColor: 'surface-sunken' }}
|
||||
borderRadius
|
||||
minHeight="40px"
|
||||
role="button"
|
||||
style={{ cursor: 'pointer', textWrap: 'nowrap', overflow: 'hidden', outline: 'none' }}
|
||||
>
|
||||
<Row alignItems="center" gap padding>
|
||||
<Icon>
|
||||
<UserCircle />
|
||||
</Icon>
|
||||
{showText && <Text>{user.username}</Text>}
|
||||
</Row>
|
||||
</Row>
|
||||
</Pressable>
|
||||
<Tooltip placement="right">{user.username}</Tooltip>
|
||||
</TooltipTrigger>
|
||||
<Popover placement="top start">
|
||||
<Column minWidth="200px">
|
||||
<Menu autoFocus="last" onAction={onClose}>
|
||||
<MenuItem id="settings" href={getUrl('/settings')}>
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<Settings />
|
||||
</Icon>
|
||||
<Text>{t(labels.settings)}</Text>
|
||||
</Row>
|
||||
</MenuItem>
|
||||
<SubmenuTrigger>
|
||||
<MenuItem id="language" showSubMenuIcon>
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<Globe />
|
||||
</Icon>
|
||||
<Text>{t(labels.language)}</Text>
|
||||
</Row>
|
||||
</MenuItem>
|
||||
<Popover placement={isMobile ? 'bottom start' : 'right bottom'} isNonModal>
|
||||
<Menu
|
||||
selectionMode="single"
|
||||
selectedKeys={new Set([locale])}
|
||||
onAction={key => saveLocale(key as string)}
|
||||
style={{ maxHeight: 300, overflow: 'auto' }}
|
||||
>
|
||||
{languageItems.map(({ value, label }) => (
|
||||
<MenuItem key={value} id={value}>
|
||||
<Text weight={value === locale ? 'bold' : undefined}>{label}</Text>
|
||||
</MenuItem>
|
||||
))}
|
||||
</Menu>
|
||||
</Popover>
|
||||
</SubmenuTrigger>
|
||||
<SubmenuTrigger>
|
||||
<MenuItem id="theme" showSubMenuIcon>
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<SunMoon />
|
||||
</Icon>
|
||||
<Text>{t(labels.theme)}</Text>
|
||||
</Row>
|
||||
</MenuItem>
|
||||
<Popover placement={isMobile ? 'bottom start' : 'right bottom'} isNonModal>
|
||||
<Menu
|
||||
selectionMode="single"
|
||||
selectedKeys={new Set([theme])}
|
||||
onAction={key => setTheme(key as 'light' | 'dark')}
|
||||
>
|
||||
<MenuItem id="light">
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<Sun />
|
||||
</Icon>
|
||||
<Text>Light</Text>
|
||||
</Row>
|
||||
</MenuItem>
|
||||
<MenuItem id="dark">
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<Moon />
|
||||
</Icon>
|
||||
<Text>Dark</Text>
|
||||
</Row>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
</Popover>
|
||||
</SubmenuTrigger>
|
||||
{items.map(({ id, path, label, icon, separator, target, external }: any) => {
|
||||
if (separator) {
|
||||
return <MenuSeparator key={id} />;
|
||||
}
|
||||
return (
|
||||
<MenuItem key={id} id={id} href={path} target={target}>
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>{icon}</Icon>
|
||||
<Text>{label}</Text>
|
||||
{external && (
|
||||
<Icon color="muted" size="sm">
|
||||
<ExternalLink />
|
||||
</Icon>
|
||||
)}
|
||||
</Row>
|
||||
</MenuItem>
|
||||
);
|
||||
})}
|
||||
</Menu>
|
||||
</Column>
|
||||
</Popover>
|
||||
</MenuTrigger>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { ListItem, Select, type SelectProps } from '@umami/react-zen';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { useMessages, useTeamMembersQuery, useUsersQuery } from '@/components/hooks';
|
||||
|
||||
export function UserSelect({
|
||||
teamId,
|
||||
onChange,
|
||||
...props
|
||||
}: {
|
||||
teamId?: string;
|
||||
} & SelectProps) {
|
||||
const { t, messages } = useMessages();
|
||||
const { data: users, isLoading: usersLoading } = useUsersQuery();
|
||||
const { data: teamMembers, isLoading: teamMembersLoading } = useTeamMembersQuery(teamId);
|
||||
const [username, setUsername] = useState<string>();
|
||||
const [search, setSearch] = useState('');
|
||||
|
||||
const listItems = useMemo(() => {
|
||||
if (!users) {
|
||||
return [];
|
||||
}
|
||||
if (!teamId || !teamMembers) {
|
||||
return users.data;
|
||||
}
|
||||
const teamMemberIds = teamMembers.data.map(({ userId }) => userId);
|
||||
return users.data.filter(({ id }) => !teamMemberIds.includes(id));
|
||||
}, [users, teamMembers, teamId]);
|
||||
|
||||
const handleSearch = (value: string) => {
|
||||
setSearch(value);
|
||||
};
|
||||
|
||||
const handleOpenChange = () => {
|
||||
setSearch('');
|
||||
};
|
||||
|
||||
const handleChange = (id: string) => {
|
||||
setUsername(listItems.find(item => item.id === id)?.username);
|
||||
onChange(id);
|
||||
};
|
||||
|
||||
return (
|
||||
<Select
|
||||
{...props}
|
||||
value={username}
|
||||
isLoading={usersLoading || (teamId && teamMembersLoading)}
|
||||
allowSearch={true}
|
||||
searchValue={search}
|
||||
onSearch={handleSearch}
|
||||
onChange={handleChange}
|
||||
onOpenChange={handleOpenChange}
|
||||
listProps={{
|
||||
renderEmptyState: () => <Empty message={t(messages.noResultsFound)} />,
|
||||
style: { maxHeight: 'calc(42vh - 65px)' },
|
||||
}}
|
||||
>
|
||||
{listItems.map(({ id, username }) => (
|
||||
<ListItem key={id} id={id}>
|
||||
{username}
|
||||
</ListItem>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
@@ -21,7 +21,7 @@ export function WebsiteDateFilter({
|
||||
allowCompare,
|
||||
}: WebsiteDateFilterProps) {
|
||||
const { dateRange, isAllTime, isCustomRange } = useDateRange();
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { t, labels } = useMessages();
|
||||
const {
|
||||
router,
|
||||
updateParams,
|
||||
@@ -31,17 +31,20 @@ export function WebsiteDateFilter({
|
||||
const showCompare = allowCompare && !isAllTime;
|
||||
|
||||
const websiteDateRange = useDateRangeQuery(websiteId);
|
||||
const { startDate, endDate } = websiteDateRange;
|
||||
const hasData = startDate && endDate;
|
||||
|
||||
const handleChange = (date: string) => {
|
||||
if (date === 'all') {
|
||||
if (date === 'all' && hasData) {
|
||||
router.push(
|
||||
updateParams({
|
||||
date: `${getDateRangeValue(websiteDateRange.startDate, websiteDateRange.endDate)}:all`,
|
||||
offset: undefined,
|
||||
page: 1,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
router.push(updateParams({ date, offset: undefined }));
|
||||
router.push(updateParams({ date, offset: undefined, unit: undefined, page: 1 }));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -74,14 +77,13 @@ export function WebsiteDateFilter({
|
||||
</Button>
|
||||
</Row>
|
||||
)}
|
||||
<Row minWidth="200px">
|
||||
<DateFilter
|
||||
value={dateValue}
|
||||
onChange={handleChange}
|
||||
showAllTime={showAllTime}
|
||||
renderDate={+offset !== 0}
|
||||
/>
|
||||
</Row>
|
||||
<DateFilter
|
||||
className="min-w-[200px]"
|
||||
value={dateValue}
|
||||
onChange={handleChange}
|
||||
showAllTime={hasData && showAllTime}
|
||||
renderDate={+offset !== 0}
|
||||
/>
|
||||
{showCompare && (
|
||||
<Row alignItems="center" gap>
|
||||
<Text weight="bold">VS</Text>
|
||||
@@ -89,10 +91,11 @@ export function WebsiteDateFilter({
|
||||
<Select
|
||||
value={compare}
|
||||
onChange={handleSelect}
|
||||
style={{ width: 200 }}
|
||||
popoverProps={{ style: { width: 200 } }}
|
||||
>
|
||||
<ListItem id="prev">{formatMessage(labels.previousPeriod)}</ListItem>
|
||||
<ListItem id="yoy">{formatMessage(labels.previousYear)}</ListItem>
|
||||
<ListItem id="prev">{t(labels.previousPeriod)}</ListItem>
|
||||
<ListItem id="yoy">{t(labels.previousYear)}</ListItem>
|
||||
</Select>
|
||||
</Row>
|
||||
</Row>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { useMessages, useNavigation } from '@/components/hooks';
|
||||
import { Checkbox, Row } from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { useFilters, useMessages, useNavigation } from '@/components/hooks';
|
||||
import { ListFilter } from '@/components/icons';
|
||||
import { DialogButton } from '@/components/input/DialogButton';
|
||||
import { FilterEditForm } from '@/components/input/FilterEditForm';
|
||||
@@ -11,21 +13,48 @@ export function WebsiteFilterButton({
|
||||
position?: 'bottom' | 'top' | 'left' | 'right';
|
||||
alignment?: 'end' | 'center' | 'start';
|
||||
}) {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { updateParams, router } = useNavigation();
|
||||
const { t, labels } = useMessages();
|
||||
const { updateParams, pathname, router, query } = useNavigation();
|
||||
const { filters: currentFilters } = useFilters();
|
||||
const [excludeBounce, setExcludeBounce] = useState(!!query.excludeBounce);
|
||||
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 cleared = Object.fromEntries(currentFilters.map(f => [f.name, undefined]));
|
||||
|
||||
const url = updateParams({ ...params, segment, cohort });
|
||||
const url = updateParams({
|
||||
...cleared,
|
||||
...params,
|
||||
segment,
|
||||
cohort,
|
||||
match,
|
||||
excludeBounce: excludeBounce ? 'true' : undefined,
|
||||
});
|
||||
|
||||
router.push(url);
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogButton icon={<ListFilter />} label={formatMessage(labels.filter)} variant="outline">
|
||||
<DialogButton icon={<ListFilter />} label={t(labels.filter)} variant="outline">
|
||||
{({ close }) => {
|
||||
return <FilterEditForm websiteId={websiteId} onChange={handleChange} onClose={close} />;
|
||||
return (
|
||||
<>
|
||||
{isOverview && (
|
||||
<Row position="absolute" top="30px" right="30px">
|
||||
<Checkbox
|
||||
value={excludeBounce ? 'true' : ''}
|
||||
onChange={setExcludeBounce}
|
||||
style={{ marginTop: '3px' }}
|
||||
>
|
||||
{t(labels.excludeBounce)}
|
||||
</Checkbox>
|
||||
</Row>
|
||||
)}
|
||||
<FilterEditForm websiteId={websiteId} onChange={handleChange} onClose={close} />
|
||||
</>
|
||||
);
|
||||
}}
|
||||
</DialogButton>
|
||||
);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ListItem, Row, Select, type SelectProps, Text } from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { Icon, ListItem, Row, Select, type SelectProps, Text } from '@umami/react-zen';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import {
|
||||
useLoginQuery,
|
||||
@@ -7,29 +7,38 @@ import {
|
||||
useUserWebsitesQuery,
|
||||
useWebsiteQuery,
|
||||
} from '@/components/hooks';
|
||||
import { Globe } from '@/components/icons';
|
||||
|
||||
export function WebsiteSelect({
|
||||
websiteId,
|
||||
teamId,
|
||||
onChange,
|
||||
includeTeams,
|
||||
isCollapsed,
|
||||
buttonProps,
|
||||
listProps,
|
||||
...props
|
||||
}: {
|
||||
websiteId?: string;
|
||||
teamId?: string;
|
||||
includeTeams?: boolean;
|
||||
isCollapsed?: boolean;
|
||||
} & SelectProps) {
|
||||
const { formatMessage, messages } = useMessages();
|
||||
const { t, labels, messages } = useMessages();
|
||||
const { data: website } = useWebsiteQuery(websiteId);
|
||||
const [name, setName] = useState<string>(website?.name);
|
||||
const [search, setSearch] = useState('');
|
||||
const { user } = useLoginQuery();
|
||||
const { data, isLoading } = useUserWebsitesQuery(
|
||||
{ userId: user?.id, teamId },
|
||||
{ search, pageSize: 10, includeTeams },
|
||||
{ search, pageSize: 20, includeTeams },
|
||||
);
|
||||
const listItems: { id: string; name: string }[] = data?.data || [];
|
||||
|
||||
useEffect(() => {
|
||||
setName(website?.name);
|
||||
}, [website?.name]);
|
||||
|
||||
const handleSearch = (value: string) => {
|
||||
setSearch(value);
|
||||
};
|
||||
@@ -44,9 +53,20 @@ export function WebsiteSelect({
|
||||
};
|
||||
|
||||
const renderValue = () => {
|
||||
if (isCollapsed) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const value = name || props.placeholder || t(labels.selectWebsite);
|
||||
|
||||
return (
|
||||
<Row maxWidth="160px">
|
||||
<Text truncate>{name}</Text>
|
||||
<Row alignItems="center" gap>
|
||||
<Icon>
|
||||
<Globe />
|
||||
</Icon>
|
||||
<Text truncate color={name ? undefined : 'muted'}>
|
||||
{value}
|
||||
</Text>
|
||||
</Row>
|
||||
);
|
||||
};
|
||||
@@ -54,7 +74,6 @@ export function WebsiteSelect({
|
||||
return (
|
||||
<Select
|
||||
{...props}
|
||||
items={listItems}
|
||||
value={websiteId}
|
||||
isLoading={isLoading}
|
||||
allowSearch={true}
|
||||
@@ -63,12 +82,31 @@ export function WebsiteSelect({
|
||||
onChange={handleChange}
|
||||
onOpenChange={handleOpenChange}
|
||||
renderValue={renderValue}
|
||||
buttonProps={{
|
||||
...buttonProps,
|
||||
style: {
|
||||
minHeight: 40,
|
||||
gap: 0,
|
||||
justifyContent: isCollapsed ? 'start' : undefined,
|
||||
...buttonProps?.style,
|
||||
},
|
||||
}}
|
||||
listProps={{
|
||||
renderEmptyState: () => <Empty message={formatMessage(messages.noResultsFound)} />,
|
||||
style: { maxHeight: '400px' },
|
||||
...listProps,
|
||||
renderEmptyState:
|
||||
listProps?.renderEmptyState || (() => <Empty message={t(messages.noResultsFound)} />),
|
||||
style: {
|
||||
maxHeight: 'calc(42vh - 65px)',
|
||||
width: 280,
|
||||
...listProps?.style,
|
||||
},
|
||||
}}
|
||||
>
|
||||
{({ id, name }: any) => <ListItem key={id}>{name}</ListItem>}
|
||||
{listItems.map(({ id, name }) => (
|
||||
<ListItem key={id} id={id}>
|
||||
{name}
|
||||
</ListItem>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user