From 957a41b08f79b207bc4b265a3826c24ec11c15f4 Mon Sep 17 00:00:00 2001 From: Terje Karlsen Date: Sun, 8 Oct 2023 11:58:01 +0200 Subject: [PATCH] Navner om toggles til korrekt prefix --- src/komponenter/header/Header.tsx | 2 +- src/server/api-handlers/features.ts | 19 +++++++++++-------- src/server/utils.ts | 2 ++ 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/komponenter/header/Header.tsx b/src/komponenter/header/Header.tsx index 131a84f21..5e4b6dd02 100644 --- a/src/komponenter/header/Header.tsx +++ b/src/komponenter/header/Header.tsx @@ -59,7 +59,7 @@ export const Header = () => { const { language } = useSelector(stateSelector); const { innloggingsstatus, menypunkt } = useSelector(stateSelector); const { authenticated } = innloggingsstatus.data; - const { PARAMS, APP_URL, API_DEKORATOREN_URL, ENV, VARSEL_API_URL } = environment; + const { PARAMS, APP_URL, ENV, VARSEL_API_URL } = environment; const currentFeatureToggles = useSelector(stateSelector).featureToggles; const breadcrumbs = PARAMS.BREADCRUMBS || []; const availableLanguages = PARAMS.AVAILABLE_LANGUAGES || []; diff --git a/src/server/api-handlers/features.ts b/src/server/api-handlers/features.ts index 1c2708807..def38d7e0 100644 --- a/src/server/api-handlers/features.ts +++ b/src/server/api-handlers/features.ts @@ -1,9 +1,8 @@ import { RequestHandler } from 'express'; +import { forceArray } from '../utils'; import { initialize, Unleash } from 'unleash-client'; let unleashInstance: Unleash; -const featurePrefix = 'dekoratoren'; -const expectedFeatures = ['skjermdeling', 'chatbotscript']; type Features = { [key: string]: boolean }; @@ -34,21 +33,25 @@ export const getFeaturesHandler: RequestHandler = async (req, res) => { await initializeUnleash(); } + const { query } = req; + if (!query?.feature) { + return; + } + const requestedFeatures: string[] = forceArray(query.feature); + // Cant easily fetch feature toggles when running locally // so just mock this. if (process.env.NODE_ENV === 'development') { const features = { - skjermdeling: true, - chatbotscript: true, + 'dekoratoren.skjermdeling': true, + 'dekoratoren.chatbotscript': true, }; res.json(features); return; } - console.log(unleashInstance.isEnabled('dekoratoren.skjermdeling')); - - const features = expectedFeatures.reduce((acc: Features, feature: string) => { - acc[feature] = unleashInstance.isEnabled(`${featurePrefix}.${feature}`); + const features = requestedFeatures.reduce((acc: Features, feature: string) => { + acc[feature] = unleashInstance.isEnabled(feature); return acc; }, {}); diff --git a/src/server/utils.ts b/src/server/utils.ts index d14d84747..8666342fb 100644 --- a/src/server/utils.ts +++ b/src/server/utils.ts @@ -252,3 +252,5 @@ export const getSalesforceContainer = (_tagName: string, className: string) => { export const fiveMinutesInSeconds = 5 * 60; export const oneMinuteInSeconds = 60; export const tenSeconds = 10; + +export const forceArray = (value: any) => (Array.isArray(value) ? value : [value]);