Skip to content

Commit

Permalink
[dashboard] Fix feature flag context evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
easyCZ authored and roboquat committed Nov 25, 2022
1 parent 263699c commit 44ac39f
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions components/dashboard/src/contexts/FeatureFlagContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,37 @@ const FeatureFlagContextProvider: React.FC = ({ children }) => {
personalAccessTokensEnabled: { defaultValue: false, setter: setPersonalAccessTokensEnabled },
slow_database: { defaultValue: false, setter: setUseSlowDatabase },
};

for (const [flagName, config] of Object.entries(featureFlags)) {
if (teams) {
for (const team of teams) {
const value = async () => {
// First check if the flag is non-default for any of the teams
for (const team of teams || []) {
const flagValue = await getExperimentsClient().getValueAsync(flagName, config.defaultValue, {
user,
projectId: project?.id,
teamId: team.id,
teamName: team?.name,
});

// We got an explicit override value from ConfigCat
if (flagValue !== config.defaultValue) {
config.setter(flagValue);
return;
// We got a non-default value, this must be configured by ConfigCat
return flagValue;
}
}
}

const flagValue = await getExperimentsClient().getValueAsync(flagName, config.defaultValue, {
user,
projectId: project?.id,
teamId: team?.id,
teamName: team?.name,
});
config.setter(flagValue);
// Second evaluate if the flag is enabled for the user
const valueForUser = await getExperimentsClient().getValueAsync(flagName, config.defaultValue, {
user,
projectId: project?.id,
teamId: team?.id,
teamName: team?.name,
});

return valueForUser;
};

const val = await value();
config.setter(val);
}
})();
}, [user, teams, team, project]);
Expand Down

0 comments on commit 44ac39f

Please sign in to comment.