1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: sync enabled and variant status (#4345)

This commit is contained in:
Mateusz Kwasniewski 2023-07-26 12:23:39 +02:00 committed by GitHub
parent 909831db6f
commit 9f35c2187f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 15 deletions

View File

@ -199,7 +199,7 @@ export default class UnleashClient {
context: Context, context: Context,
fallbackVariant?: Variant, fallbackVariant?: Variant,
): Variant { ): Variant {
return this.resolveVariant(name, context, true, fallbackVariant); return this.resolveVariant(name, context, fallbackVariant);
} }
// This function is intended to close an issue in the proxy where feature enabled // This function is intended to close an issue in the proxy where feature enabled
@ -208,16 +208,28 @@ export default class UnleashClient {
forceGetVariant( forceGetVariant(
name: string, name: string,
context: Context, context: Context,
forcedResult: Pick<
FeatureStrategiesEvaluationResult,
'result' | 'variant'
>,
fallbackVariant?: Variant, fallbackVariant?: Variant,
): Variant { ): Variant {
return this.resolveVariant(name, context, false, fallbackVariant); return this.resolveVariant(
name,
context,
fallbackVariant,
forcedResult,
);
} }
private resolveVariant( private resolveVariant(
name: string, name: string,
context: Context, context: Context,
checkToggle: boolean,
fallbackVariant?: Variant, fallbackVariant?: Variant,
forcedResult?: Pick<
FeatureStrategiesEvaluationResult,
'result' | 'variant'
>,
): Variant { ): Variant {
const fallback = fallbackVariant || getDefaultVariant(); const fallback = fallbackVariant || getDefaultVariant();
const feature = this.repository.getToggle(name); const feature = this.repository.getToggle(name);
@ -227,8 +239,9 @@ export default class UnleashClient {
} }
let enabled = true; let enabled = true;
if (checkToggle) { const result =
const result = this.isFeatureEnabled(feature, context, () => forcedResult ??
this.isFeatureEnabled(feature, context, () =>
fallbackVariant ? fallbackVariant.enabled : false, fallbackVariant ? fallbackVariant.enabled : false,
); );
enabled = result.result === true; enabled = result.result === true;
@ -239,7 +252,6 @@ export default class UnleashClient {
if (!enabled) { if (!enabled) {
return fallback; return fallback;
} }
}
if ( if (
!feature.variants || !feature.variants ||
@ -261,7 +273,7 @@ export default class UnleashClient {
return { return {
name: variant.name, name: variant.name,
payload: variant.payload, payload: variant.payload,
enabled: !checkToggle || enabled, enabled,
}; };
} }
} }

View File

@ -104,6 +104,10 @@ export class FeatureEvaluator {
forceGetVariant( forceGetVariant(
name: string, name: string,
forcedResults: Pick<
FeatureStrategiesEvaluationResult,
'result' | 'variant'
>,
context: Context = {}, context: Context = {},
fallbackVariant?: Variant, fallbackVariant?: Variant,
): Variant { ): Variant {
@ -111,6 +115,7 @@ export class FeatureEvaluator {
return this.client.forceGetVariant( return this.client.forceGetVariant(
name, name,
enhancedContext, enhancedContext,
forcedResults,
fallbackVariant, fallbackVariant,
); );
} }

View File

@ -176,7 +176,11 @@ export class PlaygroundService {
data: strategyEvaluationResult.strategies, data: strategyEvaluationResult.strategies,
}, },
projectId: featureProject[feature.name], projectId: featureProject[feature.name],
variant: client.getVariant(feature.name, clientContext), variant: client.forceGetVariant(
feature.name,
strategyEvaluationResult,
clientContext,
),
name: feature.name, name: feature.name,
environment, environment,
context, context,