Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #152 from cglewis/dev
Browse files Browse the repository at this point in the history
closes #134
  • Loading branch information
cglewis committed Apr 16, 2020
2 parents 5c14f1b + 7f633be commit 69f2c20
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Grid, Button } from 'semantic-ui-react';
import { startFetchResults, stopFetchResults } from "epics/auto-fetch-results-epic"
import { fetchResults } from 'epics/fetch-results-epic'
import { fetchToolStatus } from 'epics/fetch-status-epic'
import { fetchTools } from 'epics/fetch-tools-epic'
import { setSessionId, getResults, getToolStatuses } from 'domain/data';

import './App.css';
Expand Down Expand Up @@ -47,6 +48,7 @@ class App extends React.Component {
fetchResults = () => {
console.log("Peasant Burnination initiated...");
this.props.fetchResults({ 'sessionId': this.state.sessionId });
this.props.fetchTools();
console.log("Peasant Burnination complete!");
}

Expand All @@ -59,6 +61,7 @@ class App extends React.Component {
console.log("This House Oldification complete")
}


render() {
return (
<>
Expand Down Expand Up @@ -107,6 +110,7 @@ const mapDispatchToProps = {
setSessionId,
fetchResults,
fetchToolStatus,
fetchTools,
startFetchResults,
stopFetchResults,
};
Expand Down
14 changes: 13 additions & 1 deletion ui/src/components/table/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { connect } from "react-redux";
import { Tab, Icon, Label } from 'semantic-ui-react';
import './Table.css';

import { getResults, getToolStatuses } from 'domain/data';
import { getResults, getToolStatuses, getTools } from 'domain/data';

const customStyles = {
rows: {
Expand Down Expand Up @@ -78,6 +78,16 @@ class Table extends React.Component{
renderTool = (item, type) => {
const id = item.id;
const value = item.tool;

console.log(this.props.tools);
for(const tool of this.props.tools){
if(tool.name == value && tool.viewableOutput == false) {
return(
<p>This tool does not generate results.</p>
)
}
}

const url = `/${type}/${this.props.sessionId}/${id}/${value}`
return(
<p key={id + ":" +value}>
Expand Down Expand Up @@ -133,9 +143,11 @@ const mapStateToProps = (state, ownProps) => {

const results = getResults(state);
const toolStatuses = getToolStatuses(state);
const tools = getTools(state);
return{
rows: results.rows || [],
statuses: toolStatuses || {},
tools: tools || [],
}
};

Expand Down
14 changes: 13 additions & 1 deletion ui/src/domain/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const defaultState = {
const setSessionId = createAction("SET_SESSION_ID");
const setResults = createAction("SET_RESULTS");
const setToolStatus = createAction("SET_TOOL_STATUS");
const setTools = createAction("SET_TOOLS");

// REDUCERS
const reducer = handleActions(
Expand All @@ -29,6 +30,10 @@ const reducer = handleActions(
state.results.rows = resultRows
return { ...state};
},
[setTools]: (state, { payload }) => {
state.tools = payload;
return { ...state};
},
[setToolStatus]: (state, { payload }) => {
if(!state.toolStatus) state.toolStatus ={};

Expand Down Expand Up @@ -65,6 +70,10 @@ const _getToolStatuses = (toolStatuses, toolId) => {
return status;
}

const _getTools = (tools) => {
return tools;
}

// SELECTORS
const getResults = (state) => {
return _getResults(state.data.results);
Expand All @@ -75,7 +84,10 @@ const getToolStatus = (state, toolId) => {
const getToolStatuses = (state) => {
return _getToolStatuses(state.data.toolStatus || {}, null)
}
const getTools = (state) => {
return _getTools(state.data.tools || [], null)
}

export default reducer;

export { setSessionId, setResults, getResults, setToolStatus, getToolStatus, getToolStatuses }
export { setSessionId, setResults, setTools, getResults, setToolStatus, getToolStatus, getToolStatuses, getTools }
45 changes: 45 additions & 0 deletions ui/src/epics/fetch-tools-epic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { createAction } from 'redux-actions';
import { ofType } from 'redux-observable';
import { of } from 'rxjs';
import { ajax as rxAjax } from 'rxjs/ajax';
import { catchError, debounceTime, mergeMap, map } from 'rxjs/operators';

import { setTools } from "domain/data";

// ACTIONS
const fetchTools = createAction('FETCH_TOOLS');

// EPIC
const fetchToolsEpic = (action$, store, ajax = rxAjax) => {
return action$.pipe(
ofType(fetchTools.toString())
,debounceTime(500)
,mergeMap((action) => {
const url = '/tools';
return ajax({ 'url': url, 'crossDomain': true, 'responseType': 'json' }).pipe(
map((result) => {
const resp = result.response;
const tools = [];
const keys = Object.keys(resp);
for(const key of keys){
const items = resp[key];
for(const item of items){
tools.push(item);
}
}
console.log("tools: ");
console.log(tools);
return tools;
})
,map(setTools)
);
})
,catchError((error) => {
console.log("error xhr: %o", error)
const newErr = new Error("Error fetching Tools: " + error.message);
})
);
}

export default fetchToolsEpic;
export { fetchTools };
2 changes: 2 additions & 0 deletions ui/src/epics/root-epic.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import autoFetchResultsEpic from "epics/auto-fetch-results-epic"
import fetchResultsEpic from './fetch-results-epic';
import fetchToolStatusEpic from './fetch-status-epic';
import fetchToolResultsEpic from './fetch-tool-results-epic';
import fetchToolsEpic from './fetch-tools-epic';

const rootEpic = combineEpics(
autoFetchResultsEpic,
fetchResultsEpic,
fetchToolStatusEpic,
fetchToolResultsEpic,
fetchToolsEpic,
);

export default rootEpic;

0 comments on commit 69f2c20

Please sign in to comment.