Conversation
|
Hey @iperzic. I always disliked how smart filtering behaved. This is how I want it to behave, when toggling smart filtering:
Let me know if my fixes make sense and I would love for more tests are that. |
|
There’s certainly always been a huge amount of room for improvement in the smart-filtering feature. So it’s great to see it getting some attention and fixes/refinements. sideshowbarker@2112c16 has some further fixes, plus tests. I don’t have push/write perms to this repo, nor to PR branches here like this one — so that commit is at my own repo. But it could be fetched and cherry-picked into this branch. |
|
@dlvhdr Thanks for the review, and the follow-up. I included @sideshowbarker commit in this PR as well. As far as I'm concerned, this looks good. Though, I must caveat that I'm not that experienced with golang, so take my review with a bucket of salt. |
- Fix HasPrefix false-positive on similar repo names: HasCurrentRepoNameInConfiguredFilter() and GetSearchValue() used strings.HasPrefix, so repo:owner/repo would falsely match repo:owner/repo-extra. Changed to exact token equality. - Fix inconsistent toggle logic in issues and notifications sections: both still used the old !HasRepoNameInConfiguredFilter() guard, which prevented toggling when any repo: filter was present (including the current repo). Updated both to match the PR section's HasCurrentRepoNameInConfiguredFilter() || !HasRepoNameInConfiguredFilter() logic. - Fix NewModel initialization using strings.Contains instead of token-level matching, which could false-positive on substring matches. Changed to iterate tokens with strings.FieldsSeq and exact equality. - Change log.Info to log.Debug for the toggle state message in prssection.go, since it fires on every keypress and is only useful for debugging. - Add 28 test cases across 7 test functions covering HasRepoNameInConfiguredFilter, HasCurrentRepoNameInConfiguredFilter, SyncSmartFilterWithSearchValue, GetSearchValue (including the prefix false-positive regression), and GetConfigFiltersWithCurrentRemoteAdded. - Update Smart Filtering docs to document that manually editing the search bar and pressing Enter syncs the smart filter state to match.
0a4fc19 to
1b842e7
Compare
|
@sideshowbarker seems like the tests fail due to not running inside a git repo or something along those lines. Should we mock the currentRepoFilter func? |
To fix that, I see you made this change: func currentRepoFilter(t *testing.T) string {
t.Helper()
+ t.Setenv("GH_REPO", "https://github.com/dlvhdr/gh-dash")
repo, err := repository.Current()
if err != nil {
t.Fatal("failed to resolve current repository:", err)So yeah I hadn’t considered how that CI might not (wouldn’t) have a remote configured. But in hindsight: I can see that, because the test as currently written isn’t testing across multiple repos anyway, then for the current scope of the test, the test didn’t need const testRepoFilter = "repo:dlvhdr/gh-dash"…and then just have the test use that constant everywhere it’s calling
No, I think the fix you made is sufficient for now. The actual app code doesn’t call I had imagined the test needed to handle testing across multiple repos, and so we’d need some way for the test to know what the current repo is. But… the test as currently written isn’t testing across multiple repos — and even if it were, we could anyway actually just be using strings. So when (if) we next have need to go back in and touch that But otherwise, I think the fix you made is fine for now, and we don’t need to fiddle with it further right now. |
Summary
When running
gh-dashinside a git repo with smart filtering enabled, removing therepo:filter from the search bar and pressing Enter had no effect, the filter was silently re-added behind the scenes on every query. This happened becauseIsFilteredByCurrentRemotewas never cleared when the user edited the search value.This PR adds
SyncSmartFilterWithSearchValue()which detects that the user removed the repo filter and clears the flag, so the search respects the user's edit.Note
The issue is only reproducible when
filtersis removed from "Mine" PR section in.gh-dash.ymlHow did you test this change?
Unit tests covering: smart filter active with repo filter present, smart filter toggled off, user manually removing the repo filter, user replacing with a different repo, and config already containing a repo filter.
Images/Videos