From f7e9d22afe349ea9110003d289fdf7a4a2a5e9ed Mon Sep 17 00:00:00 2001 From: Pjero Nizetic Date: Mon, 4 Dec 2023 13:52:55 +0100 Subject: [PATCH 1/4] Increase refresh rate and fix duplicate api calls --- .gitignore | 3 + src/common/store/response.store.js | 119 +++++++++++++----------- src/pages/processing/processing.js | 40 +++----- src/pages/processing/processing.test.js | 25 +++-- 4 files changed, 99 insertions(+), 88 deletions(-) diff --git a/.gitignore b/.gitignore index 990ff8d..353f8d7 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,9 @@ junit.xml # IDEs, IntelliJ /.idea +# VSCode +/.vscode + /src/excluded .env diff --git a/src/common/store/response.store.js b/src/common/store/response.store.js index f5b1d8f..ee57fa4 100644 --- a/src/common/store/response.store.js +++ b/src/common/store/response.store.js @@ -1,11 +1,11 @@ import { create } from 'zustand'; -import { uploadFile, deleteFromLocation, fetchFromLocation, fetchWithRetries } from 'common/api'; +import { deleteFromLocation, fetchFromLocation, fetchWithRetries, uploadFile } from 'common/api'; import { HTTP_STATUS_CODE } from 'common/constants'; import i18next from 'common/translations/i18n'; +import { useGeometryStore } from './geometry.store'; import { useLayersStore } from './layers.store'; import { useLevelsStore } from './levels.store'; -import { useGeometryStore } from './geometry.store'; import { useProgressBarStore } from './progress-bar-steps'; import { resetStores } from './reset'; import { useReviewManifestStore } from './review-manifest.store'; @@ -28,10 +28,13 @@ export const useResponseStore = create((set, get) => ({ operationLocation: '', lroStatus: '', errorMessage: '', - acknowledgeError: () => set({ - errorMessage: '' - }), - uploadFile: (file) => { + refreshRunning: false, + acknowledgeError: () => { + set({ + errorMessage: '', + }); + }, + uploadFile: file => { set(() => ({ errorMessage: '', lroStatus: LRO_STATUS.UPLOADING, @@ -40,38 +43,48 @@ export const useResponseStore = create((set, get) => ({ useReviewManifestStore.getState().setOriginalPackage(file); uploadFile(file) - .then(async (r) => { - if (r.status !== HTTP_STATUS_CODE.ACCEPTED) { - const data = await r.json(); - const errorMessage = data?.error?.message; - if (errorMessage) { - throw new Error(errorMessage); + .then(async r => { + if (r.status !== HTTP_STATUS_CODE.ACCEPTED) { + const data = await r.json(); + const errorMessage = data?.error?.message; + if (errorMessage) { + throw new Error(errorMessage); + } + throw new Error(i18next.t('error.upload.file')); } - throw new Error(i18next.t('error.upload.file')); - } - // Once accepted by the backend, the response will contain the location of the operation - set(() => ({ - lroStatus: LRO_STATUS.UPLOADED, - operationLocation: r.headers.get(OPERATION_LOCATION), - })); - }) - .catch(({ message }) => { - const errorMsg = message === 'Failed to fetch' ? i18next.t('error.network.issue.cors') : message; - set(() => ({ errorMessage: errorMsg })); - }); + // Once accepted by the backend, the response will contain the location of the operation + set(() => ({ + lroStatus: LRO_STATUS.UPLOADED, + operationLocation: r.headers.get(OPERATION_LOCATION), + })); + }) + .catch(({ message }) => { + const errorMsg = message === 'Failed to fetch' ? i18next.t('error.network.issue.cors') : message; + set(() => ({ errorMessage: errorMsg })); + }); }, // Poll the backend for the status of the upload operation // Uses the operationLocation set by uploadFile() - refreshStatus: () => { + refreshStatus: async () => { const operationLocation = get().operationLocation; - if (operationLocation === '') { + const lroStatus = get().lroStatus; + const refreshRunning = get().refreshRunning; + + if ( + operationLocation === '' || + lroStatus === LRO_STATUS.FETCHING_DATA || + lroStatus === LRO_STATUS.SUCCEEDED || + refreshRunning + ) { return; } - fetchFromLocation(operationLocation) - .then(async (r) => { + set({ refreshRunning: true }); + + await fetchFromLocation(operationLocation) + .then(async r => { const data = await r.json(); if (r.status !== HTTP_STATUS_CODE.OK) { const errorMessage = data?.error?.message; @@ -86,7 +99,7 @@ export const useResponseStore = create((set, get) => ({ fetchUrl: r.headers.get(RESOURCE_LOCATION), }; }) - .then((data) => { + .then(async data => { if (!data || !data.status) { throw new Error(i18next.t('error.upload.file.processing')); } @@ -103,12 +116,11 @@ export const useResponseStore = create((set, get) => ({ } if (data.status === LRO_STATUS.SUCCEEDED) { - if (get().lroStatus !== LRO_STATUS.FETCHING_DATA) { - set(() => ({ - lroStatus: LRO_STATUS.FETCHING_DATA, - })); - get().fetchManifestData(data.fetchUrl); - } + set(() => ({ + lroStatus: LRO_STATUS.FETCHING_DATA, + })); + + await get().fetchManifestData(data.fetchUrl); } }) .catch(({ message }) => { @@ -118,11 +130,13 @@ export const useResponseStore = create((set, get) => ({ lroStatus: LRO_STATUS.FAILED, })); }); + + set({ refreshRunning: false }); }, - fetchManifestData: (fetchUrl) => { - fetchWithRetries(fetchUrl) - .then(async (data) => { + fetchManifestData: async fetchUrl => { + return fetchWithRetries(fetchUrl) + .then(async data => { resetStores(); // Compute and store useful response data @@ -159,11 +173,9 @@ export const useResponseStore = create((set, get) => ({ coordinates: data.anchorPoint, }); - useLayersStore.getState().setLayerNames( - Array.from(layerNames), - Array.from(polygonLayerNames), - Array.from(textLayerNames) - ); + useLayersStore + .getState() + .setLayerNames(Array.from(layerNames), Array.from(polygonLayerNames), Array.from(textLayerNames)); useLevelsStore.getState().setLevels(data.drawings.map(drawing => drawing.fileName)); @@ -183,17 +195,13 @@ export const useResponseStore = create((set, get) => ({ useLayersStore.getState().setLayerFromManifestJson(jsonData.featureClasses); useLayersStore.getState().setVisited(); useGeometryStore.setState({ - dwgLayers: jsonData.dwgLayers.filter((layer) => polygonLayerNames.has(layer)), + dwgLayers: jsonData.dwgLayers.filter(layer => polygonLayerNames.has(layer)), }); useGeometryStore.getState().updateAnchorPoint({ - coordinates: [ - jsonData.georeference.lon, - jsonData.georeference.lat, - ], + coordinates: [jsonData.georeference.lon, jsonData.georeference.lat], angle: jsonData.georeference.angle, }); } - } set(() => ({ @@ -203,7 +211,8 @@ export const useResponseStore = create((set, get) => ({ deleteFromLocation(fetchUrl); }) .catch(({ message }) => { - const errorMsg = message === 'Failed to fetch' ? i18next.t('error.network.issue.cors') : message || defaultErrorMessage; + const errorMsg = + message === 'Failed to fetch' ? i18next.t('error.network.issue.cors') : message || defaultErrorMessage; set(() => ({ errorMessage: errorMsg, lroStatus: LRO_STATUS.FAILED, @@ -228,7 +237,11 @@ export function parseManifestJson(json) { if (!Array.isArray(json.featureClasses)) { return null; } - if (typeof json.georeference?.lon !== 'number' || typeof json.georeference?.lat !== 'number' || typeof json.georeference?.angle !== 'number') { + if ( + typeof json.georeference?.lon !== 'number' || + typeof json.georeference?.lat !== 'number' || + typeof json.georeference?.angle !== 'number' + ) { return null; } @@ -241,7 +254,7 @@ export function parseManifestJson(json) { }; } -export function getFirstMeaningfulError({ error = {}}) { +export function getFirstMeaningfulError({ error = {} }) { if (error.message) { return error.message; } @@ -268,4 +281,4 @@ export function getFirstMeaningfulError({ error = {}}) { } return null; -} \ No newline at end of file +} diff --git a/src/pages/processing/processing.js b/src/pages/processing/processing.js index cc08ac9..24b79dd 100644 --- a/src/pages/processing/processing.js +++ b/src/pages/processing/processing.js @@ -1,31 +1,28 @@ +import { ProgressIndicator } from '@fluentui/react/lib/ProgressIndicator'; +import { PATHS } from 'common'; +import { progressBarStepsByKey, useCompletedSteps, useResponseStore, useUserStore } from 'common/store'; +import { LRO_STATUS } from 'common/store/response.store'; import { useEffect, useState } from 'react'; -import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { ProgressIndicator } from '@fluentui/react/lib/ProgressIndicator'; +import { useNavigate } from 'react-router-dom'; import { shallow } from 'zustand/shallow'; - import { containerStyle, progressIndicatorLabel, progressIndicatorStyles } from './processing.style'; -import { PATHS } from 'common'; -import { useResponseStore, useUserStore, useCompletedSteps, progressBarStepsByKey } from 'common/store'; -import { LRO_STATUS } from 'common/store/response.store'; -export const API_REQUEST_INTERVAL = 10; // in seconds -export const PAGE_REFRESH_INTERVAL = 1; +export const REFRESH_INTERVAL = 1; const LABEL = { UPLOADING: 'processing.label.uploading', RUNNING: 'processing.label.processing', }; -const responseStoreSelector = (s) => [s.errorMessage, s.lroStatus, s.refreshStatus]; -const subKeySelector = (s) => s.subscriptionKey; +const responseStoreSelector = s => [s.errorMessage, s.lroStatus, s.refreshStatus]; +const subKeySelector = s => s.subscriptionKey; const ProcessingPage = () => { const { t } = useTranslation(); const navigate = useNavigate(); const completedSteps = useCompletedSteps(); - const [lastUpdated, setLastUpdated] = useState(0); const [label, setLabel] = useState(); const subscriptionKey = useUserStore(subKeySelector); @@ -33,18 +30,12 @@ const ProcessingPage = () => { useEffect(() => { const interval = setInterval(() => { - setLastUpdated((seconds) => (seconds + PAGE_REFRESH_INTERVAL) % API_REQUEST_INTERVAL); - }, PAGE_REFRESH_INTERVAL * 1000); + refreshStatus(subscriptionKey); + }, REFRESH_INTERVAL * 1000); return () => clearInterval(interval); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - useEffect(() => { - if (lastUpdated !== API_REQUEST_INTERVAL - 1) return; - refreshStatus(subscriptionKey); - // eslint-disable-next-line react-hooks/exhaustive-deps -- we only care about lastUpdated - }, [lastUpdated]); - useEffect(() => { switch (lroStatus) { case LRO_STATUS.UPLOADING: @@ -71,9 +62,7 @@ const ProcessingPage = () => { navigate(PATHS.INDEX); break; } - - setLastUpdated(0); - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, [lroStatus]); useEffect(() => { @@ -81,15 +70,14 @@ const ProcessingPage = () => { return; } navigate(PATHS.INDEX); - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, [errorMessage]); return (
- +
); }; -export default ProcessingPage; \ No newline at end of file +export default ProcessingPage; diff --git a/src/pages/processing/processing.test.js b/src/pages/processing/processing.test.js index ff72b4b..b86ce36 100644 --- a/src/pages/processing/processing.test.js +++ b/src/pages/processing/processing.test.js @@ -1,10 +1,9 @@ import { act, render } from '@testing-library/react'; - -import ProcessingPage, { API_REQUEST_INTERVAL, PAGE_REFRESH_INTERVAL} from './processing'; import { useResponseStore, useUserStore } from 'common/store'; +import ProcessingPage, { REFRESH_INTERVAL } from './processing'; -const refreshRateMs = PAGE_REFRESH_INTERVAL * 1000; -const requestFrequency = parseInt(API_REQUEST_INTERVAL / PAGE_REFRESH_INTERVAL); +const refreshRateMs = REFRESH_INTERVAL * 1000; +const requestFrequency = 1; const mockT = jest.fn(); const mockNavigate = jest.fn(); @@ -37,16 +36,24 @@ describe('ProcessingPage', () => { jest.useFakeTimers(); render(); for (let i = 0; i < requestFrequency; i++) { - expect(mockT).toHaveBeenCalledWith('processing.last.checked', { seconds: i }); - act(() => { jest.advanceTimersByTime(refreshRateMs); }); + expect(mockT).toHaveBeenCalledWith('processing.last.checked', { + seconds: i, + }); + act(() => { + jest.advanceTimersByTime(refreshRateMs); + }); } expect(spy).toHaveBeenCalledWith('subscriptionKey'); expect(spy).toHaveBeenCalledTimes(1); for (let i = 0; i < requestFrequency * 10; i++) { - expect(mockT).toHaveBeenCalledWith('processing.last.checked', { seconds: i % 10 }); - act(() => { jest.advanceTimersByTime(refreshRateMs); }); + expect(mockT).toHaveBeenCalledWith('processing.last.checked', { + seconds: i % 10, + }); + act(() => { + jest.advanceTimersByTime(refreshRateMs); + }); } expect(spy).toHaveBeenCalledTimes(11); @@ -59,4 +66,4 @@ describe('ProcessingPage', () => { render(); expect(mockNavigate).toHaveBeenCalledWith('/'); }); -}); \ No newline at end of file +}); From f6941e0d14319b92ef24c7021de918fe144b2fd1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 Oct 2023 17:49:42 +0000 Subject: [PATCH 2/4] Bump @babel/traverse from 7.20.13 to 7.23.2 Bumps [@babel/traverse](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse) from 7.20.13 to 7.23.2. - [Release notes](https://github.com/babel/babel/releases) - [Changelog](https://github.com/babel/babel/blob/main/CHANGELOG.md) - [Commits](https://github.com/babel/babel/commits/v7.23.2/packages/babel-traverse) --- updated-dependencies: - dependency-name: "@babel/traverse" dependency-type: indirect ... Signed-off-by: dependabot[bot] (cherry picked from commit 3ecb45986cbb65f2f5b3bfae386cf6cba93acde8) --- package-lock.json | 248 +++++++++++++++++++++++----------------------- 1 file changed, 126 insertions(+), 122 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0ccf5a3..5b72e90 100644 --- a/package-lock.json +++ b/package-lock.json @@ -63,11 +63,12 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz", - "integrity": "sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==", + "version": "7.22.13", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", + "integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==", "dependencies": { - "@babel/highlight": "^7.18.6" + "@babel/highlight": "^7.22.13", + "chalk": "^2.4.2" }, "engines": { "node": ">=6.9.0" @@ -138,12 +139,13 @@ } }, "node_modules/@babel/generator": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.20.7.tgz", - "integrity": "sha512-7wqMOJq8doJMZmP4ApXTzLxSr7+oO2jroJURrVEp6XShrQUObV8Tq/D0NCcoYg2uHqUrjzO0zwBjoYzelxK+sw==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz", + "integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==", "dependencies": { - "@babel/types": "^7.20.7", + "@babel/types": "^7.23.0", "@jridgewell/gen-mapping": "^0.3.2", + "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" }, "engines": { @@ -262,9 +264,9 @@ } }, "node_modules/@babel/helper-environment-visitor": { - "version": "7.18.9", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.18.9.tgz", - "integrity": "sha512-3r/aACDJ3fhQ/EVgFy0hpj8oHyHpQc+LPtJoY9SzTThAsStm4Ptegq92vqKoE3vD706ZVFWITnMnxucw+S9Ipg==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", + "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", "engines": { "node": ">=6.9.0" } @@ -282,23 +284,23 @@ } }, "node_modules/@babel/helper-function-name": { - "version": "7.19.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.19.0.tgz", - "integrity": "sha512-WAwHBINyrpqywkUH0nTnNgI5ina5TFn85HKS0pbPDfxFfhyR/aNQEn4hGi1P1JyT//I0t4OgXUlofzWILRvS5w==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", + "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", "dependencies": { - "@babel/template": "^7.18.10", - "@babel/types": "^7.19.0" + "@babel/template": "^7.22.15", + "@babel/types": "^7.23.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-hoist-variables": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.18.6.tgz", - "integrity": "sha512-UlJQPkFqFULIcyW5sbzgbkxn2FKRgwWiRexcuaR8RNJRy8+LLveqPjwZV/bwrLZCN0eUHD/x8D0heK1ozuoo6Q==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", + "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", "dependencies": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" @@ -424,28 +426,28 @@ } }, "node_modules/@babel/helper-split-export-declaration": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.18.6.tgz", - "integrity": "sha512-bde1etTx6ZyTmobl9LLMMQsaizFVZrquTEHOqKeQESMKo4PlObf+8+JA25ZsIpZhT/WEd39+vOdLXAFG/nELpA==", + "version": "7.22.6", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz", + "integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==", "dependencies": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.19.4", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.19.4.tgz", - "integrity": "sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", + "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", - "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", + "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", "engines": { "node": ">=6.9.0" } @@ -487,12 +489,12 @@ } }, "node_modules/@babel/highlight": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.18.6.tgz", - "integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz", + "integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==", "dependencies": { - "@babel/helper-validator-identifier": "^7.18.6", - "chalk": "^2.0.0", + "@babel/helper-validator-identifier": "^7.22.20", + "chalk": "^2.4.2", "js-tokens": "^4.0.0" }, "engines": { @@ -500,9 +502,9 @@ } }, "node_modules/@babel/parser": { - "version": "7.20.13", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.13.tgz", - "integrity": "sha512-gFDLKMfpiXCsjt4za2JA9oTMn70CeseCehb11kRZgvd7+F67Hih3OHOK24cRrWECJ/ljfPGac6ygXAs/C8kIvw==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", + "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==", "bin": { "parser": "bin/babel-parser.js" }, @@ -1879,31 +1881,31 @@ } }, "node_modules/@babel/template": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.20.7.tgz", - "integrity": "sha512-8SegXApWe6VoNw0r9JHpSteLKTpTiLZ4rMlGIm9JQ18KiCtyQiAMEazujAHrUS5flrcqYZa75ukev3P6QmUwUw==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz", + "integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==", "dependencies": { - "@babel/code-frame": "^7.18.6", - "@babel/parser": "^7.20.7", - "@babel/types": "^7.20.7" + "@babel/code-frame": "^7.22.13", + "@babel/parser": "^7.22.15", + "@babel/types": "^7.22.15" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.20.13", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.20.13.tgz", - "integrity": "sha512-kMJXfF0T6DIS9E8cgdLCSAL+cuCK+YEZHWiLK0SXpTo8YRj5lpJu3CDNKiIBCne4m9hhTIqUg6SYTAI39tAiVQ==", - "dependencies": { - "@babel/code-frame": "^7.18.6", - "@babel/generator": "^7.20.7", - "@babel/helper-environment-visitor": "^7.18.9", - "@babel/helper-function-name": "^7.19.0", - "@babel/helper-hoist-variables": "^7.18.6", - "@babel/helper-split-export-declaration": "^7.18.6", - "@babel/parser": "^7.20.13", - "@babel/types": "^7.20.7", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz", + "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==", + "dependencies": { + "@babel/code-frame": "^7.22.13", + "@babel/generator": "^7.23.0", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-function-name": "^7.23.0", + "@babel/helper-hoist-variables": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "@babel/parser": "^7.23.0", + "@babel/types": "^7.23.0", "debug": "^4.1.0", "globals": "^11.1.0" }, @@ -1912,12 +1914,12 @@ } }, "node_modules/@babel/types": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.20.7.tgz", - "integrity": "sha512-69OnhBxSSgK0OzTJai4kyPDiKTIe3j+ctaHdIGVbRahTLAT7L3R9oeXHC2aVSuGYt3cVnoAMDmOCgJ2yaiLMvg==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", + "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", "dependencies": { - "@babel/helper-string-parser": "^7.19.4", - "@babel/helper-validator-identifier": "^7.19.1", + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.20", "to-fast-properties": "^2.0.0" }, "engines": { @@ -27504,11 +27506,12 @@ } }, "@babel/code-frame": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.18.6.tgz", - "integrity": "sha512-TDCmlK5eOvH+eH7cdAFlNXeVJqWIQ7gW9tY1GJIpUtFb6CmjVyq2VM3u71bOyR8CRihcCgMUYoDNyLXao3+70Q==", + "version": "7.22.13", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz", + "integrity": "sha512-XktuhWlJ5g+3TJXc5upd9Ks1HutSArik6jf2eAjYFyIOf4ej3RN+184cZbzDvbPnuTJIUhPKKJE3cIsYTiAT3w==", "requires": { - "@babel/highlight": "^7.18.6" + "@babel/highlight": "^7.22.13", + "chalk": "^2.4.2" } }, "@babel/compat-data": { @@ -27558,12 +27561,13 @@ } }, "@babel/generator": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.20.7.tgz", - "integrity": "sha512-7wqMOJq8doJMZmP4ApXTzLxSr7+oO2jroJURrVEp6XShrQUObV8Tq/D0NCcoYg2uHqUrjzO0zwBjoYzelxK+sw==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.23.0.tgz", + "integrity": "sha512-lN85QRR+5IbYrMWM6Y4pE/noaQtg4pNiqeNGX60eqOfo6gtEj6uw/JagelB8vVztSd7R6M5n1+PQkDbHbBRU4g==", "requires": { - "@babel/types": "^7.20.7", + "@babel/types": "^7.23.0", "@jridgewell/gen-mapping": "^0.3.2", + "@jridgewell/trace-mapping": "^0.3.17", "jsesc": "^2.5.1" }, "dependencies": { @@ -27651,9 +27655,9 @@ } }, "@babel/helper-environment-visitor": { - "version": "7.18.9", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.18.9.tgz", - "integrity": "sha512-3r/aACDJ3fhQ/EVgFy0hpj8oHyHpQc+LPtJoY9SzTThAsStm4Ptegq92vqKoE3vD706ZVFWITnMnxucw+S9Ipg==" + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", + "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==" }, "@babel/helper-explode-assignable-expression": { "version": "7.18.6", @@ -27665,20 +27669,20 @@ } }, "@babel/helper-function-name": { - "version": "7.19.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.19.0.tgz", - "integrity": "sha512-WAwHBINyrpqywkUH0nTnNgI5ina5TFn85HKS0pbPDfxFfhyR/aNQEn4hGi1P1JyT//I0t4OgXUlofzWILRvS5w==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", + "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", "requires": { - "@babel/template": "^7.18.10", - "@babel/types": "^7.19.0" + "@babel/template": "^7.22.15", + "@babel/types": "^7.23.0" } }, "@babel/helper-hoist-variables": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.18.6.tgz", - "integrity": "sha512-UlJQPkFqFULIcyW5sbzgbkxn2FKRgwWiRexcuaR8RNJRy8+LLveqPjwZV/bwrLZCN0eUHD/x8D0heK1ozuoo6Q==", + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", + "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", "requires": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" } }, "@babel/helper-member-expression-to-functions": { @@ -27771,22 +27775,22 @@ } }, "@babel/helper-split-export-declaration": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.18.6.tgz", - "integrity": "sha512-bde1etTx6ZyTmobl9LLMMQsaizFVZrquTEHOqKeQESMKo4PlObf+8+JA25ZsIpZhT/WEd39+vOdLXAFG/nELpA==", + "version": "7.22.6", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz", + "integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==", "requires": { - "@babel/types": "^7.18.6" + "@babel/types": "^7.22.5" } }, "@babel/helper-string-parser": { - "version": "7.19.4", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.19.4.tgz", - "integrity": "sha512-nHtDoQcuqFmwYNYPz3Rah5ph2p8PFeFCsZk9A/48dPc/rGocJ5J3hAAZ7pb76VWX3fZKu+uEr/FhH5jLx7umrw==" + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz", + "integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==" }, "@babel/helper-validator-identifier": { - "version": "7.19.1", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz", - "integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==" + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", + "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==" }, "@babel/helper-validator-option": { "version": "7.18.6", @@ -27816,19 +27820,19 @@ } }, "@babel/highlight": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.18.6.tgz", - "integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==", + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.20.tgz", + "integrity": "sha512-dkdMCN3py0+ksCgYmGG8jKeGA/8Tk+gJwSYYlFGxG5lmhfKNoAy004YpLxpS1W2J8m/EK2Ew+yOs9pVRwO89mg==", "requires": { - "@babel/helper-validator-identifier": "^7.18.6", - "chalk": "^2.0.0", + "@babel/helper-validator-identifier": "^7.22.20", + "chalk": "^2.4.2", "js-tokens": "^4.0.0" } }, "@babel/parser": { - "version": "7.20.13", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.20.13.tgz", - "integrity": "sha512-gFDLKMfpiXCsjt4za2JA9oTMn70CeseCehb11kRZgvd7+F67Hih3OHOK24cRrWECJ/ljfPGac6ygXAs/C8kIvw==" + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.23.0.tgz", + "integrity": "sha512-vvPKKdMemU85V9WE/l5wZEmImpCtLqbnTvqDS2U1fJ96KrxoW7KrXhNsNCblQlg8Ck4b85yxdTyelsMUgFUXiw==" }, "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": { "version": "7.18.6", @@ -28740,39 +28744,39 @@ } }, "@babel/template": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.20.7.tgz", - "integrity": "sha512-8SegXApWe6VoNw0r9JHpSteLKTpTiLZ4rMlGIm9JQ18KiCtyQiAMEazujAHrUS5flrcqYZa75ukev3P6QmUwUw==", + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.15.tgz", + "integrity": "sha512-QPErUVm4uyJa60rkI73qneDacvdvzxshT3kksGqlGWYdOTIUOwJ7RDUL8sGqslY1uXWSL6xMFKEXDS3ox2uF0w==", "requires": { - "@babel/code-frame": "^7.18.6", - "@babel/parser": "^7.20.7", - "@babel/types": "^7.20.7" + "@babel/code-frame": "^7.22.13", + "@babel/parser": "^7.22.15", + "@babel/types": "^7.22.15" } }, "@babel/traverse": { - "version": "7.20.13", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.20.13.tgz", - "integrity": "sha512-kMJXfF0T6DIS9E8cgdLCSAL+cuCK+YEZHWiLK0SXpTo8YRj5lpJu3CDNKiIBCne4m9hhTIqUg6SYTAI39tAiVQ==", - "requires": { - "@babel/code-frame": "^7.18.6", - "@babel/generator": "^7.20.7", - "@babel/helper-environment-visitor": "^7.18.9", - "@babel/helper-function-name": "^7.19.0", - "@babel/helper-hoist-variables": "^7.18.6", - "@babel/helper-split-export-declaration": "^7.18.6", - "@babel/parser": "^7.20.13", - "@babel/types": "^7.20.7", + "version": "7.23.2", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.23.2.tgz", + "integrity": "sha512-azpe59SQ48qG6nu2CzcMLbxUudtN+dOM9kDbUqGq3HXUJRlo7i8fvPoxQUzYgLZ4cMVmuZgm8vvBpNeRhd6XSw==", + "requires": { + "@babel/code-frame": "^7.22.13", + "@babel/generator": "^7.23.0", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-function-name": "^7.23.0", + "@babel/helper-hoist-variables": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "@babel/parser": "^7.23.0", + "@babel/types": "^7.23.0", "debug": "^4.1.0", "globals": "^11.1.0" } }, "@babel/types": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.20.7.tgz", - "integrity": "sha512-69OnhBxSSgK0OzTJai4kyPDiKTIe3j+ctaHdIGVbRahTLAT7L3R9oeXHC2aVSuGYt3cVnoAMDmOCgJ2yaiLMvg==", + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.23.0.tgz", + "integrity": "sha512-0oIyUfKoI3mSqMvsxBdclDwxXKXAUA8v/apZbc+iSyARYou1o8ZGDxbUYyLFoW2arqS2jDGqJuZvv1d/io1axg==", "requires": { - "@babel/helper-string-parser": "^7.19.4", - "@babel/helper-validator-identifier": "^7.19.1", + "@babel/helper-string-parser": "^7.22.5", + "@babel/helper-validator-identifier": "^7.22.20", "to-fast-properties": "^2.0.0" } }, From 56f1454eea7e458fe77782291cc60081548fc41a Mon Sep 17 00:00:00 2001 From: nizetic Date: Mon, 16 Oct 2023 17:29:01 +0200 Subject: [PATCH 3/4] Remove countdown test (cherry picked from commit 8fc83d353598063756418d1798079e47708fc46c) --- src/pages/processing/processing.test.js | 37 ++----------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/src/pages/processing/processing.test.js b/src/pages/processing/processing.test.js index b86ce36..21e6f62 100644 --- a/src/pages/processing/processing.test.js +++ b/src/pages/processing/processing.test.js @@ -1,9 +1,7 @@ -import { act, render } from '@testing-library/react'; +import { render } from '@testing-library/react'; import { useResponseStore, useUserStore } from 'common/store'; -import ProcessingPage, { REFRESH_INTERVAL } from './processing'; +import ProcessingPage from './processing'; -const refreshRateMs = REFRESH_INTERVAL * 1000; -const requestFrequency = 1; const mockT = jest.fn(); const mockNavigate = jest.fn(); @@ -30,37 +28,6 @@ describe('ProcessingPage', () => { expect(render()).toMatchSnapshot(); }); - it('should countdown', async () => { - const state = useResponseStore.getState(); - const spy = jest.spyOn(state, 'refreshStatus'); - jest.useFakeTimers(); - render(); - for (let i = 0; i < requestFrequency; i++) { - expect(mockT).toHaveBeenCalledWith('processing.last.checked', { - seconds: i, - }); - act(() => { - jest.advanceTimersByTime(refreshRateMs); - }); - } - - expect(spy).toHaveBeenCalledWith('subscriptionKey'); - expect(spy).toHaveBeenCalledTimes(1); - - for (let i = 0; i < requestFrequency * 10; i++) { - expect(mockT).toHaveBeenCalledWith('processing.last.checked', { - seconds: i % 10, - }); - act(() => { - jest.advanceTimersByTime(refreshRateMs); - }); - } - - expect(spy).toHaveBeenCalledTimes(11); - - jest.useRealTimers(); - }); - it('should navigate to create manifest page in case of error', () => { useResponseStore.setState({ errorMessage: 'erreur!' }); render(); From 8fa30b65beb378d79a4227782cc872017aa83139 Mon Sep 17 00:00:00 2001 From: nizetic Date: Mon, 4 Dec 2023 14:14:48 +0100 Subject: [PATCH 4/4] Update retry timeout --- src/common/api/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/common/api/index.js b/src/common/api/index.js index ddd3890..5b68cc0 100644 --- a/src/common/api/index.js +++ b/src/common/api/index.js @@ -3,6 +3,8 @@ import { getEnvs } from 'common/functions'; import { useUserStore } from '../store/user.store'; import { HTTP_STATUS_CODE } from '../constants'; +const RETRY_TIMEOUT = 1000; + export const uploadFile = (file) => { const { geography, subscriptionKey } = useUserStore.getState(); const url = `${getEnvs()[geography].URL}/manifest?api-version=2.0&subscription-key=${subscriptionKey}`; @@ -36,7 +38,7 @@ export const fetchWithRetries = (location, retries = 10) => { return new Promise((resolve) => { setTimeout(() => { resolve(fetchWithRetries(location, retries - 1)); - }, 10000); + }, RETRY_TIMEOUT); }); } throw new Error(data?.error?.message); @@ -54,4 +56,4 @@ export const fetchAddress = (address) => { const { geography, subscriptionKey } = useUserStore.getState(); return fetch(`${getEnvs()[geography].URL}/search/address/json?subscription-key=${subscriptionKey}&api-version=1.0&query=${address}&limit=1`) .then((res) => res.json()); -}; \ No newline at end of file +};