|
15 | 15 | import { TabContext, TabList, TabPanel } from "@mui/lab"; |
16 | 16 | import { Box, styled, Tab, Typography } from "@mui/material"; |
17 | 17 | import Link, { LinkProps } from "@mui/material/Link"; |
18 | | -import React, { useCallback, useEffect, useMemo, useState } from "react"; |
19 | | -import { Link as RouterLink, useParams } from "react-router"; |
| 18 | +import { useCallback, useEffect, useMemo, useState } from "react"; |
| 19 | +import { Link as RouterLink, useParams, useSearchParams } from "react-router"; |
20 | 20 | import ApiUrlFooter from "../components/ApiUrlFooter"; |
21 | 21 | import { IndexSummary } from "../components/IndexSummary"; |
22 | 22 | import { JsonEditor } from "../components/JsonEditor"; |
@@ -54,15 +54,30 @@ function IndexView() { |
54 | 54 | const { indexId } = useParams(); |
55 | 55 | const [loading, setLoading] = useState(false); |
56 | 56 | const [, setLoadingError] = useState<ErrorResult | null>(null); |
57 | | - const [tab, setTab] = useState< |
58 | | - | "summary" |
59 | | - | "sources" |
60 | | - | "doc-mapping" |
61 | | - | "indexing-settings" |
62 | | - | "search-settings" |
63 | | - | "retention-settings" |
64 | | - | "splits" |
65 | | - >("summary"); |
| 57 | + const [searchParams, setSearchParams] = useSearchParams(); |
| 58 | + |
| 59 | + const validTabs = [ |
| 60 | + "summary", |
| 61 | + "sources", |
| 62 | + "doc-mapping", |
| 63 | + "indexing-settings", |
| 64 | + "search-settings", |
| 65 | + "retention-settings", |
| 66 | + "splits", |
| 67 | + ] as const; |
| 68 | + |
| 69 | + type TabValue = (typeof validTabs)[number]; |
| 70 | + |
| 71 | + const isValidTab = (value: string | null): value is TabValue => { |
| 72 | + return validTabs.includes(value as TabValue); |
| 73 | + }; |
| 74 | + |
| 75 | + const tabFromUrl = searchParams.get("tab"); |
| 76 | + const tab = isValidTab(tabFromUrl) ? tabFromUrl : "summary"; |
| 77 | + |
| 78 | + const setTab = (newTab: TabValue) => { |
| 79 | + setSearchParams({ tab: newTab }); |
| 80 | + }; |
66 | 81 | const [index, setIndex] = useState<Index>(); |
67 | 82 | const quickwitClient = useMemo(() => new Client(), []); |
68 | 83 |
|
|
0 commit comments