Skip to content

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

Enhance GoalCard and GoalFormModal components with cloning functionality

Bill Yanga753b0e6f8df
diff --git a/client/src/app/[site]/goals/components/GoalCard.tsx b/client/src/app/[site]/goals/components/GoalCard.tsx
index 65913a474..6b3c0b7cc 100644
--- a/client/src/app/[site]/goals/components/GoalCard.tsx
+++ b/client/src/app/[site]/goals/components/GoalCard.tsx
@@ -1,6 +1,6 @@
"use client";
-import { Edit, Trash2 } from "lucide-react";
+import { Copy, Edit, Trash2 } from "lucide-react";
import { useState } from "react";
import { useDeleteGoal } from "../../../../api/analytics/goals/useDeleteGoal";
import { Goal } from "../../../../api/analytics/goals/useGetGoals";
@@ -103,14 +103,39 @@ export default function GoalCard({ goal, siteId }: GoalCardProps) {
siteId={siteId}
goal={goal}
trigger={
- <Button variant="ghost" size="smIcon">
- <Edit className="h-4 w-4" />
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button variant="ghost" size="smIcon">
+ <Edit className="h-4 w-4" />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>Edit Goal</TooltipContent>
+ </Tooltip>
+ }
+ />
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button onClick={() => setIsDeleteDialogOpen(true)} variant="ghost" size="smIcon">
+ <Trash2 className="h-4 w-4" />
</Button>
+ </TooltipTrigger>
+ <TooltipContent>Delete Goal</TooltipContent>
+ </Tooltip>
+ <GoalFormModal
+ siteId={siteId}
+ goal={goal}
+ isCloneMode={true}
+ trigger={
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Button variant="ghost" size="smIcon">
+ <Copy className="h-4 w-4" />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>Clone Goal</TooltipContent>
+ </Tooltip>
}
/>
- <Button onClick={() => setIsDeleteDialogOpen(true)} variant="ghost" size="smIcon">
- <Trash2 className="h-4 w-4" />
- </Button>
</div>
</div>
<div className="bg-neutral-700 h-1.5 w-full absolute bottom-0 left-0"></div>
diff --git a/client/src/app/[site]/goals/components/GoalFormModal.tsx b/client/src/app/[site]/goals/components/GoalFormModal.tsx
index 42528fb72..b2f37d230 100644
--- a/client/src/app/[site]/goals/components/GoalFormModal.tsx
+++ b/client/src/app/[site]/goals/components/GoalFormModal.tsx
@@ -58,9 +58,10 @@ interface GoalFormModalProps {
siteId: number;
goal?: Goal; // Optional goal for editing mode
trigger: React.ReactNode;
+ isCloneMode?: boolean; // Optional clone mode flag
}
-export default function GoalFormModal({ siteId, goal, trigger }: GoalFormModalProps) {
+export default function GoalFormModal({ siteId, goal, trigger, isCloneMode = false }: GoalFormModalProps) {
const [isOpen, setIsOpen] = useState(false);
const [useProperties, setUseProperties] = useState(
!!goal?.config.eventPropertyKey && !!goal?.config.eventPropertyValue
@@ -103,16 +104,16 @@ export default function GoalFormModal({ siteId, goal, trigger }: GoalFormModalPr
setIsOpen(false);
};
- const isEditMode = !!goal;
+ const isEditMode = !!goal && !isCloneMode;
const createGoal = useCreateGoal();
const updateGoal = useUpdateGoal();
// Initialize form with default values or existing goal
const form = useForm<FormValues>({
resolver: zodResolver(formSchema),
- defaultValues: isEditMode
+ defaultValues: (isEditMode || isCloneMode) && goal
? {
- name: goal.name || "",
+ name: isCloneMode ? `${goal.name || `Goal #${goal.goalId}`} (Copy)` : (goal.name || ""),
goalType: goal.goalType,
config: {
pathPattern: goal.config.pathPattern || "",
@@ -192,13 +193,17 @@ export default function GoalFormModal({ siteId, goal, trigger }: GoalFormModalPr
}
}}
>
- <DialogTrigger asChild>{trigger}</DialogTrigger>
+ <DialogTrigger asChild>
+ <div onClick={() => setIsOpen(true)}>{trigger}</div>
+ </DialogTrigger>
<DialogContent className="sm:max-w-[500px]">
<DialogHeader>
- <DialogTitle>{isEditMode ? "Edit Goal" : "Create Goal"}</DialogTitle>
+ <DialogTitle>{isEditMode ? "Edit Goal" : isCloneMode ? "Clone Goal" : "Create Goal"}</DialogTitle>
<DialogDescription>
{isEditMode
? "Update the goal details below."
+ : isCloneMode
+ ? "Clone this goal with the same configuration."
: "Set up a new conversion goal to track specific user actions."}
</DialogDescription>
</DialogHeader>
diff --git a/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx b/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx
index d3ce474ea..d896c5b10 100644
--- a/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx
+++ b/client/src/app/[site]/replay/components/ReplayBreadcrumbs.tsx
@@ -31,7 +31,7 @@ import { useGetSessionReplayEvents } from "../../../../api/analytics/sessionRepl
import { ScrollArea } from "../../../../components/ui/scroll-area";
import { cn } from "../../../../lib/utils";
import { useReplayStore } from "./replayStore";
-import { Avatar } from "../../../../components/Avatar";
+import { Avatar, generateName } from "../../../../components/Avatar";
import Link from "next/link";
import { Button } from "../../../../components/ui/button";
@@ -258,7 +258,7 @@ export function ReplayBreadcrumbs() {
<div className="rounded-lg border border-neutral-800 bg-neutral-900 flex items-center justify-between gap-2 p-2 text-xs text-neutral-200">
<div className="flex items-center gap-2">
<Avatar id={data.metadata.user_id} size={20} />
- {data.metadata.user_id.slice(0, 12)}
+ {generateName(data.metadata.user_id)}
</div>
<Link href={`/${siteId}/user/${data.metadata.user_id}`} className="flex items-center gap-2">
<Button size="sm">View User</Button>