Skip to content

Commit 2782429

Browse files
committed
feat: enhance Header and HeaderAction components with pathConfig support
- Added pathConfig prop to Header and HeaderAction components for improved navigation handling. - Updated LangSwitch component to utilize pathConfig, enhancing language selection logic based on cloud mode. - Adjusted button disabling logic in LangSwitch to account for cloud mode status, improving user experience.
1 parent 1d178a7 commit 2782429

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/components/Layout/Header.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export default function Header(props: HeaderProps) {
8585
docInfo={props.docInfo}
8686
buildType={props.buildType}
8787
pageUrl={props.pageUrl}
88+
pathConfig={props.pathConfig}
8889
/>
8990
</Toolbar>
9091
</AppBar>

src/components/Layout/HeaderAction.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ import TranslateIcon from "media/icons/globe-02.svg";
1717

1818
import Search from "components/Search";
1919

20-
import { Locale, BuildType } from "shared/interface";
20+
import { Locale, BuildType, PathConfig } from "shared/interface";
2121
import { ActionButton } from "components/Card/FeedbackSection/components";
2222
import { Link } from "gatsby";
2323
import { useIsAutoTranslation } from "shared/useIsAutoTranslation";
24+
import { useCloudMode } from "shared/useCloudMode";
2425

2526
const useTiDBAIStatus = () => {
2627
const [showTiDBAIButton, setShowTiDBAIButton] = React.useState(true);
@@ -62,8 +63,9 @@ export default function HeaderAction(props: {
6263
docInfo?: { type: string; version: string };
6364
buildType?: BuildType;
6465
pageUrl?: string;
66+
pathConfig?: PathConfig;
6567
}) {
66-
const { supportedLocales, docInfo, buildType, pageUrl } = props;
68+
const { supportedLocales, docInfo, buildType, pageUrl, pathConfig } = props;
6769
const { language, t } = useI18next();
6870
const { showTiDBAIButton, initializingTiDBAI } = useTiDBAIStatus();
6971
const isAutoTranslation = useIsAutoTranslation(pageUrl || "");
@@ -78,7 +80,10 @@ export default function HeaderAction(props: {
7880
sx={{ marginLeft: "auto", alignItems: "center" }}
7981
>
8082
{supportedLocales.length > 0 && (
81-
<LangSwitch supportedLocales={supportedLocales} />
83+
<LangSwitch
84+
supportedLocales={supportedLocales}
85+
pathConfig={pathConfig}
86+
/>
8287
)}
8388
{docInfo && !isAutoTranslation && buildType !== "archive" && (
8489
<>
@@ -121,13 +126,15 @@ const LangSwitch = (props: {
121126
language?: string;
122127
changeLanguage?: () => void;
123128
supportedLocales: Locale[];
129+
pathConfig?: PathConfig;
124130
}) => {
125-
const { supportedLocales } = props;
131+
const { supportedLocales, pathConfig } = props;
126132

127133
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
128134

129135
const theme = useTheme();
130136
const { language, changeLanguage } = useI18next();
137+
const { isClassic } = useCloudMode(pathConfig!.repo);
131138

132139
const open = Boolean(anchorEl);
133140
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
@@ -213,7 +220,7 @@ const LangSwitch = (props: {
213220
onClick={toggleLanguage(Locale.zh)}
214221
disableRipple
215222
selected={language === Locale.zh}
216-
disabled={!supportedLocales.includes(Locale.zh)}
223+
disabled={!supportedLocales.includes(Locale.zh) || !isClassic}
217224
>
218225
<Typography component="span" color={theme.palette.carbon[900]}>
219226
<Trans i18nKey="lang.zh" />
@@ -223,7 +230,7 @@ const LangSwitch = (props: {
223230
onClick={toggleLanguage(Locale.ja)}
224231
disableRipple
225232
selected={language === Locale.ja}
226-
disabled={!supportedLocales.includes(Locale.ja)}
233+
disabled={!supportedLocales.includes(Locale.ja) || !isClassic}
227234
>
228235
<Typography component="span" color={theme.palette.carbon[900]}>
229236
<Trans i18nKey="lang.ja" />

0 commit comments

Comments
 (0)