diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-02 09:07:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-07-02 09:07:28 +0300 |
commit | 127ab291e2c8b66ac5502257ac9e280acf257089 (patch) | |
tree | dbc144795ae86d8035abbe9bbabc9772127ed5a6 /app/assets/javascripts/feature_flags | |
parent | fd4360e1f532de6a23e5c79f06b3ef3d89c1511d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/feature_flags')
5 files changed, 5 insertions, 201 deletions
diff --git a/app/assets/javascripts/feature_flags/components/edit_feature_flag.vue b/app/assets/javascripts/feature_flags/components/edit_feature_flag.vue index e7f4b51c964..dde021b67be 100644 --- a/app/assets/javascripts/feature_flags/components/edit_feature_flag.vue +++ b/app/assets/javascripts/feature_flags/components/edit_feature_flag.vue @@ -1,10 +1,8 @@ <script> import { GlAlert, GlLoadingIcon, GlToggle } from '@gitlab/ui'; import { mapState, mapActions } from 'vuex'; -import axios from '~/lib/utils/axios_utils'; import { sprintf, s__ } from '~/locale'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; -import { LEGACY_FLAG } from '../constants'; import FeatureFlagForm from './form.vue'; export default { @@ -15,59 +13,29 @@ export default { FeatureFlagForm, }, mixins: [glFeatureFlagMixin()], - inject: { - showUserCallout: {}, - userCalloutId: { - default: '', - }, - userCalloutsPath: { - default: '', - }, - }, - data() { - return { - userShouldSeeNewFlagAlert: this.showUserCallout, - }; - }, - translations: { - legacyReadOnlyFlagAlert: s__( - 'FeatureFlags|GitLab is moving to a new way of managing feature flags. This feature flag is read-only, and it will be removed in 14.0. Please create a new feature flag.', - ), - }, computed: { ...mapState([ 'path', 'error', 'name', 'description', - 'scopes', 'strategies', 'isLoading', 'hasError', 'iid', 'active', - 'version', ]), title() { return this.iid ? `^${this.iid} ${this.name}` : sprintf(s__('Edit %{name}'), { name: this.name }); }, - deprecated() { - return this.version === LEGACY_FLAG; - }, }, created() { return this.fetchFeatureFlag(); }, methods: { ...mapActions(['updateFeatureFlag', 'fetchFeatureFlag', 'toggleActive']), - dismissNewVersionFlagAlert() { - this.userShouldSeeNewFlagAlert = false; - axios.post(this.userCalloutsPath, { - feature_name: this.userCalloutId, - }); - }, }, }; </script> @@ -76,9 +44,6 @@ export default { <gl-loading-icon v-if="isLoading" size="xl" class="gl-mt-7" /> <template v-else-if="!isLoading && !hasError"> - <gl-alert v-if="deprecated" variant="warning" :dismissible="false" class="gl-my-5">{{ - $options.translations.legacyReadOnlyFlagAlert - }}</gl-alert> <div class="gl-display-flex gl-align-items-center gl-mb-4 gl-mt-4"> <gl-toggle :value="active" @@ -100,12 +65,10 @@ export default { <feature-flag-form :name="name" :description="description" - :scopes="scopes" :strategies="strategies" :cancel-path="path" :submit-text="__('Save changes')" :active="active" - :version="version" @handleSubmit="(data) => updateFeatureFlag(data)" /> </template> diff --git a/app/assets/javascripts/feature_flags/edit.js b/app/assets/javascripts/feature_flags/edit.js index 010674592f8..98dee7c7e97 100644 --- a/app/assets/javascripts/feature_flags/edit.js +++ b/app/assets/javascripts/feature_flags/edit.js @@ -1,6 +1,5 @@ import Vue from 'vue'; import Vuex from 'vuex'; -import { parseBoolean } from '~/lib/utils/common_utils'; import EditFeatureFlag from './components/edit_feature_flag.vue'; import createStore from './store/edit'; @@ -16,9 +15,6 @@ export default () => { environmentsEndpoint, projectId, featureFlagIssuesEndpoint, - userCalloutsPath, - userCalloutId, - showUserCallout, } = el.dataset; return new Vue({ @@ -30,9 +26,6 @@ export default () => { environmentsEndpoint, projectId, featureFlagIssuesEndpoint, - userCalloutsPath, - userCalloutId, - showUserCallout: parseBoolean(showUserCallout), }, render(createElement) { return createElement(EditFeatureFlag); diff --git a/app/assets/javascripts/feature_flags/store/edit/actions.js b/app/assets/javascripts/feature_flags/store/edit/actions.js index 54c7e8c4453..8656479190a 100644 --- a/app/assets/javascripts/feature_flags/store/edit/actions.js +++ b/app/assets/javascripts/feature_flags/store/edit/actions.js @@ -2,8 +2,7 @@ import createFlash from '~/flash'; import axios from '~/lib/utils/axios_utils'; import { visitUrl } from '~/lib/utils/url_utility'; import { __ } from '~/locale'; -import { NEW_VERSION_FLAG } from '../../constants'; -import { mapFromScopesViewModel, mapStrategiesToRails } from '../helpers'; +import { mapStrategiesToRails } from '../helpers'; import * as types from './mutation_types'; /** @@ -19,12 +18,7 @@ export const updateFeatureFlag = ({ state, dispatch }, params) => { dispatch('requestUpdateFeatureFlag'); axios - .put( - state.endpoint, - params.version === NEW_VERSION_FLAG - ? mapStrategiesToRails(params) - : mapFromScopesViewModel(params), - ) + .put(state.endpoint, mapStrategiesToRails(params)) .then(() => { dispatch('receiveUpdateFeatureFlagSuccess'); visitUrl(state.path); diff --git a/app/assets/javascripts/feature_flags/store/edit/mutations.js b/app/assets/javascripts/feature_flags/store/edit/mutations.js index 0a610f4b395..3882cb2dfff 100644 --- a/app/assets/javascripts/feature_flags/store/edit/mutations.js +++ b/app/assets/javascripts/feature_flags/store/edit/mutations.js @@ -1,5 +1,5 @@ import { LEGACY_FLAG } from '../../constants'; -import { mapToScopesViewModel, mapStrategiesToViewModel } from '../helpers'; +import { mapStrategiesToViewModel } from '../helpers'; import * as types from './mutation_types'; export default { @@ -14,7 +14,6 @@ export default { state.description = response.description; state.iid = response.iid; state.active = response.active; - state.scopes = mapToScopesViewModel(response.scopes); state.strategies = mapStrategiesToViewModel(response.strategies); state.version = response.version || LEGACY_FLAG; }, diff --git a/app/assets/javascripts/feature_flags/store/helpers.js b/app/assets/javascripts/feature_flags/store/helpers.js index 2fa20e25f4e..300709f2771 100644 --- a/app/assets/javascripts/feature_flags/store/helpers.js +++ b/app/assets/javascripts/feature_flags/store/helpers.js @@ -1,149 +1,4 @@ -import { isEmpty, uniqueId, isString } from 'lodash'; -import { - ROLLOUT_STRATEGY_ALL_USERS, - ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - ROLLOUT_STRATEGY_USER_ID, - ROLLOUT_STRATEGY_GITLAB_USER_LIST, - INTERNAL_ID_PREFIX, - DEFAULT_PERCENT_ROLLOUT, - PERCENT_ROLLOUT_GROUP_ID, - fetchPercentageParams, - fetchUserIdParams, - LEGACY_FLAG, -} from '../constants'; - -/** - * Converts raw scope objects fetched from the API into an array of scope - * objects that is easier/nicer to bind to in Vue. - * @param {Array} scopesFromRails An array of scope objects fetched from the API - */ -export const mapToScopesViewModel = (scopesFromRails) => - (scopesFromRails || []).map((s) => { - const percentStrategy = (s.strategies || []).find( - (strat) => strat.name === ROLLOUT_STRATEGY_PERCENT_ROLLOUT, - ); - - const rolloutPercentage = fetchPercentageParams(percentStrategy) || DEFAULT_PERCENT_ROLLOUT; - - const userStrategy = (s.strategies || []).find( - (strat) => strat.name === ROLLOUT_STRATEGY_USER_ID, - ); - - const rolloutStrategy = - (percentStrategy && percentStrategy.name) || - (userStrategy && userStrategy.name) || - ROLLOUT_STRATEGY_ALL_USERS; - - const rolloutUserIds = (fetchUserIdParams(userStrategy) || '') - .split(',') - .filter((id) => id) - .join(', '); - - return { - id: s.id, - environmentScope: s.environment_scope, - active: Boolean(s.active), - canUpdate: Boolean(s.can_update), - protected: Boolean(s.protected), - rolloutStrategy, - rolloutPercentage, - rolloutUserIds, - - // eslint-disable-next-line no-underscore-dangle - shouldBeDestroyed: Boolean(s._destroy), - shouldIncludeUserIds: rolloutUserIds.length > 0 && percentStrategy !== null, - }; - }); -/** - * Converts the parameters emitted by the Vue component into - * the shape that the Rails API expects. - * @param {Array} scopesFromVue An array of scope objects from the Vue component - */ -export const mapFromScopesViewModel = (params) => { - const scopes = (params.scopes || []).map((s) => { - const parameters = {}; - if (s.rolloutStrategy === ROLLOUT_STRATEGY_PERCENT_ROLLOUT) { - parameters.groupId = PERCENT_ROLLOUT_GROUP_ID; - parameters.percentage = s.rolloutPercentage; - } else if (s.rolloutStrategy === ROLLOUT_STRATEGY_USER_ID) { - parameters.userIds = (s.rolloutUserIds || '').replace(/, /g, ','); - } - - const userIdParameters = {}; - - if (s.shouldIncludeUserIds && s.rolloutStrategy !== ROLLOUT_STRATEGY_USER_ID) { - userIdParameters.userIds = (s.rolloutUserIds || '').replace(/, /g, ','); - } - - // Strip out any internal IDs - const id = isString(s.id) && s.id.startsWith(INTERNAL_ID_PREFIX) ? undefined : s.id; - - const strategies = [ - { - name: s.rolloutStrategy, - parameters, - }, - ]; - - if (!isEmpty(userIdParameters)) { - strategies.push({ name: ROLLOUT_STRATEGY_USER_ID, parameters: userIdParameters }); - } - - return { - id, - environment_scope: s.environmentScope, - active: s.active, - can_update: s.canUpdate, - protected: s.protected, - _destroy: s.shouldBeDestroyed, - strategies, - }; - }); - - const model = { - operations_feature_flag: { - name: params.name, - description: params.description, - active: params.active, - scopes_attributes: scopes, - version: LEGACY_FLAG, - }, - }; - - return model; -}; - -/** - * Creates a new feature flag environment scope object for use - * in a Vue component. An optional parameter can be passed to - * override the property values that are created by default. - * - * @param {Object} overrides An optional object whose - * property values will be used to override the default values. - * - */ -export const createNewEnvironmentScope = (overrides = {}, featureFlagPermissions = false) => { - const defaultScope = { - environmentScope: '', - active: false, - id: uniqueId(INTERNAL_ID_PREFIX), - rolloutStrategy: ROLLOUT_STRATEGY_ALL_USERS, - rolloutPercentage: DEFAULT_PERCENT_ROLLOUT, - rolloutUserIds: '', - }; - - const newScope = { - ...defaultScope, - ...overrides, - }; - - if (featureFlagPermissions) { - newScope.canUpdate = true; - newScope.protected = false; - } - - return newScope; -}; +import { ROLLOUT_STRATEGY_GITLAB_USER_LIST, NEW_VERSION_FLAG } from '../constants'; const mapStrategyScopesToRails = (scopes) => scopes.length === 0 @@ -206,8 +61,8 @@ export const mapStrategiesToRails = (params) => ({ operations_feature_flag: { name: params.name, description: params.description, - version: params.version, active: params.active, strategies_attributes: (params.strategies || []).map(mapStrategyToRails), + version: NEW_VERSION_FLAG, }, }); |