Files
Jungfraujoch/frontend/src/components/NumberTextField.tsx
T
leonarski_f 75e401f0e5
Build Packages / Unit tests (push) Successful in 1h31m59s
Build Packages / build:rpm (rocky8_nocuda) (push) Successful in 8m43s
Build Packages / build:rpm (rocky9_nocuda) (push) Successful in 10m5s
Build Packages / build:rpm (ubuntu2204_nocuda) (push) Successful in 9m27s
Build Packages / build:rpm (ubuntu2404_nocuda) (push) Successful in 8m56s
Build Packages / build:rpm (rocky8_sls9) (push) Successful in 9m24s
Build Packages / build:rpm (rocky9_sls9) (push) Successful in 10m27s
Build Packages / build:rpm (rocky8) (push) Successful in 9m20s
Build Packages / build:rpm (rocky9) (push) Successful in 10m50s
Build Packages / build:rpm (ubuntu2204) (push) Successful in 9m54s
Build Packages / build:rpm (ubuntu2404) (push) Successful in 8m38s
Build Packages / DIALS test (push) Successful in 12m13s
Build Packages / XDS test (durin plugin) (push) Successful in 7m8s
Build Packages / XDS test (JFJoch plugin) (push) Successful in 7m8s
Build Packages / XDS test (neggia plugin) (push) Successful in 7m50s
Build Packages / Generate python client (push) Successful in 16s
Build Packages / Build documentation (push) Successful in 50s
Build Packages / Create release (push) Skipped
v1.0.0-rc.153 (#63)
This is an UNSTABLE release. It includes many experimental features, as well as many AI generated fixes. We recommend using rc.152 for production use.

* jfjoch_broker: Add EXPERIMENTAL pixelrefine mode for image processing
* jfjoch_broker: Allow to load user mask from 8-bit and 16-bit TIFF files
* jfjoch_broker: Add ROI calculation in non-FPGA workflow
* jfjoch_broker: Fixes to TCP image pusher
* jfjoch_broker: Remove NUMA bindings
* jfjoch_broker: Improvements to indexing
* jfjoch_broker: For PSI EIGER, trimming energies are taken from the detector configuration (now compulsory) instead of hardcoded values
* jfjoch_writer: Save ROI definitions and the per-pixel ROI bitmap in the master file; azimuthal ROIs support phi (angular) sectors
* jfjoch_viewer: Major redesign with dockable panels and saved layouts, plus on-canvas creation/move/resize of box, circle and azimuthal ROIs
* jfjoch_viewer: Run jfjoch_process reprocessing jobs from inside the GUI and overlay per-run results

Reviewed-on: #63
2026-06-23 20:29:49 +02:00

96 lines
3.1 KiB
TypeScript

import {ChangeEvent, memo, ReactNode, useEffect, useState} from 'react';
import {
InputAdornment, SxProps,
TextField, Theme
} from "@mui/material";
type MyProps = {
start_val?: number,
default?: number,
label: string,
callback: (val: number, err: boolean) => void,
counter?: number,
min?: number,
max?: number,
sx?: SxProps<Theme>,
units?: string,
disabled?: boolean,
fullWidth?: boolean,
float?: boolean
}
function unitsNode(str: string | undefined): ReactNode | null {
if (str === undefined)
return null;
else if (str === "us")
return <InputAdornment position="end">&micro;s</InputAdornment>;
else if (str === "A-1")
return <InputAdornment position="end">
<span>&#8491;<sup>-1</sup></span>
</InputAdornment>;
else
return <InputAdornment position="end">{str}</InputAdornment>;
}
function NumberTextField({start_val, default: defaultValue, label, callback, counter, min, max, sx, units, disabled, float}: MyProps) {
const [text, setText] = useState(".");
const [err, setErr] = useState(true);
const [val, setVal] = useState(0);
// Something has to change in parent to trigger setup => otherwise this makes infinite loop.
// In case of error state start_val could stay same, but we want to return to "safe" set
// so there is external counter that if changed reset is triggered.
useEffect(() => {
let v : number = 0;
if (start_val !== undefined)
v = start_val;
else if (defaultValue !== undefined)
v = defaultValue;
if (float !== true)
v = Math.round(v);
else
v = Math.round(v * 1000.0) / 1000.0
setErr(false);
setVal(v);
setText(v.toString());
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [counter, start_val]);
const updateValue = (event: ChangeEvent<HTMLInputElement>) => {
let new_text = event.target.value;
if (!new_text) new_text = "0";
let num_val : number = Number(new_text);
let new_err : boolean = !Number.isFinite(num_val)
|| (!float && !Number.isInteger(num_val))
|| ((min !== undefined) && (num_val < min))
|| ((max !== undefined) && (num_val > max));
// If error I keep old numeric value to return (so there is always a proper value kept)
let new_val : number = new_err ? val : num_val;
setErr(new_err);
setVal(new_val);
setText(new_text);
callback(new_val, new_err);
};
return <TextField id="frame_time" label={label} variant="outlined"
sx = {sx}
error={err}
onChange={updateValue}
value={text}
disabled={disabled}
InputProps={{
inputProps: {
style: {textAlign: 'right'}
},
endAdornment: unitsNode(units)
}}/>
}
export default memo(NumberTextField);