This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
/
DatasetsSagas.js
65 lines (60 loc) · 2.13 KB
/
DatasetsSagas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {
takeLatest,
call,
put,
fork,
select
} from "redux-saga/effects"
import { showLoading, hideLoading } from 'react-redux-loading-bar'
import * as actions from "../containers/Datasets/actions"
import { notificationShow } from "../containers/Root/actions.js"
import * as api from "../services/ClientAPI"
import { getToken } from "./utils";
import { push } from "connected-react-router"
// List Datasets
function* watchGetDSListRequest() {
yield takeLatest(actions.Types.REQUEST_LS_DS, getDatasetList)
}
/* for List Dataset command */
function* getDatasetList() {
try {
yield put(showLoading())
const token = yield select(getToken)
const DSList = yield call(api.requestDatasetList, {}, token)
console.log(DSList)
yield put(actions.populateDSList(DSList.data))
yield put(hideLoading())
} catch (e) {
console.error(e.response)
console.error(e)
yield put(notificationShow("Failed to Fetch DatasetList"));
// TODO: implement notification for success and error of api actions
// yield put(actions.getErrorStatus("failed to deleteUser"))
}
}
function* watchPostDatasetsRequest() {
yield takeLatest(actions.Types.CREATE_DATASET, createDataset)
}
function* createDataset(action) {
const {name, task, file, dataset_url} = action
try {
yield put(showLoading())
const token = yield select(getToken)
yield call(api.postCreateDataset, name, task, file, dataset_url, token)
console.log("Create Dataset success")
yield alert("Create Dataset success")
yield put(notificationShow("Create Dataset Success")); // no need to write test for this
yield(push('console/datasets/list-dataset'))
yield put(hideLoading())
} catch(e) {
console.error(e.response)
console.error(e)
console.error(e.response.data)
yield put(notificationShow("Failed to Create Dataset"));
}
}
// fork is for process creation, run in separate processes
export default [
fork(watchGetDSListRequest),
fork(watchPostDatasetsRequest)
]