Skip to content

Comments

Fix create new model provider action not being shown in form#1542

Open
dan-niles wants to merge 4 commits intowso2:release/bi-1.8.xfrom
dan-niles:fix-model-provider-form
Open

Fix create new model provider action not being shown in form#1542
dan-niles wants to merge 4 commits intowso2:release/bi-1.8.xfrom
dan-niles:fix-model-provider-form

Conversation

@dan-niles
Copy link
Contributor

@dan-niles dan-niles commented Feb 24, 2026

Purpose

Fixes wso2/product-ballerina-integrator#2545

Fixes the Create New Model Provider button not showing in the reusable model provider form.

image

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling during form submissions to prevent UI blocking with improved fallback behavior.
  • New Features

    • Added saving state indicators to provide visual feedback during form submissions.
    • Improved form field configuration with better support for expression and action field types across evaluation, test, and knowledge base forms.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a4a71d and 4dc3398.

📒 Files selected for processing (4)
  • workspaces/ballerina/ballerina-side-panel/src/components/editors/EditorFactory.tsx
  • workspaces/ballerina/ballerina-visualizer/src/components/ConnectionSelector/config.ts
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/AIChatAgent/MemoryManagerConfig.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/Forms/KnowledgeBaseForm/index.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • workspaces/ballerina/ballerina-side-panel/src/components/editors/EditorFactory.tsx

📝 Walkthrough

Walkthrough

Added PROMPT as an expression-editor-triggering field, introduced isSaving state and try/catch around post-submit navigation in form components, and updated several form/config schemas to use ACTION_EXPRESSION types or add types entries for fields.

Changes

Cohort / File(s) Summary
Expression Editor Routing
workspaces/ballerina/ballerina-side-panel/src/components/editors/EditorFactory.tsx
Added PROMPT to the set of field types that open the inline expression editor.
Form Submission & UI State
workspaces/ballerina/ballerina-visualizer/src/views/BI/AIEvaluationForm/index.tsx, workspaces/ballerina/ballerina-visualizer/src/views/BI/TestFunctionForm/index.tsx
Introduced isSaving state, pass isSaving to FormGeneratorNew, wrap post-submit diagram/editor opening in try/catch, and add explicit types entries for certain slider and single-select fields.
Connection Type Configs
workspaces/ballerina/ballerina-visualizer/src/components/ConnectionSelector/config.ts
Changed first types entry fieldType from EXPRESSIONACTION_EXPRESSION for multiple connection types (Model Provider, Vector Store, Embedding Provider, Chunker, Memory Store).
Memory Manager Form Schema
workspaces/ballerina/ballerina-visualizer/src/views/BI/AIChatAgent/MemoryManagerConfig.tsx
Added types: [{ fieldType: "ACTION_EXPRESSION", selected: false }] to the store fieldOverrides configuration.
Knowledge Base Form Schema
workspaces/ballerina/ballerina-visualizer/src/views/BI/Forms/KnowledgeBaseForm/index.tsx
Initialize field.types for vectorStore, embeddingModel, and chunker to [{ fieldType: "ACTION_EXPRESSION", selected: false }] during form initialization.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

Hi, I'm a rabbit with a dev hat on,
PROMPT fields now join the expression song,
Forms save safe — no more frozen spin,
Connection types updated — hop right in! 🐇✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description is incomplete relative to the template. It includes only the Purpose section with a link to the issue and a brief explanation, omitting Goals, Approach, and other required sections. Add more detail to the description, particularly the Goals section explaining what the fix achieves and the Approach section detailing the implementation strategy.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly addresses the main issue being fixed: the 'Create New Model Provider' action not displaying in the form.
Linked Issues check ✅ Passed The code changes address the core requirement from issue #2545 by adding ACTION_EXPRESSION type entries to form configurations and updating field type mappings to enable inline expression editors.
Out of Scope Changes check ✅ Passed All changes are directly scoped to resolving the missing 'Create New Model Provider' button issue by updating form field type configurations and adding necessary type entries.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dan-niles dan-niles force-pushed the fix-model-provider-form branch from 09f0e2e to 8fa2ad1 Compare February 24, 2026 06:16
@dan-niles dan-niles marked this pull request as ready for review February 24, 2026 06:29
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
workspaces/ballerina/ballerina-visualizer/src/views/BI/TestFunctionForm/index.tsx (1)

105-129: ⚠️ Potential issue | 🟠 Major

Reset isSaving for all submit outcomes.
Line 106 sets isSaving to true, but only the openView error path clears it (Line 128). If add/update fails or after a successful submit, the UI can remain stuck in a saving state. Wrap the whole submit flow in try/catch/finally and clear the flag in finally.

🛠️ Suggested fix
 const onFormSubmit = async (data: FormValues, formImports: FormImports) => {
     setIsSaving(true);
     console.log("Test Function Form Data: ", data);
     const updatedTestFunction = fillFunctionModel(data, formImports);
     console.log("Test Function: ", updatedTestFunction);
-    if (serviceType === 'UPDATE_TEST') {
-        await rpcClient.getTestManagerRpcClient().updateTestFunction({ function: updatedTestFunction, filePath });
-    } else {
-        await rpcClient.getTestManagerRpcClient().addTestFunction({ function: updatedTestFunction, filePath });
-    }
-    try {
-        const res = await rpcClient.getTestManagerRpcClient().getTestFunction(
-            { functionName: updatedTestFunction.functionName.value, filePath });
-        const nodePosition = {
-            startLine: res.function.codedata.lineRange.startLine.line,
-            startColumn: res.function.codedata.lineRange.startLine.offset,
-            endLine: res.function.codedata.lineRange.endLine.line,
-            endColumn: res.function.codedata.lineRange.endLine.offset
-        };
-        await rpcClient.getVisualizerRpcClient().openView(
-            { type: EVENT_TYPE.OPEN_VIEW, location: { position: nodePosition, documentUri: filePath } })
-    } catch (error) {
-        console.error("Error opening test function in editor: ", error);
-        setIsSaving(false);
-    }
+    try {
+        if (serviceType === 'UPDATE_TEST') {
+            await rpcClient.getTestManagerRpcClient().updateTestFunction({ function: updatedTestFunction, filePath });
+        } else {
+            await rpcClient.getTestManagerRpcClient().addTestFunction({ function: updatedTestFunction, filePath });
+        }
+        const res = await rpcClient.getTestManagerRpcClient().getTestFunction(
+            { functionName: updatedTestFunction.functionName.value, filePath });
+        const nodePosition = {
+            startLine: res.function.codedata.lineRange.startLine.line,
+            startColumn: res.function.codedata.lineRange.startLine.offset,
+            endLine: res.function.codedata.lineRange.endLine.line,
+            endColumn: res.function.codedata.lineRange.endLine.offset
+        };
+        await rpcClient.getVisualizerRpcClient().openView(
+            { type: EVENT_TYPE.OPEN_VIEW, location: { position: nodePosition, documentUri: filePath } })
+    } catch (error) {
+        console.error("Error submitting or opening test function in editor: ", error);
+    } finally {
+        setIsSaving(false);
+    }
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@workspaces/ballerina/ballerina-visualizer/src/views/BI/TestFunctionForm/index.tsx`
around lines 105 - 129, The onFormSubmit handler sets setIsSaving(true) but only
clears it in one error branch; wrap the entire submit flow in a
try/catch/finally around the calls to fillFunctionModel and rpcClient methods
(rpcClient.getTestManagerRpcClient().addTestFunction / updateTestFunction,
getTestFunction, and rpcClient.getVisualizerRpcClient().openView) so that
setIsSaving(false) is executed in the finally block; keep existing error logging
in catch blocks but ensure every exit path resets isSaving by moving the
setIsSaving(false) into finally.
workspaces/ballerina/ballerina-visualizer/src/views/BI/AIEvaluationForm/index.tsx (1)

237-264: ⚠️ Potential issue | 🟠 Major

Wrap submit flow in try-catch-finally to ensure isSaving clears on all paths.
Line 238 sets isSaving true but only clears it in the inner catch block (line 263); add/update failures (lines 245–248) won't be caught, and successful saves won't reset the state. Move the add/update calls into the try block and use finally to unconditionally clear isSaving. Note: openView returns void (a notification, not a Promise), so it should not be awaited.

🛠️ Suggested fix
 const onFormSubmit = async (data: FormValues, formImports: FormImports) => {
     setIsSaving(true);
-    const formData = {
-        ...data,
-        dataProviderMode: dataProviderMode
-    };
-    const updatedTestFunction = fillFunctionModel(formData, formImports);
-    if (serviceType === 'UPDATE_TEST') {
-        await rpcClient.getTestManagerRpcClient().updateTestFunction({ function: updatedTestFunction, filePath });
-    } else {
-        await rpcClient.getTestManagerRpcClient().addTestFunction({ function: updatedTestFunction, filePath });
-    }
-    try {
-        const res = await rpcClient.getTestManagerRpcClient().getTestFunction(
-            { functionName: updatedTestFunction.functionName.value, filePath });
-        const nodePosition = {
-            startLine: res.function.codedata.lineRange.startLine.line,
-            startColumn: res.function.codedata.lineRange.startLine.offset,
-            endLine: res.function.codedata.lineRange.endLine.line,
-            endColumn: res.function.codedata.lineRange.endLine.offset
-        };
-        rpcClient.getVisualizerRpcClient().openView(
-            { type: EVENT_TYPE.OPEN_VIEW, location: { position: nodePosition, documentUri: filePath } })
-    }
-    catch (error) {
-        console.error('Failed to open function in diagram:', error);
-        setIsSaving(false);
-    }
+    try {
+        const formData = {
+            ...data,
+            dataProviderMode: dataProviderMode
+        };
+        const updatedTestFunction = fillFunctionModel(formData, formImports);
+        if (serviceType === 'UPDATE_TEST') {
+            await rpcClient.getTestManagerRpcClient().updateTestFunction({ function: updatedTestFunction, filePath });
+        } else {
+            await rpcClient.getTestManagerRpcClient().addTestFunction({ function: updatedTestFunction, filePath });
+        }
+        const res = await rpcClient.getTestManagerRpcClient().getTestFunction(
+            { functionName: updatedTestFunction.functionName.value, filePath });
+        const nodePosition = {
+            startLine: res.function.codedata.lineRange.startLine.line,
+            startColumn: res.function.codedata.lineRange.startLine.offset,
+            endLine: res.function.codedata.lineRange.endLine.line,
+            endColumn: res.function.codedata.lineRange.endLine.offset
+        };
+        rpcClient.getVisualizerRpcClient().openView(
+            { type: EVENT_TYPE.OPEN_VIEW, location: { position: nodePosition, documentUri: filePath } })
+    } catch (error) {
+        console.error('Failed to submit or open function in diagram:', error);
+    } finally {
+        setIsSaving(false);
+    }
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@workspaces/ballerina/ballerina-visualizer/src/views/BI/AIEvaluationForm/index.tsx`
around lines 237 - 264, The submit flow in onFormSubmit sets setIsSaving(true)
but doesn't clear it on all paths; wrap the add/update/getTestFunction and
subsequent openView calls in a try block and use a finally block to always call
setIsSaving(false). Specifically, move the
rpcClient.getTestManagerRpcClient().updateTestFunction / addTestFunction and the
getTestFunction + rpcClient.getVisualizerRpcClient().openView calls into the
try, catch errors as needed, and ensure finally { setIsSaving(false); } is
present; also do not await openView since it returns void/notification.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@workspaces/ballerina/ballerina-visualizer/src/views/BI/AIEvaluationForm/index.tsx`:
- Around line 237-264: The submit flow in onFormSubmit sets setIsSaving(true)
but doesn't clear it on all paths; wrap the add/update/getTestFunction and
subsequent openView calls in a try block and use a finally block to always call
setIsSaving(false). Specifically, move the
rpcClient.getTestManagerRpcClient().updateTestFunction / addTestFunction and the
getTestFunction + rpcClient.getVisualizerRpcClient().openView calls into the
try, catch errors as needed, and ensure finally { setIsSaving(false); } is
present; also do not await openView since it returns void/notification.

In
`@workspaces/ballerina/ballerina-visualizer/src/views/BI/TestFunctionForm/index.tsx`:
- Around line 105-129: The onFormSubmit handler sets setIsSaving(true) but only
clears it in one error branch; wrap the entire submit flow in a
try/catch/finally around the calls to fillFunctionModel and rpcClient methods
(rpcClient.getTestManagerRpcClient().addTestFunction / updateTestFunction,
getTestFunction, and rpcClient.getVisualizerRpcClient().openView) so that
setIsSaving(false) is executed in the finally block; keep existing error logging
in catch blocks but ensure every exit path resets isSaving by moving the
setIsSaving(false) into finally.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebf8a66 and 2a4a71d.

📒 Files selected for processing (3)
  • workspaces/ballerina/ballerina-side-panel/src/components/editors/EditorFactory.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/AIEvaluationForm/index.tsx
  • workspaces/ballerina/ballerina-visualizer/src/views/BI/TestFunctionForm/index.tsx

@dan-niles dan-niles requested a review from senithkay February 24, 2026 09:35
Copy link
Contributor

@senithkay senithkay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants