Remove CurrentPlanReducer

Current plan state is simple enough that it can become part of plans
state

Change-Id: I135341b41cb4301c5e9ddf7e5f7cc76a99adf577
This commit is contained in:
Jiri Tomasek 2017-06-23 15:29:09 +02:00 committed by Ana Krivokapic
parent a2d103b83c
commit 868a585f50
13 changed files with 36 additions and 135 deletions

View File

@ -26,7 +26,6 @@ import NodesActions from '../../js/actions/NodesActions';
import NotificationActions from '../../js/actions/NotificationActions';
import * as utils from '../../js/services/utils';
import { IronicNode } from '../../js/immutableRecords/nodes';
import { CurrentPlanState } from '../../js/immutableRecords/currentPlan';
let createResolvingPromise = data => {
return () => {
@ -114,15 +113,13 @@ describe('nodesRegistrationFinished', () => {
() => {
return {
plans: new InitialPlanState({
currentPlanName: 'testplan',
plansLoaded: true,
all: Map({
testplan: new Plan({
name: 'testplan'
})
})
}),
currentPlan: new CurrentPlanState({
currentPlanName: 'testplan'
})
};
},
@ -173,15 +170,13 @@ describe('nodesRegistrationFinished', () => {
() => {
return {
plans: new InitialPlanState({
currentPlanName: 'testplan',
plansLoaded: true,
all: Map({
testplan: new Plan({
name: 'testplan'
})
})
}),
currentPlan: new CurrentPlanState({
currentPlanName: 'testplan'
})
};
},

View File

@ -1,48 +0,0 @@
/**
* Copyright 2017 Red Hat Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
import { CurrentPlanState } from '../../js/immutableRecords/currentPlan';
import currentPlanReducer from '../../js/reducers/currentPlanReducer';
import CurrentPlanActions from '../../js/actions/CurrentPlanActions';
describe('plansReducer state', () => {
describe('default state', () => {
let state;
beforeEach(() => {
state = currentPlanReducer(undefined, { type: 'undefined-action' });
});
it('`currentPlanName` is undefined', () => {
expect(state.get('currentPlanName')).not.toBeDefined();
});
});
describe('PLAN_CHOSEN', () => {
let state;
beforeEach(() => {
state = currentPlanReducer(
new CurrentPlanState(),
CurrentPlanActions.planChosen('another-cloud')
);
});
it('sets the current planName', () => {
expect(state.get('currentPlanName')).toEqual('another-cloud');
});
});
});

View File

@ -16,6 +16,7 @@
import { List, Map } from 'immutable';
import CurrentPlanActions from '../../js/actions/CurrentPlanActions';
import {
InitialPlanState,
Plan,
@ -39,6 +40,10 @@ describe('plansReducer state', () => {
it('`all` is empty', () => {
expect(state.get('all').size).toEqual(0);
});
it('`currentPlanName` is undefined', () => {
expect(state.get('currentPlanName')).not.toBeDefined();
});
});
describe('CREATE_PLAN_PENDING', () => {
@ -137,6 +142,21 @@ describe('plansReducer state', () => {
});
});
describe('PLAN_CHOSEN', () => {
let state;
beforeEach(() => {
state = plansReducer(
new InitialPlanState(),
CurrentPlanActions.planChosen('another-cloud')
);
});
it('sets the current planName', () => {
expect(state.get('currentPlanName')).toEqual('another-cloud');
});
});
describe('Plan deletion', () => {
let state = Map({
all: Map({

View File

@ -19,12 +19,12 @@ import { Map } from 'immutable';
import { Plan } from '../../js/immutableRecords/plans';
import { getAllPlansButCurrent } from '../../js/selectors/plans';
import { InitialPlanState } from '../../js/immutableRecords/plans';
import { CurrentPlanState } from '../../js/immutableRecords/currentPlan';
describe('plans selectors', () => {
describe('getAllPlansButCurrent()', () => {
const state = {
plans: new InitialPlanState({
currentPlanName: 'plan1',
isFetchingPlans: false,
all: Map({
plan1: new Plan({
@ -38,9 +38,6 @@ describe('plans selectors', () => {
files: Map()
})
})
}),
currentPlan: new CurrentPlanState({
currentPlanName: 'plan1'
})
};

View File

@ -21,7 +21,6 @@ import {
getCurrentStack,
getOvercloudInfo
} from '../../js/selectors/stacks';
import { CurrentPlanState } from '../../js/immutableRecords/currentPlan';
import { InitialPlanState, Plan } from '../../js/immutableRecords/plans';
import { Stack, StacksState } from '../../js/immutableRecords/stacks';
@ -43,15 +42,13 @@ describe('stacks selectors', () => {
}),
currentStackEnvironment: Map(),
plans: new InitialPlanState({
currentPlanName: 'overcloud',
plansLoaded: true,
all: Map({
overcloud: new Plan({
name: 'overcloud'
})
})
}),
currentPlan: new CurrentPlanState({
currentPlanName: 'overcloud'
})
};
});
@ -128,15 +125,13 @@ describe('stacks selectors', () => {
})
}),
plans: new InitialPlanState({
currentPlanName: 'overcloud',
plansLoaded: true,
all: Map({
overcloud: new Plan({
name: 'overcloud'
})
})
}),
currentPlan: new CurrentPlanState({
currentPlanName: 'overcloud'
})
};
@ -163,15 +158,13 @@ describe('stacks selectors', () => {
})
}),
plans: new InitialPlanState({
currentPlanName: 'overcloud',
plansLoaded: true,
all: Map({
overcloud: new Plan({
name: 'overcloud'
})
})
}),
currentPlan: new CurrentPlanState({
currentPlanName: 'overcloud'
})
};
expect(getCurrentStackDeploymentInProgress(state)).toBe(true);
@ -192,15 +185,13 @@ describe('stacks selectors', () => {
})
}),
plans: new InitialPlanState({
currentplanname: 'overcloud',
plansLoaded: true,
all: Map({
overcloud: new Plan({
name: 'overcloud'
})
})
}),
currentPlan: new CurrentPlanState({
currentplanname: 'overcloud'
})
};
expect(getCurrentStackDeploymentInProgress(state)).toBe(false);
@ -217,15 +208,13 @@ describe('stacks selectors', () => {
})
}),
plans: new InitialPlanState({
currentplanname: 'overcloud',
plansLoaded: true,
all: Map({
overcloud: new Plan({
name: 'overcloud'
})
})
}),
currentPlan: new CurrentPlanState({
currentplanname: 'overcloud'
})
};
expect(getCurrentStackDeploymentInProgress(state)).toBe(false);

View File

@ -22,7 +22,6 @@ import {
ActiveFilter,
FiltersInitialState
} from '../../js/immutableRecords/filters';
import { CurrentPlanState } from '../../js/immutableRecords/currentPlan';
import { InitialPlanState, Plan } from '../../js/immutableRecords/plans';
import {
WorkflowExecution
@ -34,6 +33,7 @@ describe(' validations selectors', () => {
beforeEach(() => {
state = {
plans: new InitialPlanState({
currentPlanName: 'overcloud',
plansLoaded: true,
all: Map({
overcloud: new Plan({
@ -41,9 +41,6 @@ describe(' validations selectors', () => {
})
})
}),
currentPlan: new CurrentPlanState({
currentPlanName: 'overcloud'
}),
filters: FiltersInitialState(),
validations: Map({
validationsLoaded: true,

View File

@ -1,21 +0,0 @@
/**
* Copyright 2017 Red Hat Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
import { Record } from 'immutable';
export const CurrentPlanState = Record({
currentPlanName: undefined
});

View File

@ -34,6 +34,7 @@ export const PlanFile = Record({
});
export const InitialPlanState = Record({
currentPlanName: undefined,
isFetchingPlans: false,
plansLoaded: false,
isTransitioningPlan: false,

View File

@ -17,7 +17,6 @@
import { combineReducers } from 'redux';
import { reducer as formReducer } from 'redux-form';
import currentPlanReducer from './currentPlanReducer';
import environmentConfigurationReducer from './environmentConfigurationReducer';
import filtersReducer from './filtersReducer';
import i18nReducer from './i18nReducer';
@ -33,7 +32,6 @@ import validationsReducer from './validationsReducer';
import workflowExecutionsReducer from './workflowExecutionsReducer';
const appReducer = combineReducers({
currentPlan: currentPlanReducer,
environmentConfiguration: environmentConfigurationReducer,
executions: workflowExecutionsReducer,
filters: filtersReducer,

View File

@ -1,30 +0,0 @@
/**
* Copyright 2017 Red Hat Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
import { CurrentPlanState } from '../immutableRecords/currentPlan';
import PlansConstants from '../constants/PlansConstants';
const initialState = new CurrentPlanState();
export default function currentPlanReducer(state = initialState, action) {
switch (action.type) {
case PlansConstants.PLAN_CHOSEN:
return state.set('currentPlanName', action.payload);
default:
return state;
}
}

View File

@ -52,6 +52,9 @@ export default function plansReducer(state = initialState, action) {
.set('all', Map(planData));
}
case PlansConstants.PLAN_CHOSEN:
return state.set('currentPlanName', action.payload);
case PlansConstants.DELETE_PLAN_PENDING: {
return state.setIn(['all', action.payload, 'transition'], 'deleting');
}

View File

@ -17,7 +17,7 @@
import { createSelector } from 'reselect';
export const plans = state => state.plans.get('all').sortBy(plan => plan.name);
export const currentPlanName = state => state.currentPlan.currentPlanName;
export const currentPlanName = state => state.plans.currentPlanName;
export const getCurrentPlan = createSelector(
plans,

View File

@ -20,12 +20,12 @@ import createLogger from 'redux-logger';
import logger from './services/logger';
import appReducer from './reducers/appReducer';
import { CurrentPlanState } from './immutableRecords/currentPlan';
import { InitialPlanState } from './immutableRecords/plans';
import { getIntl } from './selectors/i18n';
const hydrateStore = () => {
return {
currentPlan: new CurrentPlanState({
plans: new InitialPlanState({
currentPlanName: getStoredPlanName()
})
};