fix: None auth and Host.tsx edit button issues
This commit is contained in:
@@ -31,25 +31,55 @@ export function HostManager({
|
||||
username: string;
|
||||
} | null>(null);
|
||||
const { state: sidebarState } = useSidebar();
|
||||
const prevHostConfigRef = useRef<SSHHost | undefined>(hostConfig);
|
||||
const ignoreNextHostConfigChangeRef = useRef<boolean>(false);
|
||||
const lastProcessedHostIdRef = useRef<number | undefined>(undefined);
|
||||
|
||||
// Update editing host when hostConfig prop changes
|
||||
// Update editing host when hostConfig prop changes (from sidebar edit button)
|
||||
useEffect(() => {
|
||||
if (hostConfig && hostConfig !== prevHostConfigRef.current) {
|
||||
setEditingHost(hostConfig);
|
||||
setActiveTab(initialTab || "add_host");
|
||||
prevHostConfigRef.current = hostConfig;
|
||||
// Skip if we should ignore this change
|
||||
if (ignoreNextHostConfigChangeRef.current) {
|
||||
ignoreNextHostConfigChangeRef.current = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Only process if this is an external edit request (from sidebar)
|
||||
if (hostConfig && initialTab === "add_host") {
|
||||
const currentHostId = hostConfig.id;
|
||||
|
||||
// Open editor if it's a different host OR same host but user is on viewer/credentials tabs
|
||||
if (currentHostId !== lastProcessedHostIdRef.current) {
|
||||
// Different host - always open
|
||||
setEditingHost(hostConfig);
|
||||
setActiveTab("add_host");
|
||||
lastProcessedHostIdRef.current = currentHostId;
|
||||
} else if (
|
||||
activeTab === "host_viewer" ||
|
||||
activeTab === "credentials" ||
|
||||
activeTab === "add_credential"
|
||||
) {
|
||||
// Same host but user manually navigated away - reopen
|
||||
setEditingHost(hostConfig);
|
||||
setActiveTab("add_host");
|
||||
}
|
||||
// If same host and already on add_host tab, do nothing (don't block tab changes)
|
||||
}
|
||||
}, [hostConfig, initialTab]);
|
||||
|
||||
const handleEditHost = (host: SSHHost) => {
|
||||
setEditingHost(host);
|
||||
setActiveTab("add_host");
|
||||
lastProcessedHostIdRef.current = host.id;
|
||||
};
|
||||
|
||||
const handleFormSubmit = () => {
|
||||
// Ignore the next hostConfig change (which will come from ssh-hosts:changed event)
|
||||
ignoreNextHostConfigChangeRef.current = true;
|
||||
setEditingHost(null);
|
||||
setActiveTab("host_viewer");
|
||||
// Clear after a delay so the same host can be edited again
|
||||
setTimeout(() => {
|
||||
lastProcessedHostIdRef.current = undefined;
|
||||
}, 500);
|
||||
};
|
||||
|
||||
const handleEditCredential = (credential: {
|
||||
@@ -70,6 +100,7 @@ export function HostManager({
|
||||
setActiveTab(value);
|
||||
if (value !== "add_host") {
|
||||
setEditingHost(null);
|
||||
isEditingRef.current = false;
|
||||
}
|
||||
if (value !== "add_credential") {
|
||||
setEditingCredential(null);
|
||||
|
||||
@@ -666,8 +666,6 @@ export function HostManagerEditor({
|
||||
// Refresh backend polling to pick up new/updated host configuration
|
||||
const { refreshServerPolling } = await import("@/ui/main-axios.ts");
|
||||
refreshServerPolling();
|
||||
|
||||
form.reset();
|
||||
} catch {
|
||||
toast.error(t("hosts.failedToSaveHost"));
|
||||
} finally {
|
||||
|
||||
@@ -452,7 +452,7 @@ export const Terminal = forwardRef<TerminalHandle, SSHTerminalProps>(
|
||||
) {
|
||||
ws.addEventListener("open", () => {
|
||||
connectionTimeoutRef.current = setTimeout(() => {
|
||||
if (!isConnected && !totpRequired) {
|
||||
if (!isConnected && !totpRequired && !isPasswordPrompt) {
|
||||
if (terminal) {
|
||||
terminal.clear();
|
||||
}
|
||||
|
||||
@@ -108,6 +108,8 @@ export function TabProvider({ children }: TabProviderProps) {
|
||||
t.id === existingTab.id
|
||||
? {
|
||||
...t,
|
||||
// Keep the original title (Host Manager)
|
||||
title: existingTab.title,
|
||||
hostConfig: tabData.hostConfig
|
||||
? { ...tabData.hostConfig }
|
||||
: undefined,
|
||||
@@ -220,6 +222,15 @@ export function TabProvider({ children }: TabProviderProps) {
|
||||
setTabs((prev) =>
|
||||
prev.map((tab) => {
|
||||
if (tab.hostConfig && tab.hostConfig.id === hostId) {
|
||||
// Don't update the title for ssh_manager tabs - they should stay as "Host Manager"
|
||||
if (tab.type === "ssh_manager") {
|
||||
return {
|
||||
...tab,
|
||||
hostConfig: newHostConfig,
|
||||
};
|
||||
}
|
||||
|
||||
// For other tabs (terminal, server, file_manager), update both config and title
|
||||
return {
|
||||
...tab,
|
||||
hostConfig: newHostConfig,
|
||||
|
||||
@@ -350,7 +350,9 @@ export function TopNavbar({
|
||||
tab.type === "admin" ||
|
||||
tab.type === "user_profile") &&
|
||||
isSplitScreenActive);
|
||||
const disableClose = (isSplitScreenActive && isActive) || isSplit;
|
||||
const isHome = tab.type === "home";
|
||||
const disableClose =
|
||||
(isSplitScreenActive && isActive) || isSplit || isHome;
|
||||
|
||||
const isDraggingThisTab = dragState.draggedIndex === index;
|
||||
const isTheDraggedTab = tab.id === dragState.draggedId;
|
||||
@@ -420,6 +422,14 @@ export function TopNavbar({
|
||||
onDragOver={handleDragOver}
|
||||
onDrop={handleDrop}
|
||||
onDragEnd={handleDragEnd}
|
||||
e
|
||||
onMouseDown={(e) => {
|
||||
// Middle mouse button (button === 1)
|
||||
if (e.button === 1 && !disableClose) {
|
||||
e.preventDefault();
|
||||
handleTabClose(tab.id);
|
||||
}
|
||||
}}
|
||||
style={{
|
||||
transform,
|
||||
transition:
|
||||
|
||||
Reference in New Issue
Block a user