mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-31 15:45:23 +00:00
fix: manage tab refetches before giving up on a host or credential it cannot find
This commit is contained in:
1 parent
2f975f433e
commit
5e7f69456b
2 files changed
+43
-12
No files matched your search
@@ -2477,6 +2477,7 @@
|
|||||||
"collapse": "Collapse",
|
"collapse": "Collapse",
|
||||||
"expand": "Expand",
|
"expand": "Expand",
|
||||||
"cannotBeUndone": "This cannot be undone.",
|
"cannotBeUndone": "This cannot be undone.",
|
||||||
|
"hostNotFound": "Couldn't find that host. Try refreshing the list.",
|
||||||
"hostCount_one": "{{count}} host",
|
"hostCount_one": "{{count}} host",
|
||||||
"hostCount_other": "{{count}} hosts",
|
"hostCount_other": "{{count}} hosts",
|
||||||
"credentialCount_one": "{{count}} credential",
|
"credentialCount_one": "{{count}} credential",
|
||||||
|
|||||||
+42
-12
@@ -20,6 +20,7 @@ import {
|
|||||||
type SSHHostWithStatus,
|
type SSHHostWithStatus,
|
||||||
} from "@/main-axios";
|
} from "@/main-axios";
|
||||||
import { getFolderDefaultsId } from "@/api/host-defaults-api";
|
import { getFolderDefaultsId } from "@/api/host-defaults-api";
|
||||||
|
import { invalidateHostsAndStatusCaches } from "@/lib/hosts-request-cache";
|
||||||
import { registerTabCloseGuard } from "@/shell/tab-close-guards";
|
import { registerTabCloseGuard } from "@/shell/tab-close-guards";
|
||||||
import { HostEditor } from "@/sidebar/HostEditor";
|
import { HostEditor } from "@/sidebar/HostEditor";
|
||||||
import { CredentialEditorView } from "@/sidebar/CredentialEditorView";
|
import { CredentialEditorView } from "@/sidebar/CredentialEditorView";
|
||||||
@@ -109,12 +110,20 @@ export function ManageTab() {
|
|||||||
|
|
||||||
const reloadHosts = useCallback(() => {
|
const reloadHosts = useCallback(() => {
|
||||||
return getSSHHosts()
|
return getSSHHosts()
|
||||||
.then((raw) => setHosts(raw.map(sshHostToHost)))
|
.then((raw) => {
|
||||||
|
const list = raw.map(sshHostToHost);
|
||||||
|
hostsRef.current = list;
|
||||||
|
setHosts(list);
|
||||||
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
const reloadCredentials = useCallback(() => {
|
const reloadCredentials = useCallback(() => {
|
||||||
return getCredentials()
|
return getCredentials()
|
||||||
.then((res) => setCredentials(mapCredentials(res)))
|
.then((res) => {
|
||||||
|
const list = mapCredentials(res);
|
||||||
|
credentialsRef.current = list;
|
||||||
|
setCredentials(list);
|
||||||
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -207,17 +216,30 @@ export function ManageTab() {
|
|||||||
if (!(await confirmDiscard())) return;
|
if (!(await confirmDiscard())) return;
|
||||||
await loaded.current;
|
await loaded.current;
|
||||||
if (request.kind === "host") {
|
if (request.kind === "host") {
|
||||||
const host = request.hostId
|
const find = () =>
|
||||||
? (hostsRef.current.find((h) => h.id === request.hostId) ?? null)
|
hostsRef.current.find((h) => h.id === request.hostId) ?? null;
|
||||||
: null;
|
let host = request.hostId ? find() : null;
|
||||||
if (request.hostId && !host) return;
|
// Our list can lag the sidebar's, so refetch once before giving up.
|
||||||
|
if (request.hostId && !host) {
|
||||||
|
invalidateHostsAndStatusCaches();
|
||||||
|
await reloadHosts();
|
||||||
|
host = find();
|
||||||
|
if (!host) {
|
||||||
|
toast.error(t("manage.hostNotFound"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
openHost(host, request.draft);
|
openHost(host, request.draft);
|
||||||
} else if (request.kind === "credential") {
|
} else if (request.kind === "credential") {
|
||||||
const credential = request.credentialId
|
const find = () =>
|
||||||
? (credentialsRef.current.find(
|
credentialsRef.current.find(
|
||||||
(c) => c.id === request.credentialId,
|
(c) => String(c.id) === String(request.credentialId),
|
||||||
) ?? null)
|
) ?? null;
|
||||||
: null;
|
let credential = request.credentialId ? find() : null;
|
||||||
|
if (request.credentialId && !credential) {
|
||||||
|
await reloadCredentials();
|
||||||
|
credential = find();
|
||||||
|
}
|
||||||
void openCredential(credential);
|
void openCredential(credential);
|
||||||
} else if (request.kind === "defaults") {
|
} else if (request.kind === "defaults") {
|
||||||
void openDefaults(request);
|
void openDefaults(request);
|
||||||
@@ -227,7 +249,15 @@ export function ManageTab() {
|
|||||||
setMode(request.mode);
|
setMode(request.mode);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[confirmDiscard, openHost, openCredential, openDefaults],
|
[
|
||||||
|
confirmDiscard,
|
||||||
|
openHost,
|
||||||
|
openCredential,
|
||||||
|
openDefaults,
|
||||||
|
reloadHosts,
|
||||||
|
reloadCredentials,
|
||||||
|
t,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
// The request that opened this tab was parked before it mounted.
|
// The request that opened this tab was parked before it mounted.
|
||||||
|
|||||||
Reference in new issue
Block a user