Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions client/src/components/DynamicJsonForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface DynamicJsonFormProps {

export interface DynamicJsonFormRef {
validateJson: () => { isValid: boolean; error: string | null };
hasJsonError: () => boolean;
}

const isTypeSupported = (
Expand Down Expand Up @@ -129,6 +130,10 @@ const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(
// on every keystroke which would be inefficient and error-prone
const timeoutRef = useRef<ReturnType<typeof setTimeout>>();

const hasJsonError = () => {
return !!jsonError;
};

// Debounce JSON parsing and parent updates to handle typing gracefully
const debouncedUpdateParent = useCallback(
(jsonString: string) => {
Expand Down Expand Up @@ -253,6 +258,7 @@ const DynamicJsonForm = forwardRef<DynamicJsonFormRef, DynamicJsonFormProps>(

useImperativeHandle(ref, () => ({
validateJson,
hasJsonError,
}));

const renderFormFields = (
Expand Down
8 changes: 5 additions & 3 deletions client/src/components/ToolsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ const ToolsTab = ({
const { copied, setCopied } = useCopy();

// Function to check if any form has validation errors
const checkValidationErrors = () => {
const checkValidationErrors = (validateChildren: boolean = false) => {
const errors = Object.values(formRefs.current).some(
(ref) => ref && !ref.validateJson().isValid,
(ref) =>
ref &&
(validateChildren ? !ref.validateJson().isValid : ref.hasJsonError()),
);
setHasValidationErrors(errors);
return errors;
Expand Down Expand Up @@ -675,7 +677,7 @@ const ToolsTab = ({
<Button
onClick={async () => {
// Validate JSON inputs before calling tool
if (checkValidationErrors()) return;
if (checkValidationErrors(true)) return;

try {
setIsToolRunning(true);
Expand Down