Commit 934f044d authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch 'afontaine/remove-legacy-flags-frontend-new' into 'master'

Remove Frontend to Create Legacy Flags

See merge request gitlab-org/gitlab!64004
parents 363fad24 57ecbfcb
<script> <script>
import { GlAlert } from '@gitlab/ui'; import { GlAlert } from '@gitlab/ui';
import { mapState, mapActions } from 'vuex'; import { mapState, mapActions } from 'vuex';
import axios from '~/lib/utils/axios_utils';
import featureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import featureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { NEW_VERSION_FLAG, ROLLOUT_STRATEGY_ALL_USERS } from '../constants'; import { ROLLOUT_STRATEGY_ALL_USERS } from '../constants';
import { createNewEnvironmentScope } from '../store/helpers';
import FeatureFlagForm from './form.vue'; import FeatureFlagForm from './form.vue';
export default { export default {
...@@ -13,48 +11,14 @@ export default { ...@@ -13,48 +11,14 @@ export default {
GlAlert, GlAlert,
}, },
mixins: [featureFlagsMixin()], mixins: [featureFlagsMixin()],
inject: {
showUserCallout: {},
userCalloutId: {
default: '',
},
userCalloutsPath: {
default: '',
},
},
data() {
return {
userShouldSeeNewFlagAlert: this.showUserCallout,
};
},
computed: { computed: {
...mapState(['error', 'path']), ...mapState(['error', 'path']),
scopes() {
return [
createNewEnvironmentScope(
{
environmentScope: '*',
active: true,
},
this.glFeatures.featureFlagsPermissions,
),
];
},
version() {
return NEW_VERSION_FLAG;
},
strategies() { strategies() {
return [{ name: ROLLOUT_STRATEGY_ALL_USERS, parameters: {}, scopes: [] }]; return [{ name: ROLLOUT_STRATEGY_ALL_USERS, parameters: {}, scopes: [] }];
}, },
}, },
methods: { methods: {
...mapActions(['createFeatureFlag']), ...mapActions(['createFeatureFlag']),
dismissNewVersionFlagAlert() {
this.userShouldSeeNewFlagAlert = false;
axios.post(this.userCalloutsPath, {
feature_name: this.userCalloutId,
});
},
}, },
}; };
</script> </script>
...@@ -69,9 +33,7 @@ export default { ...@@ -69,9 +33,7 @@ export default {
<feature-flag-form <feature-flag-form
:cancel-path="path" :cancel-path="path"
:submit-text="s__('FeatureFlags|Create feature flag')" :submit-text="s__('FeatureFlags|Create feature flag')"
:scopes="scopes"
:strategies="strategies" :strategies="strategies"
:version="version"
@handleSubmit="(data) => createFeatureFlag(data)" @handleSubmit="(data) => createFeatureFlag(data)"
/> />
</div> </div>
......
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import { NEW_VERSION_FLAG } from '../../constants'; import { mapStrategiesToRails } from '../helpers';
import { mapFromScopesViewModel, mapStrategiesToRails } from '../helpers';
import * as types from './mutation_types'; import * as types from './mutation_types';
/** /**
...@@ -17,12 +16,7 @@ export const createFeatureFlag = ({ state, dispatch }, params) => { ...@@ -17,12 +16,7 @@ export const createFeatureFlag = ({ state, dispatch }, params) => {
dispatch('requestCreateFeatureFlag'); dispatch('requestCreateFeatureFlag');
return axios return axios
.post( .post(state.endpoint, mapStrategiesToRails(params))
state.endpoint,
params.version === NEW_VERSION_FLAG
? mapStrategiesToRails(params)
: mapFromScopesViewModel(params),
)
.then(() => { .then(() => {
dispatch('receiveCreateFeatureFlagSuccess'); dispatch('receiveCreateFeatureFlagSuccess');
visitUrl(state.path); visitUrl(state.path);
......
...@@ -4,7 +4,6 @@ import Vuex from 'vuex'; ...@@ -4,7 +4,6 @@ import Vuex from 'vuex';
import { TEST_HOST } from 'spec/test_constants'; import { TEST_HOST } from 'spec/test_constants';
import Form from '~/feature_flags/components/form.vue'; import Form from '~/feature_flags/components/form.vue';
import NewFeatureFlag from '~/feature_flags/components/new_feature_flag.vue'; import NewFeatureFlag from '~/feature_flags/components/new_feature_flag.vue';
import { ROLLOUT_STRATEGY_ALL_USERS, DEFAULT_PERCENT_ROLLOUT } from '~/feature_flags/constants';
import createStore from '~/feature_flags/store/new'; import createStore from '~/feature_flags/store/new';
import { allUsersStrategy } from '../mock_data'; import { allUsersStrategy } from '../mock_data';
...@@ -71,18 +70,6 @@ describe('New feature flag form', () => { ...@@ -71,18 +70,6 @@ describe('New feature flag form', () => {
expect(wrapper.find(Form).exists()).toEqual(true); expect(wrapper.find(Form).exists()).toEqual(true);
}); });
it('should render default * row', () => {
const defaultScope = {
id: expect.any(String),
environmentScope: '*',
active: true,
rolloutStrategy: ROLLOUT_STRATEGY_ALL_USERS,
rolloutPercentage: DEFAULT_PERCENT_ROLLOUT,
rolloutUserIds: '',
};
expect(wrapper.vm.scopes).toEqual([defaultScope]);
});
it('has an all users strategy by default', () => { it('has an all users strategy by default', () => {
const strategies = wrapper.find(Form).props('strategies'); const strategies = wrapper.find(Form).props('strategies');
......
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import { TEST_HOST } from 'spec/test_constants'; import { ROLLOUT_STRATEGY_ALL_USERS, NEW_VERSION_FLAG } from '~/feature_flags/constants';
import { import { mapStrategiesToRails } from '~/feature_flags/store/helpers';
ROLLOUT_STRATEGY_ALL_USERS,
ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
LEGACY_FLAG,
NEW_VERSION_FLAG,
} from '~/feature_flags/constants';
import { mapFromScopesViewModel, mapStrategiesToRails } from '~/feature_flags/store/helpers';
import { import {
createFeatureFlag, createFeatureFlag,
requestCreateFeatureFlag, requestCreateFeatureFlag,
...@@ -24,33 +19,13 @@ describe('Feature flags New Module Actions', () => { ...@@ -24,33 +19,13 @@ describe('Feature flags New Module Actions', () => {
let mockedState; let mockedState;
beforeEach(() => { beforeEach(() => {
mockedState = state({ endpoint: 'feature_flags.json', path: '/feature_flags' }); mockedState = state({ endpoint: '/feature_flags.json', path: '/feature_flags' });
}); });
describe('createFeatureFlag', () => { describe('createFeatureFlag', () => {
let mock; let mock;
const actionParams = {
name: 'name',
description: 'description',
active: true,
version: LEGACY_FLAG,
scopes: [
{
id: 1,
environmentScope: 'environmentScope',
active: true,
canUpdate: true,
protected: true,
shouldBeDestroyed: false,
rolloutStrategy: ROLLOUT_STRATEGY_ALL_USERS,
rolloutPercentage: ROLLOUT_STRATEGY_PERCENT_ROLLOUT,
},
],
};
beforeEach(() => { beforeEach(() => {
mockedState.endpoint = `${TEST_HOST}/endpoint.json`;
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
}); });
...@@ -60,29 +35,7 @@ describe('Feature flags New Module Actions', () => { ...@@ -60,29 +35,7 @@ describe('Feature flags New Module Actions', () => {
describe('success', () => { describe('success', () => {
it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagSuccess ', (done) => { it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagSuccess ', (done) => {
const convertedActionParams = mapFromScopesViewModel(actionParams); const actionParams = {
mock.onPost(`${TEST_HOST}/endpoint.json`, convertedActionParams).replyOnce(200);
testAction(
createFeatureFlag,
actionParams,
mockedState,
[],
[
{
type: 'requestCreateFeatureFlag',
},
{
type: 'receiveCreateFeatureFlagSuccess',
},
],
done,
);
});
it('sends strategies for new style feature flags', (done) => {
const newVersionFlagParams = {
name: 'name', name: 'name',
description: 'description', description: 'description',
active: true, active: true,
...@@ -97,13 +50,11 @@ describe('Feature flags New Module Actions', () => { ...@@ -97,13 +50,11 @@ describe('Feature flags New Module Actions', () => {
}, },
], ],
}; };
mock mock.onPost(mockedState.endpoint, mapStrategiesToRails(actionParams)).replyOnce(200);
.onPost(`${TEST_HOST}/endpoint.json`, mapStrategiesToRails(newVersionFlagParams))
.replyOnce(200);
testAction( testAction(
createFeatureFlag, createFeatureFlag,
newVersionFlagParams, actionParams,
mockedState, mockedState,
[], [],
[ [
...@@ -121,10 +72,23 @@ describe('Feature flags New Module Actions', () => { ...@@ -121,10 +72,23 @@ describe('Feature flags New Module Actions', () => {
describe('error', () => { describe('error', () => {
it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagError ', (done) => { it('dispatches requestCreateFeatureFlag and receiveCreateFeatureFlagError ', (done) => {
const convertedActionParams = mapFromScopesViewModel(actionParams); const actionParams = {
name: 'name',
description: 'description',
active: true,
version: NEW_VERSION_FLAG,
strategies: [
{
name: ROLLOUT_STRATEGY_ALL_USERS,
parameters: {},
id: 1,
scopes: [{ id: 1, environmentScope: 'environmentScope', shouldBeDestroyed: false }],
shouldBeDestroyed: false,
},
],
};
mock mock
.onPost(`${TEST_HOST}/endpoint.json`, convertedActionParams) .onPost(mockedState.endpoint, mapStrategiesToRails(actionParams))
.replyOnce(500, { message: [] }); .replyOnce(500, { message: [] });
testAction( testAction(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment