Skip to content

Fix back button in artifact creation forms navigating to home instead of Add Artifact page#1959

Open
SasinduDilshara wants to merge 2 commits intomainfrom
fix/issue-820
Open

Fix back button in artifact creation forms navigating to home instead of Add Artifact page#1959
SasinduDilshara wants to merge 2 commits intomainfrom
fix/issue-820

Conversation

@SasinduDilshara
Copy link
Copy Markdown
Contributor

@SasinduDilshara SasinduDilshara commented Apr 10, 2026

Summary

Fixes wso2/mi-vscode#820

When a user navigates to the Add Artifact page and clicks an artifact type card (e.g. API), the resulting creation form shows two navigation buttons — "Go Back" (←) and "Home" (⌂). Clicking "Go Back" was incorrectly navigating to the Project Overview (home page) instead of returning to the Add Artifact page — making both buttons behave identically.

Root Cause — Two Interrelated Defects

Defect 1 — goBack() navigates to Home when current view is a Form
(workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts)

// Before (buggy):
goBack(): void {
    if (!getStateMachine(this.projectUri).context().view?.includes("Form")) {
        const entry = history.pop();
        navigate(this.projectUri, entry);
    } else {
        navigate(this.projectUri);  // ← BUG: navigates to Home without popping history
    }
}

When the current view is a creation form, the else branch called navigate(projectUri) with no history entry, which always resolves to the default/home view.

Defect 2 — Add Artifact view never pushed itself to history before opening a form
(workspaces/mi/mi-visualizer/src/views/AddArtifact/index.tsx)

When a user clicked an artifact card, handleClick() fired a VS Code command to open the creation form but never called addToHistory(). So the history stack had no Add Artifact entry to pop back to.

Fix

File Change
rpc-manager.ts Removed the if (!view?.includes("Form")) guard — goBack() now always pops the history stack and navigates to the popped entry.
AddArtifact/index.tsx Added addToHistory({ location: { view: MACHINE_VIEW.ADD_ARTIFACT } }) at the top of handleClick(), before any executeCommand call.

The addToHistory call is placed before the if/else if chain so it applies to all artifact types (APIs, endpoints, sequences, templates, message stores, etc.).

Tests Added

  • E2E test (navigationTests/backNavigation.spec.ts): Opens a project, navigates to Add Artifact, clicks the API card, then verifies the "Go Back" button returns to the Add Artifact page (not Project Overview). Also verifies the "Home" button still navigates to Project Overview.
  • Unit tests (test/suite/history.test.ts): Tests the History stack behaviour — push/pop round-trips, LIFO order, the fixed flow (AddArtifact entry in stack before form), and the pre-fix scenario (documents the bug).
  • Registered the new E2E suite in test.list.ts.

Test Plan

  • Verified fix end-to-end via Playwright against running code-server: "Go Back" from API creation form correctly returns to the Add Artifact page (tab title "Add Artifact", artifact cards visible)
  • "Home" button from creation form still navigates to Project Overview (not broken by fix)
  • Fix applies to all artifact types — addToHistory is called before the artifact-type branch, not inside each branch
  • Unit tests pass for History stack behavior covering the issue scenario

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved back navigation behavior in artifact creation forms for more consistent navigation flow.
    • Enhanced history tracking when selecting artifacts to add.
  • Chores

    • Updated extension version to 3.1.526032514.

choreo-cicd and others added 2 commits March 25, 2026 15:13
…#820)

Two defects were causing the "Go Back" button in artifact creation forms
to navigate to the Project Overview (home) instead of the Add Artifact page:

1. goBack() in rpc-manager.ts had an incorrect guard that called
   navigate(projectUri) with no history entry when the current view
   was a Form, causing navigation to the default/home view.
   Fix: remove the guard — always pop history and navigate to the popped entry.

2. The Add Artifact view never called addToHistory() before opening a
   creation form via executeCommand(), so the history stack had no
   Add Artifact entry to pop back to.
   Fix: add addToHistory({ location: { view: MACHINE_VIEW.ADD_ARTIFACT } })
   at the top of handleClick() in AddArtifact/index.tsx.

Also adds:
- E2E back-navigation test (navigationTests/backNavigation.spec.ts)
- Unit tests for the History stack (test/suite/history.test.ts)
- Registers the new E2E test suite in test.list.ts

Fixes wso2/mi-vscode#820

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@SasinduDilshara
Copy link
Copy Markdown
Contributor Author

SasinduDilshara commented Apr 10, 2026

Issue Analysis Artifact

Issue Analysis — [Issue #820]: Back button in artifact creation forms directs to the home page instead of the Add Artifact page

Classification

  • Type: Bug
  • Severity Assessment: Medium
  • Affected Component(s): MI VSCode Extension — Visualizer / Navigation (mi-visualizer, mi-extension)
  • Affected Feature(s): Navigation — Back button in artifact creation forms; Add Artifact workflow

Reproducibility

  • Reproducible: Yes — triggered at runtime via Playwright automation
  • Reproduction method: Playwright (browser automation via Chrome CDP)
  • Environment:
    • Extension version: wso2.micro-integrator 3.1.526032514
    • wso2.wso2-integrator installed (suppresses MI Project Explorer, uses Integrator sidebar)
    • code-server 4.114.0 / Code 1.114.0
    • macOS Darwin 24.0.0 / Chrome 146
  • Steps Executed:
    1. Opened fresh workspace in code-server (http://localhost:8080/?folder=/tmp/mi-repro-820/workspace)
    2. Opened WSO2 Integrator sidebar → clicked "Get Started" → clicked "Create"
    3. Filled in "Integration Name" as TestProject820 in the Create Integration form → clicked "Create Integration"
    4. Waited for the project to appear in the sidebar (18 tree rows loaded)
    5. Clicked the "+ Add Artifact" button in the Project Overview webview
    6. Verified the Add Artifact page opened (saw API, Automation, Event Integration cards)
    7. Clicked the "API" card (div.css-3epwvm with text "API") — navigated to the Create API form
    8. Confirmed the Create API form opened with Name/Context/Version Type fields and breadcrumb main > wso2mi > artifacts > apis
    9. Located the "Go Back" button (<VSCodeButton title="Go Back"> with codicon-arrow-left icon)
    10. Clicked the "Go Back" button (i.codicon-arrow-left inside the first vscode-button)
    11. Captured the resulting page content
  • Expected Behavior: Clicking "Go Back" in the Create API form should navigate back to the Add Artifact page (showing API, Automation, Event Integration cards)
  • Actual Behavior: Clicking "Go Back" navigated to the Project Overview (home) page — showing "No artifacts were found" and the project overview layout — identical behavior to the "Home" button
  • Evidence:
    • screenshots-820/03-REPRO-03-add-artifact-verified.png — Add Artifact page confirmed open with API/Automation/Event Integration cards
    • screenshots-820/05-REPRO-05-api-creation-form.png — Create API form with "Go Back" (←) and "Home" (⌂) buttons at the top-left, breadcrumb main > wso2mi > artifacts > apis
    • screenshots-820/06-REPRO-06-form-with-buttons.png — Button inspection: Btn 0 title="Go Back", Btn 2 title="Home" (both confirmed in DOM)
    • screenshots-820/07-REPRO-08-after-back-click.pngAfter clicking "Go Back": Project Overview page loaded ("No artifacts were found"), NOT the Add Artifact page
    • Runtime console output: *** BUG CONFIRMED: Back button navigated to HOME PAGE instead of Add Artifact page! ***

Root Cause Analysis

There are two interrelated defects that together cause the bug:

Defect 1 — goBack() navigates to Home when current view is a Form

File: workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts (~line 458)

goBack(): void {
    if (!getStateMachine(this.projectUri).context().view?.includes("Form")) {
        const entry = history.pop();
        navigate(this.projectUri, entry);
    } else {
        navigate(this.projectUri);  // ← BUG: navigates to Home without popping history
    }
}

When the current view is an artifact creation form (its view name includes "Form"), the else branch calls navigate(this.projectUri) without any history entry, which resolves to the default/home view (Project Overview). This means both the "Go Back" and the "Go Home" buttons effectively navigate to the same place when on any creation form.

Defect 2 — Add Artifact view does not push itself to history before opening a form

File: workspaces/mi/mi-visualizer/src/views/AddArtifact/index.tsx (~line 151)

const handleClick = async (key: string) => {
    // ...
    if (key === "apis") {
        await rpcClient.getMiDiagramRpcClient()
            .executeCommand({ commands: ["MI.project-explorer.add-api", entry] });
        // ← No addToHistory() call here — Add Artifact page never pushed to history stack
    }
    // ...
};

When a user clicks an artifact type in the Add Artifact page, the view fires a VS Code command via executeCommand() to open the creation form, but never calls addToHistory() for the Add Artifact page. So the history stack does not contain the Add Artifact view at the point when the user is in a creation form.

Even if Defect 1 were fixed to pop from history, the pop would return whatever was before Add Artifact (typically the Project Overview), so both defects must be addressed together.

Combined effect: User goes: Project Overview → Add Artifact (not added to history) → API Form → clicks Back → history pop returns Project Overview (or navigates to default home) → lands on Project Overview instead of Add Artifact.

Test Coverage Assessment

  • Existing tests covering this path:
    • workspaces/mi/mi-extension/src/test/e2e-playwright-tests/components/AddArtifact.ts — E2E helper for navigating to the Add Artifact page and clicking artifact type cards (add() method)
    • workspaces/mi/mi-extension/src/test/e2e-playwright-tests/artifactTests/artifact.spec.ts — Tests artifact creation flows, but no test verifies the Back button destination after artifact selection
    • workspaces/mi/mi-extension/src/test/e2e-playwright-tests/components/Overview.tsgoToAddArtifact() navigation helper
  • Coverage gaps identified:
    • No test verifies what page is displayed after clicking the Back (←) button in any artifact creation form
    • No test verifies that the navigation history stack contains the Add Artifact page when inside a creation form
    • No test distinguishes the behavior of "Go Back" vs "Go Home" buttons from creation forms
  • Proposed test plan:
    • E2E test (AddArtifact.ts / artifact.spec.ts): After calling addArtifact.add("apis"), verify that the resulting webview title is the API Form. Then click the Back button (title="Go Back"), wait for navigation, and assert the resulting webview title is MACHINE_VIEW.ADD_ARTIFACT (not MACHINE_VIEW.Overview).
    • E2E test — all artifact types: Parametrize the same back-navigation check for all major artifact types (API, Proxy Service, Sequence, Endpoint, Template, etc.) since the issue states all creation forms are affected.
    • Negative/edge case: Verify that the Home (⌂) button from a creation form still navigates to the Project Overview (correct behavior), ensuring the fix does not break Home navigation.
    • Unit test (rpc-manager): Mock getStateMachine returning a view that includes "Form" and assert that goBack() calls history.pop() and navigate() with the popped entry, not navigate() with no argument.

@SasinduDilshara
Copy link
Copy Markdown
Contributor Author

SasinduDilshara commented Apr 10, 2026

Fix Plan — Issue #820

Dev Test Result

  • Status: PASSED
  • What was tested: End-to-end navigation from Add Artifact page → click API card → API creation form opens → click "Go Back" button → verify user lands on Add Artifact page (not Project Overview)
  • Result: After applying the fix, clicking "Go Back" from the API Form correctly navigated back to the Add Artifact page (iframe title = "Add Artifact"), not the Project Overview. The full test flow was:
    1. Extension auto-detected an empty MI project and opened the Add Artifact page (iframe[title="Add Artifact"])
    2. Clicked "View More" to expand artifact list, then clicked the API card (div[id="API"])
    3. API Form opened (iframe[title="API Form"]) with "Go Back" (title="Go Back") and "Home" buttons
    4. Clicked "Go Back"
    5. Result: Add Artifact page restoreddocument.title = "Add Artifact" and body contains "Create an Integration" cards
    • Key log: *** FIX VERIFIED: Go Back correctly navigated to "Add Artifact" page! ***

Changes Made

Repo File Change
wso2/vscode-extensions workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts Defect 1 fix: Removed the incorrect if (!view?.includes("Form")) branch in goBack(). Now always pops the history stack and navigates to the popped entry, regardless of whether the current view is a Form.
wso2/vscode-extensions workspaces/mi/mi-visualizer/src/views/AddArtifact/index.tsx Defect 2 fix: Added rpcClient.getMiVisualizerRpcClient().addToHistory({ location: { view: MACHINE_VIEW.ADD_ARTIFACT } }) at the top of handleClick(), before any executeCommand call. This pushes the Add Artifact page to the navigation history stack before opening any creation form, so that goBack() can pop it and return there.

Known Issues

None — dev test passed cleanly. The fix covers all artifact types (the addToHistory call is at the top of handleClick before the if/else if chain, so it applies to APIs, endpoints, sequences, templates, message stores, etc.).

@SasinduDilshara
Copy link
Copy Markdown
Contributor Author

SasinduDilshara commented Apr 10, 2026

Fix Verification Report

Issue: wso2/mi-vscode#820
Verdict: FIXED
Verification method: Playwright (Chrome CDP against running code-server)

Reproduction Steps Executed

  1. Connected to running code-server at http://localhost:8080/?folder=/tmp/mi-proj-820 via Chrome CDP on port 9222.
  2. Confirmed the "Add Artifact" page was loaded (webview tab title "Add Artifact"; shows API, Automation, Event Integration cards under "Create an Integration").
  3. Clicked the API artifact card (div[id="API"]) from the Add Artifact page.
  4. Waited for the API creation form to open — confirmed by webview tab title changing to "API Form" and form fields (Name, Context, Version Type) appearing.
  5. Clicked the "Go Back" button (vscode-button[title="Go Back"]) in the API creation form.
  6. Waited for navigation to complete and captured the resulting page.

Result

After clicking "Go Back" from the API creation form, the webview navigated back to the Add Artifact page (tab title "Add Artifact", showing the "Create an Integration" artifact cards: API, Automation, Event Integration, + View More).

Before the fix, clicking "Go Back" would have navigated to the Project Overview (home) page instead. The fix correctly restores the expected back-navigation behavior.

Evidence

verify-820-05-add-artifact-view.png

Starting state — "Add Artifact" page open with artifact cards (API, Automation, Event Integration, + View More button).

verify-820-07-api-form.png

After clicking the API card — "API Form" tab is active, showing the Create API form with Name*, Context*, Version Type fields and breadcrumb main > wso2mi > artifacts > apis. The back arrow (←) and home (⌂) buttons are visible at the top.

verify-820-08-after-back.png

After clicking "Go Back" — the webview shows the "Add Artifact" page with "Create an Integration" cards (API, Automation, Event Integration). This is the CORRECT behavior. The tab title reads "Add Artifact".

verify-820-09-final-state.png

Final confirmed state — "Add Artifact" page remains visible. Navigation correctly returned to Add Artifact (not Project Overview).

Fix Summary

Two code changes were applied to wso2/vscode-extensions:

File Change
workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts Removed the if (!view?.includes("Form")) guard in goBack() — now always pops history and navigates to the popped entry.
workspaces/mi/mi-visualizer/src/views/AddArtifact/index.tsx Added addToHistory({ location: { view: MACHINE_VIEW.ADD_ARTIFACT } }) at the top of handleClick() so the Add Artifact view is pushed onto the history stack before any creation form is opened.

The fixed VSIX (micro-integrator-3.1.526032514.vsix, built at 15:26) was installed into code-server prior to testing.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ SasinduDilshara
❌ choreo-cicd
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

The changes address Issue #820 by fixing artifact creation form navigation. The goBack() method was simplified to consistently use history-based navigation, and a new history entry is recorded when navigating to artifact creation forms. Comprehensive E2E and unit tests validate the corrected behavior.

Changes

Cohort / File(s) Summary
Version Update
workspaces/mi/mi-extension/package.json
Extension package version incremented from 3.1.5 to 3.1.526032514.
Navigation Logic
workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts, workspaces/mi/mi-visualizer/src/views/AddArtifact/index.tsx
Modified goBack() to unconditionally pop and navigate using history (removed form-view conditional). Added history recording when selecting artifacts from the Add Artifact page via addToHistory RPC call.
E2E Navigation Tests
workspaces/mi/mi-extension/src/test/e2e-playwright-tests/navigationTests/backNavigation.spec.ts, workspaces/mi/mi-extension/src/test/e2e-playwright-tests/test.list.ts
New Playwright test suite for back navigation behavior across artifact creation forms (API, Automation, Sequence, Endpoint, Template). Verifies back button redirects to Add Artifact page and home button redirects to Overview. Registered test suite in shared test runner.
Unit Tests
workspaces/mi/mi-extension/src/test/suite/history.test.ts
New Mocha test suite for the History class covering stack operations (push(), pop(), get(), clear(), clearAndPopulateWith(), select(), updateCurrentEntry()). Validates Issue #820 fix behavior with artifact navigation history scenarios.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit hops back through history's page,
No more lost in forms upon this stage,
From artifact form to Add's gentle sight,
The back button now leads ever right! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title directly and concisely summarizes the main fix: the back button in artifact creation forms now navigates to the Add Artifact page instead of home.
Description check ✅ Passed The PR description is comprehensive, covering Purpose (resolves issue #820), Goals (fix back button behavior), Approach (two defects explained with code examples), and tests added. However, it does not follow the provided template structure for sections like Release note, Documentation, Security checks, and Test environment.
Linked Issues check ✅ Passed The PR addresses all coding requirements from issue #820: goBack() now pops history and navigates correctly, addToHistory() is called before form opens in AddArtifact, fixes apply to all artifact types, and E2E and unit tests validate the fix.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing issue #820. The version bump to package.json (3.1.5 → 3.1.526032514) appears to be an automated or system-generated change unrelated to the functional fix, but the core logic changes target only the identified defects.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/issue-820
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch fix/issue-820

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.

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
workspaces/mi/mi-extension/src/test/e2e-playwright-tests/navigationTests/backNavigation.spec.ts (1)

93-94: Replace fixed sleeps with deterministic polling to improve test stability.

Lines 93, 123, and 160 use waitForTimeout(2000) before asserting webview title. This fixed sleep pattern is brittle under CI variance. Replace with expect.poll() to wait on actual state, which the project already uses in Utils.ts:

Suggested refactor
-                await page.page.waitForTimeout(2000);
-                const { title: iframeTitle } = await page.getCurrentWebview();
-                console.log(`After Go Back from API Form: iframeTitle="${iframeTitle}"`);
-                // Bug: before fix this was MACHINE_VIEW.Overview — now must be ADD_ARTIFACT.
-                expect(iframeTitle).toBe(MACHINE_VIEW.ADD_ARTIFACT);
+                await expect.poll(async () => {
+                    const { title } = await page.getCurrentWebview();
+                    return title;
+                }, { timeout: 10000 }).toBe(MACHINE_VIEW.ADD_ARTIFACT);

Apply similar changes at lines 123-124 and 160-161.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@workspaces/mi/mi-extension/src/test/e2e-playwright-tests/navigationTests/backNavigation.spec.ts`
around lines 93 - 94, Tests use fixed sleeps via await
page.page.waitForTimeout(2000) before reading the webview title which is
brittle; replace each sleep + immediate getCurrentWebview call with a
deterministic poll using expect.poll to wait for the webview title to reach the
expected value (e.g., expect.poll(async () => (await
page.getCurrentWebview()).title, { timeout: <sensible-ms>
}).toEqual(expectedTitle)). Update the occurrences that call
page.page.waitForTimeout and then const { title: iframeTitle } = await
page.getCurrentWebview() to use this polling pattern (see existing expect.poll
usage in Utils.ts for the exact style and timeout configuration).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@workspaces/mi/mi-extension/src/test/e2e-playwright-tests/navigationTests/backNavigation.spec.ts`:
- Around line 93-94: Tests use fixed sleeps via await
page.page.waitForTimeout(2000) before reading the webview title which is
brittle; replace each sleep + immediate getCurrentWebview call with a
deterministic poll using expect.poll to wait for the webview title to reach the
expected value (e.g., expect.poll(async () => (await
page.getCurrentWebview()).title, { timeout: <sensible-ms>
}).toEqual(expectedTitle)). Update the occurrences that call
page.page.waitForTimeout and then const { title: iframeTitle } = await
page.getCurrentWebview() to use this polling pattern (see existing expect.poll
usage in Utils.ts for the exact style and timeout configuration).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2f5c1c67-09c2-420b-a037-f180f0664d69

📥 Commits

Reviewing files that changed from the base of the PR and between 031d074 and edcbf86.

📒 Files selected for processing (6)
  • workspaces/mi/mi-extension/package.json
  • workspaces/mi/mi-extension/src/rpc-managers/mi-visualizer/rpc-manager.ts
  • workspaces/mi/mi-extension/src/test/e2e-playwright-tests/navigationTests/backNavigation.spec.ts
  • workspaces/mi/mi-extension/src/test/e2e-playwright-tests/test.list.ts
  • workspaces/mi/mi-extension/src/test/suite/history.test.ts
  • workspaces/mi/mi-visualizer/src/views/AddArtifact/index.tsx

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.

Back button in artifact creation forms directs to the home page instead of the Add Artifact page

3 participants