Skip to content

Commit 2b3d15d

Browse files
Inform user some compounds will be ignored
1 parent e7e05d6 commit 2b3d15d

File tree

1 file changed

+54
-17
lines changed

1 file changed

+54
-17
lines changed

frontend/src/components/Simulation/ModelInputs.tsx

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,19 @@ const ModelInputs: React.FC<{
117117
}))
118118
);
119119

120+
const firstModelValidSubstances =
121+
selectedModels.length > 0 ? new Set(selectedModels[0].validSubstances) : new Set<string>();
122+
120123
const allValidSubstances = new Set(selectedModels.flatMap((m) => m.validSubstances));
121124
const invisible = Array.from(allValidSubstances).filter((name) => concentrations[name] === undefined);
122125

123126
const handleSubmit = () => {
127+
const validConcentrations = Object.fromEntries(
128+
Object.entries(concentrations).filter(
129+
([substance]) => selectedModels.length === 0 || firstModelValidSubstances.has(substance)
130+
)
131+
);
132+
124133
const models = sortModelsByCategory(selectedModels).map((model) => {
125134
const store = getModelInputStore(model);
126135
const parameters = store.getState().parameters;
@@ -130,36 +139,64 @@ const ModelInputs: React.FC<{
130139
};
131140
});
132141

133-
onSubmit({ concentrations, models });
142+
onSubmit({ concentrations: validConcentrations, models });
134143
};
135144

145+
const hasInvalidSubstances = Object.keys(concentrations).some(
146+
(substance) => selectedModels.length > 0 && !firstModelValidSubstances.has(substance)
147+
);
148+
const hasNoValidSubstances = Object.keys(concentrations).every(
149+
(substance) => selectedModels.length > 0 && !firstModelValidSubstances.has(substance)
150+
);
151+
136152
return (
137153
<div>
138154
<Columns>
139155
<div>
140156
<Typography variant="h3">Concentrations</Typography>
141-
{Object.entries(concentrations).map(([name, value]) => (
142-
<TextField
143-
type="number"
144-
key={name}
145-
label={optionName(name)}
146-
style={{ paddingTop: "5px" }}
147-
step="any"
148-
unit="ppm"
149-
max={PPM_MAX}
150-
value={value}
151-
onChange={(e: ChangeEvent<HTMLInputElement>) =>
152-
setConcentration(name, Math.min(e.target.valueAsNumber, PPM_MAX))
153-
}
154-
/>
155-
))}
157+
{Object.entries(concentrations).map(([name, value]) => {
158+
const invalid = selectedModels.length > 0 && !firstModelValidSubstances.has(name);
159+
160+
return (
161+
<TextField
162+
type="number"
163+
key={name}
164+
label={optionName(name)}
165+
style={{
166+
paddingTop: "5px",
167+
opacity: invalid ? 0.6 : 1,
168+
}}
169+
step="any"
170+
unit="ppm"
171+
max={PPM_MAX}
172+
value={value}
173+
onChange={(e: ChangeEvent<HTMLInputElement>) =>
174+
setConcentration(name, Math.min(e.target.valueAsNumber, PPM_MAX))
175+
}
176+
helperText={invalid ? "⚠️ Not supported by selected models" : undefined}
177+
variant={invalid ? "error" : undefined}
178+
/>
179+
);
180+
})}
156181
<SubstanceAdder invisible={invisible} onAdd={(item: string) => setConcentration(item, 0)} />
157182
</div>
158183
{selectedModels.map((model) => (
159184
<ModelParametersWrapper key={model.modelId} model={model} />
160185
))}
161186
</Columns>
162-
<Button style={{ marginTop: "1em" }} onClick={handleSubmit}>
187+
{hasInvalidSubstances && (
188+
<Typography
189+
variant="body_short"
190+
style={{ marginTop: "1em", color: "var(--eds_interactive_warning__text, #ff9200)" }}
191+
>
192+
⚠️ Some substances are not supported by the first model and will be excluded from the simulation.
193+
</Typography>
194+
)}
195+
<Button
196+
style={{ marginTop: "1em" }}
197+
onClick={handleSubmit}
198+
disabled={hasNoValidSubstances || selectedModels.length === 0}
199+
>
163200
Run Simulation
164201
</Button>
165202
</div>

0 commit comments

Comments
 (0)