|
1 | 1 | import { utils } from '@monkvision/toolkit';
|
| 2 | +import { useMonitoring, MonitoringStatus, SentryTransaction, SentryOperation, SentryTag } from '@monkvision/corejs'; |
2 | 3 | import PropTypes from 'prop-types';
|
3 |
| -import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useState } from 'react'; |
| 4 | +import React, { forwardRef, useCallback, useEffect, useRef, useImperativeHandle, useMemo, useState } from 'react'; |
4 | 5 |
|
5 | 6 | import { useTranslation } from 'react-i18next';
|
6 | 7 | import { ActivityIndicator, Platform, StyleSheet, Text, useWindowDimensions, View } from 'react-native';
|
@@ -122,9 +123,6 @@ const Capture = forwardRef(({
|
122 | 123 | onPictureTaken,
|
123 | 124 | onWarningMessage,
|
124 | 125 | onReady,
|
125 |
| - onRetakeAll, |
126 |
| - onRetakeNeeded, |
127 |
| - onSkipRetake, |
128 | 126 | onStartUploadPicture,
|
129 | 127 | onFinishUploadPicture,
|
130 | 128 | orientationBlockerProps,
|
@@ -156,7 +154,9 @@ const Capture = forwardRef(({
|
156 | 154 | });
|
157 | 155 | const [endTour, setEndTour] = useState(false);
|
158 | 156 | const { height, width } = useWindowDimensions();
|
| 157 | + const { errorHandler, measurePerformance } = useMonitoring(); |
159 | 158 |
|
| 159 | + const captureTourTransRef = useRef({}); |
160 | 160 | const { camera, ref } = combinedRefs.current;
|
161 | 161 | const { current } = sights.state;
|
162 | 162 | const portraitMediaQuery = useMediaQuery({ query: '(orientation: portrait)' });
|
@@ -244,14 +244,25 @@ const Capture = forwardRef(({
|
244 | 244 |
|
245 | 245 | const checkComplianceParams = { compliance, inspectionId, sightId: current.id };
|
246 | 246 | const checkComplianceAsync = useCheckComplianceAsync(checkComplianceParams);
|
| 247 | + const handleCaptureTourFinish = useCallback(() => { |
| 248 | + /** |
| 249 | + * finish 'capture tour' transaction successfully |
| 250 | + * this function will be triggered when 'capture tour' ends |
| 251 | + */ |
| 252 | + if (!enableComplianceCheck) { |
| 253 | + utils.log(['[Event] Capture-Tour sentry transaction finishes']); |
| 254 | + captureTourTransRef.current.transaction.finish(); |
| 255 | + } |
| 256 | + onCaptureTourFinish(); |
| 257 | + }, []); |
247 | 258 | const startUploadAsyncParams = {
|
248 | 259 | inspectionId,
|
249 | 260 | sights,
|
250 | 261 | uploads,
|
251 | 262 | task,
|
252 | 263 | mapTasksToSights,
|
253 | 264 | enableCarCoverage,
|
254 |
| - onFinish: onCaptureTourFinish, |
| 265 | + onFinish: handleCaptureTourFinish, |
255 | 266 | onPictureUploaded,
|
256 | 267 | onWarningMessage,
|
257 | 268 | endTour,
|
@@ -348,6 +359,9 @@ const Capture = forwardRef(({
|
348 | 359 | if (typeof onCloseEarly === 'function') {
|
349 | 360 | onCloseEarly();
|
350 | 361 | }
|
| 362 | + // finish 'capture tour' transaction unsuccessfully |
| 363 | + utils.log(['[Event] Capture-Tour sentry transaction cancels']); |
| 364 | + captureTourTransRef.current.transaction.finish(MonitoringStatus.CANCELLED); |
351 | 365 | setEndTour(true);
|
352 | 366 | }, [setEndTour]);
|
353 | 367 |
|
@@ -377,14 +391,80 @@ const Capture = forwardRef(({
|
377 | 391 | handleCloseCaptureEarly();
|
378 | 392 | }, [setCloseEarlyModalState, handleCloseCaptureEarly]);
|
379 | 393 |
|
| 394 | + const handleComplianceCheckFinish = useCallback(() => { |
| 395 | + /** |
| 396 | + * finish 'capture tour' transaction successfully |
| 397 | + * this function will be triggered only when |
| 398 | + * enableComplianceCheck = true and UploadCenter component is rendered |
| 399 | + */ |
| 400 | + utils.log(['[Event] Capture-Tour sentry transaction finishes']); |
| 401 | + captureTourTransRef.current.transaction.finish(); |
| 402 | + onComplianceCheckFinish(); |
| 403 | + }, []); |
| 404 | + |
| 405 | + const onRetakeAll = useCallback(() => { |
| 406 | + captureTourTransRef.current.hasRetakeCalled = true; |
| 407 | + captureTourTransRef.current.transaction.setTag(SentryTag.IS_RETAKE, 1); |
| 408 | + }, []); |
| 409 | + |
| 410 | + const onSkipRetake = useCallback(() => { |
| 411 | + captureTourTransRef.current.transaction.setTag(SentryTag.IS_SKIP, 1); |
| 412 | + }, []); |
| 413 | + |
| 414 | + const onRetakeNeeded = useCallback(({ retakesNeeded = 0 }) => { |
| 415 | + if (!captureTourTransRef.current.hasRetakeCalled) { |
| 416 | + const { transaction } = captureTourTransRef.current; |
| 417 | + const percentOfNonCompliancePics = ((100 * retakesNeeded) / states.sights.state.ids.length); |
| 418 | + transaction.setTag(SentryTag.RETAKEN_PICTURES, retakesNeeded); |
| 419 | + transaction.setTag(SentryTag.PERCENT_OF_NON_COMPLIANCE_PICS, percentOfNonCompliancePics); |
| 420 | + } |
| 421 | + }, []); |
| 422 | + |
380 | 423 | // END HANDLERS //
|
381 | 424 | // EFFECTS //
|
382 | 425 |
|
| 426 | + useEffect(() => { |
| 427 | + /** |
| 428 | + * create a new transaction with operation name 'Capture Tour' to measure tour performance |
| 429 | + */ |
| 430 | + utils.log(['[Event] Capture-Tour sentry transaction starts']); |
| 431 | + const transaction = measurePerformance( |
| 432 | + SentryTransaction.PICTURE_PROCESSING, |
| 433 | + SentryOperation.CAPTURE_TOUR, |
| 434 | + ); |
| 435 | + // set tags to identify a transation and relate with an inspection |
| 436 | + transaction.setTag(SentryTag.TASK, task); |
| 437 | + transaction.setTag(SentryTag.INSPECTION_ID, inspectionId); |
| 438 | + transaction.setTag(SentryTag.IS_SKIP, 0); |
| 439 | + transaction.setTag(SentryTag.IS_RETAKE, 0); |
| 440 | + transaction.setTag(SentryTag.TAKEN_PICTURES, 0); |
| 441 | + transaction.setTag(SentryTag.RETAKEN_PICTURES, 0); |
| 442 | + captureTourTransRef.current = { |
| 443 | + transaction, |
| 444 | + takenPictures: 0, |
| 445 | + hasRetakeCalled: false, |
| 446 | + }; |
| 447 | + }, []); |
| 448 | + |
383 | 449 | useEffect(() => {
|
384 | 450 | try {
|
| 451 | + /** |
| 452 | + * add takenPictures tag in "Capture Tour" transaction for a tour |
| 453 | + */ |
| 454 | + const takenPicturesLen = Object.values(states.sights.state.takenPictures).length; |
| 455 | + const refObj = captureTourTransRef.current; |
| 456 | + if (takenPicturesLen |
| 457 | + && refObj.transaction |
| 458 | + && !refObj.hasRetakeCalled |
| 459 | + && takenPicturesLen !== refObj.takenPictures |
| 460 | + ) { |
| 461 | + refObj.takenPictures = takenPicturesLen; |
| 462 | + refObj.transaction.setTag(SentryTag.TAKEN_PICTURES, takenPicturesLen); |
| 463 | + } |
385 | 464 | onChange(states, api);
|
386 | 465 | } catch (err) {
|
387 | 466 | log([`Error in \`<Capture />\` \`onChange()\`: ${err}`], 'error');
|
| 467 | + errorHandler(err); |
388 | 468 | throw err;
|
389 | 469 | }
|
390 | 470 | }, [api, onChange, states]);
|
@@ -483,7 +563,7 @@ const Capture = forwardRef(({
|
483 | 563 | <UploadCenter
|
484 | 564 | {...states}
|
485 | 565 | isSubmitting={isSubmitting}
|
486 |
| - onComplianceCheckFinish={onComplianceCheckFinish} |
| 566 | + onComplianceCheckFinish={handleComplianceCheckFinish} |
487 | 567 | onComplianceCheckStart={onComplianceCheckStart}
|
488 | 568 | onRetakeAll={onRetakeAll}
|
489 | 569 | onSkipRetake={onSkipRetake}
|
@@ -676,11 +756,8 @@ Capture.propTypes = {
|
676 | 756 | onPictureTaken: PropTypes.func,
|
677 | 757 | onPictureUploaded: PropTypes.func,
|
678 | 758 | onReady: PropTypes.func,
|
679 |
| - onRetakeAll: PropTypes.func, |
680 |
| - onRetakeNeeded: PropTypes.func, |
681 | 759 | onSettingsChange: PropTypes.func,
|
682 | 760 | onSightsChange: PropTypes.func,
|
683 |
| - onSkipRetake: PropTypes.func, |
684 | 761 | onStartUploadPicture: PropTypes.func,
|
685 | 762 | onUploadsChange: PropTypes.func,
|
686 | 763 | onWarningMessage: PropTypes.func,
|
@@ -789,16 +866,13 @@ Capture.defaultProps = {
|
789 | 866 | onComplianceChange: () => {},
|
790 | 867 | onSettingsChange: () => {},
|
791 | 868 | onSightsChange: () => {},
|
792 |
| - onSkipRetake: () => {}, |
793 | 869 | onUploadsChange: () => {},
|
794 | 870 | onComplianceCheckFinish: () => {},
|
795 | 871 | onComplianceCheckStart: () => {},
|
796 | 872 | onFinishUploadPicture: () => {},
|
797 | 873 | onWarningMessage: () => {},
|
798 | 874 | onReady: () => {},
|
799 | 875 | onStartUploadPicture: () => {},
|
800 |
| - onRetakeAll: () => {}, |
801 |
| - onRetakeNeeded: () => {}, |
802 | 876 | orientationBlockerProps: null,
|
803 | 877 | primaryColor: '#FFF',
|
804 | 878 | resolutionOptions: undefined,
|
|
0 commit comments