Skip to content

Commit d9f2376

Browse files
committed
Load demo steps via AJAX, emit source map.
1 parent f82df5b commit d9f2376

12 files changed

+12218
-59
lines changed

demo/demo.js

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@ import url from 'url';
66
// Loaded on index.html, defined as an external in webpack.config.demo.js
77
import Graph, { GraphParser } from 'react-workflow-viz';
88

9-
// TODO: Load via AJAX or something, replace 'steps' with a 'href', ..
10-
11-
import { STEPS as testWorkflowBedToBedDB } from './testdata/workflow-bedtobeddb';
12-
import { STEPS as testWorkflowAtacSeq } from './testdata/workflow-atac-seq';
13-
import { STEPS as testFileProcessed4DNFI9WF1Y8W } from './testdata/provenance-file-processed-4DNFI9WF1Y8W';
14-
import { STEPS as testFileProcessedGAPFIWCFWBCO } from './testdata/provenance-file-processed-GAPFIWCFWBCO';
15-
import { STEPS as testExpset4DNESUJC9Y83 } from './testdata/provenance-expset-4DNESUJC9Y83';
16-
import { STEPS as testExpset4DNES54YB6TQ } from './testdata/provenance-expset-4DNES54YB6TQ';
17-
18-
9+
// eslint-disable-next-line no-undef
10+
const BASE_HREF = (typeof BUILDTYPE === "string" && BUILDTYPE === "development") ? "http://localhost:8100/demo/testdata/" : "https://unpkg.com/@hms-dbmi-bgm/react-workflow-viz/demo/testdata/"
1911

2012
const workflowOpts = {
2113
//"showReferenceFiles": true,
@@ -29,39 +21,44 @@ class DemoApp extends Component {
2921
{
3022
"name" : "File Processed - 4DNFI9WF1Y8W",
3123
"description" : null,
32-
"steps" : testFileProcessed4DNFI9WF1Y8W,
33-
// todo:
34-
//"href" : "https://unpkg.com/@hms-dbmi-bgm/react-workflow-viz/demo/testdata/provenance-file-processed-4DNFI9WF1Y8W.json",
24+
"href" : url.resolve(BASE_HREF, "provenance-file-processed-4DNFI9WF1Y8W.json"),
3525
"opts" : {}
3626
},
3727
{
3828
"name" : "File Processed - GAPFIWCFWBCO",
3929
"description" : null,
40-
"steps" : testFileProcessedGAPFIWCFWBCO,
30+
"href" : url.resolve(BASE_HREF, "provenance-file-processed-GAPFIWCFWBCO.json"),
31+
"opts" : {}
32+
},
33+
{
34+
"name" : "File Processed - GAPFIRPF7X1K",
35+
"description" : null,
36+
"href" : url.resolve(BASE_HREF, "provenance-file-processed-GAPFIRPF7X1K.json"),
4137
"opts" : {}
4238
},
4339
{
4440
"name" : "Experiment Set - 4DNES54YB6TQ",
4541
"description" : null,
46-
"steps" : testExpset4DNES54YB6TQ,
42+
"href" : url.resolve(BASE_HREF, "provenance-expset-4DNES54YB6TQ.json"),
4743
"opts" : {}
4844
},
45+
4946
{
5047
"name" : "Experiment Set - 4DNESUJC9Y83",
5148
"description" : null,
52-
"steps" : testExpset4DNESUJC9Y83,
49+
"href" : url.resolve(BASE_HREF, "provenance-expset-4DNESUJC9Y83.json"),
5350
"opts" : {}
5451
},
5552
{
5653
"name" : "CWL Workflow - ATAC-SEQ",
5754
"description" : null,
58-
"steps" : testWorkflowAtacSeq,
55+
"href" : url.resolve(BASE_HREF, "workflow-atac-seq.json"),
5956
"opts" : workflowOpts
6057
},
6158
{
6259
"name" : "CWL Workflow - BED to BEDDB",
6360
"description" : null,
64-
"steps" : testWorkflowBedToBedDB,
61+
"href" : url.resolve(BASE_HREF, "workflow-bedtobeddb.json"),
6562
"opts" : workflowOpts
6663
}
6764
]
@@ -74,17 +71,22 @@ class DemoApp extends Component {
7471
this.handleDemoChange = this.handleDemoChange.bind(this);
7572
this.loadDemoData = this.loadDemoData.bind(this);
7673
this.state = {
77-
currentDemoIdx: 1,
74+
currentDemoIdx: 0,
7875
parsingOptions: {
7976
showReferenceFiles: true,
8077
showParameters: false,
8178
showIndirectFiles: false,
8279
parseBasicIO: false
8380
},
81+
loadedSteps: {},
8482
rowSpacingType: "compact"
8583
};
8684
}
8785

86+
componentDidMount(){
87+
this.loadDemoData();
88+
}
89+
8890
handleParsingOptChange(evt){
8991
const key = evt.target.getAttribute("name");
9092
if (!key) return false;
@@ -116,30 +118,40 @@ class DemoApp extends Component {
116118

117119
loadDemoData(){
118120
const { testData } = this.props;
119-
const { currentDemoIdx } = this.state;
121+
const { currentDemoIdx, loadedSteps } = this.state;
120122
const currDemoInfo = testData[currentDemoIdx];
121123
const { name, href } = currDemoInfo;
122-
const existingSteps = currDemoInfo.steps || this.state['loadedStepsFor: ' + name];
124+
125+
const existingSteps = currDemoInfo.steps || loadedSteps[name];
126+
123127
if (!Array.isArray(existingSteps)) {
124-
this.setState({ loadingSteps: true },()=>{
128+
this.setState({ loadingSteps: true }, ()=>{
125129
window.fetch(url.resolve(window.location.href, href)).then((resp)=>{
126-
return JSON.parse(resp);
130+
return resp.json();
127131
}).then((resp)=>{
128-
this.setState({ ['loadedStepsFor: ' + name] : resp, loadingSteps: false });
132+
this.setState(function({ loadedSteps: prevSteps }){
133+
return {
134+
loadedSteps: { ...prevSteps, [name] : resp },
135+
loadingSteps: false
136+
};
137+
});
129138
});
130139
});
131140
}
141+
132142
}
133143

134144
render(){
135145
const { testData } = this.props;
136-
const { currentDemoIdx, parsingOptions, rowSpacingType } = this.state;
137-
const { name, description, steps, opts: overrideOpts } = testData[currentDemoIdx];
146+
const { currentDemoIdx, parsingOptions, rowSpacingType, loadedSteps, loadingSteps } = this.state;
147+
const { name, description, steps: preloadedSteps, opts: overrideOpts } = testData[currentDemoIdx];
138148
const fullParseOpts = { ...parsingOptions, ...overrideOpts };
139149

150+
const steps = preloadedSteps || loadedSteps[name];
151+
140152
return (
141153
<div className="demo-app-container">
142-
<TestDataSelect {...{ currentDemoIdx, testData }} onChange={this.handleDemoChange} />
154+
<TestDataSelect {...{ currentDemoIdx, testData, loadingSteps }} onChange={this.handleDemoChange} />
143155
<ParsingOptsCheckboxes {...parsingOptions} dataOpts={overrideOpts}
144156
onChange={this.handleParsingOptChange} onChangeBasicIO={this.handleChangeBasicIO} />
145157
<RowSpacingTypeSelect rowSpacingType={rowSpacingType} onChange={this.handleRowSpacingTypeChange} />
@@ -154,16 +166,16 @@ class DemoApp extends Component {
154166

155167

156168
function TestDataSelect(props){
157-
const { currentDemoIdx, testData, onChange } = props;
169+
const { currentDemoIdx, testData, onChange, loadingSteps = false } = props;
158170
const { name: currDemoName } = testData[currentDemoIdx];
159171
const optionItems = testData.map(function({ name, steps, description }, idx){
160172
return <option name={idx} key={idx}>{ name }</option>;
161173
});
162174
return (
163175
<div className="row-spacing-type-container options-container">
164176
<label>
165-
<h5>Test Data</h5>
166-
<select onChange={onChange} value={currDemoName}>
177+
<h5>Test Data { loadingSteps ? <small>(loading...)</small> : null }</h5>
178+
<select onChange={onChange} value={currDemoName} disabled={loadingSteps}>
167179
{ optionItems }
168180
</select>
169181
</label>

demo/testdata/provenance-expset-4DNES54YB6TQ.js renamed to demo/testdata/provenance-expset-4DNES54YB6TQ.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const STEPS = [
1+
[
22
{
33
"outputs":[
44
{
@@ -3835,4 +3835,4 @@ export const STEPS = [
38353835
"@id":"/workflow-runs-awsem/5d0e1af2-be6a-41b8-96ad-84eb6a6ab4ba/"
38363836
}
38373837
}
3838-
];
3838+
]

demo/testdata/provenance-expset-4DNESUJC9Y83.js renamed to demo/testdata/provenance-expset-4DNESUJC9Y83.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const STEPS = [
1+
[
22
{
33
"outputs":[
44
{
@@ -2393,4 +2393,4 @@ export const STEPS = [
23932393
"@id":"/workflow-runs-awsem/b7c603e6-8b82-4d8e-ac50-6c0860e94707/"
23942394
}
23952395
}
2396-
];
2396+
]

demo/testdata/provenance-file-processed-4DNFI9WF1Y8W.js renamed to demo/testdata/provenance-file-processed-4DNFI9WF1Y8W.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const STEPS = [
1+
[
22
{
33
"name":"/workflow-runs-awsem/d353e726-2a47-4e93-b1f4-cfa7037ee3bc/",
44
"inputs":[
@@ -2804,4 +2804,4 @@ export const STEPS = [
28042804
}
28052805
}
28062806
}
2807-
];
2807+
]

0 commit comments

Comments
 (0)