Skip to content

Commit

Permalink
Merge pull request #566 from neuroscout/frontend_regressions
Browse files Browse the repository at this point in the history
Fixes for frontend regressions.
  • Loading branch information
adelavega committed May 15, 2019
2 parents 6394bbc + 521d49a commit 803ca18
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
2 changes: 1 addition & 1 deletion neuroscout/frontend/src/AnalysisList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AnalysisList extends React.Component<AnalysisListProps> {
title: 'Name',
render: (text, record: AppAnalysis) => (
<Link to={`/builder/${record.id}`}>
{record.name}
<div className="recordName">{record.name}</div>
</Link>
),
sorter: (a, b) => a.name.localeCompare(b.name)
Expand Down
4 changes: 4 additions & 0 deletions neuroscout/frontend/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,7 @@ pre {
max-width: 100%;
max-height: 80vh;
}

.recordName {
word-break: break-all;
}
28 changes: 20 additions & 8 deletions neuroscout/frontend/src/Builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
an analysis.
*/
import { RouteComponentProps } from 'react-router';
import { Redirect } from 'react-router-dom';
import { createBrowserHistory } from 'history';
import * as React from 'react';
import {
Expand Down Expand Up @@ -122,7 +123,8 @@ let initializeStore = (): Store => ({
activeContrastIndex: -1,
xformErrors: [],
contrastErrors: [],
fillAnalysis: false
fillAnalysis: false,
analysis404: false
});

// Get list of tasks from a given dataset
Expand Down Expand Up @@ -230,10 +232,16 @@ export default class AnalysisBuilder extends React.Component<BuilderProps & Rout
jwtFetch(`${domainRoot}/api/analyses/${props.id}`)
// .then(response => response.json() as Promise<ApiAnalysis>)
.then((data: ApiAnalysis) => {
this.loadAnalysis(data);
return data;
if ((data as any).statusCode === 404) {
this.setState({analysis404: true});
return;
} else {
this.loadAnalysis(data);
return data;
}
})
.then((data: ApiAnalysis) => {
if (this.state.analysis404) { return; }
if (editableStatus.includes(data.status)) {
this.setState({model: this.buildModel()});
} else if (data.model !== undefined) {
Expand Down Expand Up @@ -469,7 +477,7 @@ export default class AnalysisBuilder extends React.Component<BuilderProps & Rout
status: data.status,
modifiedAt: data.modified_at
},
postReports: true,
postReports: analysis.contrasts.length > 0,
unsavedChanges: false
});
// will this mess with /fill workflow?
Expand All @@ -490,7 +498,7 @@ export default class AnalysisBuilder extends React.Component<BuilderProps & Rout
// Decode data returned by '/api/analyses/<id>' (ApiAnalysis) to convert it to the right shape (Analysis)
// and fetch the associated runs
loadAnalysis = (data: ApiAnalysis): Promise<Analysis> => {

if (this.state.analysis404) { return Promise.reject('404'); }
data.transformations = [];

// Extract transformations and contrasts from within step object of response.
Expand Down Expand Up @@ -805,7 +813,8 @@ export default class AnalysisBuilder extends React.Component<BuilderProps & Rout
since state changes aren't really user edits we don't want to set unsavedChanges.
*/
updateState = (attrName: keyof Store, keepClean = false, saveToAPI = false) => (value: any) => {
const { analysis, availableRuns, availablePredictors, datasets } = this.state;
const { analysis, availableRuns, availablePredictors } = this.state;
const { datasets } = this.props;
/*
if (!editableStatus.includes(analysis.status) && !keepClean) {
message.warning('This analysis is locked and cannot be edited');
Expand All @@ -829,7 +838,6 @@ export default class AnalysisBuilder extends React.Component<BuilderProps & Rout
updatedAnalysis.runIds = this.runIdsFromModel(data, updatedAnalysis.model.Input);
}
}

if (availTasks.length === 1) {
stateUpdate = {
...stateUpdate,
Expand Down Expand Up @@ -991,6 +999,9 @@ export default class AnalysisBuilder extends React.Component<BuilderProps & Rout
}

render() {
if (this.state.analysis404) {
return <Redirect to="/builder/" />;
}
let {
predictorsActive,
transformationsActive,
Expand Down Expand Up @@ -1024,6 +1035,7 @@ export default class AnalysisBuilder extends React.Component<BuilderProps & Rout
this.postTabChange(activeTab);
}
return (

<div className="App">
<Prompt
when={unsavedChanges}
Expand Down Expand Up @@ -1116,7 +1128,7 @@ export default class AnalysisBuilder extends React.Component<BuilderProps & Rout
updateBuilderState={this.updateState}
/>
<br/>
{this.navButtons()}
{this.navButtons(!(this.state.analysis.contrasts.length > 0))}
<br/>
</TabPane>}
<TabPane tab="Review" key="review" disabled={((!reviewActive || !analysis.analysisId) && isDraft)}>
Expand Down
1 change: 1 addition & 0 deletions neuroscout/frontend/src/coretypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export interface Store {
xformErrors: string[];
contrastErrors: string[];
fillAnalysis: boolean;
analysis404: boolean;
}

export interface ApiRun {
Expand Down
31 changes: 16 additions & 15 deletions neuroscout/frontend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,23 @@ export const jwtFetch = (path: string, options?: object) => {
});
throw new Error('Please Login Again');
}
if (response.status !== 200) {
// displayError(new Error(`HTTP ${response.status} on ${path}`));
if (response.status >= 400) {
return { statusCode: response.status };
} else {
return response.json().then(json => {
// Always add statusCode to the data object or array returned by response.json()
let copy: any;
if ('length' in json) {
// array
copy = [...json];
(copy as any).statusCode = response.status;
} else {
// object
copy = { ...json, statusCode: response.status };
}
return copy;
});
}
return response.json().then(json => {
// Always add statusCode to the data object or array returned by response.json()
let copy: any;
if ('length' in json) {
// array
copy = [...json];
(copy as any).statusCode = response.status;
} else {
// object
copy = { ...json, statusCode: response.status };
}
return copy;
});
});
};

Expand Down

0 comments on commit 803ca18

Please sign in to comment.