Skip to content

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

Reveal column descriptions on hover in the Detail visualization (#78875)

Andersone406a40c47f9
diff --git a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Card_Visualizations_Dark_Theme.png b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Card_Visualizations_Dark_Theme.png
index ef705dd659e..ac0c7e2472b 100644
Binary files a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Card_Visualizations_Dark_Theme.png and b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Card_Visualizations_Dark_Theme.png differ
diff --git a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Card_Visualizations_Light_Theme.png b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Card_Visualizations_Light_Theme.png
index 53830114825..ee5d9eb2aac 100644
Binary files a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Card_Visualizations_Light_Theme.png and b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedDashboardView_Card_Visualizations_Light_Theme.png differ
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.module.css b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.module.css
index cb6e31359e9..3096a8bbb3c 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.module.css
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.module.css
@@ -1,3 +1,23 @@
.fitImage {
object-fit: contain;
}
+
+.columnName {
+ display: flex;
+ align-items: center;
+ gap: var(--mantine-spacing-xs);
+}
+
+.descriptionIcon {
+ visibility: hidden;
+}
+
+.columnName:hover .descriptionIcon {
+ visibility: visible;
+}
+
+@media (hover: none) and (pointer: coarse) {
+ .descriptionIcon {
+ visibility: visible;
+ }
+}
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.tsx b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.tsx
index b9deed2f68a..40f4bf88bac 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.tsx
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.tsx
@@ -6,8 +6,9 @@ import { t } from "ttag";
import { EmptyState } from "metabase/common/components/EmptyState";
import CS from "metabase/css/core/index.css";
import QueryBuilderS from "metabase/css/query_builder.module.css";
-import { Box, Ellipsified } from "metabase/ui";
+import { Box, Ellipsified, Icon } from "metabase/ui";
import { displayNameForColumn, formatValue } from "metabase/value-formatting";
+import type { ComputedVisualizationSettings } from "metabase/visualizations/types";
import type { ClickObject } from "metabase-lib";
import { findColumnIndexesForColumnSettings } from "metabase-lib/v1/queries/utils/dataset";
import { TYPE } from "metabase-lib/v1/types/constants";
@@ -28,10 +29,10 @@ import S from "./ObjectDetailsTable.module.css";
import type { OnVisualizationClickType } from "./types";
export interface DetailsTableCellProps {
- column: any;
- value: any;
+ column: DatasetColumn;
+ value?: RowValue;
isColumnName: boolean;
- settings: any;
+ settings?: ComputedVisualizationSettings;
className?: string;
clicked?: ClickObject;
onVisualizationClick: OnVisualizationClickType;
@@ -56,18 +57,31 @@ export function DetailsTableCell({
columnSettings?.["_column_title_full"] || displayNameForColumn(column);
if (isColumnName) {
- const title = column !== null ? columnTitle : null;
- cellValue = <Ellipsified lines={8}>{title}</Ellipsified>;
+ cellValue = (
+ <span className={S.columnName}>
+ <Ellipsified lines={8}>{columnTitle}</Ellipsified>
+ {column.description && (
+ <Icon
+ name="info"
+ size={14}
+ flex="0 0 auto"
+ className={S.descriptionIcon}
+ tooltip={column.description}
+ />
+ )}
+ </span>
+ );
isLink = false;
} else {
if (value === null || value === undefined || value === "") {
cellValue = <span className={CS.textTertiary}>{t`Empty`}</span>;
} else if (isa(column.semantic_type, TYPE.SerializedJSON)) {
+ const rawJson = String(value);
let formattedJson;
try {
- formattedJson = JSON.stringify(JSON.parse(value), null, 2);
+ formattedJson = JSON.stringify(JSON.parse(rawJson), null, 2);
} catch (e) {
- formattedJson = value;
+ formattedJson = rawJson;
}
cellValue = (
<pre className={QueryBuilderS.ObjectJSON}>{formattedJson}</pre>
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.unit.spec.tsx b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.unit.spec.tsx
index c2ddb116f30..9b169ce606f 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.unit.spec.tsx
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailsTable.unit.spec.tsx
@@ -1,4 +1,5 @@
import { fireEvent } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
import { testDataset } from "__support__/testDataset";
import { render, screen } from "__support__/ui";
@@ -93,6 +94,24 @@ const objectDetailImageCard = {
}),
};
+const objectDetailDescriptionCard = {
+ data: createMockDatasetData({
+ cols: [
+ createMockColumn({
+ name: "name",
+ display_name: "Name",
+ description: "The name of the user who owns an account",
+ }),
+ createMockColumn({
+ name: "email",
+ display_name: "Email",
+ description: null,
+ }),
+ ],
+ rows: [["Hudson Borer", "[email protected]"]],
+ }),
+};
+
describe("ObjectDetailsTable", () => {
it("renders an object details table", () => {
render(
@@ -175,6 +194,38 @@ describe("ObjectDetailsTable", () => {
});
});
+ describe("column descriptions", () => {
+ const setupDescriptionCard = () =>
+ render(
+ <DetailsTable
+ columns={objectDetailDescriptionCard.data.cols}
+ zoomedRow={objectDetailDescriptionCard.data.rows[0]}
+ onVisualizationClick={() => null}
+ visualizationIsClickable={() => false}
+ settings={{
+ column: () => null,
+ }}
+ isDashboard={false}
+ />,
+ );
+
+ it("should show the column description on hovering its info icon (#68682)", async () => {
+ setupDescriptionCard();
+
+ await userEvent.hover(screen.getByRole("img", { name: "info icon" }));
+
+ expect(await screen.findByTestId("icon-tooltip")).toHaveTextContent(
+ "The name of the user who owns an account",
+ );
+ });
+
+ it("should not render an info icon for columns without a description (#68682)", () => {
+ setupDescriptionCard();
+
+ expect(screen.getAllByRole("img", { name: "info icon" })).toHaveLength(1);
+ });
+ });
+
describe("json field rendering", () => {
it("should properly display JSON semantic type data as JSON", () => {
render(