The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
feat: apply isMultiple again and add filters in Events page
Pedro Ladeira1230beb20163
diff --git a/packages/ui/src/filter/filter-list.tsx b/packages/ui/src/filter/filter-list.tsxindex 3f949f353a..964bf3f953 100644--- a/packages/ui/src/filter/filter-list.tsx+++ b/packages/ui/src/filter/filter-list.tsx@@ -9,16 +9,17 @@ import { useKeyboardShortcut } from "../hooks";import { Check, Icon } from "../icons";import { Popover } from "../popover";import { Tooltip } from "../tooltip";-import { Filter, FilterOption, ActiveFilter, FilterOperator } from "./types";+import { Filter, FilterOption, ActiveFilterInput, FilterOperator, normalizeActiveFilter } from "./types";type FilterListProps = {filters: Filter[];- activeFilters?: ActiveFilter[];+ activeFilters?: ActiveFilterInput[];onRemove: (key: string, value: FilterOption["value"]) => void;onRemoveFilter?: (key: string) => void;onRemoveAll: () => void;onSelect?: (key: string, value: FilterOption["value"] | FilterOption["value"][]) => void;onToggleOperator?: (key: string) => void;+ isMultiple?: boolean; // Enable multi-select features (operators, checkboxes, etc.)className?: string;};@@ -66,9 +67,12 @@ export function FilterList({onRemoveAll,onSelect,onToggleOperator,+ isMultiple = false,className,}: FilterListProps) {useKeyboardShortcut("Escape", onRemoveAll, { priority: 1 });+ const normalizedFilters = activeFilters?.map(normalizeActiveFilter) ?? [];+return (<AnimatedSizeContainerheight@@ -83,7 +87,7 @@ export function FilterList({><div className="flex grow flex-wrap gap-x-4 gap-y-2"><AnimatePresence>- {activeFilters?.map(({ key, values, operator }) => {+ {normalizedFilters.map(({ key, values, operator }) => {if (key === "loader") {return (<motion.div@@ -233,12 +237,13 @@ export function FilterList({onRemoveFilter={onRemoveFilter}onSelect={onSelect}onToggleOperator={onToggleOperator}+ isMultiple={isMultiple}/>);})}</AnimatePresence></div>- {activeFilters?.length !== 0 && (+ {normalizedFilters.length !== 0 && (<buttontype="button"className="group mt-px flex items-center gap-2 whitespace-nowrap rounded-lg border border-transparent px-3 py-2 text-sm text-neutral-500 ring-inset ring-neutral-500 transition-colors hover:border-neutral-200 hover:bg-white hover:text-black focus:outline-none"@@ -363,6 +368,7 @@ function OperatorFilterPill({onRemoveFilter,onSelect,onToggleOperator,+ isMultiple = false,}: {filterKey: string;filter: Filter;@@ -375,6 +381,7 @@ function OperatorFilterPill({onRemoveFilter?: (key: string) => void;onSelect?: (key: string, value: FilterOption["value"] | FilterOption["value"][]) => void;onToggleOperator?: (key: string) => void;+ isMultiple?: boolean;}) {const [operatorDropdownOpen, setOperatorDropdownOpen] = useState(false);const [valueDropdownOpen, setValueDropdownOpen] = useState(false);@@ -393,7 +400,9 @@ function OperatorFilterPill({} else {onSelect?.(filterKey, value);}- }, [filterKey, values, onSelect, onRemove]);++ if (!isMultiple) setValueDropdownOpen(false);+ }, [filterKey, values, onSelect, onRemove, isMultiple]);return (<motion.div@@ -412,52 +421,58 @@ function OperatorFilterPill({{filter.label}</div>- <Popover- openPopover={operatorDropdownOpen}- setOpenPopover={setOperatorDropdownOpen}- content={- <div className="w-32 p-1">- <button- type="button"- className={cn(- "flex w-full items-center rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-neutral-100",- !operator.includes("NOT") && "bg-neutral-50"- )}- onClick={() => {- if (operator.includes("NOT")) {- onToggleOperator?.(filterKey);- }- setOperatorDropdownOpen(false);- }}- >- is- </button>- <button- type="button"- className={cn(- "flex w-full items-center rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-neutral-100",- operator.includes("NOT") && "bg-neutral-50"- )}- onClick={() => {- if (!operator.includes("NOT")) {- onToggleOperator?.(filterKey);- }- setOperatorDropdownOpen(false);- }}- >- is not- </button>- </div>- }- align="center"- >- <button- type="button"- className="px-3 py-2 text-neutral-500 transition-colors hover:bg-neutral-50 hover:text-neutral-700"+ {isMultiple ? (+ <Popover+ openPopover={operatorDropdownOpen}+ setOpenPopover={setOperatorDropdownOpen}+ content={+ <div className="w-32 p-1">+ <button+ type="button"+ className={cn(+ "flex w-full items-center rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-neutral-100",+ !operator.includes("NOT") && "bg-neutral-50"+ )}+ onClick={() => {+ if (operator.includes("NOT")) {+ onToggleOperator?.(filterKey);+ }+ setOperatorDropdownOpen(false);+ }}+ >+ is+ </button>+ <button+ type="button"+ className={cn(+ "flex w-full items-center rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-neutral-100",+ operator.includes("NOT") && "bg-neutral-50"+ )}+ onClick={() => {+ if (!operator.includes("NOT")) {+ onToggleOperator?.(filterKey);+ }+ setOperatorDropdownOpen(false);+ }}+ >+ is not+ </button>+ </div>+ }+ align="center">- {getOperatorLabel(operator)}- </button>- </Popover>+ <button+ type="button"+ className="px-3 py-2 text-neutral-500 transition-colors hover:bg-neutral-50 hover:text-neutral-700"+ >+ {getOperatorLabel(operator)}+ </button>+ </Popover>+ ) : (+ <div className="px-3 py-2 text-neutral-500">+ is+ </div>+ )}<PopoveropenPopover={valueDropdownOpen}@@ -469,7 +484,7 @@ function OperatorFilterPill({}}}content={- <div onClick={(e) => e.stopPropagation()}>+ <div><AnimatedSizeContainerwidthheight@@ -540,18 +555,28 @@ function OperatorFilterPill({}}value={optionLabel + option.value}>- <div className={cn(- "flex h-4 w-4 items-center justify-center rounded border",- isSelected ? "border-neutral-900 bg-neutral-900" : "border-neutral-300"- )}>- {isSelected && <Check className="h-3 w-3 text-white" />}- </div>+ {isMultiple && (+ <div className={cn(+ "flex h-4 w-4 items-center justify-center rounded border",+ isSelected ? "border-neutral-900 bg-neutral-900" : "border-neutral-300"+ )}>+ {isSelected && <Check className="h-3 w-3 text-white" />}+ </div>+ )}<span className="shrink-0 text-neutral-600">{isReactNode(OptionIcon) ? OptionIcon : <OptionIcon className="h-4 w-4" />}</span><span className="flex-1">{truncate(optionLabel, 48)}</span><div className="ml-1 flex shrink-0 justify-end text-neutral-500">- {option.right}+ {isMultiple ? (+ option.right+ ) : (+ isSelected ? (+ <Check className="h-4 w-4" />+ ) : (+ option.right+ )+ )}</div></Command.Item>);@@ -561,7 +586,7 @@ function OperatorFilterPill({<>{selectedOptions.map(renderOption)}- {selectedOptions.length > 0 && unselectedOptions.length > 0 && (+ {isMultiple && selectedOptions.length > 0 && unselectedOptions.length > 0 && (<Command.Separator className="-mx-1 my-1 border-b border-neutral-200" />)}diff --git a/packages/ui/src/filter/filter-select.tsx b/packages/ui/src/filter/filter-select.tsxindex d0968fb980..bb3e703fd8 100644--- a/packages/ui/src/filter/filter-select.tsx+++ b/packages/ui/src/filter/filter-select.tsx@@ -18,7 +18,7 @@ import { useKeyboardShortcut, useMediaQuery } from "../hooks";import { useScrollProgress } from "../hooks/use-scroll-progress";import { Check, LoadingSpinner, Magic } from "../icons";import { Popover } from "../popover";-import { Filter, FilterOption, ActiveFilter } from "./types";+import { Filter, FilterOption, ActiveFilterInput, normalizeActiveFilter } from "./types";type FilterSelectProps = {filters: Filter[];@@ -27,8 +27,9 @@ type FilterSelectProps = {onOpenFilter?: (key: string) => void;onSearchChange?: (search: string) => void;onSelectedFilterChange?: (key: string | null) => void;- activeFilters?: ActiveFilter[];+ activeFilters?: ActiveFilterInput[];askAI?: boolean;+ isMultiple?: boolean;children?: ReactNode;emptyState?: ReactNode | Record<string, ReactNode>;className?: string;@@ -43,6 +44,7 @@ export function FilterSelect({onSelectedFilterChange,activeFilters,askAI,+ isMultiple = false,children,emptyState,className,@@ -101,11 +103,11 @@ export function FilterSelect({(value: FilterOption["value"]) => {if (!selectedFilter || !activeFilters) return false;- const activeFilter = activeFilters.find(- ({ key }) => key === selectedFilterKey,- );-- return activeFilter?.values.includes(value) ?? false;+ const rawActiveFilter = activeFilters.find((filter) => filter.key === selectedFilterKey);+ if (!rawActiveFilter) return false;++ const normalizedFilter = normalizeActiveFilter(rawActiveFilter);+ return normalizedFilter.values.includes(value);},[selectedFilter, activeFilters, selectedFilterKey],);@@ -114,7 +116,7 @@ export function FilterSelect({const selectOption = useCallback((value: FilterOption["value"]) => {if (selectedFilter) {- const isSingleSelect = selectedFilter?.singleSelect;+ const isSingleSelect = selectedFilter?.singleSelect || !isMultiple;if (isSingleSelect) {const isSelected = isOptionSelected(value);@@ -132,7 +134,7 @@ export function FilterSelect({}}},- [selectedFilter, isOptionSelected, onSelect, onRemove],+ [selectedFilter, isOptionSelected, onSelect, onRemove, isMultiple],);@@ -239,7 +241,7 @@ export function FilterSelect({selectedFilter.options?.filter((option) => !search || !option.hideDuringSearch)?.map((option) => {- const isSingleSelect = selectedFilter?.singleSelect;+ const isSingleSelect = selectedFilter?.singleSelect || !isMultiple;const isSelected = isOptionSelected(option.value);return (@@ -247,7 +249,7 @@ export function FilterSelect({key={option.value}filter={selectedFilter}option={option}- showCheckbox={!isSingleSelect}+ showCheckbox={!isSingleSelect && isMultiple}isChecked={isSelected}right={isSingleSelect ? (diff --git a/packages/ui/src/filter/index.ts b/packages/ui/src/filter/index.tsindex f4b8512c0e..5182f46c56 100644--- a/packages/ui/src/filter/index.ts+++ b/packages/ui/src/filter/index.ts@@ -4,4 +4,13 @@ import { FilterSelect } from "./filter-select";const Filter = { Select: FilterSelect, List: FilterList };export { Filter };-export type { FilterOperator, ActiveFilter, Filter as FilterType, FilterOption } from "./types";+export type {+ FilterOperator,+ ActiveFilter,+ ActiveFilterInput,+ LegacyActiveFilterSingular,+ LegacyActiveFilterPlural,+ Filter as FilterType,+ FilterOption+} from "./types";+export { normalizeActiveFilter } from "./types";diff --git a/packages/ui/src/filter/types.ts b/packages/ui/src/filter/types.tsindex eaa3623c31..3c02e64273 100644--- a/packages/ui/src/filter/types.ts+++ b/packages/ui/src/filter/types.ts@@ -44,3 +44,54 @@ export type ActiveFilter = {values: FilterOption["value"][];operator: FilterOperator;};++export type LegacyActiveFilterSingular = {+ key: Filter["key"];+ value: FilterOption["value"];+};++export type LegacyActiveFilterPlural = {+ key: Filter["key"];+ values: FilterOption["value"][];+};++export type ActiveFilterInput =+ | ActiveFilter+ | LegacyActiveFilterSingular+ | LegacyActiveFilterPlural;++/**+ * Normalize active filter to the new format with operator support+ * Handles backward compatibility with legacy formats:+ * - { key, value } → { key, values: [value], operator: 'IS' }+ * - { key, values } → { key, values, operator: 'IS' or 'IS_ONE_OF' }+ * - { key, values, operator } → unchanged (already correct)+ */+export function normalizeActiveFilter(filter: ActiveFilterInput): ActiveFilter {+ if ('operator' in filter && filter.operator && Array.isArray(filter.values)) {+ return filter as ActiveFilter;+ }++ if ('value' in filter && !('values' in filter)) {+ return {+ key: filter.key,+ operator: 'IS' as FilterOperator,+ values: [filter.value],+ };+ }++ if (Array.isArray((filter as any).values) && !('operator' in filter)) {+ const values = (filter as LegacyActiveFilterPlural).values;+ return {+ key: filter.key,+ operator: values.length > 1 ? 'IS_ONE_OF' : 'IS',+ values: values,+ };+ }++ return {+ key: filter.key,+ operator: 'IS',+ values: [],+ };+}