frontend: spot-finding panel never PUTs its built-in defaults

The panel started from a hard-coded settings object (adaptive threshold off,
high-resolution limit 2.5 A, count threshold 8, SNR 3, ...) and showed it until
the /statistics poll delivered the broker's copy. Every control PUTs the whole
panel object, so any touch of a control while that default was on screen -
even a click on a slider knob that changes nothing - replaced the broker's
spot-finding configuration with the frontend default. The window opens on page
load while /statistics is slow, and for as long as /statistics fails or hangs
(retry is off, so one failed poll is enough): the dashboard view switched away
and back during a failed poll remounts the panel on the default.

The panel now has no default: it shows a waiting note and no controls until the
broker's copy is in hand (and while the poll is failing), and each control sends
only its own field on top of the panel's copy of the broker settings.

Reproduced with jfjoch_broker (HLS-simulated) behind a logging proxy and headless
Chromium: before, 6 of 12 scenarios (delayed, failing, hanging or stripped
/statistics, remount during an error) PUT the default object; after, none do,
and PUTs from an adopted panel carry the broker's values with one field changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UqXYdL4qBGYRiSXSGXfCLu
This commit is contained in:
leonarski_fandClaude Opus 5.5 committed 2026-11-04 21:53:52 +01:00
1 parent 690fdb0600
commit 9f0e8458c9
1 file changed
+36 -38
@@ -12,28 +12,15 @@ type MyProps = {
update: () => void
};
const default_spot_finding_settings: spot_finding_settings = {
enable: true,
indexing: true,
photon_count_threshold: 8,
signal_to_noise_threshold: 3.0,
min_pix_per_spot: 2,
max_pix_per_spot: 50,
high_resolution_limit: 2.5,
low_resolution_limit: 50.0,
quick_integration: false,
high_resolution_limit_for_spot_count_low_res: 5.0,
ice_ring_width_q_recipA: 0.02,
high_res_gap_Q_recipA: 1.5,
adaptive_threshold: false,
false_pixels_per_frame: 100
};
function DataProcessingSettings({s: serverS, update}: MyProps) {
const [s, setS] = useState<spot_finding_settings>(default_spot_finding_settings);
const [lastDownloadedS, setLastDownloadedS] = useState<spot_finding_settings>(default_spot_finding_settings);
const [highResGap, setHighResGap] = useState(1.5);
const [highResLimit, setHighResLimit] = useState(2.5);
// The panel shows the broker's settings and nothing else: there is no local default to fall
// back on. A hard-coded default here was shown whenever the /statistics poll had not answered
// yet (page load, a view switch while a poll was failing or slow), and the first touch of any
// control then PUT that whole default object, replacing the broker's configuration.
const [s, setS] = useState<spot_finding_settings | undefined>(serverS);
const [lastDownloadedS, setLastDownloadedS] = useState<spot_finding_settings | undefined>(serverS);
const [highResGap, setHighResGap] = useState(serverS?.high_res_gap_Q_recipA ?? 1.5);
const [highResLimit, setHighResLimit] = useState(serverS?.high_resolution_limit ?? 2.5);
const { submit, snackbar } = useUpload({
...putConfigSpotFindingMutation(),
@@ -55,7 +42,18 @@ function DataProcessingSettings({s: serverS, update}: MyProps) {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [serverS]);
const apply = (next: spot_finding_settings) => {
if (s === undefined || serverS === undefined)
return (
<SettingsPanel title="Spot finding parameters" sx={{ minHeight: 800 }} snackbar={snackbar}>
<Typography sx={{ opacity: 0.7 }}>Waiting for the broker's settings ...</Typography>
</SettingsPanel>
);
// Each control changes one field and sends it on top of the panel's copy, which is the broker's
// latest (adopted by the effect above) plus the user's own changes that the poll has not
// returned yet - so two quick changes in a row do not undo each other.
const apply = (patch: Partial<spot_finding_settings>) => {
const next = {...s, ...patch};
setS(next);
submit(next);
update();
@@ -65,28 +63,28 @@ function DataProcessingSettings({s: serverS, update}: MyProps) {
// onChange for every intermediate position, and each one is a PUT that reconfigures spot
// finding on the running acquisition - one drag across the ice-ring width was ~200 of them.
const preview = (patch: Partial<spot_finding_settings>) =>
setS(prev => ({...prev, ...patch}));
setS(prev => prev && {...prev, ...patch});
// No high-resolution limit means spot finding goes as far as the detector reaches.
const autoHighResolutionLimitToggle = (event: ChangeEvent<HTMLInputElement>) =>
apply({...s, high_resolution_limit: event.target.checked ? undefined : highResLimit});
apply({high_resolution_limit: event.target.checked ? undefined : highResLimit});
const enableSpotFindingToggle = (event: ChangeEvent<HTMLInputElement>) =>
apply({...s, enable: event.target.checked});
apply({enable: event.target.checked});
const enableIndexingToggle = (event: ChangeEvent<HTMLInputElement>) =>
apply({...s, indexing: event.target.checked});
apply({indexing: event.target.checked});
const enableQuickIntegrationToggle = (event: ChangeEvent<HTMLInputElement>) =>
apply({...s, quick_integration: event.target.checked});
apply({quick_integration: event.target.checked});
const enableHighResGapToggle = (event: ChangeEvent<HTMLInputElement>) =>
apply({...s, high_res_gap_Q_recipA: event.target.checked ? highResGap : undefined});
apply({high_res_gap_Q_recipA: event.target.checked ? highResGap : undefined});
// Rejected outright by a broker whose detector finds spots on the FPGA. useUpload's onError
// already puts the server's value back, so the switch returns to off and the snackbar says why.
const adaptiveThresholdToggle = (event: ChangeEvent<HTMLInputElement>) =>
apply({...s, adaptive_threshold: event.target.checked});
apply({adaptive_threshold: event.target.checked});
return (
<SettingsPanel title="Spot finding parameters" sx={{ minHeight: 800 }} snackbar={snackbar}>
@@ -111,21 +109,21 @@ function DataProcessingSettings({s: serverS, update}: MyProps) {
<Slider disabled={!s.enable || (s.adaptive_threshold ?? false)}
value={Number(s.photon_count_threshold)}
onChange={(e, v) => preview({photon_count_threshold: v as number})}
onChangeCommitted={(e, v) => apply({...s, photon_count_threshold: v as number})}
onChangeCommitted={(e, v) => apply({photon_count_threshold: v as number})}
min={1} max={50} step={1} valueLabelDisplay="auto"/>
<Typography gutterBottom> False pixels / frame (adaptive operating point) </Typography>
<Slider disabled={!s.enable || !(s.adaptive_threshold ?? false)}
value={Number(s.false_pixels_per_frame ?? 100)}
onChange={(e, v) => preview({false_pixels_per_frame: v as number})}
onChangeCommitted={(e, v) => apply({...s, false_pixels_per_frame: v as number})}
onChangeCommitted={(e, v) => apply({false_pixels_per_frame: v as number})}
min={1} max={1000} step={1} valueLabelDisplay="auto"/>
<br/><Typography> Signal-to-noise threshold </Typography>
<Slider disabled={!s.enable}
value={Number(s.signal_to_noise_threshold)}
onChange={(e, v) => preview({signal_to_noise_threshold: v as number})}
onChangeCommitted={(e, v) => apply({...s, signal_to_noise_threshold: v as number})}
onChangeCommitted={(e, v) => apply({signal_to_noise_threshold: v as number})}
min={2}
max={10}
step={0.5}
@@ -137,13 +135,13 @@ function DataProcessingSettings({s: serverS, update}: MyProps) {
<Slider disabled={!s.enable}
value={Number(s.min_pix_per_spot)}
onChange={(e, v) => preview({min_pix_per_spot: v as number})}
onChangeCommitted={(e, v) => apply({...s, min_pix_per_spot: v as number})}
onChangeCommitted={(e, v) => apply({min_pix_per_spot: v as number})}
min={1} max={8} step={1} valueLabelDisplay="auto"/>
<Typography> Low resolution limit [&#8491;] </Typography>
<Slider disabled={!s.enable}
value={Number(s.low_resolution_limit)}
onChange={(e, v) => preview({low_resolution_limit: v as number})}
onChangeCommitted={(e, v) => apply({...s, low_resolution_limit: v as number})}
onChangeCommitted={(e, v) => apply({low_resolution_limit: v as number})}
min={10} max={100} step={0.1} valueLabelDisplay="auto"
valueLabelFormat={(value) => value.toFixed(1)}
/>
@@ -156,7 +154,7 @@ function DataProcessingSettings({s: serverS, update}: MyProps) {
<Slider disabled={!s.enable || s.high_resolution_limit === undefined}
value={Number(s.high_resolution_limit ?? highResLimit)}
onChange={(e, v) => { setHighResLimit(v as number); preview({high_resolution_limit: v as number}); }}
onChangeCommitted={(e, v) => apply({...s, high_resolution_limit: v as number})}
onChangeCommitted={(e, v) => apply({high_resolution_limit: v as number})}
min={1} max={5} step={0.1} valueLabelDisplay="auto"
valueLabelFormat={(value) => value.toFixed(1)}
/>
@@ -164,7 +162,7 @@ function DataProcessingSettings({s: serverS, update}: MyProps) {
<Slider disabled={!s.enable}
value={Number(s.high_resolution_limit_for_spot_count_low_res)}
onChange={(e, v) => preview({high_resolution_limit_for_spot_count_low_res: v as number})}
onChangeCommitted={(e, v) => apply({...s, high_resolution_limit_for_spot_count_low_res: v as number})}
onChangeCommitted={(e, v) => apply({high_resolution_limit_for_spot_count_low_res: v as number})}
min={2} max={8} step={0.1} valueLabelDisplay="auto"
valueLabelFormat={(value) => value.toFixed(1)}
/>
@@ -172,7 +170,7 @@ function DataProcessingSettings({s: serverS, update}: MyProps) {
<Slider disabled={!s.enable}
value={Number(s.ice_ring_width_q_recipA)}
onChange={(e, v) => preview({ice_ring_width_q_recipA: v as number})}
onChangeCommitted={(e, v) => apply({...s, ice_ring_width_q_recipA: v as number})}
onChangeCommitted={(e, v) => apply({ice_ring_width_q_recipA: v as number})}
min={0.0} max={0.2} step={0.001} valueLabelDisplay="auto"
valueLabelFormat={(value) => value.toFixed(3)}
/>
@@ -188,7 +186,7 @@ function DataProcessingSettings({s: serverS, update}: MyProps) {
disabled={!s.enable || s.high_res_gap_Q_recipA === undefined}
value={Number(s.high_res_gap_Q_recipA ?? highResGap)}
onChange={(e, v) => { setHighResGap(v as number); preview({high_res_gap_Q_recipA: v as number}); }}
onChangeCommitted={(e, v) => apply({...s, high_res_gap_Q_recipA: v as number})}
onChangeCommitted={(e, v) => apply({high_res_gap_Q_recipA: v as number})}
min={0.1}
max={5.0}
step={0.01}