Skip to content

Commit

Permalink
Fix function being used before declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Niestroj committed Dec 22, 2023
1 parent 1216fda commit 296b4d8
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions frontend-v2/src/features/model/VariableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const VariableRow: React.FC<Props> = ({
updateLinksToPd,
isAnyLinkToPdSelected,
updateLagTimes,
isAnyLagTimeSelected
isAnyLagTimeSelected,
}) => {
const {
fields: mappings,
Expand Down Expand Up @@ -129,6 +129,21 @@ const VariableRow: React.FC<Props> = ({
: mappings.find((mapping) => mapping.pk_variable === variable.id) !==
undefined;

const onClickDerived = (type: DerivedVariableType) => () => {
const index = derivedIndex(type);
return index >= 0 ? removeDerived(index) : addDerived(type);
};

const derivedIndex = (type: DerivedVariableType) => {
return derivedVariables.findIndex(
(ro) => ro.pk_variable === variable.id && ro.type === type,
);
};

const isLinkedTo = (type: DerivedVariableType) => {
return derivedIndex(type) >= 0;
};

useEffect(() => {
updateDosings(variable.id, hasProtocol);
}, [hasProtocol]);
Expand Down Expand Up @@ -255,21 +270,6 @@ const VariableRow: React.FC<Props> = ({
derivedVariablesRemove(index);
};

const onClickDerived = (type: DerivedVariableType) => () => {
const index = derivedIndex(type);
return index >= 0 ? removeDerived(index) : addDerived(type);
};

const derivedIndex = (type: DerivedVariableType) => {
return derivedVariables.findIndex(
(ro) => ro.pk_variable === variable.id && ro.type === type,
);
};

const isLinkedTo = (type: DerivedVariableType) => {
return derivedIndex(type) >= 0;
};

const noMapToPD = isPD || effectVariable === undefined || !isConcentration;
const noDerivedVariables = !isConcentration || isPD;
const isC1 = model.is_library_model && variable.qname.endsWith(".C1");
Expand Down Expand Up @@ -323,11 +323,11 @@ const VariableRow: React.FC<Props> = ({
<FormControlLabel
control={
<MuiCheckbox
sx={{
"& .MuiSvgIcon-root": {
color: isAnyLagTimeSelected ? "inherit" : "red",
},
}}
sx={{
"& .MuiSvgIcon-root": {
color: isAnyLagTimeSelected ? "inherit" : "red",
},
}}
checked={isLinkedTo("TLG")}
onClick={onClickDerived("TLG")}
data-cy={`checkbox-tlag-${variable.name}`}
Expand Down

0 comments on commit 296b4d8

Please sign in to comment.