Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Add metrics to button (part of #508) #582

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions gui/web/src/components/atoms/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import classNames from 'classnames';
import styles from './Button.module.scss';
import Icon from '../Icon/Icon';
import LoadingAnimation from '../LoadingAnimation/LoadingAnimation';
import sendMetricEvent from '../../../kelp-ops-api/sendMetricEvent';

const iconSizes = {
small:'10px',
Expand All @@ -18,14 +19,24 @@ const iconSizesRound = {
}

class Button extends Component {
constructor(props) {
super(props);
this.trackOnClick = this.trackOnClick.bind(this);
this.sendMetricEvent = this.sendMetricEvent.bind(this);

this._asyncRequests = {};
}

static defaultProps = {
icon: null,
size: 'medium',
variant: '',
hsize: 'regular',
loading: false,
onClick: () => {},
disabled: false
disabled: false,
trackEvent: (eventName, values) => {},
eventName: '',
nikhilsaraf marked this conversation as resolved.
Show resolved Hide resolved
}

static propTypes = {
Expand All @@ -34,8 +45,34 @@ class Button extends Component {
variant: PropTypes.string,
onClick: PropTypes.func,
loading: PropTypes.bool,
disabled: PropTypes.bool
disabled: PropTypes.bool,
trackEvent: PropTypes.func,
nikhilsaraf marked this conversation as resolved.
Show resolved Hide resolved
eventName: PropTypes.string,
};

sendMetricEvent() {
if (this._asyncRequests["sendMetricEvent"]) {
return
}

nikhilsaraf marked this conversation as resolved.
Show resolved Hide resolved
var _this = this
// TODO DS populate the eventData.
nikhilsaraf marked this conversation as resolved.
Show resolved Hide resolved
this._asyncRequests["sendMetricEvent"] = sendMetricEvent(this.props.baseUrl, this.props.eventName, {}).then(resp => {
if (!_this._asyncRequests["sendMetricEvent"]) {
// if it has been deleted it means we don't want to process the result
return
}

delete _this._asyncRequests["sendMetricEvent"];

// TODO DS Determine how to process resp
nikhilsaraf marked this conversation as resolved.
Show resolved Hide resolved
})
}

trackOnClick() {
this.props.onClick()
this.sendMetricEvent()
}

render() {
const iconOnly = this.props.children ? null : styles.iconOnly;
Expand All @@ -57,7 +94,7 @@ class Button extends Component {
<button
className={classNameList}
disabled={this.props.disabled || this.props.loading }
onClick= {this.props.onClick}
onClick={this.trackOnClick}
>
{this.props.loading &&
<span className={styles.loader}>
Expand Down