Skip to content

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

GDGT-1083: Improve visual design for new List view in Stats before v57 (#64957)

Stas Gavrylovfafc53e645a7
diff --git a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Table_Light_Theme.png b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Table_Light_Theme.png
index 5bacb28678d..5e3a7e13249 100644
Binary files a/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Table_Light_Theme.png and b/.loki/reference/chrome_laptop_App_Embed_PublicOrEmbeddedQuestionView_Table_Light_Theme.png differ
diff --git a/e2e/test/scenarios/models/models-list-view.cy.spec.js b/e2e/test/scenarios/models/models-list-view.cy.spec.js
index 27f79dbb90c..9f9d07378cf 100644
--- a/e2e/test/scenarios/models/models-list-view.cy.spec.js
+++ b/e2e/test/scenarios/models/models-list-view.cy.spec.js
@@ -87,15 +87,19 @@ describe("scenarios > models list view", () => {
cy.get("@listPreview").should("be.visible");
cy.get("@listPreview").within(() => {
// Verify preview shows sample data values
- cy.findByRole("img").should("have.attr", "aria-label", "document icon");
+ cy.findAllByRole("img").should(
+ "have.attr",
+ "aria-label",
+ "document icon",
+ );
cy.findAllByText("1").should("have.length", 2);
cy.findByText("14").should("be.visible");
cy.findByText("37.65").should("be.visible");
cy.findByText("2.07").should("be.visible");
});
- cy.log("Add CREATED_AT column to left columns");
- cy.get("@leftColumns").within(() => {
+ cy.log("Add CREATED_AT column to right columns");
+ cy.get("@rightColumns").within(() => {
cy.get("input").type("CR");
});
@@ -131,20 +135,36 @@ describe("scenarios > models list view", () => {
cy.findByText("DISCOUNT").click();
});
cy.get("@listPreview").within(() => {
- cy.findByText("$123.46").should("be.visible");
+ cy.findByText("123.46").should("be.visible");
});
cy.log("Update list item icon");
cy.get("@listPreview").within(() => {
- cy.findByRole("img").should("have.attr", "aria-label", "document icon");
+ cy.findAllByRole("img").should(
+ "have.attr",
+ "aria-label",
+ "document icon",
+ );
});
cy.findByTestId("list-view-icon").click();
H.popover().within(() => {
- cy.findByText("Company").should("be.visible").click();
+ cy.findByRole("img", { name: "factory icon" })
+ .should("have.attr", "aria-label", "factory icon")
+ .click();
+ cy.findByTestId("list-view-icon-colors").then(($list) => {
+ const $button = Cypress.$($list).find("button").eq(2);
+ expect($button.attr("style")).to.include(
+ "background: var(--mb-color-accent1)",
+ );
+ $button.click();
+ });
});
cy.get("@listPreview").within(() => {
- cy.findByRole("img").should("have.attr", "aria-label", "company icon");
+ cy.findAllByRole("img")
+ .first()
+ .should("have.attr", "style", "color: var(--mb-color-accent1);")
+ .and("have.attr", "aria-label", "factory icon");
});
cy.findByTestId("dataset-edit-bar").button("Save changes").click();
@@ -152,7 +172,7 @@ describe("scenarios > models list view", () => {
cy.log("Verify that custom column set is correct");
cy.findByTestId("visualization-root").within(() => {
- cy.findByText("ID and CREATED_AT").should("be.visible");
+ cy.findByText("ID").should("be.visible");
cy.findByText("USER_ID").should("be.visible");
cy.findByText("PRODUCT_ID").should("be.visible");
cy.findByText("SUBTOTAL").should("be.visible");
@@ -160,7 +180,7 @@ describe("scenarios > models list view", () => {
cy.findAllByRole("img")
.first()
- .should("have.attr", "aria-label", "company icon");
+ .should("have.attr", "aria-label", "factory icon");
cy.findByText("February 11, 2025, 9:40 PM").should("be.visible");
cy.findByText("14").should("be.visible");
cy.findByText("37.65").should("be.visible");
diff --git a/frontend/src/metabase-lib/v1/types/utils/isa.js b/frontend/src/metabase-lib/v1/types/utils/isa.js
index 4e69f2e9ced..0a632b6ae28 100644
--- a/frontend/src/metabase-lib/v1/types/utils/isa.js
+++ b/frontend/src/metabase-lib/v1/types/utils/isa.js
@@ -131,8 +131,17 @@ export const isPK = (field) => field && isTypePK(field.semantic_type);
export const isEntityName = (field) =>
field && isa(field.semantic_type, TYPE.Name);
export const isTitle = (field) => field && isa(field.semantic_type, TYPE.Title);
+export const isProduct = (field) =>
+ field && isa(field.semantic_type, TYPE.Product);
+export const isSource = (field) =>
+ field && isa(field.semantic_type, TYPE.Source);
export const isAddress = (field) =>
field && isa(field.semantic_type, TYPE.Address);
+export const isScore = (field) => field && isa(field.semantic_type, TYPE.Score);
+export const isQuantity = (field) =>
+ field && isa(field.semantic_type, TYPE.Quantity);
+export const isCategory = (field) =>
+ field && isa(field.semantic_type, TYPE.Category);
export const isAny = (col) => true;
@@ -165,6 +174,7 @@ export const isNumber = (field) =>
(field.semantic_type == null ||
isa(field.semantic_type, TYPE.Number) ||
isa(field.semantic_type, TYPE.Category));
+export const isFloat = (field) => field && isa(field.semantic_type, TYPE.Float);
export const isTime = (field) => {
if (!field) {
diff --git a/frontend/src/metabase-types/api/card.ts b/frontend/src/metabase-types/api/card.ts
index 266dad3e1f2..3878ba16472 100644
--- a/frontend/src/metabase-types/api/card.ts
+++ b/frontend/src/metabase-types/api/card.ts
@@ -1,4 +1,5 @@
import type { EmbeddingParameters } from "metabase/public/lib/types";
+import type { IconName } from "metabase/ui";
import type { PieRow } from "metabase/visualizations/echarts/pie/model/types";
import type { Collection, CollectionId, LastEditInfo } from "./collection";
@@ -330,8 +331,11 @@ export type VisualizationSettings = {
"sankey.label_value_formatting"?: "auto" | "full" | "compact";
// List view settings
- "list.columns"?: ListViewColumns;
- "list.entity_icon"?: string;
+ "list.columns"?: ListViewColumns; // set of columns selected for custom list view
+ "list.entity_icon_enabled"?: boolean; // display/hide first list item column rendering image/icon
+ "list.use_image_column"?: boolean; // render image from image/avatar url column instead of icon
+ "list.entity_icon"?: IconName | null;
+ "list.entity_icon_color"?: string;
[key: string]: any;
} & EmbedVisualizationSettings;
diff --git a/frontend/src/metabase/common/components/ReorderableTagsInput/ReorderableTagsInput.module.css b/frontend/src/metabase/common/components/ReorderableTagsInput/ReorderableTagsInput.module.css
index 5ccf2199974..a115f12664c 100644
--- a/frontend/src/metabase/common/components/ReorderableTagsInput/ReorderableTagsInput.module.css
+++ b/frontend/src/metabase/common/components/ReorderableTagsInput/ReorderableTagsInput.module.css
@@ -3,31 +3,33 @@
flex-wrap: wrap;
gap: var(--mantine-spacing-xs);
align-items: center;
- border: 1px dashed var(--mb-color-border);
- background-color: var(--mb-color-bg-light);
+ border: 1px dashed var(--mb-color-saturated-blue) !important;
+ background-color: var(--mb-color-background-hover-light);
border-radius: var(--mantine-radius-md);
transition: box-shadow 250ms ease;
- min-height: 2.5rem;
+ min-height: 3.25rem;
}
.max {
cursor: not-allowed;
}
-.dragOver {
- box-shadow: 0 0 2px 1px var(--mb-color-border);
+.dragOver:not(.max) {
+ box-shadow: 0 0 2px 1px var(--mb-color-saturated-blue);
cursor: none !important;
}
.pill {
+ display: flex;
+ flex: 0 0 auto;
+ padding-inline: 0.5rem;
height: 100%;
- font-weight: 400;
background: var(--mb-color-bg-white);
border: 1px solid var(--mb-color-border);
border-radius: var(--mantine-radius-xl);
cursor: pointer;
color: var(--mb-color-text-primary);
- flex: 0 0 auto;
+ font-weight: bold;
min-width: 4rem;
text-overflow: ellipsis;
overflow: hidden;
@@ -44,4 +46,5 @@
.inputField {
min-width: 1rem;
+ height: 2rem;
}
diff --git a/frontend/src/metabase/common/components/ReorderableTagsInput/ReorderableTagsInput.tsx b/frontend/src/metabase/common/components/ReorderableTagsInput/ReorderableTagsInput.tsx
index bdd5fd37a21..0f72c3df887 100644
--- a/frontend/src/metabase/common/components/ReorderableTagsInput/ReorderableTagsInput.tsx
+++ b/frontend/src/metabase/common/components/ReorderableTagsInput/ReorderableTagsInput.tsx
@@ -21,6 +21,7 @@ import { t } from "ttag";
import {
Combobox,
+ type MantineSize,
Pill,
PillsInput,
ScrollArea,
@@ -37,7 +38,7 @@ interface Props {
onChange: (next: string[]) => void;
maxValues?: number;
placeholder?: string;
- size?: string;
+ size?: MantineSize;
miw?: string | number;
maw?: string | number;
containerId?: string;
@@ -45,6 +46,7 @@ interface Props {
draggedItemId?: string | null;
currentDroppable?: string | null;
"data-testid"?: string;
+ styles?: { input?: CSSProperties };
}
export function SortablePill({
@@ -53,12 +55,14 @@ export function SortablePill({
onRemove,
containerId,
style,
+ size,
}: {
id: string;
label: string;
onRemove?: () => void;
containerId?: string;
- style?: React.CSSProperties;
+ style?: CSSProperties;
+ size?: MantineSize;
}) {
const {
attributes,
@@ -84,6 +88,7 @@ export function SortablePill({
return (
<Pill
+ size={size}
ref={setNodeRef}
className={cx(S.pill, { [S.dragging]: isDragging })}
withRemoveButton
@@ -93,6 +98,15 @@ export function SortablePill({
{...attributes}
{...listeners}
style={combinedStyle}
+ styles={{
+ label: {
+ display: "flex",
+ alignItems: "center",
+ },
+ remove: {
+ marginRight: 0,
+ },
+ }}
radius="xl"
draggable
onDragStart={(e) => {
@@ -116,6 +130,7 @@ export function ReorderableTagsInput({
draggedItemId,
currentDroppable,
"data-testid": dataTestId,
+ styles,
}: Props) {
const combobox = useCombobox({
onDropdownClose: () => combobox.resetSelectedOption(),
@@ -192,6 +207,7 @@ export function ReorderableTagsInput({
[S.dragOver]: isDragOver || currentDroppable === containerId,
}),
}}
+ styles={styles}
onMouseDownCapture={(e: React.MouseEvent<HTMLDivElement>) => {
const target = e.target as HTMLElement;
// Do not open when interacting with a pill (likely starting a drag or clicking remove)
@@ -207,6 +223,7 @@ export function ReorderableTagsInput({
onDragOver={(e) => {
// Allow dropping external items
e.preventDefault();
+ e.stopPropagation();
}}
onDragEnter={(e) => {
const related = e.relatedTarget as Node | null;
@@ -228,6 +245,7 @@ export function ReorderableTagsInput({
}}
onDrop={(e) => {
e.preventDefault();
+ e.stopPropagation();
const val = e.dataTransfer.getData("text/plain");
if (!val) {
return;
@@ -252,6 +270,7 @@ export function ReorderableTagsInput({
return (
<SortablePill
+ size={size}
key={v}
id={v}
label={data.find((o) => o.value === v)?.label ?? v}
@@ -290,6 +309,7 @@ export function ReorderableTagsInput({
removeAt(value.length - 1);
}
}}
+ style={styles?.input}
/>
</Combobox.EventsTarget>
) : null}
diff --git a/frontend/src/metabase/common/components/ReorderableTagsInput/test-utils.tsx b/frontend/src/metabase/common/components/ReorderableTagsInput/test-utils.tsx
index 15dde975876..bcb98da2511 100644
--- a/frontend/src/metabase/common/components/ReorderableTagsInput/test-utils.tsx
+++ b/frontend/src/metabase/common/components/ReorderableTagsInput/test-utils.tsx
@@ -1,4 +1,5 @@
import { renderWithProviders } from "__support__/ui";
+import type { MantineSize } from "metabase/ui";
import { type Option, ReorderableTagsInput } from "./ReorderableTagsInput";
@@ -18,7 +19,7 @@ interface SetupOpts {
onChange?: (value: string[]) => void;
maxValues?: number;
placeholder?: string;
- size?: string;
+ size?: MantineSize;
containerId?: string;
useExternalDnd?: boolean;
draggedItemId?: string | null;
diff --git a/frontend/src/metabase/list-view/components/ListView/ColumnValue.tsx b/frontend/src/metabase/list-view/components/ListView/ColumnValue.tsx
index 660b567369f..0cfbf6a115a 100644
--- a/frontend/src/metabase/list-view/components/ListView/ColumnValue.tsx
+++ b/frontend/src/metabase/list-view/components/ListView/ColumnValue.tsx
@@ -1,91 +1,308 @@
-import type { ReactNode } from "react";
+import { useMemo } from "react";
import { Ellipsified } from "metabase/common/components/Ellipsified";
-import { Box, Flex, Text } from "metabase/ui";
-import type { DatasetColumn } from "metabase-types/api";
+import {
+ formatNumber,
+ formatValue,
+ getCurrencySymbol,
+} from "metabase/lib/formatting";
+import { Badge, Box, Flex, Icon, Image, Stack, Text } from "metabase/ui";
+import { MiniBarCell } from "metabase/visualizations/components/TableInteractive/cells/MiniBarCell";
+import { getColumnExtent } from "metabase/visualizations/lib/utils";
+import type { ComputedVisualizationSettings } from "metabase/visualizations/types";
+import { TYPE } from "metabase-lib/v1/types/constants";
+import {
+ isAvatarURL,
+ isBoolean,
+ isCurrency,
+ isEmail,
+ isEntityName,
+ isFK,
+ isFloat,
+ isImageURL,
+ isNumber,
+ isPK,
+ isPercentage,
+ isProduct,
+ isQuantity,
+ isScore,
+ isSource,
+ isState,
+ isTitle,
+ isURL,
+} from "metabase-lib/v1/types/utils/isa";
+import type {
+ ColumnSettings,
+ DatasetColumn,
+ RowValues,
+} from "metabase-types/api";
import styles from "./ListView.module.css";
-
-// Light background colors for category values
-const CATEGORY_COLORS = [
- "color-mix(in srgb, var(--mb-color-brand) 8%, var(--mb-color-background))",
- "color-mix(in srgb, var(--mb-color-success) 8%, var(--mb-color-background))",
- "color-mix(in srgb, var(--mb-color-warning) 8%, var(--mb-color-background))",
- "color-mix(in srgb, var(--mb-color-error) 8%, var(--mb-color-background))",
- "color-mix(in srgb, var(--mb-color-filter) 8%, var(--mb-color-background))",
- "color-mix(in srgb, var(--mb-color-summarize) 8%, var(--mb-color-background))",
- "color-mix(in srgb, var(--mb-color-focus) 8%, var(--mb-color-background))",
- "color-mix(in srgb, var(--mb-color-text-medium) 8%, var(--mb-color-background))",
-];
-
-// Get a consistent color for a category value based on its hash
-const getCategoryColor = (value: any, columnName: string) => {
- if (value == null || value === "") {
- return "var(--mb-color-background-light)";
- }
-
- const stringValue = String(value);
-
- // Use a combination of column name and value for more consistent colors
- const combinedString = `${columnName}:${stringValue}`;
- const hash = combinedString.split("").reduce((a, b) => {
- a = (a << 5) - a + b.charCodeAt(0);
- return a & a;
- }, 0);
-
- const colorIndex = Math.abs(hash) % CATEGORY_COLORS.length;
- return CATEGORY_COLORS[colorIndex];
-};
+import { getCategoryColor } from "./styling";
interface ColumnValueProps {
column: DatasetColumn;
- value: ReactNode;
+ settings: ComputedVisualizationSettings;
rawValue: any;
+ style?: React.CSSProperties;
+ rows: RowValues;
+ cols: DatasetColumn[];
}
-export function ColumnValue({ column, value, rawValue }: ColumnValueProps) {
- const isBooleanColumn = column.base_type === "type/Boolean";
- const isCategoryColumn = column.semantic_type === "type/Category";
- const isScoreColumn = column.semantic_type === "type/Score";
- const shouldGetCategoryStyling = isCategoryColumn || isScoreColumn;
+const DEFAULT_COLUMN_SETTINGS: ColumnSettings = {};
+export function ColumnValue({
+ column,
+ settings,
+ rawValue,
+ style,
+ rows,
+ cols,
+}: ColumnValueProps) {
+ const columnSettings = useMemo(
+ () => settings.column?.(column),
+ [column, settings],
+ );
+ const value = useMemo(
+ () =>
+ formatValue(rawValue, {
+ ...(columnSettings || DEFAULT_COLUMN_SETTINGS),
+ jsx: true,
+ rich: true,
+ }),
+ [rawValue, columnSettings],
+ );
+ const columnExtent = useMemo(() => {
+ if (isQuantity(column) || isScore(column)) {
+ return getColumnExtent(cols, rows, cols.indexOf(column));
+ }
+ return null;
+ }, [cols, rows, column]);
+
+ // Need to return empty element here to preserve grid column layout in ListViewItem.
+ if (rawValue == null) {
+ return <div />;
+ }
- if (isBooleanColumn) {
+ if (isBoolean(column)) {
return (
- <Flex align="center" gap="xs">
- <Box
- w={8}
- h={8}
+ <Badge
+ className={styles.badge}
+ size="lg"
+ c="text-primary"
+ variant="outline"
+ style={{
+ background: "var(--mb-color-bg-white)",
+ textTransform: "capitalize",
+ }}
+ leftSection={
+ <Icon
+ name={rawValue === true ? "check" : "close"}
+ size={12}
+ mr="xs"
+ />
+ }
+ >
+ {value}
+ </Badge>
+ );
+ }
+
+ // switch (column.semantic_type) {
+ switch (true) {
+ case isPK(column):
+ case isFK(column):
+ if (!column.remapped_to_column) {
+ return (
+ <Badge
+ className={styles.badge}
+ size="lg"
+ variant="outline"
+ fw={400}
+ leftSection={<Icon name="label" size={16} />}
+ >
+ {value}
+ </Badge>
+ );
+ }
+ break;
+ // Not using `isCategory` because it incorrectly gives false positive
+ // for many other category subtypes, like Name / Title / City (which we dont' want here).
+ case column.semantic_type === TYPE.Category:
+ return (
+ <Badge
+ className={styles.badge}
+ size="lg"
+ variant="outline"
style={{
- borderRadius: "50%",
- backgroundColor:
- rawValue === true
- ? "var(--mb-color-success)"
- : "var(--mb-color-error)",
- flexShrink: 0,
+ background: "var(--mb-color-bg-white)",
+ color: "var(--mb-color-text-primary)",
}}
- />
- <Text fw="bold" size="sm" c="text-secondary">
+ leftSection={
+ <Stack mr="0.25rem">
+ <Box
+ style={{
+ borderRadius: "50%",
+ width: "0.5rem",
+ height: "0.5rem",
+ backgroundColor: getCategoryColor(rawValue, column.name),
+ }}
+ />
+ </Stack>
+ }
+ >
{value}
- </Text>
- </Flex>
- );
- }
+ </Badge>
+ );
+ case isState(column):
+ return (
+ <Badge
+ className={styles.badge}
+ size="lg"
+ variant="outline"
+ style={{
+ background: "var(--mb-color-bg-white)",
+ }}
+ >
+ {value}
+ </Badge>
+ );
+ case isEntityName(column):
+ case isTitle(column):
+ case isProduct(column):
+ case isSource(column):
+ return (
+ <Ellipsified
+ size="sm"
+ truncate
+ fw="bold"
+ style={style}
+ c={style?.color || "text-primary"}
+ >
+ {value}
+ </Ellipsified>
+ );
+ case isEmail(column):
+ case isURL(column) && !isImageURL(column) && !isAvatarURL(column):
+ return (
+ <Ellipsified size="sm" fw="bold" style={style} tooltip={rawValue}>
+ {value}
+ </Ellipsified>
+ );
+ case isQuantity(column):
+ case isScore(column): {
+ return (
+ <Flex direction="row" align="center" gap="sm">
+ <MiniBarCell
+ rowIndex={0}
+ columnId={column.name}
+ value={Number(rawValue)}
+ barWidth="4rem"
+ barHeight="0.25rem"
+ extent={columnExtent}
+ columnSettings={columnSettings || DEFAULT_COLUMN_SETTINGS}
+ style={{
+ paddingInline: 0,
+ marginLeft: 0,
+ width: "auto",
+ border: "none",
+ }}
+ />
+ <Text fw="bold">{value}</Text>
+ </Flex>
+ );
+ }
+ case isPercentage(column): {
+ return (
+ <Badge
+ size="lg"
+ className={styles.badge}
+ variant="outline"
+ style={{
+ background: "var(--mb-color-bg-white)",
+ }}
+ >
+ <Text fw="bold">
+ {String(value).slice(0, -1)}
+ <span
+ style={{
+ color: "var(--mb-color-text-tertiary)",
+ paddingLeft: "0.25rem",
+ }}
+ >
+ %
+ </span>
+ </Text>
+ </Badge>
+ );
+ }
+ case isCurrency(column): {
+ const options = settings.column?.(column) || {};
+ const formattedValue = formatNumber(Number(rawValue), options);
- if (shouldGetCategoryStyling && rawValue != null && rawValue !== "") {
- return (
- <Box
- className={styles.categoryValue}
- style={{ backgroundColor: getCategoryColor(rawValue, column.name) }}
- >
- <Ellipsified fw="bold" size="sm" c="text-secondary">
+ if (
+ options.currency_style === "symbol" &&
+ typeof options.currency === "string"
+ ) {
+ const currencySymbol = getCurrencySymbol(options?.currency);
+ const currencyValue = formattedValue.replace(currencySymbol, "");
+
+ return (
+ <Text fw="bold">
+ <span
+ style={{
+ color: "var(--mb-color-text-tertiary)",
+ fontWeight: "normal",
+ paddingRight: "0.25rem",
+ }}
+ >
+ {currencySymbol}
+ </span>
+ {currencyValue}
+ </Text>
+ );
+ }
+
+ return <Text fw="bold">{formattedValue}</Text>;
+ }
+ case isImageURL(column):
+ case isAvatarURL(column):
+ return (
+ <Image
+ src={rawValue}
+ w="2rem"
+ h="2rem"
+ style={{
+ objectFit: "cover",
+ borderRadius: "0.5rem",
+ border: "1px solid var(--mb-color-border-secondary)",
+ }}
+ />
+ );
+ case isFloat(column):
+ case isNumber(column):
+ return (
+ <Ellipsified
+ size="sm"
+ truncate
+ style={style}
+ fw="bold"
+ c="text-primary"
+ >
{value}
</Ellipsified>
- </Box>
- );
+ );
+
+ default:
+ break;
}
return (
- <Ellipsified fw="bold" size="sm" c="text-secondary" truncate>
+ <Ellipsified
+ size="sm"
+ truncate
+ style={style}
+ c={style?.color || "text-primary"}
+ >
{value}
</Ellipsified>
);
diff --git a/frontend/src/metabase/list-view/components/ListView/ListView.module.css b/frontend/src/metabase/list-view/components/ListView/ListView.module.css
index 53fa5e36245..ed32fd8d1ad 100644
--- a/frontend/src/metabase/list-view/components/ListView/ListView.module.css
+++ b/frontend/src/metabase/list-view/components/ListView/ListView.module.css
@@ -1,12 +1,6 @@
.listViewContainer {
- --max-width: 75rem;
-
- background: var(--mb-color-background-light);
width: 100%;
height: 100%;
- gap: var(--mantine-spacing-xs);
- padding-top: var(--mantine-spacing-xl);
- padding-inline: var(--mantine-spacing-sm);
}
.listContainer {
@@ -17,41 +11,38 @@
.listHeader {
width: 100%;
- max-width: var(--max-width);
- margin: 0 auto;
+ padding-block: 0.75rem;
padding-inline: var(--item-padding);
+ border-bottom: 1px solid var(--mb-color-border-secondary);
}
.listBody {
position: relative;
- max-width: var(--max-width);
width: 100%;
height: 100%;
margin: auto;
- gap: var(--mantine-spacing-lg);
- padding-inline: calc(50% - var(--max-width) / 2);
+ gap: 0;
overflow: auto;
}
-@media (max-width: 80rem) {
- .listHeader,
- .listBody {
- padding-inline: var(--mantine-spacing-lg);
- }
-}
-
.listItem {
width: 100%;
- max-width: 75rem;
- border: 1px solid var(--mb-color-border);
- border-radius: var(--mantine-radius-md);
+ height: 4rem;
+ border-bottom: 1px solid var(--mb-color-border-subtle);
background: var(--mb-color-bg-white);
- padding: var(--mantine-spacing-md)
- var(--item-padding, var(--mantine-spacing-md));
+ padding-inline: var(--item-padding, var(--mantine-spacing-md));
&:hover {
background-color: var(--mb-color-brand-lighter);
}
+
+ /* Columns rendering */
+ .badge {
+ cursor: inherit;
+ padding-inline: var(--mantine-spacing-sm);
+ color: var(--mb-color-text-secondary);
+ border-color: var(--mb-color-border-secondary);
+ }
}
.listItemVirtualized {
@@ -63,9 +54,13 @@
.listHeader,
.listItem {
display: grid;
- grid-template-columns: 32px minmax(0, 1fr) repeat(var(--grid-columns), 12%);
+ grid-template-columns: minmax(0, 1fr) repeat(var(--grid-columns), 14%);
gap: var(--mantine-spacing-md);
align-items: center;
+
+ &.withIcon {
+ grid-template-columns: 32px minmax(0, 1fr) repeat(var(--grid-columns), 14%);
+ }
}
.categoryValue {
@@ -81,14 +76,13 @@
.listViewConfigurationInputs {
display: grid;
- grid-template-columns: 32px minmax(calc(30% - 32px - 1rem), 1fr) calc(
- 70% - 1rem
+ grid-template-columns: 3rem minmax(calc(30% - 3rem - 0.75rem), 1fr) calc(
+ 70% - 0.75rem
);
- gap: var(--mantine-spacing-md);
+ gap: var(--mantine-spacing-sm);
align-items: start;
border: 1px solid var(--mb-color-border);
border-radius: var(--mantine-radius-md);
- max-width: var(--max-width);
background: var(--mb-color-bg-white);
padding: var(--mantine-spacing-md);
}
@@ -100,3 +94,42 @@
color: var(--mb-color-brand);
}
}
+
+.iconMenuButtonContainer {
+ width: 3rem;
+ height: 3rem;
+ background: var(--mb-color-background-hover-light);
+ justify-content: center;
+ align-items: center;
+ border: 1px dashed var(--mb-color-saturated-blue);
+ border-radius: 50%;
+ overflow: hidden;
+ padding: 0.5rem;
+}
+
+.iconMenuButton {
+ width: 100%;
+ height: 100%;
+ display: flex;
+ padding: 0;
+ border-radius: 50%;
+ border: 1px solid var(--mb-color-border);
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+}
+
+.iconColorButton {
+ width: 1rem;
+ height: 1rem;
+ border-radius: 50%;
+}
+
+.imageColumn {
+ outline: 1px solid var(--mb-color-border);
+}
+
+.selected {
+ outline-offset: 0.125rem;
+ outline: 1px solid var(--mb-color-brand);
+}
diff --git a/frontend/src/metabase/list-view/components/ListView/ListView.tsx b/frontend/src/metabase/list-view/components/ListView/ListView.tsx
index 6db9ab49d4e..1c3848aafa9 100644
--- a/frontend/src/metabase/list-view/components/ListView/ListView.tsx
+++ b/frontend/src/metabase/list-view/components/ListView/ListView.tsx
@@ -1,7 +1,6 @@
import { useVirtualizer } from "@tanstack/react-virtual";
import cx from "classnames";
import { type CSSProperties, useMemo, useRef } from "react";
-import { t } from "ttag";
import { Icon, Stack, Text } from "metabase/ui";
import { useObjectDetail } from "metabase/visualizations/components/TableInteractive/hooks/use-object-detail";
@@ -15,6 +14,7 @@ import type {
import styles from "./ListView.module.css";
import { ListViewItem } from "./ListViewItem";
+import { getEntityIcon } from "./styling";
export interface ListViewProps {
data: DatasetData;
@@ -43,19 +43,24 @@ export function ListView({
const virtualizer = useVirtualizer({
count: rows.length,
getScrollElement: () => scrollRef.current,
- estimateSize: () => 80,
+ estimateSize: () => 64,
overscan: 10,
});
const virtualRows = virtualizer.getVirtualItems();
- const { titleColumn, subtitleColumn, imageColumn, rightColumns } =
- useListColumns(cols, settings?.["list.columns"]);
+ const { titleColumn, imageColumn, rightColumns } = useListColumns(
+ cols,
+ settings?.["list.columns"],
+ );
const openObjectDetail = useObjectDetail(data);
// Get the appropriate icon based on entity type
const entityIcon =
settings?.["list.entity_icon"] || getEntityIcon(entityType);
+ const entityIconColor = settings?.["list.entity_icon_color"];
+ const entityIconEnabled = settings?.["list.entity_icon_enabled"];
+ const useImageColumn = settings?.["list.use_image_column"];
return (
<Stack
@@ -63,17 +68,20 @@ export function ListView({
className={cx(styles.listViewContainer, className)}
style={{ "--grid-columns": Math.max(rightColumns.length, 1) }}
>
- <Stack className={styles.listContainer}>
- <div className={styles.listHeader}>
+ <Stack gap={0} className={styles.listContainer}>
+ <div
+ className={cx(styles.listHeader, {
+ [styles.withIcon]: !!entityIconEnabled,
+ })}
+ >
{/* Entity Type Icon Column Placeholder */}
- <div style={{ width: 32, flexShrink: 0 }} />
+ {entityIconEnabled && <div style={{ width: 32, flexShrink: 0 }} />}
{/* Title and Subtitle Column */}
<div>
{!!titleColumn && (
<ColumnHeader
column={titleColumn}
- subtitleColumn={subtitleColumn}
sortedColumnName={sortedColumnName}
sortingDirection={sortingDirection}
onSortClick={onSortClick}
@@ -117,12 +125,17 @@ export function ListView({
<ListViewItem
key={key}
row={row}
+ rows={rows}
cols={cols}
settings={settings}
- entityIcon={entityIcon}
- imageColumn={imageColumn}
+ entityIcon={entityIconEnabled ? entityIcon : undefined}
+ entityIconColor={entityIconColor}
+ imageColumn={
+ entityIconEnabled && useImageColumn
+ ? imageColumn
+ : undefined
+ }
titleColumn={titleColumn}
- subtitleColumn={subtitleColumn}
rightColumns={rightColumns}
onClick={() => isInteractive && openObjectDetail(index)}
className={styles.listItemVirtualized}
@@ -143,7 +156,6 @@ export function ListView({
interface ColumnHeaderProps {
column: DatasetColumn;
- subtitleColumn?: DatasetColumn | null;
sortedColumnName?: string;
sortingDirection?: "asc" | "desc";
onSortClick: (column: DatasetColumn) => void;
@@ -152,7 +164,6 @@ interface ColumnHeaderProps {
function ColumnHeader({
column,
- subtitleColumn,
sortedColumnName,
sortingDirection,
style,
@@ -169,15 +180,14 @@ function ColumnHeader({
alignItems: "center",
}}
>
- <Text fw="bold" size="sm" c="text-medium" style={{ display: "inline" }}>
+ <Text fz="0.875rem" c="text-medium" style={{ display: "inline" }}>
{column.display_name}
- {subtitleColumn && " " + t`and` + " " + subtitleColumn.display_name}
</Text>
{sortedColumnName === column.name && (
<Icon
name={sortingDirection === "asc" ? "arrow_up" : "arrow_down"}
c="text-medium"
- size={12}
+ size={14}
style={{ display: "inline", marginLeft: 4 }}
/>
)}
@@ -191,7 +201,6 @@ export function useListColumns(
) {
// Column role is based on it's position in the list:
// - First column is title
- // - Second column is subtitle
// - Next 0-5 columns are right columns
const titleColumn = useMemo(() => {
return !listSettings
@@ -199,12 +208,6 @@ export function useListColumns(
: cols.find((col) => listSettings?.left[0] === col.name);
}, [cols, listSettings]);
- const subtitleColumn = useMemo(() => {
- return !listSettings || listSettings.left.length < 2
- ? null
- : cols.find((col) => listSettings?.left[1] === col.name);
- }, [cols, listSettings]);
-
const imageColumn = useMemo(() => {
return cols.find(
(col) =>
@@ -223,24 +226,7 @@ export function useListColumns(
return {
titleColumn,
- subtitleColumn,
imageColumn,
rightColumns,
};
}
-
-export const ENTITY_ICONS = {
- "entity/UserTable": "person",
- "entity/CompanyTable": "company",
- "entity/TransactionTable": "receipt",
- "entity/SubscriptionTable": "sync",
- "entity/ProductTable": "label",
- "entity/EventTable": "calendar",
- "entity/GenericTable": "document",
-} as const;
-
-export const getEntityIcon = (entityType?: string) => {
- return entityType
- ? ENTITY_ICONS[entityType as keyof typeof ENTITY_ICONS] || "document"
- : "document";
-};
diff --git a/frontend/src/metabase/list-view/components/ListView/ListViewConfiguration.tsx b/frontend/src/metabase/list-view/components/ListView/ListViewConfiguration.tsx
index 94a8259e2aa..0ef7e80d147 100644
--- a/frontend/src/metabase/list-view/components/ListView/ListViewConfiguration.tsx
+++ b/frontend/src/metabase/list-view/components/ListView/ListViewConfiguration.tsx
@@ -1,18 +1,16 @@
import {
DndContext,
- type DragEndEvent,
- type DragOverEvent,
DragOverlay,
- type DragStartEvent,
PointerSensor,
closestCenter,
useSensor,
useSensors,
} from "@dnd-kit/core";
import { snapCenterToCursor } from "@dnd-kit/modifiers";
-import { arrayMove } from "@dnd-kit/sortable";
+import cx from "classnames";
import { useEffect, useMemo, useState } from "react";
import { t } from "ttag";
+import { defaults } from "underscore";
import {
ReorderableTagsInput,
@@ -22,54 +20,60 @@ import { getColumnExample } from "metabase/query_builder/components/expressions/
import {
ActionIcon,
Box,
+ Button,
Divider,
+ Flex,
Icon,
type IconName,
+ Image,
Menu,
+ SimpleGrid,
Stack,
+ Switch,
Text,
} from "metabase/ui";
import type { ComputedVisualizationSettings } from "metabase/visualizations/types";
import type * as Lib from "metabase-lib";
import type { DatasetColumn, DatasetData, RowValues } from "metabase-types/api";
-import { ENTITY_ICONS, getEntityIcon, useListColumns } from "./ListView";
+import { useListColumns } from "./ListView";
import S from "./ListView.module.css";
import { ListViewItem } from "./ListViewItem";
-
-const formatEntityIconName = (key: string): string => {
- return key
- .replace("entity/", "")
- .replace("Table", "")
- .replace(/([A-Z])/g, " $1")
- .trim();
-};
-
-const MAX_LEFT_COLUMNS = 2;
+import {
+ ENTITY_ICONS,
+ ENTITY_ICON_COLORS,
+ getEntityIcon,
+ getIconBackground,
+} from "./styling";
+import { useExternalDragOverlay } from "./use-external-drag-overlay";
+
+const MAX_LEFT_COLUMNS = 1;
const MAX_RIGHT_COLUMNS = 5;
-type ContainerId = "left" | "right";
export const ListViewConfiguration = ({
data,
- entityType,
onChange,
settings,
columnsMetadata,
+ entityType,
}: {
data: DatasetData;
- entityType?: string;
onChange: (settings: {
left: string[];
right: string[];
- entityIcon?: string;
+ entityIcon?: IconName | null;
+ entityIconColor?: string;
+ entityIconEnabled?: boolean;
+ useImageColumn?: boolean;
}) => void;
settings?: ComputedVisualizationSettings;
columnsMetadata: Lib.ColumnMetadata[];
+ entityType?: string;
}) => {
- const { cols } = data;
+ const { cols, rows } = data;
// Use the same default inference as the list view
- const { titleColumn, subtitleColumn, rightColumns } = useListColumns(
+ const { imageColumn, titleColumn, rightColumns } = useListColumns(
cols,
settings?.["list.columns"],
);
@@ -77,40 +81,40 @@ export const ListViewConfiguration = ({
// Selected values
const [leftValues, setLeftValues] = useState(() => [
...(titleColumn ? [titleColumn.name] : []),
- ...(subtitleColumn ? [subtitleColumn.name] : []),
]);
useEffect(() => {
- setLeftValues([
- ...(titleColumn ? [titleColumn.name] : []),
- ...(subtitleColumn ? [subtitleColumn.name] : []),
- ]);
- }, [titleColumn, subtitleColumn]);
- const [rightValues, setRightValues] = useState(
- () => rightColumns.map((col) => col?.name).filter(Boolean) as string[],
+ setLeftValues([...(titleColumn ? [titleColumn.name] : [])]);
+ }, [titleColumn]);
+ const [rightValues, setRightValues] = useState(() =>
+ rightColumns.map((col) => col?.name).filter(Boolean),
);
useEffect(() => {
- setRightValues(
- rightColumns.map((col) => col?.name).filter(Boolean) as string[],
- );
+ setRightValues(rightColumns.map((col) => col?.name).filter(Boolean));
}, [rightColumns]);
- // Selected icon state
- const [selectedEntityIcon, setSelectedEntityIcon] = useState<string>(
- () => settings?.["list.entity_icon"] || getEntityIcon(entityType),
- );
-
- // Active drag state for overlay
- const [activeId, setActiveId] = useState<string | null>(null);
- const [currentDroppable, setCurrentDroppable] = useState<string | null>(null);
+ // Local state duplication for selected settings to immediately reflect
+ // list item preview changes.
+
+ const [iconConfig, setIconConfig] = useState<{
+ selectedEntityIcon: IconName | null;
+ selectedIconColor?: string;
+ entityIconEnabled: boolean;
+ useImageColumn: boolean;
+ }>(() => ({
+ selectedEntityIcon: settings?.["list.use_image_column"]
+ ? null
+ : settings?.["list.entity_icon"] || getEntityIcon(entityType),
+ selectedIconColor: settings?.["list.entity_icon_color"],
+ entityIconEnabled: settings?.["list.entity_icon_enabled"] ?? false,
+ useImageColumn: settings?.["list.use_image_column"] ?? false,
+ }));
- // All options from cols
+ // Exclude options already used by any of the two selects, but keep the ones
+ // selected in the respective select so tags render properly
const allOptions = cols.map((col) => ({
value: col.name,
label: col.display_name,
}));
-
- // Exclude options already used by any of the two selects, but keep the ones
- // selected in the respective select so tags render properly
const used = new Set([...leftValues, ...rightValues]);
const leftOptions = allOptions.filter(
(opt) => !used.has(opt.value) || leftValues.includes(opt.value),
@@ -119,149 +123,87 @@ export const ListViewConfiguration = ({
(opt) => !used.has(opt.value) || rightValues.includes(opt.value),
);
+ const previewSample = useMemo(
+ () => generatePreviewSample(data.rows, columnsMetadata),
+ [data.rows, columnsMetadata],
+ );
+
const findColByName = (name?: string): DatasetColumn | undefined =>
cols.find((c) => c.name === name);
-
const selectedTitleColumn = findColByName(leftValues[0]);
- const selectedSubtitleColumn = findColByName(leftValues[1]) ?? null;
const selectedRightColumns = rightValues
.slice(0, 5)
.map(findColByName)
- .filter(Boolean) as DatasetColumn[];
+ .filter((col) => !!col);
- const previewSample = useMemo(
- () => generatePreviewSample(data.rows, columnsMetadata),
- [data.rows, columnsMetadata],
+ const sensors = useSensors(
+ useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
);
- const onConfigurationChange = ({
+ const handleConfigurationChange = ({
left = leftValues,
right = rightValues,
entityIcon,
+ entityIconColor,
+ entityIconEnabled,
+ useImageColumn,
}: {
- left: string[];
- right: string[];
- entityIcon?: string;
+ left?: string[];
+ right?: string[];
+ entityIcon?: IconName | null;
+ entityIconColor?: string;
+ entityIconEnabled?: boolean;
+ useImageColumn?: boolean;
}) => {
- setLeftValues(left);
- setRightValues(right);
- onChange({ left, right, entityIcon });
- };
-
- const sensors = useSensors(
- useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
- );
-
- const handleDragStart = (event: DragStartEvent) => {
- setActiveId(event.active.id as string);
- };
-
- const handleDragOver = (event: DragOverEvent) => {
- const { over } = event;
- const containerId = over?.data?.current?.containerId;
- if (!containerId) {
- return;
- }
- // Storing the id of container under dragged element
- // to hide it in original container when dragging between the two.
- setCurrentDroppable(containerId);
- };
-
- const handleDragEnd = (event: DragEndEvent) => {
- setActiveId(null);
- setCurrentDroppable(null);
- const { active, over } = event;
-
- if (!over) {
- return;
- }
-
- const activeId = String(active.id);
- const from = active.data?.current?.containerId as ContainerId | undefined;
-
- if (!from) {
- return;
- }
-
- // Determine target container - could be from over item's containerId or over.id itself
- let to: ContainerId | undefined;
- let overIndexInTo = -1;
-
- // Check if we're dropping on an item (has containerId)
- if (over.data?.current?.containerId) {
- to = over.data.current.containerId as ContainerId;
- const toList = to === "left" ? leftValues : rightValues;
- overIndexInTo = toList.indexOf(String(over.id));
- }
- // Check if we're dropping on a container itself (droppable area)
- else if (over.id === "left" || over.id === "right") {
- to = over.id as ContainerId;
- overIndexInTo = -1; // Append to end when dropping on container
- }
-
- if (!to) {
- return;
- }
-
- const fromList = from === "left" ? leftValues : rightValues;
-
- const fromIndex = fromList.indexOf(activeId);
- if (fromIndex === -1) {
- return;
- }
-
- // Same container: reorder
- if (from === to) {
- if (overIndexInTo === -1 || fromIndex === overIndexInTo) {
- return;
- }
- const next = arrayMove(fromList, fromIndex, overIndexInTo);
- if (from === "left") {
- onConfigurationChange({
- left: next,
- right: rightValues,
- entityIcon: selectedEntityIcon,
- });
- } else {
- onConfigurationChange({
- left: leftValues,
- right: next,
- entityIcon: selectedEntityIcon,
- });
- }
- return;
+ if (left !== undefined) {
+ setLeftValues(left);
}
-
- // Moving items between containers
- const maxForTo = to === "left" ? MAX_LEFT_COLUMNS : MAX_RIGHT_COLUMNS;
- const toCurrent = to === "left" ? leftValues : rightValues;
- if (toCurrent.length >= maxForTo) {
- return;
+ if (right !== undefined) {
+ setRightValues(right);
}
- const nextFrom = fromList.slice() as string[];
- nextFrom.splice(fromIndex, 1);
-
- const nextTo = toCurrent.slice() as string[];
- const insertIndex = overIndexInTo === -1 ? nextTo.length : overIndexInTo;
- nextTo.splice(insertIndex, 0, activeId);
-
- if (to === "left") {
- onConfigurationChange({
- left: nextTo,
- right: nextFrom,
- entityIcon: selectedEntityIcon,
- });
- } else {
- onConfigurationChange({
- left: nextFrom,
- right: nextTo,
- entityIcon: selectedEntityIcon,
- });
+ const hasIconConfigChange =
+ entityIcon !== undefined ||
+ entityIconColor !== undefined ||
+ entityIconEnabled !== undefined ||
+ useImageColumn !== undefined;
+ if (hasIconConfigChange) {
+ setIconConfig((prev) =>
+ defaults(
+ {
+ selectedEntityIcon: entityIcon,
+ selectedIconColor: entityIconColor,
+ entityIconEnabled,
+ useImageColumn,
+ },
+ prev,
+ ),
+ );
}
+ onChange({
+ left,
+ right,
+ entityIcon,
+ entityIconColor,
+ entityIconEnabled,
+ useImageColumn,
+ });
};
- // Get the active item data for the overlay
+ const {
+ activeId,
+ currentDroppable,
+ handleDragStart,
+ handleDragOver,
+ handleDragEnd,
+ } = useExternalDragOverlay({
+ leftValues,
+ rightValues,
+ maxLeftColumns: MAX_LEFT_COLUMNS,
+ maxRightColumns: MAX_RIGHT_COLUMNS,
+ onConfigurationChange: handleConfigurationChange,
+ });
+
const activeItem = activeId
? {
id: activeId,
@@ -285,84 +227,199 @@ export const ListViewConfiguration = ({
className={S.listViewContainer}
style={{ "--grid-columns": Math.max(rightValues.length, 1) }}
>
- <Stack justify="center" flex={1} maw="var(--max-width)" w="100%">
+ <Stack justify="center" flex={1} w="100%">
<Text fw="bold">{t`Customize List columns`}</Text>
<Box className={S.listViewConfigurationInputs}>
{/* Icon selector */}
<Menu shadow="md" width={200}>
<Menu.Target>
- <ActionIcon
- data-testid="list-view-icon"
- variant="subtle"
- p={0}
- w={32}
- h={32}
- style={{
- border: "1px dashed var(--mb-color-border)",
- marginTop: "0.25rem",
- borderRadius: "50%",
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- flexShrink: 0,
- backgroundColor: "var(--mb-color-background-light)",
- }}
- >
- <Icon
- tooltip="Entity icon"
- name={selectedEntityIcon as IconName}
- size={16}
- className={S.listEntityIcon}
- />
- </ActionIcon>
+ <Flex className={S.iconMenuButtonContainer}>
+ <ActionIcon
+ data-testid="list-view-icon"
+ variant="subtle"
+ className={S.iconMenuButton}
+ style={{
+ backgroundColor: iconConfig.entityIconEnabled
+ ? getIconBackground(iconConfig.selectedIconColor)
+ : "var(--mb-color-white)",
+ }}
+ >
+ {iconConfig.useImageColumn &&
+ iconConfig.entityIconEnabled &&
+ imageColumn ? (
+ <Image
+ src={previewSample[cols.indexOf(imageColumn)]}
+ alt=""
+ w={32}
+ h={32}
+ radius="xl"
+ style={{ flexShrink: 0 }}
+ />
+ ) : (
+ <Icon
+ tooltip="Entity icon"
+ name={
+ iconConfig.entityIconEnabled &&
+ iconConfig.selectedEntityIcon
+ ? iconConfig.selectedEntityIcon
+ : "ban"
+ }
+ size="1rem"
+ className={S.listEntityIcon}
+ c={
+ iconConfig.entityIconEnabled
+ ? iconConfig.selectedIconColor
+ : "text-light"
+ }
+ />
+ )}
+ </ActionIcon>
+ </Flex>
</Menu.Target>
- <Menu.Dropdown>
- {Object.entries(ENTITY_ICONS).map(([key, iconName]) => (
- <Menu.Item
- key={key}
- leftSection={<Icon name={iconName} size={16} />}
+ <Menu.Dropdown
+ p={0}
+ w="16rem"
+ style={{ borderRadius: "var(--mantine-radius-lg)" }}
+ >
+ <Box p="md">
+ <Switch
+ label={t`Show image`}
+ size="sm"
+ labelPosition="left"
+ w="100%"
+ styles={{
+ labelWrapper: { marginRight: "auto" },
+ }}
+ checked={iconConfig.entityIconEnabled}
+ onChange={(e) => {
+ handleConfigurationChange({
+ left: leftValues,
+ right: rightValues,
+ entityIconEnabled: e.currentTarget.checked,
+ });
+ }}
+ />
+ </Box>
+ <Menu.Divider m={0} />
+ <SimpleGrid cols={5} p="md">
+ <ActionIcon
+ radius="lg"
+ p="md"
+ w="2rem"
+ h="2rem"
+ disabled={!imageColumn}
+ className={cx({
+ [S.imageColumn]: !!imageColumn,
+ [S.selected]:
+ iconConfig.useImageColumn &&
+ iconConfig.entityIconEnabled,
+ })}
onClick={() => {
- setSelectedEntityIcon(iconName);
- onConfigurationChange({
+ handleConfigurationChange({
left: leftValues,
right: rightValues,
- entityIcon: iconName,
+ useImageColumn: true,
+ entityIcon: null,
});
}}
>
- {formatEntityIconName(key)}
- </Menu.Item>
- ))}
+ {imageColumn ? (
+ <Image
+ src={previewSample[cols.indexOf(imageColumn)]}
+ alt=""
+ w={32}
+ h={32}
+ style={{ flexShrink: 0 }}
+ />
+ ) : (
+ <Flex justify="center" align="center">
+ <Icon
+ tooltip={t`Image field not found`}
+ tooltipPosition="right"
+ name="camera"
+ size={16}
+ c="text-primary"
+ />
+ </Flex>
+ )}
+ </ActionIcon>
+ {Object.entries(ENTITY_ICONS).map(([key, iconName]) => (
+ <Flex justify="center" align="center" key={key}>
+ <ActionIcon
+ w="2rem"
+ h="2rem"
+ radius="lg"
+ className={cx({
+ [S.selected]:
+ iconConfig.selectedEntityIcon === iconName &&
+ iconConfig.entityIconEnabled,
+ })}
+ onClick={() => {
+ handleConfigurationChange({
+ left: leftValues,
+ right: rightValues,
+ entityIcon: iconName,
+ useImageColumn: false,
+ });
+ }}
+ >
+ <Icon name={iconName} c="text-primary" />
+ </ActionIcon>
+ </Flex>
+ ))}
+ </SimpleGrid>
+ <Menu.Divider m={0} />
+ <SimpleGrid cols={6} p="md" data-testid="list-view-icon-colors">
+ {ENTITY_ICON_COLORS.map((color: string) => (
+ <Flex justify="center" align="center" key={color}>
+ <Button
+ className={cx(S.iconColorButton, {
+ [S.selected]: color === iconConfig.selectedIconColor,
+ })}
+ variant="subtle"
+ bg={color}
+ onClick={() => {
+ handleConfigurationChange({
+ entityIconColor: color,
+ });
+ }}
+ />
+ </Flex>
+ ))}
+ </SimpleGrid>
</Menu.Dropdown>
</Menu>
- {/* Title + Subtitle */}
+ {/* Title */}
<ReorderableTagsInput
- size="xs"
+ size="lg"
miw="10rem"
maw="33%"
data={leftOptions}
value={leftValues}
onChange={(value) =>
- onConfigurationChange({ left: value, right: rightValues })
+ handleConfigurationChange({ left: value, right: rightValues })
}
maxValues={MAX_LEFT_COLUMNS}
- placeholder={leftValues.length > 0 ? "" : t`Title + Subtitle`}
+ placeholder={leftValues.length > 0 ? "" : t`Title`}
data-testid="list-view-left-columns"
containerId="left"
- useExternalDnd={true}
+ useExternalDnd
draggedItemId={activeId}
currentDroppable={currentDroppable}
+ styles={{
+ input: { paddingBlock: "0.5rem" },
+ }}
/>
{/* Right columns */}
<ReorderableTagsInput
- size="xs"
+ size="lg"
data={rightOptions}
value={rightValues}
onChange={(value) =>
- onConfigurationChange({ left: leftValues, right: value })
+ handleConfigurationChange({ left: leftValues, right: value })
}
maxValues={MAX_RIGHT_COLUMNS}
placeholder={
@@ -370,16 +427,16 @@ export const ListViewConfiguration = ({
}
data-testid="list-view-right-columns"
containerId="right"
- useExternalDnd={true}
+ useExternalDnd
draggedItemId={activeId}
currentDroppable={currentDroppable}
+ styles={{ input: { paddingBlock: "0.5rem" } }}
/>
</Box>
</Stack>
- <Divider w="100%" maw="var(--max-width)" />
+ <Divider w="100%" />
<Stack
w="100%"
- maw="var(--max-width)"
flex={1}
justify="center"
className={S.listContainer}
@@ -387,13 +444,22 @@ export const ListViewConfiguration = ({
>
<Text fw="bold">{t`Preview`}</Text>
<ListViewItem
- row={previewSample}
cols={cols}
+ rows={rows}
+ row={previewSample}
settings={settings as ComputedVisualizationSettings}
- entityIcon={selectedEntityIcon}
- imageColumn={undefined}
+ entityIcon={
+ iconConfig.entityIconEnabled && iconConfig.selectedEntityIcon
+ ? iconConfig.selectedEntityIcon
+ : undefined
+ }
+ entityIconColor={iconConfig.selectedIconColor}
+ imageColumn={
+ iconConfig.entityIconEnabled && iconConfig.useImageColumn
+ ? imageColumn
+ : undefined
+ }
titleColumn={selectedTitleColumn}
- subtitleColumn={selectedSubtitleColumn}
rightColumns={selectedRightColumns}
onClick={() => {}}
style={{ cursor: "default" }}
diff --git a/frontend/src/metabase/list-view/components/ListView/ListViewItem.tsx b/frontend/src/metabase/list-view/components/ListView/ListViewItem.tsx
index c362ca877f2..a7a6fb23301 100644
--- a/frontend/src/metabase/list-view/components/ListView/ListViewItem.tsx
+++ b/frontend/src/metabase/list-view/components/ListView/ListViewItem.tsx
@@ -1,117 +1,109 @@
import cx from "classnames";
import type { CSSProperties } from "react";
-import { formatValue } from "metabase/lib/formatting";
-import { Box, Flex, Icon, type IconName, Image, Text } from "metabase/ui";
+import { Box, Flex, Icon, type IconName, Image } from "metabase/ui";
import type { ComputedVisualizationSettings } from "metabase/visualizations/types";
import type { DatasetColumn, DatasetData } from "metabase-types/api";
import { ColumnValue } from "./ColumnValue";
import styles from "./ListView.module.css";
+import { getIconBackground } from "./styling";
export interface ListViewItemProps {
className?: string;
row: DatasetData["rows"][number];
+ rows: DatasetData["rows"];
cols: DatasetColumn[];
settings: ComputedVisualizationSettings;
- entityIcon: string;
+ entityIcon?: string;
+ entityIconColor?: string;
imageColumn?: DatasetColumn | null;
titleColumn?: DatasetColumn | null;
- subtitleColumn?: DatasetColumn | null;
- rightColumns: DatasetColumn[];
+ rightColumns?: DatasetColumn[];
style?: CSSProperties;
onClick: () => void;
}
export function ListViewItem({
- row,
cols,
+ rows,
+ row,
settings,
entityIcon,
+ entityIconColor,
imageColumn,
titleColumn,
- subtitleColumn,
rightColumns,
style,
className,
onClick,
}: ListViewItemProps) {
+ const imgSrc = (imageColumn && row[cols.indexOf(imageColumn)]) || null;
return (
<Box
- className={cx(styles.listItem, className)}
+ className={cx(styles.listItem, className, {
+ [styles.withIcon]: !!(entityIcon || imageColumn),
+ })}
onClick={onClick}
style={style}
>
- {/* Entity Type Icon */}
- <Box
- w={32}
- h={32}
- style={{
- border: "1px solid var(--mb-color-border)",
- borderRadius: "50%",
- display: "flex",
- alignItems: "center",
- justifyContent: "center",
- flexShrink: 0,
- backgroundColor: "var(--mb-color-background-light)",
- }}
- >
- <Icon name={entityIcon as IconName} size={16} c="text-light" />
- </Box>
+ {entityIcon && !imageColumn && (
+ <Box
+ w={32}
+ h={32}
+ style={{
+ borderRadius: "50%",
+ display: "flex",
+ alignItems: "center",
+ justifyContent: "center",
+ flexShrink: 0,
+ backgroundColor: getIconBackground(entityIconColor),
+ }}
+ >
+ <Icon name={entityIcon as IconName} c={entityIconColor} />
+ </Box>
+ )}
+ {imageColumn && (
+ <Image
+ src={imgSrc}
+ alt=""
+ w={32}
+ h={32}
+ radius="xl"
+ style={{
+ flexShrink: 0,
+ visibility: imgSrc ? "visible" : "hidden",
+ }}
+ />
+ )}
- {/* Title and Subtitle Content */}
- <div>
- <Flex align="center" gap="md" style={{ flexShrink: 0 }}>
- {imageColumn && (
- <Image
- src={row[cols.indexOf(imageColumn)]}
- alt=""
- w={32}
- h={32}
- radius="xl"
- style={{ flexShrink: 0 }}
- />
- )}
- <div style={{ minWidth: 0, flex: 1 }}>
- {titleColumn && (
- <Text
- fw="bold"
- truncate
- style={{ color: "var(--mb-color-brand)" }}
- >
- {formatValue(row[cols.indexOf(titleColumn)], {
- ...(settings.column?.(titleColumn) || {}),
- jsx: true,
- rich: true,
- })}
- </Text>
- )}
- {subtitleColumn && (
- <Text size="sm" c="text-secondary" truncate fw="bold">
- {formatValue(row[cols.indexOf(subtitleColumn)], {
- ...(settings.column?.(subtitleColumn) || {}),
- jsx: true,
- rich: true,
- })}
- </Text>
- )}
- </div>
- </Flex>
- </div>
+ <Flex align="center" gap="md" style={{ flexShrink: 0 }}>
+ {titleColumn && (
+ <ColumnValue
+ rows={rows}
+ cols={cols}
+ column={titleColumn}
+ settings={settings}
+ rawValue={row[cols.indexOf(titleColumn as DatasetColumn)]}
+ style={{
+ fontWeight: "bold",
+ color: "var(--mb-color-text-primary)",
+ }}
+ />
+ )}
+ </Flex>
- {/* Right Columns */}
- {rightColumns.map((col, colIndex) => {
+ {rightColumns?.map((col) => {
const rawValue = row[cols.indexOf(col)];
- const value = formatValue(rawValue, {
- ...(settings.column?.(col) || {}),
- jsx: true,
- rich: true,
- });
-
return (
- <div key={colIndex}>
- <ColumnValue column={col} value={value} rawValue={rawValue} />
- </div>
+ <ColumnValue
+ key={col.name}
+ rows={rows}
+ cols={cols}
+ settings={settings}
+ column={col}
+ rawValue={rawValue}
+ />
);
})}
</Box>
diff --git a/frontend/src/metabase/list-view/components/ListView/ListViewItem.unit.spec.tsx b/frontend/src/metabase/list-view/components/ListView/ListViewItem.unit.spec.tsx
new file mode 100644
index 00000000000..4505ddf9bc3
--- /dev/null
+++ b/frontend/src/metabase/list-view/components/ListView/ListViewItem.unit.spec.tsx
@@ -0,0 +1,219 @@
+import { renderWithProviders, screen } from "__support__/ui";
+import type { ComputedVisualizationSettings } from "metabase/visualizations/types";
+import type { DatasetColumn, DatasetData } from "metabase-types/api";
+import { createMockColumn } from "metabase-types/api/mocks/dataset";
+
+import { ListViewItem } from "./ListViewItem";
+
+function makeSettings(overrides: Partial<ComputedVisualizationSettings> = {}) {
+ const base: ComputedVisualizationSettings = {
+ column: () => ({}),
+ };
+ return { ...base, ...overrides } as ComputedVisualizationSettings;
+}
+
+function renderItem({
+ row,
+ rows,
+ cols,
+ settings,
+ titleColumn = null,
+ rightColumns = [],
+}: {
+ row: DatasetData["rows"][number];
+ rows: DatasetData["rows"];
+ cols: DatasetColumn[];
+ settings: ComputedVisualizationSettings;
+ titleColumn?: DatasetColumn | null;
+ rightColumns?: DatasetColumn[];
+}) {
+ renderWithProviders(
+ <ListViewItem
+ className="test-item"
+ row={row}
+ rows={rows}
+ cols={cols}
+ settings={settings}
+ titleColumn={titleColumn}
+ rightColumns={rightColumns}
+ onClick={jest.fn()}
+ />,
+ );
+}
+
+describe("ListViewItem - ColumnValue rendering", () => {
+ it("renders title using Name semantic type", () => {
+ const nameCol = createMockColumn({
+ name: "name",
+ display_name: "Name",
+ semantic_type: "type/Name",
+ base_type: "type/Text",
+ });
+ const cols = [nameCol];
+ const row = ["Alice"];
+ const rows = [row];
+ const settings = makeSettings();
+
+ renderItem({ row, rows, cols, settings, titleColumn: nameCol });
+
+ expect(screen.getByText("Alice")).toBeInTheDocument();
+ });
+
+ it("renders boolean as a badge with text and proper icons for true/false", () => {
+ const boolColTrue = createMockColumn({
+ name: "active",
+ display_name: "Active",
+ base_type: "type/Boolean",
+ });
+ const boolColFalse = createMockColumn({
+ name: "inactive",
+ display_name: "Inactive",
+ base_type: "type/Boolean",
+ });
+ const cols = [boolColTrue, boolColFalse];
+ const row = [true, false];
+ const rows = [row];
+
+ renderItem({
+ row,
+ rows,
+ cols,
+ settings: makeSettings(),
+ rightColumns: [boolColTrue, boolColFalse],
+ });
+
+ // Text values
+ expect(screen.getByText("true")).toBeInTheDocument();
+ expect(screen.getByText("false")).toBeInTheDocument();
+
+ // Icons from ColumnValue for booleans
+ expect(
+ screen.getByRole("img", { name: /check icon/i }),
+ ).toBeInTheDocument();
+ expect(
+ screen.getByRole("img", { name: /close icon/i }),
+ ).toBeInTheDocument();
+ });
+
+ it("renders category as a badge with label", () => {
+ const catCol = createMockColumn({
+ name: "status",
+ display_name: "Status",
+ semantic_type: "type/Category",
+ base_type: "type/Text",
+ });
+ const cols = [catCol];
+ const row = ["Open"];
+ const rows = [row];
+
+ renderItem({
+ row,
+ rows,
+ cols,
+ settings: makeSettings(),
+ rightColumns: [catCol],
+ });
+
+ expect(screen.getByText("Open")).toBeInTheDocument();
+ });
+
+ it("renders percentage with number and % sign", () => {
+ const pctCol = createMockColumn({
+ name: "conversion",
+ display_name: "Conversion",
+ semantic_type: "type/Percentage",
+ base_type: "type/Float",
+ });
+ const cols = [pctCol];
+ const row = [0.42];
+ const rows = [row];
+
+ const settings = makeSettings({
+ column: (col) =>
+ col.name === "conversion" ? { number_style: "percent" } : {},
+ });
+
+ renderItem({ row, rows, cols, settings, rightColumns: [pctCol] });
+
+ expect(screen.getByText("0.4")).toBeInTheDocument();
+ expect(screen.getAllByText("%").length).toBeGreaterThan(0);
+ });
+
+ it("renders currency with symbol and value", () => {
+ const curCol = createMockColumn({
+ name: "price",
+ display_name: "Price",
+ semantic_type: "type/Currency",
+ base_type: "type/Float",
+ effective_type: "type/Float",
+ });
+ const cols = [curCol];
+ const row = [1234.56];
+ const rows = [row];
+
+ const settings = makeSettings({
+ column: (col) =>
+ col.name === "price"
+ ? {
+ number_style: "currency",
+ currency: "USD",
+ currency_style: "symbol",
+ }
+ : {},
+ });
+
+ renderItem({ row, rows, cols, settings, rightColumns: [curCol] });
+
+ // Symbol and numeric value should be rendered separately
+ expect(screen.getByText("$")).toBeInTheDocument();
+ expect(screen.getByText((t) => /1,?234\.56/.test(t))).toBeInTheDocument();
+ });
+
+ it("renders image for ImageURL semantic type", () => {
+ const imgCol = createMockColumn({
+ name: "avatar",
+ display_name: "Avatar",
+ semantic_type: "type/ImageURL",
+ base_type: "type/Text",
+ });
+ const cols = [imgCol];
+ const row = ["https://example.com/a.png"];
+ const rows = [row];
+
+ renderItem({
+ row,
+ rows,
+ cols,
+ settings: makeSettings(),
+ rightColumns: [imgCol],
+ });
+
+ // There should be an <img /> rendered by Mantine Image component
+ const img = screen.getByRole("img");
+ expect(img).toBeInTheDocument();
+ });
+
+ it("renders number with a minibar and formatted value for Quantity", () => {
+ const qtyCol = createMockColumn({
+ name: "score",
+ display_name: "Score",
+ semantic_type: "type/Quantity",
+ base_type: "type/Number",
+ });
+ const cols = [qtyCol];
+ const row = [75];
+ const rows = [row];
+
+ const settings = makeSettings({
+ column: () => ({ number_style: "decimal" }),
+ });
+
+ renderItem({ row, rows, cols, settings, rightColumns: [qtyCol] });
+
+ // Mini bar container from MiniBarCell
+ const container = screen.getByTestId("mini-bar-container");
+ expect(container).toBeInTheDocument();
+ // Displayed value text (bold)
+ expect(screen.getByText(/75/)).toBeInTheDocument();
+ });
+});
diff --git a/frontend/src/metabase/list-view/components/ListView/styling.ts b/frontend/src/metabase/list-view/components/ListView/styling.ts
new file mode 100644
index 00000000000..349f725c47f
--- /dev/null
+++ b/frontend/src/metabase/list-view/components/ListView/styling.ts
@@ -0,0 +1,83 @@
+import type { IconName } from "metabase/ui";
+import { color } from "metabase/ui/utils/colors";
+
+export const ENTITY_ICONS = {
+ "entity/UserTable": "person",
+ "entity/CompanyTable": "factory",
+ "entity/TransactionTable": "receipt",
+ package: "package",
+ sticky_note: "sticky_note",
+ "entity/EventTable": "calendar",
+ "entity/SubscriptionTable": "sync",
+ location: "location",
+ pivot_table: "pivot_table",
+ message_circle: "message_circle",
+ octagon_alert: "octagon_alert",
+ "entity/ProductTable": "label",
+ "entity/GenericTable": "document",
+ zap: "zap",
+ camera: "camera",
+} satisfies Record<string, IconName>;
+
+export const getEntityIcon = (entityType?: string) => {
+ return (
+ entityType
+ ? ENTITY_ICONS[entityType as keyof typeof ENTITY_ICONS] || "document"
+ : "document"
+ ) as IconName;
+};
+
+export const ENTITY_ICON_COLORS = [
+ color("text-primary"),
+ color("brand"),
+ color("accent1"),
+ color("accent2"),
+ color("accent3"),
+ color("accent6"),
+];
+
+// For icons with default color, use white background,
+// otherwise derive transparent background from custom color.
+export function getIconBackground(iconColor?: string) {
+ if (!iconColor) {
+ return "var(--mb-color-white)";
+ }
+
+ return iconColor !== color("text-primary")
+ ? `color-mix(in srgb, ${color(iconColor)}, transparent 88%)`
+ : "var(--mb-color-white)";
+}
+
+const CATEGORY_COLORS = [
+ "accent0",
+ "accent1",
+ "accent2",
+ "accent3",
+ "accent4",
+ "accent5",
+ "accent6",
+ "accent7",
+];
+
+// Get a consistent color for a category value based on its hash
+export const getCategoryColor = (categoryValue: any, columnName: string) => {
+ if (categoryValue == null || categoryValue === "") {
+ return "var(--mb-color-background-light)";
+ }
+
+ const stringValue = String(categoryValue);
+
+ // Use a combination of column name and value for more consistent colors
+ const hashInput = `${columnName}:${stringValue}`;
+ let hash = 0;
+ for (let i = 0; i < hashInput.length; i++) {
+ const char = hashInput.charCodeAt(i);
+ // 5 is used to implement DJB2-like hashing: (hash * 33) + char
+ // Bit shifting by 5 (<< 5) is equivalent to multiplying by 32 (2^5)
+ hash = (hash << 5) + hash + char;
+ hash = hash & hash; // Convert to 32-bit integer
+ }
+
+ const colorIndex = Math.abs(hash) % CATEGORY_COLORS.length;
+ return color(CATEGORY_COLORS[colorIndex]);
+};
diff --git a/frontend/src/metabase/list-view/components/ListView/use-external-drag-overlay.ts b/frontend/src/metabase/list-view/components/ListView/use-external-drag-overlay.ts
new file mode 100644
index 00000000000..798cccc4b3c
--- /dev/null
+++ b/frontend/src/metabase/list-view/components/ListView/use-external-drag-overlay.ts
@@ -0,0 +1,152 @@
+import type {
+ DragEndEvent,
+ DragOverEvent,
+ DragStartEvent,
+} from "@dnd-kit/core";
+import { arrayMove } from "@dnd-kit/sortable";
+import { useState } from "react";
+
+import type { IconName } from "metabase/ui";
+
+type ContainerId = "left" | "right";
+
+/**
+ * External drag overlay allows us to provide visual feedback when dragging
+ * pills between 2 ReorderableTagsInput components by drawing an overlay layer
+ * rendering pills.
+ */
+export function useExternalDragOverlay({
+ leftValues,
+ rightValues,
+ onConfigurationChange,
+ maxLeftColumns,
+ maxRightColumns,
+}: {
+ leftValues: string[];
+ rightValues: string[];
+ onConfigurationChange: (values: {
+ left: string[];
+ right: string[];
+ entityIcon?: IconName | null;
+ }) => void;
+ maxLeftColumns: number;
+ maxRightColumns: number;
+}) {
+ const [activePillId, setActivePillId] = useState<string | null>(null);
+ const [currentDroppableContainer, setCurrentDroppableContainer] = useState<
+ string | null
+ >(null);
+
+ const handleDragStart = (event: DragStartEvent) => {
+ setActivePillId(event.active.id as string);
+ };
+
+ const handleDragOver = (event: DragOverEvent) => {
+ const { over } = event;
+ const containerId = over?.data?.current?.containerId;
+ if (!containerId) {
+ return;
+ }
+ // Storing the id of container under dragged element
+ // to hide it in original container when dragging between the two.
+ setCurrentDroppableContainer(containerId);
+ };
+
+ const handleDragEnd = (event: DragEndEvent) => {
+ setActivePillId(null);
+ setCurrentDroppableContainer(null);
+ const { active, over } = event;
+
+ if (!over) {
+ return;
+ }
+
+ const activeId = String(active.id);
+ const from = active.data?.current?.containerId as ContainerId | undefined;
+
+ if (!from) {
+ return;
+ }
+
+ // Determine target container - could be from over item's containerId or over.id itself
+ let to: ContainerId | undefined;
+ let overIndexInTo = -1;
+
+ // Check if we're dropping on an item (has containerId)
+ if (over.data?.current?.containerId) {
+ to = over.data.current.containerId as ContainerId;
+ const toList = to === "left" ? leftValues : rightValues;
+ overIndexInTo = toList.indexOf(String(over.id));
+ }
+ // Check if we're dropping on a container itself (droppable area)
+ else if (over.id === "left" || over.id === "right") {
+ to = over.id as ContainerId;
+ overIndexInTo = -1; // Append to end when dropping on container
+ }
+
+ if (!to) {
+ return;
+ }
+
+ const fromList = from === "left" ? leftValues : rightValues;
+
+ const fromIndex = fromList.indexOf(activeId);
+ if (fromIndex === -1) {
+ return;
+ }
+
+ // Same container: reorder
+ if (from === to) {
+ if (overIndexInTo === -1 || fromIndex === overIndexInTo) {
+ return;
+ }
+ const next = arrayMove(fromList, fromIndex, overIndexInTo);
+ if (from === "left") {
+ onConfigurationChange({
+ left: next,
+ right: rightValues,
+ });
+ } else {
+ onConfigurationChange({
+ left: leftValues,
+ right: next,
+ });
+ }
+ return;
+ }
+
+ // Moving items between containers
+ const maxForTo = to === "left" ? maxLeftColumns : maxRightColumns;
+ const toCurrent = to === "left" ? leftValues : rightValues;
+ if (toCurrent.length >= maxForTo) {
+ return;
+ }
+
+ const nextFrom = fromList.slice() as string[];
+ nextFrom.splice(fromIndex, 1);
+
+ const nextTo = toCurrent.slice() as string[];
+ const insertIndex = overIndexInTo === -1 ? nextTo.length : overIndexInTo;
+ nextTo.splice(insertIndex, 0, activeId);
+
+ if (to === "left") {
+ onConfigurationChange({
+ left: nextTo,
+ right: nextFrom,
+ });
+ } else {
+ onConfigurationChange({
+ left: nextFrom,
+ right: nextTo,
+ });
+ }
+ };
+
+ return {
+ activeId: activePillId,
+ currentDroppable: currentDroppableContainer,
+ handleDragStart,
+ handleDragOver,
+ handleDragEnd,
+ };
+}
diff --git a/frontend/src/metabase/list-view/components/ListViz/ListViz.tsx b/frontend/src/metabase/list-view/components/ListViz/ListViz.tsx
index 1b8234054d8..419569a7e76 100644
--- a/frontend/src/metabase/list-view/components/ListViz/ListViz.tsx
+++ b/frontend/src/metabase/list-view/components/ListViz/ListViz.tsx
@@ -10,7 +10,7 @@ import {
getIsListViewConfigurationShown,
getQuestion,
} from "metabase/query_builder/selectors";
-import { Box } from "metabase/ui";
+import { Box, type IconName } from "metabase/ui";
import ChartSettingLinkUrlInput from "metabase/visualizations/components/settings/ChartSettingLinkUrlInput";
import { columnSettings } from "metabase/visualizations/lib/settings/column";
import {
@@ -54,6 +54,15 @@ const vizDefinition = {
"list.entity_icon": {
default: null,
},
+ "list.entity_icon_color": {
+ default: "text-primary",
+ },
+ "list.entity_icon_enabled": {
+ default: true,
+ },
+ "list.use_image_column": {
+ default: false,
+ },
"list.columns": {
getDefault: ([
{
@@ -311,19 +320,38 @@ export const ListViz = ({
left,
right,
entityIcon,
+ entityIconColor,
+ entityIconEnabled,
+ useImageColumn,
}: {
- left: string[];
- right: string[];
- entityIcon?: string;
+ left?: string[];
+ right?: string[];
+ entityIcon?: IconName | null;
+ entityIconColor?: string;
+ entityIconEnabled?: boolean;
+ useImageColumn?: boolean;
}) => {
- const newSettings = {
- "list.columns": {
+ const settings = { ...(question?.settings() || {}) };
+ if (left && right) {
+ settings["list.columns"] = {
left,
right,
- },
- "list.entity_icon": entityIcon,
- };
- const nextQuestion = question?.updateSettings(newSettings);
+ };
+ }
+ if (entityIcon !== undefined) {
+ settings["list.entity_icon"] = entityIcon;
+ }
+ if (entityIconColor !== undefined) {
+ settings["list.entity_icon_color"] = entityIconColor;
+ }
+ if (entityIconEnabled !== undefined) {
+ settings["list.entity_icon_enabled"] = entityIconEnabled;
+ }
+ if (useImageColumn !== undefined) {
+ settings["list.use_image_column"] = useImageColumn;
+ }
+
+ const nextQuestion = question?.updateSettings(settings);
if (nextQuestion) {
dispatch(updateQuestion(nextQuestion));
}
@@ -341,8 +369,8 @@ export const ListViz = ({
<ListViewConfiguration
data={data}
settings={settings}
- entityType={entityType}
onChange={updateListSettings}
+ entityType={entityType}
columnsMetadata={columnsMetadata}
/>
) : (
diff --git a/frontend/src/metabase/query_builder/components/DatasetEditor/DatasetEditorSettingsSidebar/ListViewColumnsSidebar.tsx b/frontend/src/metabase/query_builder/components/DatasetEditor/DatasetEditorSettingsSidebar/ListViewColumnsSidebar.tsx
index 98c29a3ac16..402b82e90b5 100644
--- a/frontend/src/metabase/query_builder/components/DatasetEditor/DatasetEditorSettingsSidebar/ListViewColumnsSidebar.tsx
+++ b/frontend/src/metabase/query_builder/components/DatasetEditor/DatasetEditorSettingsSidebar/ListViewColumnsSidebar.tsx
@@ -37,7 +37,7 @@ export function ListViewColumnsSidebar({
onDone,
}: ListViewColumnsSidebarProps) {
const [query, setQuery] = useState("");
- const { titleColumn, subtitleColumn, rightColumns } = useListColumns(
+ const { titleColumn, rightColumns } = useListColumns(
cols,
settings?.["list.columns"],
);
@@ -50,7 +50,6 @@ export function ListViewColumnsSidebar({
const used = new Set<string | undefined>(
[
...(titleColumn ? [titleColumn.name] : []),
- ...(subtitleColumn ? [subtitleColumn.name] : []),
...rightColumns.map((col) => col?.name),
].filter(Boolean),
);
@@ -58,7 +57,7 @@ export function ListViewColumnsSidebar({
const unusedOptions = allOptions.filter((opt) => !used.has(opt.value));
return { unusedOptions };
- }, [cols, titleColumn, subtitleColumn, rightColumns]);
+ }, [cols, titleColumn, rightColumns]);
const filtered = useMemo(() => {
const q = query.trim().toLowerCase();
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/ban.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/ban.svg
new file mode 100644
index 00000000000..02f2196a7ac
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/ban.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" ><path d="M4.929 4.929 19.07 19.071"/><circle cx="12" cy="12" r="10"/></svg>
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/camera.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/camera.svg
new file mode 100644
index 00000000000..4a738526125
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/camera.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z"/><circle cx="12" cy="13" r="3"/></svg>
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/factory.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/factory.svg
new file mode 100644
index 00000000000..afbdc73bfcf
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/factory.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
+ <path d="M12 16h.01"/><path d="M16 16h.01"/><path d="M3 19a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8.5a.5.5 0 0 0-.769-.422l-4.462 2.844A.5.5 0 0 1 15 10.5v-2a.5.5 0 0 0-.769-.422L9.77 10.922A.5.5 0 0 1 9 10.5V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2z"/><path d="M8 16h.01"/>
+</svg>
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts b/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts
index 6056dc80a2b..35b1078b642 100644
--- a/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts
@@ -46,6 +46,8 @@ import audit_component from "./audit.svg?component";
import audit_source from "./audit.svg?source";
import badge_component from "./badge.svg?component";
import badge_source from "./badge.svg?source";
+import ban_component from "./ban.svg?component";
+import ban_source from "./ban.svg?source";
import bar_component from "./bar.svg?component";
import bar_source from "./bar.svg?source";
import bell_component from "./bell.svg?component";
@@ -70,6 +72,8 @@ import burger_component from "./burger.svg?component";
import burger_source from "./burger.svg?source";
import calendar_component from "./calendar.svg?component";
import calendar_source from "./calendar.svg?source";
+import camera_component from "./camera.svg?component";
+import camera_source from "./camera.svg?source";
import check_component from "./check.svg?component";
import check_source from "./check.svg?source";
import check_filled_component from "./check_filled.svg?component";
@@ -160,6 +164,8 @@ import eye_crossed_out_component from "./eye_crossed_out.svg?component";
import eye_crossed_out_source from "./eye_crossed_out.svg?source";
import eye_outline_component from "./eye_outline.svg?component";
import eye_outline_source from "./eye_outline.svg?source";
+import factory_component from "./factory.svg?component";
+import factory_source from "./factory.svg?source";
import field_component from "./field.svg?component";
import field_source from "./field.svg?source";
import fields_component from "./fields.svg?component";
@@ -270,6 +276,8 @@ import mail_component from "./mail.svg?component";
import mail_source from "./mail.svg?source";
import mail_filled_component from "./mail_filled.svg?component";
import mail_filled_source from "./mail_filled.svg?source";
+import message_circle_component from "./message_circle.svg?component";
+import message_circle_source from "./message_circle.svg?source";
import metabot_component from "./metabot.svg?component";
import metabot_source from "./metabot.svg?source";
import metabot_sad_component from "./metabot_sad.svg?component";
@@ -292,10 +300,14 @@ import notebook_component from "./notebook.svg?component";
import notebook_source from "./notebook.svg?source";
import number_component from "./number.svg?component";
import number_source from "./number.svg?source";
+import octagon_alert_component from "./octagon_alert.svg?component";
+import octagon_alert_source from "./octagon_alert.svg?source";
import official_collection_component from "./official_collection.svg?component";
import official_collection_source from "./official_collection.svg?source";
import ordered_list_component from "./ordered_list.svg?component";
import ordered_list_source from "./ordered_list.svg?source";
+import package_component from "./package.svg?component";
+import package_source from "./package.svg?source";
import palette_component from "./palette.svg?component";
import palette_source from "./palette.svg?source";
import pause_component from "./pause.svg?component";
@@ -404,6 +416,8 @@ import star_filled_component from "./star_filled.svg?component";
import star_filled_source from "./star_filled.svg?source";
import stepped_component from "./stepped.svg?component";
import stepped_source from "./stepped.svg?source";
+import sticky_note_component from "./sticky-note.svg?component";
+import sticky_note_source from "./sticky-note.svg?source";
import stop_component from "./stop.svg?component";
import stop_source from "./stop.svg?source";
import store_component from "./store.svg?component";
@@ -482,6 +496,8 @@ import waterfall_component from "./waterfall.svg?component";
import waterfall_source from "./waterfall.svg?source";
import webhook_component from "./webhook.svg?component";
import webhook_source from "./webhook.svg?source";
+import zap_component from "./zap.svg?component";
+import zap_source from "./zap.svg?source";
import zoom_in_component from "./zoom_in.svg?component";
import zoom_in_source from "./zoom_in.svg?source";
import zoom_out_component from "./zoom_out.svg?component";
@@ -577,6 +593,10 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: badge_component,
source: badge_source,
},
+ ban: {
+ component: ban_component,
+ source: ban_source,
+ },
bar: {
component: bar_component,
source: bar_source,
@@ -621,6 +641,10 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: calendar_component,
source: calendar_source,
},
+ camera: {
+ component: camera_component,
+ source: camera_source,
+ },
check: {
component: check_component,
source: check_source,
@@ -789,6 +813,10 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: eye_outline_component,
source: eye_outline_source,
},
+ factory: {
+ component: factory_component,
+ source: factory_source,
+ },
field: {
component: field_component,
source: field_source,
@@ -1013,6 +1041,10 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: mail_filled_component,
source: mail_filled_source,
},
+ message_circle: {
+ component: message_circle_component,
+ source: message_circle_source,
+ },
metabot: {
component: metabot_component,
source: metabot_source,
@@ -1057,6 +1089,10 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: number_component,
source: number_source,
},
+ package: {
+ component: package_component,
+ source: package_source,
+ },
palette: {
component: palette_component,
source: palette_source,
@@ -1157,6 +1193,14 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: share_component,
source: share_source,
},
+ sort: {
+ component: sort_component,
+ source: sort_source,
+ },
+ sort_arrows: {
+ component: sort_arrows_component,
+ source: sort_arrows_source,
+ },
split: {
component: split_component,
source: split_source,
@@ -1177,13 +1221,9 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: stepped_component,
source: stepped_source,
},
- sort: {
- component: sort_component,
- source: sort_source,
- },
- sort_arrows: {
- component: sort_arrows_component,
- source: sort_arrows_source,
+ sticky_note: {
+ component: sticky_note_component,
+ source: sticky_note_source,
},
sum: {
component: sum_component,
@@ -1411,6 +1451,10 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: verified_component,
source: verified_source,
},
+ octagon_alert: {
+ component: octagon_alert_component,
+ source: octagon_alert_source,
+ },
official_collection: {
component: official_collection_component,
source: official_collection_source,
@@ -1455,6 +1499,7 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: one_million_component,
source: one_million_source,
},
+ zap: { component: zap_component, source: zap_source },
zoom_in: {
component: zoom_in_component,
source: zoom_in_source,
@@ -1505,6 +1550,7 @@ export type IconName =
| "arrow_split"
| "audit"
| "badge"
+ | "ban"
| "bar"
| "bell"
| "birthday"
@@ -1516,6 +1562,7 @@ export type IconName =
| "bubble"
| "burger"
| "calendar"
+ | "camera"
| "check"
| "check_filled"
| "code_block"
@@ -1561,6 +1608,7 @@ export type IconName =
| "eye"
| "eye_crossed_out"
| "eye_outline"
+ | "factory"
| "field"
| "fields"
| "filter"
@@ -1617,6 +1665,7 @@ export type IconName =
| "lock_filled"
| "mail"
| "mail_filled"
+ | "message_circle"
| "metabot"
| "metabot_sad"
| "metric"
@@ -1628,6 +1677,8 @@ export type IconName =
| "new_folder"
| "notebook"
| "number"
+ | "octagon_alert"
+ | "package"
| "palette"
| "pause"
| "pencil"
@@ -1656,6 +1707,7 @@ export type IconName =
| "subscription"
| "straight"
| "stepped"
+ | "sticky_note"
| "sort"
| "sort_arrows"
| "sum"
@@ -1724,6 +1776,7 @@ export type IconName =
| "webhook"
| "10k"
| "1m"
+ | "zap"
| "zoom_in"
| "zoom_out"
| "scalar"
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/message_circle.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/message_circle.svg
new file mode 100644
index 00000000000..2fac406ce43
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/message_circle.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" ><path d="M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092 10 10 0 1 0-4.777-4.719"/></svg>
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/octagon_alert.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/octagon_alert.svg
new file mode 100644
index 00000000000..c0c494c0e78
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/octagon_alert.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16h.01"/><path d="M12 8v4"/><path d="M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z"/></svg>
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/package.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/package.svg
new file mode 100644
index 00000000000..12f28ac7105
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/package.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z"/><path d="M12 22V12"/><polyline points="3.29 7 12 12 20.71 7"/><path d="m7.5 4.27 9 5.15"/></svg>
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/sticky-note.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/sticky-note.svg
new file mode 100644
index 00000000000..beb3bc01057
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/sticky-note.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M16 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8Z"/><path d="M15 3v4a2 2 0 0 0 2 2h4"/></svg>
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/zap.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/zap.svg
new file mode 100644
index 00000000000..a0e2b12ca16
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/zap.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z"/></svg>
diff --git a/frontend/src/metabase/visualizations/components/TableInteractive/cells/MiniBarCell.tsx b/frontend/src/metabase/visualizations/components/TableInteractive/cells/MiniBarCell.tsx
index 85bf8a30568..d18c69009fa 100644
--- a/frontend/src/metabase/visualizations/components/TableInteractive/cells/MiniBarCell.tsx
+++ b/frontend/src/metabase/visualizations/components/TableInteractive/cells/MiniBarCell.tsx
@@ -6,7 +6,7 @@ import {
type CellAlign,
type CellFormatter,
} from "metabase/data-grid";
-import { alpha, color } from "metabase/lib/colors";
+import { color } from "metabase/lib/colors";
import type { ColumnSettings } from "metabase-types/api";
import S from "./MiniBarCell.module.css";
@@ -28,12 +28,16 @@ const resolveMax = (min: number, max: number, number_style: string) => {
export interface MiniBarCellProps<TValue> {
value: TValue;
extent: [number, number];
- formatter: CellFormatter<TValue>;
+ formatter?: CellFormatter<TValue>;
backgroundColor?: string;
align?: CellAlign;
rowIndex: number;
columnId: string;
columnSettings: ColumnSettings;
+ style?: React.CSSProperties;
+ barWidth?: number | string;
+ barHeight?: number | string;
+ barColor?: string;
}
export const MiniBarCell = <TValue,>({
@@ -45,6 +49,10 @@ export const MiniBarCell = <TValue,>({
rowIndex,
columnId,
columnSettings,
+ style,
+ barWidth = BAR_WIDTH,
+ barHeight = BAR_HEIGHT,
+ barColor = color("brand"),
}: MiniBarCellProps<TValue>) => {
if (typeof value !== "number") {
return null;
@@ -55,7 +63,7 @@ export const MiniBarCell = <TValue,>({
const resolvedMax = resolveMax(min, max, columnSettings["number_style"]);
const barPercent =
(Math.abs(value) / Math.max(Math.abs(min), Math.abs(resolvedMax))) * 100;
- const barColor = isNegative ? color("error") : color("brand");
+ const barVizColor = isNegative ? color("error") : barColor;
const barStyle = !hasNegative
? {
@@ -86,29 +94,32 @@ export const MiniBarCell = <TValue,>({
className={S.root}
backgroundColor={backgroundColor}
align={align}
+ style={style}
>
<div className={S.minibarWrapper}>
{/* TEXT VALUE */}
- <div
- className={cx(
- CS.textEllipsis,
- CS.textBold,
- CS.textRight,
- CS.flexFull,
- )}
- style={{ minWidth: LABEL_MIN_WIDTH }}
- >
- {formatter(value, rowIndex, columnId)}
- </div>
+ {formatter ? (
+ <div
+ className={cx(
+ CS.textEllipsis,
+ CS.textBold,
+ CS.textRight,
+ CS.flexFull,
+ )}
+ style={{ minWidth: LABEL_MIN_WIDTH }}
+ >
+ {formatter(value, rowIndex, columnId)}
+ </div>
+ ) : null}
{/* OUTER CONTAINER BAR */}
<div
data-testid="mini-bar-container"
className={CS.ml1}
style={{
position: "relative",
- width: BAR_WIDTH,
- height: BAR_HEIGHT,
- backgroundColor: alpha(barColor, 0.2),
+ width: barWidth,
+ height: barHeight,
+ backgroundColor: `color-mix(in srgb, ${barVizColor}, white 80%)`,
borderRadius: BORDER_RADIUS,
}}
>
@@ -119,7 +130,7 @@ export const MiniBarCell = <TValue,>({
position: "absolute",
top: 0,
bottom: 0,
- backgroundColor: barColor,
+ backgroundColor: barVizColor,
...barStyle,
}}
/>