Skip to content

Commit

Permalink
update: deprecated some search indexes (#504)
Browse files Browse the repository at this point in the history
* update: deprecated some search indexes

* update search index
  • Loading branch information
shhdgit authored Aug 12, 2024
1 parent f4122d4 commit 8b36e24
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 53 deletions.
18 changes: 14 additions & 4 deletions src/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import FacebookIcon from "@mui/icons-material/Facebook";
import YouTubeIcon from "@mui/icons-material/YouTube";
import RedditIcon from "@mui/icons-material/Reddit";

import { StackOverflowIcon, SlackIcon, AskTugIcon, DiscordIcon } from "components/Icons";
import {
StackOverflowIcon,
SlackIcon,
AskTugIcon,
DiscordIcon,
} from "components/Icons";

import { convertVersionName } from "utils";
import CONFIG from "../../docs/docs.json";
Expand Down Expand Up @@ -75,7 +80,7 @@ export const EN_ICON_GROUP = [
name: "reddit",
href: "https://reddit.com/r/TiDB/",
icon: RedditIcon,
}
},
];

export const ZH_ICON_GROUP = [
Expand Down Expand Up @@ -491,7 +496,9 @@ export const JA_FOOTER_ITEMS = [
export const TIDB_EN_STABLE_VERSION = CONFIG["docs"]["tidb"]["stable"];
export const TIDB_EN_DMR_PRETTY_VERSION = CONFIG["docs"]["tidb"]["dmr"];
export const TIDB_EN_SEARCH_INDEX_VERSION =
CONFIG["docs"]["tidb"]["searchIndex"] || [];
CONFIG["docs"]["tidb"]["searchIndex"]["en"] || [];
export const TIDB_ZH_SEARCH_INDEX_VERSION =
CONFIG["docs"]["tidb"]["searchIndex"]["zh"] || [];
export const DM_EN_LATEST_VERSION =
CONFIG["docs"]["tidb-data-migration"]["languages"]["en"]["versions"][0];
export const DM_EN_STABLE_VERSION = "";
Expand All @@ -500,7 +507,10 @@ export const OP_EN_STABLE_VERSION =

export const TIDB_EN_VERSIONS = CONFIG["docs"]["tidb"]["languages"]["en"][
"versions"
].map((d) => convertVersionName(d, TIDB_EN_STABLE_VERSION));
].map((d) => convertVersionName(d, ""));
export const TIDB_ZH_VERSIONS = CONFIG["docs"]["tidb"]["languages"]["zh"][
"versions"
].map((d) => convertVersionName(d, ""));

export const DM_EN_VERSIONS = CONFIG["docs"]["tidb-data-migration"][
"languages"
Expand Down
95 changes: 46 additions & 49 deletions src/templates/DocSearchTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import {
CLOUD_EN_VERSIONS,
EN_DOC_TYPE_LIST,
ZH_DOC_TYPE_LIST,
TIDB_ZH_SEARCH_INDEX_VERSION,
TIDB_ZH_VERSIONS,
} from "static";
import { Locale } from "static/Type";
import { FeedbackSurveyCampaign } from "components/Campaign/FeedbackSurvey";
Expand All @@ -41,7 +43,7 @@ import { FeedbackSurveyCampaign } from "components/Campaign/FeedbackSurvey";
// TiDB Cloud: only has one version
// TiDB Operator: get stable version
// TiDB Data Migration: get latest version
const fetchVersionListByDocType = (docType: string) => {
const fetchVersionListByDocType = (docType: string, lang: string) => {
switch (docType) {
case "tidb-data-migration":
return [DM_EN_LATEST_VERSION];
Expand All @@ -50,27 +52,18 @@ const fetchVersionListByDocType = (docType: string) => {
case "tidbcloud":
return CLOUD_EN_VERSIONS;
case "tidb":
return fetchTidbSearchIndcies();
return fetchTidbSearchIndcies(lang);
default:
return [];
}
};

const fetchTidbSearchIndcies = (lts = 2, dmr = 1) => {
const tidbSearchIndices: string[] = [...TIDB_EN_SEARCH_INDEX_VERSION];
const tidbVersions = TIDB_EN_VERSIONS.filter((version) => version !== "dev");
const tidbDmrVersions = TIDB_EN_DMR_PRETTY_VERSION;
const tidbLtsVersions = [];
for (let i = 0; i < TIDB_EN_VERSIONS.length; i++) {
!tidbDmrVersions.includes(tidbVersions[i]) &&
tidbLtsVersions.push(tidbVersions[i]);
}
// tidbLtsVersions.slice(0, lts).forEach((version) => {
// tidbSearchIndices.push(version);
// });
tidbDmrVersions.slice(0, dmr).forEach((version) => {
tidbSearchIndices.push(version);
});
const fetchTidbSearchIndcies = (lang: string, lts = 1, dmr = 1) => {
const tidbSearchIndices: string[] = [
...(lang === "en"
? TIDB_EN_SEARCH_INDEX_VERSION
: TIDB_ZH_SEARCH_INDEX_VERSION),
];
return tidbSearchIndices.sort().reverse();
};

Expand Down Expand Up @@ -112,10 +105,14 @@ const convertStableToRealVersion = (
// TiDB Cloud: only has one version
// TiDB Operator: get stable version
// TiDB Data Migration: get latest version
const getSearchIndexVersion = (docType: string, docVersion: string) => {
const getSearchIndexVersion = (
docType: string,
docVersion: string,
lang: string
) => {
switch (docType) {
case "tidb":
const versions = fetchVersionListByDocType(docType);
const versions = fetchVersionListByDocType(docType, lang);
const realVersion =
docVersion === "stable" ? replaceStableVersion(docType) : docVersion;
if (versions.includes(realVersion || "")) {
Expand All @@ -141,9 +138,7 @@ interface DocSearchTemplateProps {
}

export default function DocSearchTemplate({
pageContext: {
feature
}
pageContext: { feature },
}: DocSearchTemplateProps) {
const [docType, setDocType] = React.useState("");
const [docVersion, setDocVersion] = React.useState("");
Expand Down Expand Up @@ -172,10 +167,10 @@ export default function DocSearchTemplate({
}, [docType, docQuery, docVersion]);

const realVersionMemo = React.useMemo(() => {
return getSearchIndexVersion(docType, docVersion);
return getSearchIndexVersion(docType, docVersion, language);
}, [docType, docVersion]);
const tidbSearchIndciesMemo = React.useMemo(() => {
return fetchTidbSearchIndcies();
return fetchTidbSearchIndcies(language);
}, []);

const execSearch = () => {
Expand Down Expand Up @@ -209,7 +204,7 @@ export default function DocSearchTemplate({
setDocType(selected);
};

const bannerVisible = feature?.banner && language !== Locale.ja
const bannerVisible = feature?.banner && language !== Locale.ja;

return (
<>
Expand Down Expand Up @@ -275,7 +270,7 @@ export default function DocSearchTemplate({
))}
</Stack>
</Box>
{!!fetchVersionListByDocType(docType).length && (
{!!fetchVersionListByDocType(docType, language).length && (
<Box
sx={{
display: "flex",
Expand All @@ -297,29 +292,31 @@ export default function DocSearchTemplate({
<Trans i18nKey="search.version" />
</Typography>
<Stack direction="row" sx={{ flexWrap: "wrap", gap: "1rem" }}>
{fetchVersionListByDocType(docType).map((version) => {
return (
<Button
key={version}
size="small"
variant="text"
onClick={() => {
setDocVersion(version);
}}
sx={{
backgroundColor:
realVersionMemo ===
convertStableToRealVersion(docType, version)
? "#EAF6FB"
: "",
}}
>
{version === "stable"
? convertStableToRealVersion(docType, version)
: version?.replace("release-", "v")}
</Button>
);
})}
{fetchVersionListByDocType(docType, language).map(
(version) => {
return (
<Button
key={version}
size="small"
variant="text"
onClick={() => {
setDocVersion(version);
}}
sx={{
backgroundColor:
realVersionMemo ===
convertStableToRealVersion(docType, version)
? "#EAF6FB"
: "",
}}
>
{version === "stable"
? convertStableToRealVersion(docType, version)
: version?.replace("release-", "v")}
</Button>
);
}
)}
</Stack>
</Box>
)}
Expand Down

0 comments on commit 8b36e24

Please sign in to comment.