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

Merge branch 'master' of github.com:metabase/metabase into saved-questions

parents 2f12eb25 4aa82e4c
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ import SavedQuestionsApp from './containers/SavedQuestionsApp.jsx';
import { createStore, combineReducers } from "metabase/lib/redux";
import _ from "underscore";
import i from "icepick";
import moment from "moment";
import MetabaseAnalytics from "metabase/lib/analytics";
import DataGrid from "metabase/lib/data_grid";
......@@ -244,6 +245,7 @@ CardControllers.controller('CardDetail', [
// run it
setCard(newCard);
MetabaseAnalytics.trackEvent("QueryBuilder", "Table Cell Click", "PK");
} else if (coldef.special_type === "fk") {
// action is on an FK column
let newCard = startNewCard("query", card.dataset_query.database);
......@@ -255,13 +257,34 @@ CardControllers.controller('CardDetail', [
// run it
setCard(newCard);
MetabaseAnalytics.trackEvent("QueryBuilder", "Table Cell Click", "FK");
} else {
// this is applying a filter by clicking on a cell value
let dataset_query = angular.copy(card.dataset_query);
Query.addFilter(dataset_query.query);
Query.updateFilter(dataset_query.query, dataset_query.query.filter.length - 1, [filter, coldef.id, value]);
if (coldef.unit) {
// this is someone using quick filters on a datetime value
let start = moment(value).format("YYYY-MM-DD");
let end = start;
switch(coldef.unit) {
case "week": end = moment(value).add(1, "weeks").subtract(1, "days").format("YYYY-MM-DD"); break;
case "month": end = moment(value).add(1, "months").subtract(1, "days").format("YYYY-MM-DD"); break;
case "quarter": end = moment(value).add(1, "quarters").subtract(1, "days").format("YYYY-MM-DD"); break;
case "year": start = moment(value, "YYYY").format("YYYY-MM-DD");
end = moment(value, "YYYY").add(1, "years").subtract(1, "days").format("YYYY-MM-DD"); break;
}
Query.updateFilter(dataset_query.query, dataset_query.query.filter.length - 1, ["BETWEEN", coldef.id, start, end]);
} else {
// quick filtering on a normal value (string/number)
Query.updateFilter(dataset_query.query, dataset_query.query.filter.length - 1, [filter, coldef.id, value]);
}
onQueryChanged(dataset_query);
runQuery();
MetabaseAnalytics.trackEvent("QueryBuilder", "Table Cell Click", "Quick Filter");
}
},
followForeignKeyFn: function(fk) {
......
......@@ -78,6 +78,8 @@ function formatTimeWithUnit(value, unit, options = {}) {
return moment().week(value).format("wo");
case "month-of-year": // January
return moment().month(value - 1).format("MMMM");
case "quarter-of-year": // January
return moment().quarter(value).format("[Q]Q");
default:
return m.format("LLLL");
}
......
......@@ -91,6 +91,9 @@ export default class BreakoutWidget extends Component {
{this.renderPopover()}
</div>
);
} else {
// this needs to be here to prevent React error (#2304)
return null;
}
}
}
......@@ -3,8 +3,8 @@ import React, { Component, PropTypes } from "react";
import Icon from "metabase/components/Icon.jsx";
import Query from "metabase/lib/query";
import { parseFieldTarget } from "metabase/lib/query_time";
import { formatBucketing, parseFieldBucketing, parseFieldTarget } from "metabase/lib/query_time";
import { isDate } from "metabase/lib/schema_metadata";
import { stripId } from "metabase/lib/formatting";
import _ from "underscore";
......@@ -27,6 +27,7 @@ export default class FieldName extends Component {
let targetTitle, fkTitle, fkIcon, bucketingTitle;
let { field, fieldOptions } = this.props;
let bucketing = parseFieldBucketing(field);
field = parseFieldTarget(field);
let fieldDef;
......@@ -47,6 +48,11 @@ export default class FieldName extends Component {
targetTitle = (<span>{fieldDef.display_name}</span>);
}
// if this is a datetime field then add an extra bit of labeling about the time bucket
if (fieldDef && isDate(fieldDef)) {
bucketingTitle = ": " + formatBucketing(bucketing);
}
var titleElement;
if (fkTitle || targetTitle) {
titleElement = <span className="QueryOption">{fkTitle}{fkIcon}{targetTitle}{bucketingTitle}</span>;
......
......@@ -21,7 +21,7 @@ const BUCKETINGS = [
// "day-of-year",
"week-of-year",
"month-of-year",
// "quarter-of-year",
"quarter-of-year",
];
export default class TimeGroupingPopover extends Component {
......
......@@ -316,11 +316,16 @@
(defn- render:sparkline
[_ {:keys [rows cols]}]
(let [xs (for [row rows
(let [ft-row (if (datetime-field? (first cols))
#(.getTime ^Date (u/->Timestamp %))
identity)
rows (if (> (ft-row (first (first rows)))
(ft-row (first (last rows))))
(reverse rows)
rows)
xs (for [row rows
:let [x (first row)]]
(if (datetime-field? (first cols))
(.getTime ^Date (u/->Timestamp x))
x))
(ft-row x))
xmin (apply min xs)
xmax (apply max xs)
xrange (- xmax xmin)
......
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