mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	refactor: remove unused feature tags state (#689)
This commit is contained in:
		
							parent
							
								
									83778a9928
								
							
						
					
					
						commit
						b7d106d7ab
					
				@ -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));
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
@ -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,
 | 
			
		||||
};
 | 
			
		||||
@ -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;
 | 
			
		||||
@ -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,
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user