Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Fix ComboBox/MultiSelect issues. Closes #4355

Francis Cao8b177f1a21f3
diff --git a/src/app/(main)/websites/[websiteId]/(reports)/funnels/EventDataFilterRow.tsx b/src/app/(main)/websites/[websiteId]/(reports)/funnels/EventDataFilterRow.tsx
index f970c62ff..6f673869b 100644
--- a/src/app/(main)/websites/[websiteId]/(reports)/funnels/EventDataFilterRow.tsx
+++ b/src/app/(main)/websites/[websiteId]/(reports)/funnels/EventDataFilterRow.tsx
@@ -1,7 +1,6 @@
import {
Button,
Column,
- ComboBox,
FormField,
Grid,
Icon,
@@ -12,6 +11,7 @@ import {
} from '@umami/react-zen';
import { endOfDay, subMonths } from 'date-fns';
import { useState } from 'react';
+import { ComboBox } from '@/components/common/ComboBox';
import { Empty } from '@/components/common/Empty';
import { useApi, useMessages, useMobile } from '@/components/hooks';
import { X } from '@/components/icons';
@@ -56,7 +56,7 @@ function PropertySelect({
enabled: !!websiteId,
});
- const properties = [...new Set(data?.map(d => d.propertyName) ?? [])];
+ const properties: string[] = Array.from(new Set<string>(data?.map(d => d.propertyName) ?? []));
return (
<ComboBox
@@ -118,7 +118,7 @@ function ValueSelect({
enabled: !!(websiteId && eventName && propertyName),
});
- const values = data?.map(d => d.value) ?? [];
+ const values: string[] = data?.map(d => d.value) ?? [];
return (
<ComboBox
diff --git a/src/app/(main)/websites/[websiteId]/events/EventProperties.tsx b/src/app/(main)/websites/[websiteId]/events/EventProperties.tsx
index 8328a19fc..26ca15a93 100644
--- a/src/app/(main)/websites/[websiteId]/events/EventProperties.tsx
+++ b/src/app/(main)/websites/[websiteId]/events/EventProperties.tsx
@@ -1,6 +1,7 @@
'use client';
-import { Column, ComboBox, Grid, Label, ListItem, Row, Select } from '@umami/react-zen';
+import { Column, Grid, Label, ListItem, Row, Select } from '@umami/react-zen';
import { useEffect, useMemo, useState } from 'react';
+import { ComboBox } from '@/components/common/ComboBox';
import { LoadingPanel } from '@/components/common/LoadingPanel';
import { Panel } from '@/components/common/Panel';
import { useEventDataPropertiesQuery, useMessages } from '@/components/hooks';
@@ -13,8 +14,22 @@ import { DATA_TYPE } from '@/lib/constants';
import type { PropertyFilter } from '@/lib/types';
import { EventDataPivotTable } from '../event-data/EventDataPivotTable';
+const MOCK_WEBSITE_ID = '86d4095c-a2a8-4fc8-9521-103e858e2b41';
+const mockEventNames = Array.from(
+ { length: 50 },
+ (_, index) =>
+ `mock-event-${index + 1}-with-a-long-name-for-dropdown-overflow-and-selection-testing`,
+);
+const selectValueStyle = {
+ display: 'block',
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap' as const,
+};
+
export function EventProperties({ websiteId }: { websiteId: string }) {
const [eventName, setEventName] = useState('');
+ const [eventSearch, setEventSearch] = useState('');
const [propertyName, setPropertyName] = useState('');
const [propertyFilters, setPropertyFilters] = useState<PropertyFilter[]>([]);
const { t, labels } = useMessages();
@@ -27,9 +42,14 @@ export function EventProperties({ websiteId }: { websiteId: string }) {
const { data, isLoading, isFetching, error } = useEventDataPropertiesQuery(websiteId);
const eventNames = useMemo<string[]>(() => {
- if (!data) return [];
- return [...new Set<string>(data.map((e: { eventName: string }) => e.eventName))];
- }, [data]);
+ const names = data ? [...new Set<string>(data.map((e: { eventName: string }) => e.eventName))] : [];
+
+ if (process.env.NODE_ENV !== 'development' || websiteId !== MOCK_WEBSITE_ID) {
+ return names;
+ }
+
+ return [...new Set([...names, ...mockEventNames])];
+ }, [data, websiteId]);
const properties = useMemo(() => {
if (!data || !eventName) return [];
@@ -52,12 +72,26 @@ export function EventProperties({ websiteId }: { websiteId: string }) {
);
}, [properties, propertyName]);
+ const filteredEventNames = useMemo(() => {
+ if (!eventSearch) {
+ return eventNames;
+ }
+
+ const normalizedSearch = eventSearch.toLowerCase();
+
+ return eventNames.filter(name => name.toLowerCase().includes(normalizedSearch));
+ }, [eventNames, eventSearch]);
+
const handleEventChange = (value: string) => {
setEventName(value);
setPropertyName('');
setPropertyFilters([]);
};
+ const handleEventOpenChange = () => {
+ setEventSearch('');
+ };
+
return (
<LoadingPanel
data={data}
@@ -87,10 +121,18 @@ export function EventProperties({ websiteId }: { websiteId: string }) {
<Select
value={eventName}
onChange={handleEventChange}
+ allowSearch
+ searchValue={eventSearch}
+ onSearch={setEventSearch}
+ onOpenChange={handleEventOpenChange}
placeholder={t(labels.selectEvent)}
- maxHeight={480}
+ maxHeight={400}
+ buttonProps={{ style: { minWidth: 0, maxWidth: '100%', overflow: 'hidden' } }}
+ renderValue={({ defaultChildren }) => (
+ <span style={selectValueStyle}>{defaultChildren}</span>
+ )}
>
- {eventNames.map(name => (
+ {filteredEventNames.map(name => (
<ListItem key={name} id={name}>
{name}
</ListItem>
diff --git a/src/app/(main)/websites/[websiteId]/sessions/SessionProperties.tsx b/src/app/(main)/websites/[websiteId]/sessions/SessionProperties.tsx
index 5e1a7009f..7c5e2bdfa 100644
--- a/src/app/(main)/websites/[websiteId]/sessions/SessionProperties.tsx
+++ b/src/app/(main)/websites/[websiteId]/sessions/SessionProperties.tsx
@@ -1,5 +1,6 @@
-import { Column, ComboBox, Grid, Label, ListItem, Row } from '@umami/react-zen';
+import { Column, Grid, Label, ListItem, Row } from '@umami/react-zen';
import { useMemo, useState } from 'react';
+import { ComboBox } from '@/components/common/ComboBox';
import { LoadingPanel } from '@/components/common/LoadingPanel';
import { Panel } from '@/components/common/Panel';
import {
diff --git a/src/components/common/ComboBox.tsx b/src/components/common/ComboBox.tsx
new file mode 100644
index 000000000..65de348a7
--- /dev/null
+++ b/src/components/common/ComboBox.tsx
@@ -0,0 +1,24 @@
+import { type ComboBoxProps, type ListProps, ComboBox as ZenComboBox } from '@umami/react-zen';
+
+const defaultListProps: Partial<ListProps> = {
+ shouldSelectOnPressUp: true,
+ shouldFocusOnHover: false,
+ style: {
+ maxHeight: 'min(400px, calc(100dvh - 8rem))',
+ },
+};
+
+export function ComboBox({ listProps, ...props }: ComboBoxProps) {
+ const mergedListProps: ListProps = {
+ ...defaultListProps,
+ ...listProps,
+ style: {
+ ...defaultListProps.style,
+ ...listProps?.style,
+ },
+ };
+
+ return <ZenComboBox {...props} listProps={mergedListProps} />;
+}
+
+export type { ComboBoxProps };
diff --git a/src/components/common/MultiSelect.tsx b/src/components/common/MultiSelect.tsx
index 21782d7ae..6fbb159c9 100644
--- a/src/components/common/MultiSelect.tsx
+++ b/src/components/common/MultiSelect.tsx
@@ -2,6 +2,10 @@ import { Button, Column, Icon, List, MenuTrigger, Popover, SearchField } from '@
import type { ReactNode } from 'react';
import { ChevronRight } from '@/components/icons';
+const listStyle = {
+ maxHeight: 'min(320px, calc(100dvh - 8rem))',
+};
+
interface MultiSelectProps {
value?: string[];
onChange?: (values: string[]) => void;
@@ -60,6 +64,9 @@ export function MultiSelect({
value={value}
onChange={onChange}
showCheckmark
+ shouldSelectOnPressUp
+ shouldFocusOnHover={false}
+ style={listStyle}
renderEmptyState={renderEmptyState}
>
{children}
diff --git a/src/components/input/LookupField.tsx b/src/components/input/LookupField.tsx
index ba17f18f4..4594066ce 100644
--- a/src/components/input/LookupField.tsx
+++ b/src/components/input/LookupField.tsx
@@ -1,4 +1,5 @@
-import { ComboBox, type ComboBoxProps, ListItem, Loading, useDebounce } from '@umami/react-zen';
+import { type ComboBoxProps, ListItem, Loading, useDebounce } from '@umami/react-zen';
+import { ComboBox } from '@/components/common/ComboBox';
import { endOfDay, subMonths } from 'date-fns';
import { type SetStateAction, useMemo, useState } from 'react';
import { Empty } from '@/components/common/Empty';
diff --git a/src/components/property-data/PropertyFilterRecord.tsx b/src/components/property-data/PropertyFilterRecord.tsx
index 4e2b9c03f..45032dd39 100644
--- a/src/components/property-data/PropertyFilterRecord.tsx
+++ b/src/components/property-data/PropertyFilterRecord.tsx
@@ -3,7 +3,6 @@ import {
Button,
Calendar,
Column,
- ComboBox,
Dialog,
DialogTrigger,
Grid,
@@ -18,6 +17,7 @@ import {
} from '@umami/react-zen';
import { format, parseISO } from 'date-fns';
import { useState } from 'react';
+import { ComboBox } from '@/components/common/ComboBox';
import { DateDisplay } from '@/components/common/DateDisplay';
import { Empty } from '@/components/common/Empty';
import { MultiSelect } from '@/components/common/MultiSelect';