Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Redesign thread ancestry #38722

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c5563d6
Redesign thread ancestry
rayane-djouah Mar 20, 2024
2da0db8
fix lint errors
rayane-djouah Mar 21, 2024
d4e5d3c
fix lint errors
rayane-djouah Mar 21, 2024
24f7d3d
fix failing test
rayane-djouah Mar 21, 2024
6527a1c
Merge branch 'Expensify:main' into Feat-Redesign-thread-ancestry
rayane-djouah Mar 21, 2024
4f05883
Merge branch 'Expensify:main' into Feat-Redesign-thread-ancestry
rayane-djouah Mar 21, 2024
b3c0163
make first thread padding consistet with the rest of threads
rayane-djouah Mar 21, 2024
9b1c348
show the replies divider only when there is at least one reply
rayane-djouah Mar 21, 2024
d6f4c17
Display the pointer cursor when hovering over any part of the message
rayane-djouah Mar 21, 2024
90836d2
Merge branch 'Expensify:main' into Feat-Redesign-thread-ancestry
rayane-djouah Mar 22, 2024
e8fbd0d
fix replies divider margins
rayane-djouah Mar 23, 2024
23ed381
Merge branch 'Expensify:main' into Feat-Redesign-thread-ancestry
rayane-djouah Mar 23, 2024
5a12242
Merge branch 'Expensify:main' into Feat-Redesign-thread-ancestry
rayane-djouah Mar 23, 2024
f6360d9
Merge branch 'Expensify:main' into Feat-Redesign-thread-ancestry
rayane-djouah Mar 26, 2024
26cc4ec
fix lint warning
rayane-djouah Mar 26, 2024
9b0c3fe
prettier
rayane-djouah Mar 26, 2024
242ead9
make sure all the links are deep links back to the specific comment i…
rayane-djouah Mar 26, 2024
8940017
add deep linking to the header links of the IOU and transaction repor…
rayane-djouah Mar 26, 2024
311399a
Merge branch 'Expensify:main' into Feat-Redesign-thread-ancestry
rayane-djouah Mar 28, 2024
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
3 changes: 3 additions & 0 deletions assets/images/thread.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/components/Icon/Expensicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ import Sync from '@assets/images/sync.svg';
import Tag from '@assets/images/tag.svg';
import Task from '@assets/images/task.svg';
import Tax from '@assets/images/tax.svg';
import Thread from '@assets/images/thread.svg';
import ThreeDots from '@assets/images/three-dots.svg';
import ThumbsUp from '@assets/images/thumbs-up.svg';
import Transfer from '@assets/images/transfer.svg';
Expand Down Expand Up @@ -229,6 +230,7 @@ export {
Folder,
Tag,
Tax,
Thread,
Gallery,
Gear,
Globe,
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2363,6 +2363,7 @@ export default {
hiddenMessage: '[Hidden message]',
},
threads: {
thread: 'Thread',
replies: 'Replies',
reply: 'Reply',
from: 'From',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2854,6 +2854,7 @@ export default {
hiddenMessage: '[Mensaje oculto]',
},
threads: {
thread: 'Hilo',
replies: 'Respuestas',
reply: 'Respuesta',
from: 'De',
Expand Down
7 changes: 1 addition & 6 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ type Ancestor = {
report: Report;
reportAction: ReportAction;
shouldDisplayNewMarker: boolean;
shouldHideThreadDividerLine: boolean;
};

type AncestorIDs = {
Expand Down Expand Up @@ -5368,7 +5367,7 @@ function shouldDisableThread(reportAction: OnyxEntry<ReportAction>, reportID: st
);
}

function getAllAncestorReportActions(report: Report | null | undefined, shouldHideThreadDividerLine: boolean): Ancestor[] {
function getAllAncestorReportActions(report: Report | null | undefined): Ancestor[] {
if (!report) {
return [];
}
Expand All @@ -5378,7 +5377,6 @@ function getAllAncestorReportActions(report: Report | null | undefined, shouldHi

// Store the child of parent report
let currentReport = report;
let currentUnread = shouldHideThreadDividerLine;

while (parentReportID) {
const parentReport = getReport(parentReportID);
Expand All @@ -5393,14 +5391,11 @@ function getAllAncestorReportActions(report: Report | null | undefined, shouldHi
report: currentReport,
reportAction: parentReportAction,
shouldDisplayNewMarker: isParentReportActionUnread,
// We should hide the thread divider line if the previous ancestor action is unread
shouldHideThreadDividerLine: currentUnread,
});
parentReportID = parentReport?.parentReportID;
parentReportActionID = parentReport?.parentReportActionID;
if (!isEmptyObject(parentReport)) {
currentReport = parentReport;
currentUnread = isParentReportActionUnread;
}
}

Expand Down
36 changes: 36 additions & 0 deletions src/pages/home/report/RepliesDivider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import {View} from 'react-native';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import variables from '@styles/variables';

type RepliesDividerProps = {
/** Whether we should hide thread divider line */
shouldHideThreadDividerLine: boolean;
};

function RepliesDivider({shouldHideThreadDividerLine}: RepliesDividerProps) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();

return (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.ml5, styles.mt3, styles.mb1]}>
<Icon
src={Expensicons.Thread}
fill={theme.icon}
width={variables.iconSizeExtraSmall}
height={variables.iconSizeExtraSmall}
/>
<Text style={[styles.threadDividerText, styles.textSupporting, styles.ml1]}>{translate('threads.replies')}</Text>
{!shouldHideThreadDividerLine && <View style={[styles.threadDividerLine]} />}
</View>
);
}

RepliesDivider.displayName = 'RepliesDivider';
export default RepliesDivider;
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ function ReportActionItem({
checkIfContextMenuActive={toggleContextMenuFromActiveReportAction}
setIsEmojiPickerActive={setIsEmojiPickerActive}
/>
<View style={StyleUtils.getReportActionItemStyle(hovered || isWhisper || isContextMenuActive || !!isEmojiPickerActive || draftMessage !== undefined)}>
<View style={StyleUtils.getReportActionItemStyle(hovered || isWhisper || isContextMenuActive || !!isEmojiPickerActive || draftMessage !== undefined, !!onPress)}>
<OfflineWithFeedback
onClose={() => ReportActions.clearAllRelatedReportActionErrors(report.reportID, action)}
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
Expand Down
16 changes: 11 additions & 5 deletions src/pages/home/report/ReportActionItemParentAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground';
import RepliesDivider from './RepliesDivider';
import ReportActionItem from './ReportActionItem';
import ThreadDivider from './ThreadDivider';

type ReportActionItemParentActionProps = {
/** Flag to show, hide the thread divider line */
Expand All @@ -31,9 +33,12 @@ type ReportActionItemParentActionProps = {

/** Report actions belonging to the report's parent */
parentReportAction: OnyxEntry<OnyxTypes.ReportAction>;

/** Whether we should display "Replies" divider */
shouldDisplayReplyDivider: boolean;
};

function ReportActionItemParentAction({report, parentReportAction, index = 0, shouldHideThreadDividerLine = false}: ReportActionItemParentActionProps) {
function ReportActionItemParentAction({report, parentReportAction, index = 0, shouldHideThreadDividerLine = false, shouldDisplayReplyDivider}: ReportActionItemParentActionProps) {
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
const {isSmallScreenWidth} = useWindowDimensions();
Expand All @@ -48,15 +53,15 @@ function ReportActionItemParentAction({report, parentReportAction, index = 0, sh
onyxSubscribe({
key: `${ONYXKEYS.COLLECTION.REPORT}${ancestorReportID}`,
callback: () => {
setAllAncestors(ReportUtils.getAllAncestorReportActions(report, shouldHideThreadDividerLine));
setAllAncestors(ReportUtils.getAllAncestorReportActions(report));
},
}),
);
unsubscribeReportActions.push(
onyxSubscribe({
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${ancestorReportID}`,
callback: () => {
setAllAncestors(ReportUtils.getAllAncestorReportActions(report, shouldHideThreadDividerLine));
setAllAncestors(ReportUtils.getAllAncestorReportActions(report));
},
}),
);
Expand All @@ -82,8 +87,9 @@ function ReportActionItemParentAction({report, parentReportAction, index = 0, sh
errorRowStyles={[styles.ml10, styles.mr2]}
onClose={() => Report.navigateToConciergeChatAndDeleteReport(ancestor.report.reportID)}
>
<ThreadDivider ancestor={ancestor} />
<ReportActionItem
onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.reportID))}
onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.parentReportID ?? ''))}
parentReportAction={parentReportAction}
report={ancestor.report}
action={ancestor.reportAction}
Expand All @@ -92,9 +98,9 @@ function ReportActionItemParentAction({report, parentReportAction, index = 0, sh
shouldDisplayNewMarker={ancestor.shouldDisplayNewMarker}
index={index}
/>
{!ancestor.shouldHideThreadDividerLine && <View style={[styles.threadDividerLine]} />}
</OfflineWithFeedback>
))}
{shouldDisplayReplyDivider && <RepliesDivider shouldHideThreadDividerLine={shouldHideThreadDividerLine} />}
</View>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/report/ReportActionsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,10 @@
mostRecentIOUReportActionID={mostRecentIOUReportActionID}
shouldHideThreadDividerLine={shouldHideThreadDividerLine}
shouldDisplayNewMarker={shouldDisplayNewMarker(reportAction, index)}
shouldDisplayReplyDivider={sortedReportActions.length > 1}
/>
),
[report, linkedReportActionID, sortedVisibleReportActions, mostRecentIOUReportActionID, shouldHideThreadDividerLine, shouldDisplayNewMarker, parentReportAction],

Check warning on line 528 in src/pages/home/report/ReportActionsList.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

React Hook useCallback has a missing dependency: 'sortedReportActions.length'. Either include it or remove the dependency array
);

// Native mobile does not render updates flatlist the changes even though component did update called.
Expand Down
5 changes: 5 additions & 0 deletions src/pages/home/report/ReportActionsListItemRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ type ReportActionsListItemRendererProps = {

/** Linked report action ID */
linkedReportActionID?: string;

/** Whether we should display "Replies" divider */
shouldDisplayReplyDivider: boolean;
};

function ReportActionsListItemRenderer({
Expand All @@ -46,6 +49,7 @@ function ReportActionsListItemRenderer({
shouldHideThreadDividerLine,
shouldDisplayNewMarker,
linkedReportActionID = '',
shouldDisplayReplyDivider,
}: ReportActionsListItemRendererProps) {
const shouldDisplayParentAction =
reportAction.actionName === CONST.REPORT.ACTIONS.TYPE.CREATED && ReportUtils.isChatThread(report) && !ReportActionsUtils.isTransactionThread(parentReportAction);
Expand Down Expand Up @@ -119,6 +123,7 @@ function ReportActionsListItemRenderer({
return shouldDisplayParentAction ? (
<ReportActionItemParentAction
shouldHideThreadDividerLine={shouldDisplayParentAction && shouldHideThreadDividerLine}
shouldDisplayReplyDivider={shouldDisplayReplyDivider}
parentReportAction={parentReportAction}
reportID={report.reportID}
report={report}
Expand Down
48 changes: 48 additions & 0 deletions src/pages/home/report/ThreadDivider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import {View} from 'react-native';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import {PressableWithoutFeedback} from '@components/Pressable';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import Navigation from '@libs/Navigation/Navigation';
import type {Ancestor} from '@libs/ReportUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';

type ThreadDividerProps = {
/** Thread ancestor */
ancestor: Ancestor;
};

function ThreadDivider({ancestor}: ThreadDividerProps) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();

return (
<View style={[styles.flexRow, styles.alignItemsCenter, styles.ml5, styles.mt3, styles.mb1]}>
<PressableWithoutFeedback
onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(ancestor?.report?.parentReportID ?? ''))}
accessibilityLabel={translate('threads.thread')}
role={CONST.ROLE.BUTTON}
style={[styles.flexRow, styles.alignItemsCenter, styles.gap1]}
>
<Icon
src={Expensicons.Thread}
fill={theme.link}
width={variables.iconSizeExtraSmall}
height={variables.iconSizeExtraSmall}
/>
<Text style={[styles.threadDividerText, styles.link]}>{translate('threads.thread')}</Text>
</PressableWithoutFeedback>
{!ancestor.shouldDisplayNewMarker && <View style={[styles.threadDividerLine]} />}
</View>
);
}

ThreadDivider.displayName = 'ThreadDivider';
export default ThreadDivider;
10 changes: 8 additions & 2 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,6 @@ const styles = (theme: ThemeColors) =>
fontFamily: FontUtils.fontFamily.platform.EXP_NEUE,
lineHeight: variables.lineHeightXLarge,
maxWidth: '100%',
...cursor.cursorAuto,
...whiteSpace.preWrap,
...wordBreak.breakWord,
},
Expand Down Expand Up @@ -2743,7 +2742,8 @@ const styles = (theme: ThemeColors) =>
height: 1,
backgroundColor: theme.border,
flexGrow: 1,
marginHorizontal: 20,
marginLeft: 8,
marginRight: 20,
},

unreadIndicatorText: {
Expand All @@ -2754,6 +2754,12 @@ const styles = (theme: ThemeColors) =>
textTransform: 'capitalize',
},

threadDividerText: {
fontFamily: FontUtils.fontFamily.platform.EXP_NEUE,
fontSize: variables.fontSizeSmall,
textTransform: 'capitalize',
},

flipUpsideDown: {
transform: `rotate(180deg)`,
},
Expand Down
4 changes: 2 additions & 2 deletions src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
/**
* Generate the styles for the ReportActionItem wrapper view.
*/
getReportActionItemStyle: (isHovered = false): ViewStyle =>
getReportActionItemStyle: (isHovered = false, isClickable = false): ViewStyle =>
// TODO: Remove this "eslint-disable-next" once the theme switching migration is done and styles are fully typed (GH Issue: https://github.com/Expensify/App/issues/27337)
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
({
Expand All @@ -1450,7 +1450,7 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
: // Warning: Setting this to a non-transparent color will cause unread indicator to break on Android
theme.transparent,
opacity: 1,
...styles.cursorInitial,
...(isClickable ? styles.cursorPointer : styles.cursorInitial),
}),

/**
Expand Down
31 changes: 5 additions & 26 deletions tests/unit/ReportUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,34 +747,13 @@ describe('ReportUtils', () => {

it('should return correctly all ancestors of a thread report', () => {
const resultAncestors = [
{report: reports[1], reportAction: reportActions[0], shouldDisplayNewMarker: false, shouldHideThreadDividerLine: false},
{report: reports[2], reportAction: reportActions[1], shouldDisplayNewMarker: false, shouldHideThreadDividerLine: false},
{report: reports[3], reportAction: reportActions[2], shouldDisplayNewMarker: false, shouldHideThreadDividerLine: false},
{report: reports[4], reportAction: reportActions[3], shouldDisplayNewMarker: false, shouldHideThreadDividerLine: false},
{report: reports[1], reportAction: reportActions[0], shouldDisplayNewMarker: false},
{report: reports[2], reportAction: reportActions[1], shouldDisplayNewMarker: false},
{report: reports[3], reportAction: reportActions[2], shouldDisplayNewMarker: false},
{report: reports[4], reportAction: reportActions[3], shouldDisplayNewMarker: false},
];

expect(ReportUtils.getAllAncestorReportActions(reports[4], false)).toEqual(resultAncestors);
});

it('should hide thread divider line of the nearest ancestor if the first action of thread report is unread', () => {
const allAncestors = ReportUtils.getAllAncestorReportActions(reports[4], true);
expect(allAncestors.reverse()[0].shouldHideThreadDividerLine).toBe(true);
});

it('should hide thread divider line of the previous ancestor and display unread marker of the current ancestor if the current ancestor action is unread', () => {
let allAncestors = ReportUtils.getAllAncestorReportActions(reports[4], false);
expect(allAncestors[0].shouldHideThreadDividerLine).toBe(false);
expect(allAncestors[1].shouldDisplayNewMarker).toBe(false);

Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}2`, {
lastReadTime: '2024-02-01 04:42:28.001',
})
.then(() => waitForBatchedUpdates())
.then(() => {
allAncestors = ReportUtils.getAllAncestorReportActions(reports[4], false);
expect(allAncestors[0].shouldHideThreadDividerLine).toBe(true);
expect(allAncestors[1].shouldDisplayNewMarker).toBe(true);
});
expect(ReportUtils.getAllAncestorReportActions(reports[4])).toEqual(resultAncestors);
});
});
});
Loading