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:
parent
909831db6f
commit
9f35c2187f
@ -199,7 +199,7 @@ export default class UnleashClient {
|
||||
context: Context,
|
||||
fallbackVariant?: 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
|
||||
@ -208,16 +208,28 @@ export default class UnleashClient {
|
||||
forceGetVariant(
|
||||
name: string,
|
||||
context: Context,
|
||||
forcedResult: Pick<
|
||||
FeatureStrategiesEvaluationResult,
|
||||
'result' | 'variant'
|
||||
>,
|
||||
fallbackVariant?: Variant,
|
||||
): Variant {
|
||||
return this.resolveVariant(name, context, false, fallbackVariant);
|
||||
return this.resolveVariant(
|
||||
name,
|
||||
context,
|
||||
fallbackVariant,
|
||||
forcedResult,
|
||||
);
|
||||
}
|
||||
|
||||
private resolveVariant(
|
||||
name: string,
|
||||
context: Context,
|
||||
checkToggle: boolean,
|
||||
fallbackVariant?: Variant,
|
||||
forcedResult?: Pick<
|
||||
FeatureStrategiesEvaluationResult,
|
||||
'result' | 'variant'
|
||||
>,
|
||||
): Variant {
|
||||
const fallback = fallbackVariant || getDefaultVariant();
|
||||
const feature = this.repository.getToggle(name);
|
||||
@ -227,18 +239,18 @@ export default class UnleashClient {
|
||||
}
|
||||
|
||||
let enabled = true;
|
||||
if (checkToggle) {
|
||||
const result = this.isFeatureEnabled(feature, context, () =>
|
||||
const result =
|
||||
forcedResult ??
|
||||
this.isFeatureEnabled(feature, context, () =>
|
||||
fallbackVariant ? fallbackVariant.enabled : false,
|
||||
);
|
||||
enabled = result.result === true;
|
||||
const strategyVariant = result.variant;
|
||||
if (enabled && strategyVariant) {
|
||||
return strategyVariant;
|
||||
}
|
||||
if (!enabled) {
|
||||
return fallback;
|
||||
}
|
||||
enabled = result.result === true;
|
||||
const strategyVariant = result.variant;
|
||||
if (enabled && strategyVariant) {
|
||||
return strategyVariant;
|
||||
}
|
||||
if (!enabled) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
if (
|
||||
@ -261,7 +273,7 @@ export default class UnleashClient {
|
||||
return {
|
||||
name: variant.name,
|
||||
payload: variant.payload,
|
||||
enabled: !checkToggle || enabled,
|
||||
enabled,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +104,10 @@ export class FeatureEvaluator {
|
||||
|
||||
forceGetVariant(
|
||||
name: string,
|
||||
forcedResults: Pick<
|
||||
FeatureStrategiesEvaluationResult,
|
||||
'result' | 'variant'
|
||||
>,
|
||||
context: Context = {},
|
||||
fallbackVariant?: Variant,
|
||||
): Variant {
|
||||
@ -111,6 +115,7 @@ export class FeatureEvaluator {
|
||||
return this.client.forceGetVariant(
|
||||
name,
|
||||
enhancedContext,
|
||||
forcedResults,
|
||||
fallbackVariant,
|
||||
);
|
||||
}
|
||||
|
@ -176,7 +176,11 @@ export class PlaygroundService {
|
||||
data: strategyEvaluationResult.strategies,
|
||||
},
|
||||
projectId: featureProject[feature.name],
|
||||
variant: client.getVariant(feature.name, clientContext),
|
||||
variant: client.forceGetVariant(
|
||||
feature.name,
|
||||
strategyEvaluationResult,
|
||||
clientContext,
|
||||
),
|
||||
name: feature.name,
|
||||
environment,
|
||||
context,
|
||||
|
Loading…
Reference in New Issue
Block a user