From b7d106d7ab37c9268213a9a2ff0de02aa5445d5f Mon Sep 17 00:00:00 2001 From: olav Date: Wed, 9 Feb 2022 14:40:58 +0100 Subject: [PATCH] refactor: remove unused feature tags state (#689) --- frontend/src/store/feature-tags/actions.js | 50 ---------------------- frontend/src/store/feature-tags/api.js | 44 ------------------- frontend/src/store/feature-tags/index.js | 25 ----------- frontend/src/store/index.js | 2 - 4 files changed, 121 deletions(-) delete mode 100644 frontend/src/store/feature-tags/actions.js delete mode 100644 frontend/src/store/feature-tags/api.js delete mode 100644 frontend/src/store/feature-tags/index.js diff --git a/frontend/src/store/feature-tags/actions.js b/frontend/src/store/feature-tags/actions.js deleted file mode 100644 index 87e82b4399..0000000000 --- a/frontend/src/store/feature-tags/actions.js +++ /dev/null @@ -1,50 +0,0 @@ -import api from './api'; -import { dispatchError } from '../util'; - -export const TAG_FEATURE_TOGGLE = 'TAG_FEATURE_TOGGLE'; -export const UNTAG_FEATURE_TOGGLE = 'UNTAG_FEATURE_TOGGLE'; -export const START_TAG_FEATURE_TOGGLE = 'START_TAG_FEATURE_TOGGLE'; -export const START_UNTAG_FEATURE_TOGGLE = 'START_UNTAG_FEATURE_TOGGLE'; -export const ERROR_TAG_FEATURE_TOGGLE = 'ERROR_TAG_FEATURE_TOGGLE'; -export const ERROR_UNTAG_FEATURE_TOGGLE = 'ERROR_UNTAG_FEATURE_TOGGLE'; -export const START_FETCH_FEATURE_TOGGLE_TAGS = 'START_FETCH_FEATURE_TOGGLE_TAGS'; -export const RECEIVE_FEATURE_TOGGLE_TAGS = 'RECEIVE_FEATURE_TOGGLE_TAGS'; -export const ERROR_FETCH_FEATURE_TOGGLE_TAGS = 'ERROR_FETCH_FEATURE_TOGGLE_TAGS'; - -function receiveFeatureToggleTags(json) { - return { - type: RECEIVE_FEATURE_TOGGLE_TAGS, - value: json, - receivedAt: Date.now(), - }; -} - -export function tagFeature(featureToggle, tag) { - return dispatch => { - dispatch({ type: START_TAG_FEATURE_TOGGLE }); - return api - .tagFeature(featureToggle, tag) - .then(json => dispatch({ type: TAG_FEATURE_TOGGLE, featureToggle, tag: json })) - .catch(dispatchError(dispatch, ERROR_TAG_FEATURE_TOGGLE)); - }; -} - -export function untagFeature(featureToggle, tag) { - return dispatch => { - dispatch({ type: START_UNTAG_FEATURE_TOGGLE }); - return api - .untagFeature(featureToggle, tag) - .then(() => dispatch({ type: UNTAG_FEATURE_TOGGLE, featureToggle, tag })) - .catch(dispatchError(dispatch, ERROR_UNTAG_FEATURE_TOGGLE)); - }; -} - -export function fetchTags(featureToggle) { - return dispatch => { - dispatch({ type: START_FETCH_FEATURE_TOGGLE_TAGS }); - return api - .fetchFeatureToggleTags(featureToggle) - .then(json => dispatch(receiveFeatureToggleTags(json))) - .catch(dispatchError(dispatch, ERROR_FETCH_FEATURE_TOGGLE_TAGS)); - }; -} diff --git a/frontend/src/store/feature-tags/api.js b/frontend/src/store/feature-tags/api.js deleted file mode 100644 index 5b0574408d..0000000000 --- a/frontend/src/store/feature-tags/api.js +++ /dev/null @@ -1,44 +0,0 @@ -import { formatApiPath } from '../../utils/format-path'; -import { throwIfNotSuccess, headers } from '../api-helper'; - -const URI = formatApiPath('api/admin/features'); - -function tagFeature(featureToggle, tag) { - return fetch(`${URI}/${featureToggle}/tags`, { - method: 'POST', - headers, - credentials: 'include', - body: JSON.stringify(tag), - }) - .then(throwIfNotSuccess) - .then(response => response.json()); -} - -function untagFeature(featureToggle, tag) { - return fetch( - `${URI}/${featureToggle}/tags/${tag.type}/${encodeURIComponent( - tag.value - )}`, - { - method: 'DELETE', - headers, - credentials: 'include', - } - ).then(throwIfNotSuccess); -} - -function fetchFeatureToggleTags(featureToggle) { - return fetch(`${URI}/${featureToggle}/tags`, { - method: 'GET', - headers, - credentials: 'include', - }) - .then(throwIfNotSuccess) - .then(response => response.json()); -} - -export default { - tagFeature, - untagFeature, - fetchFeatureToggleTags, -}; diff --git a/frontend/src/store/feature-tags/index.js b/frontend/src/store/feature-tags/index.js deleted file mode 100644 index dcc6383ef4..0000000000 --- a/frontend/src/store/feature-tags/index.js +++ /dev/null @@ -1,25 +0,0 @@ -import { List, Map as $MAP } from 'immutable'; -import { RECEIVE_FEATURE_TOGGLE_TAGS, TAG_FEATURE_TOGGLE, UNTAG_FEATURE_TOGGLE } from './actions'; - -function getInitState() { - return new List(); -} - -const featureTags = (state = getInitState(), action) => { - switch (action.type) { - case RECEIVE_FEATURE_TOGGLE_TAGS: - if (action.value) { - return new List(action.value.tags); - } else { - return getInitState(); - } - case TAG_FEATURE_TOGGLE: - return state.push(new $MAP(action.tag)); - case UNTAG_FEATURE_TOGGLE: - return state.remove(state.findIndex(t => t.value === action.tag.value && t.type === action.tag.type)); - default: - return state; - } -}; - -export default featureTags; diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 18fb4f76e6..98be9e9f04 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -1,7 +1,6 @@ import { combineReducers } from 'redux'; import features from './feature-toggle'; import featureMetrics from './feature-metrics'; -import featureTags from './feature-tags'; import tagTypes from './tag-type'; import tags from './tag'; import strategies from './strategy'; @@ -18,7 +17,6 @@ const unleashStore = combineReducers({ strategies, tagTypes, tags, - featureTags, error, user, applications,