Skip to content

Commit

Permalink
detector + results bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wkozyra95 committed Jan 31, 2018
1 parent 6735904 commit 5ec4eb6
Show file tree
Hide file tree
Showing 20 changed files with 152 additions and 49 deletions.
5 changes: 3 additions & 2 deletions config/docker.run.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

echo "window.env = {};" > $1/env.js
echo "window.env.BACKEND_PUBLIC_URL = \"$YAPTIDE_BACKEND_PUBLIC_URL\";" >> $1/env.js
echo "window.process = window.process || {};" > $1/env.js
echo "window.process.env = {};" >> $1/env.js
echo "window.process.env.BACKEND_PUBLIC_URL = \"$YAPTIDE_BACKEND_PUBLIC_URL\";" >> $1/env.js

nginx -c /etc/nginx/nginx.conf
1 change: 1 addition & 0 deletions config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ if (!__TEST__) {

plugins.push(
new webpack.DefinePlugin({
'process.env.BACKEND_PUBLIC_URL': JSON.stringify(BACKEND_PUBLIC_URL),
__DEV__,
__TEST__,
__PROD__,
Expand Down
1 change: 1 addition & 0 deletions flow/decl/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ declare var require: {
ensure(ids: Array<string>, callback?: { (require: typeof require): void }, chunk?: string): void
}
declare var BACKEND_PUBLIC_URL: string;
declare var process: Object;
13 changes: 4 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/api/endpoint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow */
window.env = window.env || {};
export const baseURL = `${window.location.protocol}//${window.env.BACKEND_PUBLIC_URL}`;
window.process = window.process || {};
window.process.env = window.process.env || {};
export const baseURL = `${window.location.protocol}//${window.process.env.BACKEND_PUBLIC_URL}`;

export type Endpoint = 'LOGIN' |
'REGISTER';
Expand Down
18 changes: 9 additions & 9 deletions src/components/Chart/ChartInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ class ChartInterface extends React.Component<Props> {
let axis1Label = { label: 'unknown', unit: 'unknown', startValue: 0, endValue: 100 };
let axis2Label = { label: 'unknown', unit: 'unknown', startValue: 0, endValue: 100 };
if (this.props.data.length === 1) {
axis1Label = this.props.labels.dimensions[1];
axis2Label = this.props.labels.dimensions[2];
data = _.flatten(this.props.data);
} else if (this.props.data[0].length > 1) {
axis1Label = this.props.labels.dimensions[0];
axis2Label = this.props.labels.dimensions[2];
data = _.map(this.props.data, item => _.flatten(item));
} else if (this.props.data[0][0].length > 1) {
axis1Label = this.props.labels.dimensions[0];
axis1Label = this.props.labels.dimensions[2];
axis2Label = this.props.labels.dimensions[1];
data = this.props.data[0];
} else if (this.props.data[0].length === 1) {
axis1Label = this.props.labels.dimensions[2];
axis2Label = this.props.labels.dimensions[0];
data = _.map(this.props.data, item => item[0]);
} else if (this.props.data[0][0].length === 1) {
axis1Label = this.props.labels.dimensions[1];
axis2Label = this.props.labels.dimensions[0];
data = _.map(this.props.data, array2d => _.map(array2d, array1d => array1d[0]));
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const UNDEFINED_ZONE = '-------------';

type Props = {
name: string,
label: string,
updateName: (value: string) => void,
classes: Object,
};
Expand All @@ -19,7 +20,7 @@ type State = {
name: string,
};

class ZoneName extends React.Component<Props, State> {
class EditableName extends React.Component<Props, State> {
props: Props
state: State = {
isEditOn: false,
Expand All @@ -45,7 +46,6 @@ class ZoneName extends React.Component<Props, State> {
? (
<TextField
value={this.state.name}
name="zone name"
onBlur={this.stopEditing}
onChange={this.updateName}
inputRef={this.setRef}
Expand All @@ -58,7 +58,7 @@ class ZoneName extends React.Component<Props, State> {
className={classes.label}
noWrap
>
{`Zone: ${this.props.name}` || UNDEFINED_ZONE}
{`${this.props.label}${this.props.name}` || UNDEFINED_ZONE}
</Typography>
</div>
)
Expand All @@ -74,4 +74,4 @@ const styles = (theme: Object) => ({
},
});

export default withStyles(styles)(ZoneName);
export default withStyles(styles)(EditableName);
5 changes: 3 additions & 2 deletions src/components/Editor/ZoneEditor/ZoneEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import Style from 'styles';
import Typography from 'material-ui/Typography';
import { withStyles } from 'material-ui/styles';
import {
ZoneName,
ZoneOperation,
MaterialSelector,
} from 'components/Editor/ZoneEditor';
import { EditableName } from 'components/Editor';
import type { OperationType, ConstructionPath, PrintableOperation } from 'model/simulation/zone';
import type { PrintableMaterial } from 'model/simulation/material';

Expand All @@ -35,7 +35,8 @@ class ZoneEditor extends React.Component<Props> {
render() {
const { classes } = this.props;
const zoneTitle = (
<ZoneName
<EditableName
label="Zone: "
name={this.props.zoneName}
updateName={this.props.onZoneNameUpdate}
/>
Expand Down
1 change: 0 additions & 1 deletion src/components/Editor/ZoneEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

export { default as ZoneOperation } from './ZoneOperation';
export { default as MaterialSelector } from './MaterialSelector';
export { default as ZoneName } from './ZoneName';
export { default as OperationSelector } from './OperationSelector.js';
export { default as ZoneEditor } from './ZoneEditor';
3 changes: 3 additions & 0 deletions src/components/Editor/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* @flow */

export { default as EditableName } from './EditableName';
4 changes: 3 additions & 1 deletion src/routes/Results/components/ResultDetailsLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import React from 'react';
import Paper from 'material-ui/Paper';
import { withStyles } from 'material-ui/styles';
import type { Score, DimensionsInfo } from 'model/result';
import type { Detector } from 'model/simulation/detector';
import { ChartInterface } from 'components/Chart';
import { generateDetectorChartLabels } from 'utils/simulation/detectorInfo';
import AppLayout from 'pages/AppLayout';

type Props = {
setup: Detector,
scored: Score,
dimensions: DimensionsInfo,
classes: Object,
Expand All @@ -27,7 +29,7 @@ class ResultDetailsLayout extends React.Component<Props> {
data={this.props.scored}
numberOfDimensions={this.props.dimensions.numberOfDimensions}
classes={{ root: classes.chart }}
labels={generateDetectorChartLabels(({ name: 'test', shape: null }: any))}
labels={generateDetectorChartLabels(this.props.setup)}
/>
</Paper>
{
Expand Down
4 changes: 4 additions & 0 deletions src/routes/Results/containers/ResultDetailsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React from 'react';
import { connect } from 'react-redux';
import type { Score, DetectorResultsInfo } from 'model/result';
import type { Detector } from 'model/simulation/detector';
import { LoadingCircle } from 'pages/Empty';
import ResultDetailsLayout from '../components/ResultDetailsLayout';
import selector from '../selector';
Expand All @@ -11,6 +12,7 @@ import { actionCreator } from '../reducer';
type Props = {
scored: Score,
metadata: DetectorResultsInfo,
setup: Detector,
isFetchPending: bool,
fetchResults: () => void,
}
Expand All @@ -30,6 +32,7 @@ class ResultDetailsContainer extends React.Component<Props> {
}
return (
<ResultDetailsLayout
setup={this.props.setup}
scored={this.props.scored}
dimensions={this.props.metadata.dimensions}
/>
Expand All @@ -41,6 +44,7 @@ const mapStateToProps = (state, props) => {
return {
scored: selector.resultScoreSelector(state, props.params.detectorId),
metadata: selector.resultOverviewSelector(state, props.params.detectorId),
setup: selector.resultSetupSelector(state, props.params.detectorId),
};
};

Expand Down
9 changes: 5 additions & 4 deletions src/routes/Results/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@ const ACTION_HANDLERS = {
})
),
[actionType.FETCH_SIMULATION_RESULTS_SUCCESS]: (state, action) => {
const { detectors, results } = action.results;
const detectorIds = _.map(detectors, item => item.metadata.filename);
const { detectors: results } = action.results;
const { detectors: setup } = action.setup;

const detectorsMap = _.keyBy(detectors, item => item.metadata.filename);
const detectorIds = _.map(results, item => item.detectorId);
const detectorsMap = _.keyBy(results, item => item.detectorId);
const detectorsProcessed = _.mapValues(detectorsMap, (item) => {
const { scored, ...rest } = item;
return rest;
});
const detectorsScore = _.mapValues(detectorsMap, item => item.scored);

return state.merge({
...results,
detectorIds,
detectors: detectorsProcessed,
detectorsSetup: setup,
detectorsScore,
dataStatus: 'success',
});
Expand Down
17 changes: 14 additions & 3 deletions src/routes/Results/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,30 @@ export function* fetchSimulationResults(
versionId: state.results.get('versionId'),
dataStatus: state.results.get('dataStatus'),
}));
if (dataStatus !== 'none' && projectId === action.projectId && versionId === action.versionId) {
if (dataStatus !== 'none'
&& projectId === action.projectId
&& versionId === action.versionId
) {
return;
}
yield put({
type: actionType.FETCH_SIMULATION_RESULTS_PENDING,
projectId: action.projectId,
versionId: action.versionId,
});
const response = yield call(
const results = yield call(
api.get,
endpoint.simulationResults(action.projectId, action.versionId),
);
yield put({ type: actionType.FETCH_SIMULATION_RESULTS_SUCCESS, results: response.data });
const setup = yield call(
api.get,
endpoint.simulationSetup(action.projectId, action.versionId),
);
yield put({
type: actionType.FETCH_SIMULATION_RESULTS_SUCCESS,
setup: setup.data,
results: results.data,
});
} catch (error) {
yield put({ type: actionType.FETCH_SIMULATION_RESULTS_ERROR, error: error.response.data });
}
Expand Down
10 changes: 8 additions & 2 deletions src/routes/Results/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ function resultsListSelector(
}

function resultOverviewSelector(state: Store, detectorId: DetectorResultId): ?DetectorResultsInfo {
const overview = state.results.getIn(['detectors', detectorId]);
const overview = state.results.getIn(['detectors', String(detectorId)]);
return overview ? overview.toJS() : undefined;
}

function resultScoreSelector(state: Store, detectorId: DetectorResultId): ?Score {
const score = state.results.getIn(['detectorsScore', detectorId]);
const score = state.results.getIn(['detectorsScore', String(detectorId)]);
return score ? score.toJS() : undefined;
}

function resultSetupSelector(state: Store, detectorId: DetectorResultId): ?Score {
const score = state.results.getIn(['detectorsSetup', String(detectorId)]);
return score ? score.toJS() : undefined;
}

export default {
resultsListSelector,
resultOverviewSelector,
resultScoreSelector,
resultSetupSelector,
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import Button from 'material-ui/Button';
import DeleteIcon from 'material-ui-icons/Delete';
import type { Detector } from 'model/simulation/detector';
import { t } from 'i18n';
import { EditableName } from 'components/Editor';
import ParticleEditor from 'components/Editor/ParticleEditor';
import DetectorGeometryItemLayout from './DetectorGeometryItemLayout';
import DetectorScoringItemLayout from './DetectorScoringItemLayout';

type Props = {
detector: Detector,
updateType: (type: string) => void,
detectorNameUpdate: (value: string) => void,
geometryUpdate: (value: Object, type: string) => void,
particleUpdate: (value: Object) => void,
scoringUpdate: (value: Object) => void,
Expand Down Expand Up @@ -44,6 +46,11 @@ class DetectorItemLayout extends React.Component<Props> {
className={classes.root}
elevation={4}
>
<EditableName
label="Detector: "
name={detector.name}
updateName={this.props.detectorNameUpdate}
/>
<FormSelect
type="detectorGeometry"
value={detector.detectorGeometry && detector.detectorGeometry.type}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class DetectorItemContainer extends React.Component<Props> {
detectorGeometry: defaultDetectorGeometryForType(type),
});
}

detectorNameUpdate = (name: string) => {
this.props.updateDetector({
...this.props.detector,
name,
});
}

geometryUpdate = (type: string, value: any) => {
this.props.updateDetector({
...this.props.detector,
Expand Down Expand Up @@ -61,6 +69,7 @@ class DetectorItemContainer extends React.Component<Props> {
classes={this.props.classes}
detector={this.props.detector || EMPTY}
updateType={this.updateType}
detectorNameUpdate={this.detectorNameUpdate}
geometryUpdate={this.geometryUpdate}
particleUpdate={this.particleUpdate}
scoringUpdate={this.scoringUpdate}
Expand Down
6 changes: 4 additions & 2 deletions src/routes/Workspace/Geometry/components/ZoneItemLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Paper from 'material-ui/Paper';
import Button from 'material-ui/Button';
import RightArrowIcon from 'material-ui-icons/KeyboardArrowRight';
import { withStyles } from 'material-ui/styles';
import { ZoneName, ZoneEditor } from 'components/Editor/ZoneEditor';
import { ZoneEditor } from 'components/Editor/ZoneEditor';
import { EditableName } from 'components/Editor';
import type { OperationType, ConstructionPath, PrintableOperation } from 'model/simulation/zone';
import type { PrintableMaterial } from 'model/simulation/material';

Expand Down Expand Up @@ -43,7 +44,8 @@ class ZoneItemLayout extends React.Component<Props, State> {
render() {
const { classes, zoneName, base, construction, materialId, materials } = this.props;
const zoneTitle = (
<ZoneName
<EditableName
label="Zone: "
name={zoneName}
isOpen={this.state.isOpen}
toggleOpen={this.toggleOpen}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class CompoundMaterialEditorLayout extends React.Component<Props> {
props: Props

updateColor = (color: Color) => {
console.log(color);
this.props.updateField(color, 'color');
}

Expand Down
Loading

0 comments on commit 5ec4eb6

Please sign in to comment.