Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useNodeRegistry } from "@/routes/v2/shared/nodes/NodeRegistryContext";
import { CMDALT, SHIFT } from "@/routes/v2/shared/shortcuts/keys";
import { useSharedStores } from "@/routes/v2/shared/store/SharedStoreContext";

import { CanvasUndoRedo } from "./components/CanvasUndoRedo";
import { ConnectionLine } from "./components/ConnectionLine";
import { FloatingSelectionToolbar } from "./components/FloatingSelectionToolbar";
import { useClipboardShortcuts } from "./hooks/useClipboardShortcuts";
Expand Down Expand Up @@ -141,6 +142,7 @@ export const FlowCanvas = observer(function FlowCanvas({
onNodeClick={() => track("v2.pipeline_canvas.minimap.node.click")}
/>
</ReactFlow>
<CanvasUndoRedo />
</BlockStack>
);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { observer } from "mobx-react-lite";

import { Button } from "@/components/ui/button";
import { Icon } from "@/components/ui/icon";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { useAnalytics } from "@/providers/AnalyticsProvider";
import { useEditorSession } from "@/routes/v2/pages/Editor/store/EditorSessionContext";
import { ShortcutBadge } from "@/routes/v2/shared/components/ShortcutBadge";

export const CanvasUndoRedo = observer(function CanvasUndoRedo() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly similar to https://app.graphite.com/github/pr/TangleML/tangle-ui/2269?ref=gt-pasteable-stack - I believe we can merge two components in future

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can have a look at bringing them together

const { track } = useAnalytics();
const { undo } = useEditorSession();

const handleUndo = () => {
track("v2.pipeline_canvas.controls.undo.click");
undo.undo();
};

const handleRedo = () => {
track("v2.pipeline_canvas.controls.redo.click");
undo.redo();
};

return (
<div className="absolute right-16 bottom-4 z-10 flex gap-1">
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="sm"
className="p-0"
onClick={handleUndo}
disabled={!undo.canUndo}
aria-label="Undo"
>
<Icon name="Undo2" size="sm" />
</Button>
</TooltipTrigger>
<TooltipContent side="top" className="flex items-center gap-1">
Undo
<ShortcutBadge id="undo" className="text-primary-foreground z-10" />
</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="sm"
className="p-0"
onClick={handleRedo}
disabled={!undo.canRedo}
aria-label="Redo"
>
<Icon name="Redo2" size="sm" />
</Button>
</TooltipTrigger>
<TooltipContent side="top" className="flex items-center gap-1">
Redo
<ShortcutBadge id="redo" className="text-primary-foreground z-10" />
</TooltipContent>
</Tooltip>
</TooltipProvider>
</div>
);
});
8 changes: 7 additions & 1 deletion src/routes/v2/shared/components/ShortcutBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ import { useSharedStores } from "@/routes/v2/shared/store/SharedStoreContext";

export const ShortcutBadge = observer(function ShortcutBadge({
id,
className,
}: {
id: string;
className?: string;
}) {
const { keyboard } = useSharedStores();
const shortcut = keyboard.getShortcut(id);

if (!shortcut) return null;

return <Badge variant="outline">{formatShortcut(shortcut.keys)}</Badge>;
return (
<Badge variant="outline" className={className}>
{formatShortcut(shortcut.keys)}
</Badge>
);
});

const isMac =
Expand Down
Loading