Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

GDGT-2767 Replace deprecated MaybeLink (#77908)

Egor Grushin8ab2269f04cf
diff --git a/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/StrategyEditorForQuestionsAndDashboards.module.css b/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/StrategyEditorForQuestionsAndDashboards.module.css
index bc40268ea29..fcfb990c2d8 100644
--- a/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/StrategyEditorForQuestionsAndDashboards.module.css
+++ b/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/StrategyEditorForQuestionsAndDashboards.module.css
@@ -41,17 +41,7 @@
}
}
-.ItemLink {
- font-size: inherit !important;
-
- &:hover {
- color: var(--mb-color-core-brand);
- }
-}
-
-.ItemLink,
-.CollectionLink {
- :hover {
- color: var(--mb-color-core-brand);
- }
+.ItemLink:hover,
+.CollectionLink :hover {
+ color: var(--mb-color-core-brand);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/TableRowForCacheableItem.tsx b/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/TableRowForCacheableItem.tsx
index 55934c1bd1a..b4a17eadff9 100644
--- a/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/TableRowForCacheableItem.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/caching/components/StrategyEditorForQuestionsAndDashboards/TableRowForCacheableItem.tsx
@@ -3,7 +3,6 @@ import { useMemo } from "react";
import { getShortStrategyLabel } from "metabase/admin/performance/utils";
import { EllipsifiedCollectionPath } from "metabase/common/components/EllipsifiedPath/EllipsifiedCollectionPath";
import { Link } from "metabase/common/components/Link";
-import { MaybeLink } from "metabase/common/components/MaybeLink/MaybeLink.styled";
import { useGetIcon } from "metabase/hooks/use-icon";
import { Box, Button, Ellipsified, FixedSizeIcon, Flex } from "metabase/ui";
import * as Urls from "metabase/urls";
@@ -48,6 +47,20 @@ export const TableRowForCacheableItem = ({
}
};
+ const cellContent = (
+ <Flex
+ className={StrategyEditorForQuestionsAndDashboardsS.ItemLink}
+ align="center"
+ wrap="nowrap"
+ gap="sm"
+ fw={700}
+ style={{ overflow: "hidden" }}
+ >
+ {iconName ? <FixedSizeIcon name={iconName} /> : <Box h="sm" w="md" />}
+ <Ellipsified>{name}</Ellipsified>
+ </Flex>
+ );
+
return (
<tr
className={
@@ -56,26 +69,7 @@ export const TableRowForCacheableItem = ({
: undefined
}
>
- <td>
- <MaybeLink
- className={StrategyEditorForQuestionsAndDashboardsS.ItemLink}
- to={url}
- >
- <Flex
- align="center"
- wrap="nowrap"
- gap="sm"
- style={{ overflow: "hidden" }}
- >
- {iconName ? (
- <FixedSizeIcon name={iconName} />
- ) : (
- <Box h="sm" w="md" />
- )}
- <Ellipsified style={{ fontWeight: "bold" }}>{name}</Ellipsified>
- </Flex>
- </MaybeLink>
- </td>
+ <td>{url ? <Link to={url}>{cellContent}</Link> : cellContent}</td>
<td>
{collection && (
<Link
diff --git a/frontend/src/metabase/browse/metrics/MetricsTable.tsx b/frontend/src/metabase/browse/metrics/MetricsTable.tsx
index 4afb7fb2f42..78931cce378 100644
--- a/frontend/src/metabase/browse/metrics/MetricsTable.tsx
+++ b/frontend/src/metabase/browse/metrics/MetricsTable.tsx
@@ -14,7 +14,6 @@ import { SortableColumnHeader } from "metabase/common/components/ItemsTable/Base
import {
ColumnHeader,
ItemNameCell,
- MaybeItemLink,
TBody,
Table,
TableColumn,
@@ -229,36 +228,28 @@ function preventDefault(event: MouseEvent) {
function NameCell({ metric }: { metric?: MetricResult }) {
const headingId = `metric-${metric?.id ?? "dummy"}-heading`;
-
return (
<ItemNameCell
data-testid="metric-name"
aria-labelledby={headingId}
{...nameProps}
>
- <MaybeItemLink
- to={
- metric
- ? Urls.metric({ id: metric.id, name: metric.name, type: "metric" })
- : undefined
- }
- style={{
- // To align the icons with "Name" in the <th>
- paddingInlineStart: "1.4rem",
- paddingInlineEnd: ".5rem",
- }}
- onClick={preventDefault}
- >
+ <Flex align="center" gap="0.5rem" ps="1.4rem" pe="0.5rem">
{metric ? (
- <EntityItem.Name
- name={metric?.name || ""}
- variant="list"
- id={headingId}
- />
+ <Link
+ to={Urls.metric({
+ id: metric.id,
+ name: metric.name,
+ type: "metric",
+ })}
+ onClick={preventDefault}
+ >
+ <EntityItem.Name name={metric.name} variant="list" id={headingId} />
+ </Link>
) : (
<SkeletonText />
)}
- </MaybeItemLink>
+ </Flex>
</ItemNameCell>
);
}
diff --git a/frontend/src/metabase/browse/models/ModelsTable.tsx b/frontend/src/metabase/browse/models/ModelsTable.tsx
index 34955d4f782..282b74aa1e8 100644
--- a/frontend/src/metabase/browse/models/ModelsTable.tsx
+++ b/frontend/src/metabase/browse/models/ModelsTable.tsx
@@ -9,7 +9,6 @@ import { EntityItem } from "metabase/common/components/EntityItem";
import { SortableColumnHeader } from "metabase/common/components/ItemsTable/BaseItemsTable";
import {
ItemNameCell,
- MaybeItemLink,
TBody,
Table,
TableColumn,
@@ -210,35 +209,28 @@ function NameCell({ model }: { model?: ModelResult }) {
const getIcon = useGetIcon();
const headingId = `model-${model?.id || "dummy"}-heading`;
const icon = getIcon(model ?? { model: "dataset" }) ?? { name: "folder" };
+ const name = <EntityItem.Name name={model?.name || ""} variant="list" />;
return (
<ItemNameCell data-testid="model-name" aria-labelledby={headingId}>
- <MaybeItemLink
- to={
- model
- ? Urls.model({ id: model.id, name: model.name, type: "model" })
- : undefined
- }
- style={{
- // To align the icons with "Name" in the <th>
- paddingInlineStart: "1.4rem",
- paddingInlineEnd: ".5rem",
- }}
- onClick={preventDefault}
- >
+ <Flex id={headingId} align="center" gap="0.5rem" ps="1.4rem" pe="0.5rem">
<EntityIcon
size="1rem"
{...icon}
color="icon-brand"
style={{ flexShrink: 0 }}
/>
- {
- <EntityItem.Name
- name={model?.name || ""}
- variant="list"
- id={headingId}
- />
- }
- </MaybeItemLink>
+ {model ? (
+ <Link
+ to={Urls.model({ id: model.id, name: model.name, type: "model" })}
+ onClick={preventDefault}
+ style={{ overflow: "hidden" }}
+ >
+ {name}
+ </Link>
+ ) : (
+ name
+ )}
+ </Flex>
</ItemNameCell>
);
}
diff --git a/frontend/src/metabase/common/collections/components/PinnedItemCard/PinnedItemCard.styled.tsx b/frontend/src/metabase/common/collections/components/PinnedItemCard/PinnedItemCard.styled.tsx
index c71b120b99b..7e8ad06576b 100644
--- a/frontend/src/metabase/common/collections/components/PinnedItemCard/PinnedItemCard.styled.tsx
+++ b/frontend/src/metabase/common/collections/components/PinnedItemCard/PinnedItemCard.styled.tsx
@@ -1,25 +1,9 @@
// eslint-disable-next-line no-restricted-imports
-import { css } from "@emotion/react";
-// eslint-disable-next-line no-restricted-imports
import styled from "@emotion/styled";
import { MarkdownPreview } from "metabase/common/components/MarkdownPreview";
-import { RawMaybeLink } from "metabase/common/components/MaybeLink/MaybeLink.styled";
import { Box, type BoxProps } from "metabase/ui";
-export const ItemLink = styled(RawMaybeLink)<{ to?: string }>`
- display: block;
- height: min-content;
- ${(props) =>
- props.to
- ? ""
- : css`
- ${Body} {
- cursor: default;
- }
- `}
-`;
-
// Unjustified type cast. FIXME
export const ActionsContainer = styled(Box)<BoxProps>`
display: flex;
diff --git a/frontend/src/metabase/common/collections/components/PinnedItemCard/PinnedItemCard.tsx b/frontend/src/metabase/common/collections/components/PinnedItemCard/PinnedItemCard.tsx
index d2f6d1102ba..d5067f78a7f 100644
--- a/frontend/src/metabase/common/collections/components/PinnedItemCard/PinnedItemCard.tsx
+++ b/frontend/src/metabase/common/collections/components/PinnedItemCard/PinnedItemCard.tsx
@@ -9,9 +9,10 @@ import type {
} from "metabase/common/collections/types";
import { EntityIcon } from "metabase/common/components/EntityIcon";
import { EventSandbox } from "metabase/common/components/EventSandbox";
+import { Link } from "metabase/common/components/Link";
import { useGetIcon } from "metabase/hooks/use-icon";
import { PLUGIN_MODERATION } from "metabase/plugins";
-import { Card, Flex, Skeleton, Tooltip } from "metabase/ui";
+import { Box, Card, Flex, Skeleton, Tooltip } from "metabase/ui";
import { modelToUrl } from "metabase/urls";
import type Database from "metabase-lib/v1/metadata/Database";
import type {
@@ -27,7 +28,6 @@ import {
Body,
Description,
Header,
- ItemLink,
Title,
} from "./PinnedItemCard.styled";
@@ -119,71 +119,74 @@ function PinnedItemCard({
isCollectionItem(item) &&
(onCopy || onMove || createBookmark || deleteBookmark || collection);
+ const card = (
+ <Card p={0} radius="md" shadow="none" withBorder>
+ <Body style={item ? undefined : { cursor: "default" }}>
+ <Header>
+ <EntityIcon {...iconData} size="1.5rem" color="core-brand" />
+ <ActionsContainer h={item ? undefined : "2rem"}>
+ {hasActions && (
+ // This component is used within a `<Link>` component,
+ // so we must prevent events from triggering the activation of the link
+ <EventSandbox preventDefault sandboxedEvents={["onClick"]}>
+ <ActionMenu
+ databases={databases}
+ bookmarks={bookmarks}
+ createBookmark={createBookmark}
+ deleteBookmark={deleteBookmark}
+ item={item}
+ collection={collection}
+ onCopy={onCopy}
+ onMove={onMove}
+ />
+ </EventSandbox>
+ )}
+ </ActionsContainer>
+ </Header>
+ {item ? (
+ <>
+ <Tooltip
+ label={item.name}
+ position="bottom"
+ disabled={!showTitleTooltip}
+ maw={TOOLTIP_MAX_WIDTH}
+ >
+ <Title
+ onMouseEnter={(e) => maybeEnableTooltip(e, setShowTitleTooltip)}
+ >
+ <Flex align="center" gap="0.5rem">
+ {item.name}
+ <PLUGIN_MODERATION.ModerationStatusIcon
+ status={item.moderated_status}
+ filled
+ size={14}
+ />
+ </Flex>
+ </Title>
+ </Tooltip>
+ <Description tooltipMaxWidth={TOOLTIP_MAX_WIDTH}>
+ {item.description || DEFAULT_DESCRIPTION[item.model] || ""}
+ </Description>
+ </>
+ ) : (
+ <>
+ <Skeleton natural h="1.5rem" />
+ <Skeleton natural mt="xs" mb="4px" h="1rem" />
+ </>
+ )}
+ </Body>
+ </Card>
+ );
+ const to = item ? (modelToUrl(item) ?? "/") : undefined;
return (
- <ItemLink
+ <Box
+ display="block"
+ h="min-content"
className={className}
- to={item ? (modelToUrl(item) ?? "/") : undefined}
onClick={onClick}
>
- <Card p={0} radius="md" shadow="none" withBorder>
- <Body>
- <Header>
- <EntityIcon {...iconData} size="1.5rem" color="core-brand" />
- <ActionsContainer h={item ? undefined : "2rem"}>
- {hasActions && (
- // This component is used within a `<Link>` component,
- // so we must prevent events from triggering the activation of the link
- <EventSandbox preventDefault sandboxedEvents={["onClick"]}>
- <ActionMenu
- databases={databases}
- bookmarks={bookmarks}
- createBookmark={createBookmark}
- deleteBookmark={deleteBookmark}
- item={item}
- collection={collection}
- onCopy={onCopy}
- onMove={onMove}
- />
- </EventSandbox>
- )}
- </ActionsContainer>
- </Header>
- {item ? (
- <>
- <Tooltip
- label={item.name}
- position="bottom"
- disabled={!showTitleTooltip}
- maw={TOOLTIP_MAX_WIDTH}
- >
- <Title
- onMouseEnter={(e) =>
- maybeEnableTooltip(e, setShowTitleTooltip)
- }
- >
- <Flex align="center" gap="0.5rem">
- {item.name}
- <PLUGIN_MODERATION.ModerationStatusIcon
- status={item.moderated_status}
- filled
- size={14}
- />
- </Flex>
- </Title>
- </Tooltip>
- <Description tooltipMaxWidth={TOOLTIP_MAX_WIDTH}>
- {item.description || DEFAULT_DESCRIPTION[item.model] || ""}
- </Description>
- </>
- ) : (
- <>
- <Skeleton natural h="1.5rem" />
- <Skeleton natural mt="xs" mb="4px" h="1rem" />
- </>
- )}
- </Body>
- </Card>
- </ItemLink>
+ {to ? <Link to={to}>{card}</Link> : card}
+ </Box>
);
}
diff --git a/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable.styled.tsx b/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable.styled.tsx
index 7f00d350e39..2dc3479c52b 100644
--- a/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable.styled.tsx
+++ b/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable.styled.tsx
@@ -12,7 +12,6 @@ import {
import { EntityItem } from "metabase/common/components/EntityItem";
import { IconButtonWrapper } from "metabase/common/components/IconButtonWrapper";
import { Link } from "metabase/common/components/Link";
-import { RawMaybeLink } from "metabase/common/components/MaybeLink/MaybeLink.styled";
import AdminS from "metabase/css/admin.module.css";
import type { IconProps, TextProps } from "metabase/ui";
import { FixedSizeIcon, Text } from "metabase/ui";
@@ -112,17 +111,15 @@ export const ItemButton = styled(Text)<
export const ItemLink = styled(Link)(itemLinkStyle);
-export const MaybeItemLink = styled(RawMaybeLink)(itemLinkStyle);
-
export const ItemNameCell = styled.td`
padding: 0 !important;
- ${ItemLink}, ${MaybeItemLink}, ${ItemButton} {
+ & > * {
padding: 1em;
}
&:hover {
- ${ItemLink}, ${MaybeItemLink}, ${ItemButton} {
+ & > * {
color: var(--mb-color-core-brand);
}
diff --git a/frontend/src/metabase/common/components/MaybeLink/MaybeLink.styled.tsx b/frontend/src/metabase/common/components/MaybeLink/MaybeLink.styled.tsx
deleted file mode 100644
index 7b90671e0c3..00000000000
--- a/frontend/src/metabase/common/components/MaybeLink/MaybeLink.styled.tsx
+++ /dev/null
@@ -1,48 +0,0 @@
-// eslint-disable-next-line no-restricted-imports
-import { css } from "@emotion/react";
-// eslint-disable-next-line no-restricted-imports
-import styled from "@emotion/styled";
-import type { HTMLAttributes } from "react";
-
-import type { LinkProps } from "metabase/common/components/Link";
-import { Link } from "metabase/common/components/Link";
-import { maybeColor } from "metabase/ui/utils/colors";
-
-interface RawMaybeLinkProps {
- to?: string;
- activeColor?: string;
- inactiveColor?: string;
- isSingleLine?: boolean;
-}
-
-export function RawMaybeLink({
- to,
- activeColor,
- inactiveColor,
- isSingleLine,
- ...props
-}: RawMaybeLinkProps & (LinkProps | HTMLAttributes<HTMLSpanElement>)) {
- return to ? <Link to={to} {...props} /> : <span {...props} />;
-}
-
-const hoverStyle = (props: RawMaybeLinkProps) => css`
- cursor: pointer;
- ${props.activeColor ? `color: ${maybeColor(props.activeColor)};` : ""}
-`;
-
-/**
- * @deprecated styled components are deprecated
- */
-export const MaybeLink = styled(RawMaybeLink)`
- display: flex;
- align-items: center;
- font-size: 0.875em;
- font-weight: bold;
- ${(props) =>
- props.inactiveColor ? `color: ${maybeColor(props.inactiveColor)};` : ""}
- min-width: ${(props) => (props.isSingleLine ? 0 : "")};
-
- :hover {
- ${(props) => (props.to || props.onClick) && hoverStyle(props)}
- }
-`;