mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-19 00:15:43 +01:00
* feat: strategies list * feat: dnd * fix: resolve reference issues * feat: configure strategy wip * feat: rearrange list * feat: add debounce and execution plan * feat: add separator * feat: update strategy * fix: feature strategy accordion key * fix: localize parameter update logic * feat: ts conversion * fix: perf issues * feat: production guard * fix: clean up environment list * fix: implement markup hooks for environment list * feat: wip constraints * fix: handle nested data structure reference issue * fix: clone deep on child props * fix: remove constraints check * fix: revert to strategies length * fix: refactor useFeature * feat: cache revalidation * fix: set correct starting tab * fix: reset params on adding new strategy * fix: refactor to use useSWR instead of local cache * fix: check dirty directly from new params * fix: dialogue ts * fix: Clean-up typescript warnings * fix: some more typescript nits * feat: strategy execution * feat: strategy execution for environment * fix: refactor execution separator * fix: remove unused property * fix: add header * fix: 0 value for rollout * fix: update snapshots * fix: remove empty deps * fix: use constant for env type * fix: use default for useFeatureStrategy * fix: update snapshot * Update src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesEnvironmentList/useDeleteStrategyMarkup.tsx Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai> * Update src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategyExecution/FeatureStrategyExecution.tsx Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai> * Update src/component/feature/strategy/EditStrategyModal/general-strategy.jsx Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai> Co-authored-by: Christopher Kolstad <chriswk@getunleash.ai> Co-authored-by: UnleashTeam <79193084+UnleashTeam@users.noreply.github.com>
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import useSWR, { mutate } from 'swr';
|
|
import { useState, useEffect } from 'react';
|
|
|
|
import { formatApiPath } from '../../../../utils/format-path';
|
|
import { IFeatureToggle } from '../../../../interfaces/featureToggle';
|
|
import { defaultFeature } from './defaultFeature';
|
|
|
|
interface IUseFeatureOptions {
|
|
refreshInterval?: number;
|
|
revalidateOnFocus?: boolean;
|
|
revalidateOnReconnect?: boolean;
|
|
revalidateIfStale?: boolean;
|
|
}
|
|
|
|
const useFeature = (
|
|
projectId: string,
|
|
id: string,
|
|
options: IUseFeatureOptions
|
|
) => {
|
|
const fetcher = () => {
|
|
const path = formatApiPath(
|
|
`api/admin/projects/${projectId}/features/${id}`
|
|
);
|
|
return fetch(path, {
|
|
method: 'GET',
|
|
}).then(res => res.json());
|
|
};
|
|
|
|
const FEATURE_CACHE_KEY = `api/admin/projects/${projectId}/features/${id}`;
|
|
|
|
const { data, error } = useSWR<IFeatureToggle>(FEATURE_CACHE_KEY, fetcher, {
|
|
...options,
|
|
});
|
|
|
|
const [loading, setLoading] = useState(!error && !data);
|
|
|
|
const refetch = () => {
|
|
mutate(FEATURE_CACHE_KEY);
|
|
};
|
|
|
|
useEffect(() => {
|
|
setLoading(!error && !data);
|
|
}, [data, error]);
|
|
|
|
return {
|
|
feature: data || defaultFeature,
|
|
error,
|
|
loading,
|
|
refetch,
|
|
FEATURE_CACHE_KEY,
|
|
};
|
|
};
|
|
|
|
export default useFeature;
|