diff --git a/frontend/src/components/DataProcessingSettings.tsx b/frontend/src/components/DataProcessingSettings.tsx index a2ead9396..f49dad304 100644 --- a/frontend/src/components/DataProcessingSettings.tsx +++ b/frontend/src/components/DataProcessingSettings.tsx @@ -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(default_spot_finding_settings); - const [lastDownloadedS, setLastDownloadedS] = useState(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(serverS); + const [lastDownloadedS, setLastDownloadedS] = useState(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 ( + + Waiting for the broker's settings ... + + ); + + // 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) => { + 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) => - 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) => - apply({...s, high_resolution_limit: event.target.checked ? undefined : highResLimit}); + apply({high_resolution_limit: event.target.checked ? undefined : highResLimit}); const enableSpotFindingToggle = (event: ChangeEvent) => - apply({...s, enable: event.target.checked}); + apply({enable: event.target.checked}); const enableIndexingToggle = (event: ChangeEvent) => - apply({...s, indexing: event.target.checked}); + apply({indexing: event.target.checked}); const enableQuickIntegrationToggle = (event: ChangeEvent) => - apply({...s, quick_integration: event.target.checked}); + apply({quick_integration: event.target.checked}); const enableHighResGapToggle = (event: ChangeEvent) => - 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) => - apply({...s, adaptive_threshold: event.target.checked}); + apply({adaptive_threshold: event.target.checked}); return ( @@ -111,21 +109,21 @@ function DataProcessingSettings({s: serverS, update}: MyProps) { 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"/> False pixels / frame (adaptive operating point) 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"/>
Signal-to-noise threshold 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) { 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"/> Low resolution limit [Å] 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) { { 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) { 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) { 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}