Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(BYT-9319): migrate remaining snap-back number inputs to NumberInput (#20066)

h3n4lc4a862da782a
diff --git a/frontend/src/react/pages/settings/SemanticTypesPage.tsx b/frontend/src/react/pages/settings/SemanticTypesPage.tsx
index 0c34a949cf..f53f1f05af 100644
--- a/frontend/src/react/pages/settings/SemanticTypesPage.tsx
+++ b/frontend/src/react/pages/settings/SemanticTypesPage.tsx
@@ -6,6 +6,7 @@ import { v4 as uuidv4 } from "uuid";
import { FeatureAttention } from "@/react/components/FeatureAttention";
import { Button } from "@/react/components/ui/button";
import { Input } from "@/react/components/ui/input";
+import { NumberInput } from "@/react/components/ui/number-input";
import { Tooltip } from "@/react/components/ui/tooltip";
import { useVueState } from "@/react/hooks/useVueState";
import {
@@ -505,12 +506,14 @@ function MaskingAlgorithmDrawer({
? algorithm.mask.value.type
: Algorithm_InnerOuterMask_MaskType.INNER
);
- const [innerOuterPrefix, setInnerOuterPrefix] = useState(
+ // `number | null`: `null` represents an empty input while the user is
+ // typing; coerced to `0` on save.
+ const [innerOuterPrefix, setInnerOuterPrefix] = useState<number | null>(
algorithm?.mask?.case === "innerOuterMask"
? algorithm.mask.value.prefixLen
: 0
);
- const [innerOuterSuffix, setInnerOuterSuffix] = useState(
+ const [innerOuterSuffix, setInnerOuterSuffix] = useState<number | null>(
algorithm?.mask?.case === "innerOuterMask"
? algorithm.mask.value.suffixLen
: 0
@@ -659,8 +662,9 @@ function MaskingAlgorithmDrawer({
case: "innerOuterMask",
value: create(Algorithm_InnerOuterMaskSchema, {
type: innerOuterType,
- prefixLen: innerOuterPrefix,
- suffixLen: innerOuterSuffix,
+ // Proto field is int32 — floor any fractional input defensively.
+ prefixLen: Math.floor(innerOuterPrefix ?? 0),
+ suffixLen: Math.floor(innerOuterSuffix ?? 0),
substitution: innerOuterSubstitution,
}),
},
@@ -924,15 +928,12 @@ function MaskingAlgorithmDrawer({
)}
<span className="text-error ml-0.5">*</span>
</label>
- <Input
- type="number"
+ <NumberInput
value={innerOuterPrefix}
className="w-24"
- onChange={(e) => {
- const val = Number(e.target.value);
- if (!Number.isNaN(val) && val >= 0)
- setInnerOuterPrefix(val);
- }}
+ min={0}
+ step={1}
+ onValueChange={setInnerOuterPrefix}
/>
</div>
<div className="flex flex-col gap-y-1">
@@ -942,15 +943,12 @@ function MaskingAlgorithmDrawer({
)}
<span className="text-error ml-0.5">*</span>
</label>
- <Input
- type="number"
+ <NumberInput
value={innerOuterSuffix}
className="w-24"
- onChange={(e) => {
- const val = Number(e.target.value);
- if (!Number.isNaN(val) && val >= 0)
- setInnerOuterSuffix(val);
- }}
+ min={0}
+ step={1}
+ onValueChange={setInnerOuterSuffix}
/>
</div>
<div className="flex-1 flex flex-col gap-y-1">
diff --git a/frontend/src/react/pages/settings/general/AccountSection.tsx b/frontend/src/react/pages/settings/general/AccountSection.tsx
index 9594362d4d..c5a311a85e 100644
--- a/frontend/src/react/pages/settings/general/AccountSection.tsx
+++ b/frontend/src/react/pages/settings/general/AccountSection.tsx
@@ -18,6 +18,7 @@ import {
usePermissionCheck,
} from "@/react/components/PermissionGuard";
import { Input } from "@/react/components/ui/input";
+import { NumberInput } from "@/react/components/ui/number-input";
import { useVueState } from "@/react/hooks/useVueState";
import {
useActuatorV1Store,
@@ -51,11 +52,41 @@ interface ToggleState {
}
interface TokenState {
- accessTokenDuration: number;
+ // `null` represents an empty input while the user is typing; coerced to
+ // sensible defaults (1 for durations, -1 for inactiveTimeout = "no limit")
+ // on save and dirty comparison.
+ accessTokenDuration: number | null;
accessTokenTimeFormat: "MINUTES" | "HOURS";
- refreshTokenDuration: number;
+ refreshTokenDuration: number | null;
refreshTokenTimeFormat: "HOURS" | "DAYS";
- inactiveTimeout: number;
+ inactiveTimeout: number | null;
+}
+
+// Defaults used when the user leaves a duration field empty.
+const EMPTY_TOKEN_DURATION_DEFAULT = 1;
+const EMPTY_INACTIVE_TIMEOUT_DEFAULT = -1;
+
+// Canonicalizes TokenState for both isDirty comparison and save: coerces
+// transient `null` inputs to defaults and floors any fractional values (paste
+// of "1.5" etc.) so the two paths always agree on what counts as a change.
+function normalizeTokenState(state: TokenState): TokenState {
+ const floorOr = (v: number | null, fallback: number): number =>
+ Math.floor(v ?? fallback);
+ return {
+ ...state,
+ accessTokenDuration: floorOr(
+ state.accessTokenDuration,
+ EMPTY_TOKEN_DURATION_DEFAULT
+ ),
+ refreshTokenDuration: floorOr(
+ state.refreshTokenDuration,
+ EMPTY_TOKEN_DURATION_DEFAULT
+ ),
+ inactiveTimeout: floorOr(
+ state.inactiveTimeout,
+ EMPTY_INACTIVE_TIMEOUT_DEFAULT
+ ),
+ };
}
interface AccountSectionProps {
@@ -208,6 +239,7 @@ export const AccountSection = forwardRef<SectionHandle, AccountSectionProps>(
if (
prevAccessFormat.current !== tokenState.accessTokenTimeFormat &&
tokenState.accessTokenTimeFormat === "MINUTES" &&
+ tokenState.accessTokenDuration !== null &&
tokenState.accessTokenDuration > 59
) {
setTokenState((s) => ({ ...s, accessTokenDuration: 59 }));
@@ -221,6 +253,7 @@ export const AccountSection = forwardRef<SectionHandle, AccountSectionProps>(
if (
prevRefreshFormat.current !== tokenState.refreshTokenTimeFormat &&
tokenState.refreshTokenTimeFormat === "HOURS" &&
+ tokenState.refreshTokenDuration !== null &&
tokenState.refreshTokenDuration > 23
) {
setTokenState((s) => ({ ...s, refreshTokenDuration: 23 }));
@@ -234,7 +267,12 @@ export const AccountSection = forwardRef<SectionHandle, AccountSectionProps>(
passwordState,
getInitialPasswordRestriction()
);
- const isTokenDirty = !isEqual(tokenState, getInitialTokenState());
+ // Normalize transient empty inputs (`null`) before comparing so a
+ // cleared-then-saved field doesn't leave the section permanently dirty.
+ const isTokenDirty = !isEqual(
+ normalizeTokenState(tokenState),
+ getInitialTokenState()
+ );
const isDirty = isToggleDirty || isPasswordDirty || isTokenDirty;
// --- Update ---
@@ -251,16 +289,23 @@ export const AccountSection = forwardRef<SectionHandle, AccountSectionProps>(
updateMaskPaths.push("value.workspace_profile.password_restriction");
}
- // Token durations
+ // Token durations — `normalizeTokenState` coerces transient `null`
+ // inputs to defaults and floors fractional values, so the resolved
+ // shape matches what isDirty compared against.
const initToken = getInitialTokenState();
+ const resolvedToken = normalizeTokenState(tokenState);
+ const accessTokenDuration = resolvedToken.accessTokenDuration as number;
+ const refreshTokenDuration = resolvedToken.refreshTokenDuration as number;
+ const inactiveTimeout = resolvedToken.inactiveTimeout as number;
+
if (
- initToken.accessTokenDuration !== tokenState.accessTokenDuration ||
+ initToken.accessTokenDuration !== accessTokenDuration ||
initToken.accessTokenTimeFormat !== tokenState.accessTokenTimeFormat
) {
const seconds =
tokenState.accessTokenTimeFormat === "MINUTES"
- ? tokenState.accessTokenDuration * 60
- : tokenState.accessTokenDuration * 60 * 60;
+ ? accessTokenDuration * 60
+ : accessTokenDuration * 60 * 60;
payload.accessTokenDuration = create(DurationSchema, {
seconds: BigInt(seconds),
nanos: 0,
@@ -269,13 +314,13 @@ export const AccountSection = forwardRef<SectionHandle, AccountSectionProps>(
}
if (
- initToken.refreshTokenDuration !== tokenState.refreshTokenDuration ||
+ initToken.refreshTokenDuration !== refreshTokenDuration ||
initToken.refreshTokenTimeFormat !== tokenState.refreshTokenTimeFormat
) {
const seconds =
tokenState.refreshTokenTimeFormat === "HOURS"
- ? tokenState.refreshTokenDuration * 60 * 60
- : tokenState.refreshTokenDuration * 24 * 60 * 60;
+ ? refreshTokenDuration * 60 * 60
+ : refreshTokenDuration * 24 * 60 * 60;
payload.refreshTokenDuration = create(DurationSchema, {
seconds: BigInt(seconds),
nanos: 0,
@@ -283,9 +328,9 @@ export const AccountSection = forwardRef<SectionHandle, AccountSectionProps>(
updateMaskPaths.push("value.workspace_profile.refresh_token_duration");
}
- if (initToken.inactiveTimeout !== tokenState.inactiveTimeout) {
+ if (initToken.inactiveTimeout !== inactiveTimeout) {
payload.inactiveSessionTimeout = create(DurationSchema, {
- seconds: BigInt(tokenState.inactiveTimeout * 60 * 60),
+ seconds: BigInt(inactiveTimeout * 60 * 60),
nanos: 0,
});
updateMaskPaths.push(
@@ -730,26 +775,16 @@ export const AccountSection = forwardRef<SectionHandle, AccountSectionProps>(
)}
</p>
<div className="mt-3 flex flex-row justify-start items-center gap-x-4">
- <Input
- type="number"
+ <NumberInput
className="w-24"
value={tokenState.accessTokenDuration}
min={1}
max={tokenState.accessTokenTimeFormat === "MINUTES" ? 59 : 23}
+ step={1}
disabled={disabled || !hasSecureTokenFeature}
- onChange={(e) => {
- const val = parseInt(e.target.value, 10);
- if (!Number.isNaN(val)) {
- const max =
- tokenState.accessTokenTimeFormat === "MINUTES"
- ? 59
- : 23;
- setTokenState((s) => ({
- ...s,
- accessTokenDuration: Math.max(1, Math.min(val, max)),
- }));
- }
- }}
+ onValueChange={(v) =>
+ setTokenState((s) => ({ ...s, accessTokenDuration: v }))
+ }
/>
<label className="flex items-center gap-x-1">
<input
@@ -804,8 +839,7 @@ export const AccountSection = forwardRef<SectionHandle, AccountSectionProps>(
)}
</p>
<div className="mt-3 flex flex-row justify-start items-center gap-x-4">
- <Input
- type="number"
+ <NumberInput
className="w-24"
value={tokenState.refreshTokenDuration}
min={1}
@@ -814,23 +848,11 @@ export const AccountSection = forwardRef<SectionHandle, AccountSectionProps>(
? 23
: undefined
}
+ step={1}
disabled={disabled || !hasSecureTokenFeature}
- onChange={(e) => {
- const val = parseInt(e.target.value, 10);
- if (!Number.isNaN(val)) {
- const max =
- tokenState.refreshTokenTimeFormat === "HOURS"
- ? 23
- : undefined;
- setTokenState((s) => ({
- ...s,
- refreshTokenDuration: Math.max(
- 1,
- max ? Math.min(val, max) : val
- ),
- }));
- }
- }}
+ onValueChange={(v) =>
+ setTokenState((s) => ({ ...s, refreshTokenDuration: v }))
+ }
/>
<label className="flex items-center gap-x-1">
<input
@@ -888,21 +910,15 @@ export const AccountSection = forwardRef<SectionHandle, AccountSectionProps>(
</span>
</p>
<div className="mt-3 flex flex-row justify-start items-center gap-x-4">
- <Input
- type="number"
+ <NumberInput
className="w-24"
value={tokenState.inactiveTimeout}
min={-1}
+ step={1}
disabled={disabled || !hasSecureTokenFeature}
- onChange={(e) => {
- const val = parseInt(e.target.value, 10);
- if (!Number.isNaN(val)) {
- setTokenState((s) => ({
- ...s,
- inactiveTimeout: Math.max(-1, val),
- }));
- }
- }}
+ onValueChange={(v) =>
+ setTokenState((s) => ({ ...s, inactiveTimeout: v }))
+ }
/>
<span className="text-sm text-gray-500">
{t(