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
35 changes: 22 additions & 13 deletions src/components/LHNOptionsList/OptionRowLHN/OptionRow/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
import React from 'react';
import type {ColorValue, ViewStyle} from 'react-native';
import type {ColorValue} from 'react-native';
import type {ValueOf} from 'type-fest';
import LHNAvatar from '@components/LHNOptionsList/LHNAvatar';
import {usePersonalDetails} from '@components/OnyxListItemProvider';
import useThemeStyles from '@hooks/useThemeStyles';
import {shouldOptionShowTooltip} from '@libs/OptionsListUtils';
import {getDelegateAccountIDFromReportAction} from '@libs/ReportActionsUtils';
import type {OptionData} from '@libs/ReportUtils';
import CONST from '@src/CONST';

type OptionMode = ValueOf<typeof CONST.OPTION_MODE>;

type AvatarProps = {
/** Option data for the row. Source of avatar icons, subscript flag, tooltip eligibility, and delegate metadata. */
optionItem: OptionData;
isInFocusMode: boolean;
subscriptAvatarBorderColor: ColorValue;
secondaryAvatarBackgroundColor: ColorValue;
singleAvatarContainerStyle: ViewStyle[];

/** Display density mode. `COMPACT` switches the avatar size to `SMALL`. */
viewMode: OptionMode;

/** Background color used for both the subscript icon border and the secondary avatar background. Matches the row background so the chrome blends in. */
avatarBackgroundColor: ColorValue;
};

function AvatarInner({optionItem, isInFocusMode, subscriptAvatarBorderColor, secondaryAvatarBackgroundColor, singleAvatarContainerStyle}: AvatarProps) {
function AvatarInner({optionItem, viewMode, avatarBackgroundColor}: AvatarProps) {
const styles = useThemeStyles();
const personalDetails = usePersonalDetails();

const isInFocusMode = viewMode === CONST.OPTION_MODE.COMPACT;
const singleAvatarContainerStyle = [styles.actionAvatar, styles.mr3];

const delegateAccountID = getDelegateAccountIDFromReportAction(optionItem?.parentReportAction);

// Match the header's delegate avatar logic: when a delegate exists on the
Expand Down Expand Up @@ -53,9 +64,9 @@ function AvatarInner({optionItem, isInFocusMode, subscriptAvatarBorderColor, sec
icons={icons}
shouldShowSubscript={!!optionItem.shouldShowSubscript}
size={isInFocusMode ? CONST.AVATAR_SIZE.SMALL : CONST.AVATAR_SIZE.DEFAULT}
subscriptAvatarBorderColor={subscriptAvatarBorderColor}
subscriptAvatarBorderColor={avatarBackgroundColor}
useMidSubscriptSize={isInFocusMode}
secondaryAvatarBackgroundColor={secondaryAvatarBackgroundColor}
secondaryAvatarBackgroundColor={avatarBackgroundColor}
singleAvatarContainerStyle={singleAvatarContainerStyle}
shouldShowTooltip={shouldOptionShowTooltip(optionItem)}
delegateAccountID={skipDelegate ? undefined : delegateAccountID}
Expand All @@ -66,18 +77,16 @@ function AvatarInner({optionItem, isInFocusMode, subscriptAvatarBorderColor, sec

AvatarInner.displayName = 'OptionRow.AvatarInner';

function Avatar({optionItem, isInFocusMode, subscriptAvatarBorderColor, secondaryAvatarBackgroundColor, singleAvatarContainerStyle}: AvatarProps) {
function Avatar({optionItem, viewMode, avatarBackgroundColor}: AvatarProps) {
// Bail out before subscribing to personal details when the row has no avatar to render.
if (!optionItem.icons?.length || !optionItem.icons.at(0)) {
return null;
}
return (
<AvatarInner
optionItem={optionItem}
isInFocusMode={isInFocusMode}
subscriptAvatarBorderColor={subscriptAvatarBorderColor}
secondaryAvatarBackgroundColor={secondaryAvatarBackgroundColor}
singleAvatarContainerStyle={singleAvatarContainerStyle}
viewMode={viewMode}
avatarBackgroundColor={avatarBackgroundColor}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FS from '@libs/Fullstory';
import type {OptionData} from '@libs/ReportUtils';

type DescriptiveTextProps = {
/** Option data for the row. Renders `optionItem.descriptiveText` when present; component returns null otherwise. */
optionItem: OptionData;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';

type DraftIndicatorProps = {
/** Whether the report has an unsent draft comment. Required for the pencil icon to render. */
hasDraftComment: boolean;

/** Whether the current user can comment in the report. The icon is hidden in read-only rows even when a draft exists. */
isAllowedToComment: boolean | null | undefined;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type {OptionData} from '@libs/ReportUtils';
import CONST from '@src/CONST';

type ErrorBadgeProps = {
/** Brick road indicator for the row. The badge only renders when this equals ERROR (RBR). */
brickRoadIndicator: OptionData['brickRoadIndicator'];

/** Action badge key used to derive the badge label (translated locally, debug builds only). */
actionBadge: OptionData['actionBadge'];
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import type {ReactNode, RefObject} from 'react';
import React, {useState} from 'react';
import type {ReactNode} from 'react';
import React, {useRef, useState} from 'react';
import type {GestureResponderEvent, LayoutChangeEvent, View} from 'react-native';
import Hoverable from '@components/Hoverable';
import {useLHNTooltipContext} from '@components/LHNOptionsList/LHNTooltipContext';
import useLHNRowProductTrainingTooltip from '@components/LHNOptionsList/OptionRowLHN/useLHNRowProductTrainingTooltip';
import PressableWithSecondaryInteraction from '@components/PressableWithSecondaryInteraction';
import getContextMenuAccessibilityHint from '@components/utils/getContextMenuAccessibilityHint';
import getContextMenuAccessibilityProps from '@components/utils/getContextMenuAccessibilityProps';
import useEnvironment from '@hooks/useEnvironment';
import useLocalize from '@hooks/useLocalize';
import useResponsiveLayout from '@hooks/useResponsiveLayout';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
Expand All @@ -14,35 +20,72 @@ import {startSpan} from '@libs/telemetry/activeSpans';
import {showContextMenu} from '@pages/inbox/report/ContextMenu/ReportActionContextMenu';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import useLHNRowProductTrainingTooltip from './useLHNRowProductTrainingTooltip';

type OptionRowPressableProps = {
type PressableProps = {
/** Option data for the row. Source of accessibility text and the report ID used by press/context-menu actions. */
optionItem: OptionData;

/** Whether the row is the currently focused/active option. Drives the focused background and accessibility metadata. */
isOptionFocused: boolean;
isScreenFocused: boolean;
popoverAnchor: RefObject<View | null>;
onSelectRow: (optionItem: OptionData, popoverAnchor: RefObject<View | null>) => void;

/** Press handler invoked with the option data and the popover anchor ref. */
onSelectRow: (optionItem: OptionData, popoverAnchor: React.RefObject<View | null>) => void;

/** Layout handler forwarded to the underlying pressable. */
onLayout?: (event: LayoutChangeEvent) => void;
accessibilityLabel: string;
accessibilityHint?: string;
testID?: string;
children: (hovered: boolean) => ReactNode;

/** Fires when the mouse enters the row. Hover state lives in the parent so leaves like Avatar can react. */
onHoverIn?: () => void;

/** Fires when the mouse leaves the row. */
onHoverOut?: () => void;

/** Row content. */
children: ReactNode;
};

function OptionRowPressable({
optionItem,
isOptionFocused,
isScreenFocused,
popoverAnchor,
onSelectRow,
onLayout,
accessibilityLabel,
accessibilityHint,
testID,
children,
}: OptionRowPressableProps) {
function Pressable({optionItem, isOptionFocused, onSelectRow, onLayout, onHoverIn, onHoverOut, children}: PressableProps) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {translate} = useLocalize();
const {isProduction} = useEnvironment();
const {isScreenFocused} = useLHNTooltipContext();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {hideProductTrainingTooltip} = useLHNRowProductTrainingTooltip();

const popoverAnchor = useRef<View>(null);
const [isContextMenuActive, setIsContextMenuActive] = useState(false);

const reportID = optionItem.reportID;
const brickRoadIndicator = optionItem.brickRoadIndicator;
const actionBadgeText = !isProduction && optionItem.actionBadge ? translate(`common.actionBadge.${optionItem.actionBadge}`) : '';

let accessibilityLabelForBadge = '';
if (brickRoadIndicator) {
accessibilityLabelForBadge = [translate('common.yourReviewIsRequired'), actionBadgeText].filter(Boolean).join(', ');
} else if (optionItem.isPinned) {
accessibilityLabelForBadge = translate('common.pinned');
}

const accessibilityLabel = [
`${translate('accessibilityHints.navigatesToChat')} ${optionItem.text}`,
optionItem.isUnread ? translate('common.unread') : '',
optionItem.alternateText ?? '',
accessibilityLabelForBadge,
]
.filter(Boolean)
.join('. ');
const contextMenuHint = getContextMenuAccessibilityHint({translate});
const {accessibilityLabel: accessibilityLabelWithContextMenuHint, accessibilityHint} = getContextMenuAccessibilityProps({
accessibilityLabel,
nativeAccessibilityHint: accessibilityLabel,
contextMenuHint,
});

// reportID may be a number contrary to the type definition
const testID = typeof reportID === 'number' ? String(reportID) : reportID;

const onPress = (event: GestureResponderEvent | KeyboardEvent | undefined) => {
hideProductTrainingTooltip();
startSpan(`${CONST.TELEMETRY.SPAN_OPEN_REPORT}_${reportID}`, {
Expand All @@ -55,11 +98,6 @@ function OptionRowPressable({
ReportActionComposeFocusManager.focus();
onSelectRow(optionItem, popoverAnchor);
};
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {shouldUseNarrowLayout} = useResponsiveLayout();
const [isContextMenuActive, setIsContextMenuActive] = useState(false);

const showPopover = (event: MouseEvent | GestureResponderEvent) => {
if (!isScreenFocused && shouldUseNarrowLayout) {
Expand All @@ -86,7 +124,10 @@ function OptionRowPressable({
};

return (
<Hoverable>
<Hoverable
onHoverIn={onHoverIn}
onHoverOut={onHoverOut}
>
{(hovered) => (
<PressableWithSecondaryInteraction
ref={popoverAnchor}
Expand Down Expand Up @@ -121,19 +162,19 @@ function OptionRowPressable({
(hovered || isContextMenuActive) && !isOptionFocused ? styles.sidebarLinkHover : null,
]}
role={CONST.ROLE.BUTTON}
accessibilityLabel={accessibilityLabel}
accessibilityLabel={accessibilityLabelWithContextMenuHint}
accessibilityHint={accessibilityHint}
onLayout={onLayout}
needsOffscreenAlphaCompositing={(optionItem?.icons?.length ?? 0) >= 2}
sentryLabel={CONST.SENTRY_LABEL.LHN.OPTION_ROW}
>
{children(hovered)}
{children}
</PressableWithSecondaryInteraction>
)}
</Hoverable>
);
}

OptionRowPressable.displayName = 'OptionRowPressable';
Pressable.displayName = 'OptionRow.Pressable';

export default OptionRowPressable;
export default Pressable;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ProductTrainingTooltipProps = {
};

type ProductTrainingTooltipInnerProps = {
/** Row content the tooltip anchors to. Mounted only when the row is eligible to show a tooltip. */
children: ReactElement;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import type {StyleProp, TextStyle} from 'react-native';
import type {ValueOf} from 'type-fest';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
Expand All @@ -13,13 +12,17 @@ import CONST from '@src/CONST';
type OptionMode = ValueOf<typeof CONST.OPTION_MODE>;

type SubtitleProps = {
/** Option data for the row. Source of `alternateText` and emoji rendering hints. */
optionItem: OptionData;

/** Display density mode. Compact rows render the subtitle with compact styles; the subtitle is hidden only when `optionItem.alternateText` is empty. */
viewMode: OptionMode;

/** Whether the row is the currently focused/active option. Drives the active text style. */
isOptionFocused: boolean;
style?: StyleProp<TextStyle>;
};

function Subtitle({optionItem, viewMode, isOptionFocused, style}: SubtitleProps) {
function Subtitle({optionItem, viewMode, isOptionFocused}: SubtitleProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();

Expand All @@ -31,8 +34,8 @@ function Subtitle({optionItem, viewMode, isOptionFocused, style}: SubtitleProps)
const isInFocusMode = viewMode === CONST.OPTION_MODE.COMPACT;
const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText;
const alternateTextStyle = isInFocusMode
? [textStyle, styles.textLabelSupporting, styles.optionAlternateTextCompact, styles.ml2, style]
: [textStyle, styles.optionAlternateText, styles.textLabelSupporting, style];
? [textStyle, styles.textLabelSupporting, styles.optionAlternateTextCompact, styles.ml2]
: [textStyle, styles.optionAlternateText, styles.textLabelSupporting];
const alternateTextFSClass = FS.getChatFSClass(optionItem);

const containsCustomEmojiWithText = containsCustomEmojiUtils(alternateText) && !containsOnlyCustomEmoji(alternateText);
Expand Down
17 changes: 14 additions & 3 deletions src/components/LHNOptionsList/OptionRowLHN/OptionRow/Title.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
import React from 'react';
import type {StyleProp, TextStyle} from 'react-native';
import DisplayNames from '@components/DisplayNames';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import {shouldUseBoldText} from '@libs/OptionsListUtils';
import type {OptionData} from '@libs/ReportUtils';
import {isGroupChat, isSystemChat} from '@libs/ReportUtils';
import CONST from '@src/CONST';

type TitleProps = {
/** Option data for the row. Source of `text`, `displayNamesWithTooltips`, chat-type flags, parse-mode hints, and unread/bold derivation. */
optionItem: OptionData;
displayNameStyle: StyleProp<TextStyle>;

/** Whether the row is the currently focused/active option. Drives the active text style. */
isOptionFocused: boolean;

/** Numeric testID for the title node. This is the FlashList row index passed in from the renderItem callback, not the report ID. */
testID: number;
};

function Title({optionItem, displayNameStyle, testID}: TitleProps) {
function Title({optionItem, isOptionFocused, testID}: TitleProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();

const textStyle = isOptionFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText;
const textUnreadStyle = shouldUseBoldText(optionItem) ? [textStyle, styles.sidebarLinkTextBold] : [textStyle];
const displayNameStyle = [styles.optionDisplayName, styles.optionDisplayNameCompact, styles.pre, textUnreadStyle, styles.flexShrink0];

const shouldParseFullTitle = optionItem?.parentReportAction?.actionName !== CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT && !isGroupChat(optionItem);
const shouldUseFullTitle =
Expand Down
31 changes: 31 additions & 0 deletions src/components/LHNOptionsList/OptionRowLHN/OptionRow/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Avatar from './Avatar';
import DescriptiveText from './DescriptiveText';
import DraftIndicator from './DraftIndicator';
import ErrorBadge from './ErrorBadge';
import InfoBadge from './InfoBadge';
import OfflineWrapper from './OfflineWrapper';
import OnboardingBadge from './OnboardingBadge';
import PinIndicator from './PinIndicator';
import Pressable from './Pressable';
import ProductTrainingTooltip from './ProductTrainingTooltip';
import Status from './Status';
import Subtitle from './Subtitle';
import Title from './Title';

const OptionRow = {
Avatar,
DescriptiveText,
DraftIndicator,
ErrorBadge,
InfoBadge,
OfflineWrapper,
OnboardingBadge,
PinIndicator,
Pressable,
ProductTrainingTooltip,
Status,
Subtitle,
Title,
};

export default OptionRow;
Loading
Loading