mirror of
https://github.com/datahub-project/datahub.git
synced 2025-10-14 18:38:27 +00:00
adds actions for browse.entity to request nodes and child entities in view.
This commit is contained in:
parent
756cd8f072
commit
06917ea4f4
69
wherehows-web/app/actions/browse/entity.js
Normal file
69
wherehows-web/app/actions/browse/entity.js
Normal file
@ -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 };
|
@ -24,7 +24,6 @@ const ActionTypes = {
|
||||
};
|
||||
|
||||
const requestPagedDatasets = createAction(ActionTypes.REQUEST_PAGED_DATASETS);
|
||||
|
||||
const receivePagedDatasets = createAction(
|
||||
ActionTypes.RECEIVE_PAGED_DATASETS,
|
||||
({ data }) => data,
|
||||
|
@ -38,7 +38,7 @@ const fetchPagedUrnEntities = entity => getState => {
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* Request urn child nodes/ datasets for the specified entity
|
||||
* @param entity
|
||||
*/
|
||||
const fetchNodes = entity => getState => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user