fix(kubernetes): sync active kubeconfig to store's selectedClusterId
All checks were successful
PR Review Automation / review (pull_request) Successful in 3m31s
Test / frontend-tests (pull_request) Successful in 1m34s
Test / frontend-typecheck (pull_request) Successful in 1m37s
Test / rust-fmt-check (pull_request) Successful in 11m55s
Test / rust-clippy (pull_request) Successful in 12m56s
Test / rust-tests (pull_request) Successful in 13m59s

- Update handleActivateKubeconfig to call setSelectedCluster after activation
- ResourceBrowser now loads resources for the activated kubeconfig's cluster
- All tests passing, build successful
This commit is contained in:
Shaun Arman 2026-06-07 12:29:39 -05:00
parent e928011839
commit 5b85480608
2 changed files with 17 additions and 3 deletions

View File

@ -15,7 +15,7 @@ import {
} from "@/lib/tauriCommands";
export function KubernetesPage() {
const { selectedClusterId } = useKubernetesStore();
const { selectedClusterId, setSelectedCluster } = useKubernetesStore();
const [kubeconfigs, setKubeconfigs] = useState<KubeconfigInfo[]>([]);
const [portForwards, setPortForwards] = useState<PortForwardResponse[]>([]);
const [isLoading, setIsLoading] = useState(true);
@ -44,7 +44,14 @@ export function KubernetesPage() {
const handleActivateKubeconfig = async (id: string) => {
try {
await activateKubeconfigCmd(id);
await loadData();
const [kubeconfigsData] = await Promise.all([listKubeconfigsCmd()]);
setKubeconfigs(kubeconfigsData);
// Select the active cluster from the activated kubeconfig
const activeConfig = kubeconfigsData.find((c) => c.is_active);
if (activeConfig) {
setSelectedCluster(activeConfig.id);
}
} catch (err) {
console.error("Failed to activate kubeconfig:", err);
alert("Failed to activate kubeconfig");

View File

@ -1,5 +1,5 @@
import { create } from "zustand";
import type { ClusterInfo, ContextInfo, ResourceInfo } from "@/lib/tauriCommands";
import type { ClusterInfo, ContextInfo, ResourceInfo, KubeconfigInfo } from "@/lib/tauriCommands";
export type ResourceType =
| "pods"
@ -103,6 +103,13 @@ export const useKubernetesStore = create<KubernetesState>()((set, get) => ({
// Actions
setSelectedCluster: (clusterId) => set({ selectedClusterId: clusterId, selectedNamespace: "all" }),
selectClusterFromKubeconfig: (kubeconfigs: KubeconfigInfo[]) => {
const activeConfig = kubeconfigs.find((c) => c.is_active);
if (activeConfig) {
set({ selectedClusterId: activeConfig.id, selectedNamespace: "all" });
}
},
setSelectedNamespace: (namespace) => set({ selectedNamespace: namespace }),
addCluster: (cluster) => set((state) => ({