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 { MetricData } from "../../../common/k8s-api/endpoints/metrics.api";
|
||||
import type { IAsyncComputed } from "@ogre-tools/injectable-react";
|
||||
import { isComputed } from "mobx";
|
||||
|
||||
export type AtLeastOneMetricTab = [MetricsTab, ...MetricsTab[]];
|
||||
|
||||
@ -20,10 +21,14 @@ export interface ResourceMetricsProps<Keys extends string> {
|
||||
tabs: AtLeastOneMetricTab;
|
||||
object: KubeObject;
|
||||
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[];
|
||||
}
|
||||
|
||||
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 {
|
||||
object: KubeObject;
|
||||
tab: MetricsTab;
|
||||
@ -57,7 +62,9 @@ export function ResourceMetrics<Keys extends string>({ object, tabs, children, c
|
||||
value={{
|
||||
object,
|
||||
tab,
|
||||
metrics: metrics.value.get(),
|
||||
metrics: isAsyncComputedMetrics(metrics)
|
||||
? metrics.value.get()
|
||||
: metrics,
|
||||
}}
|
||||
>
|
||||
<div className="graph">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user