diff --git a/src/components/Attachments/AttachmentCarousel/extractAttachments.ts b/src/components/Attachments/AttachmentCarousel/extractAttachments.ts index 81ee6d08934b..12943eafeee0 100644 --- a/src/components/Attachments/AttachmentCarousel/extractAttachments.ts +++ b/src/components/Attachments/AttachmentCarousel/extractAttachments.ts @@ -7,7 +7,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import tryResolveUrlFromApiRoot from '@libs/tryResolveUrlFromApiRoot'; import CONST from '@src/CONST'; import type {ReportAction, ReportActions} from '@src/types/onyx'; -import type {Note} from '@src/types/onyx/Report'; +import type {Note} from '@src/types/onyx/ReportMetadata'; /** * Constructs the initial component state from report actions diff --git a/src/components/Attachments/AttachmentCarousel/index.native.tsx b/src/components/Attachments/AttachmentCarousel/index.native.tsx index a8eb614202a7..37d01b421f5f 100644 --- a/src/components/Attachments/AttachmentCarousel/index.native.tsx +++ b/src/components/Attachments/AttachmentCarousel/index.native.tsx @@ -24,6 +24,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi const pagerRef = useRef(null); const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, {canEvict: false}); const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false}); + const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`, {canEvict: false}); const [page, setPage] = useState(); const [attachments, setAttachments] = useState([]); const {shouldShowArrows, setShouldShowArrows, autoHideArrows, cancelAutoHideArrows} = useCarouselArrows(); @@ -34,7 +35,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi const parentReportAction = report.parentReportActionID && parentReportActions ? parentReportActions[report.parentReportActionID] : undefined; let newAttachments: Attachment[] = []; if (type === CONST.ATTACHMENT_TYPE.NOTE && accountID) { - newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.NOTE, {privateNotes: report.privateNotes, accountID}); + newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.NOTE, {privateNotes: reportMetadata?.privateNotes, accountID}); } else { newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.REPORT, {parentReportAction, reportActions}); } diff --git a/src/components/Attachments/AttachmentCarousel/index.tsx b/src/components/Attachments/AttachmentCarousel/index.tsx index b578da242d88..2186e5d75f54 100644 --- a/src/components/Attachments/AttachmentCarousel/index.tsx +++ b/src/components/Attachments/AttachmentCarousel/index.tsx @@ -50,6 +50,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi const pagerRef = useRef(null); const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`, {canEvict: false}); const [reportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, {canEvict: false}); + const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`, {canEvict: false}); const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen(); const modalStyles = styles.centeredModalStyles(shouldUseNarrowLayout, true); @@ -76,7 +77,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi const parentReportAction = report.parentReportActionID && parentReportActions ? parentReportActions[report.parentReportActionID] : undefined; let newAttachments: Attachment[] = []; if (type === CONST.ATTACHMENT_TYPE.NOTE && accountID) { - newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.NOTE, {privateNotes: report.privateNotes, accountID}); + newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.NOTE, {privateNotes: reportMetadata?.privateNotes, accountID}); } else { newAttachments = extractAttachments(CONST.ATTACHMENT_TYPE.REPORT, {parentReportAction, reportActions: reportActions ?? undefined}); } @@ -117,7 +118,7 @@ function AttachmentCarousel({report, source, onNavigate, setDownloadButtonVisibi onNavigate(attachment); } } - }, [report.privateNotes, reportActions, parentReportActions, compareImage, report.parentReportActionID, attachments, setDownloadButtonVisibility, onNavigate, accountID, type]); + }, [reportMetadata?.privateNotes, reportActions, parentReportActions, compareImage, report.parentReportActionID, attachments, setDownloadButtonVisibility, onNavigate, accountID, type]); // Scroll position is affected when window width is resized, so we readjust it on width changes useEffect(() => { diff --git a/src/libs/DebugUtils.ts b/src/libs/DebugUtils.ts index 2f0da08b194d..bd625820c7ff 100644 --- a/src/libs/DebugUtils.ts +++ b/src/libs/DebugUtils.ts @@ -427,15 +427,6 @@ function validateReportDraftProperty(key: keyof Report, value: string) { if (REPORT_REQUIRED_PROPERTIES.includes(key) && value === 'undefined') { throw SyntaxError('debug.missingValue'); } - if (key === 'privateNotes') { - return validateObject( - value, - { - note: 'string', - }, - 'number', - ); - } if (key === 'permissions') { return validateArray(value, CONST.REPORT.PERMISSIONS); } diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index fa3eea80c09c..6e3699994726 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4218,11 +4218,11 @@ function navigateBackAfterDeleteTransaction(backRoute: Route | undefined, isFrom /** * Go back to the previous page from the edit private page of a given report */ -function goBackFromPrivateNotes(report: OnyxEntry, accountID?: number, backTo?: string) { +function goBackFromPrivateNotes(report: OnyxEntry, reportMetadata: OnyxEntry, accountID?: number, backTo?: string) { if (isEmpty(report) || !accountID) { return; } - const currentUserPrivateNote = report.privateNotes?.[accountID]?.note ?? ''; + const currentUserPrivateNote = reportMetadata?.privateNotes?.[accountID]?.note ?? ''; if (isEmpty(currentUserPrivateNote)) { const participantAccountIDs = getParticipantsAccountIDsForDisplay(report); @@ -7711,11 +7711,11 @@ function shouldAutoFocusOnKeyPress(event: KeyboardEvent): boolean { /** * Navigates to the appropriate screen based on the presence of a private note for the current user. */ -function navigateToPrivateNotes(report: OnyxEntry, session: OnyxEntry, backTo?: string) { +function navigateToPrivateNotes(report: OnyxEntry, reportMetadata: OnyxEntry, session: OnyxEntry, backTo?: string) { if (isEmpty(report) || isEmpty(session) || !session.accountID) { return; } - const currentUserPrivateNote = report.privateNotes?.[session.accountID]?.note ?? ''; + const currentUserPrivateNote = reportMetadata?.privateNotes?.[session.accountID]?.note ?? ''; if (isEmpty(currentUserPrivateNote)) { Navigation.navigate(ROUTES.PRIVATE_NOTES_EDIT.getRoute(report.reportID, session.accountID, backTo)); return; diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 32c0a40876d7..5bc429166b61 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -107,6 +107,7 @@ import type { RecentlyUsedReportFields, ReportAction, ReportActionReactions, + ReportMetadata, ReportUserIsTyping, } from '@src/types/onyx'; import type {Decision} from '@src/types/onyx/OriginalMessage'; @@ -3380,7 +3381,7 @@ const updatePrivateNotes = (reportID: string, accountID: number, note: string) = const optimisticData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, value: { privateNotes: { [accountID]: { @@ -3396,7 +3397,7 @@ const updatePrivateNotes = (reportID: string, accountID: number, note: string) = const successData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, value: { privateNotes: { [accountID]: { @@ -3411,7 +3412,7 @@ const updatePrivateNotes = (reportID: string, accountID: number, note: string) = const failureData: OnyxUpdate[] = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, value: { privateNotes: { [accountID]: { @@ -3954,14 +3955,14 @@ function openRoomMembersPage(reportID: string) { * * @returns Returns true if there are errors in any of the private notes on the report */ -function hasErrorInPrivateNotes(report: OnyxEntry): boolean { - const privateNotes = report?.privateNotes ?? {}; +function hasErrorInPrivateNotes(reportMetadata: OnyxEntry): boolean { + const privateNotes = reportMetadata?.privateNotes ?? {}; return Object.values(privateNotes).some((privateNote) => !isEmpty(privateNote.errors)); } /** Clears all errors associated with a given private note */ function clearPrivateNotesError(reportID: string, accountID: number) { - Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {privateNotes: {[accountID]: {errors: null}}}); + Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, {privateNotes: {[accountID]: {errors: null}}}); } function getDraftPrivateNote(reportID: string): string { diff --git a/src/libs/migrateOnyx.ts b/src/libs/migrateOnyx.ts index 423b5e7c0017..15ae8f3d5bef 100644 --- a/src/libs/migrateOnyx.ts +++ b/src/libs/migrateOnyx.ts @@ -1,6 +1,7 @@ import Log from './Log'; import KeyReportActionsDraftByReportActionID from './migrations/KeyReportActionsDraftByReportActionID'; import NVPMigration from './migrations/NVPMigration'; +import PrivateNotesMigration from './migrations/PrivateNotesMigration'; import PronounsMigration from './migrations/PronounsMigration'; import RemoveEmptyReportActionsDrafts from './migrations/RemoveEmptyReportActionsDrafts'; import RenameCardIsVirtual from './migrations/RenameCardIsVirtual'; @@ -21,6 +22,7 @@ export default function () { RemoveEmptyReportActionsDrafts, NVPMigration, PronounsMigration, + PrivateNotesMigration, ]; // Reduce all promises down to a single promise. All promises run in a linear fashion, waiting for the diff --git a/src/libs/migrations/PrivateNotesMigration.ts b/src/libs/migrations/PrivateNotesMigration.ts new file mode 100644 index 000000000000..f823472a4755 --- /dev/null +++ b/src/libs/migrations/PrivateNotesMigration.ts @@ -0,0 +1,74 @@ +import type {NullishDeep, OnyxInputValue} from 'react-native-onyx'; +import Onyx from 'react-native-onyx'; +import Log from '@libs/Log'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type * as OnyxTypes from '@src/types/onyx'; +import type {Note} from '@src/types/onyx/ReportMetadata'; +import {isEmptyObject} from '@src/types/utils/EmptyObject'; + +type ReportMetadataKey = `${typeof ONYXKEYS.COLLECTION.REPORT_METADATA}${string}`; +type ReportKey = `${typeof ONYXKEYS.COLLECTION.REPORT}${string}`; + +/** + * This migration moves private notes from the report object to reportMetadata. + * Before: report.privateNotes + * After: reportMetadata.privateNotes + */ +export default function (): Promise { + return new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.COLLECTION.REPORT, + waitForCollectionCallback: true, + callback: (allReports) => { + Onyx.disconnect(connection); + + if (!allReports) { + Log.info('[Migrate Onyx] Skipped migration PrivateNotesMigration because there were no reports'); + return resolve(); + } + + // @ts-expect-error this migration moves privateNotes from Report to ReportMetadata so it is expected to not exist in Report type anymore + const reportsWithPrivateNotes = Object.entries(allReports).filter(([, report]) => report?.privateNotes); + + if (reportsWithPrivateNotes.length === 0) { + Log.info('[Migrate Onyx] Skipped migration PrivateNotesMigration because there were no reports with private notes'); + return resolve(); + } + + const newReportMetadata: Record> = {}; + const reportsToUpdate: Record<`${typeof ONYXKEYS.COLLECTION.REPORT}${string}`, NullishDeep> = {}; + + reportsWithPrivateNotes.forEach(([reportOnyxKey, report]) => { + // @ts-expect-error this migration moves privateNotes from Report to ReportMetadata so it is expected to not exist in Report type anymore + if (!report?.reportID || !report.privateNotes) { + return; + } + + // Move private notes to reportMetadata + const metadataKey: ReportMetadataKey = `${ONYXKEYS.COLLECTION.REPORT_METADATA}${report.reportID}`; + newReportMetadata[metadataKey] = { + // @ts-expect-error this migration moves privateNotes from Report to ReportMetadata so it is expected to not exist in Report type anymore + privateNotes: report?.privateNotes as Note, + }; + // @ts-expect-error this migration moves privateNotes from Report to ReportMetadata so it is expected to not exist in Report type anymore + reportsToUpdate[reportOnyxKey as ReportKey] = {privateNotes: undefined}; + }); + + if (isEmptyObject(newReportMetadata)) { + Log.info('[Migrate Onyx] Skipped migration PrivateNotesMigration because there were no private notes to migrate'); + return resolve(); + } + + Log.info(`[Migrate Onyx] Moving private notes to reportMetadata for ${Object.keys(newReportMetadata).length} reports`); + + // eslint-disable-next-line rulesdir/prefer-actions-set-data + const promises = [Onyx.multiSet(newReportMetadata), Onyx.mergeCollection(ONYXKEYS.COLLECTION.REPORT, reportsToUpdate)]; + + Promise.all(promises).then(() => { + Log.info('[Migrate Onyx] Successfully migrated private notes to reportMetadata'); + resolve(); + }); + }, + }); + }); +} diff --git a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx index 53a52f9cebb5..6bb284118ce8 100644 --- a/src/pages/PrivateNotes/PrivateNotesEditPage.tsx +++ b/src/pages/PrivateNotes/PrivateNotesEditPage.tsx @@ -31,7 +31,7 @@ import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; import INPUT_IDS from '@src/types/form/PrivateNotesForm'; import type {Report} from '@src/types/onyx'; -import type {Note} from '@src/types/onyx/Report'; +import type {Note} from '@src/types/onyx/ReportMetadata'; type PrivateNotesEditPageProps = WithReportAndPrivateNotesOrNotFoundProps & StackScreenProps & { @@ -39,7 +39,7 @@ type PrivateNotesEditPageProps = WithReportAndPrivateNotesOrNotFoundProps & report: Report; }; -function PrivateNotesEditPage({route, report, accountID}: PrivateNotesEditPageProps) { +function PrivateNotesEditPage({route, report, accountID, reportMetadata}: PrivateNotesEditPageProps) { const backTo = route.params.backTo; const styles = useThemeStyles(); const {translate} = useLocalize(); @@ -47,7 +47,7 @@ function PrivateNotesEditPage({route, report, accountID}: PrivateNotesEditPagePr // We need to edit the note in markdown format, but display it in HTML format const [privateNote, setPrivateNote] = useState( - () => ReportActions.getDraftPrivateNote(report.reportID).trim() || Parser.htmlToMarkdown(report?.privateNotes?.[Number(route.params.accountID)]?.note ?? '').trim(), + () => ReportActions.getDraftPrivateNote(report.reportID).trim() || Parser.htmlToMarkdown(reportMetadata?.privateNotes?.[Number(route.params.accountID)]?.note ?? '').trim(), ); /** @@ -85,7 +85,7 @@ function PrivateNotesEditPage({route, report, accountID}: PrivateNotesEditPagePr ); const savePrivateNote = () => { - const originalNote = report?.privateNotes?.[Number(route.params.accountID)]?.note ?? ''; + const originalNote = reportMetadata?.privateNotes?.[Number(route.params.accountID)]?.note ?? ''; let editedNote = ''; if (privateNote.trim() !== originalNote.trim()) { editedNote = ReportActions.handleUserDeletedLinksInHtml(privateNote.trim(), Parser.htmlToMarkdown(originalNote).trim()); @@ -96,7 +96,7 @@ function PrivateNotesEditPage({route, report, accountID}: PrivateNotesEditPagePr debouncedSavePrivateNote(''); Keyboard.dismiss(); - if (!Object.values({...report.privateNotes, [route.params.accountID]: {note: editedNote}}).some((item) => item.note)) { + if (!Object.values({...reportMetadata?.privateNotes, [route.params.accountID]: {note: editedNote}}).some((item) => item.note)) { ReportUtils.navigateToDetailsPage(report, backTo); } else { Navigation.goBack(ROUTES.PRIVATE_NOTES_LIST.getRoute(report.reportID, backTo)); @@ -111,7 +111,7 @@ function PrivateNotesEditPage({route, report, accountID}: PrivateNotesEditPagePr > ReportUtils.goBackFromPrivateNotes(report, accountID, backTo)} + onBackButtonPress={() => ReportUtils.goBackFromPrivateNotes(report, reportMetadata, accountID, backTo)} shouldShowBackButton onCloseButtonPress={() => Navigation.dismissModal()} /> @@ -131,7 +131,7 @@ function PrivateNotesEditPage({route, report, accountID}: PrivateNotesEditPagePr ReportActions.clearPrivateNotesError(report.reportID, Number(route.params.accountID))} style={[styles.mb3]} diff --git a/src/pages/PrivateNotes/PrivateNotesListPage.tsx b/src/pages/PrivateNotes/PrivateNotesListPage.tsx index 474075d928f8..86fc3f83c46e 100644 --- a/src/pages/PrivateNotes/PrivateNotesListPage.tsx +++ b/src/pages/PrivateNotes/PrivateNotesListPage.tsx @@ -40,6 +40,7 @@ function PrivateNotesListPage({report, accountID: sessionAccountID}: PrivateNote const route = useRoute>(); const backTo = route.params.backTo; const [personalDetailsList] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); + const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${report?.reportID ?? -1}`); const styles = useThemeStyles(); const {translate} = useLocalize(); const getAttachmentValue = useCallback((item: NoteListItem) => ({reportID: item.reportID, accountID: Number(item.accountID), type: CONST.ATTACHMENT_TYPE.NOTE}), []); @@ -70,9 +71,9 @@ function PrivateNotesListPage({report, accountID: sessionAccountID}: PrivateNote * Returns a list of private notes on the given chat report */ const privateNotes = useMemo(() => { - const privateNoteBrickRoadIndicator = (accountID: number) => (report.privateNotes?.[accountID].errors ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined); - return Object.keys(report.privateNotes ?? {}).map((accountID: string) => { - const privateNote = report.privateNotes?.[Number(accountID)]; + const privateNoteBrickRoadIndicator = (accountID: number) => (reportMetadata?.privateNotes?.[accountID].errors ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined); + return Object.keys(reportMetadata?.privateNotes ?? {}).map((accountID: string) => { + const privateNote = reportMetadata?.privateNotes?.[Number(accountID)]; return { reportID: report.reportID, accountID, @@ -83,7 +84,7 @@ function PrivateNotesListPage({report, accountID: sessionAccountID}: PrivateNote disabled: Number(sessionAccountID) !== Number(accountID), }; }); - }, [report, personalDetailsList, sessionAccountID, translate, backTo]); + }, [report, reportMetadata, personalDetailsList, sessionAccountID, translate, backTo]); return ( (isCurrentUser ? ReportUtils.findSelfDMReportID() : ReportUtils.getChatByParticipants(session?.accountID ? [accountID, session.accountID] : [], reports)?.reportID ?? '-1'), + [accountID, isCurrentUser, reports, session], + ); const reportKey = useMemo(() => { - const reportID = isCurrentUser - ? ReportUtils.findSelfDMReportID() - : ReportUtils.getChatByParticipants(session?.accountID ? [accountID, session.accountID] : [], reports)?.reportID ?? '-1'; - if (SessionActions.isAnonymousUser() || !reportID) { return `${ONYXKEYS.COLLECTION.REPORT}0` as const; } return `${ONYXKEYS.COLLECTION.REPORT}${reportID}` as const; - }, [accountID, isCurrentUser, reports, session]); + }, [reportID]); const [report] = useOnyx(reportKey); + const [reportMetadata] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`); const styles = useThemeStyles(); const {translate, formatPhoneNumber} = useLocalize(); @@ -286,10 +287,10 @@ function ProfilePage({route}: ProfilePageProps) { title={`${translate('privateNotes.title')}`} titleStyle={styles.flex1} icon={Expensicons.Pencil} - onPress={() => ReportUtils.navigateToPrivateNotes(report, session, navigateBackTo)} + onPress={() => ReportUtils.navigateToPrivateNotes(report, reportMetadata, session, navigateBackTo)} wrapperStyle={styles.breakAll} shouldShowRightIcon - brickRoadIndicator={ReportActions.hasErrorInPrivateNotes(report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} + brickRoadIndicator={ReportActions.hasErrorInPrivateNotes(reportMetadata) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined} /> )} {isConcierge && !!guideCalendarLink && ( diff --git a/src/pages/ReportDetailsPage.tsx b/src/pages/ReportDetailsPage.tsx index 9e438f0549e2..ed271340a9ee 100644 --- a/src/pages/ReportDetailsPage.tsx +++ b/src/pages/ReportDetailsPage.tsx @@ -80,7 +80,7 @@ const CASES = { type CaseID = ValueOf; -function ReportDetailsPage({policies, report, route}: ReportDetailsPageProps) { +function ReportDetailsPage({policies, report, route, reportMetadata}: ReportDetailsPageProps) { const {translate} = useLocalize(); const {isOffline} = useNetwork(); const styles = useThemeStyles(); @@ -419,8 +419,8 @@ function ReportDetailsPage({policies, report, route}: ReportDetailsPageProps) { icon: Expensicons.Pencil, isAnonymousAction: false, shouldShowRightIcon: true, - action: () => ReportUtils.navigateToPrivateNotes(report, session, backTo), - brickRoadIndicator: Report.hasErrorInPrivateNotes(report) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, + action: () => ReportUtils.navigateToPrivateNotes(report, reportMetadata, session, backTo), + brickRoadIndicator: Report.hasErrorInPrivateNotes(reportMetadata) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, }); } diff --git a/src/pages/home/report/withReportAndPrivateNotesOrNotFound.tsx b/src/pages/home/report/withReportAndPrivateNotesOrNotFound.tsx index 2fed275045bc..d7d7e831861a 100644 --- a/src/pages/home/report/withReportAndPrivateNotesOrNotFound.tsx +++ b/src/pages/home/report/withReportAndPrivateNotesOrNotFound.tsx @@ -31,7 +31,7 @@ export default function (pageTitle: TranslationPaths) { const {translate} = useLocalize(); const {isOffline} = useNetwork(); const [session] = useOnyx(ONYXKEYS.SESSION); - const {route, report} = props; + const {route, report, reportMetadata} = props; const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${report?.reportID ?? -1}`); const accountID = ('accountID' in route.params && route.params.accountID) || ''; const isPrivateNotesFetchTriggered = report?.isLoadingPrivateNotes !== undefined; @@ -39,7 +39,7 @@ export default function (pageTitle: TranslationPaths) { const isReconnecting = prevIsOffline && !isOffline; const isOtherUserNote = !!accountID && Number(session?.accountID) !== Number(accountID); const isPrivateNotesFetchFinished = isPrivateNotesFetchTriggered && !report.isLoadingPrivateNotes; - const isPrivateNotesUndefined = accountID ? report?.privateNotes?.[Number(accountID)]?.note === undefined : isEmptyObject(report?.privateNotes); + const isPrivateNotesUndefined = accountID ? reportMetadata?.privateNotes?.[Number(accountID)]?.note === undefined : isEmptyObject(reportMetadata?.privateNotes); useEffect(() => { // Do not fetch private notes if isLoadingPrivateNotes is already defined, or if network is offline. diff --git a/src/types/onyx/Report.ts b/src/types/onyx/Report.ts index 1241556c8dbd..2359001f709a 100644 --- a/src/types/onyx/Report.ts +++ b/src/types/onyx/Report.ts @@ -14,15 +14,6 @@ type WriteCapability = ValueOf; /** Defines which users have access to the chat */ type RoomVisibility = ValueOf; -/** Model of report private note */ -type Note = OnyxCommon.OnyxValueWithOfflineFeedback<{ - /** Content of the note */ - note: string; - - /** Collection of errors to show to the user */ - errors?: OnyxCommon.Errors; -}>; - /** The pending member of report */ type PendingChatMember = { /** Account ID of the pending member */ @@ -229,9 +220,6 @@ type Report = OnyxCommon.OnyxValueWithOfflineFeedback< /** Whether the report is hidden from options list */ isHidden?: boolean; - /** Collection of participant private notes, indexed by their accountID */ - privateNotes?: Record; - /** Whether participants private notes are being currently loaded */ isLoadingPrivateNotes?: boolean; @@ -271,4 +259,4 @@ type ReportCollectionDataSet = CollectionDataSet; + /** Model of report metadata */ type ReportMetadata = { /** Are we loading newer report actions? */ @@ -17,6 +28,11 @@ type ReportMetadata = { /** The time when user last visited the report */ lastVisitTime?: string; + + /** Collection of participant private notes, indexed by their accountID */ + privateNotes?: Record; }; export default ReportMetadata; + +export type {Note}; diff --git a/src/types/utils/whitelistedReportKeys.ts b/src/types/utils/whitelistedReportKeys.ts index 3c566c987526..25e6fafc8bf4 100644 --- a/src/types/utils/whitelistedReportKeys.ts +++ b/src/types/utils/whitelistedReportKeys.ts @@ -60,7 +60,6 @@ type WhitelistedReport = OnyxCommon.OnyxValueWithOfflineFeedback< preexistingReportID: unknown; nonReimbursableTotal: unknown; isHidden: unknown; - privateNotes: unknown; isLoadingPrivateNotes: unknown; pendingChatMembers: unknown; transactionThreadReportID: unknown;