Skip to content

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

Truncate the longest app bar breadcrumbs first so short collection names stay readable (#84823)

Andersond14d6c049c64
diff --git a/e2e/test/scenarios/onboarding/navbar/navbar.cy.spec.js b/e2e/test/scenarios/onboarding/navbar/navbar.cy.spec.js
index 0187577dda8..da04a30cf34 100644
--- a/e2e/test/scenarios/onboarding/navbar/navbar.cy.spec.js
+++ b/e2e/test/scenarios/onboarding/navbar/navbar.cy.spec.js
@@ -6,7 +6,7 @@ import {
THIRD_COLLECTION_ID,
} from "e2e/support/cypress_sample_instance_data";
-const { ORDERS_ID } = SAMPLE_DATABASE;
+const { ORDERS_ID, PEOPLE_ID } = SAMPLE_DATABASE;
describe("scenarios > navigation > navbar", () => {
describe("Normal user", () => {
@@ -83,6 +83,56 @@ describe("scenarios > navigation > navbar", () => {
});
});
+ describe("app bar breadcrumbs", () => {
+ const LONG_COLLECTION_NAME = "A collection with a very long name "
+ .repeat(4)
+ .trim();
+
+ beforeEach(() => {
+ H.restore();
+ cy.signInAsAdmin();
+ });
+
+ it("should keep short breadcrumbs readable next to a very long one (#79984)", () => {
+ H.createCollection({ name: "Examples" })
+ .then(({ body: parent }) =>
+ H.createCollection({
+ name: LONG_COLLECTION_NAME,
+ parent_id: parent.id,
+ }),
+ )
+ .then(({ body: collection }) =>
+ H.createQuestion({
+ name: "People model",
+ type: "model",
+ collection_id: collection.id,
+ query: { "source-table": PEOPLE_ID },
+ }),
+ )
+ .then(({ body: model }) => {
+ cy.log("Collection path on the model page");
+ H.visitModel(model.id);
+ assertBreadcrumbIsNotTruncated("Examples");
+ assertBreadcrumbIsTruncated(LONG_COLLECTION_NAME);
+ H.appBar().findByText(LONG_COLLECTION_NAME).realHover();
+ H.tooltip()
+ .should("be.visible")
+ .and("have.text", LONG_COLLECTION_NAME);
+
+ cy.log("Full trail in the object detail view");
+ H.DetailView.visitModel(model.id, 1);
+ assertBreadcrumbIsNotTruncated("Examples");
+ assertBreadcrumbIsNotTruncated("People model");
+ assertBreadcrumbIsNotTruncated("Hudson Borer");
+ assertBreadcrumbIsTruncated(LONG_COLLECTION_NAME);
+ H.appBar().findByText(LONG_COLLECTION_NAME).realHover();
+ H.tooltip()
+ .should("be.visible")
+ .and("have.text", LONG_COLLECTION_NAME);
+ });
+ });
+ });
+
describe("EE", () => {
beforeEach(() => {
H.restore();
@@ -123,3 +173,19 @@ describe("scenarios > navigation > navbar", () => {
});
});
});
+
+/** @param {string} name */
+function assertBreadcrumbIsNotTruncated(name) {
+ H.appBar()
+ .findByText(name)
+ .should("be.visible")
+ .and(($element) => H.assertIsNotEllipsified($element[0]));
+}
+
+/** @param {string} name */
+function assertBreadcrumbIsTruncated(name) {
+ H.appBar()
+ .findByText(name)
+ .should("be.visible")
+ .and(($element) => H.assertIsEllipsified($element[0]));
+}
diff --git a/frontend/src/metabase/app/nav/AppBar.tsx b/frontend/src/metabase/app/nav/AppBar.tsx
index 77c84304f8b..ae4303a3803 100644
--- a/frontend/src/metabase/app/nav/AppBar.tsx
+++ b/frontend/src/metabase/app/nav/AppBar.tsx
@@ -139,6 +139,7 @@ export function AppBarContainer() {
<CollectionBreadcrumbs
dashboard={dashboardId != null ? dashboard : undefined}
collectionId={breadcrumbCollectionId ?? undefined}
+ truncateLongestFirst
/>
}
questionLineage={
diff --git a/frontend/src/metabase/common/collections/components/CollectionBadge/CollectionBadge.tsx b/frontend/src/metabase/common/collections/components/CollectionBadge/CollectionBadge.tsx
index 297f3b97e0e..bb2fa05ca57 100644
--- a/frontend/src/metabase/common/collections/components/CollectionBadge/CollectionBadge.tsx
+++ b/frontend/src/metabase/common/collections/components/CollectionBadge/CollectionBadge.tsx
@@ -21,11 +21,13 @@ const IRREGULAR_ICON_PROPS = {
type CollectionBadgeInnerProps = {
collection: CollectionType;
+ showTooltip?: boolean;
onClick?: () => void;
};
const CollectionBadgeInner = ({
collection,
+ showTooltip,
onClick,
}: CollectionBadgeInnerProps) => {
const tc = useTranslateContent();
@@ -45,6 +47,7 @@ const CollectionBadgeInner = ({
<Breadcrumb
icon={icon.name}
iconColor={icon.color}
+ showTooltip={showTooltip}
to={
onClick ? undefined : modelToUrl({ model: "collection", ...collection })
}
@@ -57,11 +60,13 @@ const CollectionBadgeInner = ({
type CollectionBadgeProps = {
collectionId?: CollectionId;
+ showTooltip?: boolean;
onClick?: () => void;
};
export const CollectionBadge = ({
collectionId,
+ showTooltip,
onClick,
}: CollectionBadgeProps) => {
const { data: collection } = useGetCollectionQuery({
@@ -70,5 +75,11 @@ export const CollectionBadge = ({
if (!collection) {
return null;
}
- return <CollectionBadgeInner collection={collection} onClick={onClick} />;
+ return (
+ <CollectionBadgeInner
+ collection={collection}
+ showTooltip={showTooltip}
+ onClick={onClick}
+ />
+ );
};
diff --git a/frontend/src/metabase/common/components/Breadcrumb/Breadcrumb.module.css b/frontend/src/metabase/common/components/Breadcrumb/Breadcrumb.module.css
index 24f3bf48880..e9346a0b882 100644
--- a/frontend/src/metabase/common/components/Breadcrumb/Breadcrumb.module.css
+++ b/frontend/src/metabase/common/components/Breadcrumb/Breadcrumb.module.css
@@ -3,6 +3,12 @@
font-size: 0.875em;
}
+/* Crumbs get equal shares of the trail, capped at their own width, so the longest crumbs truncate first */
+.trail > .breadcrumb {
+ flex: 1 1 0;
+ max-width: max-content;
+}
+
.content {
--color: var(--mb-color-text-disabled);
--active-color: var(--mb-color-core-brand);
diff --git a/frontend/src/metabase/common/components/Breadcrumb/Breadcrumb.tsx b/frontend/src/metabase/common/components/Breadcrumb/Breadcrumb.tsx
index 8ba74b9a01d..d20f1f77e94 100644
--- a/frontend/src/metabase/common/components/Breadcrumb/Breadcrumb.tsx
+++ b/frontend/src/metabase/common/components/Breadcrumb/Breadcrumb.tsx
@@ -9,6 +9,9 @@ import type { IconName } from "metabase-types/api";
import S from "./Breadcrumb.module.css";
+/** For a single-line flex trail: its direct `Breadcrumb` children truncate the longest crumbs first. */
+export const BREADCRUMB_TRAIL_CLASS_NAME = S.trail;
+
interface Props {
children: ReactNode;
className?: string;
diff --git a/frontend/src/metabase/common/components/Breadcrumb/index.ts b/frontend/src/metabase/common/components/Breadcrumb/index.ts
index eadaed4d9d1..43a338a41b1 100644
--- a/frontend/src/metabase/common/components/Breadcrumb/index.ts
+++ b/frontend/src/metabase/common/components/Breadcrumb/index.ts
@@ -1 +1 @@
-export { Breadcrumb } from "./Breadcrumb";
+export { BREADCRUMB_TRAIL_CLASS_NAME, Breadcrumb } from "./Breadcrumb";
diff --git a/frontend/src/metabase/detail-view/components/Nav/CollectionBreadcrumb.tsx b/frontend/src/metabase/detail-view/components/Nav/CollectionBreadcrumb.tsx
index 8a014ea2b17..5f87c9a34ca 100644
--- a/frontend/src/metabase/detail-view/components/Nav/CollectionBreadcrumb.tsx
+++ b/frontend/src/metabase/detail-view/components/Nav/CollectionBreadcrumb.tsx
@@ -9,7 +9,7 @@ interface Props {
export const CollectionBreadcrumb = ({ collectionId }: Props) => (
<>
- <CollectionBadge collectionId={collectionId} />
+ <CollectionBadge collectionId={collectionId} showTooltip />
<Separator />
</>
diff --git a/frontend/src/metabase/detail-view/components/Nav/ModelNav.tsx b/frontend/src/metabase/detail-view/components/Nav/ModelNav.tsx
index 222c8ed30a2..d9e5f58a68d 100644
--- a/frontend/src/metabase/detail-view/components/Nav/ModelNav.tsx
+++ b/frontend/src/metabase/detail-view/components/Nav/ModelNav.tsx
@@ -1,3 +1,4 @@
+import cx from "classnames";
import { type ReactNode, useMemo } from "react";
import {
@@ -6,7 +7,10 @@ import {
useGetCollectionQuery,
} from "metabase/api";
import { CollectionBadge } from "metabase/common/collections/components/CollectionBadge";
-import { Breadcrumb } from "metabase/common/components/Breadcrumb";
+import {
+ BREADCRUMB_TRAIL_CLASS_NAME,
+ Breadcrumb,
+} from "metabase/common/components/Breadcrumb";
import { Group, type GroupProps } from "metabase/ui";
import * as Urls from "metabase/urls";
import { getQuestionIdFromVirtualTableId } from "metabase-lib/v1/metadata/utils/saved-questions";
@@ -21,7 +25,7 @@ interface Props extends GroupProps {
table: Table;
}
-export const ModelNav = ({ rowName, table, ...props }: Props) => {
+export const ModelNav = ({ rowName, table, className, ...props }: Props) => {
const modelId = getQuestionIdFromVirtualTableId(table.id);
const { data: card } = useGetCardQuery(
@@ -37,7 +41,14 @@ export const ModelNav = ({ rowName, table, ...props }: Props) => {
}, [collection]);
return (
- <Group align="center" gap="sm" miw={0} wrap="nowrap" {...props}>
+ <Group
+ align="center"
+ className={cx(BREADCRUMB_TRAIL_CLASS_NAME, className)}
+ gap="sm"
+ miw={0}
+ wrap="nowrap"
+ {...props}
+ >
{collections.map((collection) => (
<CollectionBreadcrumb
collectionId={collection.id}
@@ -47,7 +58,7 @@ export const ModelNav = ({ rowName, table, ...props }: Props) => {
{collection && (
<>
- <CollectionBadge collectionId={collection.id} />
+ <CollectionBadge collectionId={collection.id} showTooltip />
<Separator />
</>
diff --git a/frontend/src/metabase/detail-view/components/Nav/TableNav.tsx b/frontend/src/metabase/detail-view/components/Nav/TableNav.tsx
index f83fb81a8d2..dc648c9b52a 100644
--- a/frontend/src/metabase/detail-view/components/Nav/TableNav.tsx
+++ b/frontend/src/metabase/detail-view/components/Nav/TableNav.tsx
@@ -1,7 +1,11 @@
+import cx from "classnames";
import type { ReactNode } from "react";
import { skipToken, useListDatabaseSchemasQuery } from "metabase/api";
-import { Breadcrumb } from "metabase/common/components/Breadcrumb";
+import {
+ BREADCRUMB_TRAIL_CLASS_NAME,
+ Breadcrumb,
+} from "metabase/common/components/Breadcrumb";
import { Group, type GroupProps } from "metabase/ui";
import * as Urls from "metabase/urls";
import { type Table, isConcreteTableId } from "metabase-types/api";
@@ -13,7 +17,7 @@ interface Props extends GroupProps {
table: Table;
}
-export const TableNav = ({ rowName, table, ...props }: Props) => {
+export const TableNav = ({ rowName, table, className, ...props }: Props) => {
const { data: schemas, isLoading: isLoadingSchemas } =
useListDatabaseSchemasQuery(
table && table.db_id && table.schema ? { id: table.db_id } : skipToken,
@@ -24,7 +28,14 @@ export const TableNav = ({ rowName, table, ...props }: Props) => {
}
return (
- <Group align="center" gap="sm" miw={0} wrap="nowrap" {...props}>
+ <Group
+ align="center"
+ className={cx(BREADCRUMB_TRAIL_CLASS_NAME, className)}
+ gap="sm"
+ miw={0}
+ wrap="nowrap"
+ {...props}
+ >
<Breadcrumb
icon="database"
to={Urls.browseDatabase(table.db)}
diff --git a/frontend/src/metabase/nav/components/CollectionBreadcrumbs/CollectionBreadcrumbs.tsx b/frontend/src/metabase/nav/components/CollectionBreadcrumbs/CollectionBreadcrumbs.tsx
index c9a4957c7df..178cbcf3483 100644
--- a/frontend/src/metabase/nav/components/CollectionBreadcrumbs/CollectionBreadcrumbs.tsx
+++ b/frontend/src/metabase/nav/components/CollectionBreadcrumbs/CollectionBreadcrumbs.tsx
@@ -17,6 +17,7 @@ export interface CollectionBreadcrumbsProps {
dashboard?: Dashboard;
onClick?: (collection: CollectionEssentials) => void;
baseCollectionId: CollectionId | null;
+ truncateLongestFirst?: boolean;
}
export const CollectionBreadcrumbs = ({
@@ -24,6 +25,7 @@ export const CollectionBreadcrumbs = ({
dashboard,
onClick,
baseCollectionId = null,
+ truncateLongestFirst,
}: CollectionBreadcrumbsProps): JSX.Element | null => {
const tc = useTranslateContent();
@@ -45,6 +47,7 @@ export const CollectionBreadcrumbs = ({
}
: undefined
}
+ truncateLongestFirst={truncateLongestFirst}
/>
);
};
diff --git a/frontend/src/metabase/nav/components/CollectionBreadcrumbs/CollectionBreadcrumbsView.tsx b/frontend/src/metabase/nav/components/CollectionBreadcrumbs/CollectionBreadcrumbsView.tsx
index 6972b938d52..f8611ba0394 100644
--- a/frontend/src/metabase/nav/components/CollectionBreadcrumbs/CollectionBreadcrumbsView.tsx
+++ b/frontend/src/metabase/nav/components/CollectionBreadcrumbs/CollectionBreadcrumbsView.tsx
@@ -1,8 +1,12 @@
+import cx from "classnames";
import { Fragment, type ReactNode, useState } from "react";
import { t } from "ttag";
import { CollectionBadge } from "metabase/common/collections/components/CollectionBadge";
-import { Breadcrumb } from "metabase/common/components/Breadcrumb";
+import {
+ BREADCRUMB_TRAIL_CLASS_NAME,
+ Breadcrumb,
+} from "metabase/common/components/Breadcrumb";
import { ActionIcon, Box, Flex, Icon } from "metabase/ui";
import type { CollectionEssentials, IconName } from "metabase-types/api";
@@ -31,6 +35,8 @@ type CollectionBreadcrumbsViewProps = {
path: BreadcrumbCrumb[];
/** Pinned after the path, and never collapsed away. */
terminal?: BreadcrumbCrumb;
+ /** When the trail is too narrow, the longest crumbs truncate first and truncated crumbs show a tooltip. */
+ truncateLongestFirst?: boolean;
};
const BreadcrumbSeparator = () => (
@@ -50,28 +56,43 @@ const getCrumbKey = (crumb: BreadcrumbCrumb) =>
? `collection-${crumb.collection.id}`
: `static-${crumb.key}`;
-const CrumbContent = ({ crumb }: { crumb: BreadcrumbCrumb }) =>
+type CrumbContentProps = {
+ crumb: BreadcrumbCrumb;
+ showTooltip: boolean;
+};
+
+const CrumbContent = ({ crumb, showTooltip }: CrumbContentProps) =>
crumb.kind === "collection" ? (
<CollectionBadge
collectionId={crumb.collection.id}
+ showTooltip={showTooltip}
onClick={crumb.onClick}
/>
) : (
- <Breadcrumb icon={crumb.icon} to={crumb.to} onClick={crumb.onClick}>
+ <Breadcrumb
+ icon={crumb.icon}
+ showTooltip={showTooltip}
+ to={crumb.to}
+ onClick={crumb.onClick}
+ >
{crumb.label}
</Breadcrumb>
);
type TrailItem = { key: string; node: ReactNode };
-const toTrailItem = (crumb: BreadcrumbCrumb): TrailItem => ({
+const toTrailItem = (
+ crumb: BreadcrumbCrumb,
+ showTooltip: boolean,
+): TrailItem => ({
key: getCrumbKey(crumb),
- node: <CrumbContent crumb={crumb} />,
+ node: <CrumbContent crumb={crumb} showTooltip={showTooltip} />,
});
export const CollectionBreadcrumbsView = ({
path,
terminal,
+ truncateLongestFirst = false,
}: CollectionBreadcrumbsViewProps) => {
const [isExpanded, setIsExpanded] = useState(false);
@@ -79,7 +100,7 @@ export const CollectionBreadcrumbsView = ({
const pathItems: TrailItem[] = isCollapsed
? [
- toTrailItem(path[0]),
+ toTrailItem(path[0], truncateLongestFirst),
{
key: "expand",
node: (
@@ -92,14 +113,20 @@ export const CollectionBreadcrumbsView = ({
</ActionIcon>
),
},
- toTrailItem(path[path.length - 1]),
+ toTrailItem(path[path.length - 1], truncateLongestFirst),
]
- : path.map(toTrailItem);
+ : path.map((crumb) => toTrailItem(crumb, truncateLongestFirst));
- const items = terminal ? [...pathItems, toTrailItem(terminal)] : pathItems;
+ const items = terminal
+ ? [...pathItems, toTrailItem(terminal, truncateLongestFirst)]
+ : pathItems;
return (
- <Flex align="center" miw="0">
+ <Flex
+ align="center"
+ className={cx({ [BREADCRUMB_TRAIL_CLASS_NAME]: truncateLongestFirst })}
+ miw="0"
+ >
{items.map(({ key, node }, index) => (
<Fragment key={key}>
{index > 0 && <BreadcrumbSeparator />}