From a6f32306eabd0e333ae98f65c188824180c8217a Mon Sep 17 00:00:00 2001 From: Kyle Doherty <kyle.l.doherty@gmail.com> Date: Mon, 5 Feb 2018 15:15:43 -0800 Subject: [PATCH] consolidate instrumentation logic, fix props validation --- .../pulse/components/PulseCardPreview.jsx | 6 ++--- .../pulse/components/PulseEditCards.jsx | 23 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/frontend/src/metabase/pulse/components/PulseCardPreview.jsx b/frontend/src/metabase/pulse/components/PulseCardPreview.jsx index 4d2c51e0fbe..d225b0e8f42 100644 --- a/frontend/src/metabase/pulse/components/PulseCardPreview.jsx +++ b/frontend/src/metabase/pulse/components/PulseCardPreview.jsx @@ -6,7 +6,6 @@ import PropTypes from "prop-types"; import Icon from "metabase/components/Icon.jsx"; import LoadingSpinner from "metabase/components/LoadingSpinner.jsx"; import Tooltip from "metabase/components/Tooltip.jsx"; -import MetabaseAnalytics from "metabase/lib/analytics"; import { t } from "c-3po"; import cx from "classnames"; @@ -23,6 +22,7 @@ export default class PulseCardPreview extends Component { onRemove: PropTypes.func.isRequired, fetchPulseCardPreview: PropTypes.func.isRequired, attachmentsEnabled: PropTypes.bool, + trackPulseEvent: PropTypes.func.isRequired }; componentWillMount() { @@ -48,11 +48,11 @@ export default class PulseCardPreview extends Component { if (this.hasAttachment()) { onChange({ ...card, include_csv: false, include_xls: false }) - MetabaseAnalytics.trackEvent((this.props.pulseId) ? "PulseEdit" : "PulseCreate", "RemoveAttachment"); + this.props.trackPulseEvent("RemoveAttachment") } else { onChange({ ...card, include_csv: true }) - MetabaseAnalytics.trackEvent((this.props.pulseId) ? "PulseEdit" : "PulseCreate", "AddAttachment", 'csv'); + this.props.trackPulseEvent("AddAttachment", 'csv') } } diff --git a/frontend/src/metabase/pulse/components/PulseEditCards.jsx b/frontend/src/metabase/pulse/components/PulseEditCards.jsx index f19e7b6d2c0..10f8b5c2c68 100644 --- a/frontend/src/metabase/pulse/components/PulseEditCards.jsx +++ b/frontend/src/metabase/pulse/components/PulseEditCards.jsx @@ -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) { this.setCard(index, { id: cardId }) - - MetabaseAnalytics.trackEvent((this.props.pulseId) ? "PulseEdit" : "PulseCreate", "AddCard", index); + this.trackPulseEvent("AddCard", index); } removeCard(index) { @@ -51,7 +58,7 @@ export default class PulseEditCards extends Component { cards: [...pulse.cards.slice(0, index), ...pulse.cards.slice(index + 1)] }); - MetabaseAnalytics.trackEvent((this.props.pulseId) ? "PulseEdit" : "PulseCreate", "RemoveCard", index); + this.trackPulseEvent("RmoveCard", index); } getNotices(card, cardPreview, index) { @@ -61,7 +68,7 @@ export default class PulseEditCards extends Component { if (hasAttachment) { notices.push({ head: t`Attachment`, - body: <AttachmentWidget card={card} onChange={(card) => this.setCard(index, card)} index={index} pulseId={this.props.pulseId} /> + body: <AttachmentWidget card={card} onChange={(card) => this.setCard(index, card)} trackPulseEvent={this.trackPulseEvent} /> }); } if (cardPreview) { @@ -128,13 +135,13 @@ export default class PulseEditCards extends Component { <span className="h3 text-bold mr1 mt2">{index + 1}.</span> { card ? <PulseCardPreview - pulseId={this.props.pulseId} card={card} cardPreview={cardPreviews[card.id]} onChange={this.setCard.bind(this, index)} onRemove={this.removeCard.bind(this, index)} fetchPulseCardPreview={this.props.fetchPulseCardPreview} attachmentsEnabled={this.props.attachmentsEnabled} + trackPulseEvent={this.trackPulseEvent} /> : <CardPicker @@ -156,7 +163,7 @@ export default class PulseEditCards extends Component { const ATTACHMENT_TYPES = ["csv", "xls"]; -const AttachmentWidget = ({ card, onChange, pulseId }) => +const AttachmentWidget = ({ card, onChange, trackPulseEvent }) => <div> { ATTACHMENT_TYPES.map(type => <span @@ -168,7 +175,7 @@ const AttachmentWidget = ({ card, onChange, pulseId }) => newCard["include_" + attachmentType] = type === attachmentType; } - MetabaseAnalytics.trackEvent((pulseId) ? "PulseEdit" : "PulseCreate", "AttachmentTypeChanged", type); + trackPulseEvent("AttachmentTypeChanged", type); onChange(newCard) }} > @@ -180,5 +187,5 @@ const AttachmentWidget = ({ card, onChange, pulseId }) => AttachmentWidget.propTypes = { card: PropTypes.object.isRequired, onChange: PropTypes.func.isRequired, - pulseId: PropTypes.number + trackPulseEvent: PropTypes.func.isRequired } -- GitLab