Skip to content

Commit

Permalink
redirect /g and /p to the search page
Browse files Browse the repository at this point in the history
  • Loading branch information
ciyer committed Jan 31, 2025
1 parent 7b941f8 commit 6501ce5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
27 changes: 25 additions & 2 deletions client/src/features/rootV2/RootV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,19 @@

import cx from "classnames";
import { useEffect, useState } from "react";
import { Route, Routes, useNavigate } from "react-router-dom-v5-compat";
import {
Route,
Routes,
generatePath,
useNavigate,
} from "react-router-dom-v5-compat";

import ContainerWrap from "../../components/container/ContainerWrap";
import LazyNotFound from "../../not-found/LazyNotFound";
import { RELATIVE_ROUTES } from "../../routing/routes.constants";
import {
ABSOLUTE_ROUTES,
RELATIVE_ROUTES,
} from "../../routing/routes.constants";
import useAppDispatch from "../../utils/customHooks/useAppDispatch.hook";
import useAppSelector from "../../utils/customHooks/useAppSelector.hook";
import { setFlag } from "../../utils/feature-flags/featureFlags.slice";
Expand Down Expand Up @@ -149,6 +157,7 @@ export default function RootV2() {
function GroupsV2Routes() {
return (
<Routes>
<Route index element={<RedirectToSearch entityType="group" />} />
<Route path={RELATIVE_ROUTES.v2.groups.show.root}>
<Route element={<LazyGroupContainer />}>
<Route index element={<LazyGroupV2Overview />} />
Expand Down Expand Up @@ -178,9 +187,23 @@ function HelpV2Routes() {
);
}

function RedirectToSearch({ entityType }: { entityType: string }) {
const navigate = useNavigate();
navigate(
{
pathname: generatePath(ABSOLUTE_ROUTES.v2.search),
search: `q=type:${entityType}`,
},
{ replace: true }
);

return null;
}

function ProjectsV2Routes() {
return (
<Routes>
<Route index element={<RedirectToSearch entityType="project" />} />
<Route path={RELATIVE_ROUTES.v2.projects.show.root}>
<Route element={<LazyProjectPageV2Show />}>
<Route index element={<LazyProjectPageOverview />} />
Expand Down
12 changes: 12 additions & 0 deletions tests/cypress/e2e/searchV2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,16 @@ describe("Search V2", () => {
cy.getDataCy("search-sorting-select").select("Newest");
cy.getDataCy("search-header").contains("sort:created-desc");
});

it("/g redirects to search", () => {
fixtures.searchV2ListProjects();
cy.visit("/g");
cy.location("pathname").should("eq", "/search");
});

it("/p redirects to search", () => {
fixtures.searchV2ListProjects();
cy.visit("/p");
cy.location("pathname").should("eq", "/search");
});
});

0 comments on commit 6501ce5

Please sign in to comment.