Skip to content

Commit

Permalink
fix: API reference resets when switching languages (#890)
Browse files Browse the repository at this point in the history
Reverts the changes from #723 since the Construct Hub backend now generates IDs / urls that are stable across languages when applicable (cdklabs/construct-hub#142). More precisely, when a linked section of a page has docs in multiple languages, the corresponding directory and URL hash should be the same across them (`/api/Foo#bar`).

Fixes #714
  • Loading branch information
Chriscbr authored Jan 31, 2022
1 parent a528e89 commit 3ace71e
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions src/views/Package/LanguageBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { IconButton, Stack } from "@chakra-ui/react";
import type { FunctionComponent } from "react";
import { useHistory } from "react-router-dom";
import { getFullPackageName } from "../../api/package/util";
import { LanguageSupportTooltip } from "../../components/LanguageSupportTooltip";
import {
Language,
Expand All @@ -10,9 +8,7 @@ import {
LANGUAGES,
} from "../../constants/languages";
import { clickEvent, useAnalytics } from "../../contexts/Analytics";
import { getPackagePath } from "../../util/url";
import { PACKAGE_ANALYTICS } from "./constants";
import { usePackageState } from "./PackageState";

export interface LanguageBarProps {
targetLanguages: readonly Language[];
Expand All @@ -23,10 +19,9 @@ export interface LanguageBarProps {
export const LanguageBar: FunctionComponent<LanguageBarProps> = ({
targetLanguages,
selectedLanguage,
setSelectedLanguage,
}) => {
const { trackCustomEvent } = useAnalytics();
const { name, scope, version } = usePackageState();
const { push } = useHistory();
return (
<Stack
align="center"
Expand All @@ -51,15 +46,7 @@ export const LanguageBar: FunctionComponent<LanguageBarProps> = ({
name: PACKAGE_ANALYTICS.LANGUAGE.eventName(language),
})
);
// reset to package root since our URL scheme for APIs currently
// differs between languages.
push(
getPackagePath({
name: getFullPackageName(name, scope),
version,
language,
})
);
setSelectedLanguage(language);
};

return (
Expand Down

0 comments on commit 3ace71e

Please sign in to comment.