Sha256: cff389c064d2b365f178096b15500b3eeb2f320accc39c05575b5dd52e8e8064

Contents?: true

Size: 1.95 KB

Versions: 36

Compression:

Stored size: 1.95 KB

Contents

import Immutable from 'seamless-immutable';
import { combineReducers } from 'redux';
import { union } from 'lodash';
import { createTableReducer } from 'foremanReact/components/common/table';
import createTableActionTypes from 'foremanReact/components/common/table/actionsHelpers/actionTypeCreator';
import {
  TASKS_TABLE_ID,
  SELECT_ROWS,
  UNSELECT_ROWS,
  UNSELECT_ALL_ROWS,
  UPDATE_CLICKED,
  SELECT_ALL_ROWS,
  OPEN_SELECT_ALL,
} from './TasksTableConstants';

const initialState = Immutable({
  selectedRows: [],
});

export const TasksTableQueryReducer = (state = initialState, action) => {
  const { type, payload, response } = action;
  const {
    subtotal,
    per_page: perPageString,
    action_name: actionName,
    can_edit: canEdit,
  } = response || {};
  const ACTION_TYPES = createTableActionTypes(TASKS_TABLE_ID);
  switch (type) {
    case SELECT_ALL_ROWS:
      return state.set('allRowsSelected', true);
    case ACTION_TYPES.SUCCESS:
      return Immutable.merge(state, {
        itemCount: subtotal,
        actionName,
        perPage: Number(perPageString),
        selectedRows: [],
        permissions: {
          edit: canEdit,
        },
      });
    case SELECT_ROWS:
      return state.set('selectedRows', union(payload, state.selectedRows));
    case OPEN_SELECT_ALL:
      return state.set('showSelectAll', true);
    case UNSELECT_ROWS:
      return state
        .set(
          'selectedRows',
          state.selectedRows.filter(row => row !== payload.id)
        )
        .set('showSelectAll', false)
        .set('allRowsSelected', false);
    case UNSELECT_ALL_ROWS:
      return state
        .set('selectedRows', [])
        .set('allRowsSelected', false)
        .set('showSelectAll', false);
    case UPDATE_CLICKED:
      return state.set('clicked', payload.clicked);
    default:
      return state;
  }
};
export default combineReducers({
  tasksTableContent: createTableReducer(TASKS_TABLE_ID),
  tasksTableQuery: TasksTableQueryReducer,
});

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
foreman-tasks-10.0.2 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-10.0.1 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-10.0.0 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-9.2.3 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-9.2.2 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-9.2.1 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-9.2.0 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-9.1.1 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-9.0.4 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-9.1.0 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-9.0.2 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-9.0.1 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-8.3.3 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-9.0.0 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-8.2.1 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-8.1.4 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-8.3.2 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-8.3.1 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-8.1.3 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js
foreman-tasks-8.3.0 webpack/ForemanTasks/Components/TasksTable/TasksTableReducer.js