Skip to content

Commit

Permalink
Merge pull request #519 from shahm5/main
Browse files Browse the repository at this point in the history
fetchDevices() and update banner telemetry
  • Loading branch information
shahm5 authored Jul 29, 2022
2 parents 1401453 + c3f0f04 commit 4f17b8e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
15 changes: 12 additions & 3 deletions src/app/api/services/devicesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { DeviceIdentity } from '../models/deviceIdentity';
import { dataPlaneConnectionHelper, dataPlaneResponseHelper, request, DATAPLANE_CONTROLLER_ENDPOINT, DataPlaneRequest } from './dataplaneServiceHelper';
import { getDeviceInterface, getEventHubInterface } from '../shared/interfaceUtils';
import { parseEventHubMessage } from './eventHubMessageHelper';
import { AppInsightsClient } from '../../shared/appTelemetry/appInsightsClient';
import { TELEMETRY_EVENTS } from '../../constants/telemetry';

const PAGE_SIZE = 100;

Expand Down Expand Up @@ -173,6 +175,7 @@ export const fetchDevice = async (parameters: FetchDeviceParameters): Promise<De
return result && result.body;
};

// tslint:disable-next-line:cyclomatic-complexity
export const fetchDevices = async (parameters: FetchDevicesParameters): Promise<DataPlaneResponse<Device[]>> => {
const connectionInformation = await dataPlaneConnectionHelper();
const queryString = buildQueryString(parameters.query);
Expand All @@ -195,9 +198,15 @@ export const fetchDevices = async (parameters: FetchDevicesParameters): Promise<
(dataPlaneRequest.headers as any)[HEADERS.CONTINUATION_TOKEN] = parameters.query.continuationTokens[parameters.query.currentPageIndex]; // tslint:disable-line: no-any
}

const response = await request(DATAPLANE_CONTROLLER_ENDPOINT, dataPlaneRequest);
const result = await dataPlaneResponseHelper(response);
return result;
try {
const response = await request(DATAPLANE_CONTROLLER_ENDPOINT, dataPlaneRequest);
AppInsightsClient.getInstance()?.trackEvent({name: TELEMETRY_EVENTS.FETCH_DEVICES}, {status: response.status.toString(), statusText: response.statusText});
const result = await dataPlaneResponseHelper(response);
return result;
} catch (e) {
AppInsightsClient.getInstance()?.trackEvent({name: TELEMETRY_EVENTS.FETCH_DEVICES}, {status: 'N/A', statusText: e.toString()});
throw (e);
}
};

export const deleteDevices = async (parameters: DeleteDevicesParameters) => {
Expand Down
7 changes: 5 additions & 2 deletions src/app/constants/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export enum TELEMETRY_PAGE_NAMES {

}

export enum TELEMETRY_ACTIONS {
ADD = 'add',
export enum TELEMETRY_EVENTS {
FETCH_DEVICES = 'fetch_devices',
INIT = 'init',
UPDATE_BANNER_DISPLAYED = 'update_banner:displayed',
UPDATE_BANNER_CLICKED = 'update_banner:clicked'
}
16 changes: 14 additions & 2 deletions src/app/home/components/appVersionMessageBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ResourceKeys } from '../../../localization/resourceKeys';
import { fetchLatestReleaseTagName, latestReleaseUrlPath } from '../../api/services/githubService';
import * as packageJson from '../../../../package.json';
import { isNewReleaseVersionHigher } from '../utils/appVersionHelper';
import { AppInsightsClient } from '../../shared/appTelemetry/appInsightsClient';
import { TELEMETRY_EVENTS } from '../../constants/telemetry';

export const AppVersionMessageBar: React.FC = () => {
const { t } = useTranslation();
Expand All @@ -32,13 +34,23 @@ export const AppVersionMessageBar: React.FC = () => {
}
};

const onBannerClicked = () => {
AppInsightsClient.getInstance()?.trackEvent({name: TELEMETRY_EVENTS.UPDATE_BANNER_CLICKED});
};

React.useEffect(() => {
if (hasNewerRelease()) {
AppInsightsClient.getInstance()?.trackEvent({name: TELEMETRY_EVENTS.UPDATE_BANNER_DISPLAYED});
}
}, [hasNewerRelease]); // tslint:disable-line: align

return hasNewerRelease() ?
(
(
<MessageBar
messageBarType={MessageBarType.info}
>
{t(ResourceKeys.deviceLists.messageBar.message, {version: latestReleaseVersion})}
<Link href={latestReleaseUrlPath} target="_blank">
<Link href={latestReleaseUrlPath} target="_blank" onClick={onBannerClicked}>
{t(ResourceKeys.deviceLists.messageBar.link)}
</Link>
</MessageBar>
Expand Down
3 changes: 2 additions & 1 deletion src/app/shared/appTelemetry/appInsightsClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApplicationInsights } from '@microsoft/applicationinsights-web';
import { TELEMETRY_EVENTS } from '../../constants/telemetry';
import { appConfig } from '../../../appConfig/appConfig';
export class AppInsightsClient {
private static instance: ApplicationInsights;
Expand All @@ -11,7 +12,7 @@ export class AppInsightsClient {
} });
try {
appInsights.loadAppInsights();
appInsights.trackEvent({name: `INIT`}, {type: 'init'});
appInsights.trackEvent({name: TELEMETRY_EVENTS.INIT});
AppInsightsClient.instance = appInsights;
} catch (e) {
// tslint:disable-next-line:no-console
Expand Down

0 comments on commit 4f17b8e

Please sign in to comment.