Skip to content

fix: deleted workspace doesn´t appear as Archived #61891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/components/OptionListContextProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {createContext, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import {useOnyx} from 'react-native-onyx';
import type {OnyxCollection} from 'react-native-onyx';
import usePrevious from '@hooks/usePrevious';
import {createOptionFromReport, createOptionList, processReport} from '@libs/OptionsListUtils';
import type {OptionList, SearchOption} from '@libs/OptionsListUtils';
Expand Down Expand Up @@ -84,23 +85,35 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
loadOptions();
}, [prevReportAttributesLocale, loadOptions, reportAttributes?.locale]);

const changedReportsEntries = useMemo(() => {
const result: OnyxCollection<Report> = {};

Object.keys(changedReports ?? {}).forEach((key) => {
const report = reports?.[key];
if (report) {
result[key] = report;
}
});
return result;
}, [changedReports, reports]);

/**
* This effect is responsible for updating the options only for changed reports
*/
useEffect(() => {
if (!changedReports || !areOptionsInitialized.current) {
if (!changedReportsEntries || !areOptionsInitialized.current) {
return;
}

setOptions((prevOptions) => {
const changedReportKeys = Object.keys(changedReports);
const changedReportKeys = Object.keys(changedReportsEntries);
if (changedReportKeys.length === 0) {
return prevOptions;
}

const updatedReportsMap = new Map(prevOptions.reports.map((report) => [report.reportID, report]));
changedReportKeys.forEach((reportKey) => {
const report = changedReports[reportKey];
const report = changedReportsEntries[reportKey];
const reportID = reportKey.replace(ONYXKEYS.COLLECTION.REPORT, '');
const {reportOption} = processReport(report, personalDetails);

Expand All @@ -116,7 +129,7 @@ function OptionsListContextProvider({children}: OptionsListProviderProps) {
reports: Array.from(updatedReportsMap.values()),
};
});
}, [changedReports, personalDetails]);
}, [changedReportsEntries, personalDetails]);

/**
* This effect is used to update the options list when personal details change.
Expand Down
Loading