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

Fix misleading no metrics message (#5240)

* Add NoMetrics style module

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Add Open Cluster Settings link

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Fine-tune NoMetrics layout

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Add test for clicking Open Settings link

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Add data-testid

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Fixing tests

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Use navigateToEntitySettings instead of broadcastMessage

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>

* Fix test selector

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2022-04-27 15:48:49 +03:00 committed by GitHub
parent 22d2133ac8
commit d1ae30a562
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 70 additions and 5 deletions

View File

@ -39,6 +39,11 @@ utils.describeIf(minikubeReady(TEST_NAMESPACE))("Minikube based tests", () => {
await frame.waitForSelector(`.Menu >> text="Remove"`); await frame.waitForSelector(`.Menu >> text="Remove"`);
}); });
it("opens cluster settings by clicking link in no-metrics area", async () => {
await frame.locator("text=Open cluster settings >> nth=0").click();
await window.waitForSelector(`[data-testid="metrics-header"]`);
});
it( it(
"should navigate around common cluster pages", "should navigate around common cluster pages",

View File

@ -0,0 +1,18 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
.ClusterNoMetrics {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
line-height: 1.7;
flex-grow: 1;
.link {
color: var(--blue);
cursor: pointer;
}
}

View File

@ -3,20 +3,53 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import styles from "./cluster-no-metrics.module.scss";
import React from "react"; import React from "react";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { cssNames } from "../../utils"; import { cssNames } from "../../utils";
import type { NavigateToEntitySettings } from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
import { withInjectables } from "@ogre-tools/injectable-react";
import navigateToEntitySettingsInjectable from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
import hostedClusterInjectable from "../../../common/cluster-store/hosted-cluster.injectable";
export interface ClusterNoMetricsProps { export interface ClusterNoMetricsProps {
className: string; className: string;
} }
export function ClusterNoMetrics({ className }: ClusterNoMetricsProps) { interface Dependencies {
navigateToEntitySettings: NavigateToEntitySettings;
clusterId: string | undefined;
}
export function NonInjectedClusterNoMetrics({ className, navigateToEntitySettings, clusterId }: Dependencies & ClusterNoMetricsProps) {
function openMetricSettingsPage() {
if (clusterId) {
navigateToEntitySettings(clusterId, "metrics");
}
}
return ( return (
<div className={cssNames("ClusterNoMetrics flex column box grow justify-center align-center", className)}> <div className={cssNames(styles.ClusterNoMetrics, className)} data-testid="no-metrics-message">
<Icon material="info"/> <Icon material="info"/>
<p>Metrics are not available due to missing or invalid Prometheus configuration.</p> <p>Metrics are not available due to missing or invalid Prometheus configuration.</p>
<p>Right click cluster icon to open cluster settings.</p> <p><span className={styles.link} onClick={openMetricSettingsPage}>Open cluster settings</span></p>
</div> </div>
); );
} }
export const ClusterNoMetrics = withInjectables<Dependencies, ClusterNoMetricsProps>(
NonInjectedClusterNoMetrics,
{
getProps: (di, props) => {
const cluster = di.inject(hostedClusterInjectable);
return {
navigateToEntitySettings: di.inject(navigateToEntitySettingsInjectable),
clusterId: cluster?.id,
...props,
};
},
},
);

View File

@ -7,7 +7,7 @@
background: var(--contentColor); background: var(--contentColor);
min-height: 280px; min-height: 280px;
text-align: center; text-align: center;
padding: calc(var(--padding) * 2) 0; padding: calc(var(--padding) * 2);
} }
.chart { .chart {
@ -15,3 +15,8 @@
background: var(--contentColor); background: var(--contentColor);
padding: calc(var(--padding) * 2) var(--padding); padding: calc(var(--padding) * 2) var(--padding);
} }
.noMetrics {
display: flex;
flex-grow: 1;
}

View File

@ -232,7 +232,11 @@ const NonInjectedClusterPieCharts = observer(({ clusterOverviewStore }: Dependen
const { memoryCapacity, cpuCapacity, podCapacity } = getMetricLastPoints(clusterOverviewStore.metrics); const { memoryCapacity, cpuCapacity, podCapacity } = getMetricLastPoints(clusterOverviewStore.metrics);
if (!memoryCapacity || !cpuCapacity || !podCapacity) { if (!memoryCapacity || !cpuCapacity || !podCapacity) {
return <ClusterNoMetrics className={styles.empty}/>; return (
<div className={styles.noMetrics}>
<ClusterNoMetrics className={styles.empty}/>
</div>
);
} }
return renderCharts(); return renderCharts();