Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Navner om toggles til korrekt prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeofnorway committed Oct 8, 2023
1 parent 38c7212 commit 957a41b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/komponenter/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [];
Expand Down
19 changes: 11 additions & 8 deletions src/server/api-handlers/features.ts
Original file line number Diff line number Diff line change
@@ -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 };

Expand Down Expand Up @@ -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;
}, {});

Expand Down
2 changes: 2 additions & 0 deletions src/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

0 comments on commit 957a41b

Please sign in to comment.