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
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ function TransactionGroupListItem<TItem extends ListItem>({
offset: isRefresh ? 0 : (transactionsSnapshot?.search?.offset ?? 0) + pageSize,
shouldCalculateTotals: false,
isLoading: !!transactionsSnapshot?.search?.isLoading,
isOffline,
});
},
[groupItem.transactionsQueryJSON, transactionsSnapshot?.search?.offset, transactionsSnapshot?.search?.isLoading],
[groupItem.transactionsQueryJSON, isOffline, transactionsSnapshot?.search?.offset, transactionsSnapshot?.search?.isLoading],
);

const animatedHighlightStyle = useAnimatedHighlightStyle({
Expand Down
103 changes: 71 additions & 32 deletions src/libs/actions/IOU/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
updateOptimisticParentReportAction,
updateReportPreview,
} from '@libs/ReportUtils';
import {buildCannedSearchQuery, getCurrentSearchQueryJSON} from '@libs/SearchQueryUtils';
import {buildCannedSearchQuery, buildSearchQueryJSON, buildSearchQueryString, getCurrentSearchQueryJSON} from '@libs/SearchQueryUtils';
import {getSuggestedSearches} from '@libs/SearchUIUtils';
import playSound, {SOUNDS} from '@libs/Sound';
import {shouldRestrictUserBillableActions} from '@libs/SubscriptionUtils';
Expand Down Expand Up @@ -801,7 +801,7 @@
};

let allPersonalDetails: OnyxTypes.PersonalDetailsList = {};
Onyx.connect({

Check warning on line 804 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand Down Expand Up @@ -894,7 +894,7 @@
};

let allTransactions: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 897 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -908,7 +908,7 @@
});

let allTransactionDrafts: NonNullable<OnyxCollection<OnyxTypes.Transaction>> = {};
Onyx.connect({

Check warning on line 911 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_DRAFT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -917,7 +917,7 @@
});

let allTransactionViolations: NonNullable<OnyxCollection<OnyxTypes.TransactionViolations>> = {};
Onyx.connect({

Check warning on line 920 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -931,7 +931,7 @@
});

let allPolicyTags: OnyxCollection<OnyxTypes.PolicyTagLists> = {};
Onyx.connect({

Check warning on line 934 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.POLICY_TAGS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -944,7 +944,7 @@
});

let allReports: OnyxCollection<OnyxTypes.Report>;
Onyx.connect({

Check warning on line 947 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -953,7 +953,7 @@
});

let allReportNameValuePairs: OnyxCollection<OnyxTypes.ReportNameValuePairs>;
Onyx.connect({

Check warning on line 956 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -963,7 +963,7 @@

let userAccountID = -1;
let currentUserEmail = '';
Onyx.connect({

Check warning on line 966 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserEmail = value?.email ?? '';
Expand All @@ -972,7 +972,7 @@
});

let deprecatedCurrentUserPersonalDetails: OnyxEntry<OnyxTypes.PersonalDetails>;
Onyx.connect({

Check warning on line 975 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
deprecatedCurrentUserPersonalDetails = value?.[userAccountID] ?? undefined;
Expand All @@ -980,7 +980,7 @@
});

let allReportActions: OnyxCollection<OnyxTypes.ReportActions>;
Onyx.connect({

Check warning on line 983 in src/libs/actions/IOU/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
waitForCollectionCallback: true,
callback: (actions) => {
Expand Down Expand Up @@ -12528,41 +12528,80 @@
},
});
}
return {
optimisticData: [
{
const snapshotData = {
[ONYXKEYS.PERSONAL_DETAILS_LIST]: {
[toAccountID]: {
accountID: toAccountID,
displayName: participant?.displayName,
login: participant?.login,
},
[fromAccountID]: {
accountID: fromAccountID,
avatar: deprecatedCurrentUserPersonalDetails?.avatar,
displayName: deprecatedCurrentUserPersonalDetails?.displayName,
login: deprecatedCurrentUserPersonalDetails?.login,
},
},
[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`]: {
accountID: fromAccountID,
managerID: toAccountID,
...(transactionThreadReportID && {transactionThreadReportID}),
...(isFromOneTransactionReport && {isFromOneTransactionReport}),
...transaction,
},
...(policy && {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy}),
...(iouReport && {[`${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`]: iouReport}),
...(iouReport && iouAction && {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`]: {[iouAction.reportActionID]: iouAction}}),
};

const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.SNAPSHOT>> = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${currentSearchQueryJSON.hash}` as const,
value: {
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
data: snapshotData,
},
},
];

if (currentSearchQueryJSON.groupBy === CONST.SEARCH.GROUP_BY.FROM) {
const newFlatFilters = currentSearchQueryJSON.flatFilters.filter((filter) => filter.key !== CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM);
newFlatFilters.push({
key: CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM,
filters: [{operator: CONST.SEARCH.SYNTAX_OPERATORS.EQUAL_TO, value: fromAccountID}],
});

const groupTransactionsQueryJSON = buildSearchQueryJSON(
buildSearchQueryString({
...currentSearchQueryJSON,
groupBy: undefined,
flatFilters: newFlatFilters,
}),
);

if (groupTransactionsQueryJSON?.hash) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${currentSearchQueryJSON.hash}` as const,
key: `${ONYXKEYS.COLLECTION.SNAPSHOT}${groupTransactionsQueryJSON.hash}` as const,
value: {
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
data: {
[ONYXKEYS.PERSONAL_DETAILS_LIST]: {
[toAccountID]: {
accountID: toAccountID,
displayName: participant?.displayName,
login: participant?.login,
},
[fromAccountID]: {
accountID: fromAccountID,
avatar: deprecatedCurrentUserPersonalDetails?.avatar,
displayName: deprecatedCurrentUserPersonalDetails?.displayName,
login: deprecatedCurrentUserPersonalDetails?.login,
},
},
[`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`]: {
accountID: fromAccountID,
managerID: toAccountID,
...(transactionThreadReportID && {transactionThreadReportID}),
...(isFromOneTransactionReport && {isFromOneTransactionReport}),
...transaction,
},
...(policy && {[`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`]: policy}),
...(iouReport && {[`${ONYXKEYS.COLLECTION.REPORT}${iouReport.reportID}`]: iouReport}),
...(iouReport && iouAction && {[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${iouReport.reportID}`]: {[iouAction.reportActionID]: iouAction}}),
search: {
type: groupTransactionsQueryJSON.type,
status: groupTransactionsQueryJSON.status,
offset: 0,
hasMoreResults: false,
hasResults: true,
isLoading: false,
},
// @ts-expect-error - will be solved in https://github.com/Expensify/App/issues/73830
data: snapshotData,
},
},
],
});
}
}

return {
optimisticData,
successData,
};
}
Expand Down
Loading
Loading