Skip to content

Commit

Permalink
Bugfix/2076 clone t03 instance when creating a new t20 project (#408)
Browse files Browse the repository at this point in the history
* Feature/2076 - Fix t20 cloning and calculation

* Save calculation id in t20 instance

* Clone t03 instance when creating new T20 project

* Remove console.log()

Co-authored-by: Robert Schlick <robert.schlick@hydwis.de>
  • Loading branch information
rabbl and Roschl committed Jul 5, 2021
1 parent 64e2cdb commit d182389
Showing 1 changed file with 50 additions and 52 deletions.
102 changes: 50 additions & 52 deletions src/scenes/t20/components/calculation/Calculation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,74 @@ import {IRootReducer} from '../../../../reducers';
import {PackageActualizationWrapper} from '../../../modflow/components/content';
import {Segment} from 'semantic-ui-react';
import {appendBoundaryData} from '../appendBoundaryData';
import {startCalculation, updatePackages, updateRTModelling} from '../../actions/actions';
import {useDispatch, useSelector} from 'react-redux';
import {startCalculation, updatePackages} from '../../actions/actions';
import {useSelector} from 'react-redux';
import RTModelling from '../../../../core/model/rtm/modelling/RTModelling';
import React, {useEffect} from 'react';

interface IProps {
onChange: (rtm: RTModelling) => void;
onChange: (rtm: RTModelling) => void;
}

const Calculation = (props: IProps) => {
const dispatch = useDispatch();
const T20 = useSelector((state: IRootReducer) => state.T20);
const model = T20.model ? ModflowModel.fromObject(T20.model) : null;
const boundaries = T20.boundaries ? BoundaryCollection.fromObject(T20.boundaries) : null;
const rtm = T20.rtmodelling ? RTModelling.fromObject(T20.rtmodelling) : null;

const T20 = useSelector((state: IRootReducer) => state.T20);
const model = T20.model ? ModflowModel.fromObject(T20.model) : null;
const boundaries = T20.boundaries ? BoundaryCollection.fromObject(T20.boundaries) : null;
const rtm = T20.rtmodelling ? RTModelling.fromObject(T20.rtmodelling) : null;

useEffect(() => {
if (rtm && !rtm.results) {
handleCalculate();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [rtm, model, boundaries])

useEffect(() => {
if (rtm && T20.calculation && T20.calculation.calculation_id
&& T20.calculation.calculation_id !== rtm.calculationId) {
const cRtm = rtm.toObject();
cRtm.data.calculation_id = T20.calculation.calculation_id;
dispatch(updateRTModelling(RTModelling.fromObject(cRtm)));
}
// eslint-disable-next-line
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [T20.calculation]);
useEffect(() => {
if (rtm && !rtm.results) {
handleCalculate();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [rtm, model, boundaries])

if (!rtm || !model || !boundaries) {
return null;
useEffect(() => {
if (rtm && T20.calculation && T20.calculation.calculation_id
&& T20.calculation.calculation_id !== rtm.calculationId) {
const cRtm = rtm.toObject();
cRtm.data.calculation_id = T20.calculation.calculation_id;
props.onChange(RTModelling.fromObject(cRtm));
}
// eslint-disable-next-line
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [T20.calculation]);

const handleCalculate = () => {
const results = appendBoundaryData(boundaries, model, rtm);
if (!rtm || !model || !boundaries) {
return null;
}

if (!results || !results.stressperiods || !results.boundaries) {
return null;
}
const handleCalculate = () => {
const results = appendBoundaryData(boundaries, model, rtm);

model.stressperiods = Stressperiods.fromObject(results.stressperiods);
if (!results || !results.stressperiods || !results.boundaries) {
return null;
}

const cRtm = rtm.toObject();
cRtm.data.results = {boundaries: results.boundaries, model: model.toObject()};
props.onChange(RTModelling.fromObject(cRtm));
};
model.stressperiods = Stressperiods.fromObject(results.stressperiods);

if (rtm && rtm.results) {
return (
<PackageActualizationWrapper
boundaries={BoundaryCollection.fromObject(rtm.results.boundaries)}
model={ModflowModel.fromObject(rtm.results.model)}
property="calculation"
reducer={T20}
updatePackages={updatePackages}
startCalculation={startCalculation}
/>
);
}
const cRtm = rtm.toObject();
cRtm.data.results = {boundaries: results.boundaries, model: model.toObject()};
props.onChange(RTModelling.fromObject(cRtm));
};

if (rtm && rtm.results) {
return (
<Segment color={'grey'} loading={true}>
</Segment>
<PackageActualizationWrapper
boundaries={BoundaryCollection.fromObject(rtm.results.boundaries)}
model={ModflowModel.fromObject(rtm.results.model)}
property="calculation"
reducer={T20}
updatePackages={updatePackages}
startCalculation={startCalculation}
/>
);
}

return (
<Segment color={'grey'} loading={true}>
</Segment>
);
};

export default Calculation;

0 comments on commit d182389

Please sign in to comment.