mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
added port-forward details
Signed-off-by: Jim Ehrismann <jehrismann@mirantis.com>
This commit is contained in:
parent
5ffa1de7e6
commit
47ac36c904
@ -23,10 +23,11 @@ import type { RouteProps } from "react-router";
|
||||
import { buildURL } from "../utils/buildUrl";
|
||||
|
||||
export const portForwardsRoute: RouteProps = {
|
||||
path: "/port-forwards"
|
||||
path: "/port-forwards/:forwardport?"
|
||||
};
|
||||
|
||||
export interface PortForwardsRouteParams {
|
||||
forwardport: string;
|
||||
}
|
||||
|
||||
export const portForwardsURL = buildURL<PortForwardsRouteParams>(portForwardsRoute.path);
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
.PortForwardDetails {
|
||||
.SubTitle {
|
||||
text-transform: none
|
||||
}
|
||||
|
||||
.status {
|
||||
@include port-forward-status-colors;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
/**
|
||||
* 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 "./port-forward-details.scss";
|
||||
|
||||
import React from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import type { PortForwardItem } from "../../port-forward";
|
||||
import { Drawer, DrawerItem } from "../drawer";
|
||||
import { cssNames } from "../../utils";
|
||||
import { podsApi, serviceApi } from "../../../common/k8s-api/endpoints";
|
||||
import { getDetailsUrl } from "../kube-detail-params";
|
||||
|
||||
interface Props {
|
||||
portForward: PortForwardItem;
|
||||
hideDetails(): void;
|
||||
}
|
||||
|
||||
export class PortForwardDetails extends React.Component<Props> {
|
||||
|
||||
renderContent() {
|
||||
const { portForward } = this.props;
|
||||
const api = {
|
||||
"service": serviceApi,
|
||||
"pod": podsApi
|
||||
}[portForward.kind];
|
||||
|
||||
return (
|
||||
<div>
|
||||
<DrawerItem name="Resource Name">
|
||||
<Link to={getDetailsUrl(api.getUrl({ name: portForward.getName(), namespace: portForward.getNs() }))}>
|
||||
{portForward.getName()}
|
||||
</Link>
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Namespace">
|
||||
{portForward.getNs()}
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Kind">
|
||||
{portForward.getKind()}
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Pod Port">
|
||||
{portForward.getPort()}
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Local Port">
|
||||
{portForward.getForwardPort()}
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Status">
|
||||
<span className={cssNames("status", portForward.getStatus().toLowerCase())}>{portForward.getStatus()}</span>
|
||||
</DrawerItem>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { hideDetails, portForward } = this.props;
|
||||
const title = "Port Forward";
|
||||
|
||||
return (
|
||||
<Drawer
|
||||
className="PortForwardDetails"
|
||||
usePortal={true}
|
||||
open={!!portForward}
|
||||
title={title}
|
||||
onClose={hideDetails}
|
||||
>
|
||||
{this.renderContent()}
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -23,9 +23,13 @@ import "./port-forwards.scss";
|
||||
|
||||
import React from "react";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import type { RouteComponentProps } from "react-router-dom";
|
||||
import { ItemListLayout } from "../item-object-list/item-list-layout";
|
||||
import { PortForwardItem, portForwardStore } from "../../port-forward";
|
||||
import { PortForwardMenu } from "./port-forward-menu";
|
||||
import { PortForwardsRouteParams, portForwardsURL } from "../../../common/routes";
|
||||
import { PortForwardDetails } from "./port-forward-details";
|
||||
import { navigation } from "../../navigation";
|
||||
|
||||
enum columnId {
|
||||
name = "name",
|
||||
@ -36,8 +40,11 @@ enum columnId {
|
||||
status = "status",
|
||||
}
|
||||
|
||||
interface Props extends RouteComponentProps<PortForwardsRouteParams> {
|
||||
}
|
||||
|
||||
@observer
|
||||
export class PortForwards extends React.Component {
|
||||
export class PortForwards extends React.Component<Props> {
|
||||
|
||||
componentDidMount() {
|
||||
disposeOnUnmount(this, [
|
||||
@ -45,6 +52,34 @@ export class PortForwards extends React.Component {
|
||||
]);
|
||||
}
|
||||
|
||||
get selectedPortForward() {
|
||||
const { match: { params: { forwardport } } } = this.props;
|
||||
|
||||
return portForwardStore.items.find(pf => {
|
||||
return pf.getForwardPort() == Number(forwardport);
|
||||
});
|
||||
}
|
||||
|
||||
onDetails = (item: PortForwardItem) => {
|
||||
if (item === this.selectedPortForward) {
|
||||
this.hideDetails();
|
||||
} else {
|
||||
this.showDetails(item);
|
||||
}
|
||||
};
|
||||
|
||||
showDetails = (item: PortForwardItem) => {
|
||||
navigation.push(portForwardsURL({
|
||||
params: {
|
||||
forwardport: String(item.getForwardPort()),
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
||||
hideDetails = () => {
|
||||
navigation.push(portForwardsURL());
|
||||
};
|
||||
|
||||
renderRemoveDialogMessage(selectedItems: PortForwardItem[]) {
|
||||
const forwardPorts = selectedItems.map(item => item.getForwardPort()).join(", ");
|
||||
|
||||
@ -100,7 +135,15 @@ export class PortForwards extends React.Component {
|
||||
customizeRemoveDialog={selectedItems => ({
|
||||
message: this.renderRemoveDialogMessage(selectedItems)
|
||||
})}
|
||||
detailsItem={this.selectedPortForward}
|
||||
onDetails={this.onDetails}
|
||||
/>
|
||||
{this.selectedPortForward && (
|
||||
<PortForwardDetails
|
||||
portForward={this.selectedPortForward}
|
||||
hideDetails={this.hideDetails}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user