Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions src/components/TestToolMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import useIsAuthenticated from '@hooks/useIsAuthenticated';
import useLocalize from '@hooks/useLocalize';
import useOnyx from '@hooks/useOnyx';
import {useSidebarOrderedReports} from '@hooks/useSidebarOrderedReports';
import useThemeStyles from '@hooks/useThemeStyles';
import {isUsingStagingApi} from '@libs/ApiUtils';
import {setShouldFailAllRequests, setShouldForceOffline, setShouldSimulatePoorConnection} from '@userActions/Network';
Expand All @@ -23,6 +24,7 @@ function TestToolMenu() {
const [isDebugModeEnabled = false] = useOnyx(ONYXKEYS.IS_DEBUG_MODE_ENABLED, {canBeMissing: true});
const styles = useThemeStyles();
const {translate} = useLocalize();
const {clearLHNCache} = useSidebarOrderedReports();

// Check if the user is authenticated to show options that require authentication
const isAuthenticated = useIsAuthenticated();
Expand Down Expand Up @@ -72,6 +74,15 @@ function TestToolMenu() {
onPress={() => expireSessionWithDelay()}
/>
</TestToolRow>

{/* Clears the useSidebarOrderedReports cache to re-compute from latest onyx values */}
<TestToolRow title={translate('initialSettingsPage.troubleshoot.leftHandNavCache')}>
<Button
small
text={translate('initialSettingsPage.troubleshoot.clearleftHandNavCache')}
onPress={clearLHNCache}
/>
</TestToolRow>
</>
)}

Expand Down
31 changes: 29 additions & 2 deletions src/hooks/useSidebarOrderedReports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type SidebarOrderedReportsContextValue = {
orderedReportIDs: string[];
currentReportID: string | undefined;
policyMemberAccountIDs: number[];
clearLHNCache: () => void;
};

type ReportsToDisplayInLHN = Record<string, OnyxTypes.Report & {hasErrorsOtherThanFailedReceipt?: boolean}>;
Expand All @@ -40,6 +41,7 @@ const SidebarOrderedReportsContext = createContext<SidebarOrderedReportsContextV
orderedReportIDs: [],
currentReportID: '',
policyMemberAccountIDs: [],
clearLHNCache: () => {},
});

const policySelector = (policy: OnyxEntry<OnyxTypes.Policy>): PartialPolicyForSidebar =>
Expand Down Expand Up @@ -81,6 +83,10 @@ function SidebarOrderedReportsContextProvider({
const derivedCurrentReportID = currentReportIDForTests ?? currentReportIDValue?.currentReportID;
const prevDerivedCurrentReportID = usePrevious(derivedCurrentReportID);

// we need to force reportsToDisplayInLHN to re-compute when we clear currentReportsToDisplay, but the way it currently works relies on not having currentReportsToDisplay as a memo dependency, so we just need something we can change to trigger it
// I don't like it either, but clearing the cache is only a hack for the debug modal and I will endeavor to make it better as I work to improve the cache correctness of the LHN more broadly
const [clearCacheDummyCounter, setClearCacheDummyCounter] = useState(0);

const policyMemberAccountIDs = useMemo(() => getPolicyEmployeeListByIdWithoutCurrentUser(policies, undefined, accountID), [policies, accountID]);
const prevBetas = usePrevious(betas);
const prevPriorityMode = usePrevious(priorityMode);
Expand Down Expand Up @@ -185,6 +191,7 @@ function SidebarOrderedReportsContextProvider({
draftComments: reportsDrafts,
});
} else {
Log.info('[useSidebarOrderedReports] building reportsToDisplay from scratch');
reportsToDisplay = SidebarUtils.getReportsToDisplayInLHN(
derivedCurrentReportID,
chatReports,
Expand All @@ -201,7 +208,19 @@ function SidebarOrderedReportsContextProvider({
return reportsToDisplay;
// Rule disabled intentionally — triggering a re-render on currentReportsToDisplay would cause an infinite loop
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
}, [getUpdatedReports, chatReports, derivedCurrentReportID, priorityMode, betas, policies, transactionViolations, reportNameValuePairs, reportAttributes, reportsDrafts]);
}, [
getUpdatedReports,
chatReports,
derivedCurrentReportID,
priorityMode,
betas,
policies,
transactionViolations,
reportNameValuePairs,
reportAttributes,
reportsDrafts,
clearCacheDummyCounter,
]);

const deepComparedReportsToDisplayInLHN = useDeepCompareRef(reportsToDisplayInLHN);
const deepComparedReportsDrafts = useDeepCompareRef(reportsDrafts);
Expand Down Expand Up @@ -232,6 +251,12 @@ function SidebarOrderedReportsContextProvider({

const orderedReports = useMemo(() => getOrderedReports(orderedReportIDs), [getOrderedReports, orderedReportIDs]);

const clearLHNCache = useCallback(() => {
Log.info('[useSidebarOrderedReports] Clearing sidebar cache manually via debug modal');
setCurrentReportsToDisplay({});
setClearCacheDummyCounter((current) => current + 1);
}, []);

const contextValue: SidebarOrderedReportsContextValue = useMemo(() => {
// We need to make sure the current report is in the list of reports, but we do not want
// to have to re-generate the list every time the currentReportID changes. To do that
Expand All @@ -256,6 +281,7 @@ function SidebarOrderedReportsContextProvider({
orderedReportIDs: updatedReportIDs,
currentReportID: derivedCurrentReportID,
policyMemberAccountIDs,
clearLHNCache,
};
}

Expand All @@ -264,8 +290,9 @@ function SidebarOrderedReportsContextProvider({
orderedReportIDs,
currentReportID: derivedCurrentReportID,
policyMemberAccountIDs,
clearLHNCache,
};
}, [getOrderedReportIDs, orderedReportIDs, derivedCurrentReportID, policyMemberAccountIDs, shouldUseNarrowLayout, getOrderedReports, orderedReports]);
}, [getOrderedReportIDs, orderedReportIDs, derivedCurrentReportID, policyMemberAccountIDs, shouldUseNarrowLayout, getOrderedReports, orderedReports, clearLHNCache]);

const currentDeps = {
priorityMode,
Expand Down
2 changes: 2 additions & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,8 @@ const translations: TranslationDeepObject<typeof en> = {
sentryDebugDescription: 'Sentry-Anfragen in der Konsole protokollieren',
sentryHighlightedSpanOps: 'Hervorgehobene Span-Namen',
sentryHighlightedSpanOpsPlaceholder: 'ui.interaction.click, navigation, ui.load',
leftHandNavCache: 'Cache für linke Seitenleiste',
clearleftHandNavCache: 'Löschen',
},
debugConsole: {
saveLog: 'Protokoll speichern',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,8 @@ const translations = {
invalidFile: 'Invalid file',
invalidFileDescription: 'The file you are trying to import is not valid. Please try again.',
invalidateWithDelay: 'Invalidate with delay',
leftHandNavCache: 'Left Hand Nav cache',
clearleftHandNavCache: 'Clear',
recordTroubleshootData: 'Record Troubleshoot Data',
softKillTheApp: 'Soft kill the app',
kill: 'Kill',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1518,6 +1518,8 @@ const translations: TranslationDeepObject<typeof en> = {
invalidFile: 'Archivo inválido',
invalidFileDescription: 'El archivo que ests intentando importar no es válido. Por favor, inténtalo de nuevo.',
invalidateWithDelay: 'Invalidar con retraso',
leftHandNavCache: 'Caché del menú de navegación izquierdo',
clearleftHandNavCache: 'borrar',
recordTroubleshootData: 'Registrar datos de resolución de problemas',
softKillTheApp: 'Desactivar la aplicación',
kill: 'Matar',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1860,6 +1860,8 @@ const translations: TranslationDeepObject<typeof en> = {
sentryDebugDescription: 'Enregistrer les requêtes Sentry dans la console',
sentryHighlightedSpanOps: 'Noms de spans mis en valeur',
sentryHighlightedSpanOpsPlaceholder: 'ui.interaction.click, navigation, ui.load',
leftHandNavCache: 'Cache de navigation gauche',
clearleftHandNavCache: 'Effacer',
},
debugConsole: {
saveLog: 'Enregistrer le journal',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,8 @@ const translations: TranslationDeepObject<typeof en> = {
sentryDebugDescription: 'Registra le richieste Sentry nella console',
sentryHighlightedSpanOps: 'Nomi degli span evidenziati',
sentryHighlightedSpanOpsPlaceholder: 'ui.interaction.click, navigation, ui.load',
leftHandNavCache: 'Cache della navigazione sinistra',
clearleftHandNavCache: 'Cancella',
},
debugConsole: {
saveLog: 'Salva registro',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,8 @@ const translations: TranslationDeepObject<typeof en> = {
sentryDebugDescription: 'Sentryリクエストをコンソールに記録',
sentryHighlightedSpanOps: 'ハイライト表示するspan名',
sentryHighlightedSpanOpsPlaceholder: 'ui.interaction.click, navigation, ui.load',
leftHandNavCache: '左側ナビキャッシュ',
clearleftHandNavCache: 'クリア',
},
debugConsole: {
saveLog: 'ログを保存',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,8 @@ const translations: TranslationDeepObject<typeof en> = {
sentryDebugDescription: 'Sentry-verzoeken naar console loggen',
sentryHighlightedSpanOps: 'Geresalteerde spannamen',
sentryHighlightedSpanOpsPlaceholder: 'ui.interaction.click, navigation, ui.load',
leftHandNavCache: 'Cache van linkernavigatie',
clearleftHandNavCache: 'Wissen',
},
debugConsole: {
saveLog: 'Log opslaan',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,8 @@ const translations: TranslationDeepObject<typeof en> = {
sentryDebugDescription: 'Rejestruj żądania Sentry w konsoli',
sentryHighlightedSpanOps: 'Nazwy wyróżnionych spanów',
sentryHighlightedSpanOpsPlaceholder: 'ui.interaction.click, navigation, ui.load',
leftHandNavCache: 'Pamięć podręczna lewego panelu nawigacyjnego',
clearleftHandNavCache: 'Wyczyść',
},
debugConsole: {
saveLog: 'Zapisz log',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1848,6 +1848,8 @@ const translations: TranslationDeepObject<typeof en> = {
sentryDebugDescription: 'Registrar solicitações do Sentry no console',
sentryHighlightedSpanOps: 'Nomes de spans destacados',
sentryHighlightedSpanOpsPlaceholder: 'ui.interaction.click, navigation, ui.load',
leftHandNavCache: 'Cache da navegação lateral esquerda',
clearleftHandNavCache: 'Limpar',
},
debugConsole: {
saveLog: 'Salvar log',
Expand Down
2 changes: 2 additions & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1825,6 +1825,8 @@ const translations: TranslationDeepObject<typeof en> = {
sentryDebugDescription: '将Sentry请求记录到控制台',
sentryHighlightedSpanOps: '突出显示的Span名称',
sentryHighlightedSpanOpsPlaceholder: 'ui.interaction.click, navigation, ui.load',
leftHandNavCache: '左侧导航缓存',
clearleftHandNavCache: '清除',
},
debugConsole: {
saveLog: '保存日志',
Expand Down
Loading