From 06917ea4f495303c47ee4705bc92aa860d1e3614 Mon Sep 17 00:00:00 2001 From: Seyi Adebajo Date: Wed, 26 Apr 2017 00:48:55 -0700 Subject: [PATCH] adds actions for browse.entity to request nodes and child entities in view. --- wherehows-web/app/actions/browse/entity.js | 69 +++++++++++++++++++ wherehows-web/app/actions/datasets.js | 1 - .../app/actions/entities/entity-request.js | 2 +- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 wherehows-web/app/actions/browse/entity.js diff --git a/wherehows-web/app/actions/browse/entity.js b/wherehows-web/app/actions/browse/entity.js new file mode 100644 index 0000000000..0046632860 --- /dev/null +++ b/wherehows-web/app/actions/browse/entity.js @@ -0,0 +1,69 @@ +import Ember from 'ember'; +import { createAction } from 'redux-actions'; + +import actionSet from 'wherehows-web/actions/action-set'; +import { lazyRequestUrnPagedDatasets, lazyRequestDatasetNodes } from 'wherehows-web/actions/datasets'; + +const { debug } = Ember; + +const ActionTypes = { + REQUEST_NODE_LIST: actionSet('REQUEST_NODE_LIST'), + RECEIVE_NODE_LIST: actionSet('RECEIVE_NODE_LIST') +}; + +/** + * Start and end wrapping actions for request an entities node list + */ +const requestNodeList = createAction(ActionTypes.REQUEST_NODE_LIST); +const receiveNodeList = createAction(ActionTypes.RECEIVE_NODE_LIST); + +/** + * Wraps action sequence for request node list and related child entities for urn + * @param {Object} params + * @param {String} listURL + * @param {Array} queryParams current list of query parameters for the Ember route + */ +const asyncRequestNodeList = (params, listURL, { queryParams }) => + /** + * Async thunk + * @param {Function} dispatch + * @return {Promise.<*>} + */ + async function(dispatch) { + const { entity, page, urn } = params; + const query = { page, urn }; + + dispatch(requestNodeList({ entity, listURL, query, queryParams })); + + try { + let nodesResult = {}, pagedEntities = {}; + switch (entity) { + case 'datasets': + [nodesResult, pagedEntities] = await [ + dispatch(lazyRequestDatasetNodes({ listURL, query })), + dispatch(lazyRequestUrnPagedDatasets({ query })) + ]; + break; + case 'metrics': + case 'flows': + default: + return; + } + // If there are no errors on the action payloads, dispatch `receiveNodeList` action creator with nodesResult + // and exit handler + if (!pagedEntities.error || !nodesResult.error) { + return dispatch(receiveNodeList({ nodesResult, entity })); + } + + return dispatch( + receiveNodeList( + new Error(`An error occurred requesting data. list: ${nodesResult.status} entities:${pagedEntities.status}`) + ) + ); + } catch (e) { + debug(e); + return dispatch(receiveNodeList(new Error(`An error occurred requesting data ${e}`))); + } + }; + +export { ActionTypes, asyncRequestNodeList }; diff --git a/wherehows-web/app/actions/datasets.js b/wherehows-web/app/actions/datasets.js index fc53f97588..c6e88a98cc 100644 --- a/wherehows-web/app/actions/datasets.js +++ b/wherehows-web/app/actions/datasets.js @@ -24,7 +24,6 @@ const ActionTypes = { }; const requestPagedDatasets = createAction(ActionTypes.REQUEST_PAGED_DATASETS); - const receivePagedDatasets = createAction( ActionTypes.RECEIVE_PAGED_DATASETS, ({ data }) => data, diff --git a/wherehows-web/app/actions/entities/entity-request.js b/wherehows-web/app/actions/entities/entity-request.js index 776c6cb542..842b872bad 100644 --- a/wherehows-web/app/actions/entities/entity-request.js +++ b/wherehows-web/app/actions/entities/entity-request.js @@ -38,7 +38,7 @@ const fetchPagedUrnEntities = entity => getState => { }; /** - * + * Request urn child nodes/ datasets for the specified entity * @param entity */ const fetchNodes = entity => getState => {