Skip to content

Commit

Permalink
Fix indexes breadcrum link, fixes #4326 (#4327)
Browse files Browse the repository at this point in the history
* Fix indexes breadcrum link, fixes #4326

* Wrap indexView in router in test
  • Loading branch information
ddelemeny authored Dec 26, 2023
1 parent 77b0e17 commit 2a01fe8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
22 changes: 4 additions & 18 deletions quickwit/quickwit-ui/src/views/IndexView.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { render, unmountComponentAtNode } from "react-dom";
import { waitFor } from "@testing-library/react";
import { screen } from '@testing-library/dom';
import { unmountComponentAtNode } from "react-dom";
import { render, waitFor, screen } from "@testing-library/react";
import { act } from "react-dom/test-utils";
import { Client } from "../services/client";
import IndexView from "./IndexView";
import { BrowserRouter } from "react-router-dom";

jest.mock('../services/client');
const mockedUsedNavigate = jest.fn();
Expand All @@ -33,20 +33,6 @@ jest.mock('react-router-dom', () => ({
})
}));

let container = null;
beforeEach(() => {
// setup a DOM element as a render target
container = document.createElement("div");
document.body.appendChild(container);
});

afterEach(() => {
// cleanup on exiting
unmountComponentAtNode(container);
container.remove();
container = null;
});

test('renders IndexView', async () => {
const index = {
metadata: {
Expand All @@ -59,7 +45,7 @@ test('renders IndexView', async () => {
Client.prototype.getIndex.mockImplementation(() => Promise.resolve(index));

await act(async () => {
render(<IndexView />, container);
render( <IndexView /> , {wrapper: BrowserRouter});
});

await waitFor(() => expect(screen.getByText(/my-new-fresh-index-uri/)).toBeInTheDocument());
Expand Down
19 changes: 15 additions & 4 deletions quickwit/quickwit-ui/src/views/IndexView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { Box, styled, Typography, Link, Tab } from '@mui/material';
import { Box, styled, Typography, Tab } from '@mui/material';
import Link, { LinkProps } from '@mui/material/Link';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { Client } from '../services/client';
import Loader from '../components/Loader';
import { useParams } from 'react-router-dom';
import { Link as RouterLink, useParams } from 'react-router-dom';
import { Index } from '../utils/models';
import { TabContext, TabList, TabPanel } from '@mui/lab';
import { IndexSummary } from '../components/IndexSummary';
Expand All @@ -39,6 +40,16 @@ padding-right: 0;
height: 100%;
`;

// NOTE : https://mui.com/material-ui/react-breadcrumbs/#integration-with-react-router
interface LinkRouterProps extends LinkProps {
to: string;
replace?: boolean;
}

function LinkRouter(props: LinkRouterProps) {
return <Link {...props} component={RouterLink} />;
}

function IndexView() {
const { indexId } = useParams();
const [loading, setLoading] = useState(false)
Expand Down Expand Up @@ -123,9 +134,9 @@ function IndexView() {
<ViewUnderAppBarBox>
<FullBoxContainer>
<QBreadcrumbs aria-label="breadcrumb">
<Link underline="hover" color="inherit" href="../indexes">
<LinkRouter underline="hover" color="inherit" to="/indexes">
<Typography color="text.primary">Indexes</Typography>
</Link>
</LinkRouter>
<Typography color="text.primary">{indexId}</Typography>
</QBreadcrumbs>
{ renderFetchIndexResult() }
Expand Down

0 comments on commit 2a01fe8

Please sign in to comment.