From 7c851c89312f3c060064a56ff1440f30ff2d9c34 Mon Sep 17 00:00:00 2001 From: ormus Date: Mon, 25 Apr 2016 23:02:38 +0300 Subject: [PATCH 1/3] Issue #28: Specoffer list - removed query params --- src/modules/navbar/NavBar.jsx | 6 +----- src/modules/settings/containers/timePeriodId.js | 11 ++++++++--- .../specoffers/containers/SpecoffersListPage.jsx | 16 ++++++++-------- src/modules/specoffers/reducers/index.js | 3 +-- src/modules/specoffers/reducers/list.js | 9 --------- src/modules/specoffers/reducers/view.js | 1 - 6 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/modules/navbar/NavBar.jsx b/src/modules/navbar/NavBar.jsx index a422585..eb48b19 100644 --- a/src/modules/navbar/NavBar.jsx +++ b/src/modules/navbar/NavBar.jsx @@ -29,7 +29,7 @@ export default class NavBar extends Component { Статистика - + Пропозиції @@ -95,10 +95,6 @@ function select(state) { ratingQueryParams: { departmentId: state.rating.specofferChooser.departmentId, specofferId: state.rating.specofferChooser.specofferId - }, - specoffersQueryParams: { - timePeriodId: state.specoffers.list.timePeriodId, - limit: state.specoffers.list.limit } }; } diff --git a/src/modules/settings/containers/timePeriodId.js b/src/modules/settings/containers/timePeriodId.js index 5c6c941..546e757 100644 --- a/src/modules/settings/containers/timePeriodId.js +++ b/src/modules/settings/containers/timePeriodId.js @@ -3,6 +3,8 @@ import React, {Component, PropTypes} from 'react'; import {connect} from 'react-redux'; import FormControl from 'react-bootstrap/lib/FormControl'; +import FormGroup from 'react-bootstrap/lib/FormGroup'; +import ControlLabel from 'react-bootstrap/lib/ControlLabel'; import { createSelector } from 'reselect'; import {TIMEPERIODS} from './../../dictionaries/constants'; import {isDictLoaded} from './../../dictionaries/helpers'; @@ -33,12 +35,15 @@ class TimePeriodId extends Component { }); return ( - + + + Оберіть вступну кампанію + value={timePeriodId} onChange={this.handleOptionChange}> { optionList } - + + ); } } diff --git a/src/modules/specoffers/containers/SpecoffersListPage.jsx b/src/modules/specoffers/containers/SpecoffersListPage.jsx index daf2bb2..688e06b 100644 --- a/src/modules/specoffers/containers/SpecoffersListPage.jsx +++ b/src/modules/specoffers/containers/SpecoffersListPage.jsx @@ -30,7 +30,7 @@ let buildCells = (decodedSpecoffers, specoffersFieldNames) => { }; class SpecoffersListPage extends Component { - + componentDidMount() { const {timePeriodId, limit} = this.props; this.props.loadDictionaries([dictConst.DEPARTMENTS, dictConst.SPECOFFERS_TYPES, dictConst.EDUCATION_FORM_TYPES]); @@ -84,22 +84,22 @@ class SpecoffersListPage extends Component { SpecoffersListPage.propTypes = { dispatch: PropTypes.func.isRequired, decodedSpecoffers: PropTypes.array.isRequired, - timePeriodId: PropTypes.string.isRequired, - limit: PropTypes.string.isRequired + timePeriodId: PropTypes.string.isRequired }; const mapStateToSpecoffers = createSelector( (state) => state.specoffers.list, (state) => state.dictionaries, - (state, ownProps) => ownProps.location.query, (state) => state.specoffers.list.specoffersFieldNames, (state) => state.specoffers.list.filterByName, - (list, listOfDict, query, specoffersFieldNames, filterByName) => ({ + (state) => state.settings.timePeriodId, + (state) => state.specoffers.list.limit, + (list, listOfDict, specoffersFieldNames, filterByName, timePeriodId, limit) => ({ decodedSpecoffers: decodeSpecoffers(filteredByName(list, filterByName), listOfDict), - timePeriodId: query.timePeriodId, - limit: query.limit, specoffersFieldNames: specoffersFieldNames, - filterByName: filterByName + filterByName: filterByName, + timePeriodId: timePeriodId, + limit: limit }) ); diff --git a/src/modules/specoffers/reducers/index.js b/src/modules/specoffers/reducers/index.js index 428a217..2e04042 100644 --- a/src/modules/specoffers/reducers/index.js +++ b/src/modules/specoffers/reducers/index.js @@ -8,7 +8,6 @@ import {LOCATION_CHANGE} from 'react-router-redux'; * export combined reducers (SPECOFFER REDUCER) */ export default combineReducers({ - list: ignoreActions(list, - (action) => action.type === LOCATION_CHANGE && action.payload.pathname !== '/specoffers/list'), + list, view }); \ No newline at end of file diff --git a/src/modules/specoffers/reducers/list.js b/src/modules/specoffers/reducers/list.js index 81e8df1..2d8a7b5 100644 --- a/src/modules/specoffers/reducers/list.js +++ b/src/modules/specoffers/reducers/list.js @@ -1,6 +1,5 @@ import * as types from '../constants'; import {SPECOFFERS_FIELD_NAMES} from '../constants'; -import {LOCATION_CHANGE} from 'react-router-redux'; import lcache from '../../../system/lcache'; import { TIMEPERIODID_CHANGED } from '../../settings/duck'; @@ -9,7 +8,6 @@ const defaultState = { isLoading: false, resources: [], specoffersFieldNames: SPECOFFERS_FIELD_NAMES, - timePeriodId: lcache.get('timePeriodId') || 8, filterByName: '', limit: 300, error: null @@ -41,13 +39,6 @@ export default function list(state = defaultState, action = {}) { } ); - case LOCATION_CHANGE: // listen to query parameters changes - //if (action.payload.pathname !== '/specoffers') return state; - let { - timePeriodId = state.timePeriodId, - limit = state.limit } = action.payload.query; - return Object.assign({}, state, {timePeriodId, limit}); - case types.SPECOFFERS_LIST_WIDTH_CHANGED: let changedName = { 'name': state.specoffersFieldNames[action.payload.columnKey].name, diff --git a/src/modules/specoffers/reducers/view.js b/src/modules/specoffers/reducers/view.js index 340a410..6d7fea4 100644 --- a/src/modules/specoffers/reducers/view.js +++ b/src/modules/specoffers/reducers/view.js @@ -1,7 +1,6 @@ import * as types from '../constants'; import {ENROLMENTS_FIELD_NAMES} from '../../enrolments/constants'; import {combineReducers} from 'redux'; -import {LOCATION_CHANGE} from 'react-router-redux'; export let getSpecofferEnrolmentsBySpecofferId = (state, specofferId) => { return state.specoffers.view.specofferEnrolments.data[specofferId] From 0a8397c99da61aefda9a524047e88dce0a8e739b Mon Sep 17 00:00:00 2001 From: ormus Date: Tue, 26 Apr 2016 22:07:44 +0300 Subject: [PATCH 2/3] Fix Loader in timePeriodId --- .../loader/{spinner.jsx => Spinner.js} | 2 +- .../settings/containers/timePeriodId.js | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) rename src/modules/commons/loader/{spinner.jsx => Spinner.js} (95%) diff --git a/src/modules/commons/loader/spinner.jsx b/src/modules/commons/loader/Spinner.js similarity index 95% rename from src/modules/commons/loader/spinner.jsx rename to src/modules/commons/loader/Spinner.js index 660af6c..cb30068 100644 --- a/src/modules/commons/loader/spinner.jsx +++ b/src/modules/commons/loader/Spinner.js @@ -1,6 +1,6 @@ import React from 'react' import './styles/spinner.styl' -import classNames from 'classNames' +import classNames from 'classnames' export default ({className}) =>
diff --git a/src/modules/settings/containers/timePeriodId.js b/src/modules/settings/containers/timePeriodId.js index 546e757..c3e4926 100644 --- a/src/modules/settings/containers/timePeriodId.js +++ b/src/modules/settings/containers/timePeriodId.js @@ -30,20 +30,22 @@ class TimePeriodId extends Component { let { isDictLoadedProp, timeperiods, timePeriodId } = this.props; + if (!isDictLoadedProp) { + return + } + const optionList = timeperiods.map((item, i) => { return ; }); return ( - - - Оберіть вступну кампанію - - { optionList } - - - + + Оберіть вступну кампанію + + { optionList } + + ); } } From bcac9b1f9ec7b7583ed8872187f0ceaf577f9f91 Mon Sep 17 00:00:00 2001 From: ormus Date: Wed, 27 Apr 2016 20:16:08 +0300 Subject: [PATCH 3/3] Issue #28: Specoffer list - moved params from component to action --- src/modules/specoffers/actions.js | 10 +++++++--- .../specoffers/containers/SpecoffersListPage.jsx | 16 +++++----------- src/system/middleware/request.js | 7 ++++++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/modules/specoffers/actions.js b/src/modules/specoffers/actions.js index f46f77d..09e364e 100644 --- a/src/modules/specoffers/actions.js +++ b/src/modules/specoffers/actions.js @@ -2,7 +2,7 @@ import {REQUEST_API} from '../../system/constants'; import * as types from './constants'; import {getSpecofferEnrolmentsBySpecofferId, getSpecofferInfoMain} from './reducers/view.js' -export function loadSpecoffersList(params) { +export function loadSpecoffersList() { return { type: REQUEST_API, request: { @@ -12,8 +12,12 @@ export function loadSpecoffersList(params) { success: {type: types.LOAD_ALL_SPECOFFERS_SUCCESS}, fail: {type: types.LOAD_ALL_SPECOFFERS_FAIL} }, - params, - cache: true + params: (store) => { + return { + limit: store.getState().specoffers.list.limit, + timePeriodId: store.getState().settings.timePeriodId + } + } }, interrupt: (store) => !!store.getState().specoffers.list.resources.length }; diff --git a/src/modules/specoffers/containers/SpecoffersListPage.jsx b/src/modules/specoffers/containers/SpecoffersListPage.jsx index 688e06b..c1072b8 100644 --- a/src/modules/specoffers/containers/SpecoffersListPage.jsx +++ b/src/modules/specoffers/containers/SpecoffersListPage.jsx @@ -32,9 +32,8 @@ let buildCells = (decodedSpecoffers, specoffersFieldNames) => { class SpecoffersListPage extends Component { componentDidMount() { - const {timePeriodId, limit} = this.props; this.props.loadDictionaries([dictConst.DEPARTMENTS, dictConst.SPECOFFERS_TYPES, dictConst.EDUCATION_FORM_TYPES]); - this.props.loadSpecoffersList({timePeriodId, limit}); + this.props.loadSpecoffersList(); } _onColumnResizeEndCallback = (newColumnWidth, columnKey) => { @@ -83,8 +82,7 @@ class SpecoffersListPage extends Component { SpecoffersListPage.propTypes = { dispatch: PropTypes.func.isRequired, - decodedSpecoffers: PropTypes.array.isRequired, - timePeriodId: PropTypes.string.isRequired + decodedSpecoffers: PropTypes.array.isRequired }; const mapStateToSpecoffers = createSelector( @@ -92,19 +90,15 @@ const mapStateToSpecoffers = createSelector( (state) => state.dictionaries, (state) => state.specoffers.list.specoffersFieldNames, (state) => state.specoffers.list.filterByName, - (state) => state.settings.timePeriodId, - (state) => state.specoffers.list.limit, - (list, listOfDict, specoffersFieldNames, filterByName, timePeriodId, limit) => ({ + (list, listOfDict, specoffersFieldNames, filterByName) => ({ decodedSpecoffers: decodeSpecoffers(filteredByName(list, filterByName), listOfDict), specoffersFieldNames: specoffersFieldNames, - filterByName: filterByName, - timePeriodId: timePeriodId, - limit: limit + filterByName: filterByName }) ); const mapDispatchToSpecoffers = (dispatch) => ( - { loadSpecoffersList: (params) => dispatch(loadSpecoffersList(params)), + { loadSpecoffersList: () => dispatch(loadSpecoffersList()), loadDictionaries: (dicArray) => dispatch(loadDictionaries(dicArray)), setSpecofferFieldWidth: (newColumnWidth, columnKey) => dispatch(setSpecofferFieldWidth(newColumnWidth, columnKey)), goToDetailed: (id) => dispatch(push(`/specoffers/${id}/enrolments`)), diff --git a/src/system/middleware/request.js b/src/system/middleware/request.js index f65a5fb..47f9f67 100644 --- a/src/system/middleware/request.js +++ b/src/system/middleware/request.js @@ -37,7 +37,8 @@ export default store => next => action => { } const {backendHost, token}= store.getState().config; - const {url, headers={}, method='get', params} = request; + const {url, headers={}, method='get'} = request; + let {params} = request; const {start, success, fail} = request.actions; const sendType = method === 'get' ? 'query' : 'send'; dispatchAction(store.dispatch, start, {payload: payload}); @@ -50,6 +51,10 @@ export default store => next => action => { .keys(headers) .forEach(key=>currentRequest.set(key, headers[key])); + if (isFunction(params)) { + params = params(store) + } + currentRequest[sendType](params) .end((error, response) => { if (error) {