Skip to content

Commit

Permalink
Issue #28: Specoffer list - moved params from component to action
Browse files Browse the repository at this point in the history
  • Loading branch information
ormus2002 committed Apr 27, 2016
1 parent 0a8397c commit bcac9b1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
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,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) => {
Expand Down Expand Up @@ -83,28 +82,23 @@ 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(
(state) => state.specoffers.list,
(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`)),
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 bcac9b1

Please sign in to comment.