connected seatch to wf catalog
[sdc/sdc-workflow-designer.git] / workflow-designer-ui / src / main / frontend / src / features / catalog / catalogSagas.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 { call, put, takeLatest, throttle } from 'redux-saga/effects';
18
19 import catalogApi from 'features/catalog/catalogApi';
20 import { fetchWorkflow, updateWorkflow } from 'features/catalog/catalogActions';
21 import {
22     SEARCH_CHANGED,
23     SEARCH_BUFFER
24 } from 'features/catalog/catalogConstants';
25
26 const noOp = () => {};
27
28 export function* fetchWorkflowSaga({ payload }) {
29     const { sort, limit, offset, searchNameFilter } = payload;
30     try {
31         const data = yield call(
32             catalogApi.getWorkflows,
33             sort,
34             limit,
35             offset === undefined ? 0 : offset + limit,
36             searchNameFilter
37         );
38         yield put(updateWorkflow({ sort, ...data }));
39     } catch (e) {
40         noOp();
41     }
42 }
43
44 function* catalogSaga() {
45     yield takeLatest(fetchWorkflow, fetchWorkflowSaga);
46     yield throttle(SEARCH_BUFFER, SEARCH_CHANGED, fetchWorkflowSaga);
47 }
48
49 export default catalogSaga;