mirror of
https://github.com/Unleash/unleash.git
synced 2024-11-01 19:07:38 +01:00
3193423d2d
Project scoped stickiness <!-- Thanks for creating a PR! To make it easier for reviewers and everyone else to understand what your changes relate to, please add some relevant content to the headings below. Feel free to ignore or delete sections that you don't think are relevant. Thank you! ❤️ --> Adds `projectScopedStickiness` flag to experimental.ts Refactor Stickiness select for reusability Modify FlexibleStrategy to respect the setting. Modify EnvironmentVariantModal to respect the setting ## About the changes <!-- Describe the changes introduced. What are they and why are they being introduced? Feel free to also add screenshots or steps to view the changes if they're visual. --> <!-- Does it close an issue? Multiple? --> Closes # <!-- (For internal contributors): Does it relate to an issue on public roadmap? --> <!-- Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item: # --> ### Important files <!-- PRs can contain a lot of changes, but not all changes are equally important. Where should a reviewer start looking to get an overview of the changes? Are any files particularly important? --> ## Discussion points <!-- Anything about the PR you'd like to discuss before it gets merged? Got any questions or doubts? --> --------- Signed-off-by: andreas-unleash <andreas@getunleash.ai>
56 lines
1.3 KiB
TypeScript
56 lines
1.3 KiB
TypeScript
import {
|
|
IStrategy,
|
|
IFeatureStrategy,
|
|
IFeatureStrategyParameters,
|
|
IStrategyParameter,
|
|
} from 'interfaces/strategy';
|
|
|
|
// Create a new feature strategy with default values from a strategy definition.
|
|
export const createFeatureStrategy = (
|
|
featureId: string,
|
|
strategyDefinition: IStrategy
|
|
): Omit<IFeatureStrategy, 'id'> => {
|
|
const parameters: IFeatureStrategyParameters = {};
|
|
|
|
strategyDefinition.parameters.forEach((parameter: IStrategyParameter) => {
|
|
parameters[parameter.name] = createFeatureStrategyParameterValue(
|
|
featureId,
|
|
parameter
|
|
);
|
|
});
|
|
|
|
return {
|
|
name: strategyDefinition.name,
|
|
constraints: [],
|
|
parameters,
|
|
};
|
|
};
|
|
|
|
// Create default feature strategy parameter values from a strategy definition.
|
|
const createFeatureStrategyParameterValue = (
|
|
featureId: string,
|
|
parameter: IStrategyParameter
|
|
): string => {
|
|
if (
|
|
parameter.name === 'rollout' ||
|
|
parameter.name === 'percentage' ||
|
|
parameter.type === 'percentage'
|
|
) {
|
|
return '50';
|
|
}
|
|
|
|
if (parameter.name === 'stickiness') {
|
|
return '';
|
|
}
|
|
|
|
if (parameter.name === 'groupId') {
|
|
return featureId;
|
|
}
|
|
|
|
if (parameter.type === 'boolean') {
|
|
return 'false';
|
|
}
|
|
|
|
return '';
|
|
};
|