diff --git a/src/components/LHNOptionsList/OptionRowLHNData.tsx b/src/components/LHNOptionsList/OptionRowLHNData.tsx index cc6e677a6ab9..b4b2d4bb43e9 100644 --- a/src/components/LHNOptionsList/OptionRowLHNData.tsx +++ b/src/components/LHNOptionsList/OptionRowLHNData.tsx @@ -92,6 +92,7 @@ function OptionRowLHNData({ invoiceReceiverPolicy, shouldDisplayReportViolations, lastMessageTextFromReport, + reportAttributes, ]); return ( diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 1d2210590a19..d78f8d216afe 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -1,5 +1,6 @@ import {generateReportName, isValidReport} from '@libs/ReportUtils'; import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig'; +import hasKeyTriggeredCompute from '@userActions/OnyxDerived/utils'; import ONYXKEYS from '@src/ONYXKEYS'; import type {Report, ReportAttributesDerivedValue, ReportMetadata} from '@src/types/onyx'; @@ -22,17 +23,18 @@ export default createOnyxDerivedValueConfig({ ONYXKEYS.COLLECTION.REPORT_METADATA, ], compute: (dependencies, {currentValue, sourceValues}) => { - const areAllDependenciesSet = [...dependencies].every((dependency) => dependency !== undefined); + // transactions are undefined by default so it needs to be set to an empty object as default + const [reports, preferredLocale, personalDetails, transactions = {}, ...rest] = dependencies; + + const areAllDependenciesSet = [reports, preferredLocale, personalDetails, transactions, ...rest].every((dependency) => dependency !== undefined); if (!areAllDependenciesSet) { return { reports: {}, locale: null, }; } - const [reports, preferredLocale] = dependencies; - - // if the preferred locale has changed, reset the isFullyComputed flag - if (preferredLocale !== currentValue?.locale) { + // if any of those keys changed, reset the isFullyComputed flag to recompute all reports + if (hasKeyTriggeredCompute(ONYXKEYS.NVP_PREFERRED_LOCALE, sourceValues) || hasKeyTriggeredCompute(ONYXKEYS.PERSONAL_DETAILS_LIST, sourceValues)) { isFullyComputed = false; } diff --git a/src/libs/actions/OnyxDerived/index.ts b/src/libs/actions/OnyxDerived/index.ts index 4fbd0543cd12..15a2361072ff 100644 --- a/src/libs/actions/OnyxDerived/index.ts +++ b/src/libs/actions/OnyxDerived/index.ts @@ -76,7 +76,8 @@ function init() { callback: (value) => { Log.info(`[OnyxDerived] dependency ${dependencyOnyxKey} for derived key ${key} changed, recomputing`); setDependencyValue(i, value as Parameters[0][typeof i]); - recomputeDerivedValue(dependencyOnyxKey); + // if the dependency is not a collection, pass the entire value as the source value + recomputeDerivedValue(dependencyOnyxKey, value); }, }); } diff --git a/src/libs/actions/OnyxDerived/utils.ts b/src/libs/actions/OnyxDerived/utils.ts new file mode 100644 index 000000000000..81883bfbacfe --- /dev/null +++ b/src/libs/actions/OnyxDerived/utils.ts @@ -0,0 +1,15 @@ +import type {NonEmptyTuple} from 'type-fest'; +import type {OnyxKey} from '@src/ONYXKEYS'; +import type {DerivedValueContext} from './types'; + +/** + * Check if a specific key exists in sourceValue from OnyxDerived + */ +const hasKeyTriggeredCompute = >>(key: K, sourceValues: DerivedValueContext['sourceValues']) => { + if (!sourceValues) { + return false; + } + return Object.keys(sourceValues).some((sourceKey) => sourceKey === key); +}; + +export default hasKeyTriggeredCompute;