Add delete option for project actions (#223)
Adds a delete button to the action edit dialog with a confirmation alert. Fixes pingdotgg/t3code#208.
This commit is contained in:
1 parent
18b6590d2e
commit
1c43bad705
2 files changed
+79
-1
No files matched your search
@@ -14,7 +14,7 @@ import {
|
||||
SettingsIcon,
|
||||
WrenchIcon,
|
||||
} from "lucide-react";
|
||||
import React, { type FormEvent, type KeyboardEvent, useMemo, useState } from "react";
|
||||
import React, { type FormEvent, type KeyboardEvent, useCallback, useMemo, useState } from "react";
|
||||
|
||||
import {
|
||||
keybindingValueForCommand,
|
||||
@@ -27,6 +27,15 @@ import {
|
||||
} from "~/projectScripts";
|
||||
import { shortcutLabelForCommand } from "~/keybindings";
|
||||
import { isMacPlatform } from "~/lib/utils";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogClose,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogPopup,
|
||||
AlertDialogTitle,
|
||||
} from "./ui/alert-dialog";
|
||||
import { Button } from "./ui/button";
|
||||
import {
|
||||
Dialog,
|
||||
@@ -84,6 +93,7 @@ interface ProjectScriptsControlProps {
|
||||
onRunScript: (script: ProjectScript) => void;
|
||||
onAddScript: (input: NewProjectScriptInput) => Promise<void> | void;
|
||||
onUpdateScript: (scriptId: string, input: NewProjectScriptInput) => Promise<void> | void;
|
||||
onDeleteScript: (scriptId: string) => Promise<void> | void;
|
||||
}
|
||||
|
||||
function normalizeShortcutKeyToken(key: string): string | null {
|
||||
@@ -144,6 +154,7 @@ export default function ProjectScriptsControl({
|
||||
onRunScript,
|
||||
onAddScript,
|
||||
onUpdateScript,
|
||||
onDeleteScript,
|
||||
}: ProjectScriptsControlProps) {
|
||||
const addScriptFormId = React.useId();
|
||||
const [editingScriptId, setEditingScriptId] = useState<string | null>(null);
|
||||
@@ -155,6 +166,7 @@ export default function ProjectScriptsControl({
|
||||
const [runOnWorktreeCreate, setRunOnWorktreeCreate] = useState(false);
|
||||
const [keybinding, setKeybinding] = useState("");
|
||||
const [validationError, setValidationError] = useState<string | null>(null);
|
||||
const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
|
||||
|
||||
const primaryScript = useMemo(() => {
|
||||
if (preferredScriptId) {
|
||||
@@ -247,6 +259,13 @@ export default function ProjectScriptsControl({
|
||||
setDialogOpen(true);
|
||||
};
|
||||
|
||||
const confirmDeleteScript = useCallback(() => {
|
||||
if (!editingScriptId) return;
|
||||
setDeleteConfirmOpen(false);
|
||||
setDialogOpen(false);
|
||||
void onDeleteScript(editingScriptId);
|
||||
}, [editingScriptId, onDeleteScript]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{primaryScript ? (
|
||||
@@ -440,6 +459,16 @@ export default function ProjectScriptsControl({
|
||||
</form>
|
||||
</DialogPanel>
|
||||
<DialogFooter>
|
||||
{isEditing && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="destructive-outline"
|
||||
className="mr-auto"
|
||||
onClick={() => setDeleteConfirmOpen(true)}
|
||||
>
|
||||
Delete
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
@@ -455,6 +484,21 @@ export default function ProjectScriptsControl({
|
||||
</DialogFooter>
|
||||
</DialogPopup>
|
||||
</Dialog>
|
||||
|
||||
<AlertDialog open={deleteConfirmOpen} onOpenChange={setDeleteConfirmOpen}>
|
||||
<AlertDialogPopup>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete action "{name}"?</AlertDialogTitle>
|
||||
<AlertDialogDescription>This action cannot be undone.</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogClose render={<Button variant="outline" />}>Cancel</AlertDialogClose>
|
||||
<Button variant="destructive" onClick={confirmDeleteScript}>
|
||||
Delete action
|
||||
</Button>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogPopup>
|
||||
</AlertDialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user