Skip to content
Snippets Groups Projects
Unverified Commit 6725c0cf authored by Ariya Hidayat's avatar Ariya Hidayat Committed by GitHub
Browse files

Make temporal fields selectable for max/min summary (#18135)

parent e6023765
Branches
Tags
No related merge requests found
......@@ -16,6 +16,7 @@ import {
isBoolean,
isString,
isSummable,
isScope,
isCategory,
isAddress,
isCity,
......@@ -120,6 +121,9 @@ export default class Field extends Base {
isSummable() {
return isSummable(this);
}
isScope() {
return isScope(this);
}
isCategory() {
return isCategory(this);
}
......
......@@ -21,6 +21,7 @@ export const PRIMARY_KEY = "PRIMARY_KEY";
// other types used for various purporses
export const ENTITY = "ENTITY";
export const SUMMABLE = "SUMMABLE";
export const SCOPE = "SCOPE";
export const CATEGORY = "CATEGORY";
export const DIMENSION = "DIMENSION";
......@@ -71,6 +72,10 @@ const TYPES = {
include: [NUMBER],
exclude: [ENTITY, LOCATION, TEMPORAL],
},
[SCOPE]: {
include: [NUMBER, TEMPORAL],
exclude: [ENTITY, LOCATION],
},
[CATEGORY]: {
base: [TYPE.Boolean],
effective: [TYPE.Boolean],
......@@ -147,6 +152,7 @@ export const isNumeric = isFieldType.bind(null, NUMBER);
export const isBoolean = isFieldType.bind(null, BOOLEAN);
export const isString = isFieldType.bind(null, STRING);
export const isSummable = isFieldType.bind(null, SUMMABLE);
export const isScope = isFieldType.bind(null, SCOPE);
export const isCategory = isFieldType.bind(null, CATEGORY);
export const isLocation = isFieldType.bind(null, LOCATION);
......@@ -578,6 +584,10 @@ function summableFields(fields) {
return _.filter(fields, isSummable);
}
function scopeFields(fields) {
return _.filter(fields, isScope);
}
const AGGREGATION_OPERATORS = [
{
// DEPRECATED: "rows" is equivalent to no aggregations
......@@ -656,7 +666,7 @@ const AGGREGATION_OPERATORS = [
name: t`Minimum of ...`,
columnName: t`Min`,
description: t`Minimum value of a column`,
validFieldsFilters: [summableFields],
validFieldsFilters: [scopeFields],
requiresField: true,
requiredDriverFeature: "basic-aggregations",
},
......@@ -665,7 +675,7 @@ const AGGREGATION_OPERATORS = [
name: t`Maximum of ...`,
columnName: t`Max`,
description: t`Maximum value of a column`,
validFieldsFilters: [summableFields],
validFieldsFilters: [scopeFields],
requiresField: true,
requiredDriverFeature: "basic-aggregations",
},
......
import { restore } from "__support__/e2e/cypress";
describe("issue 4482", () => {
beforeEach(() => {
cy.intercept("POST", "/api/dataset").as("dataset");
restore();
cy.signInAsAdmin();
});
it("should be possible to summarize min of a temporal column (metabase#6239)", () => {
cy.visit("/question/new");
cy.contains("Custom question").click();
cy.contains("Sample Dataset").click();
cy.contains("Products").click();
cy.contains("Pick the metric").click();
cy.contains("Minimum of").click();
cy.findByText("Price");
cy.findByText("Rating");
cy.contains("Created At").click();
cy.button("Visualize").click();
cy.wait("@dataset");
cy.findByText("April 1, 2016, 12:00 AM");
});
it("should be possible to summarize max of a temporal column (metabase#6239)", () => {
cy.visit("/question/new");
cy.contains("Custom question").click();
cy.contains("Sample Dataset").click();
cy.contains("Products").click();
cy.contains("Pick the metric").click();
cy.contains("Maximum of").click();
cy.findByText("Price");
cy.findByText("Rating");
cy.contains("Created At").click();
cy.button("Visualize").click();
cy.wait("@dataset");
cy.findByText("April 1, 2019, 12:00 AM");
});
it("should be not possible to average a temporal column (metabase#6239)", () => {
cy.visit("/question/new");
cy.contains("Custom question").click();
cy.contains("Sample Dataset").click();
cy.contains("Products").click();
cy.contains("Pick the metric").click();
cy.contains("Average of").click();
cy.findByText("Price");
cy.findByText("Rating");
cy.findByText("Created At").should("not.exist");
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment