mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-10 01:16:39 +02: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>
41 lines
1008 B
TypeScript
41 lines
1008 B
TypeScript
import useSWR, { mutate } from 'swr';
|
|
import { useEffect, useState } from 'react';
|
|
import { formatApiPath } from '../../../../utils/format-path';
|
|
import { IStrategy } from '../../../../interfaces/strategy';
|
|
|
|
export const STRATEGIES_CACHE_KEY = 'api/admin/strategies';
|
|
|
|
const useStrategies = () => {
|
|
const fetcher = () => {
|
|
const path = formatApiPath(`api/admin/strategies`);
|
|
|
|
return fetch(path, {
|
|
method: 'GET',
|
|
credentials: 'include',
|
|
}).then(res => res.json());
|
|
};
|
|
|
|
const { data, error } = useSWR<{ strategies: IStrategy[] }>(
|
|
STRATEGIES_CACHE_KEY,
|
|
fetcher
|
|
);
|
|
const [loading, setLoading] = useState(!error && !data);
|
|
|
|
const refetch = () => {
|
|
mutate(STRATEGIES_CACHE_KEY);
|
|
};
|
|
|
|
useEffect(() => {
|
|
setLoading(!error && !data);
|
|
}, [data, error]);
|
|
|
|
return {
|
|
strategies: data?.strategies || [],
|
|
error,
|
|
loading,
|
|
refetch,
|
|
};
|
|
};
|
|
|
|
export default useStrategies;
|