Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Adaptive cards instrumentation #849

Merged
merged 4 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
32 changes: 28 additions & 4 deletions src/app/views/query-response/adaptive-cards/AdaptiveCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FormattedMessage, injectIntl } from 'react-intl';
import { connect } from 'react-redux';
import { bindActionCreators, Dispatch } from 'redux';

import { componentNames, telemetry } from '../../../../telemetry';
import { componentNames, eventTypes, telemetry } from '../../../../telemetry';
import { IAdaptiveCardProps } from '../../../../types/adaptivecard';
import { getAdaptiveCard } from '../../../services/actions/adaptive-cards-action-creator';
import { translateMessage } from '../../../utils/translate-messages';
Expand Down Expand Up @@ -99,9 +99,9 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {
this.adaptiveCard!.parse(data);
const renderedCard = this.adaptiveCard!.render();
return (
<Pivot className='pivot-response'>
<Pivot className='pivot-response' onLinkClick={onPivotItemClick}>
<PivotItem
key='card'
itemKey='card'
ariaLabel={translateMessage('card')}
headerText={'Card'}
className={classes.cardStyles}
Expand All @@ -119,7 +119,7 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {
/>
</PivotItem>
<PivotItem
key='templateJSON'
itemKey='templateJSON'
Copy link
Collaborator

@thewahome thewahome Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key name's not consistent with the title of the tab

ariaLabel={translateMessage('JSON Schema')}
headerText={'JSON Schema'}
>
Expand Down Expand Up @@ -154,6 +154,30 @@ class AdaptiveCard extends Component<IAdaptiveCardProps> {
}
}

function onPivotItemClick(item?: PivotItem) {
if (!item) { return; }
const key = item.props.itemKey;
if (key) {
trackTabClickEvent(key);
}
}

function trackTabClickEvent(tabKey: string) {
switch (tabKey) {
case 'templateJSON': {
telemetry.trackEvent(
eventTypes.TAB_CLICK_EVENT,
{
ComponentName: componentNames.JSON_SCHEMA_TAB
});
break;
}
default: {
break;
}
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be no need for the switch case at this point. The telemetry tab click event can be called immediately

function mapStateToProps(state: any) {
return {
card: state.adaptiveCard,
Expand Down
3 changes: 2 additions & 1 deletion src/telemetry/component-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ export const ACCESS_TOKEN_TAB = 'Access token tab';
export const REQUEST_BODY_TAB = 'Request body tab';
export const CODE_SNIPPETS_TAB = 'Code snippets tab';
export const ADAPTIVE_CARDS_TAB = 'Adaptive cards tab';
export const REQUEST_HEADERS_TAB= 'Request headers tab';
export const REQUEST_HEADERS_TAB = 'Request headers tab';
export const EXPAND_RESPONSE_TAB = 'Expand response tab';
export const RESPONSE_PREVIEW_TAB = 'Response preview tab';
export const RESPONSE_HEADERS_TAB = 'Response headers tab';
export const TOOLKIT_COMPONENT_TAB = 'Toolkit component tab';
export const MODIFY_PERMISSIONS_TAB = 'Modify permissions tab';
export const JSON_SCHEMA_TAB = 'JSON schema tab';

// Dropdowns
export const VERSION_CHANGE_DROPDOWN = 'Version change dropdown';
Expand Down