mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-19 14:14:17 +00:00
refactor: allow submitting same value
This commit is contained in:
committed by
Carlos Valente
parent
b173b5a8e8
commit
b38a7e5c92
+3
-1
@@ -5,16 +5,18 @@ import useReactiveTextInput from '../../../../common/components/input/text-input
|
||||
|
||||
interface SingleLineCellProps {
|
||||
initialValue: string;
|
||||
allowSubmitSameValue?: boolean;
|
||||
handleUpdate: (newValue: string) => void;
|
||||
handleCancelUpdate?: () => void;
|
||||
}
|
||||
|
||||
const SingleLineCell = forwardRef((props: SingleLineCellProps, inputRef) => {
|
||||
const { initialValue, handleUpdate, handleCancelUpdate } = props;
|
||||
const { initialValue, allowSubmitSameValue, handleUpdate, handleCancelUpdate } = props;
|
||||
const ref = useRef<HTMLInputElement | null>(null);
|
||||
const submitCallback = useCallback((newValue: string) => handleUpdate(newValue), [handleUpdate]);
|
||||
|
||||
const { value, onChange, onBlur, onKeyDown } = useReactiveTextInput(initialValue, submitCallback, ref, {
|
||||
allowSubmitSameValue,
|
||||
submitOnEnter: true, // single line should submit on enter
|
||||
submitOnCtrlEnter: true,
|
||||
onCancelUpdate: handleCancelUpdate,
|
||||
|
||||
+6
-3
@@ -41,8 +41,9 @@ export default function TimeInputDuration(props: TimeInputDurationProps) {
|
||||
(newValue: string) => {
|
||||
setIsEditing(false);
|
||||
|
||||
// Check if there is anything there
|
||||
// if the user sends an empty string, we want to clear the value
|
||||
if (newValue === '') {
|
||||
onSubmit(newValue);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,14 +60,15 @@ export default function TimeInputDuration(props: TimeInputDurationProps) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (valueInMillis === initialValue) {
|
||||
// if the value is the same, we may still want to push the lock change
|
||||
if (valueInMillis === initialValue && lockedValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
onSubmit(newValue);
|
||||
setValue(Number(newValue));
|
||||
},
|
||||
[initialValue, onSubmit],
|
||||
[initialValue, lockedValue, onSubmit],
|
||||
);
|
||||
|
||||
// duration times have a special format
|
||||
@@ -77,6 +79,7 @@ export default function TimeInputDuration(props: TimeInputDurationProps) {
|
||||
<SingleLineCell
|
||||
ref={inputRef}
|
||||
initialValue={timeString}
|
||||
allowSubmitSameValue={!lockedValue} // if the value is not locked, submitting will lock the value
|
||||
handleUpdate={handleUpdate}
|
||||
handleCancelUpdate={handleFakeBlur}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user