1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

code reorg

Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
Jim Ehrismann 2021-10-22 18:53:37 -04:00
parent b6fb9c1f64
commit eaf7e10958
3 changed files with 56 additions and 28 deletions

View File

@ -22,3 +22,4 @@
export * from "./port-forward.store";
export * from "./port-forward-item";
export * from "./port-forward-dialog";
export * from "./port-forward-utils";

View File

@ -0,0 +1,54 @@
/**
* Copyright (c) 2021 OpenLens Authors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import { openExternal } from "../utils";
import { Notifications } from "../components/notifications";
import type { ForwardedPort } from "./port-forward-item";
import logger from "../../common/logger";
export function portForwardAddress(portForward: ForwardedPort) {
return `${portForward.protocol ?? "http"}://localhost:${portForward.forwardPort}`;
}
export function openPortForward(portForward: ForwardedPort) {
const browseTo = portForwardAddress(portForward);
openExternal(browseTo)
.catch(error => {
logger.error(`failed to open in browser: ${error}`, {
clusterId: portForward.clusterId,
port: portForward.port,
kind: portForward.kind,
namespace: portForward.namespace,
name: portForward.name,
});
Notifications.error(`Failed to open ${browseTo} in browser`);
}
);
}
export function predictProtocol(name: string) {
return name === "https" ? "https" : "http";
}

View File

@ -22,11 +22,10 @@
import { makeObservable, observable, reaction } from "mobx";
import { ItemStore } from "../../common/item.store";
import { autoBind, createStorage, disposer, getHostedClusterId, openExternal } from "../utils";
import { autoBind, createStorage, disposer, getHostedClusterId } from "../utils";
import { ForwardedPort, PortForwardItem } from "./port-forward-item";
import { apiBase } from "../api";
import { waitUntilFree } from "tcp-port-used";
import { Notifications } from "../components/notifications";
import logger from "../../common/logger";
export class PortForwardStore extends ItemStore<PortForwardItem> {
@ -178,30 +177,4 @@ export async function getPortForwards(): Promise<ForwardedPort[]> {
}
}
export function portForwardAddress(portForward: ForwardedPort) {
return `${portForward.protocol ?? "http"}://localhost:${portForward.forwardPort}`;
}
export function openPortForward(portForward: ForwardedPort) {
const browseTo = portForwardAddress(portForward);
openExternal(browseTo)
.catch(error => {
logger.error(`failed to open in browser: ${error}`, {
clusterId: portForward.clusterId,
port: portForward.port,
kind: portForward.kind,
namespace: portForward.namespace,
name: portForward.name,
});
Notifications.error(`Failed to open ${browseTo} in browser`);
}
);
}
export function predictProtocol(name: string) {
return name === "https" ? "https" : "http";
}
export const portForwardStore = new PortForwardStore();