From 7cbd06834f9cbc7f31cff74153fbde249414b57b Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Wed, 21 Dec 2016 16:39:29 -0700 Subject: [PATCH 1/3] set defaults on fetchAssets --- client/coral-admin/src/actions/assets.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/coral-admin/src/actions/assets.js b/client/coral-admin/src/actions/assets.js index 92f511d5f..930feba5e 100644 --- a/client/coral-admin/src/actions/assets.js +++ b/client/coral-admin/src/actions/assets.js @@ -14,9 +14,9 @@ import coralApi from '../../../coral-framework/helpers/response'; // Fetch a page of assets // Get comments to fill each of the three lists on the mod queue -export const fetchAssets = (skip, limit, search, sort, filter) => (dispatch) => { +export const fetchAssets = (skip = '', limit = '', search = '', sort = '', filter = '') => (dispatch) => { dispatch({type: FETCH_ASSETS}); - return coralApi(`/assets?skip=${skip || ''}&limit=${limit || ''}&sort=${sort || ''}&search=${search || ''}&filter=${filter || ''}`) + return coralApi(`/assets?skip=${skip}&limit=${limit}&sort=${sort}&search=${search}&filter=${filter}`) .then(({result, count}) => dispatch({type: FETCH_ASSETS_SUCCESS, assets: result, From 7fc3dffc77252413e1cfc90b53cde43182d29e74 Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Wed, 21 Dec 2016 16:49:53 -0700 Subject: [PATCH 2/3] reload assets after updating state --- client/coral-admin/src/containers/Streams/Streams.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/coral-admin/src/containers/Streams/Streams.js b/client/coral-admin/src/containers/Streams/Streams.js index 55fe10fc2..559621fc5 100644 --- a/client/coral-admin/src/containers/Streams/Streams.js +++ b/client/coral-admin/src/containers/Streams/Streams.js @@ -60,7 +60,11 @@ class Streams extends Component { prev.statusMenus[id] = false; return prev; }); - this.props.updateAssetState(id, closeStream ? Date.now() : null); + this.props.updateAssetState(id, closeStream ? Date.now() : null) + .then(() => { + const {search, sort, filter, page} = this.state; + this.props.fetchAssets(page, limit, search, sort, filter); + }); } else { this.setState(prev => { prev.statusMenus[id] = true; @@ -169,9 +173,7 @@ const mapDispatchToProps = (dispatch) => { fetchAssets: (...args) => { dispatch(fetchAssets.apply(this, args)); }, - updateAssetState: (...args) => { - dispatch(updateAssetState.apply(this, args)); - } + updateAssetState: (...args) => dispatch(updateAssetState.apply(this, args)) }; }; From b8b47e9c2c987382e27fe872e0e4f8b6e46cb7dc Mon Sep 17 00:00:00 2001 From: Riley Davis Date: Wed, 21 Dec 2016 16:56:29 -0700 Subject: [PATCH 3/3] normalize constant names --- client/coral-admin/src/actions/assets.js | 16 ++++++++-------- client/coral-admin/src/constants/assets.js | 8 ++++---- client/coral-admin/src/reducers/assets.js | 4 ++-- tests/client/coral-admin/actions/assets.js | 16 ++++++++-------- tests/client/coral-admin/reducers/assets.js | 4 ++-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/client/coral-admin/src/actions/assets.js b/client/coral-admin/src/actions/assets.js index 930feba5e..f431f1ad6 100644 --- a/client/coral-admin/src/actions/assets.js +++ b/client/coral-admin/src/actions/assets.js @@ -1,10 +1,10 @@ import { - FETCH_ASSETS, + FETCH_ASSETS_REQUEST, FETCH_ASSETS_SUCCESS, - FETCH_ASSETS_FAILED, - UPDATE_ASSET_STATE, + FETCH_ASSETS_FAILURE, + UPDATE_ASSET_STATE_REQUEST, UPDATE_ASSET_STATE_SUCCESS, - UPDATE_ASSET_STATE_FAILED + UPDATE_ASSET_STATE_FAILURE } from '../constants/assets'; import coralApi from '../../../coral-framework/helpers/response'; @@ -15,22 +15,22 @@ import coralApi from '../../../coral-framework/helpers/response'; // Fetch a page of assets // Get comments to fill each of the three lists on the mod queue export const fetchAssets = (skip = '', limit = '', search = '', sort = '', filter = '') => (dispatch) => { - dispatch({type: FETCH_ASSETS}); + dispatch({type: FETCH_ASSETS_REQUEST}); return coralApi(`/assets?skip=${skip}&limit=${limit}&sort=${sort}&search=${search}&filter=${filter}`) .then(({result, count}) => dispatch({type: FETCH_ASSETS_SUCCESS, assets: result, count })) - .catch(error => dispatch({type: FETCH_ASSETS_FAILED, error})); + .catch(error => dispatch({type: FETCH_ASSETS_FAILURE, error})); }; // Update an asset state // Get comments to fill each of the three lists on the mod queue export const updateAssetState = (id, closedAt) => (dispatch) => { - dispatch({type: UPDATE_ASSET_STATE}); + dispatch({type: UPDATE_ASSET_STATE_REQUEST}); return coralApi(`/assets/${id}/status`, {method: 'PUT', body: {closedAt}}) .then(() => dispatch({type: UPDATE_ASSET_STATE_SUCCESS})) - .catch(error => dispatch({type: UPDATE_ASSET_STATE_FAILED, error})); + .catch(error => dispatch({type: UPDATE_ASSET_STATE_FAILURE, error})); }; diff --git a/client/coral-admin/src/constants/assets.js b/client/coral-admin/src/constants/assets.js index 8927b351d..0a2ecf73c 100644 --- a/client/coral-admin/src/constants/assets.js +++ b/client/coral-admin/src/constants/assets.js @@ -1,6 +1,6 @@ -export const FETCH_ASSETS = 'FETCH_ASSETS'; +export const FETCH_ASSETS_REQUEST = 'FETCH_ASSETS_REQUEST'; export const FETCH_ASSETS_SUCCESS = 'FETCH_ASSETS_SUCCESS'; -export const FETCH_ASSETS_FAILED = 'FETCH_ASSETS_FAILED'; -export const UPDATE_ASSET_STATE = 'UPDATE_ASSET_STATE'; +export const FETCH_ASSETS_FAILURE = 'FETCH_ASSETS_FAILURE'; +export const UPDATE_ASSET_STATE_REQUEST = 'UPDATE_ASSET_STATE_REQUEST'; export const UPDATE_ASSET_STATE_SUCCESS = 'UPDATE_ASSET_STATE_SUCCESS'; -export const UPDATE_ASSET_STATE_FAILED = 'UPDATE_ASSET_STATE_FAILED'; +export const UPDATE_ASSET_STATE_FAILURE = 'UPDATE_ASSET_STATE_FAILURE'; diff --git a/client/coral-admin/src/reducers/assets.js b/client/coral-admin/src/reducers/assets.js index f18aaec33..77d0bf081 100644 --- a/client/coral-admin/src/reducers/assets.js +++ b/client/coral-admin/src/reducers/assets.js @@ -1,5 +1,5 @@ import {Map, List, fromJS} from 'immutable'; -import {FETCH_ASSETS_SUCCESS, UPDATE_ASSET_STATE} from '../constants/assets'; +import {FETCH_ASSETS_SUCCESS, UPDATE_ASSET_STATE_REQUEST} from '../constants/assets'; const initialState = Map({ byId: Map(), @@ -10,7 +10,7 @@ export default (state = initialState, action) => { switch (action.type) { case FETCH_ASSETS_SUCCESS: return replaceAssets(action, state); - case UPDATE_ASSET_STATE: + case UPDATE_ASSET_STATE_REQUEST: return state.setIn(['byId', action.id, 'closedAt'], action.closedAt); default: return state; } diff --git a/tests/client/coral-admin/actions/assets.js b/tests/client/coral-admin/actions/assets.js index 55addb805..24a28daef 100644 --- a/tests/client/coral-admin/actions/assets.js +++ b/tests/client/coral-admin/actions/assets.js @@ -30,7 +30,7 @@ describe('Asset actions', () => { fetchMock.restore(); }); - describe('FETCH_ASSETS', () => { + describe('FETCH_ASSETS_REQUEST', () => { it('should fetch a list of assets', () => { @@ -41,7 +41,7 @@ describe('Asset actions', () => { return actions.fetchAssets(2, 20)(store.dispatch) .then(() => { - expect(store.getActions()[0]).to.have.property('type', 'FETCH_ASSETS'); + expect(store.getActions()[0]).to.have.property('type', 'FETCH_ASSETS_REQUEST'); expect(store.getActions()[1]).to.have.property('type', 'FETCH_ASSETS_SUCCESS'); expect(store.getActions()[1]).to.have.property('count', 2); expect(store.getActions()[1]).to.have.property('assets'). @@ -55,13 +55,13 @@ describe('Asset actions', () => { return actions.fetchAssets(2, 20)(store.dispatch) .then(() => { - expect(store.getActions()[0]).to.have.property('type', 'FETCH_ASSETS'); - expect(store.getActions()[1]).to.have.property('type', 'FETCH_ASSETS_FAILED'); + expect(store.getActions()[0]).to.have.property('type', 'FETCH_ASSETS_REQUEST'); + expect(store.getActions()[1]).to.have.property('type', 'FETCH_ASSETS_FAILURE'); }); }); }); - describe('UPDATE_ASSET_STATE', () => { + describe('UPDATE_ASSET_STATE_REQUEST', () => { it('should update an asset', () => { @@ -69,7 +69,7 @@ describe('Asset actions', () => { return actions.updateAssetState('123', 'status', 'open')(store.dispatch) .then(() => { - expect(store.getActions()[0]).to.have.property('type', 'UPDATE_ASSET_STATE'); + expect(store.getActions()[0]).to.have.property('type', 'UPDATE_ASSET_STATE_REQUEST'); expect(store.getActions()[1]).to.have.property('type', 'UPDATE_ASSET_STATE_SUCCESS'); }); @@ -81,8 +81,8 @@ describe('Asset actions', () => { return actions.updateAssetState('123', 'status', 'open')(store.dispatch) .then(() => { - expect(store.getActions()[0]).to.have.property('type', 'UPDATE_ASSET_STATE'); - expect(store.getActions()[1]).to.have.property('type', 'UPDATE_ASSET_STATE_FAILED'); + expect(store.getActions()[0]).to.have.property('type', 'UPDATE_ASSET_STATE_REQUEST'); + expect(store.getActions()[1]).to.have.property('type', 'UPDATE_ASSET_STATE_FAILURE'); }); }); }); diff --git a/tests/client/coral-admin/reducers/assets.js b/tests/client/coral-admin/reducers/assets.js index 60972f47a..753061612 100644 --- a/tests/client/coral-admin/reducers/assets.js +++ b/tests/client/coral-admin/reducers/assets.js @@ -36,10 +36,10 @@ describe ('assetsReducer', () => { }); }); - describe('UPDATE_ASSET_STATE', () => { + describe('UPDATE_ASSET_STATE_REQUEST', () => { it('should update the state of a particular asset', () => { const action = { - type: 'UPDATE_ASSET_STATE', + type: 'UPDATE_ASSET_STATE_REQUEST', id: '123', closedAt: null };