Skip to content

Commit

Permalink
frontend: k8s: Add useDetailsSingleCluster to get cluster
Browse files Browse the repository at this point in the history
From the ?cluster= in a URL search paramater.

Signed-off-by: René Dudfield <[email protected]>
  • Loading branch information
illume committed Dec 30, 2024
1 parent f313f60 commit 5925769
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions frontend/src/lib/k8s/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ export function useClusterGroup(): string[] {
return clusterGroup;
}

/**
* Use the cluster name from the URL query parameters if it's there.
*
* @returns the cluster name from the URL. If no cluster is defined in the URL, undefined is returned.
*/
export function useDetailsSingleCluster(): string | undefined {
const location = useLocation();
const searchParams = new URLSearchParams(location.search);
return searchParams.get('cluster') || undefined;
}

export function getVersion(clusterName: string = ''): Promise<StringDict> {
return clusterRequest('/version', { cluster: clusterName || getCluster() });
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/plugin/__snapshots__/pluginLib.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@
"default": [Function],
},
"useCluster": [Function],
"useClusterFromURLVar": [Function],
"useClusterGroup": [Function],
"useClustersConf": [Function],
"useClustersVersion": [Function],
Expand Down

0 comments on commit 5925769

Please sign in to comment.