Skip to content

Commit 81d82be

Browse files
committed
frontend: k8s: Add useClusterFromURLVar to get cluster
From the ?cluster= in a URL search paramater. Signed-off-by: René Dudfield <[email protected]>
1 parent 3b2b822 commit 81d82be

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

frontend/src/lib/k8s/index.ts

+11
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,17 @@ export function useClusterGroup(): string[] {
140140
return clusterGroup;
141141
}
142142

143+
/**
144+
* Use the cluster name from the URL query parameters if it's there.
145+
*
146+
* @returns the cluster name from the URL. If no cluster is defined in the URL, undefined is returned.
147+
*/
148+
export function useClusterFromURLVar(): string | undefined {
149+
const location = useLocation();
150+
const searchParams = new URLSearchParams(location.search);
151+
return searchParams.get('cluster') || undefined;
152+
}
153+
143154
export function getVersion(clusterName: string = ''): Promise<StringDict> {
144155
return clusterRequest('/version', { cluster: clusterName || getCluster() });
145156
}

frontend/src/plugin/__snapshots__/pluginLib.snapshot

+1
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@
363363
"default": [Function],
364364
},
365365
"useCluster": [Function],
366+
"useClusterFromURLVar": [Function],
366367
"useClusterGroup": [Function],
367368
"useClustersConf": [Function],
368369
"useClustersVersion": [Function],

0 commit comments

Comments
 (0)