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,
|
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,18 +239,18 @@ 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;
|
||||||
const strategyVariant = result.variant;
|
const strategyVariant = result.variant;
|
||||||
if (enabled && strategyVariant) {
|
if (enabled && strategyVariant) {
|
||||||
return strategyVariant;
|
return strategyVariant;
|
||||||
}
|
}
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
return fallback;
|
return fallback;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user