Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(redirects): remove retiredLocale parameter #11148

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions client/src/document/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { useSearchParams, useNavigate } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import useSWR, { mutate } from "swr";

import { WRITER_MODE, PLACEMENT_ENABLED } from "../env";
Expand All @@ -25,7 +25,6 @@ import { LocalizedContentNote } from "./molecules/localized-content-note";
import { OfflineStatusBar } from "../ui/molecules/offline-status-bar";
import { TOC } from "./organisms/toc";
import { RenderSideBar } from "./organisms/sidebar";
import { RetiredLocaleNote } from "./molecules/retired-locale-note";
import { MainContentContainer } from "../ui/atoms/page-content";
import { Loading } from "../ui/atoms/loading";
import { ArticleFooter } from "./organisms/article-footer";
Expand Down Expand Up @@ -74,7 +73,6 @@ export function Document(props /* TODO: define a TS interface for this */) {
const mountCounter = React.useRef(0);
const documentURL = useDocumentURL();
const locale = useLocale();
const [searchParams] = useSearchParams();

const navigate = useNavigate();

Expand Down Expand Up @@ -213,8 +211,6 @@ export function Document(props /* TODO: define a TS interface for this */) {
return null;
}

const retiredLocale = searchParams.get("retiredLocale");

return (
<>
<div className="sticky-header-container">
Expand All @@ -223,16 +219,10 @@ export function Document(props /* TODO: define a TS interface for this */) {
</div>
{/* only include this if we are not server-side rendering */}
{!isServer && <OfflineStatusBar />}
{doc.isTranslated ? (
{doc.isTranslated && (
<div className="container">
<LocalizedContentNote isActive={doc.isActive} locale={locale} />
</div>
) : (
retiredLocale && (
<div className="container">
<RetiredLocaleNote locale={retiredLocale} />
</div>
)
)}
<div className="main-wrapper">
<div className="sidebar-container">
Expand Down
26 changes: 0 additions & 26 deletions client/src/document/molecules/retired-locale-note/index.tsx

This file was deleted.

7 changes: 2 additions & 5 deletions libs/fundamental-redirects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,8 @@ const LOCALE_PATTERNS = [
)})(/(?<suffix>.*)|$)`,
"i"
),
({ locale, suffix }) => {
const join = suffix && suffix.includes("?") ? "&" : "?";
return `/${DEFAULT_LOCALE}/${
(suffix || "") + join
}retiredLocale=${RETIRED_LOCALES.get(locale.toLowerCase())}`;
({ suffix }) => {
return `/${DEFAULT_LOCALE}/${suffix || ""}`;
}
),
];
Expand Down
55 changes: 0 additions & 55 deletions testing/integration/headless/test_redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,58 +108,3 @@ def test_firefox_source_docs_redirects(url, base_url):
def test_misc_redirects(url, base_url):
url["base_url"] = base_url
assert_valid_url(**url)


@pytest.mark.parametrize(
"retired_locale",
(
"ar",
"bg",
"bn",
"ca",
"el",
"fa",
"fi",
"he",
"hi-IN",
"hu",
"id",
"it",
"kab",
"ms",
"my",
"nl",
"pt-PT",
"sv-SE",
"th",
"tr",
"uk",
"vi",
),
)
@pytest.mark.parametrize(
"slug",
[
"",
"/",
"/docs/Web",
"/docs/Web/",
"/search",
"/search/",
"/search?q=video",
"/search/?q=video",
"/settings",
],
)
def test_retired_locale_redirects(base_url, slug, retired_locale):
"""Ensure that requests for retired locales properly redirect."""
resp = request("get", f"{base_url}/{retired_locale}{slug}")
assert resp.status_code == 302
slug_parts = slug.split("?")
expected_slug = slug_parts[0].lstrip("/")
expected_qs = f"?retiredLocale={retired_locale}"
if len(slug_parts) > 1:
expected_qs += f"&{slug_parts[1]}"
assert (
resp.headers["Location"] == f"/en-US/{expected_slug}{expected_qs}"
), f"{resp.headers['Location']} is not /en-US/{expected_slug}{expected_qs}"
29 changes: 3 additions & 26 deletions testing/tests/headless.index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,44 +229,21 @@ test.describe("changing language", () => {
test.describe("viewing retired locales", () => {
test("redirect retired locale to English (document)", async ({ page }) => {
await page.goto(testURL("/ar/docs/Web/Foo"));
expect(page.url()).toBe(testURL("/en-US/docs/Web/Foo/?retiredLocale=ar"));
expect(page.url()).toBe(testURL("/en-US/docs/Web/Foo/"));
expect(await page.innerText("h1")).toBe("<foo>: A test tag");
});

test("redirect retired locale to English (index.json)", async ({ page }) => {
await page.goto(testURL("/ar/docs/Web/Foo/index.json"));
expect(page.url()).toBe(
testURL("/en-US/docs/Web/Foo/index.json?retiredLocale=ar")
);
expect(page.url()).toBe(testURL("/en-US/docs/Web/Foo/index.json"));
expect(await page.isVisible("text=<foo>: A test tag")).toBeTruthy();
});

test("redirect retired locale to English (search with query string)", async ({
page,
}) => {
await page.goto(testURL("/ar/search?q=video"));
expect(page.url()).toBe(testURL("/en-US/search/?q=video&retiredLocale=ar"));
expect(page.url()).toBe(testURL("/en-US/search/?q=video"));
expect(await page.isVisible("text=Search results for: video")).toBeTruthy();
});

test("say the locale was retired", async ({ page }) => {
await page.goto(testURL("/en-US/docs/Web/Foo/?retiredLocale=ar"));
expect(
await page.isVisible("text=The page you requested has been retired")
).toBeTruthy();
// sanity check that it goes away
await page.goto(testURL("/en-US/docs/Web/Foo/"));
expect(
await page.isVisible("text=The page you requested has been retired")
).toBeFalsy();
});

test("not say the locale was retired if viewing a translated page", async ({
page,
}) => {
await page.goto(testURL("/fr/docs/Web/Foo/?retiredLocale=sv-SE"));
expect(
await page.isVisible("text=The page you requested has been retired")
).toBeFalsy();
});
});
Loading
Loading