Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: include origin in support link#16572

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 9 commits intomainfrom15542-lins
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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
22 changes: 22 additions & 0 deletionssite/src/modules/dashboard/Navbar/MobileMenu.test.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import { includeOrigin } from "./MobileMenu";

const mockOrigin = "https://example.com";

describe("support link", () => {
it("should include origin if target starts with '/'", () => {
(window as unknown as { location: Partial<Location> }).location = {
origin: mockOrigin,
}; // Mock the location origin

expect(includeOrigin("/test")).toBe(`${mockOrigin}/test`);
expect(includeOrigin("/path/to/resource")).toBe(
`${mockOrigin}/path/to/resource`,
);
});

it("should return the target unchanged if it does not start with '/'", () => {
expect(includeOrigin(`${mockOrigin}/page`)).toBe(`${mockOrigin}/page`);
expect(includeOrigin("../relative/path")).toBe("../relative/path");
expect(includeOrigin("relative/path")).toBe("relative/path");
});
});
14 changes: 13 additions & 1 deletionsite/src/modules/dashboard/Navbar/MobileMenu.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -307,7 +307,11 @@ const UserSettingsSub: FC<UserSettingsSubProps> = ({
asChild
className={cn(itemStyles.default, itemStyles.sub)}
>
<a href={l.target} target="_blank" rel="noreferrer">
<a
href={includeOrigin(l.target)}
target="_blank"
rel="noreferrer"
>
{l.name}
</a>
</DropdownMenuItem>
Expand All@@ -318,3 +322,11 @@ const UserSettingsSub: FC<UserSettingsSubProps> = ({
</Collapsible>
);
};

export const includeOrigin = (target: string): string => {
if (target.startsWith("/")) {
const baseUrl = window.location.origin;
return `${baseUrl}${target}`;
}
return target;
};
5 changes: 5 additions & 0 deletionssite/src/testHelpers/entities.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -246,6 +246,11 @@ export const MockSupportLinks: TypesGen.LinkConfig[] = [
"https://github.com/coder/coder/issues/new?labels=needs+grooming&body={CODER_BUILD_INFO}",
icon: "",
},
{
name: "Fourth link",
target: "/icons",
icon: "",
},
];

export const MockUpdateCheck: TypesGen.UpdateCheckResponse = {
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp