mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
refactor: wait for UI config for CO flag (#781)
This commit is contained in:
parent
5646d0cd96
commit
f0aa764d3e
@ -52,9 +52,14 @@ export const FeatureStrategyForm = ({
|
|||||||
const StrategyIcon = getFeatureStrategyIcon(strategy.name ?? '');
|
const StrategyIcon = getFeatureStrategyIcon(strategy.name ?? '');
|
||||||
const strategyName = formatStrategyName(strategy.name ?? '');
|
const strategyName = formatStrategyName(strategy.name ?? '');
|
||||||
const { hasAccess } = useContext(AccessContext);
|
const { hasAccess } = useContext(AccessContext);
|
||||||
const { uiConfig } = useUiConfig();
|
|
||||||
const { push } = useHistory();
|
const { push } = useHistory();
|
||||||
|
|
||||||
|
const {
|
||||||
|
uiConfig,
|
||||||
|
error: uiConfigError,
|
||||||
|
loading: uiConfigLoading,
|
||||||
|
} = useUiConfig();
|
||||||
|
|
||||||
const onCancel = () => {
|
const onCancel = () => {
|
||||||
push(formatFeaturePath(feature.project, feature.name));
|
push(formatFeaturePath(feature.project, feature.name));
|
||||||
};
|
};
|
||||||
@ -74,6 +79,15 @@ export const FeatureStrategyForm = ({
|
|||||||
strategy.constraints
|
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.
|
// TODO(olav): Remove uiConfig.flags.CO when new constraints are released.
|
||||||
const FeatureStrategyConstraintsImplementation = uiConfig.flags.CO
|
const FeatureStrategyConstraintsImplementation = uiConfig.flags.CO
|
||||||
? FeatureStrategyConstraints2
|
? FeatureStrategyConstraints2
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import useSWR, { mutate, SWRConfiguration } from 'swr';
|
import useSWR, { mutate, SWRConfiguration } from 'swr';
|
||||||
import { useState, useEffect } from 'react';
|
|
||||||
import { formatApiPath } from '../../../../utils/format-path';
|
import { formatApiPath } from '../../../../utils/format-path';
|
||||||
import { defaultValue } from './defaultValue';
|
import { defaultValue } from './defaultValue';
|
||||||
import { IUiConfig } from '../../../../interfaces/uiConfig';
|
import { IUiConfig } from '../../../../interfaces/uiConfig';
|
||||||
@ -20,7 +19,6 @@ const useUiConfig = (options: SWRConfiguration = {}) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const { data, error } = useSWR<IUiConfig>(REQUEST_KEY, fetcher, options);
|
const { data, error } = useSWR<IUiConfig>(REQUEST_KEY, fetcher, options);
|
||||||
const [loading, setLoading] = useState(!error && !data);
|
|
||||||
|
|
||||||
const refetch = () => {
|
const refetch = () => {
|
||||||
mutate(REQUEST_KEY);
|
mutate(REQUEST_KEY);
|
||||||
@ -35,14 +33,10 @@ const useUiConfig = (options: SWRConfiguration = {}) => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setLoading(!error && !data);
|
|
||||||
}, [data, error]);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
uiConfig: { ...defaultValue, ...data },
|
uiConfig: { ...defaultValue, ...data },
|
||||||
|
loading: !error && !data,
|
||||||
error,
|
error,
|
||||||
loading,
|
|
||||||
refetch,
|
refetch,
|
||||||
isOss,
|
isOss,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user