Repository navigation
Fix: hide Tag filter in advanced search when no tags exist - #93953
Conversation
Co-authored-by: daledah <daledah@users.noreply.github.com>
|
I created this PR from an upstream branch since I don't have push access to your fork. To take ownership of this branch and be able to push updates, run: Then you can close this PR and open a new one from your fork. |
|
🤖 I looked into the failing checks — there's nothing for me to fix here. The only failing check is Every code/CI check passes:
( Next step: |
|
@MelvinBot mark this PR as ready for review |
|
@DylanDylann Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppandroid.movAndroid: mWeb Chromeandroid-mweb.moviOS: HybridAppios.moviOS: mWeb Safariios-mweb.movMacOS: Chrome / Safariweb.mov |
|
|
||
| const shouldDisplayCategoryFilter = shouldDisplayFilter(hasNonPersonalPolicyCategories ? 1 : 0, policyDerived?.areCategoriesEnabled ?? false, selectedPolicyCategories?.length > 0); | ||
| const shouldDisplayTagFilter = shouldDisplayFilter(hasTags ? 1 : 0, policyDerived?.areTagsEnabled ?? false, !!selectedPolicyTagLists); | ||
| const hasSelectedPolicyTags = selectedPolicyTagLists.some((policyTagList) => Object.values(policyTagList ?? {}).some((tagList) => Object.keys(tagList.tags ?? {}).length > 0)); |
There was a problem hiding this comment.
❌ CONSISTENCY-3 (docs)
The new hasSelectedPolicyTags expression duplicates the tag-existence logic already implemented in hasTagsSelector (lines 285-297). Both iterate over the policy tag lists and check Object.keys(tagList.tags ?? {}).length > 0 to decide whether any tag exists. The only difference is the input source (selectedPolicyTagLists array vs. the full Onyx collection). This repeated logic increases maintenance overhead — changing how "has at least one tag" is determined would require edits in two places.
Extract the shared inner check into a reusable helper and call it from both spots:
const policyTagListHasTags = (policyTagList: PolicyTagLists | undefined) =>
Object.values(policyTagList ?? {}).some((tagList) => Object.keys(tagList.tags ?? {}).length > 0);
// hasTagsSelector
const hasTagsSelector = (allPolicyTagLists: OnyxCollection<PolicyTagLists>) =>
Object.values(allPolicyTagLists ?? {}).some(policyTagListHasTags);
// in the hook
const hasSelectedPolicyTags = selectedPolicyTagLists.some(policyTagListHasTags);Reviewed at: 42fd7bd | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
Done in b33caad. Extracted the shared tag-existence check into a policyTagListHasTags helper and reused it from both hasTagsSelector and hasSelectedPolicyTags, so the "has at least one tag" logic now lives in one place.
Verified locally: Prettier, ESLint, typecheck, React Compiler compliance, and all 18 useAdvancedSearchFilters unit tests pass.
Co-authored-by: daledah <daledah@users.noreply.github.com>
Codecov Report✅ Changes either increased or maintained existing code coverage, great job!
|
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / SafariMacOS: Desktop |
|
🚧 @lakchote has triggered a test Expensify/App build. You can view the workflow run here. |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/lakchote in version: 9.4.16-1 🚀
Bundle Size Analysis (Sentry): |
|
🤖 Help site review: no docs changes required. This PR fixes internal display logic — the Tag filter in advanced Search is now hidden when no tags exist, matching the existing Category filter behavior ( I reviewed the relevant help articles and none document the previous (buggy) behavior, so nothing needs to be corrected:
No draft help site PR was created since there is nothing to update. @daledah, if you believe a help article should document when individual filters appear/hide, let me know and I'll draft the update. |
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.4.16-5 🚀
|
Explanation of Change
In the Search advanced filters, the Tag filter was shown whenever the Tags feature was enabled on a workspace, even when no tags actually existed — unlike the Category filter, which is correctly hidden when no categories exist.
The Tag filter's visibility passed
!!selectedPolicyTagListsas thesinglePolicyConditionargument toshouldDisplayFilter.selectedPolicyTagListscomes fromgetAllPolicyValues, which always returns an array ([]at minimum), and a non-null array is always truthy. SosinglePolicyConditionwas permanentlytrue, collapsing the whole expression to justareTagsEnabledand keeping the filter visible regardless of whether any tags existed.This change replaces the always-truthy check with
hasSelectedPolicyTags, which verifies that the selected policies actually contain at least one tag entry (mirroring the existinghasTagsSelectorlogic). This brings the Tag filter's behavior in line with the Category filter.Fixed Issues
$ #93568
PROPOSAL: #93568 (comment)
Tests
// TODO: The human co-author must fill out the tests you ran before marking this PR as "ready for review"
// Please describe what tests you performed that validates your changed worked.
Offline tests
This is pure client-side display logic with no API call, so behavior is identical offline.
QA Steps
// TODO: The human co-author must fill out the QA tests you ran before marking this PR as "ready for review".
// Please describe what QA needs to do to validate your changes and what areas do they need to test for regressions.
PR Author Checklist
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari