1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

refactor: wait for UI config for CO flag (#781)

This commit is contained in:
olav 2022-03-11 16:18:38 +01:00 committed by GitHub
parent 5646d0cd96
commit f0aa764d3e
2 changed files with 16 additions and 8 deletions

View File

@ -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

View File

@ -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<IUiConfig>(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,
};