mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add quick namespace filtering to Services view
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
b765ad61ea
commit
fcff986841
@ -1,12 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
|
||||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { asLegacyGlobalForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
|
||||||
import serviceStoreInjectable from "./store.injectable";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated use `di.inject(serviceStoreInjectable)` instead
|
|
||||||
*/
|
|
||||||
export const serviceStore = asLegacyGlobalForExtensionApi(serviceStoreInjectable);
|
|
||||||
@ -25,5 +25,9 @@
|
|||||||
@include service-status-colors;
|
@include service-status-colors;
|
||||||
flex: 0.6;
|
flex: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a.filterNamespace {
|
||||||
|
border-bottom: unset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,10 +9,16 @@ import React from "react";
|
|||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { KubeObjectListLayout } from "../kube-object-list-layout";
|
import { KubeObjectListLayout } from "../kube-object-list-layout";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { serviceStore } from "./legacy-store";
|
|
||||||
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
import { KubeObjectStatusIcon } from "../kube-object-status-icon";
|
||||||
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
|
import { SiblingsInTabLayout } from "../layout/siblings-in-tab-layout";
|
||||||
import { KubeObjectAge } from "../kube-object/age";
|
import { KubeObjectAge } from "../kube-object/age";
|
||||||
|
import { prevDefault } from "../../utils";
|
||||||
|
import type { ServiceStore } from "./store";
|
||||||
|
import type { FilterByNamespace } from "../+namespaces/namespace-select-filter-model/filter-by-namespace.injectable";
|
||||||
|
import type { Service } from "../../../common/k8s-api/endpoints";
|
||||||
|
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||||
|
import filterByNamespaceInjectable from "../+namespaces/namespace-select-filter-model/filter-by-namespace.injectable";
|
||||||
|
import serviceStoreInjectable from "./store.injectable";
|
||||||
|
|
||||||
enum columnId {
|
enum columnId {
|
||||||
name = "name",
|
name = "name",
|
||||||
@ -26,8 +32,27 @@ enum columnId {
|
|||||||
status = "status",
|
status = "status",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const formatExternalIps = (service: Service) => {
|
||||||
|
const externalIps = service.getExternalIps();
|
||||||
|
|
||||||
|
if (externalIps.length > 0) {
|
||||||
|
return externalIps.join(", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (service.spec?.externalName) {
|
||||||
|
return service.spec.externalName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "-";
|
||||||
|
};
|
||||||
|
|
||||||
|
interface Dependencies {
|
||||||
|
serviceStore: ServiceStore;
|
||||||
|
filterByNamespace: FilterByNamespace;
|
||||||
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class Services extends React.Component {
|
class NonInjectedServices extends React.Component<Dependencies> {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<SiblingsInTabLayout>
|
<SiblingsInTabLayout>
|
||||||
@ -35,7 +60,7 @@ export class Services extends React.Component {
|
|||||||
isConfigurable
|
isConfigurable
|
||||||
tableId="network_services"
|
tableId="network_services"
|
||||||
className="Services"
|
className="Services"
|
||||||
store={serviceStore}
|
store={this.props.serviceStore}
|
||||||
sortingCallbacks={{
|
sortingCallbacks={{
|
||||||
[columnId.name]: service => service.getName(),
|
[columnId.name]: service => service.getName(),
|
||||||
[columnId.namespace]: service => service.getNs(),
|
[columnId.namespace]: service => service.getNs(),
|
||||||
@ -64,28 +89,34 @@ export class Services extends React.Component {
|
|||||||
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
|
{ title: "Age", className: "age", sortBy: columnId.age, id: columnId.age },
|
||||||
{ title: "Status", className: "status", sortBy: columnId.status, id: columnId.status },
|
{ title: "Status", className: "status", sortBy: columnId.status, id: columnId.status },
|
||||||
]}
|
]}
|
||||||
renderTableContents={service => {
|
renderTableContents={service => [
|
||||||
const externalIps = service.getExternalIps();
|
service.getName(),
|
||||||
|
<KubeObjectStatusIcon key="icon" object={ service } />,
|
||||||
if (externalIps.length === 0 && service.spec?.externalName) {
|
<a
|
||||||
externalIps.push(service.spec.externalName);
|
key="namespace"
|
||||||
}
|
className="filterNamespace"
|
||||||
|
onClick={ prevDefault(() => this.props.filterByNamespace(service.getNs())) }
|
||||||
return [
|
>
|
||||||
service.getName(),
|
{ service.getNs() }
|
||||||
<KubeObjectStatusIcon key="icon" object={service} />,
|
</a>,
|
||||||
service.getNs(),
|
service.getType(),
|
||||||
service.getType(),
|
service.getClusterIp(),
|
||||||
service.getClusterIp(),
|
service.getPorts().join(", "),
|
||||||
service.getPorts().join(", "),
|
formatExternalIps(service),
|
||||||
externalIps.join(", ") || "-",
|
service.getSelector().map(label => <Badge key={ label } label={ label } />),
|
||||||
service.getSelector().map(label => <Badge key={label} label={label} />),
|
<KubeObjectAge key="age" object={ service } />,
|
||||||
<KubeObjectAge key="age" object={service} />,
|
{ title: service.getStatus(), className: service.getStatus().toLowerCase() },
|
||||||
{ title: service.getStatus(), className: service.getStatus().toLowerCase() },
|
]}
|
||||||
];
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</SiblingsInTabLayout>
|
</SiblingsInTabLayout>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const Services = withInjectables<Dependencies>(NonInjectedServices, {
|
||||||
|
getProps: (di, props) => ({
|
||||||
|
...props,
|
||||||
|
filterByNamespace: di.inject(filterByNamespaceInjectable),
|
||||||
|
serviceStore: di.inject(serviceStoreInjectable),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user