From 08dfb817fade641d3892d5ebabf4047d5ec0f12d Mon Sep 17 00:00:00 2001
From: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
Date: Fri, 22 Dec 2023 09:26:47 -0600
Subject: [PATCH] Change Loading Logic for Metrics Page
Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com>
---
.../screens/Console/Dashboard/Dashboard.tsx | 22 ++++--------
.../Dashboard/Prometheus/PrDashboard.tsx | 35 ++++++-------------
.../Console/Dashboard/dashboardSlice.ts | 10 +++---
portal-ui/src/store.ts | 4 ++-
4 files changed, 25 insertions(+), 46 deletions(-)
diff --git a/portal-ui/src/screens/Console/Dashboard/Dashboard.tsx b/portal-ui/src/screens/Console/Dashboard/Dashboard.tsx
index 045ebd18e2..5c9d25988c 100644
--- a/portal-ui/src/screens/Console/Dashboard/Dashboard.tsx
+++ b/portal-ui/src/screens/Console/Dashboard/Dashboard.tsx
@@ -15,7 +15,6 @@
// along with this program. If not, see .
import React, { Fragment, useEffect, useState } from "react";
-import { Grid, ProgressBar } from "mds";
import { useSelector } from "react-redux";
import { AppState, useAppDispatch } from "../../../store";
import { getUsageAsync } from "./dashboardThunks";
@@ -27,7 +26,7 @@ import HelpMenu from "../HelpMenu";
const Dashboard = () => {
const dispatch = useAppDispatch();
- const [loading, setLoading] = useState(true);
+ const [iniLoad, setIniLoad] = useState(false);
const usage = useSelector((state: AppState) => state.dashboard.usage);
const features = useSelector(selFeatures);
@@ -40,31 +39,22 @@ const Dashboard = () => {
}
useEffect(() => {
- if (loading) {
- setLoading(false);
+ if (!iniLoad) {
+ setIniLoad(true);
dispatch(getUsageAsync());
}
- }, [loading, dispatch]);
+ }, [iniLoad, dispatch]);
useEffect(() => {
dispatch(setHelpName("metrics"));
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
+ }, [dispatch]);
return (
{!hideMenu && (
} />
)}
- {loading ? (
-
-
-
-
-
- ) : (
-
- )}
+
);
};
diff --git a/portal-ui/src/screens/Console/Dashboard/Prometheus/PrDashboard.tsx b/portal-ui/src/screens/Console/Dashboard/Prometheus/PrDashboard.tsx
index 033db0ae01..a7a6d99031 100644
--- a/portal-ui/src/screens/Console/Dashboard/Prometheus/PrDashboard.tsx
+++ b/portal-ui/src/screens/Console/Dashboard/Prometheus/PrDashboard.tsx
@@ -15,7 +15,6 @@
// along with this program. If not, see .
import React, { Fragment, useState } from "react";
-import { useSelector } from "react-redux";
import {
Box,
Button,
@@ -31,7 +30,7 @@ import {
import { IDashboardPanel } from "./types";
import { panelsConfiguration } from "./utils";
import { componentToUse } from "./widgetUtils";
-import { AppState, useAppDispatch } from "../../../../store";
+import { useAppDispatch, useAppSelector } from "../../../../store";
import {
DLayoutColumnProps,
DLayoutRowProps,
@@ -57,16 +56,12 @@ interface IPrDashboard {
const PrDashboard = ({ apiPrefix = "admin", usage }: IPrDashboard) => {
const dispatch = useAppDispatch();
- const loadingUsage = useSelector(
- (state: AppState) => state.dashboard.loadingUsage,
+ const status = useAppSelector((state) => state.dashboard.status);
+ const zoomOpen = useAppSelector((state) => state.dashboard.zoom.openZoom);
+ const zoomWidget = useAppSelector(
+ (state) => state.dashboard.zoom.widgetRender,
);
- const zoomOpen = useSelector(
- (state: AppState) => state.dashboard.zoom.openZoom,
- );
- const zoomWidget = useSelector(
- (state: AppState) => state.dashboard.zoom.widgetRender,
- );
- const features = useSelector(selFeatures);
+ const features = useAppSelector(selFeatures);
const obOnly = !!features?.includes("object-browser-only");
let hideMenu = false;
if (features?.includes("hide-menu")) {
@@ -78,9 +73,7 @@ const PrDashboard = ({ apiPrefix = "admin", usage }: IPrDashboard) => {
const [timeStart, setTimeStart] = useState(null);
const [timeEnd, setTimeEnd] = useState(null);
const panelInformation = panelsConfiguration;
- const [curTab, setCurTab] = useState(
- usage?.advancedMetricsStatus === "not configured" ? "info" : "usage",
- );
+ const [curTab, setCurTab] = useState("info");
const getPanelDetails = (id: number) => {
return panelInformation.find((panel) => panel.id === id);
@@ -186,7 +179,7 @@ const PrDashboard = ({ apiPrefix = "admin", usage }: IPrDashboard) => {
onClick={() => {
dispatch(getUsageAsync());
}}
- disabled={loadingUsage}
+ disabled={status === "loading"}
icon={}
label={"Sync"}
/>
@@ -210,8 +203,8 @@ const PrDashboard = ({ apiPrefix = "admin", usage }: IPrDashboard) => {
tabConfig: { label: "Info", id: "info", disabled: false },
content: (
- {(!usage || loadingUsage) && }
- {usage && !loadingUsage && (
+ {(!usage || status === "loading") && }
+ {usage && status === "idle" && (
{searchBox}
@@ -321,13 +314,7 @@ const PrDashboard = ({ apiPrefix = "admin", usage }: IPrDashboard) => {
},
];
- let tabsOptions: TabItemProps[];
-
- if (!prometheusOptionsDisabled) {
- tabsOptions = [...prometheusTabs, infoTab];
- } else {
- tabsOptions = [infoTab, ...prometheusTabs];
- }
+ let tabsOptions: TabItemProps[] = [infoTab, ...prometheusTabs];
return (
{
builder
.addCase(getUsageAsync.pending, (state) => {
- state.loadingUsage = true;
+ state.status = "loading";
})
.addCase(getUsageAsync.rejected, (state) => {
- state.loadingUsage = false;
+ state.status = "failed";
})
.addCase(getUsageAsync.fulfilled, (state, action) => {
- state.loadingUsage = false;
+ state.status = "idle";
state.usage = action.payload;
});
},
diff --git a/portal-ui/src/store.ts b/portal-ui/src/store.ts
index 48c4a6b549..de966a0f78 100644
--- a/portal-ui/src/store.ts
+++ b/portal-ui/src/store.ts
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
-import { useDispatch } from "react-redux";
+import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux";
import { combineReducers, configureStore } from "@reduxjs/toolkit";
import systemReducer from "./systemSlice";
@@ -69,6 +69,8 @@ if (process.env.NODE_ENV !== "production" && module.hot) {
export type AppState = ReturnType;
export type AppDispatch = typeof store.dispatch;
+export type RootState = ReturnType;
export const useAppDispatch = () => useDispatch();
+export const useAppSelector: TypedUseSelectorHook = useSelector;
export default store;