Skip to content
Snippets Groups Projects
Commit 50568cc5 authored by Sameer Al-Sakran's avatar Sameer Al-Sakran
Browse files

Merge branch 'master' into update-dataselector-properly

parents a6ea8bb5 9277e555
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,7 @@ export default class PulseCardPreview extends Component { ...@@ -22,6 +22,7 @@ export default class PulseCardPreview extends Component {
onRemove: PropTypes.func.isRequired, onRemove: PropTypes.func.isRequired,
fetchPulseCardPreview: PropTypes.func.isRequired, fetchPulseCardPreview: PropTypes.func.isRequired,
attachmentsEnabled: PropTypes.bool, attachmentsEnabled: PropTypes.bool,
trackPulseEvent: PropTypes.func.isRequired
}; };
componentWillMount() { componentWillMount() {
...@@ -46,8 +47,12 @@ export default class PulseCardPreview extends Component { ...@@ -46,8 +47,12 @@ export default class PulseCardPreview extends Component {
const { card, onChange } = this.props; const { card, onChange } = this.props;
if (this.hasAttachment()) { if (this.hasAttachment()) {
onChange({ ...card, include_csv: false, include_xls: false }) onChange({ ...card, include_csv: false, include_xls: false })
this.props.trackPulseEvent("RemoveAttachment")
} else { } else {
onChange({ ...card, include_csv: true }) onChange({ ...card, include_csv: true })
this.props.trackPulseEvent("AddAttachment", 'csv')
} }
} }
......
...@@ -38,10 +38,17 @@ export default class PulseEditCards extends Component { ...@@ -38,10 +38,17 @@ export default class PulseEditCards extends Component {
}); });
} }
trackPulseEvent = (eventName: string, eventValue: string) => {
MetabaseAnalytics.trackEvent(
(this.props.pulseId) ? "PulseEdit" : "PulseCreate",
eventName,
eventValue
);
}
addCard(index, cardId) { addCard(index, cardId) {
this.setCard(index, { id: cardId }) this.setCard(index, { id: cardId })
this.trackPulseEvent("AddCard", index);
MetabaseAnalytics.trackEvent((this.props.pulseId) ? "PulseEdit" : "PulseCreate", "AddCard", index);
} }
removeCard(index) { removeCard(index) {
...@@ -51,7 +58,7 @@ export default class PulseEditCards extends Component { ...@@ -51,7 +58,7 @@ export default class PulseEditCards extends Component {
cards: [...pulse.cards.slice(0, index), ...pulse.cards.slice(index + 1)] cards: [...pulse.cards.slice(0, index), ...pulse.cards.slice(index + 1)]
}); });
MetabaseAnalytics.trackEvent((this.props.pulseId) ? "PulseEdit" : "PulseCreate", "RemoveCard", index); this.trackPulseEvent("RemoveCard", index);
} }
getNotices(card, cardPreview, index) { getNotices(card, cardPreview, index) {
...@@ -61,7 +68,7 @@ export default class PulseEditCards extends Component { ...@@ -61,7 +68,7 @@ export default class PulseEditCards extends Component {
if (hasAttachment) { if (hasAttachment) {
notices.push({ notices.push({
head: t`Attachment`, head: t`Attachment`,
body: <AttachmentWidget card={card} onChange={(card) => this.setCard(index, card)} /> body: <AttachmentWidget card={card} onChange={(card) => this.setCard(index, card)} trackPulseEvent={this.trackPulseEvent} />
}); });
} }
if (cardPreview) { if (cardPreview) {
...@@ -134,6 +141,7 @@ export default class PulseEditCards extends Component { ...@@ -134,6 +141,7 @@ export default class PulseEditCards extends Component {
onRemove={this.removeCard.bind(this, index)} onRemove={this.removeCard.bind(this, index)}
fetchPulseCardPreview={this.props.fetchPulseCardPreview} fetchPulseCardPreview={this.props.fetchPulseCardPreview}
attachmentsEnabled={this.props.attachmentsEnabled} attachmentsEnabled={this.props.attachmentsEnabled}
trackPulseEvent={this.trackPulseEvent}
/> />
: :
<CardPicker <CardPicker
...@@ -155,7 +163,7 @@ export default class PulseEditCards extends Component { ...@@ -155,7 +163,7 @@ export default class PulseEditCards extends Component {
const ATTACHMENT_TYPES = ["csv", "xls"]; const ATTACHMENT_TYPES = ["csv", "xls"];
const AttachmentWidget = ({ card, onChange }) => const AttachmentWidget = ({ card, onChange, trackPulseEvent }) =>
<div> <div>
{ ATTACHMENT_TYPES.map(type => { ATTACHMENT_TYPES.map(type =>
<span <span
...@@ -166,6 +174,8 @@ const AttachmentWidget = ({ card, onChange }) => ...@@ -166,6 +174,8 @@ const AttachmentWidget = ({ card, onChange }) =>
for (const attachmentType of ATTACHMENT_TYPES) { for (const attachmentType of ATTACHMENT_TYPES) {
newCard["include_" + attachmentType] = type === attachmentType; newCard["include_" + attachmentType] = type === attachmentType;
} }
trackPulseEvent("AttachmentTypeChanged", type);
onChange(newCard) onChange(newCard)
}} }}
> >
...@@ -176,5 +186,6 @@ const AttachmentWidget = ({ card, onChange }) => ...@@ -176,5 +186,6 @@ const AttachmentWidget = ({ card, onChange }) =>
AttachmentWidget.propTypes = { AttachmentWidget.propTypes = {
card: PropTypes.object.isRequired, card: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired onChange: PropTypes.func.isRequired,
trackPulseEvent: PropTypes.func.isRequired
} }
...@@ -104,7 +104,6 @@ describe("QueryBuilder", () => { ...@@ -104,7 +104,6 @@ describe("QueryBuilder", () => {
} }
})); }));
click(qb.find(RunButton)); click(qb.find(RunButton));
await store.waitForActions([QUERY_COMPLETED]); await store.waitForActions([QUERY_COMPLETED]);
...@@ -112,7 +111,9 @@ describe("QueryBuilder", () => { ...@@ -112,7 +111,9 @@ describe("QueryBuilder", () => {
const firstRowCells = table.find("tbody tr").first().find("td"); const firstRowCells = table.find("tbody tr").first().find("td");
expect(firstRowCells.length).toBe(2); expect(firstRowCells.length).toBe(2);
expect(firstRowCells.first().text()).toBe("4 – 6"); // NOTE: Commented out due to the randomness involved in sample dataset generation
// which sometimes causes the cell value to be different
// expect(firstRowCells.first().text()).toBe("4 – 6");
const countCell = firstRowCells.last(); const countCell = firstRowCells.last();
expect(countCell.text()).toBe("2"); expect(countCell.text()).toBe("2");
...@@ -220,6 +221,10 @@ describe("QueryBuilder", () => { ...@@ -220,6 +221,10 @@ describe("QueryBuilder", () => {
// Should have visualization type set to the previous visualization // Should have visualization type set to the previous visualization
const card = getCard(store.getState()) const card = getCard(store.getState())
expect(card.display).toBe("bar"); expect(card.display).toBe("bar");
// Some part of visualization seems to be asynchronous, causing a cluster of errors
// about missing query results if this delay isn't present
await delay(100)
}); });
}) })
}) })
......
...@@ -63,10 +63,10 @@ ...@@ -63,10 +63,10 @@
;;; ### breakout ;;; ### breakout
(defn- first-aggregation [{aggregations :aggregation}] (defn- aggregations [{aggregations :aggregation}]
(if (every? sequential? aggregations) (if (every? sequential? aggregations)
(first aggregations) aggregations
aggregations)) [aggregations]))
(defn- unit->ga-dimension (defn- unit->ga-dimension
[unit] [unit]
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
:descending "-") :descending "-")
(cond (cond
(instance? DateTimeField field) (unit->ga-dimension (:unit field)) (instance? DateTimeField field) (unit->ga-dimension (:unit field))
(instance? AgFieldRef field) (second (first-aggregation query)) ; aggregation is of format [ag-type metric-name]; get the metric-name (instance? AgFieldRef field) (second (nth (aggregations query) (:index field))) ; aggregation is of format [ag-type metric-name]; get the metric-name
:else (->rvalue field)))))})) :else (->rvalue field)))))}))
;;; ### limit ;;; ### limit
...@@ -249,11 +249,12 @@ ...@@ -249,11 +249,12 @@
(defn- built-in-metrics (defn- built-in-metrics
[{query :query}] [{query :query}]
(let [[aggregation-type metric-name] (first-aggregation query)] (if-not (empty? (aggregations query))
(when (and aggregation-type (s/join "," (for [[aggregation-type metric-name] (aggregations query)
(= :metric (qputil/normalize-token aggregation-type)) :when (and aggregation-type
(string? metric-name)) (= :metric (qputil/normalize-token aggregation-type))
metric-name))) (string? metric-name))]
metric-name))))
(defn- handle-built-in-metrics [query] (defn- handle-built-in-metrics [query]
(-> query (-> query
......
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