-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Implement get all ancestor of the thread #34640
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
Changes from 10 commits
e96ce99
dc794ea
07ccc0c
ce57da7
dbdb166
44337c1
40693fb
c0f27d5
6a876e4
bfffe59
c1725c9
850ba24
88e294b
56d5d2c
c374042
7df2fb7
d13b954
8077847
518aec7
44e36c6
9b9d8aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,105 @@ | ||
import React from 'react'; | ||
import {deepEqual} from 'fast-equals'; | ||
import lodashIsEqual from 'lodash/isEqual'; | ||
import React, {memo} from 'react'; | ||
import {View} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import type {OnyxCollection} from 'react-native-onyx'; | ||
import OfflineWithFeedback from '@components/OfflineWithFeedback'; | ||
import useStyleUtils from '@hooks/useStyleUtils'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
import * as ReportActionsUtils from '@libs/ReportActionsUtils'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as ReportUtils from '@libs/ReportUtils'; | ||
import * as Report from '@userActions/Report'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
import AnimatedEmptyStateBackground from './AnimatedEmptyStateBackground'; | ||
import ReportActionItem from './ReportActionItem'; | ||
|
||
type ReportActionItemParentActionOnyxProps = { | ||
/** The report currently being looked at */ | ||
report: OnyxEntry<OnyxTypes.Report>; | ||
allReportActions: OnyxCollection<OnyxTypes.ReportActions>; | ||
|
||
/** The actions from the parent report */ | ||
parentReportActions: OnyxEntry<OnyxTypes.ReportActions>; | ||
allReports: OnyxCollection<OnyxTypes.Report>; | ||
}; | ||
|
||
type ReportActionItemParentActionProps = ReportActionItemParentActionOnyxProps & { | ||
/** Flag to show, hide the thread divider line */ | ||
shouldHideThreadDividerLine?: boolean; | ||
|
||
/** Flag to display the new marker on top of the comment */ | ||
shouldDisplayNewMarker: boolean; | ||
|
||
/** Position index of the report parent action in the overall report FlatList view */ | ||
index: number; | ||
|
||
/** The id of the report */ | ||
// eslint-disable-next-line react/no-unused-prop-types | ||
reportID: string; | ||
|
||
/** The id of the parent report */ | ||
// eslint-disable-next-line react/no-unused-prop-types | ||
parentReportID: string; | ||
}; | ||
|
||
function ReportActionItemParentAction({report, parentReportActions = {}, index = 0, shouldHideThreadDividerLine = false, shouldDisplayNewMarker}: ReportActionItemParentActionProps) { | ||
function ReportActionItemParentAction({allReportActions = {}, allReports = {}, index = 0, shouldHideThreadDividerLine = false, reportID}: ReportActionItemParentActionProps) { | ||
const styles = useThemeStyles(); | ||
const StyleUtils = useStyleUtils(); | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
const parentReportAction = parentReportActions?.[`${report?.parentReportActionID ?? ''}`] ?? null; | ||
const report = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; | ||
const allAncestors = ReportUtils.getAllAncestorReportActions(report, shouldHideThreadDividerLine, allReports, allReportActions); | ||
|
||
// In case of transaction threads, we do not want to render the parent report action. | ||
if (ReportActionsUtils.isTransactionThread(parentReportAction)) { | ||
marcaaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return null; | ||
} | ||
marcaaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ( | ||
<OfflineWithFeedback | ||
shouldDisableOpacity={Boolean(parentReportAction?.pendingAction ?? false)} | ||
pendingAction={report?.pendingFields?.addWorkspaceRoom ?? report?.pendingFields?.createChat} | ||
errors={report?.errorFields?.addWorkspaceRoom ?? report?.errorFields?.createChat} | ||
errorRowStyles={[styles.ml10, styles.mr2]} | ||
onClose={() => Report.navigateToConciergeChatAndDeleteReport(report?.reportID ?? '0')} | ||
> | ||
<View style={StyleUtils.getReportWelcomeContainerStyle(isSmallScreenWidth)}> | ||
<> | ||
<View style={[StyleUtils.getReportWelcomeContainerStyle(isSmallScreenWidth), styles.justifyContentEnd]}> | ||
<AnimatedEmptyStateBackground /> | ||
<View style={[styles.p5, StyleUtils.getReportWelcomeTopMarginStyle(isSmallScreenWidth)]} /> | ||
{parentReportAction && ( | ||
<ReportActionItem | ||
// @ts-expect-error TODO: Remove the comment after ReportActionItem is migrated to TypeScript. | ||
report={report} | ||
action={parentReportAction} | ||
displayAsGroup={false} | ||
isMostRecentIOUReportAction={false} | ||
shouldDisplayNewMarker={shouldDisplayNewMarker} | ||
index={index} | ||
/> | ||
)} | ||
{allAncestors.map((ancestor) => ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick gut check here - could this change have any impact on Comment Linking? cc @perunt @roryabraham |
||
<OfflineWithFeedback | ||
shouldDisableOpacity={Boolean(ancestor.reportAction?.pendingAction)} | ||
pendingAction={ancestor.report?.pendingFields?.addWorkspaceRoom ?? ancestor.report?.pendingFields?.createChat} | ||
errors={ancestor.report?.errorFields?.addWorkspaceRoom ?? ancestor.report?.errorFields?.createChat} | ||
errorRowStyles={[styles.ml10, styles.mr2]} | ||
onClose={() => Report.navigateToConciergeChatAndDeleteReport(ancestor.report.reportID)} | ||
> | ||
<ReportActionItem | ||
key={ancestor.reportAction.reportActionID} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's still showing the warning. We might move it to the above component to clear the warning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mollfpr I updated. |
||
// @ts-expect-error TODO: Remove this once ReportActionItem (https://github.com/Expensify/App/issues/31982) is migrated to TypeScript. | ||
onPress={() => Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(ancestor.report.reportID))} | ||
report={ancestor.report} | ||
action={ancestor.reportAction} | ||
displayAsGroup={false} | ||
isMostRecentIOUReportAction={false} | ||
shouldDisplayNewMarker={ancestor.shouldDisplayNewMarker} | ||
index={index} | ||
dukenv0307 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
{!ancestor.shouldHideThreadDividerLine && <View style={[styles.threadDividerLine]} />} | ||
</OfflineWithFeedback> | ||
))} | ||
</View> | ||
{!shouldHideThreadDividerLine && <View style={[styles.threadDividerLine]} />} | ||
</OfflineWithFeedback> | ||
</> | ||
); | ||
} | ||
|
||
ReportActionItemParentAction.displayName = 'ReportActionItemParentAction'; | ||
|
||
export default withOnyx<ReportActionItemParentActionProps, ReportActionItemParentActionOnyxProps>({ | ||
report: { | ||
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, | ||
// We should subscribe all reports and report actions here to dynamic update when any parent report action is changed | ||
allReportActions: { | ||
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, | ||
marcaaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
parentReportActions: { | ||
key: ({parentReportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`, | ||
canEvict: false, | ||
allReports: { | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
marcaaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
})(ReportActionItemParentAction); | ||
})( | ||
memo(ReportActionItemParentAction, (prevProps, nextProps) => { | ||
const {allReportActions: prevAllReportActions, allReports: prevAllReports, ...prevPropsWithoutReportActionsAndReports} = prevProps; | ||
const {allReportActions: nextAllReportActions, allReports: nextAllReports, ...nextPropsWithoutReportActionsAndReports} = nextProps; | ||
|
||
const prevReport = prevAllReports?.[`${ONYXKEYS.COLLECTION.REPORT}${prevProps.reportID}`]; | ||
const nextReport = nextAllReports?.[`${ONYXKEYS.COLLECTION.REPORT}${nextProps.reportID}`]; | ||
const prevAllAncestors = ReportUtils.getAllAncestorReportActions(prevReport, prevProps.shouldHideThreadDividerLine ?? false, prevAllReports, prevAllReportActions); | ||
const nextAllAncestors = ReportUtils.getAllAncestorReportActions(nextReport, nextProps.shouldHideThreadDividerLine ?? false, nextAllReports, nextAllReportActions); | ||
|
||
if (prevReport !== nextReport || !deepEqual(prevAllAncestors, nextAllAncestors)) { | ||
return false; | ||
} | ||
|
||
return lodashIsEqual(prevPropsWithoutReportActionsAndReports, nextPropsWithoutReportActionsAndReports); | ||
}), | ||
marcaaron marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); |
Uh oh!
There was an error while loading. Please reload this page.