-
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
Show primary workspace chat first when creating expense #47437
Changes from 1 commit
02ef09a
7f3878b
caffcd1
3cf5578
38d3d8e
8836661
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 |
---|---|---|
|
@@ -222,7 +222,7 @@ type PreviewConfig = {showChatPreviewLine?: boolean; forcePolicyNamePreview?: bo | |
type FilterOptionsConfig = Pick< | ||
GetOptionsConfig, | ||
'sortByReportTypeInSearch' | 'canInviteUser' | 'betas' | 'selectedOptions' | 'excludeUnknownUsers' | 'excludeLogins' | 'maxRecentReportsToShow' | ||
> & {preferChatroomsOverThreads?: boolean; includeChatRoomsByParticipants?: boolean}; | ||
> & {preferChatroomsOverThreads?: boolean; includeChatRoomsByParticipants?: boolean; preferPolicyExpenseChat?: boolean}; | ||
|
||
type HasText = { | ||
text?: string; | ||
|
@@ -359,6 +359,12 @@ Onyx.connect({ | |
callback: (value) => (allReportsDraft = value), | ||
}); | ||
|
||
let primaryPolicyID: OnyxEntry<string>; | ||
Onyx.connect({ | ||
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID, | ||
callback: (value) => (primaryPolicyID = value), | ||
}); | ||
|
||
/** | ||
* Get the report or draft report given a reportID | ||
*/ | ||
|
@@ -1617,11 +1623,19 @@ function createOptionFromReport(report: Report, personalDetails: OnyxEntry<Perso | |
* @param searchValue - search string | ||
* @returns a sorted list of options | ||
*/ | ||
function orderOptions(options: ReportUtils.OptionData[], searchValue: string | undefined, {preferChatroomsOverThreads = false} = {}) { | ||
function orderOptions(options: ReportUtils.OptionData[], searchValue: string | undefined, {preferChatroomsOverThreads = false, preferPolicyExpenseChat = false} = {}) { | ||
return lodashOrderBy( | ||
options, | ||
[ | ||
(option) => { | ||
if (option.isPolicyExpenseChat && preferPolicyExpenseChat && option.policyID === primaryPolicyID) { | ||
return 0; | ||
} | ||
|
||
if (option.isPolicyExpenseChat && preferPolicyExpenseChat) { | ||
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. @mountiny I have a question here: Do we also prefer re-order the other policy expense chat that isn't the active policy ID when we re-order the active policy expense chat. 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. Actually, I implemented this logic. If we don't want to do that, I can remove this logic. 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. @mountiny What do you think about my comment above? |
||
return 1; | ||
} | ||
|
||
if (option.isSelfDM) { | ||
return 0; | ||
} | ||
|
@@ -2060,11 +2074,14 @@ function getOptions( | |
} | ||
|
||
// If we are prioritizing 1:1 chats in search, do it only once we started searching | ||
if (sortByReportTypeInSearch && searchValue !== '') { | ||
if (sortByReportTypeInSearch && (searchValue !== '' || !!action)) { | ||
// When sortByReportTypeInSearch is true, recentReports will be returned with all the reports including personalDetailsOptions in the correct Order. | ||
recentReportOptions.push(...personalDetailsOptions); | ||
personalDetailsOptions = []; | ||
recentReportOptions = orderOptions(recentReportOptions, searchValue, {preferChatroomsOverThreads: true}); | ||
// If we're in money request flow, we only order the recent report option. | ||
if (!action) { | ||
recentReportOptions.push(...personalDetailsOptions); | ||
personalDetailsOptions = []; | ||
} | ||
recentReportOptions = orderOptions(recentReportOptions, searchValue, {preferChatroomsOverThreads: true, preferPolicyExpenseChat: !!action}); | ||
} | ||
|
||
return { | ||
|
@@ -2173,6 +2190,7 @@ function getFilteredOptions( | |
recentlyUsedPolicyReportFieldOptions: string[] = [], | ||
includeInvoiceRooms = false, | ||
action: IOUAction | undefined = undefined, | ||
sortByReportTypeInSearch = false, | ||
) { | ||
return getOptions( | ||
{reports, personalDetails}, | ||
|
@@ -2201,6 +2219,7 @@ function getFilteredOptions( | |
recentlyUsedPolicyReportFieldOptions, | ||
includeInvoiceRooms, | ||
action, | ||
sortByReportTypeInSearch, | ||
}, | ||
); | ||
} | ||
|
@@ -2426,6 +2445,7 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt | |
excludeLogins = [], | ||
preferChatroomsOverThreads = false, | ||
includeChatRoomsByParticipants = false, | ||
preferPolicyExpenseChat = false, | ||
} = config ?? {}; | ||
if (searchInputValue.trim() === '' && maxRecentReportsToShow > 0) { | ||
return {...options, recentReports: options.recentReports.slice(0, maxRecentReportsToShow)}; | ||
|
@@ -2539,7 +2559,7 @@ function filterOptions(options: Options, searchInputValue: string, config?: Filt | |
|
||
return { | ||
personalDetails, | ||
recentReports: orderOptions(recentReports, searchValue, {preferChatroomsOverThreads}), | ||
recentReports: orderOptions(recentReports, searchValue, {preferChatroomsOverThreads, preferPolicyExpenseChat}), | ||
userToInvite, | ||
currentUserOption: matchResults.currentUserOption, | ||
categoryOptions: [], | ||
|
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.
Can we call it activePolicyID as thats how the nvp key is called?
This comment was marked as outdated.
Sorry, something went wrong.
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.
@mountiny I updated.
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.
NAB, but i feel
primaryPolicyID
is right over here,activePolicyID
is the policyID we are on currentlyThere 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.
@nkdengineer @allgandalf I realize this is not ideal, but we already call the variables from the
NVP_ACTIVE_POLICY_ID
as activePolicyID elsewhere so I think we should just keep using that instead of using this term