Skip to content

Commit 67b1660

Browse files
authored
fix: navigate to config from the project page (#1424)
# Fix Config Button Navigation to Settings Sidebar ## Problem Clicking the **Config** button in the project navigation bar resulted in a 404 error instead of opening the project settings sidebar. **Steps to Reproduce:** 1. Open the home page (Dashboard) 2. Click on any project to navigate to `/projects/{projectId}/explorer` 3. Click the **Config** button in the top navigation 4. **Expected:** Navigate to `/projects/{projectId}/explorer/settings` and open settings sidebar 5. **Actual:** Navigate to `/projects/{projectId}/settings` → 404 error, `projectId` becomes `undefined` ## Root Cause The navigation issue occurred during the React Router redirect transition. When navigating from the dashboard to a project: 1. The route initially lands at `/projects/{projectId}` (index route) 2. React Router then redirects to `/projects/{projectId}/explorer` 3. During this transition, if the Config button was clicked, the `useNavigateWithSettings` hook would capture the base path as `/projects/{projectId}` (without `/explorer`) 4. This resulted in navigating to `/projects/{projectId}/settings` instead of `/projects/{projectId}/explorer/settings` 5. Since no route exists for `/projects/{projectId}/settings` directly, the app returned a 404 error ## Solution Modified `src/utilities/navigation.ts` in the `useNavigateWithSettings` function to intelligently detect and handle project index routes: - **Detection:** Added regex pattern to detect when the base path matches `/projects/{projectId}` without a specific page - **Default Behavior:** When navigating to settings from the project index route (without `/explorer`, `/sessions`, or `/deployments`), automatically append `/explorer/` before the settings path - **Result:** Ensures navigation always produces `/projects/{projectId}/explorer/settings` instead of `/projects/{projectId}/settings` ## What type of PR is this? (check all applicable) - [ ] 💡 (feat) - A new feature (non-breaking change which adds functionality) - [ ] 🔄 (refactor) - Code Refactoring - A code change that neither fixes a bug nor adds a feature - [x] 🐞 (fix) - Bug Fix (non-breaking change which fixes an issue) - [ ] 🏎 (perf) - Optimization - [ ] 📄 (docs) - Documentation - Documentation only changes - [ ] 📄 (test) - Tests - Adding missing tests or correcting existing tests - [ ] ⚙️ (ci) - Continuous Integrations - Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs) - [ ] ☑️ (chore) - Chores - Other changes that don't modify src or test files - [ ] ↩️ (revert) - Reverts - Reverts a previous commit(s). <!-- For a timely review/response, please avoid force-pushing additional commits if your PR already received reviews or comments. Before submitting a Pull Request, please ensure you've done the following: - 👷‍♀️ Create small PRs. In most cases this will be possible. - ✅ Provide tests for your changes. - 📝 Use descriptive commit messages (as described below). - 📗 Update any related documentation and include any relevant screenshots. Commit Message Structure (all lower-case): <type>(optional ticket number): <description> [optional body] -->
1 parent bbbc793 commit 67b1660

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

e2e/project/triggers/triggerBase.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-console */
21
/* eslint-disable @typescript-eslint/naming-convention */
32
import type { Page } from "@playwright/test";
43

@@ -91,9 +90,6 @@ async function modifyTrigger(
9190
await expect(page.getByRole("heading", { name: "Configuration" })).toBeVisible();
9291
}
9392

94-
const drawerVisible = await page.locator("#project-sidebar-config").isVisible();
95-
console.log("Drawer visible before edit click:", drawerVisible);
96-
9793
const configureButtons = page.locator(`button[aria-label="Edit ${name}"]`);
9894
await configureButtons.click();
9995

e2e/project/webhookSessionTriggered.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ async function setupProjectAndTriggerSession({ dashboardPage, page, request }: S
7979

8080
await page.getByPlaceholder("Enter project name").fill(projectName);
8181
await page.locator('button[aria-label="Create"]').click();
82+
await page.waitForURL(/\/explorer\/settings/);
8283
await expect(page.getByRole("heading", { name: "Configuration" })).toBeVisible();
8384
// eslint-disable-next-line @typescript-eslint/no-unused-vars
8485
} catch (error) {

src/utilities/navigation.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export const useNavigateWithSettings = () => {
3737
const location = useLocation();
3838

3939
return (to: string, options?: { replace?: boolean; state?: ProjectLocationState }) => {
40-
const { basePath, settingsPath } = extractSettingsPath(location.pathname);
40+
const currentPath = location.pathname;
41+
const { basePath, settingsPath } = extractSettingsPath(currentPath);
4142
const cleanBasePath = basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
4243

4344
let newBasePath: string;
@@ -50,7 +51,17 @@ export const useNavigateWithSettings = () => {
5051
const projectBasePath = cleanBasePath.split("/").slice(0, -1).join("/");
5152
newBasePath = `${projectBasePath}/${pageName}`;
5253
} else {
53-
newBasePath = `${cleanBasePath}/${to}`;
54+
const projectPageMatch = cleanBasePath.match(/^\/projects\/[^/]+$/);
55+
if (
56+
projectPageMatch &&
57+
!currentPath.includes("/explorer") &&
58+
!currentPath.includes("/sessions") &&
59+
!currentPath.includes("/deployments")
60+
) {
61+
newBasePath = `${cleanBasePath}/explorer/${to}`;
62+
} else {
63+
newBasePath = `${cleanBasePath}/${to}`;
64+
}
5465
}
5566

5667
let finalPath: string;

0 commit comments

Comments
 (0)