-
Notifications
You must be signed in to change notification settings - Fork 107
add SSH environments from the composer #274
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
7 commits
Select commit
Hold shift + click to select a range
c4276b0
feat: add SSH environments from the composer
damienrj b768834
fix: namespace remote host selector values
damienrj 00c318d
fix: persist ready manual ssh hosts
damienrj 2bd552c
fix: keep pending SSH dialog dismissible
damienrj d70962e
fix: reject superseded SSH selections
damienrj a5aba65
fix: align SSH host terminology
damienrj 6146d85
fix: explain superseded SSH connections
damienrj 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| import { useEffect, useRef, useState, type FormEvent } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { useRemoteHostStore } from "@/features/remoteHosts/stores/remoteHostStore"; | ||
| import { isRemoteBackendError } from "@/shared/api/remoteHosts"; | ||
| import { Button } from "@/shared/ui/button"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from "@/shared/ui/dialog"; | ||
| import { Input } from "@/shared/ui/input"; | ||
| import { Label } from "@/shared/ui/label"; | ||
|
|
||
| interface AddRemoteHostDialogProps { | ||
| open: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| onConnected: (host: string) => void; | ||
| } | ||
|
|
||
| export function AddRemoteHostDialog({ | ||
| open, | ||
| onOpenChange, | ||
| onConnected, | ||
| }: AddRemoteHostDialogProps) { | ||
| const { t } = useTranslation("chat"); | ||
| const [hostDraft, setHostDraft] = useState(""); | ||
| const [error, setError] = useState<string | null>(null); | ||
| const [pending, setPending] = useState(false); | ||
| const attemptRef = useRef(0); | ||
|
|
||
| useEffect( | ||
| () => () => { | ||
| attemptRef.current += 1; | ||
| }, | ||
| [], | ||
| ); | ||
|
|
||
| const handleOpenChange = (nextOpen: boolean) => { | ||
| onOpenChange(nextOpen); | ||
| if (!nextOpen) { | ||
| // The backend connection may still finish, but closing the dialog must | ||
| // keep that late result from changing the composer's selected host. | ||
| attemptRef.current += 1; | ||
| setHostDraft(""); | ||
| setError(null); | ||
| setPending(false); | ||
| } | ||
| }; | ||
|
|
||
| const handleSubmit = async (event: FormEvent<HTMLFormElement>) => { | ||
| event.preventDefault(); | ||
| if (pending) return; | ||
|
|
||
| const host = hostDraft.trim(); | ||
| if (!host) { | ||
| setError(t("toolbar.remoteHost.add.emptyHost")); | ||
| return; | ||
| } | ||
|
|
||
| setError(null); | ||
| setPending(true); | ||
| const attempt = ++attemptRef.current; | ||
| try { | ||
| const outcome = await useRemoteHostStore | ||
| .getState() | ||
| .ensureHostConnected(host); | ||
| if (attemptRef.current !== attempt) return; | ||
| if (outcome === "superseded") { | ||
| setError(t("toolbar.remoteHost.add.superseded")); | ||
| return; | ||
| } | ||
| onConnected(host); | ||
| handleOpenChange(false); | ||
| } catch (connectionError) { | ||
| if (attemptRef.current !== attempt) return; | ||
| setError( | ||
| isRemoteBackendError(connectionError) | ||
| ? connectionError.message | ||
| : String(connectionError), | ||
| ); | ||
| } finally { | ||
| if (attemptRef.current === attempt) { | ||
| setPending(false); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Dialog open={open} onOpenChange={handleOpenChange}> | ||
| <DialogContent size="md" closeLabel={t("toolbar.remoteHost.add.close")}> | ||
| <form className="contents" onSubmit={handleSubmit}> | ||
| <DialogHeader> | ||
| <DialogTitle>{t("toolbar.remoteHost.add.title")}</DialogTitle> | ||
| <DialogDescription> | ||
| {t("toolbar.remoteHost.add.description")} | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <div className="space-y-2"> | ||
| <Label htmlFor="add-ssh-environment-host"> | ||
| {t("toolbar.remoteHost.add.hostLabel")} | ||
| </Label> | ||
| <Input | ||
| id="add-ssh-environment-host" | ||
| value={hostDraft} | ||
| placeholder={t("toolbar.remoteHost.add.hostPlaceholder")} | ||
| disabled={pending} | ||
| aria-invalid={error ? true : undefined} | ||
| aria-describedby={error ? "add-ssh-environment-error" : undefined} | ||
| onChange={(event) => { | ||
| setHostDraft(event.target.value); | ||
| if (error) setError(null); | ||
| }} | ||
| /> | ||
| {error ? ( | ||
| <p | ||
| id="add-ssh-environment-error" | ||
| className="text-sm text-destructive" | ||
| role="alert" | ||
| > | ||
| {error} | ||
| </p> | ||
| ) : null} | ||
| </div> | ||
| <DialogFooter> | ||
| <Button | ||
| type="button" | ||
| variant="outline" | ||
| onClick={() => handleOpenChange(false)} | ||
| > | ||
| {t("toolbar.remoteHost.add.cancel")} | ||
| </Button> | ||
| <Button | ||
| type="submit" | ||
| feedbackState={pending ? "loading" : "idle"} | ||
| loadingLabel={t("toolbar.remoteHost.status.connecting")} | ||
| preserveWidth | ||
| > | ||
| {t("toolbar.remoteHost.add.connect")} | ||
| </Button> | ||
| </DialogFooter> | ||
| </form> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.