Commit 0c30ede2 authored by Marco Sehrer's avatar Marco Sehrer
Browse files

Merge pull request #51 from ninjaconcept/51-sample-elements-refresh

Sample list must update after sample was edited
parents 6128d0c2 c34967bf
......@@ -12,6 +12,13 @@ export default class NumeralInput extends Component {
};
}
componentWillReceiveProps(nextProps) {
let {value} = nextProps;
this.setState({
numeralValue: this._convertValueToNumeralValue(value)
});
}
_convertValueToNumeralValue(value) {
let {numeralFormat} = this.props;
return Numeral(value).format(numeralFormat);
......
......@@ -84,32 +84,31 @@ export default class SampleDetails extends React.Component {
});
}
render() {
let ajaxCall = (unit, nextUnit, value) => {
console.log("ajax call with unit: " + unit + " nextUnit: " + nextUnit + " and value: " + value);
let convertedValue = value;
if (unit && nextUnit && unit != nextUnit) {
switch (unit) {
case 'g':
if (nextUnit == 'mol') {
convertedValue = value * 2;
}
break;
case 'mol':
if (nextUnit == 'g') {
convertedValue = value / 2;
}
break;
}
handleUnitChanged(unit, nextUnit, value) {
console.log("ajax call with unit: " + unit + " nextUnit: " + nextUnit + " and value: " + value);
let convertedValue = value;
if (unit && nextUnit && unit != nextUnit) {
switch (unit) {
case 'g':
if (nextUnit == 'mol') {
convertedValue = value * 2;
}
break;
case 'mol':
if (nextUnit == 'g') {
convertedValue = value / 2;
}
break;
}
console.log("result:" + convertedValue);
return convertedValue;
};
}
console.log("result:" + convertedValue);
return convertedValue;
}
render() {
let sample = this.state.sample || {}
let sampleAmount = sample.amount_value && sample.amount_unit ? `(${sample.amount_value} ${sample.amount_unit})` : '';
let svgPath = sample.molecule_svg ? `/assets/${sample.molecule_svg}` : '';
return (
<div>
<Panel header="Sample Details" bsStyle='primary'>
......@@ -138,7 +137,7 @@ export default class SampleDetails extends React.Component {
label="Amount"
units={['g', 'ml', 'mol']}
numeralFormat='0,0.00'
convertValueFromUnitToNextUnit={(unit, nextUnit, value) => ajaxCall(unit, nextUnit, value)}
convertValueFromUnitToNextUnit={(unit, nextUnit, value) => this.handleUnitChanged(unit, nextUnit, value)}
onChange={(amount) => this.handleAmountChanged(amount)}
/>
<Input type="textarea" label="Description" ref="descriptionInput"
......
......@@ -33,6 +33,10 @@ class UIActions {
setPagination(pagination) {
this.dispatch(pagination);
}
refreshSamples() {
this.dispatch(type)
}
}
export default alt.createActions(UIActions);
......@@ -23,7 +23,8 @@ class UIStore {
handleUncheckAllElements: UIActions.uncheckAllElements,
handleDeselectAllElements: UIActions.deselectAllElements,
handleSelectElement: UIActions.selectElement,
handleSetPagination: UIActions.setPagination
handleSetPagination: UIActions.setPagination,
handleRefreshSamples: ElementActions.updateSample
});
}
......@@ -89,6 +90,10 @@ class UIStore {
handleSetPagination(pagination) {
this.state.pagination = pagination;
}
handleRefreshSamples() {
ElementActions.fetchSamplesByCollectionId(this.state.currentCollectionId, this.state.pagination)
}
}
export default alt.createStore(UIStore, 'UIStore');
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment