The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
table viz should not collapse whitespaces (#62521)
Aleksandr Lesnenkoacfc829c9ec6
diff --git a/.loki/reference/chrome_laptop_viz_Table_Preserve_Whitespace_Unwrapped.png b/.loki/reference/chrome_laptop_viz_Table_Preserve_Whitespace_Unwrapped.pngnew file mode 100644index 00000000000..f39f536aa03Binary files /dev/null and b/.loki/reference/chrome_laptop_viz_Table_Preserve_Whitespace_Unwrapped.png differdiff --git a/.loki/reference/chrome_laptop_viz_Table_Preserve_Whitespace_Wrapped.png b/.loki/reference/chrome_laptop_viz_Table_Preserve_Whitespace_Wrapped.pngnew file mode 100644index 00000000000..744cc7bf5f6Binary files /dev/null and b/.loki/reference/chrome_laptop_viz_Table_Preserve_Whitespace_Wrapped.png differdiff --git a/frontend/src/metabase/data-grid/components/BodyCell/BodyCell.module.css b/frontend/src/metabase/data-grid/components/BodyCell/BodyCell.module.cssindex 36a1fed7f07..2fa0824372b 100644--- a/frontend/src/metabase/data-grid/components/BodyCell/BodyCell.module.css+++ b/frontend/src/metabase/data-grid/components/BodyCell/BodyCell.module.css@@ -12,10 +12,11 @@.content {line-height: 17px;overflow: visible;+ white-space: pre-wrap;}.noWrap {- white-space: nowrap;+ white-space: pre;overflow: hidden;text-overflow: ellipsis;}diff --git a/frontend/src/metabase/visualizations/visualizations/Table/Table.stories.tsx b/frontend/src/metabase/visualizations/visualizations/Table/Table.stories.tsxindex 64dc76d29dc..200201da215 100644--- a/frontend/src/metabase/visualizations/visualizations/Table/Table.stories.tsx+++ b/frontend/src/metabase/visualizations/visualizations/Table/Table.stories.tsx@@ -155,6 +155,20 @@ export const DashboardTableWithRowId = {},};+export const PreserveWhitespaceWrapped = {+ render: DefaultTemplate,+ args: {+ series: data.preserveWhitespaceWrapped,+ },+};++export const PreserveWhitespaceUnwrapped = {+ render: DefaultTemplate,+ args: {+ series: data.preserveWhitespaceUnwrapped,+ },+};+export const Watermark = {parameters: {loki: { skip: true },diff --git a/frontend/src/metabase/visualizations/visualizations/Table/Table.tsx b/frontend/src/metabase/visualizations/visualizations/Table/Table.tsxindex 2063d6e1594..88ff21c10b3 100644--- a/frontend/src/metabase/visualizations/visualizations/Table/Table.tsx+++ b/frontend/src/metabase/visualizations/visualizations/Table/Table.tsx@@ -277,7 +277,7 @@ class Table extends Component<TableProps, TableState> {}if (isString(column)) {- const canWrapText = (columnSettings: OptionsType) =>+ const isNotImage = (columnSettings: OptionsType) =>columnSettings["view_as"] !== "image";settings["text_wrapping"] = {@@ -286,10 +286,10 @@ class Table extends Component<TableProps, TableState> {widget: "toggle",inline: true,isValid: (_column, columnSettings) => {- return canWrapText(columnSettings);+ return isNotImage(columnSettings);},getHidden: (_column, columnSettings) => {- return !canWrapText(columnSettings);+ return !isNotImage(columnSettings);},};}diff --git a/frontend/src/metabase/visualizations/visualizations/Table/stories-data/index.ts b/frontend/src/metabase/visualizations/visualizations/Table/stories-data/index.tsindex 89dc86bae9a..b273c88bb62 100644--- a/frontend/src/metabase/visualizations/visualizations/Table/stories-data/index.ts+++ b/frontend/src/metabase/visualizations/visualizations/Table/stories-data/index.ts@@ -1,6 +1,8 @@import groupedOrders from "./grouped-orders.json";import images from "./images.json";import ordersWithPeople from "./orders-with-people.json";+import preserveWhitespaceUnwrapped from "./preserve-whitespace-unwrapped.json";+import preserveWhitespaceWrapped from "./preserve-whitespace-wrapped.json";import variousColumnSettings from "./various-column-settings.json";import wrappedLinks from "./wrapped-links.json";@@ -10,4 +12,6 @@ export {images,wrappedLinks,groupedOrders,+ preserveWhitespaceUnwrapped,+ preserveWhitespaceWrapped,};diff --git a/frontend/src/metabase/visualizations/visualizations/Table/stories-data/preserve-whitespace-unwrapped.json b/frontend/src/metabase/visualizations/visualizations/Table/stories-data/preserve-whitespace-unwrapped.jsonnew file mode 100644index 00000000000..968136d9b46--- /dev/null+++ b/frontend/src/metabase/visualizations/visualizations/Table/stories-data/preserve-whitespace-unwrapped.json@@ -0,0 +1,182 @@+[+ {+ "data": {+ "rows": [+ ["big spaces gap", "lorem"],+ [+ "_ _",+ "Lorem ipsum dolor sit amet"+ ]+ ],+ "results_timezone": "America/Montevideo",+ "download_perms": "full",+ "results_metadata": {+ "columns": [+ {+ "database_type": "CHARACTER VARYING",+ "semantic_type": null,+ "lib/deduplicated-name": "A",+ "lib/original-name": "A",+ "name": "A",+ "lib/source": "source/native",+ "source": "native",+ "field_ref": [+ "field",+ "A",+ {+ "base-type": "type/Text"+ }+ ],+ "effective_type": "type/Text",+ "display_name": "A",+ "fingerprint": {+ "global": {+ "distinct-count": 2,+ "nil%": 0+ },+ "type": {+ "type/Text": {+ "percent-json": 0,+ "percent-url": 0,+ "percent-email": 0,+ "percent-state": 0,+ "average-length": 34.5+ }+ }+ },+ "base_type": "type/Text"+ },+ {+ "database_type": "CHARACTER VARYING",+ "semantic_type": null,+ "lib/deduplicated-name": "B",+ "lib/original-name": "B",+ "name": "B",+ "lib/source": "source/native",+ "source": "native",+ "field_ref": [+ "field",+ "B",+ {+ "base-type": "type/Text"+ }+ ],+ "effective_type": "type/Text",+ "display_name": "B",+ "fingerprint": {+ "global": {+ "distinct-count": 2,+ "nil%": 0+ },+ "type": {+ "type/Text": {+ "percent-json": 0,+ "percent-url": 0,+ "percent-email": 0,+ "percent-state": 0,+ "average-length": 30+ }+ }+ },+ "base_type": "type/Text"+ }+ ]+ },+ "format-rows?": true,+ "pivot-export-options": {+ "show-row-totals": true,+ "show-column-totals": true+ },+ "cols": [+ {+ "database_type": "CHARACTER VARYING",+ "lib/deduplicated-name": "A",+ "lib/original-name": "A",+ "name": "A",+ "lib/source": "source/native",+ "source": "native",+ "field_ref": [+ "field",+ "A",+ {+ "base-type": "type/Text"+ }+ ],+ "effective_type": "type/Text",+ "display_name": "A",+ "base_type": "type/Text"+ },+ {+ "database_type": "CHARACTER VARYING",+ "lib/deduplicated-name": "B",+ "lib/original-name": "B",+ "name": "B",+ "lib/source": "source/native",+ "source": "native",+ "field_ref": [+ "field",+ "B",+ {+ "base-type": "type/Text"+ }+ ],+ "effective_type": "type/Text",+ "display_name": "B",+ "base_type": "type/Text"+ }+ ],+ "native_form": {+ "params": null,+ "query": "select 'big spaces gap' a, 'lorem' b\nunion all select '_ _', 'Lorem ipsum dolor sit amet'"+ },+ "is_sandboxed": false,+ "insights": null+ },+ "cached": null,+ "database_id": 1,+ "started_at": "2025-08-21T18:15:32.527977-03:00",+ "json_query": {+ "database": 1,+ "type": "native",+ "native": {+ "template-tags": {},+ "query": "select 'big spaces gap' a, 'lorem' b\nunion all select '_ _', 'Lorem ipsum dolor sit amet'\n"+ },+ "middleware": {+ "js-int-to-string?": true,+ "userland-query?": true,+ "add-default-userland-constraints?": true+ }+ },+ "average_execution_time": null,+ "status": "completed",+ "context": "ad-hoc",+ "row_count": 2,+ "running_time": 24,+ "card": {+ "collection_id": null,+ "creationType": "native_question",+ "dataset_query": {+ "database": 1,+ "type": "native",+ "native": {+ "template-tags": {},+ "query": "select 'big spaces gap' a, 'lorem' b\nunion all select '_ _', 'Lorem ipsum dolor sit amet'\n"+ }+ },+ "display": "table",+ "type": "question",+ "visualization_settings": {+ "column_settings": {+ "[\"name\",\"A\"]": {+ "preserve_whitespace": true+ },+ "[\"name\",\"B\"]": {+ "preserve_whitespace": true+ }+ }+ },+ "parameters": []+ }+ }+]diff --git a/frontend/src/metabase/visualizations/visualizations/Table/stories-data/preserve-whitespace-wrapped.json b/frontend/src/metabase/visualizations/visualizations/Table/stories-data/preserve-whitespace-wrapped.jsonnew file mode 100644index 00000000000..b5c2ddafa8e--- /dev/null+++ b/frontend/src/metabase/visualizations/visualizations/Table/stories-data/preserve-whitespace-wrapped.json@@ -0,0 +1,185 @@+[+ {+ "data": {+ "rows": [+ ["big spaces gap", "lorem"],+ [+ "_ _",+ "Lorem ipsum dolor sit amet"+ ]+ ],+ "results_timezone": "America/Montevideo",+ "download_perms": "full",+ "results_metadata": {+ "columns": [+ {+ "database_type": "CHARACTER VARYING",+ "semantic_type": null,+ "lib/deduplicated-name": "A",+ "lib/original-name": "A",+ "name": "A",+ "lib/source": "source/native",+ "source": "native",+ "field_ref": [+ "field",+ "A",+ {+ "base-type": "type/Text"+ }+ ],+ "effective_type": "type/Text",+ "display_name": "A",+ "fingerprint": {+ "global": {+ "distinct-count": 2,+ "nil%": 0+ },+ "type": {+ "type/Text": {+ "percent-json": 0,+ "percent-url": 0,+ "percent-email": 0,+ "percent-state": 0,+ "average-length": 34.5+ }+ }+ },+ "base_type": "type/Text"+ },+ {+ "database_type": "CHARACTER VARYING",+ "semantic_type": null,+ "lib/deduplicated-name": "B",+ "lib/original-name": "B",+ "name": "B",+ "lib/source": "source/native",+ "source": "native",+ "field_ref": [+ "field",+ "B",+ {+ "base-type": "type/Text"+ }+ ],+ "effective_type": "type/Text",+ "display_name": "B",+ "fingerprint": {+ "global": {+ "distinct-count": 2,+ "nil%": 0+ },+ "type": {+ "type/Text": {+ "percent-json": 0,+ "percent-url": 0,+ "percent-email": 0,+ "percent-state": 0,+ "average-length": 30+ }+ }+ },+ "base_type": "type/Text"+ }+ ]+ },+ "format-rows?": true,+ "pivot-export-options": {+ "show-row-totals": true,+ "show-column-totals": true+ },+ "cols": [+ {+ "database_type": "CHARACTER VARYING",+ "lib/deduplicated-name": "A",+ "lib/original-name": "A",+ "name": "A",+ "lib/source": "source/native",+ "source": "native",+ "field_ref": [+ "field",+ "A",+ {+ "base-type": "type/Text"+ }+ ],+ "effective_type": "type/Text",+ "display_name": "A",+ "base_type": "type/Text"+ },+ {+ "database_type": "CHARACTER VARYING",+ "lib/deduplicated-name": "B",+ "lib/original-name": "B",+ "name": "B",+ "lib/source": "source/native",+ "source": "native",+ "field_ref": [+ "field",+ "B",+ {+ "base-type": "type/Text"+ }+ ],+ "effective_type": "type/Text",+ "display_name": "B",+ "base_type": "type/Text"+ }+ ],+ "native_form": {+ "params": null,+ "query": "select 'big spaces gap' a, 'lorem' b\nunion all select '_ _', 'Lorem ipsum dolor sit amet'"+ },+ "is_sandboxed": false,+ "insights": null+ },+ "cached": null,+ "database_id": 1,+ "started_at": "2025-08-21T18:15:32.527977-03:00",+ "json_query": {+ "database": 1,+ "type": "native",+ "native": {+ "template-tags": {},+ "query": "select 'big spaces gap' a, 'lorem' b\nunion all select '_ _', 'Lorem ipsum dolor sit amet'\n"+ },+ "middleware": {+ "js-int-to-string?": true,+ "userland-query?": true,+ "add-default-userland-constraints?": true+ }+ },+ "average_execution_time": null,+ "status": "completed",+ "context": "ad-hoc",+ "row_count": 2,+ "running_time": 24,+ "card": {+ "collection_id": null,+ "creationType": "native_question",+ "dataset_query": {+ "database": 1,+ "type": "native",+ "native": {+ "template-tags": {},+ "query": "select 'big spaces gap' a, 'lorem' b\nunion all select '_ _', 'Lorem ipsum dolor sit amet'\n"+ }+ },+ "display": "table",+ "type": "question",+ "visualization_settings": {+ "column_settings": {+ "[\"name\",\"A\"]": {+ "preserve_whitespace": true,+ "text_wrapping": true+ },+ "[\"name\",\"B\"]": {+ "preserve_whitespace": true,+ "text_wrapping": true+ }+ },+ "table.column_widths": [108, 99]+ },+ "parameters": []+ }+ }+]