UNPKG

@talend/react-containers

Version:

Provide connected components aka containers for @talend/react-cmf based on @talend/react-components.

53 lines (52 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; exports.onPushNotification = onPushNotification; var _effects = require("redux-saga/effects"); var _reactCmf = _interopRequireDefault(require("@talend/react-cmf")); var _utils = require("@talend/utils"); var _Notification = _interopRequireDefault(require("./Notification.connect")); var _Notification2 = _interopRequireDefault(require("./Notification.constants")); var _Notification3 = require("./Notification.actions"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const CMF_CONST = _reactCmf.default.constants; const onError = _reactCmf.default.onError; const DEFAULT_COMPONENT_ID = 'Notification'; function* onPushNotification(action) { const componentState = yield (0, _effects.select)(state => _Notification.default.getState(state, DEFAULT_COMPONENT_ID)); const newComponentState = componentState.updateIn(['notifications'], notifications => notifications.push({ id: (0, _utils.randomUUID)(), ...action.notification })); const updateStateAction = _Notification.default.setStateAction(newComponentState, DEFAULT_COMPONENT_ID); yield (0, _effects.put)(updateStateAction); } function* onCMFError(action) { if (process.env.DISABLE_JS_ERROR_NOTIFICATION && process.env.NODE_ENV === 'production') { return; } const error = action.error; const download = { href: onError.createObjectURL(error), label: 'Download details', download: 'report.json', 'data-feature': 'download-on-error-details' }; const notification = { type: 'error', title: error.name, message: error.message, action: download }; yield (0, _effects.put)((0, _Notification3.pushError)(notification)); } function* defaultHandler() { yield (0, _effects.takeEvery)(_Notification2.default.PUSH_NOTIFICATION, onPushNotification); yield (0, _effects.takeEvery)(CMF_CONST.ERROR, onCMFError); } var _default = exports.default = { 'Notification#default': defaultHandler }; //# sourceMappingURL=Notification.sagas.js.map