Skip to content

Commit f94977d

Browse files
committed
fix: fix empty parameters for keyboard shortcut crash
1 parent 8651b22 commit f94977d

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

frontend/testing-view/src/features/keyBindings/components/AddKeyBindingDialog.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,16 @@ export const AddKeyBindingDialog = ({
116116
setParameterValues((prev) => ({ ...prev, [fieldId]: value }));
117117
};
118118

119-
const canSubmit = selectedCommandId !== null && capturedKey !== "";
119+
const hasInvalidNumericParams =
120+
selectedCommand !== null &&
121+
selectedCommand !== undefined &&
122+
Object.entries(selectedCommand.fields).some(
123+
([key, field]) =>
124+
field.kind === "numeric" && isNaN(parseFloat(parameterValues[key])),
125+
);
126+
127+
const canSubmit =
128+
selectedCommandId !== null && capturedKey !== "" && !hasInvalidNumericParams;
120129

121130
return (
122131
<Dialog open={open} onOpenChange={onOpenChange}>

frontend/testing-view/src/features/keyBindings/hooks/useGlobalKeyBindings.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,18 @@ export const useGlobalKeyBindings = () => {
100100
];
101101
}
102102

103+
const numericValue =
104+
field.kind === "numeric" ? parseFloat(value) : value;
105+
106+
if (field.kind === "numeric" && isNaN(numericValue as number)) {
107+
logger.testingView.warn(
108+
`Skipping command: numeric field "${fieldKey}" has no valid value`,
109+
);
110+
return acc;
111+
}
112+
103113
acc[fieldKey] = {
104-
value: field.kind === "numeric" ? parseFloat(value) : value,
114+
value: numericValue,
105115
isEnabled: true,
106116
type: field.type,
107117
};

0 commit comments

Comments
 (0)