Skip to content

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

Various Data Studio Table Adjustments (#66795)

Nick Fitzpatrick2ebcd1631c75
diff --git a/.loki/reference/chrome_laptop_Components_Table_Default.png b/.loki/reference/chrome_laptop_Components_Table_Default.png
new file mode 100644
index 00000000000..740f0c37a79
Binary files /dev/null and b/.loki/reference/chrome_laptop_Components_Table_Default.png differ
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.module.css b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.module.css
index 4abf6d19706..bae786b8bbd 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.module.css
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.module.css
@@ -1,4 +1,4 @@
-.Row {
+.row {
display: flex;
width: 100%;
border-bottom: 1px solid var(--mb-color-border);
@@ -16,25 +16,25 @@
}
}
-.Cell {
+.cell {
display: flex;
align-items: center;
gap: 0.5rem;
}
-.Table {
+.table {
background: inherit;
display: grid;
}
-.Header {
+.header {
background: inherit;
display: grid;
position: sticky;
top: 0;
z-index: 1;
- .Row {
+ .row {
cursor: unset;
padding-left: 1rem;
@@ -44,13 +44,24 @@
}
}
-.HeaderBadge {
+.headerBadge {
cursor: pointer;
user-select: none;
}
-.ScrollContainer {
+.headerBadgeLabel {
+ text-transform: none;
+ font-size: 0.75rem;
+}
+
+.scrollContainer {
background: inherit;
overflow: auto;
position: relative;
}
+
+.body {
+ .row:last-of-type {
+ border-bottom: none;
+ }
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.tsx
index 96f1e89dfab..cfd54fefe42 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/Table.tsx
@@ -19,6 +19,8 @@ import { Badge, Icon } from "metabase/ui";
import S from "./Table.module.css";
+const DEFAULT_ROW_HEIGHT = 47;
+
export const TableComponent = <
T extends Record<string, any> & { children?: T[] },
>({
@@ -45,12 +47,12 @@ export const TableComponent = <
});
return (
- <div className={S.ScrollContainer} ref={(e) => setScrollRef(e)}>
+ <div className={S.scrollContainer} ref={(e) => setScrollRef(e)}>
{/* Even though we're still using semantic table tags, we must use CSS grid and flexbox for dynamic row heights */}
- <table className={S.Table}>
- <thead className={S.Header}>
+ <table className={S.table}>
+ <thead className={S.header}>
{table.getHeaderGroups().map((headerGroup) => (
- <tr key={headerGroup.id} className={S.Row}>
+ <tr key={headerGroup.id} className={S.row}>
{headerGroup.headers.map((header) => {
const headerContent = flexRender(
header.column.columnDef.header,
@@ -67,7 +69,10 @@ export const TableComponent = <
{headerContent && (
<Badge
onClick={header.column.getToggleSortingHandler()}
- className={S.HeaderBadge}
+ classNames={{
+ root: S.headerBadge,
+ label: S.headerBadgeLabel,
+ }}
rightSection={
{
asc: <Icon name="chevronup" size={10} />,
@@ -112,12 +117,10 @@ function TableBody<T>({
// Important: Keep the row virtualizer in the lowest component possible to avoid unnecessary re-renders.
const rowVirtualizer = useVirtualizer<HTMLDivElement, HTMLTableRowElement>({
count: rows.length,
- estimateSize: () => 33, //estimate row height for accurate scrollbar dragging
+ estimateSize: () => DEFAULT_ROW_HEIGHT, //estimate row height for accurate scrollbar dragging
getScrollElement: () => tableContainerRef,
- //measure dynamic row height, except in firefox because it measures table border height incorrectly
measureElement:
- typeof window !== "undefined" &&
- navigator.userAgent.indexOf("Firefox") === -1
+ typeof window !== "undefined"
? (element) => element?.getBoundingClientRect().height
: undefined,
overscan: 5,
@@ -125,6 +128,7 @@ function TableBody<T>({
return (
<tbody
+ className={S.body}
style={{
display: "grid",
height: `${rowVirtualizer.getTotalSize()}px`, //tells scrollbar how big the table is
@@ -169,7 +173,7 @@ function TableBodyRow<T>({
data-index={virtualRow.index} //needed for dynamic row height measurement
ref={(node) => rowVirtualizer.measureElement(node)} //measure dynamic row height
key={row.id}
- className={S.Row}
+ className={S.row}
style={{
position: "absolute",
transform: `translateY(${virtualRow.start}px)`, //this should always be a `style` as it changes on scroll
@@ -185,7 +189,7 @@ function TableBodyRow<T>({
return (
<td
key={cell.id}
- className={S.Cell}
+ className={S.cell}
style={{
...getColumWidthStyle(cell.column.columnDef),
}}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/Table.stories.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/Table.stories.tsx
new file mode 100644
index 00000000000..79c1c19966c
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/Table.stories.tsx
@@ -0,0 +1,48 @@
+import type { ColumnDef } from "@tanstack/react-table";
+import type { ReactNode } from "react";
+
+import { Card, Group, Icon, ThemeProvider } from "metabase/ui";
+
+import { Table } from "..";
+
+import data from "./data.json";
+
+const columns: ColumnDef<Record<string, any>, ReactNode>[] = [
+ {
+ accessorKey: "name",
+ header: "Name",
+ meta: { width: "auto" },
+ cell: ({ getValue, row }) => {
+ const data = row.original;
+ return (
+ <Group data-testid={`${data.model}-name`} gap="sm">
+ {data.icon && <Icon name={data.icon} c="brand" />}
+ {getValue()}
+ </Group>
+ );
+ },
+ },
+ {
+ accessorKey: "updatedAt",
+ header: "Updated At",
+ },
+];
+
+const Template = () => {
+ return (
+ <ThemeProvider>
+ <Card p={0} withBorder h={600} w={600}>
+ <Table data={data} columns={columns} onSelect={() => {}} />
+ </Card>
+ </ThemeProvider>
+ );
+};
+
+export default {
+ title: "Components/Table",
+ component: Table,
+};
+
+export const Default = {
+ render: Template,
+};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/data.json b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/data.json
new file mode 100644
index 00000000000..2a26679d1e1
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/Table/stories/data.json
@@ -0,0 +1,475 @@
+[
+ {
+ "name": "Data",
+ "id": 8,
+ "icon": "table",
+ "data": {
+ "authority_level": null,
+ "description": null,
+ "archived": false,
+ "children": [],
+ "slug": "data",
+ "archive_operation_id": null,
+ "can_write": true,
+ "name": "Data",
+ "is_remote_synced": false,
+ "personal_owner_id": null,
+ "type": "library-data",
+ "here": ["table"],
+ "is_sample": false,
+ "id": 8,
+ "archived_directly": null,
+ "entity_id": "1z7rDfL_9EEIifEZZLVtV",
+ "location": "/7/",
+ "namespace": null,
+ "created_at": "2025-12-08T14:53:32.380269Z",
+ "model": "collection"
+ },
+ "model": "collection",
+ "children": [
+ {
+ "name": "Action",
+ "icon": "table",
+ "data": {
+ "authority_level": null,
+ "description": "An action is something you can do, such as run a readwrite query",
+ "archived": false,
+ "collection_position": null,
+ "table_id": 97,
+ "database_id": 2,
+ "collection_id": 8,
+ "query_type": null,
+ "name": "Action",
+ "is_remote_synced": null,
+ "personal_owner_id": null,
+ "last_used_at": null,
+ "icon": null,
+ "moderated_status": null,
+ "dataset_query": null,
+ "id": 97,
+ "display": null,
+ "entity_id": null,
+ "is_upload": null,
+ "collection_preview": null,
+ "location": null,
+ "dashboard_id": null,
+ "model": "table"
+ },
+ "id": 97,
+ "model": "table"
+ },
+ {
+ "name": "Api Key",
+ "icon": "table",
+ "data": {
+ "authority_level": null,
+ "description": "An API Key",
+ "archived": false,
+ "collection_position": null,
+ "table_id": 42,
+ "database_id": 2,
+ "collection_id": 8,
+ "query_type": null,
+ "name": "Api Key",
+ "is_remote_synced": null,
+ "personal_owner_id": null,
+ "last_used_at": null,
+ "icon": null,
+ "moderated_status": null,
+ "dataset_query": null,
+ "id": 42,
+ "display": null,
+ "entity_id": null,
+ "is_upload": null,
+ "collection_preview": null,
+ "location": null,
+ "dashboard_id": null,
+ "model": "table"
+ },
+ "id": 42,
+ "model": "table"
+ },
+ {
+ "name": "Application Permissions Revision",
+ "icon": "table",
+ "data": {
+ "authority_level": null,
+ "description": null,
+ "archived": false,
+ "collection_position": null,
+ "table_id": 89,
+ "database_id": 2,
+ "collection_id": 8,
+ "query_type": null,
+ "name": "Application Permissions Revision",
+ "is_remote_synced": null,
+ "personal_owner_id": null,
+ "last_used_at": null,
+ "icon": null,
+ "moderated_status": null,
+ "dataset_query": null,
+ "id": 89,
+ "display": null,
+ "entity_id": null,
+ "is_upload": null,
+ "collection_preview": null,
+ "location": null,
+ "dashboard_id": null,
+ "model": "table"
+ },
+ "id": 89,
+ "model": "table"
+ },
+ {
+ "name": "Audit Log",
+ "icon": "table",
+ "data": {
+ "authority_level": null,
+ "description": "Used to store application events for auditing use cases",
+ "archived": false,
+ "collection_position": null,
+ "table_id": 124,
+ "database_id": 2,
+ "collection_id": 8,
+ "query_type": null,
+ "name": "Audit Log",
+ "is_remote_synced": null,
+ "personal_owner_id": null,
+ "last_used_at": null,
+ "icon": null,
+ "moderated_status": null,
+ "dataset_query": null,
+ "id": 124,
+ "display": null,
+ "entity_id": null,
+ "is_upload": null,
+ "collection_preview": null,
+ "location": null,
+ "dashboard_id": null,
+ "model": "table"
+ },
+ "id": 124,
+ "model": "table"
+ },
+ {
+ "name": "Auth Identity",
+ "icon": "table",
+ "data": {
+ "authority_level": null,
+ "description": "Stores authentication credentials for users. A user can have multiple auth identities.",
+ "archived": false,
+ "collection_position": null,
+ "table_id": 150,
+ "database_id": 2,
+ "collection_id": 8,
+ "query_type": null,
+ "name": "Auth Identity",
+ "is_remote_synced": null,
+ "personal_owner_id": null,
+ "last_used_at": null,
+ "icon": null,
+ "moderated_status": null,
+ "dataset_query": null,
+ "id": 150,
+ "display": null,
+ "entity_id": null,
+ "is_upload": null,
+ "collection_preview": null,
+ "location": null,
+ "dashboard_id": null,
+ "model": "table"
+ },
+ "id": 150,
+ "model": "table"
+ },
+ {
+ "name": "Bookmark Ordering",
+ "icon": "table",
+ "data": {
+ "authority_level": null,
+ "description": null,
+ "archived": false,
+ "collection_position": null,
+ "table_id": 26,
+ "database_id": 2,
+ "collection_id": 8,
+ "query_type": null,
+ "name": "Bookmark Ordering",
+ "is_remote_synced": null,
+ "personal_owner_id": null,
+ "last_used_at": null,
+ "icon": null,
+ "moderated_status": null,
+ "dataset_query": null,
+ "id": 26,
+ "display": null,
+ "entity_id": null,
+ "is_upload": null,
+ "collection_preview": null,
+ "location": null,
+ "dashboard_id": null,
+ "model": "table"
+ },
+ "id": 26,
+ "model": "table"
+ },
+ {
+ "name": "Cache Config",
+ "icon": "table",
+ "data": {
+ "authority_level": null,
+ "description": "Cache Configuration",
+ "archived": false,
+ "collection_position": null,
+ "table_id": 101,
+ "database_id": 2,
+ "collection_id": 8,
+ "query_type": null,
+ "name": "Cache Config",
+ "is_remote_synced": null,
+ "personal_owner_id": null,
+ "last_used_at": null,
+ "icon": null,
+ "moderated_status": null,
+ "dataset_query": null,
+ "id": 101,
+ "display": null,
+ "entity_id": null,
+ "is_upload": null,
+ "collection_preview": null,
+ "location": null,
+ "dashboard_id": null,
+ "model": "table"
+ },
+ "id": 101,
+ "model": "table"
+ }
+ ]
+ },
+ {
+ "name": "Metrics",
+ "id": 9,
+ "icon": "metric",
+ "data": {
+ "authority_level": null,
+ "description": null,
+ "archived": false,
+ "children": [],
+ "slug": "metrics",
+ "archive_operation_id": null,
+ "can_write": true,
+ "name": "Metrics",
+ "is_remote_synced": false,
+ "personal_owner_id": null,
+ "type": "library-metrics",
+ "here": ["metric"],
+ "is_sample": false,
+ "id": 9,
+ "archived_directly": null,
+ "entity_id": "7v6-Hdh0vm94n28nKiQXP",
+ "location": "/7/",
+ "namespace": null,
+ "created_at": "2025-12-08T14:53:32.397579Z",
+ "model": "collection"
+ },
+ "model": "collection",
+ "children": [
+ {
+ "name": "Number of Orders - Duplicate",
+ "updatedAt": "2025-12-08T14:54:11.762685Z",
+ "icon": "metric",
+ "data": {
+ "description": "Canonical metric for number of orders placed",
+ "archived": false,
+ "collection_position": 2,
+ "can_write": true,
+ "database_id": null,
+ "collection_id": 9,
+ "name": "Number of Orders - Duplicate",
+ "is_remote_synced": false,
+ "dashboard_count": 0,
+ "fully_parameterized": true,
+ "last_used_at": "2025-12-09T14:38:37.011576Z",
+ "dashboard": null,
+ "can_restore": false,
+ "moderated_status": null,
+ "id": 113,
+ "display": "line",
+ "entity_id": "GciYt6tgWa1Mmxql59wd8",
+ "collection_preview": true,
+ "last-edit-info": {
+ "id": 1,
+ "last_name": "Fitzpatrick",
+ "first_name": "Nicholas",
+ "email": "[email protected]",
+ "timestamp": "2025-12-08T14:54:11.762685Z"
+ },
+ "location": null,
+ "dashboard_id": null,
+ "can_delete": false,
+ "model": "metric"
+ },
+ "id": 113,
+ "model": "metric"
+ },
+ {
+ "name": "Revenue - Duplicate",
+ "updatedAt": "2025-12-08T14:54:29.023573Z",
+ "icon": "metric",
+ "data": {
+ "description": "Canonical metric for revenue across all product lines",
+ "archived": false,
+ "collection_position": 1,
+ "can_write": true,
+ "database_id": null,
+ "collection_id": 9,
+ "name": "Revenue - Duplicate",
+ "is_remote_synced": false,
+ "dashboard_count": 0,
+ "fully_parameterized": true,
+ "last_used_at": "2025-12-08T17:41:03.27253Z",
+ "dashboard": null,
+ "can_restore": false,
+ "moderated_status": null,
+ "id": 114,
+ "display": "line",
+ "entity_id": "rW_8izY2VcNcOl7YTi9h9",
+ "collection_preview": true,
+ "last-edit-info": {
+ "id": 1,
+ "last_name": "Fitzpatrick",
+ "first_name": "Nicholas",
+ "email": "[email protected]",
+ "timestamp": "2025-12-08T14:54:29.023573Z"
+ },
+ "location": null,
+ "dashboard_id": null,
+ "can_delete": false,
+ "model": "metric"
+ },
+ "id": 114,
+ "model": "metric"
+ }
+ ]
+ },
+ {
+ "id": "root",
+ "name": "SQL snippets",
+ "model": "collection",
+ "icon": "snippet",
+ "data": {
+ "authority_level": null,
+ "can_write": true,
+ "name": "Top folder",
+ "is_remote_synced": null,
+ "effective_ancestors": [],
+ "can_restore": false,
+ "effective_location": null,
+ "parent_id": null,
+ "id": "root",
+ "namespace": "snippets",
+ "is_personal": false,
+ "can_delete": false,
+ "model": "collection"
+ },
+ "children": [
+ {
+ "id": 10,
+ "name": "Child Folder",
+ "model": "collection",
+ "icon": "folder",
+ "data": {
+ "authority_level": null,
+ "description": null,
+ "archived": false,
+ "slug": "child_folder",
+ "archive_operation_id": null,
+ "can_write": true,
+ "name": "Child Folder",
+ "is_remote_synced": false,
+ "personal_owner_id": null,
+ "type": null,
+ "is_sample": false,
+ "parent_id": null,
+ "id": 10,
+ "archived_directly": null,
+ "entity_id": "XDsrJhm7QE5P3wRfCOqHF",
+ "location": "/",
+ "namespace": "snippets",
+ "is_personal": false,
+ "created_at": "2025-12-10T15:06:57.01592Z",
+ "can_delete": false,
+ "model": "collection"
+ },
+ "children": [
+ {
+ "id": 11,
+ "name": "Sub Sub Folder",
+ "model": "collection",
+ "icon": "folder",
+ "data": {
+ "authority_level": null,
+ "description": null,
+ "archived": false,
+ "slug": "sub_sub_folder",
+ "archive_operation_id": null,
+ "can_write": true,
+ "name": "Sub Sub Folder",
+ "is_remote_synced": false,
+ "personal_owner_id": null,
+ "type": null,
+ "is_sample": false,
+ "parent_id": 10,
+ "id": 11,
+ "archived_directly": null,
+ "entity_id": "-XxBiHgFNe4Kq1u3cROa-",
+ "location": "/10/",
+ "namespace": "snippets",
+ "is_personal": false,
+ "created_at": "2025-12-10T15:07:21.323663Z",
+ "can_delete": false,
+ "model": "collection"
+ },
+ "children": [
+ {
+ "id": 1,
+ "name": "My Snippet",
+ "icon": "snippet",
+ "model": "snippet",
+ "data": {
+ "description": null,
+ "archived": false,
+ "dependency_analysis_version": 3,
+ "creator": {
+ "email": "[email protected]",
+ "first_name": "Nicholas",
+ "last_login": "2025-12-08T14:34:17.749893Z",
+ "is_qbnewb": false,
+ "is_superuser": true,
+ "id": 1,
+ "last_name": "Fitzpatrick",
+ "tenant_id": null,
+ "date_joined": "2025-12-08T14:34:17.511001Z",
+ "common_name": "Nicholas Fitzpatrick"
+ },
+ "content": "order.id === 1",
+ "collection_id": 11,
+ "name": "My Snippet",
+ "is_remote_synced": null,
+ "creator_id": 1,
+ "updated_at": "2025-12-10T15:07:50.438363Z",
+ "id": 1,
+ "entity_id": "6dBsu95KeBRBCpV9cK7VN",
+ "template_tags": {},
+ "created_at": "2025-12-10T15:07:50.438363Z",
+ "model": "snippet"
+ },
+ "updatedAt": "2025-12-10T15:07:50.438363Z"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ }
+]
diff --git a/loki.config.js b/loki.config.js
index e0c5ede977f..ee2d9c1ed6d 100644
--- a/loki.config.js
+++ b/loki.config.js
@@ -15,6 +15,7 @@ module.exports = {
"^Components/overlays/Tooltip",
"^Components/Documents",
"^Components/Feedback/Alert",
+ "^Components/Table",
"^App/Palette",
].join("|"),
configurations: {