Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Implement search functionality in Funnels and Goals pages

Bill Yangd197e5ea270e
diff --git a/client/src/app/[site]/funnels/components/CreateFunnel.tsx b/client/src/app/[site]/funnels/components/CreateFunnel.tsx
index b095ba852..d022ce784 100644
--- a/client/src/app/[site]/funnels/components/CreateFunnel.tsx
+++ b/client/src/app/[site]/funnels/components/CreateFunnel.tsx
@@ -1,16 +1,12 @@
"use client";
-import { FunnelStep, useGetFunnel, useSaveFunnel } from "../../../../api/analytics/funnels/useGetFunnel";
-import { Time } from "@/components/DateSelector/types";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
import { Plus } from "lucide-react";
-import { DateTime } from "luxon";
import { useState } from "react";
import { toast } from "sonner";
-import { getStartAndEndDate } from "../../../../api/utils";
+import { FunnelStep, useGetFunnel, useSaveFunnel } from "../../../../api/analytics/funnels/useGetFunnel";
import { FunnelForm } from "./FunnelForm";
-import { Filter } from "@rybbit/shared";
export function CreateFunnelDialog() {
const [open, setOpen] = useState(false);
diff --git a/client/src/app/[site]/funnels/page.tsx b/client/src/app/[site]/funnels/page.tsx
index 6ac5737e4..e057287b4 100644
--- a/client/src/app/[site]/funnels/page.tsx
+++ b/client/src/app/[site]/funnels/page.tsx
@@ -11,6 +11,8 @@ import { useSetPageTitle } from "../../../hooks/useSetPageTitle";
import { DisabledOverlay } from "../../../components/DisabledOverlay";
import { MobileSidebar } from "../components/Sidebar/MobileSidebar";
import { SubHeader } from "../components/SubHeader/SubHeader";
+import { Input } from "@/components/ui/input";
+import { useMemo, useState } from "react";
// Skeleton for the funnel row component
const FunnelRowSkeleton = () => (
@@ -66,6 +68,24 @@ export default function FunnelsPage() {
const { site } = useStore();
const { data: funnels, isLoading, error } = useGetFunnels(site);
+ const [searchQuery, setSearchQuery] = useState("");
+
+ // Filter funnels based on search query
+ const filteredFunnels = useMemo(() => {
+ if (!funnels) return [];
+ if (!searchQuery.trim()) return funnels;
+
+ const query = searchQuery.toLowerCase();
+ return funnels.filter((funnel: SavedFunnel) => {
+ // Search in funnel name
+ if (funnel.name.toLowerCase().includes(query)) return true;
+
+ // Search in step values
+ return funnel.steps.some(
+ step => step.value.toLowerCase().includes(query) || step.name?.toLowerCase().includes(query)
+ );
+ });
+ }, [funnels, searchQuery]);
if (isLoading) {
return (
@@ -87,7 +107,14 @@ export default function FunnelsPage() {
<DisabledOverlay message="Funnels" featurePath="funnels">
<div className="p-2 md:p-4 max-w-[1300px] mx-auto space-y-3">
<SubHeader availableFilters={GOALS_PAGE_FILTERS} />
- <div className="flex justify-end">
+ <div className="flex justify-between items-center">
+ <Input
+ placeholder="Filter funnels"
+ className="w-48"
+ isSearch
+ value={searchQuery}
+ onChange={e => setSearchQuery(e.target.value)}
+ />
<CreateFunnelDialog />
</div>
@@ -95,12 +122,18 @@ export default function FunnelsPage() {
<div className="p-4 bg-red-50 dark:bg-red-900/20 text-red-600 dark:text-red-400 rounded-lg">
Failed to load funnels: {error instanceof Error ? error.message : "Unknown error"}
</div>
- ) : funnels?.length ? (
+ ) : filteredFunnels?.length ? (
<div className="space-y-4">
- {funnels.map((funnel: SavedFunnel, index: number) => (
+ {filteredFunnels.map((funnel: SavedFunnel, index: number) => (
<FunnelRow key={funnel.id} funnel={funnel} index={index} />
))}
</div>
+ ) : funnels?.length ? (
+ <NothingFound
+ icon={<Funnel className="w-10 h-10" />}
+ title={"No funnels found"}
+ description={`No funnels match "${searchQuery}"`}
+ />
) : (
<NothingFound
icon={<Funnel className="w-10 h-10" />}
diff --git a/client/src/app/[site]/goals/page.tsx b/client/src/app/[site]/goals/page.tsx
index 7929e5e54..e8ca6f7d4 100644
--- a/client/src/app/[site]/goals/page.tsx
+++ b/client/src/app/[site]/goals/page.tsx
@@ -1,6 +1,6 @@
"use client";
-import { useState } from "react";
+import { useMemo, useState } from "react";
import { useGetGoals } from "../../../api/analytics/goals/useGetGoals";
import { DisabledOverlay } from "../../../components/DisabledOverlay";
import { NothingFound } from "../../../components/NothingFound";
@@ -11,11 +11,13 @@ import { SubHeader } from "../components/SubHeader/SubHeader";
import CreateGoalButton from "./components/CreateGoalButton";
import GoalsList from "./components/GoalsList";
import { Target } from "lucide-react";
+import { Input } from "@/components/ui/input";
export default function GoalsPage() {
useSetPageTitle("Rybbit · Goals");
const { site } = useStore();
+ const [searchQuery, setSearchQuery] = useState("");
const [pagination, setPagination] = useState({
pageIndex: 0, // TablePagination uses 0-based indexing
pageSize: 10, // Show 10 goals per page
@@ -26,6 +28,32 @@ export default function GoalsPage() {
pageSize: pagination.pageSize,
});
+ // Filter goals based on search query
+ const filteredGoals = useMemo(() => {
+ if (!goalsData?.data) return [];
+ if (!searchQuery.trim()) return goalsData.data;
+
+ const query = searchQuery.toLowerCase();
+ return goalsData.data.filter(goal => {
+ // Search in goal name
+ if (goal.name?.toLowerCase().includes(query)) return true;
+
+ // Search in path pattern or event name
+ if (goal.goalType === "path" && goal.config.pathPattern?.toLowerCase().includes(query)) return true;
+ if (goal.goalType === "event" && goal.config.eventName?.toLowerCase().includes(query)) return true;
+
+ // Search in event property key/value
+ if (
+ goal.config.eventPropertyKey?.toLowerCase().includes(query) ||
+ String(goal.config.eventPropertyValue)?.toLowerCase().includes(query)
+ ) {
+ return true;
+ }
+
+ return false;
+ });
+ }, [goalsData?.data, searchQuery]);
+
// Create pagination controller for TablePagination
const paginationController = {
getState: () => ({ pagination }),
@@ -110,7 +138,13 @@ export default function GoalsPage() {
<div className="p-2 md:p-4 max-w-[1400px] mx-auto space-y-3">
<SubHeader availableFilters={GOALS_PAGE_FILTERS} />
<div className="flex items-center justify-between">
- <div />
+ <Input
+ placeholder="Filter goals"
+ className="w-48"
+ isSearch
+ value={searchQuery}
+ onChange={e => setSearchQuery(e.target.value)}
+ />
<CreateGoalButton siteId={Number(site)} />
</div>
@@ -129,11 +163,17 @@ export default function GoalsPage() {
description={"Create your first conversion goal to start tracking important user actions."}
action={<CreateGoalButton siteId={Number(site)} />}
/>
+ ) : filteredGoals.length === 0 ? (
+ <NothingFound
+ icon={<Target className="w-10 h-10" />}
+ title={"No goals found"}
+ description={`No goals match "${searchQuery}"`}
+ />
) : (
<div className="space-y-6">
- <GoalsList goals={goalsData.data} siteId={Number(site)} />
+ <GoalsList goals={filteredGoals} siteId={Number(site)} />
- {goalsData.meta.totalPages > 1 && (
+ {goalsData.meta.totalPages > 1 && !searchQuery && (
<Pagination
table={paginationController}
data={paginationData}
diff --git a/client/src/components/ui/input.tsx b/client/src/components/ui/input.tsx
index 4deed9d1e..18219257b 100644
--- a/client/src/components/ui/input.tsx
+++ b/client/src/components/ui/input.tsx
@@ -1,5 +1,6 @@
import * as React from "react";
import { cva, type VariantProps } from "class-variance-authority";
+import { Search } from "lucide-react";
import { cn } from "@/lib/utils";
@@ -8,7 +9,7 @@ const inputVariants = cva(
{
variants: {
inputSize: {
- default: "h-9 px-3 py-1 text-base md:text-sm file:text-sm",
+ default: "h-9 px-3 py-1 text-sm file:text-sm",
sm: "h-7 px-2 py-0.5 text-xs file:text-xs",
},
},
@@ -20,11 +21,24 @@ const inputVariants = cva(
export interface InputProps
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">,
- VariantProps<typeof inputVariants> {}
+ VariantProps<typeof inputVariants> {
+ isSearch?: boolean;
+}
-const Input = React.forwardRef<HTMLInputElement, InputProps>(({ className, type, inputSize, ...props }, ref) => {
- return <input type={type} className={cn(inputVariants({ inputSize, className }))} ref={ref} {...props} />;
-});
+const Input = React.forwardRef<HTMLInputElement, InputProps>(
+ ({ className, type, inputSize, isSearch, ...props }, ref) => {
+ if (isSearch) {
+ return (
+ <div className="relative">
+ <Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-neutral-400" />
+ <input type={type} className={cn(inputVariants({ inputSize }), "pl-9", className)} ref={ref} {...props} />
+ </div>
+ );
+ }
+
+ return <input type={type} className={cn(inputVariants({ inputSize, className }))} ref={ref} {...props} />;
+ }
+);
Input.displayName = "Input";
export { Input };