-
Notifications
You must be signed in to change notification settings - Fork 918
feat(desktop): add terminal presets system #279
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
140 changes: 140 additions & 0 deletions
140
...nderer/screens/main/components/WorkspaceView/Sidebar/TabsView/PresetModal/PresetModal.tsx
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,140 @@ | ||
| import { Button } from "@superset/ui/button"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from "@superset/ui/dialog"; | ||
| import { Input } from "@superset/ui/input"; | ||
| import { Label } from "@superset/ui/label"; | ||
| import { Textarea } from "@superset/ui/textarea"; | ||
| import { useEffect, useState } from "react"; | ||
| import { trpc } from "renderer/lib/trpc"; | ||
| import { | ||
| useClosePresetModal, | ||
| usePresetModalOpen, | ||
| usePresetModalPrefillCwd, | ||
| usePresetModalProjectId, | ||
| } from "renderer/stores/preset-modal"; | ||
|
|
||
| export function PresetModal() { | ||
| const isOpen = usePresetModalOpen(); | ||
| const projectId = usePresetModalProjectId(); | ||
| const prefillCwd = usePresetModalPrefillCwd(); | ||
| const closeModal = useClosePresetModal(); | ||
|
|
||
| const [name, setName] = useState(""); | ||
| const [cwd, setCwd] = useState(""); | ||
| const [commands, setCommands] = useState(""); | ||
|
|
||
| const utils = trpc.useUtils(); | ||
|
|
||
| const savePresetMutation = trpc.config.saveTerminalPreset.useMutation({ | ||
| onSuccess: () => { | ||
| utils.config.getTerminalPresets.invalidate(); | ||
| closeModal(); | ||
| }, | ||
| }); | ||
|
|
||
| // Reset form when modal opens/closes | ||
| useEffect(() => { | ||
| if (isOpen) { | ||
| setName(""); | ||
| setCwd(prefillCwd || ""); | ||
| setCommands(""); | ||
| } | ||
| }, [isOpen, prefillCwd]); | ||
|
|
||
| const handleSave = () => { | ||
| if (!projectId || !name.trim() || !commands.trim()) return; | ||
|
|
||
| // Split commands by newline and filter empty lines | ||
| const commandList = commands | ||
| .split("\n") | ||
| .map((c) => c.trim()) | ||
| .filter((c) => c.length > 0); | ||
|
|
||
| savePresetMutation.mutate({ | ||
| projectId, | ||
| preset: { | ||
| name: name.trim(), | ||
| cwd: cwd.trim() || undefined, | ||
| commands: commandList.length === 1 ? commandList[0] : commandList, | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| const isValid = name.trim().length > 0 && commands.trim().length > 0; | ||
|
|
||
| return ( | ||
| <Dialog modal open={isOpen} onOpenChange={(open) => !open && closeModal()}> | ||
| <DialogContent className="sm:max-w-md"> | ||
| <DialogHeader> | ||
| <DialogTitle>Create Terminal Preset</DialogTitle> | ||
| <DialogDescription> | ||
| Save a terminal configuration for quick access from the sidebar. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
|
|
||
| <div className="space-y-4 py-4"> | ||
| <div className="space-y-2"> | ||
| <Label htmlFor="preset-name">Name</Label> | ||
| <Input | ||
| id="preset-name" | ||
| placeholder="e.g., Dev Server" | ||
| value={name} | ||
| onChange={(e) => setName(e.target.value)} | ||
| autoFocus | ||
| /> | ||
| </div> | ||
|
|
||
| <div className="space-y-2"> | ||
| <Label htmlFor="preset-cwd"> | ||
| Working Directory{" "} | ||
| <span className="text-muted-foreground font-normal"> | ||
| (optional) | ||
| </span> | ||
| </Label> | ||
| <Input | ||
| id="preset-cwd" | ||
| placeholder="e.g., ./apps/web" | ||
| value={cwd} | ||
| onChange={(e) => setCwd(e.target.value)} | ||
| /> | ||
| <p className="text-xs text-muted-foreground"> | ||
| Relative to project root or absolute path | ||
| </p> | ||
| </div> | ||
|
|
||
| <div className="space-y-2"> | ||
| <Label htmlFor="preset-commands">Commands</Label> | ||
| <Textarea | ||
| id="preset-commands" | ||
| placeholder="One command per line" | ||
| value={commands} | ||
| onChange={(e) => setCommands(e.target.value)} | ||
| rows={3} | ||
| /> | ||
| <p className="text-xs text-muted-foreground"> | ||
| Commands run sequentially when the preset is launched | ||
| </p> | ||
| </div> | ||
| </div> | ||
|
|
||
| <DialogFooter> | ||
| <Button variant="outline" onClick={closeModal}> | ||
| Cancel | ||
| </Button> | ||
| <Button | ||
| onClick={handleSave} | ||
| disabled={!isValid || savePresetMutation.isPending} | ||
| > | ||
| {savePresetMutation.isPending ? "Saving..." : "Save Preset"} | ||
| </Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } |
1 change: 1 addition & 0 deletions
1
.../src/renderer/screens/main/components/WorkspaceView/Sidebar/TabsView/PresetModal/index.ts
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 @@ | ||
| export { PresetModal } from "./PresetModal"; |
28 changes: 28 additions & 0 deletions
28
...eens/main/components/WorkspaceView/Sidebar/TabsView/TerminalPresets/PresetContextMenu.tsx
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,28 @@ | ||
| import { | ||
| ContextMenu, | ||
| ContextMenuContent, | ||
| ContextMenuItem, | ||
| ContextMenuTrigger, | ||
| } from "@superset/ui/context-menu"; | ||
| import type React from "react"; | ||
|
|
||
| interface PresetContextMenuProps { | ||
| onDelete: () => void; | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| export function PresetContextMenu({ | ||
| onDelete, | ||
| children, | ||
| }: PresetContextMenuProps) { | ||
| return ( | ||
| <ContextMenu> | ||
| <ContextMenuTrigger asChild>{children}</ContextMenuTrigger> | ||
| <ContextMenuContent className="w-48"> | ||
| <ContextMenuItem onSelect={onDelete} className="text-destructive"> | ||
| Delete Preset | ||
| </ContextMenuItem> | ||
| </ContextMenuContent> | ||
| </ContextMenu> | ||
| ); | ||
| } |
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.
Harden JSON read/write error handling in preset mutations
Both
saveTerminalPresetanddeleteTerminalPresetassume thatconfig.jsonis valid JSON and readable. If the file is manually edited and broken, or a previous write was truncated,JSON.parsewill throw and surface as an unhandled error from the TRPC procedure.Given that
getTerminalPresetsandgetConfigContentalready defend against bad JSON, it would be good to harden the mutation paths similarly so a malformed config doesn’t completely break preset management. For example:and analogously for
deleteTerminalPreset(wrap read/parse/write in a try/catch and return{ success: false }on failure).You might also consider, as a follow‑up:
CONFIG_TEMPLATEto include"terminalPresets": []for a clearer default shape.saveTerminalPresetallows duplicates, anddeleteTerminalPresetremoves all presets with a matchingname.These are not blockers, but tightening the mutation error handling will make the feature more resilient to config corruption.