-
Notifications
You must be signed in to change notification settings - Fork 0
fix(audit-sprint-4c): modal primitives (Phase 1) + 2 proof migrations #167
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,31 @@ | |
| import { useState } from "react" | ||
| import { useRouter } from "next/navigation" | ||
| import { createSupabaseClient } from "@/lib/supabase/client" | ||
| import { Trash2, Loader2, AlertTriangle, X } from "lucide-react" | ||
| import { Trash2, Loader2 } from "lucide-react" | ||
| import { logActivity } from "@/lib/actions/audit" | ||
| import { useComplianceAction, type NodeType } from "@/components/compliance-system" | ||
| import { | ||
| AlertDialog, | ||
| AlertDialogAction, | ||
| AlertDialogCancel, | ||
| AlertDialogContent, | ||
| AlertDialogDescription, | ||
| AlertDialogFooter, | ||
| AlertDialogHeader, | ||
| AlertDialogTitle, | ||
| AlertDialogTrigger, | ||
| } from "@/components/ui/alert-dialog" | ||
|
|
||
| /** | ||
| * ========================================================= | ||
| * DELETE BUTTON | ||
| * Action: Removes node from compliance graph | ||
| * Shows system impact warning before deletion | ||
| * Action: Removes node from compliance graph. | ||
| * | ||
| * Audit 2026-05-23 (Sprint 4c Phase 1): migrated from inline | ||
| * confirm card to AlertDialog. The previous implementation had | ||
| * no focus trap, no ESC handler, no aria-modal, and rendered | ||
| * confirmation as a sibling element. AlertDialog gives all of | ||
| * those for free. | ||
| * ========================================================= | ||
| */ | ||
|
|
||
|
|
@@ -22,7 +38,6 @@ type DeleteButtonProps = { | |
| onDelete?: () => void | ||
| } | ||
|
|
||
| // Map table names to node types | ||
| const tableToNodeType: Record<string, NodeType> = { | ||
| 'org_policies': 'policy', | ||
| 'org_registers': 'control', | ||
|
|
@@ -37,88 +52,89 @@ const tableToLabel: Record<string, string> = { | |
|
|
||
| export function DeleteButton({ id, tableName, itemTitle, onDelete }: DeleteButtonProps) { | ||
| const [loading, setLoading] = useState(false) | ||
| const [confirm, setConfirm] = useState(false) | ||
| const [open, setOpen] = useState(false) | ||
| const router = useRouter() | ||
| const { nodeDeleted, reportError } = useComplianceAction() | ||
|
|
||
| const nodeType = tableToNodeType[tableName] || 'entity' | ||
| const nodeLabel = tableToLabel[tableName] || 'Record' | ||
| const displayTitle = itemTitle || `${nodeLabel} ${id.slice(0, 8)}` | ||
|
|
||
| async function handleDelete() { | ||
| async function handleDelete(event: React.MouseEvent) { | ||
| // Stop the AlertDialog default close so the spinner has time to render. | ||
| event.preventDefault() | ||
| setLoading(true) | ||
|
|
||
| // 1. Execute the deletion | ||
|
|
||
| const supabase = createSupabaseClient() | ||
| const { error } = await supabase.from(tableName).delete().eq('id', id) | ||
|
|
||
| if (error) { | ||
| reportError({ title: "Delete failed", message: `Failed to delete ${nodeLabel.toLowerCase()}: ${error.message}` }) | ||
| reportError({ | ||
| title: "Delete failed", | ||
| message: `Failed to delete ${nodeLabel.toLowerCase()}: ${error.message}`, | ||
| }) | ||
| setLoading(false) | ||
| setConfirm(false) | ||
| return | ||
| } | ||
|
|
||
| // 2. Trigger the Automated Audit Log | ||
| const recordType = tableName.split('_')[1].replace(/s$/, '').toUpperCase(); | ||
|
|
||
|
|
||
| const recordType = tableName.split('_')[1].replace(/s$/, '').toUpperCase() | ||
|
|
||
| try { | ||
| await logActivity({ | ||
| type: `${recordType}_DELETE`, | ||
| description: `User permanently deleted ${recordType.toLowerCase()} record: ${id.slice(0, 8)}`, | ||
| metadata: { record_id: id, source_table: tableName } | ||
| }); | ||
| metadata: { record_id: id, source_table: tableName }, | ||
| }) | ||
| } catch (auditError) { | ||
| console.error("Audit log failed, but record was deleted:", auditError); | ||
| console.error("Audit log failed, but record was deleted:", auditError) | ||
| } | ||
|
|
||
| // 3. Report to compliance system | ||
| nodeDeleted(nodeType, itemTitle || `${nodeLabel} ${id.slice(0, 8)}`) | ||
| nodeDeleted(nodeType, displayTitle) | ||
|
|
||
| // 4. Update UI | ||
| setConfirm(false) | ||
| setLoading(false) | ||
| setOpen(false) | ||
| if (onDelete) onDelete() | ||
| router.refresh() | ||
| } | ||
|
|
||
| if (confirm) { | ||
| return ( | ||
| <div className="flex items-center gap-2 bg-rose-500/10 px-3 py-1.5 rounded-lg border border-rose-500/30 animate-in fade-in slide-in-from-right-2 duration-200"> | ||
| <AlertTriangle className="h-3.5 w-3.5 text-rose-400 shrink-0" /> | ||
| <span className="text-xs font-medium text-rose-300 hidden sm:inline"> | ||
| This will disconnect all linked nodes | ||
| </span> | ||
| <button | ||
| onClick={() => setConfirm(false)} | ||
| className="p-1 text-muted-foreground hover:text-foreground/90 hover:bg-glass-strong rounded transition-colors" | ||
| title="Cancel" | ||
| > | ||
| <X className="h-3.5 w-3.5" /> | ||
| </button> | ||
| <div className="h-4 w-px bg-rose-500/30" /> | ||
| <button | ||
| onClick={handleDelete} | ||
| disabled={loading} | ||
| className="flex items-center gap-1.5 px-2 py-1 text-xs font-bold uppercase text-rose-300 hover:text-white hover:bg-rose-500/20 rounded transition-all disabled:opacity-50" | ||
| return ( | ||
| <AlertDialog open={open} onOpenChange={setOpen}> | ||
| <AlertDialogTrigger asChild> | ||
| <button | ||
| className="group p-2 text-muted-foreground hover:text-rose-400 hover:bg-rose-500/10 rounded-lg border border-transparent hover:border-rose-500/20 transition-all motion-safe:active:scale-95" | ||
| title={`Delete ${nodeLabel.toLowerCase()}`} | ||
| > | ||
|
Comment on lines
+103
to
106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set an explicit button type and accessible name on the dialog trigger. This icon-only trigger can submit a parent form by default and lacks a reliable accessible name. Add Suggested fix <button
+ type="button"
+ aria-label={`Delete ${nodeLabel.toLowerCase()}`}
className="group p-2 text-muted-foreground hover:text-rose-400 hover:bg-rose-500/10 rounded-lg border border-transparent hover:border-rose-500/20 transition-all motion-safe:active:scale-95"
title={`Delete ${nodeLabel.toLowerCase()}`}
>🤖 Prompt for AI Agents |
||
| {loading ? ( | ||
| <Loader2 className="h-3 w-3 animate-spin" /> | ||
| ) : ( | ||
| <Trash2 className="h-3 w-3" /> | ||
| )} | ||
| Delete | ||
| <Trash2 className="h-4 w-4 group-hover:animate-pulse" /> | ||
| </button> | ||
|
Comment on lines
+103
to
108
|
||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <button | ||
| onClick={() => setConfirm(true)} | ||
| className="group p-2 text-muted-foreground hover:text-rose-400 hover:bg-rose-500/10 rounded-lg border border-transparent hover:border-rose-500/20 transition-all motion-safe:active:scale-95" | ||
| title={`Delete ${nodeLabel.toLowerCase()}`} | ||
| > | ||
| <Trash2 className="h-4 w-4 group-hover:animate-pulse" /> | ||
| </button> | ||
| </AlertDialogTrigger> | ||
| <AlertDialogContent> | ||
| <AlertDialogHeader> | ||
| <AlertDialogTitle>Delete {nodeLabel.toLowerCase()}?</AlertDialogTitle> | ||
| <AlertDialogDescription> | ||
| <span className="block text-slate-300">{displayTitle}</span> | ||
| <span className="mt-2 block"> | ||
| This will disconnect all linked nodes. The deletion is permanent | ||
| and will be recorded in the audit log. | ||
| </span> | ||
| </AlertDialogDescription> | ||
| </AlertDialogHeader> | ||
| <AlertDialogFooter> | ||
| <AlertDialogCancel disabled={loading}>Cancel</AlertDialogCancel> | ||
| <AlertDialogAction onClick={handleDelete} disabled={loading}> | ||
| {loading ? ( | ||
| <> | ||
| <Loader2 className="mr-2 h-4 w-4 animate-spin" /> | ||
| Deleting… | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <Trash2 className="mr-2 h-4 w-4" /> | ||
| Delete {nodeLabel.toLowerCase()} | ||
| </> | ||
| )} | ||
| </AlertDialogAction> | ||
| </AlertDialogFooter> | ||
| </AlertDialogContent> | ||
| </AlertDialog> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard
pendingDeleteIdcleanup to avoid clobbering a newer delete intent.The unconditional reset in
finallycan close a newly opened confirmation if a previous delete request finishes later. Reset only when the samecommentIdis still pending.Suggested fix
📝 Committable suggestion
🤖 Prompt for AI Agents