Skip to content

Commit

Permalink
Track prior notification card download button enabling time
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangabriele committed Sep 4, 2024
1 parent 119c10f commit 8912d59
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
StatusBodyEnum,
useGetPriorNotificationPdfExistenceQuery
} from '@features/PriorNotification/priorNotificationApi'
import { Accent, Button, customDayjs, Dropdown, Icon } from '@mtes-mct/monitor-ui'
import { customSentry, CustomSentryMeasurementName } from '@libs/customSentry'
import { Accent, Button, customDayjs, Dropdown, Icon, usePrevious } from '@mtes-mct/monitor-ui'
import { downloadAsPdf } from '@utils/downloadAsPdf'
import printJS from 'print-js'
import { useMemo } from 'react'
import { useEffect, useMemo } from 'react'

import { HTML_STYLE } from './template'
import { getHasAuthorizedLandingDownload, getHtmlContent } from './utils'
Expand All @@ -33,6 +34,8 @@ export function DownloadButton({
const getGearsApiQuery = useGetGearsQuery()
const { data } = useGetPriorNotificationPdfExistenceQuery(reportId, RTK_ONE_MINUTE_POLLING_QUERY_OPTIONS)

const wasDisabled = usePrevious(isDisabled)

const isPriorNotificationDocumentAvailable = useMemo(() => data?.status === StatusBodyEnum.FOUND, [data])

const hasAuthorizedLandingDownload =
Expand Down Expand Up @@ -76,6 +79,18 @@ export function DownloadButton({
downloadAsPdf(fileName, blob)
}

useEffect(() => {
if (isDisabled === wasDisabled) {
return
}

if (isDisabled) {
customSentry.startMeasurement(CustomSentryMeasurementName.PRIOR_NOTIFICATION_CARD_DOWNLOAD_BUTTON, reportId)
} else {
customSentry.endMeasurement(CustomSentryMeasurementName.PRIOR_NOTIFICATION_CARD_DOWNLOAD_BUTTON, reportId)
}
}, [isDisabled, reportId, wasDisabled])

return (
<>
{hasAuthorizedLandingDownload && (
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/libs/customSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,25 @@ type CustomSentryMeasurementValue = {
}

export enum CustomSentryMeasurementName {
LOGBOOK_PRIOR_NOTIFICATION_FORM_DOWNLOAD_BUTTON = 'LOGBOOK_PRIOR_NOTIFICATION_FORM_DOWNLOAD_BUTTON',
LOGBOOK_PRIOR_NOTIFICATION_FORM_SPINNER = 'LOGBOOK_PRIOR_NOTIFICATION_FORM_SPINNER',
MANUAL_PRIOR_NOTIFICATION_FORM_DOWNLOAD_BUTTON = 'MANUAL_PRIOR_NOTIFICATION_FORM_DOWNLOAD_BUTTON',
MANUAL_PRIOR_NOTIFICATION_FORM_SPINNER = 'MANUAL_PRIOR_NOTIFICATION_FORM_SPINNER'
MANUAL_PRIOR_NOTIFICATION_FORM_SPINNER = 'MANUAL_PRIOR_NOTIFICATION_FORM_SPINNER',
PRIOR_NOTIFICATION_CARD_DOWNLOAD_BUTTON = 'PRIOR_NOTIFICATION_CARD_DOWNLOAD_BUTTON'
}

class CustomSentry {
mesurements: Map<string, CustomSentryMeasurementValue> = new Map()

clearMeasurement(name: CustomSentryMeasurementName, id: string) {
try {
const key = `${name}-${id}`
if (!this.mesurements.has(key)) {
return
}

this.mesurements.delete(key)
} catch (_) {}
}

startMeasurement(name: CustomSentryMeasurementName, id: string) {
try {
const key = `${name}-${id}`
Expand Down

0 comments on commit 8912d59

Please sign in to comment.