1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/renderer/components/+namespaces/namespace-details.tsx
Jari Kolehmainen 035dd470ef
Refactor watches to use native k8s api (#2095)
* fix lint

Signed-off-by: Roman <ixrock@gmail.com>

* fixes & refactoring

Signed-off-by: Roman <ixrock@gmail.com>

* fix lint, micro-refactoring

Signed-off-by: Roman <ixrock@gmail.com>

* more refactoring, clean up, responding to comments

Signed-off-by: Roman <ixrock@gmail.com>

* fix: remove extra check for cluster.allowedApi from processing buffered watch-api events

Signed-off-by: Roman <ixrock@gmail.com>

* refactoring, detaching NamespaceStore from KubeObjectStore

Signed-off-by: Roman <ixrock@gmail.com>

* fix: wait for contextReady in NamespaceStore

Signed-off-by: Roman <ixrock@gmail.com>

* refactoring & fixes

Signed-off-by: Roman <ixrock@gmail.com>

* fix lint

Signed-off-by: Roman <ixrock@gmail.com>

* fixes: reloading context stores on NamespaceSelect-change

Signed-off-by: Roman <ixrock@gmail.com>

* optimize loading all resources when "all namespaces" selected -> single request per resource (when have rights)

Signed-off-by: Roman <ixrock@gmail.com>

* use native k8s api watches

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* retry watch when it makes sense

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* workaround for browser connection limits

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* cleanup

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* cleanup

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* use always random subdomain for getResponse

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* resubscribe stores on contextNamespace change

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* fix

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

* modify watch event before calling callback

Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>

Co-authored-by: Roman <ixrock@gmail.com>
2021-02-09 15:31:15 +02:00

85 lines
2.5 KiB
TypeScript

import "./namespace-details.scss";
import React from "react";
import { computed } from "mobx";
import { observer } from "mobx-react";
import { DrawerItem } from "../drawer";
import { cssNames } from "../../utils";
import { Namespace } from "../../api/endpoints";
import { getDetailsUrl, KubeObjectDetailsProps } from "../kube-object";
import { Link } from "react-router-dom";
import { Spinner } from "../spinner";
import { resourceQuotaStore } from "../+config-resource-quotas/resource-quotas.store";
import { KubeObjectMeta } from "../kube-object/kube-object-meta";
import { kubeObjectDetailRegistry } from "../../api/kube-object-detail-registry";
import { limitRangeStore } from "../+config-limit-ranges/limit-ranges.store";
interface Props extends KubeObjectDetailsProps<Namespace> {
}
@observer
export class NamespaceDetails extends React.Component<Props> {
@computed get quotas() {
const namespace = this.props.object.getName();
return resourceQuotaStore.getAllByNs(namespace);
}
@computed get limitranges() {
const namespace = this.props.object.getName();
return limitRangeStore.getAllByNs(namespace);
}
componentDidMount() {
resourceQuotaStore.reloadAll();
limitRangeStore.reloadAll();
}
render() {
const { object: namespace } = this.props;
if (!namespace) return;
const status = namespace.getStatus();
return (
<div className="NamespaceDetails">
<KubeObjectMeta object={namespace}/>
<DrawerItem name="Status">
<span className={cssNames("status", status.toLowerCase())}>{status}</span>
</DrawerItem>
<DrawerItem name="Resource Quotas" className="quotas flex align-center">
{!this.quotas && resourceQuotaStore.isLoading && <Spinner/>}
{this.quotas.map(quota => {
return (
<Link key={quota.getId()} to={getDetailsUrl(quota.selfLink)}>
{quota.getName()}
</Link>
);
})}
</DrawerItem>
<DrawerItem name={`Limit Ranges`}>
{!this.limitranges && limitRangeStore.isLoading && <Spinner/>}
{this.limitranges.map(limitrange => {
return (
<Link key={limitrange.getId()} to={getDetailsUrl(limitrange.selfLink)}>
{limitrange.getName()}
</Link>
);
})}
</DrawerItem>
</div>
);
}
}
kubeObjectDetailRegistry.add({
kind: "Namespace",
apiVersions: ["v1"],
components: {
Details: (props) => <NamespaceDetails {...props} />
}
});