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.

feat: introduce a filter-bar

flooorianflo26f0f8ebc8b2
diff --git a/apps/web/ui/analytics/domain-selector.tsx b/apps/web/ui/analytics/domain-selector.tsx
new file mode 100644
index 0000000000..13e5411840
--- /dev/null
+++ b/apps/web/ui/analytics/domain-selector.tsx
@@ -0,0 +1,47 @@
+import useTags from "@/lib/swr/use-tags";
+import { InputSelect, useRouterStuff } from "@dub/ui";
+import { Globe, Tag } from "lucide-react";
+import { useRouter, useSearchParams } from "next/navigation";
+
+export default function DomainSelector() {
+ const router = useRouter();
+ const { queryParams } = useRouterStuff();
+
+ const { tags } = useTags();
+ const searchParams = useSearchParams();
+ const selectedTagId = searchParams?.get("tagId");
+
+ return tags && tags.length > 0 ? (
+ <InputSelect
+ adjustForMobile
+ items={tags.map(({ id, name, color }) => ({
+ id,
+ color,
+ value: name,
+ }))}
+ icon={<Globe className="h-4 w-4 text-black" />}
+ selectedItem={{
+ id: selectedTagId!,
+ value: tags.find(({ id }) => id === selectedTagId)?.name || "",
+ color: tags.find(({ id }) => id === selectedTagId)?.color,
+ }}
+ setSelectedItem={(tag) => {
+ if (tag && typeof tag !== "function" && tag.id)
+ router.push(
+ queryParams({
+ set: { tagId: tag.id },
+ getNewPath: true,
+ }) as string,
+ );
+ else
+ router.push(
+ queryParams({ del: "tagId", getNewPath: true }) as string,
+ );
+ }}
+ inputAttrs={{
+ placeholder: "Filter domains",
+ }}
+ className="md:w-48"
+ />
+ ) : undefined;
+}
diff --git a/apps/web/ui/analytics/filter-bar.tsx b/apps/web/ui/analytics/filter-bar.tsx
new file mode 100644
index 0000000000..ef0141d674
--- /dev/null
+++ b/apps/web/ui/analytics/filter-bar.tsx
@@ -0,0 +1,15 @@
+import { Plus } from "lucide-react";
+import DomainSelector from "./domain-selector";
+import TagSelector from "./tag-selector";
+
+export default function FilterBar() {
+ return (
+ <div className="flex w-full max-w-lg gap-1 rounded-lg bg-gray-100 p-1">
+ <TagSelector />
+ <DomainSelector />
+ <button className="flex w-10 items-center justify-center rounded-lg border border-gray-200 bg-white p-2">
+ <Plus className="h-5 w-5 text-black" />
+ </button>
+ </div>
+ );
+}
diff --git a/apps/web/ui/analytics/toggle.tsx b/apps/web/ui/analytics/toggle.tsx
index ba634139ef..00821ef166 100644
--- a/apps/web/ui/analytics/toggle.tsx
+++ b/apps/web/ui/analytics/toggle.tsx
@@ -26,6 +26,8 @@ import ExportButton from "./export-button";
import SharePopover from "./share-popover";
import TagSelector from "./tag-selector";
import DateRangePicker from "./date-range-picker";
+import FilterList from "./filter-bar";
+import FilterBar from "./filter-bar";
export default function Toggle() {
const { basePath, domain, key, url, admin } = useContext(AnalyticsContext);
@@ -89,7 +91,7 @@ export default function Toggle() {
)}
<div className="flex w-full items-center justify-end gap-2">
{!isPublicStatsPage && key && <SharePopover />}
- {!isPublicStatsPage && !key && <TagSelector />}
+ {!isPublicStatsPage && !key && <FilterBar />}
<DateRangePicker />
{!isPublicStatsPage && <ExportButton />}
</div>