summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/feature_flags/store
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/feature_flags/store')
-rw-r--r--app/assets/javascripts/feature_flags/store/edit/actions.js6
-rw-r--r--app/assets/javascripts/feature_flags/store/index/actions.js34
-rw-r--r--app/assets/javascripts/feature_flags/store/index/mutation_types.js7
-rw-r--r--app/assets/javascripts/feature_flags/store/index/mutations.js54
-rw-r--r--app/assets/javascripts/feature_flags/store/index/state.js9
5 files changed, 15 insertions, 95 deletions
diff --git a/app/assets/javascripts/feature_flags/store/edit/actions.js b/app/assets/javascripts/feature_flags/store/edit/actions.js
index 72b17333832..54c7e8c4453 100644
--- a/app/assets/javascripts/feature_flags/store/edit/actions.js
+++ b/app/assets/javascripts/feature_flags/store/edit/actions.js
@@ -1,4 +1,4 @@
-import { deprecatedCreateFlash as createFlash } from '~/flash';
+import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils';
import { visitUrl } from '~/lib/utils/url_utility';
import { __ } from '~/locale';
@@ -55,7 +55,9 @@ export const receiveFeatureFlagSuccess = ({ commit }, response) =>
commit(types.RECEIVE_FEATURE_FLAG_SUCCESS, response);
export const receiveFeatureFlagError = ({ commit }) => {
commit(types.RECEIVE_FEATURE_FLAG_ERROR);
- createFlash(__('Something went wrong on our end. Please try again!'));
+ createFlash({
+ message: __('Something went wrong on our end. Please try again!'),
+ });
};
export const toggleActive = ({ commit }, active) => commit(types.TOGGLE_ACTIVE, active);
diff --git a/app/assets/javascripts/feature_flags/store/index/actions.js b/app/assets/javascripts/feature_flags/store/index/actions.js
index 4372c280f39..751f627ca48 100644
--- a/app/assets/javascripts/feature_flags/store/index/actions.js
+++ b/app/assets/javascripts/feature_flags/store/index/actions.js
@@ -1,4 +1,3 @@
-import Api from '~/api';
import axios from '~/lib/utils/axios_utils';
import * as types from './mutation_types';
@@ -26,19 +25,6 @@ export const receiveFeatureFlagsSuccess = ({ commit }, response) =>
commit(types.RECEIVE_FEATURE_FLAGS_SUCCESS, response);
export const receiveFeatureFlagsError = ({ commit }) => commit(types.RECEIVE_FEATURE_FLAGS_ERROR);
-export const fetchUserLists = ({ state, dispatch }) => {
- dispatch('requestUserLists');
-
- return Api.fetchFeatureFlagUserLists(state.projectId, state.options.page)
- .then(({ data, headers }) => dispatch('receiveUserListsSuccess', { data, headers }))
- .catch(() => dispatch('receiveUserListsError'));
-};
-
-export const requestUserLists = ({ commit }) => commit(types.REQUEST_USER_LISTS);
-export const receiveUserListsSuccess = ({ commit }, response) =>
- commit(types.RECEIVE_USER_LISTS_SUCCESS, response);
-export const receiveUserListsError = ({ commit }) => commit(types.RECEIVE_USER_LISTS_ERROR);
-
export const toggleFeatureFlag = ({ dispatch }, flag) => {
dispatch('updateFeatureFlag', flag);
@@ -57,26 +43,6 @@ export const receiveUpdateFeatureFlagSuccess = ({ commit }, data) =>
export const receiveUpdateFeatureFlagError = ({ commit }, id) =>
commit(types.RECEIVE_UPDATE_FEATURE_FLAG_ERROR, id);
-export const deleteUserList = ({ state, dispatch }, list) => {
- dispatch('requestDeleteUserList', list);
-
- return Api.deleteFeatureFlagUserList(state.projectId, list.iid)
- .then(() => dispatch('fetchUserLists'))
- .catch((error) =>
- dispatch('receiveDeleteUserListError', {
- list,
- error: error?.response?.data ?? error,
- }),
- );
-};
-
-export const requestDeleteUserList = ({ commit }, list) =>
- commit(types.REQUEST_DELETE_USER_LIST, list);
-
-export const receiveDeleteUserListError = ({ commit }, { error, list }) => {
- commit(types.RECEIVE_DELETE_USER_LIST_ERROR, { error, list });
-};
-
export const rotateInstanceId = ({ state, dispatch }) => {
dispatch('requestRotateInstanceId');
diff --git a/app/assets/javascripts/feature_flags/store/index/mutation_types.js b/app/assets/javascripts/feature_flags/store/index/mutation_types.js
index 189c763782e..ed05294a6f3 100644
--- a/app/assets/javascripts/feature_flags/store/index/mutation_types.js
+++ b/app/assets/javascripts/feature_flags/store/index/mutation_types.js
@@ -4,13 +4,6 @@ export const REQUEST_FEATURE_FLAGS = 'REQUEST_FEATURE_FLAGS';
export const RECEIVE_FEATURE_FLAGS_SUCCESS = 'RECEIVE_FEATURE_FLAGS_SUCCESS';
export const RECEIVE_FEATURE_FLAGS_ERROR = 'RECEIVE_FEATURE_FLAGS_ERROR';
-export const REQUEST_USER_LISTS = 'REQUEST_USER_LISTS';
-export const RECEIVE_USER_LISTS_SUCCESS = 'RECEIVE_USER_LISTS_SUCCESS';
-export const RECEIVE_USER_LISTS_ERROR = 'RECEIVE_USER_LISTS_ERROR';
-
-export const REQUEST_DELETE_USER_LIST = 'REQUEST_DELETE_USER_LIST';
-export const RECEIVE_DELETE_USER_LIST_ERROR = 'RECEIVE_DELETE_USER_LIST_ERROR';
-
export const UPDATE_FEATURE_FLAG = 'UPDATE_FEATURE_FLAG';
export const RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS = 'RECEIVE_UPDATE_FEATURE_FLAG_SUCCESS';
export const RECEIVE_UPDATE_FEATURE_FLAG_ERROR = 'RECEIVE_UPDATE_FEATURE_FLAG_ERROR';
diff --git a/app/assets/javascripts/feature_flags/store/index/mutations.js b/app/assets/javascripts/feature_flags/store/index/mutations.js
index 25eb7da1c72..54e48a4b80c 100644
--- a/app/assets/javascripts/feature_flags/store/index/mutations.js
+++ b/app/assets/javascripts/feature_flags/store/index/mutations.js
@@ -1,17 +1,16 @@
import Vue from 'vue';
import { parseIntPagination, normalizeHeaders } from '~/lib/utils/common_utils';
-import { FEATURE_FLAG_SCOPE, USER_LIST_SCOPE } from '../../constants';
import { mapToScopesViewModel } from '../helpers';
import * as types from './mutation_types';
const mapFlag = (flag) => ({ ...flag, scopes: mapToScopesViewModel(flag.scopes || []) });
const updateFlag = (state, flag) => {
- const index = state[FEATURE_FLAG_SCOPE].findIndex(({ id }) => id === flag.id);
- Vue.set(state[FEATURE_FLAG_SCOPE], index, flag);
+ const index = state.featureFlags.findIndex(({ id }) => id === flag.id);
+ Vue.set(state.featureFlags, index, flag);
};
-const createPaginationInfo = (state, headers) => {
+const createPaginationInfo = (headers) => {
let paginationInfo;
if (Object.keys(headers).length) {
const normalizedHeaders = normalizeHeaders(headers);
@@ -32,44 +31,16 @@ export default {
[types.RECEIVE_FEATURE_FLAGS_SUCCESS](state, response) {
state.isLoading = false;
state.hasError = false;
- state[FEATURE_FLAG_SCOPE] = (response.data.feature_flags || []).map(mapFlag);
+ state.featureFlags = (response.data.feature_flags || []).map(mapFlag);
- const paginationInfo = createPaginationInfo(state, response.headers);
- state.count = {
- ...state.count,
- [FEATURE_FLAG_SCOPE]: paginationInfo?.total ?? state[FEATURE_FLAG_SCOPE].length,
- };
- state.pageInfo = {
- ...state.pageInfo,
- [FEATURE_FLAG_SCOPE]: paginationInfo,
- };
+ const paginationInfo = createPaginationInfo(response.headers);
+ state.count = paginationInfo?.total ?? state.featureFlags.length;
+ state.pageInfo = paginationInfo;
},
[types.RECEIVE_FEATURE_FLAGS_ERROR](state) {
state.isLoading = false;
state.hasError = true;
},
- [types.REQUEST_USER_LISTS](state) {
- state.isLoading = true;
- },
- [types.RECEIVE_USER_LISTS_SUCCESS](state, response) {
- state.isLoading = false;
- state.hasError = false;
- state[USER_LIST_SCOPE] = response.data || [];
-
- const paginationInfo = createPaginationInfo(state, response.headers);
- state.count = {
- ...state.count,
- [USER_LIST_SCOPE]: paginationInfo?.total ?? state[USER_LIST_SCOPE].length,
- };
- state.pageInfo = {
- ...state.pageInfo,
- [USER_LIST_SCOPE]: paginationInfo,
- };
- },
- [types.RECEIVE_USER_LISTS_ERROR](state) {
- state.isLoading = false;
- state.hasError = true;
- },
[types.REQUEST_ROTATE_INSTANCE_ID](state) {
state.isRotating = true;
state.hasRotateError = false;
@@ -90,18 +61,9 @@ export default {
updateFlag(state, mapFlag(data));
},
[types.RECEIVE_UPDATE_FEATURE_FLAG_ERROR](state, i) {
- const flag = state[FEATURE_FLAG_SCOPE].find(({ id }) => i === id);
+ const flag = state.featureFlags.find(({ id }) => i === id);
updateFlag(state, { ...flag, active: !flag.active });
},
- [types.REQUEST_DELETE_USER_LIST](state, list) {
- state.userLists = state.userLists.filter((l) => l !== list);
- },
- [types.RECEIVE_DELETE_USER_LIST_ERROR](state, { error, list }) {
- state.isLoading = false;
- state.hasError = false;
- state.alerts = [].concat(error.message);
- state.userLists = state.userLists.concat(list).sort((l1, l2) => l1.iid - l2.iid);
- },
[types.RECEIVE_CLEAR_ALERT](state, index) {
state.alerts.splice(index, 1);
},
diff --git a/app/assets/javascripts/feature_flags/store/index/state.js b/app/assets/javascripts/feature_flags/store/index/state.js
index f8439b02639..488da265b28 100644
--- a/app/assets/javascripts/feature_flags/store/index/state.js
+++ b/app/assets/javascripts/feature_flags/store/index/state.js
@@ -1,11 +1,8 @@
-import { FEATURE_FLAG_SCOPE, USER_LIST_SCOPE } from '../../constants';
-
export default ({ endpoint, projectId, unleashApiInstanceId, rotateInstanceIdPath }) => ({
- [FEATURE_FLAG_SCOPE]: [],
- [USER_LIST_SCOPE]: [],
+ featureFlags: [],
alerts: [],
- count: {},
- pageInfo: { [FEATURE_FLAG_SCOPE]: {}, [USER_LIST_SCOPE]: {} },
+ count: 0,
+ pageInfo: {},
isLoading: true,
hasError: false,
endpoint,