application/redux/reducers/ssts-reducers.js
- import _ from 'lodash';
- import Immutable from 'immutable';
- import {
- SSTSS_REQUEST,
- SSTSS_RECEIVE,
- SSTSS_RECEIVE_PAGINATION,
- SSTS_RECEIVE,
- SSTSS_INVALIDATE,
- SSTS_SELECTED,
- SSTSS_SET_PAGE
- } from './../actions/ssts-actions';
-
- const PER_PAGE = 20;
-
- export function sstss(state = null, action) {
- if (state === null) {
- state = {
- isFetching: false,
- didInvalidate: false,
- items: Immutable.fromJS({}),
- selected: false,
- page: 0,
- pagination: {
- before: 0,
- current: 0,
- first: 0,
- last: 0,
- limit: 0,
- next: 0,
- total_items: 0,
- total_pages: 0
- },
- order: "name",
- dir: "asc",
- filter: false
- };
- }
-
- let newState;
-
- switch (action.type) {
- case SSTSS_RECEIVE_PAGINATION:
- return Object.assign({}, state, {
- pagination: {
- 'before': action.payload.before,
- 'current': action.payload.current,
- 'first': action.payload.first,
- 'last': action.payload.last,
- 'limit': action.payload.limit,
- 'next': action.payload.next,
- 'total_items': action.payload.total_items,
- 'total_pages': action.payload.total_pages,
- }
- });
- case SSTSS_INVALIDATE:
- return Object.assign({}, state, {
- didInvalidate: true,
- });
- case SSTSS_REQUEST:
- return Object.assign({}, state, {
- isFetching: true,
- didInvalidate: false
- });
- case SSTS_SELECTED: {
- return Object.assign({}, state, {
- selected: action.payload.selected
- });
- }
- case SSTS_RECEIVE:
- const ssts = action.payload.ssts;
- let found = false;
- const allSstss = state.items.map((item, i) => {
- if (item.get('uuid') == ssts.get('uuid')) {
- found = true;
- return ssts;
- }
- return item;
- });
-
- if (!found) {
- let temp = allSstss.toList().asMutable();
- temp.push(ssts);
- action.payload.sstss = temp.asMutable();
- } else {
- action.payload.sstss = allSstss;
- }
- case SSTSS_RECEIVE:
- return Object.assign({}, state, {
- isFetching: false,
- didInvalidate: false,
- items: action.payload.sstss
- });
- }
-
- return state;
- };