-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat(insights): add Top Categories suggested search #80102
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4d5aff2
feat(insights): add Top Categories suggested search
ashu75575 59f41f6
fix style and translation
ashu75575 1946495
fix ai comments
ashu75575 7860598
code format
ashu75575 9775494
Update src/languages/de.ts
ashu75575 a5a06df
Update src/languages/fr.ts
ashu75575 d7e5183
Update src/languages/fr.ts
ashu75575 6cb9d6a
remove unnecessary changes
ashu75575 6def831
fix "Top Categories" visibility logic in getSuggestedSearchesVisibil…
ashu75575 a70d6c8
Merge branch 'Expensify:main' into issue/80036
ashu75575 af79c27
merge main and add limit filter
ashu75575 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -389,6 +389,47 @@ type GetSectionsParams = { | |
| allTransactionViolations?: OnyxCollection<OnyxTypes.TransactionViolation[]>; | ||
| }; | ||
|
|
||
| /** | ||
| * Creates a top search menu item with common structure for TOP_SPENDERS and TOP_CATEGORIES | ||
| */ | ||
| function createTopSearchMenuItem( | ||
| key: SearchKey, | ||
| translationPath: TranslationPaths, | ||
| icon: IconAsset | Extract<ExpensifyIconName, 'Receipt' | 'ChatBubbles' | 'MoneyBag' | 'CreditCard' | 'MoneyHourglass' | 'CreditCardHourglass' | 'Bank'>, | ||
| groupBy: ValueOf<typeof CONST.SEARCH.GROUP_BY>, | ||
| limit?: number, | ||
| ): SearchTypeMenuItem { | ||
| const searchQuery = buildQueryStringFromFilterFormValues( | ||
| { | ||
| type: CONST.SEARCH.DATA_TYPES.EXPENSE, | ||
| groupBy, | ||
| dateOn: CONST.SEARCH.DATE_PRESETS.LAST_MONTH, | ||
| }, | ||
| { | ||
| sortBy: CONST.SEARCH.TABLE_COLUMNS.GROUP_TOTAL, | ||
| sortOrder: CONST.SEARCH.SORT_ORDER.DESC, | ||
| ...(limit && {limit}), | ||
| }, | ||
| ); | ||
|
|
||
| return { | ||
| key, | ||
| translationPath, | ||
| type: CONST.SEARCH.DATA_TYPES.EXPENSE, | ||
| icon, | ||
| searchQuery, | ||
| get searchQueryJSON() { | ||
| return buildSearchQueryJSON(this.searchQuery); | ||
| }, | ||
| get hash() { | ||
| return this.searchQueryJSON?.hash ?? CONST.DEFAULT_NUMBER_ID; | ||
| }, | ||
| get similarSearchHash() { | ||
| return this.searchQueryJSON?.similarSearchHash ?? CONST.DEFAULT_NUMBER_ID; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Returns a list of all possible searches in the LHN, along with their query & hash. | ||
| * *NOTE* When rendering the LHN, you should use the "createTypeMenuSections" method, which | ||
|
|
@@ -623,32 +664,14 @@ function getSuggestedSearches( | |
| return this.searchQueryJSON?.similarSearchHash ?? CONST.DEFAULT_NUMBER_ID; | ||
| }, | ||
| }, | ||
| [CONST.SEARCH.SEARCH_KEYS.TOP_SPENDERS]: { | ||
| key: CONST.SEARCH.SEARCH_KEYS.TOP_SPENDERS, | ||
| translationPath: 'search.topSpenders', | ||
| type: CONST.SEARCH.DATA_TYPES.EXPENSE, | ||
| icon: Expensicons.User, | ||
| searchQuery: buildQueryStringFromFilterFormValues( | ||
| { | ||
| type: CONST.SEARCH.DATA_TYPES.EXPENSE, | ||
| groupBy: CONST.SEARCH.GROUP_BY.FROM, | ||
| dateOn: CONST.SEARCH.DATE_PRESETS.LAST_MONTH, | ||
| }, | ||
| { | ||
| sortBy: CONST.SEARCH.TABLE_COLUMNS.GROUP_TOTAL, | ||
| sortOrder: CONST.SEARCH.SORT_ORDER.DESC, | ||
| }, | ||
| ), | ||
| get searchQueryJSON() { | ||
| return buildSearchQueryJSON(this.searchQuery); | ||
| }, | ||
| get hash() { | ||
| return this.searchQueryJSON?.hash ?? CONST.DEFAULT_NUMBER_ID; | ||
| }, | ||
| get similarSearchHash() { | ||
| return this.searchQueryJSON?.similarSearchHash ?? CONST.DEFAULT_NUMBER_ID; | ||
| }, | ||
| }, | ||
| [CONST.SEARCH.SEARCH_KEYS.TOP_SPENDERS]: createTopSearchMenuItem(CONST.SEARCH.SEARCH_KEYS.TOP_SPENDERS, 'search.topSpenders', Expensicons.User, CONST.SEARCH.GROUP_BY.FROM), | ||
| [CONST.SEARCH.SEARCH_KEYS.TOP_CATEGORIES]: createTopSearchMenuItem( | ||
|
Contributor
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.
Contributor
Author
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. this will be part of #80035, limit filter not exist yet |
||
| CONST.SEARCH.SEARCH_KEYS.TOP_CATEGORIES, | ||
| 'search.topCategories', | ||
| Expensicons.Folder, | ||
|
ashu75575 marked this conversation as resolved.
|
||
| CONST.SEARCH.GROUP_BY.CATEGORY, | ||
| CONST.SEARCH.TOP_SEARCH_LIMIT, | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -671,6 +694,7 @@ function getSuggestedSearchesVisibility( | |
| let shouldShowUnapprovedCardSuggestion = false; | ||
| let shouldShowReconciliationSuggestion = false; | ||
| let shouldShowTopSpendersSuggestion = false; | ||
| let shouldShowTopCategoriesSuggestion = false; | ||
|
|
||
| const hasCardFeed = Object.values(cardFeedsByPolicy ?? {}).some((feeds) => feeds.length > 0); | ||
|
|
||
|
|
@@ -707,6 +731,7 @@ function getSuggestedSearchesVisibility( | |
| const isEligibleForReconciliationSuggestion = isPaidPolicy && isAdmin && ((isPaymentEnabled && hasVBBA && hasReimburser) || isECardEnabled); | ||
| const isAuditor = policy.role === CONST.POLICY.ROLE.AUDITOR; | ||
| const isEligibleForTopSpendersSuggestion = isPaidPolicy && (isAdmin || isAuditor || isApprover); | ||
|
ashu75575 marked this conversation as resolved.
|
||
| const isEligibleForTopCategoriesSuggestion = isPaidPolicy; | ||
|
|
||
| shouldShowSubmitSuggestion ||= isEligibleForSubmitSuggestion; | ||
| shouldShowPaySuggestion ||= isEligibleForPaySuggestion; | ||
|
|
@@ -717,6 +742,7 @@ function getSuggestedSearchesVisibility( | |
| shouldShowUnapprovedCardSuggestion ||= isEligibleForUnapprovedCardSuggestion; | ||
| shouldShowReconciliationSuggestion ||= isEligibleForReconciliationSuggestion; | ||
| shouldShowTopSpendersSuggestion ||= isEligibleForTopSpendersSuggestion; | ||
| shouldShowTopCategoriesSuggestion ||= isEligibleForTopCategoriesSuggestion; | ||
|
|
||
| // We don't need to check the rest of the policies if we already determined that all suggestions should be displayed | ||
| return ( | ||
|
|
@@ -728,7 +754,8 @@ function getSuggestedSearchesVisibility( | |
| shouldShowUnapprovedCashSuggestion && | ||
| shouldShowUnapprovedCardSuggestion && | ||
| shouldShowReconciliationSuggestion && | ||
| shouldShowTopSpendersSuggestion | ||
| shouldShowTopSpendersSuggestion && | ||
| shouldShowTopCategoriesSuggestion | ||
| ); | ||
| }); | ||
|
|
||
|
|
@@ -745,6 +772,7 @@ function getSuggestedSearchesVisibility( | |
| [CONST.SEARCH.SEARCH_KEYS.UNAPPROVED_CARD]: shouldShowUnapprovedCardSuggestion, | ||
| [CONST.SEARCH.SEARCH_KEYS.RECONCILIATION]: shouldShowReconciliationSuggestion, | ||
| [CONST.SEARCH.SEARCH_KEYS.TOP_SPENDERS]: shouldShowTopSpendersSuggestion, | ||
| [CONST.SEARCH.SEARCH_KEYS.TOP_CATEGORIES]: shouldShowTopCategoriesSuggestion, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -3019,9 +3047,15 @@ function createTypeMenuSections( | |
| menuItems: [], | ||
| }; | ||
|
|
||
| if (suggestedSearchesVisibility[CONST.SEARCH.SEARCH_KEYS.TOP_SPENDERS]) { | ||
| const insightsSearchKeys = [CONST.SEARCH.SEARCH_KEYS.TOP_SPENDERS, CONST.SEARCH.SEARCH_KEYS.TOP_CATEGORIES]; | ||
|
|
||
| for (const key of insightsSearchKeys) { | ||
| if (!suggestedSearchesVisibility[key]) { | ||
| continue; | ||
| } | ||
|
|
||
| insightsSection.menuItems.push({ | ||
| ...suggestedSearches[CONST.SEARCH.SEARCH_KEYS.TOP_SPENDERS], | ||
| ...suggestedSearches[key], | ||
| emptyState: { | ||
| title: 'search.searchResults.emptyResults.title', | ||
| subtitle: 'search.searchResults.emptyResults.subtitle', | ||
|
|
||
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.
We do not need to add the
createTopSearchMenuItemutil function here. Therefore, you only need to add the TOP_CATEGORIES case and follow the existing code pattern above.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.
please check this ai comment #80102 (comment)