-
Notifications
You must be signed in to change notification settings - Fork 2
feat(config-editor): diff preview before saving (#133) #217
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
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f9d4d2b
feat(config-editor): add diff preview modal before saving (#133)
BillChirico 12a9b27
feat(config-editor): wire up diff modal, undo, section revert, badge …
BillChirico dafc011
test(config-editor): add tests for ConfigDiff and ConfigDiffModal (#133)
BillChirico 1b3e6c1
fix(web): fix ai-feedback-stats TypeScript errors and add missing API…
BillChirico da32199
fix: scope undo snapshot by guildId to prevent cross-guild config cor…
c706959
fix: validate and clamp days param in ai-feedback stats route (resolv…
ec8d749
refactor: extract AiFeedbackStats type to shared analytics.ts (resolv…
e0976a4
Merge origin/main into feat/issue-133
e2e2de1
fix: resolve type name conflict in ai-feedback-stats
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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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 |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| 'use client'; | ||
|
|
||
| import { Loader2, RotateCcw, Save } from 'lucide-react'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from '@/components/ui/dialog'; | ||
| import { ConfigDiff } from './config-diff'; | ||
|
|
||
| interface ConfigDiffModalProps { | ||
| /** Whether the modal is open. */ | ||
| open: boolean; | ||
| /** Callback to open/close the modal. Blocked while saving. */ | ||
| onOpenChange: (open: boolean) => void; | ||
| /** The original (saved) config to diff against. */ | ||
| original: object; | ||
| /** The modified (draft) config to diff. */ | ||
| modified: object; | ||
| /** Top-level section keys that have changes. */ | ||
| changedSections: string[]; | ||
| /** Called when user confirms the save. */ | ||
| onConfirm: () => void; | ||
| /** Called when user reverts a specific top-level section. */ | ||
| onRevertSection: (section: string) => void; | ||
| /** Whether a save is in progress. */ | ||
| saving: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * A modal dialog that shows a diff preview of pending config changes before saving. | ||
| * | ||
| * Displays the changed sections as badges with individual revert buttons, a scrollable | ||
| * line-by-line diff, and Cancel / Confirm Save actions. | ||
| * | ||
| * @param open - Whether the dialog is visible. | ||
| * @param onOpenChange - Callback to open/close the dialog (blocked while saving). | ||
| * @param original - The original saved config object. | ||
| * @param modified - The draft config object with pending changes. | ||
| * @param changedSections - List of top-level section keys that differ. | ||
| * @param onConfirm - Called when the user clicks "Confirm Save". | ||
| * @param onRevertSection - Called with a section key when the user reverts that section. | ||
| * @param saving - When true, disables controls and shows a spinner on the confirm button. | ||
| * @returns The diff preview dialog element. | ||
| */ | ||
| export function ConfigDiffModal({ | ||
| open, | ||
| onOpenChange, | ||
| original, | ||
| modified, | ||
| changedSections, | ||
| onConfirm, | ||
| onRevertSection, | ||
| saving, | ||
| }: ConfigDiffModalProps) { | ||
| return ( | ||
| <Dialog open={open} onOpenChange={saving ? undefined : onOpenChange}> | ||
| <DialogContent className="flex max-h-[85vh] max-w-3xl flex-col"> | ||
| <DialogHeader> | ||
| <DialogTitle>Review Changes Before Saving</DialogTitle> | ||
| <DialogDescription> | ||
| Review your pending changes. Revert individual sections or confirm to save all changes. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| {/* Changed sections with per-section revert buttons */} | ||
| {changedSections.length > 0 && ( | ||
| <fieldset | ||
| aria-label="Changed sections" | ||
| className="flex flex-wrap items-center gap-2 rounded-md border bg-muted/30 p-3" | ||
| > | ||
| <legend className="sr-only">Changed sections</legend> | ||
| <span className="text-xs text-muted-foreground" aria-hidden="true"> | ||
| Changed sections: | ||
| </span> | ||
| {changedSections.map((section) => ( | ||
| <div key={section} className="flex items-center gap-1"> | ||
| <span className="rounded border border-yellow-500/30 bg-yellow-500/20 px-2 py-0.5 text-xs capitalize text-yellow-300"> | ||
| {section} | ||
| </span> | ||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| className="h-6 px-1.5 text-xs text-muted-foreground hover:text-destructive" | ||
| onClick={() => onRevertSection(section)} | ||
| disabled={saving} | ||
| aria-label={`Revert ${section} changes`} | ||
| > | ||
| <RotateCcw className="h-3 w-3" aria-hidden="true" /> | ||
| </Button> | ||
| </div> | ||
| ))} | ||
| </fieldset> | ||
| )} | ||
|
|
||
| {/* Scrollable diff view */} | ||
| <div className="min-h-0 flex-1 overflow-y-auto"> | ||
| <ConfigDiff original={original} modified={modified} title="Pending Changes" /> | ||
| </div> | ||
|
|
||
| <DialogFooter> | ||
| <Button variant="outline" onClick={() => onOpenChange(false)} disabled={saving}> | ||
| Cancel | ||
| </Button> | ||
| <Button onClick={onConfirm} disabled={saving}> | ||
| {saving ? ( | ||
| <> | ||
| <Loader2 className="mr-2 h-4 w-4 animate-spin" aria-hidden="true" /> | ||
| Saving... | ||
| </> | ||
| ) : ( | ||
| <> | ||
| <Save className="mr-2 h-4 w-4" aria-hidden="true" /> | ||
| Confirm Save | ||
| </> | ||
| )} | ||
| </Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } |
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.
Type name inconsistency - import renames to
AiFeedbackStatsTypebut assertion usesAiFeedbackStatsPrompt To Fix With AI