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
@@ -0,0 +1,32 @@
import React from 'react';
import type {ReactNode} from 'react';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import type {OptionData} from '@libs/ReportUtils';

type OfflineWrapperProps = {
/** Pending action forwarded to OfflineWithFeedback to drive opacity and strikethrough. */
pendingAction: OptionData['pendingAction'];

/** Errors forwarded to OfflineWithFeedback. Error messages themselves are hidden in the LHN. */
errors: OptionData['allReportErrors'];

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

function OfflineWrapper({pendingAction, errors, children}: OfflineWrapperProps) {
return (
<OfflineWithFeedback
pendingAction={pendingAction}
errors={errors}
shouldShowErrorMessages={false}
needsOffscreenAlphaCompositing
>
{children}
</OfflineWithFeedback>
);
}

OfflineWrapper.displayName = 'OptionRow.OfflineWrapper';

export default OfflineWrapper;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import type {ReactElement} from 'react';
import {useLHNTooltipContext} from '@components/LHNOptionsList/LHNTooltipContext';
import OfflineWithFeedback from '@components/OfflineWithFeedback';
import useLHNRowProductTrainingTooltip from '@components/LHNOptionsList/OptionRowLHN/useLHNRowProductTrainingTooltip';
import {useSession} from '@components/OnyxListItemProvider';
import EducationalTooltip from '@components/Tooltip/EducationalTooltip';
import useOnyx from '@hooks/useOnyx';
Expand All @@ -10,21 +11,20 @@ import type {OptionData} from '@libs/ReportUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import useLHNRowProductTrainingTooltip from './useLHNRowProductTrainingTooltip';

type OptionRowTooltipLayerProps = {
/** Option data, drives onboarding eligibility checks and forwards pendingAction/errors to OfflineWithFeedback */
type ProductTrainingTooltipProps = {
/** Option data, drives onboarding eligibility checks for the educational tooltip. */
optionItem: OptionData;

/** Renders the row content. */
renderChildren: () => React.ReactNode;
/** Row content the tooltip anchors to. */
children: ReactElement;
};

type OptionRowTooltipLayerInnerProps = {
renderChildren: () => React.ReactNode;
type ProductTrainingTooltipInnerProps = {
children: ReactElement;
};

function OptionRowTooltipLayerInner({renderChildren}: OptionRowTooltipLayerInnerProps) {
function ProductTrainingTooltipInner({children}: ProductTrainingTooltipInnerProps) {
const styles = useThemeStyles();
const {shouldShowProductTrainingTooltip, renderProductTrainingTooltip, hideProductTrainingTooltip} = useLHNRowProductTrainingTooltip();

Expand All @@ -42,14 +42,14 @@ function OptionRowTooltipLayerInner({renderChildren}: OptionRowTooltipLayerInner
onTooltipPress={hideProductTrainingTooltip}
shouldHideOnScroll
>
{renderChildren()}
{children}
</EducationalTooltip>
);
}

OptionRowTooltipLayerInner.displayName = 'OptionRowTooltipLayerInner';
ProductTrainingTooltipInner.displayName = 'OptionRow.ProductTrainingTooltipInner';

function OptionRowTooltipLayer({optionItem, renderChildren}: OptionRowTooltipLayerProps) {
function ProductTrainingTooltip({optionItem, children}: ProductTrainingTooltipProps) {
const {firstReportIDWithGBRorRBR, onboardingPurpose, onboarding} = useLHNTooltipContext();
const session = useSession();
const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID);
Expand All @@ -62,18 +62,13 @@ function OptionRowTooltipLayer({optionItem, renderChildren}: OptionRowTooltipLay
// Skip the inner component (and its heavy hooks) entirely when the row can never show a tooltip.
const shouldEvaluateTooltip = shouldShowRBRorGBRTooltip || shouldShowGetStartedTooltip;

return (
<OfflineWithFeedback
pendingAction={optionItem.pendingAction}
errors={optionItem.allReportErrors}
shouldShowErrorMessages={false}
needsOffscreenAlphaCompositing
>
{shouldEvaluateTooltip ? <OptionRowTooltipLayerInner renderChildren={renderChildren} /> : renderChildren()}
</OfflineWithFeedback>
);
if (!shouldEvaluateTooltip) {
return children;
}

return <ProductTrainingTooltipInner>{children}</ProductTrainingTooltipInner>;
}

OptionRowTooltipLayer.displayName = 'OptionRowTooltipLayer';
ProductTrainingTooltip.displayName = 'OptionRow.ProductTrainingTooltip';

export default OptionRowTooltipLayer;
export default ProductTrainingTooltip;
151 changes: 76 additions & 75 deletions src/components/LHNOptionsList/OptionRowLHN/OptionRowLHNCore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import DescriptiveText from './OptionRow/DescriptiveText';
import DraftIndicator from './OptionRow/DraftIndicator';
import ErrorBadge from './OptionRow/ErrorBadge';
import InfoBadge from './OptionRow/InfoBadge';
import OfflineWrapper from './OptionRow/OfflineWrapper';
import OnboardingBadge from './OptionRow/OnboardingBadge';
import PinIndicator from './OptionRow/PinIndicator';
import ProductTrainingTooltip from './OptionRow/ProductTrainingTooltip';
import Status from './OptionRow/Status';
import Subtitle from './OptionRow/Subtitle';
import Title from './OptionRow/Title';
import OptionRowAvatar from './OptionRowAvatar';
import OptionRowPressable from './OptionRowPressable';
import OptionRowTooltipLayer from './OptionRowTooltipLayer';

function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionItem, viewMode = 'default', style, onLayout = () => {}, hasDraftComment, testID}: OptionRowLHNProps) {
const {isProduction} = useEnvironment();
Expand Down Expand Up @@ -77,86 +78,86 @@ function OptionRowLHN({isOptionFocused = false, onSelectRow = () => {}, optionIt
contextMenuHint,
});

const renderPressableRow = () => (
<OptionRowPressable
optionItem={optionItem}
isOptionFocused={isOptionFocused}
isScreenFocused={isScreenFocused}
popoverAnchor={popoverAnchor}
onSelectRow={onSelectRow}
onLayout={onLayout}
accessibilityLabel={accessibilityLabelWithContextMenuHint}
accessibilityHint={accessibilityHint}
// reportID may be a number contrary to the type definition
testID={typeof optionItem.reportID === 'number' ? String(optionItem.reportID) : optionItem.reportID}
return (
<OfflineWrapper
pendingAction={optionItem.pendingAction}
errors={optionItem.allReportErrors}
>
{(hovered) => {
let secondaryAvatarBgColor = theme.sidebar;
if (isOptionFocused) {
secondaryAvatarBgColor = focusedBackgroundColor;
} else if (hovered) {
secondaryAvatarBgColor = hoveredBackgroundColor;
}
return (
<>
<View style={sidebarInnerRowStyle}>
<View style={[styles.flexRow, styles.alignItemsCenter]}>
<OptionRowAvatar
optionItem={optionItem}
isInFocusMode={isInFocusMode}
subscriptAvatarBorderColor={hovered && !isOptionFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor}
secondaryAvatarBackgroundColor={secondaryAvatarBgColor}
singleAvatarContainerStyle={singleAvatarContainerStyle}
/>
<View style={contentContainerStyles}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}>
<Title
<ProductTrainingTooltip optionItem={optionItem}>
<OptionRowPressable
optionItem={optionItem}
isOptionFocused={isOptionFocused}
isScreenFocused={isScreenFocused}
popoverAnchor={popoverAnchor}
onSelectRow={onSelectRow}
onLayout={onLayout}
accessibilityLabel={accessibilityLabelWithContextMenuHint}
accessibilityHint={accessibilityHint}
// reportID may be a number contrary to the type definition
testID={typeof optionItem.reportID === 'number' ? String(optionItem.reportID) : optionItem.reportID}
>
{(hovered) => {
let secondaryAvatarBgColor = theme.sidebar;
if (isOptionFocused) {
secondaryAvatarBgColor = focusedBackgroundColor;
} else if (hovered) {
secondaryAvatarBgColor = hoveredBackgroundColor;
}
return (
<>
<View style={sidebarInnerRowStyle}>
<View style={[styles.flexRow, styles.alignItemsCenter]}>
<OptionRowAvatar
optionItem={optionItem}
displayNameStyle={displayNameStyle}
testID={testID}
isInFocusMode={isInFocusMode}
subscriptAvatarBorderColor={hovered && !isOptionFocused ? hoveredBackgroundColor : subscriptAvatarBorderColor}
secondaryAvatarBackgroundColor={secondaryAvatarBgColor}
singleAvatarContainerStyle={singleAvatarContainerStyle}
/>
<View style={contentContainerStyles}>
<View style={[styles.flexRow, styles.alignItemsCenter, styles.mw100, styles.overflowHidden]}>
<Title
optionItem={optionItem}
displayNameStyle={displayNameStyle}
testID={testID}
/>
<OnboardingBadge optionItem={optionItem} />
<Status optionItem={optionItem} />
</View>
<Subtitle
optionItem={optionItem}
viewMode={viewMode}
isOptionFocused={isOptionFocused}
style={style}
/>
</View>
<DescriptiveText optionItem={optionItem} />
<ErrorBadge
brickRoadIndicator={brickRoadIndicator}
actionBadge={optionItem.actionBadge}
/>
<OnboardingBadge optionItem={optionItem} />
<Status optionItem={optionItem} />
</View>
<Subtitle
optionItem={optionItem}
viewMode={viewMode}
isOptionFocused={isOptionFocused}
style={style}
</View>
<View style={[styles.flexRow, styles.alignItemsCenter]}>
<InfoBadge
brickRoadIndicator={brickRoadIndicator}
actionBadge={optionItem.actionBadge}
/>
<DraftIndicator
hasDraftComment={hasDraftComment}
isAllowedToComment={optionItem.isAllowedToComment}
/>
<PinIndicator
isPinned={optionItem.isPinned}
brickRoadIndicator={brickRoadIndicator}
/>
</View>
<DescriptiveText optionItem={optionItem} />
<ErrorBadge
brickRoadIndicator={brickRoadIndicator}
actionBadge={optionItem.actionBadge}
/>
</View>
</View>
<View style={[styles.flexRow, styles.alignItemsCenter]}>
<InfoBadge
brickRoadIndicator={brickRoadIndicator}
actionBadge={optionItem.actionBadge}
/>
<DraftIndicator
hasDraftComment={hasDraftComment}
isAllowedToComment={optionItem.isAllowedToComment}
/>
<PinIndicator
isPinned={optionItem.isPinned}
brickRoadIndicator={brickRoadIndicator}
/>
</View>
</>
);
}}
</OptionRowPressable>
);

return (
<OptionRowTooltipLayer
optionItem={optionItem}
renderChildren={renderPressableRow}
/>
</>
);
}}
</OptionRowPressable>
</ProductTrainingTooltip>
</OfflineWrapper>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CONST from '@src/CONST';

/**
* Resolves the product-training tooltip state (CONCIERGE_LHN_GBR) for an LHN row.
* Used by both OptionRowTooltipLayerInner (render the tooltip) and OptionRowPressable (hide on press).
* Used by both ProductTrainingTooltipInner (render the tooltip) and OptionRowPressable (hide on press).
*/
function useLHNRowProductTrainingTooltip() {
const {shouldUseNarrowLayout} = useResponsiveLayout();
Expand Down
Loading