Skip to content
Snippets Groups Projects
Unverified Commit 793cb968 authored by Paul Rosenzweig's avatar Paul Rosenzweig Committed by GitHub
Browse files

Only show object detail for single rows (#11209)

parent 0c4881cd
Branches
Tags
No related merge requests found
......@@ -18,6 +18,7 @@ export const TEMPORAL = "TEMPORAL";
export const LOCATION = "LOCATION";
export const COORDINATE = "COORDINATE";
export const FOREIGN_KEY = "FOREIGN_KEY";
export const PRIMARY_KEY = "PRIMARY_KEY";
// other types used for various purporses
export const ENTITY = "ENTITY";
......@@ -60,6 +61,9 @@ const TYPES = {
[FOREIGN_KEY]: {
special: [TYPE.FK],
},
[PRIMARY_KEY]: {
special: [TYPE.PK],
},
[SUMMABLE]: {
include: [NUMBER],
exclude: [ENTITY, LOCATION, TEMPORAL],
......@@ -119,6 +123,7 @@ export function getFieldType(field) {
LOCATION,
COORDINATE,
FOREIGN_KEY,
PRIMARY_KEY,
NUMBER,
STRING,
STRING_LIKE,
......@@ -410,6 +415,7 @@ const FILTER_OPERATORS_BY_TYPE_ORDERED = {
{ name: "not-null", verboseName: t`Not empty` },
],
[FOREIGN_KEY]: DEFAULT_FILTER_OPERATORS,
[PRIMARY_KEY]: DEFAULT_FILTER_OPERATORS,
[UNKNOWN]: DEFAULT_FILTER_OPERATORS,
};
......
......@@ -33,21 +33,23 @@ export function getMode(question: ?Question): ?QueryMode {
const filters = query.filters();
if (aggregations.length === 0 && breakouts.length === 0) {
const isPKFilter = filter => {
const isPKFilterWithOneID = filter => {
if (filter.isFieldFilter()) {
const field = filter.field();
if (
field &&
field.isPK() &&
field.table &&
field.table.id === query.sourceTableId()
field.table.id === query.sourceTableId() &&
filter.operatorName() === "=" &&
filter.arguments().length === 1
) {
return true;
}
}
return false;
};
if (filters.some(isPKFilter)) {
if (filters.some(isPKFilterWithOneID)) {
return ObjectMode;
} else {
return SegmentMode;
......
......@@ -7,6 +7,7 @@ import {
BOOLEAN,
LOCATION,
COORDINATE,
PRIMARY_KEY,
foreignKeyCountsByOriginTable,
} from "metabase/lib/schema_metadata";
......@@ -48,6 +49,11 @@ describe("schema_metadata", () => {
getFieldType({ base_type: TYPE.Text, special_type: TYPE.URL }),
).toEqual(STRING);
});
it("should know a pk", () => {
expect(
getFieldType({ base_type: TYPE.Integer, special_type: TYPE.PK }),
).toEqual(PRIMARY_KEY);
});
it("should know a bool", () => {
expect(getFieldType({ base_type: TYPE.Boolean })).toEqual(BOOLEAN);
});
......
import { getMode } from "metabase/modes/lib/modes";
import ObjectMode from "metabase/modes/components/modes/ObjectMode";
import SegmentMode from "metabase/modes/components/modes/SegmentMode";
import { ORDERS } from "__support__/sample_dataset_fixture";
describe("modes", () => {
describe("getMode", () => {
it("should be in object mode when selecting one PK ID", () => {
const filter = ["=", ["field-id", ORDERS.ID.id], 42];
const query = ORDERS.query().filter(filter);
const question = ORDERS.question().setQuery(query);
expect(getMode(question)).toBe(ObjectMode);
});
it("should be in segment mode when selecting multiple PK IDs", () => {
const filter = ["=", ["field-id", ORDERS.ID.id], 42, 24];
const query = ORDERS.query().filter(filter);
const question = ORDERS.question().setQuery(query);
expect(getMode(question)).toBe(SegmentMode);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment