diff --git a/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx b/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx index 48ab30a6d8..265cb7b180 100644 --- a/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx +++ b/frontend/src/component/feature/FeatureStrategy/FeatureStrategyForm/FeatureStrategyForm.tsx @@ -52,9 +52,14 @@ export const FeatureStrategyForm = ({ const StrategyIcon = getFeatureStrategyIcon(strategy.name ?? ''); const strategyName = formatStrategyName(strategy.name ?? ''); const { hasAccess } = useContext(AccessContext); - const { uiConfig } = useUiConfig(); const { push } = useHistory(); + const { + uiConfig, + error: uiConfigError, + loading: uiConfigLoading, + } = useUiConfig(); + const onCancel = () => { push(formatFeaturePath(feature.project, feature.name)); }; @@ -74,6 +79,15 @@ export const FeatureStrategyForm = ({ strategy.constraints ); + if (uiConfigError) { + throw uiConfigError; + } + + // Wait for uiConfig to load for the correct uiConfig.flags.CO value. + if (uiConfigLoading) { + return null; + } + // TODO(olav): Remove uiConfig.flags.CO when new constraints are released. const FeatureStrategyConstraintsImplementation = uiConfig.flags.CO ? FeatureStrategyConstraints2 diff --git a/frontend/src/hooks/api/getters/useUiConfig/useUiConfig.ts b/frontend/src/hooks/api/getters/useUiConfig/useUiConfig.ts index 34807618af..fceabf02fa 100644 --- a/frontend/src/hooks/api/getters/useUiConfig/useUiConfig.ts +++ b/frontend/src/hooks/api/getters/useUiConfig/useUiConfig.ts @@ -1,5 +1,4 @@ import useSWR, { mutate, SWRConfiguration } from 'swr'; -import { useState, useEffect } from 'react'; import { formatApiPath } from '../../../../utils/format-path'; import { defaultValue } from './defaultValue'; import { IUiConfig } from '../../../../interfaces/uiConfig'; @@ -20,7 +19,6 @@ const useUiConfig = (options: SWRConfiguration = {}) => { }; const { data, error } = useSWR(REQUEST_KEY, fetcher, options); - const [loading, setLoading] = useState(!error && !data); const refetch = () => { mutate(REQUEST_KEY); @@ -35,14 +33,10 @@ const useUiConfig = (options: SWRConfiguration = {}) => { return true; }; - useEffect(() => { - setLoading(!error && !data); - }, [data, error]); - return { uiConfig: { ...defaultValue, ...data }, + loading: !error && !data, error, - loading, refetch, isOss, };