Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Move "Clear filters" button

Tim Wilson896a086aba0d
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index 36c1a69206..ade40105a0 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -340,11 +340,6 @@ export default function Toggle() {
del: key === "link" ? ["domain", "key"] : key,
})
}
- onRemoveAll={() =>
- queryParams({
- del: ["domain", "key", ...VALID_ANALYTICS_FILTERS],
- })
- }
/>
)}
<div
@@ -437,6 +432,11 @@ export default function Toggle() {
del: key === "link" ? ["domain", "key"] : key,
})
}
+ onRemoveAll={() =>
+ queryParams({
+ del: ["domain", "key", ...VALID_ANALYTICS_FILTERS],
+ })
+ }
/>
<div
className={cn(
diff --git a/packages/ui/src/filter/filter-list.tsx b/packages/ui/src/filter/filter-list.tsx
index 412e9259a1..c61a6f3d5b 100644
--- a/packages/ui/src/filter/filter-list.tsx
+++ b/packages/ui/src/filter/filter-list.tsx
@@ -12,6 +12,7 @@ type FilterListProps = {
value: FilterOption["value"];
}[];
onRemove: (key: string) => void;
+ onRemoveAll: () => void;
className?: string;
};
@@ -19,6 +20,7 @@ export function FilterList({
filters,
activeFilters,
onRemove,
+ onRemoveAll,
className,
}: FilterListProps) {
return (
@@ -27,74 +29,85 @@ export function FilterList({
className="w-full"
transition={{ type: "tween", duration: 0.3 }}
>
- <div className={cn("flex flex-wrap gap-x-4 gap-y-2", className)}>
- <AnimatePresence>
- {activeFilters?.map(({ key, value }) => {
- const filter = filters.find((f) => f.key === key);
- if (!filter) {
- throw new Error(
- "Filter.List received an activeFilter without a corresponding filter",
- );
- }
+ <div className={cn("flex w-full flex-wrap items-start gap-4", className)}>
+ <div className="flex grow flex-wrap gap-x-4 gap-y-2">
+ <AnimatePresence>
+ {activeFilters?.map(({ key, value }) => {
+ const filter = filters.find((f) => f.key === key);
+ if (!filter) {
+ throw new Error(
+ "Filter.List received an activeFilter without a corresponding filter",
+ );
+ }
- const option = filter.options?.find((o) => o.value === value);
+ const option = filter.options?.find((o) => o.value === value);
- return (
- <motion.div
- key={key}
- initial={{ opacity: 0, y: 4 }}
- animate={{ opacity: 1, y: 0 }}
- className="flex items-center divide-x rounded-md border border-gray-200 bg-white text-sm text-black"
- >
- {/* Filter */}
- <div className="flex items-center gap-2.5 px-3 py-2">
- <span className="shrink-0 text-gray-600">
- {isReactNode(filter.icon) ? (
- filter.icon
- ) : (
- <filter.icon className="h-4 w-4" />
- )}
- </span>
- {filter.label}
- </div>
+ return (
+ <motion.div
+ key={key}
+ initial={{ opacity: 0, y: 4 }}
+ animate={{ opacity: 1, y: 0 }}
+ className="flex items-center divide-x rounded-md border border-gray-200 bg-white text-sm text-black"
+ >
+ {/* Filter */}
+ <div className="flex items-center gap-2.5 px-3 py-2">
+ <span className="shrink-0 text-gray-600">
+ {isReactNode(filter.icon) ? (
+ filter.icon
+ ) : (
+ <filter.icon className="h-4 w-4" />
+ )}
+ </span>
+ {filter.label}
+ </div>
- {/* is */}
- <div className="px-3 py-2 text-gray-500">is</div>
+ {/* is */}
+ <div className="px-3 py-2 text-gray-500">is</div>
- {/* Option */}
- <div className="flex items-center gap-2.5 px-3 py-2">
- {filter.options ? (
- option ? (
- <>
- <span className="shrink-0 text-gray-600">
- {isReactNode(option.icon) ? (
- option.icon
- ) : (
- <option.icon className="h-4 w-4" />
- )}
- </span>
- {truncate(option.label, 30)}
- </>
+ {/* Option */}
+ <div className="flex items-center gap-2.5 px-3 py-2">
+ {filter.options ? (
+ option ? (
+ <>
+ <span className="shrink-0 text-gray-600">
+ {isReactNode(option.icon) ? (
+ option.icon
+ ) : (
+ <option.icon className="h-4 w-4" />
+ )}
+ </span>
+ {truncate(option.label, 30)}
+ </>
+ ) : (
+ value
+ )
) : (
- value
- )
- ) : (
- <div className="h-5 w-12 animate-pulse rounded-md bg-gray-200" />
- )}
- </div>
+ <div className="h-5 w-12 animate-pulse rounded-md bg-gray-200" />
+ )}
+ </div>
- {/* Remove */}
- <button
- type="button"
- className="h-full rounded-r-md p-2 text-gray-500 ring-inset ring-gray-500 hover:bg-gray-100 hover:text-gray-800 focus:outline-none focus-visible:ring-1"
- onClick={() => onRemove(key)}
- >
- <X className="h-3.5 w-3.5" />
- </button>
- </motion.div>
- );
- })}
- </AnimatePresence>
+ {/* Remove */}
+ <button
+ type="button"
+ className="h-full rounded-r-md p-2 text-gray-500 ring-inset ring-gray-500 hover:bg-gray-100 hover:text-gray-800 focus:outline-none focus-visible:ring-1"
+ onClick={() => onRemove(key)}
+ >
+ <X className="h-3.5 w-3.5" />
+ </button>
+ </motion.div>
+ );
+ })}
+ </AnimatePresence>
+ </div>
+ {activeFilters?.length !== 0 && (
+ <button
+ type="button"
+ className="whitespace-nowrap rounded-md px-3 py-2.5 text-sm text-gray-500 ring-inset ring-gray-500 transition-colors hover:text-gray-700 focus:outline-none focus-visible:ring-1"
+ onClick={onRemoveAll}
+ >
+ Clear Filters
+ </button>
+ )}
</div>
</AnimatedSizeContainer>
);
diff --git a/packages/ui/src/filter/filter-select.tsx b/packages/ui/src/filter/filter-select.tsx
index 133b8244b4..c9714e9a99 100644
--- a/packages/ui/src/filter/filter-select.tsx
+++ b/packages/ui/src/filter/filter-select.tsx
@@ -1,6 +1,6 @@
import { cn, truncate } from "@dub/utils";
import { Command } from "cmdk";
-import { Check, ChevronDown, FilterX, ListFilter } from "lucide-react";
+import { Check, ChevronDown, ListFilter } from "lucide-react";
import {
CSSProperties,
ReactNode,
@@ -20,7 +20,6 @@ type FilterSelectProps = {
filters: Filter[];
onSelect: (key: string, value: string) => void;
onRemove: (key: string) => void;
- onRemoveAll?: () => void;
activeFilters?: {
key: Filter["key"];
value: FilterOption["value"];
@@ -33,7 +32,6 @@ export function FilterSelect({
filters,
onSelect,
onRemove,
- onRemoveAll,
activeFilters,
children,
className,
@@ -130,19 +128,6 @@ export function FilterSelect({
onSelect={() => openFilter(filter.key)}
/>
))}
- {onRemoveAll && activeFilters?.length !== 0 && (
- <>
- <Command.Separator className="my-2 border-b border-gray-100" />
- <FilterButton
- icon={FilterX}
- label="Clear filters"
- onSelect={() => {
- onRemoveAll();
- setIsOpen(false);
- }}
- />
- </>
- )}
<NoMatches />
</Command.List>
) : (