Add a query param for filtering port forwards by clusterId

Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
Jim Ehrismann committed 2021-11-26 18:12:30 -05:00
1 parent 406f595011
commit 536e9bbd31
2 files changed
+13 -7

No files matched your search

+9 -2
View File
@@ -189,9 +189,10 @@ export class PortForwardRoute {
} }
static async routeAllPortForwards(request: LensApiRequest) { static async routeAllPortForwards(request: LensApiRequest) {
const { response } = request; const { query, response } = request;
const clusterId = query.get("clusterId");
const portForwards: PortForwardArgs[] = PortForward.portForwards.map(f => ( let portForwards: PortForwardArgs[] = PortForward.portForwards.map(f => (
{ {
clusterId: f.clusterId, clusterId: f.clusterId,
kind: f.kind, kind: f.kind,
@@ -203,6 +204,12 @@ export class PortForwardRoute {
}), }),
); );
if (clusterId) {
// filter out any not for this cluster
portForwards = portForwards.filter(pf => pf.clusterId == clusterId);
}
respondJson(response, { portForwards }); respondJson(response, { portForwards });
} }
@@ -60,10 +60,8 @@ export class PortForwardStore extends ItemStore<PortForwardItem> {
loadAll() { loadAll() {
return this.loadItems(async () => { return this.loadItems(async () => {
let portForwards = await getPortForwards(); const portForwards = await getPortForwards(getHostedClusterId());
// filter out any not for this cluster
portForwards = portForwards.filter(pf => pf.clusterId == getHostedClusterId());
this.storage.set(portForwards); this.storage.set(portForwards);
this.reset(); this.reset();
@@ -166,9 +164,10 @@ export async function removePortForward(portForward: ForwardedPort) {
portForwardStore.reset(); portForwardStore.reset();
} }
export async function getPortForwards(): Promise<ForwardedPort[]> { export async function getPortForwards(clusterId?: string): Promise<ForwardedPort[]> {
try { try {
const response = await apiBase.get<PortForwardsResult>(`/pods/port-forwards`); const query = clusterId ? `?clusterId=${clusterId}` : "";
const response = await apiBase.get<PortForwardsResult>(`/pods/port-forwards${query}`);
return response.portForwards; return response.portForwards;
} catch (error) { } catch (error) {