diff --git a/frontend/src/metabase/visualizations/lib/table.js b/frontend/src/metabase/visualizations/lib/table.js index d612533ab495e15d6bd0886dce6ebc0f67d59cfe..8203808bc944ae10cd35f03ef6df5a49e6df4930 100644 --- a/frontend/src/metabase/visualizations/lib/table.js +++ b/frontend/src/metabase/visualizations/lib/table.js @@ -2,7 +2,7 @@ import type { DatasetData, Column } from "metabase/meta/types/Dataset"; import type { ClickObject } from "metabase/meta/types/Visualization"; -import { isNumber } from "metabase/lib/schema_metadata"; +import { isNumber, isCoordinate } from "metabase/lib/schema_metadata"; export function getTableCellClickedObject(data: DatasetData, rowIndex: number, columnIndex: number, isPivoted: boolean): ClickObject { const { rows, cols } = data; @@ -37,6 +37,10 @@ export function getTableCellClickedObject(data: DatasetData, rowIndex: number, c } } +/* + * Returns whether the column should be right-aligned in a table. + * Includes numbers and lat/lon coordinates, but not zip codes, IDs, etc. + */ export function isColumnRightAligned(column: Column) { - return isNumber(column); + return isNumber(column) || isCoordinate(column); } diff --git a/frontend/src/metabase/visualizations/lib/table.spec.js b/frontend/src/metabase/visualizations/lib/table.spec.js index 9e89fa2f791c8f8758e4ca9074d1e67f264f3a6c..8b12d8c8480601951420d4273a8e93e889173607 100644 --- a/frontend/src/metabase/visualizations/lib/table.spec.js +++ b/frontend/src/metabase/visualizations/lib/table.spec.js @@ -1,4 +1,5 @@ -import { getTableCellClickedObject } from "./table"; +import { getTableCellClickedObject, isColumnRightAligned } from "./table"; +import { TYPE } from "metabase/lib/types"; const RAW_COLUMN = { source: "fields" @@ -40,4 +41,24 @@ describe("metabase/visualization/lib/table", () => { // TODO: }) }) + + describe("isColumnRightAligned", () => { + it("should return true for numeric columns without a special type", () => { + expect(isColumnRightAligned({ base_type: TYPE.Integer })).toBe(true); + }); + it("should return true for numeric columns with special type Number", () => { + expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.Number })).toBe(true); + }); + it("should return true for numeric columns with special type latitude or longitude ", () => { + expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.Latitude })).toBe(true); + expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.Longitude })).toBe(true); + }); + it("should return false for numeric columns with special type zip code", () => { + expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.ZipCode })).toBe(false) + }); + it("should return false for numeric columns with special type FK or PK", () => { + expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.FK })).toBe(false); + expect(isColumnRightAligned({ base_type: TYPE.Integer, special_type: TYPE.FK })).toBe(false); + }); + }) })