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

Links to metabase URLs should open in the same window in link cards #41508

Merged
merged 4 commits into from
Apr 18, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import _ from "underscore";
import TippyPopover from "metabase/components/Popover/TippyPopover";
import Search from "metabase/entities/search";
import { useToggle } from "metabase/hooks/use-toggle";
import { getUrlTarget } from "metabase/lib/dom";
import { SearchResults } from "metabase/nav/components/search/SearchResults";
import type {
LinkCardSettings,
Expand Down Expand Up @@ -181,7 +182,11 @@ function LinkVizInner({
data-testid="custom-view-text-link"
fade={isEditingParameter}
>
<ExternalLink href={url ?? ""} target="_blank" rel="noreferrer">
<ExternalLink
href={url ?? ""}
target={getUrlTarget(url)}
rel="noreferrer"
>
<UrlLinkDisplay url={url} />
</ExternalLink>
</DisplayLinkCardWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,41 @@ describe("LinkViz", () => {
expect(screen.getByText("https://example23.com")).toBeInTheDocument();
expect(screen.getByRole("link")).toHaveAttribute("target", "_blank");
});

it("should open absolute links to question in the same tab", () => {
const dashcard = createMockLinkDashboardCard({
url: "http://localhost/question/1-example",
});

setup({
isEditing: false,
dashcard,
settings: dashcard.visualization_settings as LinkCardVizSettings,
});

expect(window.location.origin).toBe("http://localhost");

expect(
screen.getByText("http://localhost/question/1-example"),
).toBeInTheDocument();

expect(screen.getByRole("link")).toHaveAttribute("target", "_self");
});

it("should open relative links to question in the same tab", () => {
const dashcard = createMockLinkDashboardCard({
url: "question/2-example",
});

setup({
isEditing: false,
dashcard,
settings: dashcard.visualization_settings as LinkCardVizSettings,
});

expect(screen.getByText("question/2-example")).toBeInTheDocument();
expect(screen.getByRole("link")).toHaveAttribute("target", "_self");
});
});

describe("entity links", () => {
Expand Down