2020-10-01 17:08:36 -04:00
|
|
|
import { s__, n__, sprintf } from '~/locale';
|
|
|
|
import {
|
|
|
|
ALL_ENVIRONMENTS_NAME,
|
|
|
|
ROLLOUT_STRATEGY_ALL_USERS,
|
2020-10-13 11:08:53 -04:00
|
|
|
ROLLOUT_STRATEGY_FLEXIBLE_ROLLOUT,
|
2020-10-01 17:08:36 -04:00
|
|
|
ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
|
|
|
|
ROLLOUT_STRATEGY_USER_ID,
|
|
|
|
ROLLOUT_STRATEGY_GITLAB_USER_LIST,
|
|
|
|
} from './constants';
|
|
|
|
|
|
|
|
const badgeTextByType = {
|
|
|
|
[ROLLOUT_STRATEGY_ALL_USERS]: {
|
|
|
|
name: s__('FeatureFlags|All Users'),
|
|
|
|
parameters: null,
|
|
|
|
},
|
2020-10-13 11:08:53 -04:00
|
|
|
[ROLLOUT_STRATEGY_FLEXIBLE_ROLLOUT]: {
|
|
|
|
name: s__('FeatureFlags|Percent rollout'),
|
|
|
|
parameters: ({ parameters: { rollout, stickiness } }) => {
|
|
|
|
switch (stickiness) {
|
|
|
|
case 'USERID':
|
|
|
|
return sprintf(s__('FeatureFlags|%{percent} by user ID'), { percent: `${rollout}%` });
|
|
|
|
case 'SESSIONID':
|
|
|
|
return sprintf(s__('FeatureFlags|%{percent} by session ID'), { percent: `${rollout}%` });
|
|
|
|
case 'RANDOM':
|
|
|
|
return sprintf(s__('FeatureFlags|%{percent} randomly'), { percent: `${rollout}%` });
|
|
|
|
default:
|
|
|
|
return sprintf(s__('FeatureFlags|%{percent} by available ID'), {
|
|
|
|
percent: `${rollout}%`,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2020-10-01 17:08:36 -04:00
|
|
|
[ROLLOUT_STRATEGY_PERCENT_ROLLOUT]: {
|
|
|
|
name: s__('FeatureFlags|Percent of users'),
|
|
|
|
parameters: ({ parameters: { percentage } }) => `${percentage}%`,
|
|
|
|
},
|
|
|
|
[ROLLOUT_STRATEGY_USER_ID]: {
|
|
|
|
name: s__('FeatureFlags|User IDs'),
|
|
|
|
parameters: ({ parameters: { userIds } }) =>
|
|
|
|
sprintf(n__('FeatureFlags|%d user', 'FeatureFlags|%d users', userIds.split(',').length)),
|
|
|
|
},
|
|
|
|
[ROLLOUT_STRATEGY_GITLAB_USER_LIST]: {
|
|
|
|
name: s__('FeatureFlags|User List'),
|
|
|
|
parameters: ({ user_list: { name } }) => name,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const scopeName = ({ environment_scope: scope }) =>
|
|
|
|
scope === ALL_ENVIRONMENTS_NAME ? s__('FeatureFlags|All Environments') : scope;
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
export const labelForStrategy = (strategy) => {
|
2020-10-01 17:08:36 -04:00
|
|
|
const { name, parameters } = badgeTextByType[strategy.name];
|
|
|
|
|
|
|
|
if (parameters) {
|
|
|
|
return sprintf('%{name} - %{parameters}: %{scopes}', {
|
|
|
|
name,
|
|
|
|
parameters: parameters(strategy),
|
|
|
|
scopes: strategy.scopes.map(scopeName).join(', '),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf('%{name}: %{scopes}', {
|
|
|
|
name,
|
|
|
|
scopes: strategy.scopes.map(scopeName).join(', '),
|
|
|
|
});
|
|
|
|
};
|