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
19 changes: 18 additions & 1 deletion src/components/Search/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React, {forwardRef, useCallback, useEffect, useImperativeHandle, useRef,
import type {ForwardedRef} from 'react';
import {View} from 'react-native';
import type {FlatList, ListRenderItemInfo, NativeSyntheticEvent, StyleProp, ViewStyle, ViewToken} from 'react-native';
import {useOnyx} from 'react-native-onyx';
import Animated from 'react-native-reanimated';
import type {FlatListPropsWithLayout} from 'react-native-reanimated';
import Checkbox from '@components/Checkbox';
Expand All @@ -28,6 +29,7 @@ import {isMobileChrome} from '@libs/Browser';
import {addKeyDownPressListener, removeKeyDownPressListener} from '@libs/KeyboardShortcut/KeyDownPressListener';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';

type SearchListItem = TransactionListItemType | ReportListItemType | ReportActionListItemType;
type SearchListItemComponentType = typeof TransactionListItem | typeof ChatListItem | typeof ReportListItem;
Expand Down Expand Up @@ -125,6 +127,8 @@ function SearchList(
// Keep track of the number of selected items to determine if we should turn off selection mode
const selectionRef = useRef(0);

const [policies] = useOnyx(ONYXKEYS.COLLECTION.POLICY);

useEffect(() => {
selectionRef.current = selectedItemsLength;

Expand Down Expand Up @@ -304,10 +308,23 @@ function SearchList(
}}
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
queryJSONHash={queryJSONHash}
policies={policies}
/>
);
},
[ListItem, canSelectMultiple, focusedIndex, handleLongPressRow, itemsToHighlight, onCheckboxPress, onSelectRow, queryJSONHash, setFocusedIndex, shouldPreventDefaultFocusOnSelectRow],
[
ListItem,
canSelectMultiple,
focusedIndex,
handleLongPressRow,
itemsToHighlight,
onCheckboxPress,
onSelectRow,
policies,
queryJSONHash,
setFocusedIndex,
shouldPreventDefaultFocusOnSelectRow,
],
);

return (
Expand Down
2 changes: 2 additions & 0 deletions src/components/SelectionList/ChatListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ function ChatListItem<TItem extends ListItem>({
onFocus,
onLongPressRow,
shouldSyncFocus,
policies,
}: ChatListItemProps<TItem>) {
const reportActionItem = item as unknown as ReportActionListItemType;
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportActionItem?.reportID ?? CONST.DEFAULT_NUMBER_ID}`);
Expand Down Expand Up @@ -87,6 +88,7 @@ function ChatListItem<TItem extends ListItem>({
CONST.REPORT.ACTIONS.TYPE.FORWARDED,
].some((type) => type === reportActionItem.actionName)
}
policies={policies}
/>
</BaseListItem>
);
Expand Down
5 changes: 5 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import type {
TextStyle,
ViewStyle,
} from 'react-native';
import type {OnyxCollection} from 'react-native-onyx';
import type {AnimatedStyle} from 'react-native-reanimated';
import type {SearchRouterItem} from '@components/Search/SearchAutocompleteList';
import type {SearchColumnType} from '@components/Search/types';
import type {BrickRoad} from '@libs/WorkspacesSettingsUtils';
// eslint-disable-next-line no-restricted-imports
import type CursorStyles from '@styles/utils/cursor/types';
import type CONST from '@src/CONST';
import type {Policy} from '@src/types/onyx';
import type {Attendee} from '@src/types/onyx/IOU';
import type {Errors, Icon, PendingAction} from '@src/types/onyx/OnyxCommon';
import type {SearchPersonalDetails, SearchReport, SearchReportAction, SearchTransaction} from '@src/types/onyx/SearchResults';
Expand Down Expand Up @@ -362,6 +364,9 @@ type ReportListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {

type ChatListItemProps<TItem extends ListItem> = ListItemProps<TItem> & {
queryJSONHash?: number;

/** The policies which the user has access to */
policies?: OnyxCollection<Policy>;
};

type ValidListItem =
Expand Down
7 changes: 6 additions & 1 deletion src/pages/home/report/PureReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import mapValues from 'lodash/mapValues';
import React, {memo, useCallback, useContext, useEffect, useMemo, useRef, useState} from 'react';
import type {GestureResponderEvent, TextInput} from 'react-native';
import {InteractionManager, Keyboard, View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import type {Emoji} from '@assets/emojis/types';
import {AttachmentContext} from '@components/AttachmentContext';
Expand Down Expand Up @@ -329,6 +329,9 @@ type PureReportActionItemProps = {

/** A message related to a report action that has been automatically forwarded */
reportAutomaticallyForwardedMessage?: string;

/** Policies */
policies?: OnyxCollection<OnyxTypes.Policy>;
};

// This is equivalent to returning a negative boolean in normal functions, but we can keep the element return type
Expand Down Expand Up @@ -400,6 +403,7 @@ function PureReportActionItem({
dismissTrackExpenseActionableWhisper = () => {},
userBillingFundID,
reportAutomaticallyForwardedMessage,
policies,
}: PureReportActionItemProps) {
const {translate} = useLocalize();
const {shouldUseNarrowLayout} = useResponsiveLayout();
Expand Down Expand Up @@ -1221,6 +1225,7 @@ function PureReportActionItem({
hasBeenFlagged={
![CONST.MODERATION.MODERATOR_DECISION_APPROVED, CONST.MODERATION.MODERATOR_DECISION_PENDING].some((item) => item === moderationDecision) && !isPendingRemove(action)
}
policies={policies}
>
{content}
</ReportActionItemSingle>
Expand Down
15 changes: 10 additions & 5 deletions src/pages/home/report/ReportActionItemSingle.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useCallback, useMemo} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Avatar from '@components/Avatar';
import {FallbackAvatar} from '@components/Icon/Expensicons';
import MultipleAvatars from '@components/MultipleAvatars';
Expand Down Expand Up @@ -39,7 +39,7 @@ import {
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Report, ReportAction} from '@src/types/onyx';
import type {Policy, Report, ReportAction} from '@src/types/onyx';
import type {Icon} from '@src/types/onyx/OnyxCommon';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import ReportActionItemDate from './ReportActionItemDate';
Expand Down Expand Up @@ -72,6 +72,9 @@ type ReportActionItemSingleProps = Partial<ChildrenProps> & {

/** If the action is being actived */
isActive?: boolean;

/** Policies */
policies?: OnyxCollection<Policy>;
};

const showUserDetails = (accountID: number | undefined) => {
Expand All @@ -96,6 +99,7 @@ function ReportActionItemSingle({
iouReport,
isHovered = false,
isActive = false,
policies,
}: ReportActionItemSingleProps) {
const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -107,9 +111,10 @@ function ReportActionItemSingle({
const ownerAccountID = iouReport?.ownerAccountID ?? action?.childOwnerAccountID;
const isReportPreviewAction = action?.actionName === CONST.REPORT.ACTIONS.TYPE.REPORT_PREVIEW;
const actorAccountID = getReportActionActorAccountID(action, iouReport, report, delegatePersonalDetails);
const [invoiceReceiverPolicy] = useOnyx(
`${ONYXKEYS.COLLECTION.POLICY}${report?.invoiceReceiver && 'policyID' in report.invoiceReceiver ? report.invoiceReceiver.policyID : CONST.DEFAULT_NUMBER_ID}`,
);
const invoiceReceiverPolicy =
report?.invoiceReceiver && 'policyID' in report.invoiceReceiver
? policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report.invoiceReceiver.policyID}`]
: policies?.[`${ONYXKEYS.COLLECTION.POLICY}${CONST.DEFAULT_NUMBER_ID}`];

let displayName = getDisplayNameForParticipant({accountID: actorAccountID, personalDetailsData: personalDetails});
const {avatar, login, pendingFields, status, fallbackIcon} = personalDetails?.[actorAccountID ?? CONST.DEFAULT_NUMBER_ID] ?? {};
Expand Down