mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Allow use of ResourceMetrics without IAsyncComputed
Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
parent
8e67ba2e8b
commit
1444c73e47
@ -13,6 +13,7 @@ import { Spinner } from "../spinner";
|
|||||||
import type { MetricsTab } from "../chart/options";
|
import type { MetricsTab } from "../chart/options";
|
||||||
import type { MetricData } from "../../../common/k8s-api/endpoints/metrics.api";
|
import type { MetricData } from "../../../common/k8s-api/endpoints/metrics.api";
|
||||||
import type { IAsyncComputed } from "@ogre-tools/injectable-react";
|
import type { IAsyncComputed } from "@ogre-tools/injectable-react";
|
||||||
|
import { isComputed } from "mobx";
|
||||||
|
|
||||||
export type AtLeastOneMetricTab = [MetricsTab, ...MetricsTab[]];
|
export type AtLeastOneMetricTab = [MetricsTab, ...MetricsTab[]];
|
||||||
|
|
||||||
@ -20,10 +21,14 @@ export interface ResourceMetricsProps<Keys extends string> {
|
|||||||
tabs: AtLeastOneMetricTab;
|
tabs: AtLeastOneMetricTab;
|
||||||
object: KubeObject;
|
object: KubeObject;
|
||||||
className?: string;
|
className?: string;
|
||||||
metrics: IAsyncComputed<Partial<Record<Keys, MetricData>> | null | undefined>;
|
metrics: IAsyncComputed<Partial<Record<Keys, MetricData>> | null | undefined> | Partial<Record<Keys, MetricData>>;
|
||||||
children: React.ReactChild | React.ReactChild[];
|
children: React.ReactChild | React.ReactChild[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isAsyncComputedMetrics<Keys extends string>(metrics: IAsyncComputed<Partial<Record<Keys, MetricData>> | null | undefined> | Partial<Record<Keys, MetricData>>): metrics is IAsyncComputed<Partial<Record<Keys, MetricData>> | null | undefined> {
|
||||||
|
return isComputed((metrics as any).value);
|
||||||
|
}
|
||||||
|
|
||||||
export interface ResourceMetricsValue {
|
export interface ResourceMetricsValue {
|
||||||
object: KubeObject;
|
object: KubeObject;
|
||||||
tab: MetricsTab;
|
tab: MetricsTab;
|
||||||
@ -57,7 +62,9 @@ export function ResourceMetrics<Keys extends string>({ object, tabs, children, c
|
|||||||
value={{
|
value={{
|
||||||
object,
|
object,
|
||||||
tab,
|
tab,
|
||||||
metrics: metrics.value.get(),
|
metrics: isAsyncComputedMetrics(metrics)
|
||||||
|
? metrics.value.get()
|
||||||
|
: metrics,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="graph">
|
<div className="graph">
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user