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

Fix KubeObjectDetails drawer not working for Cluster scoped resources (#5954)

- Fix not displaying spinner while object is not defined

- Fix not displaying loading error if object is not defined

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-08-01 03:25:29 -07:00 committed by GitHub
parent 485f213461
commit 07568839f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 33 deletions

View File

@ -355,7 +355,7 @@ export abstract class KubeObjectStore<
async loadFromPath(resourcePath: string) {
const { namespace, name } = parseKubeApi(resourcePath);
assert(name && namespace, "Both name and namesapce must be part of resourcePath");
assert(name, "name must be part of resourcePath");
return this.load({ name, namespace });
}

View File

@ -8,7 +8,7 @@ import "./kube-object-details.scss";
import React from "react";
import { disposeOnUnmount, observer } from "mobx-react";
import type { IComputedValue } from "mobx";
import { computed, observable, reaction, makeObservable } from "mobx";
import { observable, reaction, makeObservable } from "mobx";
import { Drawer } from "../drawer";
import type { KubeObject } from "../../../common/k8s-api/kube-object";
import { Spinner } from "../spinner";
@ -51,11 +51,11 @@ class NonInjectedKubeObjectDetails extends React.Component<Dependencies> {
makeObservable(this);
}
@computed get path() {
get path() {
return this.props.kubeDetailsUrlParam.get();
}
@computed get object() {
get object() {
return this.props.kubeObject.get();
}
@ -102,10 +102,8 @@ class NonInjectedKubeObjectDetails extends React.Component<Dependencies> {
}
renderContents(object: KubeObject) {
const { isLoading, loadingError } = this;
const details = this.props.detailComponents.get();
const getContents = () => {
if (details.length === 0) {
const crd = this.props.customResourceDefinitionStore.getByObject(object);
@ -130,15 +128,6 @@ class NonInjectedKubeObjectDetails extends React.Component<Dependencies> {
return details.map((DetailComponent, index) => (
<DetailComponent key={index} object={object} />
));
};
return (
<>
{isLoading && <Spinner center/>}
{loadingError && <div className="box center">{loadingError}</div>}
{getContents()}
</>
);
}
render() {
@ -152,6 +141,8 @@ class NonInjectedKubeObjectDetails extends React.Component<Dependencies> {
toolbar={object && <KubeObjectMenu object={object} toolbar={true}/>}
onClose={this.props.hideDetails}
>
{isLoading && <Spinner center/>}
{loadingError && <div className="box center">{loadingError}</div>}
{object && this.renderContents(object)}
</Drawer>
);