From 7efe52402ba690d203393a1d1b2f662319d22e22 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Wed, 1 May 2024 18:33:39 +0800 Subject: [PATCH 1/2] remove report from cache when deleted --- src/components/OptionListContextProvider.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/OptionListContextProvider.tsx b/src/components/OptionListContextProvider.tsx index b530eecd4d3c..44230105c5dc 100644 --- a/src/components/OptionListContextProvider.tsx +++ b/src/components/OptionListContextProvider.tsx @@ -86,7 +86,7 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp }, [reports]); /** - * This effect is used to add a new report option to the list of options when a new report is added to the collection. + * This effect is used to add a new report option or remove a report option to the list of options when a new report is added to/removed from the collection. */ useEffect(() => { if (!areOptionsInitialized.current || !reports) { @@ -95,7 +95,10 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp const missingReportIds = Object.keys(reports).filter((key) => prevReports && !(key in prevReports)); setOptions((prevOptions) => { - const newOptions = {...prevOptions}; + const newOptions = { + ...prevOptions, + reports: prevOptions.reports.filter((report) => reports[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`] !== null), + }; missingReportIds.forEach((missingReportId) => { const report = missingReportId ? reports[missingReportId] : null; if (!missingReportId || !report) { From f1333ea3db92896a34ec1853068efdbe77f0b3ff Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Thu, 2 May 2024 10:36:53 +0800 Subject: [PATCH 2/2] update comment --- src/components/OptionListContextProvider.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/OptionListContextProvider.tsx b/src/components/OptionListContextProvider.tsx index 44230105c5dc..4eef9e93f188 100644 --- a/src/components/OptionListContextProvider.tsx +++ b/src/components/OptionListContextProvider.tsx @@ -86,7 +86,7 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp }, [reports]); /** - * This effect is used to add a new report option or remove a report option to the list of options when a new report is added to/removed from the collection. + * This effect is used to add a new report option or remove a report option from the list of options when a new report is added to/removed from the collection. */ useEffect(() => { if (!areOptionsInitialized.current || !reports) {