Commit 5452cde3 authored by Marco Sehrer's avatar Marco Sehrer
Browse files

Move addMaterial, deleteMaterial, moveMaterial methods to Reaction

parent 18193568
......@@ -22,25 +22,20 @@ export default class ReactionDetailsScheme extends Component {
dropSample(sample, materialGroup) {
const {reaction} = this.state;
const materials = reaction[materialGroup];
const splitSample = Sample.buildChild(sample);
materials.push(splitSample);
reaction.addMaterial(splitSample, materialGroup);
this.onReactionChange(reaction, {schemaChanged: true});
}
deleteMaterial(material, materialGroup) {
const {reaction} = this.state;
const materials = reaction[materialGroup];
const materialIndex = materials.indexOf(material);
materials.splice(materialIndex, 1);
let {reaction} = this.state;
reaction.deleteMaterial(material, materialGroup);
this.onReactionChange(reaction, {schemaChanged: true});
}
dropMaterial(material, previousMaterialGroup, materialGroup) {
const {reaction} = this.state;
const materials = reaction[materialGroup];
this.deleteMaterial(material, previousMaterialGroup);
materials.push(material);
reaction.moveMaterial(material, previousMaterialGroup, materialGroup);
this.onReactionChange(reaction, {schemaChanged: true});
}
......
......@@ -77,6 +77,23 @@ export default class Reaction {
return [...this.starting_materials, ...this.reactants, ...this.products]
}
addMaterial(material, materialGroup) {
const materials = this[materialGroup];
materials.push(material);
}
deleteMaterial(material, materialGroup) {
const materials = this[materialGroup];
const materialIndex = materials.indexOf(material);
materials.splice(materialIndex, 1);
}
moveMaterial(material, previousMaterialGroup, materialGroup) {
const materials = this[materialGroup];
this.deleteMaterial(material, previousMaterialGroup);
materials.push(material);
}
_coerceToSamples(samples) {
return samples && samples.map(s => new Sample(s)) || []
}
......
Markdown is supported
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