Skip to content
Snippets Groups Projects
Unverified Commit bc264fb4 authored by Tom Robinson's avatar Tom Robinson
Browse files

Right align lat/lon. Add tests

parent 766f7537
No related merge requests found
......@@ -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);
}
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);
});
})
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment