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(filters): preserve commas in search values

Aditya1976622494e8
diff --git a/src/components/common/FilterRecord.test.tsx b/src/components/common/FilterRecord.test.tsx
new file mode 100644
index 000000000..d9e4dbb9b
--- /dev/null
+++ b/src/components/common/FilterRecord.test.tsx
@@ -0,0 +1,47 @@
+import { render, screen } from '@testing-library/react';
+import type { ReactNode } from 'react';
+import { expect, test, vi } from 'vitest';
+import { FilterRecord } from './FilterRecord';
+
+vi.mock('@umami/react-zen', () => ({
+ Button: ({ children }: { children: ReactNode }) => <button>{children}</button>,
+ Column: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+ Grid: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+ Icon: ({ children }: { children: ReactNode }) => <span>{children}</span>,
+ Label: ({ children }: { children: ReactNode }) => <label>{children}</label>,
+ ListItem: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+ Loading: () => <div>Loading</div>,
+ Select: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+ TextField: ({ value }: { value: string }) => (
+ <input aria-label="Filter value" value={value} readOnly />
+ ),
+}));
+
+vi.mock('@/components/common/Empty', () => ({ Empty: () => <div>Empty</div> }));
+vi.mock('@/components/common/MultiSelect', () => ({
+ MultiSelect: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+ MultiSelectItem: ({ children }: { children: ReactNode }) => <div>{children}</div>,
+}));
+vi.mock('@/components/hooks', () => ({
+ useFilters: () => ({ fields: [], operators: [] }),
+ useFormat: () => ({ formatValue: (value: string) => value }),
+ useWebsiteValuesQuery: () => ({ data: [], isLoading: false }),
+}));
+vi.mock('@/components/icons', () => ({ X: () => null }));
+
+test('keeps commas in regex filter values', () => {
+ const value = '^[a-zA-Z0-9]{21,22}$';
+
+ render(
+ <FilterRecord
+ type="path"
+ startDate={new Date('2026-08-01')}
+ endDate={new Date('2026-08-02')}
+ name="path"
+ operator="re"
+ value={value}
+ />,
+ );
+
+ expect(screen.getByLabelText('Filter value')).toHaveValue(value);
+});
diff --git a/src/components/common/FilterRecord.tsx b/src/components/common/FilterRecord.tsx
index d9b52f4bd..b689b76bc 100644
--- a/src/components/common/FilterRecord.tsx
+++ b/src/components/common/FilterRecord.tsx
@@ -42,7 +42,14 @@ export function FilterRecord({
onChange,
}: FilterRecordProps) {
const { fields, operators } = useFilters();
- const initValues = Array.isArray(value) ? value : value ? value.split(',') : [];
+ const isSearch = isSearchOperator(operator);
+ const initValues = Array.isArray(value)
+ ? value
+ : value
+ ? isSearch
+ ? [value]
+ : value.split(',')
+ : [];
const [selected, setSelected] = useState<string[]>(initValues);
const [search, setSearch] = useState('');
const { formatValue } = useFormat();
@@ -53,7 +60,6 @@ export function FilterRecord({
startDate,
endDate,
});
- const isSearch = isSearchOperator(operator);
const items = data?.filter(({ value }) => value) || [];
const handleSearch = (value: string) => {