Skip to content
Draft
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
23 changes: 21 additions & 2 deletions src/libs/actions/IOU/SearchUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {SearchQueryJSON} from '@components/Search/types';
Expand All @@ -10,9 +10,18 @@
import type * as OnyxTypes from '@src/types/onyx';
import type {Participant} from '@src/types/onyx/IOU';
import type {OnyxData} from '@src/types/onyx/Request';
import type {SearchResultDataType} from '@src/types/onyx/SearchResults';
import type {SearchMemberGroup, SearchResultDataType} from '@src/types/onyx/SearchResults';
import {getCurrentUserPersonalDetails} from './index';

let allSnapshots: OnyxCollection<OnyxTypes.SearchResults> = {};
Onyx.connect({

Check failure on line 17 in src/libs/actions/IOU/SearchUpdate.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function

Check failure on line 17 in src/libs/actions/IOU/SearchUpdate.ts

View workflow job for this annotation

GitHub Actions / ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.SNAPSHOT,
waitForCollectionCallback: true,
callback: (value) => {
allSnapshots = value ?? {};
},
});

type ExpenseReportStatusPredicate = (expenseReport: OnyxEntry<OnyxTypes.Report>, transactionReportID?: string) => boolean;

const expenseReportStatusFilterMapping: Record<string, ExpenseReportStatusPredicate> = {
Expand Down Expand Up @@ -202,6 +211,16 @@
];

if (currentSearchQueryJSON.groupBy === CONST.SEARCH.GROUP_BY.FROM) {
const groupKey = `${CONST.SEARCH.GROUP_PREFIX}${fromAccountID}`;
const currentSnapshot = allSnapshots[`${ONYXKEYS.COLLECTION.SNAPSHOT}${currentSearchQueryJSON.hash}`];

Check failure on line 215 in src/libs/actions/IOU/SearchUpdate.ts

View workflow job for this annotation

GitHub Actions / typecheck

'allSnapshots' is possibly 'undefined'.
const existingGroup = currentSnapshot?.data?.[groupKey] as SearchMemberGroup | undefined;

Check failure on line 216 in src/libs/actions/IOU/SearchUpdate.ts

View workflow job for this annotation

GitHub Actions / typecheck

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'SearchResultDataType'.
optimisticSnapshotData[groupKey] = {

Check failure on line 217 in src/libs/actions/IOU/SearchUpdate.ts

View workflow job for this annotation

GitHub Actions / typecheck

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'SearchResultDataType'.
accountID: fromAccountID,
count: (existingGroup?.count ?? 0) + 1,
total: (existingGroup?.total ?? 0) + (transaction.amount ?? 0),
currency: existingGroup?.currency ?? transaction.currency ?? CONST.CURRENCY.USD,
};

const newFlatFilters = currentSearchQueryJSON.flatFilters.filter((filter) => filter.key !== CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM);
newFlatFilters.push({
key: CONST.SEARCH.SYNTAX_FILTER_KEYS.FROM,
Expand Down
Loading