From 1d174aa898a28d51a6fa952536c27efea7c9b66d Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 12 Mar 2024 15:12:37 -1000 Subject: [PATCH 1/4] add JS snippet to mark reports on a policy as read --- src/libs/markAllPolicyReportsAsRead.ts | 32 ++++++++++++++++++++++++ src/setup/platformSetup/index.website.ts | 6 +++++ 2 files changed, 38 insertions(+) create mode 100644 src/libs/markAllPolicyReportsAsRead.ts diff --git a/src/libs/markAllPolicyReportsAsRead.ts b/src/libs/markAllPolicyReportsAsRead.ts new file mode 100644 index 000000000000..5ab533be5a10 --- /dev/null +++ b/src/libs/markAllPolicyReportsAsRead.ts @@ -0,0 +1,32 @@ +// eslint-disable-next-line you-dont-need-lodash-underscore/each +import ONYXKEYS from '@src/ONYXKEYS'; +import Onyx from 'react-native-onyx'; +import type {Report} from '@src/types/onyx'; +import * as ReportActionFile from './actions/Report'; + +export default function markAllPolicyReportsAsRead(policyID: string) { + const connectionID = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + if (!allReports) { + return; + } + + let delay = 0; + Object.keys(allReports).forEach((key: string) => { + const report: Report|null|undefined = allReports[key]; + if (report?.policyID !== policyID) { + return; + } + + setTimeout(() => { + ReportActionFile.readNewestAction(report?.reportID); + }, delay); + + delay += 1000; + }); + Onyx.disconnect(connectionID); + }, + }) +} diff --git a/src/setup/platformSetup/index.website.ts b/src/setup/platformSetup/index.website.ts index 0fef333e6508..d4be23831f71 100644 --- a/src/setup/platformSetup/index.website.ts +++ b/src/setup/platformSetup/index.website.ts @@ -3,11 +3,17 @@ import {AppRegistry} from 'react-native'; import 'shim-keyboard-event-key'; import checkForUpdates from '@libs/checkForUpdates'; import DateUtils from '@libs/DateUtils'; +import markAllPolicyReportsAsRead from '@libs/markAllPolicyReportsAsRead'; import Visibility from '@libs/Visibility'; import Config from '@src/CONFIG'; import pkg from '../../../package.json'; import type PlatformSpecificUpdater from './types'; + +// Temporary workaround to give employees the ability to mark reports as read via the JS console +// eslint-disable-next-line @typescript-eslint/no-explicit-any +(window as any).markAllPolicyReportsAsRead = markAllPolicyReportsAsRead; + /** * Download the latest app version from the server, and if it is different than the current one, * then refresh. If the page is visibile, prompt the user to refresh. From 99010cc9e0b387516449351cc5c94d0f3bd0065c Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Tue, 12 Mar 2024 15:15:45 -1000 Subject: [PATCH 2/4] Run prettier and make work on desktop --- src/libs/markAllPolicyReportsAsRead.ts | 6 +++--- src/setup/platformSetup/index.desktop.ts | 5 +++++ src/setup/platformSetup/index.website.ts | 1 - 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libs/markAllPolicyReportsAsRead.ts b/src/libs/markAllPolicyReportsAsRead.ts index 5ab533be5a10..1daf1e4c125a 100644 --- a/src/libs/markAllPolicyReportsAsRead.ts +++ b/src/libs/markAllPolicyReportsAsRead.ts @@ -1,6 +1,6 @@ // eslint-disable-next-line you-dont-need-lodash-underscore/each -import ONYXKEYS from '@src/ONYXKEYS'; import Onyx from 'react-native-onyx'; +import ONYXKEYS from '@src/ONYXKEYS'; import type {Report} from '@src/types/onyx'; import * as ReportActionFile from './actions/Report'; @@ -15,7 +15,7 @@ export default function markAllPolicyReportsAsRead(policyID: string) { let delay = 0; Object.keys(allReports).forEach((key: string) => { - const report: Report|null|undefined = allReports[key]; + const report: Report | null | undefined = allReports[key]; if (report?.policyID !== policyID) { return; } @@ -28,5 +28,5 @@ export default function markAllPolicyReportsAsRead(policyID: string) { }); Onyx.disconnect(connectionID); }, - }) + }); } diff --git a/src/setup/platformSetup/index.desktop.ts b/src/setup/platformSetup/index.desktop.ts index 7c8227ba9f30..e1408428e210 100644 --- a/src/setup/platformSetup/index.desktop.ts +++ b/src/setup/platformSetup/index.desktop.ts @@ -1,11 +1,16 @@ import {AppRegistry} from 'react-native'; import ELECTRON_EVENTS from '@desktop/ELECTRON_EVENTS'; import DateUtils from '@libs/DateUtils'; +import markAllPolicyReportsAsRead from '@libs/markAllPolicyReportsAsRead'; import Navigation from '@libs/Navigation/Navigation'; import LocalNotification from '@libs/Notification/LocalNotification'; import Config from '@src/CONFIG'; import ROUTES from '@src/ROUTES'; +// Temporary workaround to give employees the ability to mark reports as read via the JS console +// eslint-disable-next-line @typescript-eslint/no-explicit-any +(window as any).markAllPolicyReportsAsRead = markAllPolicyReportsAsRead; + export default function () { AppRegistry.runApplication(Config.APP_NAME, { rootTag: document.getElementById('root'), diff --git a/src/setup/platformSetup/index.website.ts b/src/setup/platformSetup/index.website.ts index d4be23831f71..68466828d3ae 100644 --- a/src/setup/platformSetup/index.website.ts +++ b/src/setup/platformSetup/index.website.ts @@ -9,7 +9,6 @@ import Config from '@src/CONFIG'; import pkg from '../../../package.json'; import type PlatformSpecificUpdater from './types'; - // Temporary workaround to give employees the ability to mark reports as read via the JS console // eslint-disable-next-line @typescript-eslint/no-explicit-any (window as any).markAllPolicyReportsAsRead = markAllPolicyReportsAsRead; From 096f90dac1f51e8eea74c2692ae4b32efb81b10c Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 21 Mar 2024 09:11:31 -1000 Subject: [PATCH 3/4] Make requested changes --- src/libs/markAllPolicyReportsAsRead.ts | 3 ++- src/setup/addUtilsToWindow.ts | 5 +++++ src/setup/platformSetup/index.desktop.ts | 5 ----- src/setup/platformSetup/index.website.ts | 5 ----- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/libs/markAllPolicyReportsAsRead.ts b/src/libs/markAllPolicyReportsAsRead.ts index 1daf1e4c125a..c3c719b1132e 100644 --- a/src/libs/markAllPolicyReportsAsRead.ts +++ b/src/libs/markAllPolicyReportsAsRead.ts @@ -3,6 +3,7 @@ import Onyx from 'react-native-onyx'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Report} from '@src/types/onyx'; import * as ReportActionFile from './actions/Report'; +import * as ReportUtils from './ReportUtils'; export default function markAllPolicyReportsAsRead(policyID: string) { const connectionID = Onyx.connect({ @@ -16,7 +17,7 @@ export default function markAllPolicyReportsAsRead(policyID: string) { let delay = 0; Object.keys(allReports).forEach((key: string) => { const report: Report | null | undefined = allReports[key]; - if (report?.policyID !== policyID) { + if (report?.policyID !== policyID || !ReportUtils.isUnread(report)) { return; } diff --git a/src/setup/addUtilsToWindow.ts b/src/setup/addUtilsToWindow.ts index 9991a3dc07cd..e5da96e0e128 100644 --- a/src/setup/addUtilsToWindow.ts +++ b/src/setup/addUtilsToWindow.ts @@ -1,6 +1,7 @@ import Onyx from 'react-native-onyx'; import * as Environment from '@libs/Environment/Environment'; import * as Session from '@userActions/Session'; +import markAllPolicyReportsAsRead from '@libs/markAllPolicyReportsAsRead'; /** * This is used to inject development/debugging utilities into the window object on web and desktop. @@ -44,5 +45,9 @@ export default function addUtilsToWindow() { }; window.setSupportToken = Session.setSupportAuthToken; + + // Workaround to give employees the ability to mark reports as read via the JS console + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (window as any).markAllPolicyReportsAsRead = markAllPolicyReportsAsRead; }); } diff --git a/src/setup/platformSetup/index.desktop.ts b/src/setup/platformSetup/index.desktop.ts index e1408428e210..7c8227ba9f30 100644 --- a/src/setup/platformSetup/index.desktop.ts +++ b/src/setup/platformSetup/index.desktop.ts @@ -1,16 +1,11 @@ import {AppRegistry} from 'react-native'; import ELECTRON_EVENTS from '@desktop/ELECTRON_EVENTS'; import DateUtils from '@libs/DateUtils'; -import markAllPolicyReportsAsRead from '@libs/markAllPolicyReportsAsRead'; import Navigation from '@libs/Navigation/Navigation'; import LocalNotification from '@libs/Notification/LocalNotification'; import Config from '@src/CONFIG'; import ROUTES from '@src/ROUTES'; -// Temporary workaround to give employees the ability to mark reports as read via the JS console -// eslint-disable-next-line @typescript-eslint/no-explicit-any -(window as any).markAllPolicyReportsAsRead = markAllPolicyReportsAsRead; - export default function () { AppRegistry.runApplication(Config.APP_NAME, { rootTag: document.getElementById('root'), diff --git a/src/setup/platformSetup/index.website.ts b/src/setup/platformSetup/index.website.ts index 68466828d3ae..0fef333e6508 100644 --- a/src/setup/platformSetup/index.website.ts +++ b/src/setup/platformSetup/index.website.ts @@ -3,16 +3,11 @@ import {AppRegistry} from 'react-native'; import 'shim-keyboard-event-key'; import checkForUpdates from '@libs/checkForUpdates'; import DateUtils from '@libs/DateUtils'; -import markAllPolicyReportsAsRead from '@libs/markAllPolicyReportsAsRead'; import Visibility from '@libs/Visibility'; import Config from '@src/CONFIG'; import pkg from '../../../package.json'; import type PlatformSpecificUpdater from './types'; -// Temporary workaround to give employees the ability to mark reports as read via the JS console -// eslint-disable-next-line @typescript-eslint/no-explicit-any -(window as any).markAllPolicyReportsAsRead = markAllPolicyReportsAsRead; - /** * Download the latest app version from the server, and if it is different than the current one, * then refresh. If the page is visibile, prompt the user to refresh. From 6da0e23cf9c257d86f729fcad9c689e58200f5fe Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 21 Mar 2024 09:56:00 -1000 Subject: [PATCH 4/4] Prettier --- src/setup/addUtilsToWindow.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup/addUtilsToWindow.ts b/src/setup/addUtilsToWindow.ts index e5da96e0e128..d2d11e138431 100644 --- a/src/setup/addUtilsToWindow.ts +++ b/src/setup/addUtilsToWindow.ts @@ -1,7 +1,7 @@ import Onyx from 'react-native-onyx'; import * as Environment from '@libs/Environment/Environment'; -import * as Session from '@userActions/Session'; import markAllPolicyReportsAsRead from '@libs/markAllPolicyReportsAsRead'; +import * as Session from '@userActions/Session'; /** * This is used to inject development/debugging utilities into the window object on web and desktop.