From 67cce9b9f6cee7c8ad9202ec7001e878b0b00cf9 Mon Sep 17 00:00:00 2001 From: kielosz Date: Thu, 4 Aug 2022 21:32:38 +0200 Subject: [PATCH] Filter INITIAL_LOADING_ACTIONS based on products Signed-off-by: kielosz --- plugins/cost-insights/src/hooks/useLoading.tsx | 13 ++++++++++++- plugins/cost-insights/src/utils/loading.ts | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/cost-insights/src/hooks/useLoading.tsx b/plugins/cost-insights/src/hooks/useLoading.tsx index 25599db58e..84828491de 100644 --- a/plugins/cost-insights/src/hooks/useLoading.tsx +++ b/plugins/cost-insights/src/hooks/useLoading.tsx @@ -21,6 +21,7 @@ import React, { SetStateAction, useContext, useEffect, + useMemo, useReducer, useState, } from 'react'; @@ -32,6 +33,7 @@ import { INITIAL_LOADING_ACTIONS, } from '../utils/loading'; import { useBackdropStyles as useStyles } from '../utils/styles'; +import { useConfig } from './useConfig'; export type LoadingContextProps = { state: Loading; @@ -54,7 +56,16 @@ function reducer(prevState: Loading, action: Partial): Loading { export const LoadingProvider = ({ children }: PropsWithChildren<{}>) => { const classes = useStyles(); - const actions = INITIAL_LOADING_ACTIONS; + const { products } = useConfig(); + const actions = useMemo( + () => + INITIAL_LOADING_ACTIONS.filter( + action => + products.length || + action !== DefaultLoadingAction.CostInsightsProducts, + ), + [products], + ); const [state, dispatch] = useReducer(reducer, getDefaultState(actions)); const [isBackdropVisible, setBackdropVisible] = useState(false); diff --git a/plugins/cost-insights/src/utils/loading.ts b/plugins/cost-insights/src/utils/loading.ts index ce02644265..2a453a58f1 100644 --- a/plugins/cost-insights/src/utils/loading.ts +++ b/plugins/cost-insights/src/utils/loading.ts @@ -35,6 +35,7 @@ export enum DefaultLoadingAction { export const INITIAL_LOADING_ACTIONS = [ DefaultLoadingAction.UserGroups, DefaultLoadingAction.CostInsightsInitial, + DefaultLoadingAction.CostInsightsProducts, ]; export const getDefaultState = (loadingActions: string[]): Loading => {