Migrate sdc-sdc-workflow-designer docs
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-ui / src / main / frontend / src / features / catalog / catalogReducer.js
1 /*
2 * Copyright © 2018 European Support Limited
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http: //www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 import {
18     NAME,
19     ASC,
20     UPDATE_WORKFLOW,
21     SEARCH_CHANGED
22 } from 'features/catalog/catalogConstants';
23 import { WORKFLOW_STATUS } from 'features/workflow/workflowConstants';
24 export const initialState = {
25     paging: {
26         hasMore: true,
27         total: 0
28     },
29     sort: {
30         [NAME]: ASC
31     },
32     status: WORKFLOW_STATUS.ACTIVE,
33     //In order to save state inside iframe session
34     searchNameFilter: sessionStorage.getItem('searchNameFilter') || ''
35 };
36
37 const catalogReducer = (state = initialState, action) => {
38     const { type, payload } = action;
39
40     switch (type) {
41         case UPDATE_WORKFLOW:
42             return {
43                 ...state,
44                 ...payload,
45                 items:
46                     payload.paging.offset === 0
47                         ? [...payload.items]
48                         : [...state.items, ...payload.items]
49             };
50         case SEARCH_CHANGED:
51             return {
52                 ...state,
53                 searchNameFilter: action.payload.searchNameFilter
54             };
55         default:
56             return state;
57     }
58 };
59
60 export default catalogReducer;