Sha256: 1e93cd52bdc367a7686b9be3da030ae63aeebae280c1418a5a4d0aa624df76f1

Contents?: true

Size: 1.19 KB

Versions: 11

Compression:

Stored size: 1.19 KB

Contents

import Immutable from 'seamless-immutable';
import {
  LAYOUT_CHANGE_ORG,
  LAYOUT_INITIALIZE,
} from 'foremanReact/components/Layout/LayoutConstants';
import {
  INVENTORY_FILTER_UPDATE,
  INVENTORY_FILTER_CLEAR,
  ANY_ORGANIZATION,
} from './InventoryFilterConstants';

const initialState = Immutable({
  filterTerm: '',
});

export default (
  state = initialState,
  { type, payload: { filterTerm, org, organization } = {} }
) => {
  switch (type) {
    case INVENTORY_FILTER_UPDATE:
      return state.merge({
        filterTerm,
      });
    case INVENTORY_FILTER_CLEAR:
      return state.merge({
        filterTerm: '',
      });
    case LAYOUT_CHANGE_ORG: {
      const { title } = org;
      const term = title === ANY_ORGANIZATION ? '' : title;
      return state.merge({
        filterTerm: term,
      });
    }
    case LAYOUT_INITIALIZE: {
      // Layout action changed in Jul 20 2020 - https://github.com/theforeman/foreman/commit/e4c39a7d8f8b50ba45ef63e46f6f6914b69f247a
      const { title } = organization; // org was renamed
      const term = title === ANY_ORGANIZATION ? '' : title;
      return state.merge({
        filterTerm: term,
      });
    }
    default:
      return state;
  }
};

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
foreman_rh_cloud-2.0.18.1 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js
foreman_rh_cloud-2.0.18 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js
foreman_rh_cloud-2.0.17 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js
foreman_rh_cloud-2.0.16 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js
foreman_rh_cloud-2.0.15 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js
foreman_rh_cloud-3.0.14 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js
foreman_rh_cloud-2.0.14 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js
foreman_rh_cloud-2.0.13.1 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js
foreman_rh_cloud-2.0.13 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js
foreman_rh_cloud-2.0.12 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js
foreman_rh_cloud-2.0.11 webpack/ForemanInventoryUpload/Components/InventoryFilter/InventoryFilterReducer.js