Skip to content

Commit

Permalink
Merge pull request #40 from mkozhukharenko/ormus
Browse files Browse the repository at this point in the history
Issue #28: Specoffer list - removed query params
  • Loading branch information
mkozhukharenko committed Apr 27, 2016
2 parents 44ac46b + bcac9b1 commit 82210cb
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 38 deletions.
6 changes: 1 addition & 5 deletions src/modules/navbar/NavBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default class NavBar extends Component {
<NavItem>Статистика</NavItem>
</LinkContainer>

<LinkContainer to={{ pathname: '/specoffers/list', query: this.props.specoffersQueryParams}}>
<LinkContainer to={{ pathname: '/specoffers/list'}}>
<NavItem>Пропозиції</NavItem>
</LinkContainer>

Expand Down Expand Up @@ -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
}
};
}
Expand Down
19 changes: 13 additions & 6 deletions src/modules/settings/containers/timePeriodId.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -28,17 +30,22 @@ class TimePeriodId extends Component {

let { isDictLoadedProp, timeperiods, timePeriodId } = this.props;

if (!isDictLoadedProp) {
return <Loader className="body" isLoading />
}

const optionList = timeperiods.map((item, i) => {
return <option value={i} key={i}>{item}</option>;
});

return (
<Loader className="body" isLoading={!isDictLoadedProp}>
<FormControl componentClass="select" placeholder="Оберіть вступну кампанію"
value={timePeriodId} onChange={this.handleOptionChange}>
{ optionList }
</FormControl>
</Loader>
<FormGroup controlId="formControlsSelect">
<ControlLabel>Оберіть вступну кампанію</ControlLabel>
<FormControl componentClass="select" placeholder="Оберіть вступну кампанію"
value={timePeriodId} onChange={this.handleOptionChange}>
{ optionList }
</FormControl>
</FormGroup>
);
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/modules/specoffers/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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
};
Expand Down
16 changes: 5 additions & 11 deletions src/modules/specoffers/containers/SpecoffersListPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ 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) => {
Expand Down Expand Up @@ -84,28 +83,23 @@ class SpecoffersListPage extends Component {

SpecoffersListPage.propTypes = {
dispatch: PropTypes.func.isRequired,
decodedSpecoffers: PropTypes.array.isRequired,
timePeriodId: PropTypes.string.isRequired,
limit: PropTypes.string.isRequired
decodedSpecoffers: PropTypes.array.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) => ({
(list, listOfDict, specoffersFieldNames, filterByName) => ({
decodedSpecoffers: decodeSpecoffers(filteredByName(list, filterByName), listOfDict),
timePeriodId: query.timePeriodId,
limit: query.limit,
specoffersFieldNames: specoffersFieldNames,
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`)),
Expand Down
3 changes: 1 addition & 2 deletions src/modules/specoffers/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
9 changes: 0 additions & 9 deletions src/modules/specoffers/reducers/list.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,7 +8,6 @@ const defaultState = {
isLoading: false,
resources: [],
specoffersFieldNames: SPECOFFERS_FIELD_NAMES,
timePeriodId: lcache.get('timePeriodId') || 8,
filterByName: '',
limit: 300,
error: null
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/modules/specoffers/reducers/view.js
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
7 changes: 6 additions & 1 deletion src/system/middleware/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -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) {
Expand Down

0 comments on commit 82210cb

Please sign in to comment.