2019-03-30 12:30:42 +00:00
|
|
|
import CanvasWidgetsNormalizer from "../normalizers/CanvasWidgetsNormalizer"
|
2019-09-13 09:56:11 +00:00
|
|
|
import { ReduxActionTypes, ReduxAction, LoadCanvasWidgetsPayload } from "../constants/ReduxActionConstants"
|
2019-03-30 12:30:42 +00:00
|
|
|
import PageApi, { PageResponse, PageRequest } from "../api/PageApi"
|
2019-09-13 09:56:11 +00:00
|
|
|
import { call, put, takeEvery, all } from "redux-saga/effects"
|
2019-03-30 12:30:42 +00:00
|
|
|
import { RenderModes } from "../constants/WidgetConstants"
|
|
|
|
|
|
|
|
|
|
export function* fetchPageSaga(pageRequestAction: ReduxAction<PageRequest>) {
|
|
|
|
|
const pageRequest = pageRequestAction.payload
|
2019-08-26 12:41:21 +00:00
|
|
|
try {
|
|
|
|
|
const pageResponse: PageResponse = yield call(PageApi.fetchPage, pageRequest)
|
|
|
|
|
if (pageRequest.renderMode === RenderModes.CANVAS) {
|
|
|
|
|
const normalizedResponse = CanvasWidgetsNormalizer.normalize(pageResponse)
|
2019-09-13 09:56:11 +00:00
|
|
|
const canvasWidgetsPayload: LoadCanvasWidgetsPayload = {
|
2019-08-26 12:41:21 +00:00
|
|
|
pageWidgetId: normalizedResponse.result,
|
|
|
|
|
widgets: normalizedResponse.entities.canvasWidgets
|
|
|
|
|
}
|
2019-09-13 09:56:11 +00:00
|
|
|
yield all([
|
|
|
|
|
put({ type: ReduxActionTypes.UPDATE_CANVAS, canvasWidgetsPayload }),
|
|
|
|
|
put({ type: ReduxActionTypes.LOAD_CANVAS_ACTIONS, payload: pageResponse.layout.actions })
|
|
|
|
|
])
|
2019-03-30 12:30:42 +00:00
|
|
|
}
|
2019-08-29 11:22:09 +00:00
|
|
|
} catch(err){
|
2019-08-26 12:41:21 +00:00
|
|
|
//TODO(abhinav): REFACTOR THIS
|
2019-03-30 12:30:42 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function* watchFetchPage() {
|
2019-09-12 11:19:38 +00:00
|
|
|
yield takeEvery(ReduxActionTypes.FETCH_PAGE, fetchPageSaga)
|
2019-03-30 12:30:42 +00:00
|
|
|
}
|