From 6d4250279220f098f6091aabe559776aed157cda Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Fri, 15 Oct 2021 11:43:11 +0200 Subject: [PATCH] Add default strategy type to strategy hook - Fixes the missing sidebar while loading the strategy types Trello: https://trello.com/c/WJk8bI8l/490-feature-strategies-loading-state --- .../getters/useStrategies/useStrategies.ts | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/frontend/src/hooks/api/getters/useStrategies/useStrategies.ts b/frontend/src/hooks/api/getters/useStrategies/useStrategies.ts index c1d005e560..5964227c30 100644 --- a/frontend/src/hooks/api/getters/useStrategies/useStrategies.ts +++ b/frontend/src/hooks/api/getters/useStrategies/useStrategies.ts @@ -6,13 +6,29 @@ import handleErrorResponses from '../httpErrorResponseHandler'; export const STRATEGIES_CACHE_KEY = 'api/admin/strategies'; +const flexibleRolloutStrategy: IStrategy = { + deprecated: false, + name: 'flexibleRollout', + displayName: 'Gradual rollout', + editable: false, + description: 'Roll out to a percentage of your userbase, and ensure that the experience is the same for the user on each visit.', + parameters: [{ + name: 'rollout', type: 'percentage', description: '', required: false + }, { + name: 'stickiness', + type: 'string', + description: 'Used to defined stickiness', + required: true + }, { name: 'groupId', type: 'string', description: '', required: true }] +}; + const useStrategies = () => { const fetcher = () => { const path = formatApiPath(`api/admin/strategies`); return fetch(path, { method: 'GET', - credentials: 'include', + credentials: 'include' }).then(handleErrorResponses('Strategies')).then(res => res.json()); }; @@ -31,10 +47,10 @@ const useStrategies = () => { }, [data, error]); return { - strategies: data?.strategies || [], + strategies: data?.strategies || [flexibleRolloutStrategy], error, loading, - refetch, + refetch }; };