Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement custom save shortcut in SaveControl component #8407

Merged
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
@@ -1,4 +1,4 @@
import React from "react";
import React, { useCallback, useEffect } from "react";
import {
Popover,
PopoverContent,
Expand All @@ -15,6 +15,7 @@ import {
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { useToast } from "@/components/ui/use-toast";

interface SaveControlProps {
agentMeta: GraphMeta | null;
Expand Down Expand Up @@ -52,14 +53,35 @@ export const SaveControl = ({

// Determines if we're saving a template or an agent
let isTemplate = agentMeta?.is_template ? true : undefined;
const handleSave = () => {
const handleSave = useCallback(() => {
onSave(isTemplate);
};
}, [onSave, isTemplate]);

const getType = () => {
return agentMeta?.is_template ? "template" : "agent";
};

const { toast } = useToast();

useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if ((event.ctrlKey || event.metaKey) && event.key === "s") {
event.preventDefault(); // Stop the browser default action
handleSave(); // Call your save function
toast({
duration: 2000,
title: "All changes saved successfully!",
});
}
};

window.addEventListener("keydown", handleKeyDown);

return () => {
window.removeEventListener("keydown", handleKeyDown);
};
}, [handleSave]);

return (
<Popover open={pinSavePopover ? true : undefined}>
<Tooltip delayDuration={500}>
Expand Down
Loading