-
Notifications
You must be signed in to change notification settings - Fork 0
[] Add custom 404 page, language fallback banner, and feedback widget to docs site #263
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c8ad4a6
chore: Add custom 404 page, language fallback banner, and feedback wi…
ca59c9e
Merge branch 'main' into feature/019f0d7d8813-019f0d7d8813
red-codens[bot] 9695e63
chore: Add custom 404 page, language fallback banner, and feedback wi…
86f5b5e
Merge remote-tracking branch 'origin/main' into pr263
zoetaka38 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { render, screen, waitFor } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { FeedbackWidget } from "../../components/FeedbackWidget"; | ||
|
|
||
| describe("FeedbackWidget", () => { | ||
| afterEach(() => { | ||
| vi.unstubAllGlobals(); | ||
| }); | ||
|
|
||
| it("posts helpful feedback and shows a thank-you message", async () => { | ||
| const user = userEvent.setup(); | ||
| const fetchMock = vi.fn().mockResolvedValue({ | ||
| ok: true, | ||
| status: 202, | ||
| }); | ||
| vi.stubGlobal("fetch", fetchMock); | ||
|
|
||
| render( | ||
| <FeedbackWidget path="/docs/getting-started" version="latest" />, | ||
| ); | ||
|
|
||
| await user.click(screen.getByRole("button", { name: "役に立った" })); | ||
|
|
||
| await waitFor(() => { | ||
| expect(fetchMock).toHaveBeenCalledWith("/api/docs/feedback", { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ | ||
| path: "/docs/getting-started", | ||
| helpful: true, | ||
| version: "latest", | ||
| }), | ||
| }); | ||
| }); | ||
|
|
||
| expect( | ||
| screen.getByText("ごフィードバックありがとうございます。"), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it("does not show error UI when fetch fails", async () => { | ||
| const user = userEvent.setup(); | ||
| vi.stubGlobal("fetch", vi.fn().mockRejectedValue(new Error("network"))); | ||
|
|
||
| render(<FeedbackWidget path="/docs/getting-started" version="latest" />); | ||
|
|
||
| await user.click(screen.getByRole("button", { name: "役に立った" })); | ||
|
|
||
| await waitFor(() => { | ||
| expect(global.fetch).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| expect(screen.queryByText(/error/i)).not.toBeInTheDocument(); | ||
| expect(screen.queryByText(/エラー/i)).not.toBeInTheDocument(); | ||
| expect( | ||
| screen.getByRole("button", { name: "役に立った" }), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { render, screen } from "@testing-library/react"; | ||
| import userEvent from "@testing-library/user-event"; | ||
| import { UntranslatedBanner } from "../../components/UntranslatedBanner"; | ||
|
|
||
| describe("UntranslatedBanner", () => { | ||
| it("shows banner for en locale on ja-only pages and hides it when dismissed", async () => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| render(<UntranslatedBanner locale="en" pageLang="ja" />); | ||
|
|
||
| expect( | ||
| screen.getByText("このページはまだ日本語のみ提供されています。"), | ||
| ).toBeInTheDocument(); | ||
|
|
||
| await user.click(screen.getByRole("button", { name: "閉じる" })); | ||
|
|
||
| expect( | ||
| screen.queryByText("このページはまだ日本語のみ提供されています。"), | ||
| ).not.toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // @vitest-environment node | ||
|
|
||
| import { readFileSync } from "fs"; | ||
| import { join } from "path"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| describe("404 page", () => { | ||
| it("includes title frontmatter and a link back to the docs home", () => { | ||
| const content = readFileSync( | ||
| join(__dirname, "../../pages/404.mdx"), | ||
| "utf-8", | ||
| ); | ||
|
|
||
| expect(content).toMatch(/title:\s*ページが見つかりません/); | ||
| expect(content).toMatch(/\]\(\/docs[^)]*\)/); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
|
|
||
| type FeedbackWidgetProps = { | ||
| path: string; | ||
| version?: string; | ||
| }; | ||
|
|
||
| export function FeedbackWidget({ | ||
| path, | ||
| version = "latest", | ||
| }: FeedbackWidgetProps) { | ||
| const [submitted, setSubmitted] = useState(false); | ||
| const [pending, setPending] = useState(false); | ||
|
|
||
| async function submitFeedback(helpful: boolean) { | ||
| if (pending || submitted) { | ||
| return; | ||
| } | ||
|
|
||
| setPending(true); | ||
|
|
||
| try { | ||
| const response = await fetch("/api/docs/feedback", { | ||
| method: "POST", | ||
| headers: { "Content-Type": "application/json" }, | ||
| body: JSON.stringify({ path, helpful, version }), | ||
| }); | ||
|
|
||
| if (response.ok) { | ||
| setSubmitted(true); | ||
| } | ||
| } catch { | ||
| // Fail silently when the feedback endpoint is unavailable. | ||
| } finally { | ||
| setPending(false); | ||
| } | ||
| } | ||
|
|
||
| if (submitted) { | ||
| return ( | ||
| <div | ||
| aria-label="ドキュメントフィードバック" | ||
| style={{ marginTop: "32px", paddingTop: "16px" }} | ||
| > | ||
| <p style={{ color: "#166534", margin: 0 }}> | ||
| ごフィードバックありがとうございます。 | ||
| </p> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| aria-label="ドキュメントフィードバック" | ||
| style={{ | ||
| borderTop: "1px solid #e5e7eb", | ||
| display: "flex", | ||
| flexWrap: "wrap", | ||
| gap: "8px", | ||
| marginTop: "32px", | ||
| paddingTop: "16px", | ||
| }} | ||
| > | ||
| <span style={{ marginRight: "8px" }}>このページは役に立ちましたか?</span> | ||
| <button | ||
| type="button" | ||
| disabled={pending} | ||
| onClick={() => submitFeedback(true)} | ||
| style={{ | ||
| backgroundColor: "#16a34a", | ||
| border: "none", | ||
| borderRadius: "6px", | ||
| color: "#ffffff", | ||
| cursor: pending ? "not-allowed" : "pointer", | ||
| opacity: pending ? 0.7 : 1, | ||
| padding: "6px 12px", | ||
| }} | ||
| > | ||
| 役に立った | ||
| </button> | ||
| <button | ||
| type="button" | ||
| disabled={pending} | ||
| onClick={() => submitFeedback(false)} | ||
| style={{ | ||
| backgroundColor: "#ffffff", | ||
| border: "1px solid #d1d5db", | ||
| borderRadius: "6px", | ||
| color: "#374151", | ||
| cursor: pending ? "not-allowed" : "pointer", | ||
| opacity: pending ? 0.7 : 1, | ||
| padding: "6px 12px", | ||
| }} | ||
| > | ||
| 役に立たなかった | ||
| </button> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| "use client"; | ||
|
|
||
| import { useState } from "react"; | ||
|
|
||
| type UntranslatedBannerProps = { | ||
| locale?: string; | ||
| pageLang?: string; | ||
| }; | ||
|
|
||
| export function UntranslatedBanner({ | ||
| locale, | ||
| pageLang, | ||
| }: UntranslatedBannerProps) { | ||
| const [dismissed, setDismissed] = useState(false); | ||
|
|
||
| if (dismissed || locale !== "en" || pageLang !== "ja") { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| role="status" | ||
| style={{ | ||
| backgroundColor: "#fef9c3", | ||
| border: "1px solid #fde047", | ||
| borderRadius: "6px", | ||
| color: "#713f12", | ||
| display: "flex", | ||
| alignItems: "center", | ||
| justifyContent: "space-between", | ||
| gap: "12px", | ||
| marginBottom: "16px", | ||
| padding: "12px 16px", | ||
| }} | ||
| > | ||
| <span>このページはまだ日本語のみ提供されています。</span> | ||
| <button | ||
| type="button" | ||
| aria-label="閉じる" | ||
| onClick={() => setDismissed(true)} | ||
| style={{ | ||
| background: "transparent", | ||
| border: "none", | ||
| color: "#713f12", | ||
| cursor: "pointer", | ||
| fontSize: "18px", | ||
| lineHeight: 1, | ||
| padding: "0 4px", | ||
| }} | ||
| > | ||
| × | ||
| </button> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| --- | ||
| title: ページが見つかりません | ||
| --- | ||
|
|
||
| # ページが見つかりません | ||
|
|
||
| お探しのページは存在しないか、移動した可能性があります。 | ||
|
|
||
| [ドキュメントのトップページへ戻る](/docs) | ||
|
|
||
| サイト内検索を使って、目的のページを探すこともできます。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 [high] Pages Router と App Router のフックを混在させている
locale取得にnext/routerのuseRouterを使いながら、パス取得にnext/navigationのusePathnameを使っており、Next.js 標準のルーティングモデルでは同一ツリー内で併用できません。localeをnext/routerから取っている時点で Pages Router 前提と読め、usePathname()は実行時エラーになるか、常にnullとなりpathが空文字になる恐れがあります。該当箇所:
フィードバック POST の
pathが空になると、分析用途のデータ品質も損なわれます。code.router.mixed_hooks| confidence: 0.82