-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fixed LHN Ordering #35907
Merged
Merged
Fixed LHN Ordering #35907
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
9b040c5
Test LHN fix
shubham1206agra 6333dcd
revert unintentional change
shubham1206agra 87826ab
Merge branch 'main' into test-lhn-fix
shubham1206agra 06f5775
Optimization attempt 1
shubham1206agra f556253
Fixed perf test
shubham1206agra f8ab7cc
Fixed display name filter
shubham1206agra 90343b9
Added violation for RBR in sorting
shubham1206agra 6b19fd2
Optimization attempt 2
shubham1206agra c61adb1
Revert "Optimization attempt 2"
shubham1206agra cf3147f
Merge branch 'Expensify:main' into test-lhn-fix
shubham1206agra 6649bb9
Minor fixes
shubham1206agra 40e7a05
Merge branch 'main' into test-lhn-fix
shubham1206agra 89a56b2
Optimization Attempt 3
shubham1206agra 102bbda
Fixed perf test
shubham1206agra 1eca3e1
code adjustment according to recommendations
shubham1206agra 1314854
Merge branch 'main' into test-lhn-fix
shubham1206agra 4e35908
Fixed lint
shubham1206agra e15075f
Merge branch 'Expensify:main' into test-lhn-fix
shubham1206agra 651e372
Revert "Merge branch 'Expensify:main' into test-lhn-fix"
shubham1206agra 70ef3fc
fixing name display
shubham1206agra 91cea78
Revert "Revert "Merge branch 'Expensify:main' into test-lhn-fix""
shubham1206agra e2f769a
adding small comment
shubham1206agra 8495e60
Rename variable
shubham1206agra 29216c2
Fixed violation to be used properly for all permissions users
shubham1206agra 888195b
Merge branch 'Expensify:main' into test-lhn-fix
shubham1206agra f14090e
Added transaction as dependency
shubham1206agra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import CONST from '@src/CONST'; | |
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {PersonalDetails, PersonalDetailsList, TransactionViolation} from '@src/types/onyx'; | ||
import type Beta from '@src/types/onyx/Beta'; | ||
import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; | ||
import type Policy from '@src/types/onyx/Policy'; | ||
import type Report from '@src/types/onyx/Report'; | ||
import type {ReportActions} from '@src/types/onyx/ReportAction'; | ||
|
@@ -59,6 +60,13 @@ function compareStringDates(a: string, b: string): 0 | 1 | -1 { | |
return 0; | ||
} | ||
|
||
function filterDisplayName(displayName: string): string { | ||
if (CONST.REGEX.INVALID_DISPLAY_NAME_ONLY_LHN.test(displayName)) { | ||
return displayName; | ||
} | ||
return displayName.replace(CONST.REGEX.INVALID_DISPLAY_NAME_LHN, '').trim(); | ||
} | ||
|
||
/** | ||
* @returns An array of reportIDs sorted in the proper order | ||
*/ | ||
|
@@ -68,22 +76,27 @@ function getOrderedReportIDs( | |
betas: Beta[], | ||
policies: Record<string, Policy>, | ||
priorityMode: ValueOf<typeof CONST.PRIORITY_MODE>, | ||
allReportActions: OnyxCollection<ReportAction[]>, | ||
allReportActions: OnyxCollection<ReportActions>, | ||
transactionViolations: OnyxCollection<TransactionViolation[]>, | ||
currentPolicyID = '', | ||
policyMemberAccountIDs: number[] = [], | ||
reportIDsWithErrors: Record<string, OnyxCommon.Errors> = {}, | ||
canUseViolations = false, | ||
): string[] { | ||
const isInGSDMode = priorityMode === CONST.PRIORITY_MODE.GSD; | ||
const isInDefaultMode = !isInGSDMode; | ||
const allReportsDictValues = Object.values(allReports); | ||
|
||
const reportIDsWithViolations = new Set<string>(); | ||
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. Couldn't this be moved to 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. Nope. It didn't give any. |
||
|
||
// Filter out all the reports that shouldn't be displayed | ||
let reportsToDisplay = allReportsDictValues.filter((report) => { | ||
const parentReportActionsKey = `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report?.parentReportID}`; | ||
const parentReportActions = allReportActions?.[parentReportActionsKey]; | ||
const parentReportAction = parentReportActions?.find((action) => action && report && action?.reportActionID === report?.parentReportActionID); | ||
const doesReportHaveViolations = | ||
betas.includes(CONST.BETAS.VIOLATIONS) && !!parentReportAction && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction); | ||
const parentReportAction = allReportActions?.[parentReportActionsKey]?.[report.parentReportActionID ?? '']; | ||
const doesReportHaveViolations = canUseViolations && !!parentReportAction && ReportUtils.doesTransactionThreadHaveViolations(report, transactionViolations, parentReportAction); | ||
if (doesReportHaveViolations) { | ||
reportIDsWithViolations.add(report.reportID); | ||
} | ||
return ReportUtils.shouldReportBeInOptionList({ | ||
report, | ||
currentReportId: currentReportId ?? '', | ||
|
@@ -105,15 +118,15 @@ function getOrderedReportIDs( | |
} | ||
|
||
// The LHN is split into four distinct groups, and each group is sorted a little differently. The groups will ALWAYS be in this order: | ||
// 1. Pinned/GBR - Always sorted by reportDisplayName | ||
// 1. Pinned/GBR/RBR - Always sorted by reportDisplayName | ||
// 2. Drafts - Always sorted by reportDisplayName | ||
// 3. Non-archived reports and settled IOUs | ||
// - Sorted by lastVisibleActionCreated in default (most recent) view mode | ||
// - Sorted by reportDisplayName in GSD (focus) view mode | ||
// 4. Archived reports | ||
// - Sorted by lastVisibleActionCreated in default (most recent) view mode | ||
// - Sorted by reportDisplayName in GSD (focus) view mode | ||
const pinnedAndGBRReports: Report[] = []; | ||
const pinnedAndBrickRoadReports: Report[] = []; | ||
const draftReports: Report[] = []; | ||
const nonArchivedReports: Report[] = []; | ||
const archivedReports: Report[] = []; | ||
|
@@ -127,12 +140,14 @@ function getOrderedReportIDs( | |
// However, this code needs to be very performant to handle thousands of reports, so in the interest of speed, we're just going to disable this lint rule and add | ||
// the reportDisplayName property to the report object directly. | ||
// eslint-disable-next-line no-param-reassign | ||
report.displayName = ReportUtils.getReportName(report); | ||
report.displayName = filterDisplayName(ReportUtils.getReportName(report)); | ||
|
||
shubham1206agra marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const hasRBR = report.reportID in reportIDsWithErrors || reportIDsWithViolations.has(report.reportID); | ||
|
||
const isPinned = report.isPinned ?? false; | ||
const reportAction = ReportActionsUtils.getReportAction(report.parentReportID ?? '', report.parentReportActionID ?? ''); | ||
if (isPinned || ReportUtils.requiresAttentionFromCurrentUser(report, reportAction)) { | ||
pinnedAndGBRReports.push(report); | ||
if (isPinned || hasRBR || ReportUtils.requiresAttentionFromCurrentUser(report, reportAction)) { | ||
pinnedAndBrickRoadReports.push(report); | ||
} else if (report.hasDraft) { | ||
draftReports.push(report); | ||
} else if (ReportUtils.isArchivedRoom(report)) { | ||
|
@@ -143,7 +158,7 @@ function getOrderedReportIDs( | |
}); | ||
|
||
// Sort each group of reports accordingly | ||
pinnedAndGBRReports.sort((a, b) => (a?.displayName && b?.displayName ? localeCompare(a.displayName, b.displayName) : 0)); | ||
pinnedAndBrickRoadReports.sort((a, b) => (a?.displayName && b?.displayName ? localeCompare(a.displayName, b.displayName) : 0)); | ||
draftReports.sort((a, b) => (a?.displayName && b?.displayName ? localeCompare(a.displayName, b.displayName) : 0)); | ||
|
||
if (isInDefaultMode) { | ||
|
@@ -161,7 +176,7 @@ function getOrderedReportIDs( | |
|
||
// Now that we have all the reports grouped and sorted, they must be flattened into an array and only return the reportID. | ||
// The order the arrays are concatenated in matters and will determine the order that the groups are displayed in the sidebar. | ||
const LHNReports = [...pinnedAndGBRReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report.reportID); | ||
const LHNReports = [...pinnedAndBrickRoadReports, ...draftReports, ...nonArchivedReports, ...archivedReports].map((report) => report.reportID); | ||
return LHNReports; | ||
} | ||
|
||
|
@@ -170,19 +185,19 @@ function getOrderedReportIDs( | |
*/ | ||
function getOptionData({ | ||
report, | ||
reportActions, | ||
personalDetails, | ||
preferredLocale, | ||
policy, | ||
parentReportAction, | ||
reportErrors, | ||
hasViolations, | ||
}: { | ||
report: OnyxEntry<Report>; | ||
reportActions: OnyxEntry<ReportActions>; | ||
personalDetails: OnyxEntry<PersonalDetailsList>; | ||
preferredLocale: DeepValueOf<typeof CONST.LOCALES>; | ||
policy: OnyxEntry<Policy> | undefined; | ||
parentReportAction: OnyxEntry<ReportAction> | undefined; | ||
reportErrors: OnyxCommon.Errors | undefined; | ||
hasViolations: boolean; | ||
}): ReportUtils.OptionData | undefined { | ||
// When a user signs out, Onyx is cleared. Due to the lazy rendering with a virtual list, it's possible for | ||
|
@@ -195,7 +210,7 @@ function getOptionData({ | |
const result: ReportUtils.OptionData = { | ||
text: '', | ||
alternateText: null, | ||
allReportErrors: OptionsListUtils.getAllReportErrors(report, reportActions), | ||
allReportErrors: reportErrors, | ||
brickRoadIndicator: null, | ||
tooltipText: null, | ||
subtitle: null, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not added to the dependencies of
useMemo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reportErrors
seems to be an object, if we add it as dependency we should memoize it also on the parent componentparent:
and not sure about
reportIDsWithErrors
cc: @youssef-lr