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
1 change: 1 addition & 0 deletions src/components/LHNOptionsList/OptionRowLHNData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ function OptionRowLHNData({
invoiceReceiverPolicy,
shouldDisplayReportViolations,
lastMessageTextFromReport,
reportAttributes,
]);

return (
Expand Down
12 changes: 7 additions & 5 deletions src/libs/actions/OnyxDerived/configs/reportAttributes.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/libs/actions/OnyxDerived/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ function init() {
callback: (value) => {
Log.info(`[OnyxDerived] dependency ${dependencyOnyxKey} for derived key ${key} changed, recomputing`);
setDependencyValue(i, value as Parameters<typeof compute>[0][typeof i]);
recomputeDerivedValue(dependencyOnyxKey);
// if the dependency is not a collection, pass the entire value as the source value
recomputeDerivedValue(dependencyOnyxKey, value);
},
});
}
Expand Down
15 changes: 15 additions & 0 deletions src/libs/actions/OnyxDerived/utils.ts
Original file line number Diff line number Diff line change
@@ -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 = <K extends OnyxKey, Deps extends NonEmptyTuple<Exclude<OnyxKey, K>>>(key: K, sourceValues: DerivedValueContext<K, Deps>['sourceValues']) => {
if (!sourceValues) {
return false;
}
return Object.keys(sourceValues).some((sourceKey) => sourceKey === key);
};

export default hasKeyTriggeredCompute;