-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat(filters): add StartsWith/EndsWith (a*z
) to OData/GraphQL
#1532
Conversation
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1532 +/- ##
========================================
+ Coverage 99.8% 99.8% +0.1%
========================================
Files 198 198
Lines 21636 21661 +25
Branches 7227 6965 -262
========================================
+ Hits 21575 21600 +25
Misses 61 61 ☔ View full report in Codecov by Sentry. |
@zewa666 here you go, the PR to add StartsWith/EndsWith to both OData and GraphQL, I think the query are ok (see above), but it would be nice to have confirmation and a review from you. Also a reminder that if you want to test without doing a git checkout, you can use the stackblitz link above Couple of things to note:
I don't think there's anything left to do and fix after that? Did you wanted to push something else before a new release? |
I'll give the PR a proper look tonight. sorting had a couple of issues due to columnName vs columnId usage but I've fixed that a while ago in a PR, perhaps this is another bug. and yep gridstate is something that I'll have to inspect in more detail anyways. For our usecase with ForeignKey columns I always display the referenced tables label col but write as value the id col. so I'd need the same for the filter persistence, meaning storing the whole object instead of only the value. will let you know once I dig into that |
So I found the pagination bug and fixed it in PR #1534 , it was related to Grid Preset of a page number that was out of boundaries (displayed as gif in the PR). It's probable that the issue might not have shown with a real backend server since typically the server will never return a page number that is out of boundaries (e.g. page size of 20, page number is set to 2, but we have less than 20 items so technically being in page 2 is out of bound and impossible, that only happened when loading Grid Preset)
I designed Grid State/Preset to be easily stringified so that it can be saved in DB/LocalStorage and reused easily by parsing string to an object. Anyway you most probably know all of this already 😉 So I updated the OData with RxJS and I'm pretty much done with this PR and I think that I have addressed all other issues as well. |
sry, didnt manage to look at it yesterday but plan to do so tonight |
no worries, it's weekend after all... enjoy it 😉 |
so what stood out while looking at the examples is that no matter what Operator I choose, as soon as I add a star and type on it will move to starts/endswith combo. I've realized though that you can disable the feature toggling off Aside from that I think this PR looks totally fine, nice addition. While looking at the example 14 though I came up with a quick example of what I thought the SQL Like style would be: searchSQLLike(value, searchString) {
// Replace * with .* to convert to regex pattern
const regexPattern = '^' + searchString.replace(/\*/g, '.*') + '$';
const regex = new RegExp(regexPattern); // add 'i' as second argument for insensitive
return regex.test(value);
} adding the insenstive operator would match To quickly try it out I've added the additional condition in the filterPredicate of example 14 else if (searchFilterArgs.searchTerms[0]?.toString().includes('*')) {
return this.searchSQLLike(cellValue, searchFilterArgs.searchTerms[0]);
} So now writing something like Now if we'd like to have the same feature available in OData, one possible solution would be to use the matchesPattern string function. Note that searchBy = `matchesPattern(${fieldName}, '%5EA${searchValue.replace(/\*/g, '.*')}$')`; |
hmm I even forgot that I added For the example 14, I have to mention again that was only meant for demo purposes (and to answer that SO question), though I do understand it might open ideas for other filter operators and others, the Example 14 remains an example which I don't really want to extend more than what it is. I guess what could be done in future PR is to add an extra Compound Operator (maybe
I not familiar with the ILIKE, is that related here? I mean the For now, I will merge the PR and anything else could be added in separate PRs |
sorry for the confusion. example 14 is absolutely fine as it is. My example function was more along the lines of mimicking the exact behavior of SQL LIKE, because in combo with matchesPattern, it's a simple mean for the backend to translate it back into SQL and that way receive ILIKE is just the case insensitive form of LIKE And yes you're right that the simple cases with a*, *z and a*z are absolutely enough. I'm just leaving this here as a reminder for how to get the multi wildcard feature supported, which I'm going to implement via the previously mentioned Operator.Custom |
ah ok cool, I wasn't aware, at least it's not another Apple stuff haha
if you get it all working as expected, I again think we could add it as a new compound operator that when selected (and only when selected) would parse SQL LIKE form just like with the |
the only reason I'm holding off doing that right away is bc this is a very narrow use case thats only helpful if your OData is driving a SQL based DB backend. So while important for my app I feel like its too specific to be implemented as a standard feature for slickgrid universal itself. In contrast the a*z one is applicable for all types of OData backends
well there is SFDC with the OData Wrapper, SAP, Sharepoint and a couple of others not exposing the DB directly ;) |
actually taking another look at this very own PR, the regex to be replaced is actually in the backend service (OData/GraphQL) and not the one from filter service (since that is meant to be local dataset)
perhaps some kind of backend plugin? Maybe some kind of
what I meant was that SQL LIKE is a standard that many people already know 😄 |
yep thats what I did for trying it out
thats a great idea. while I already have subclassed the odata service for other reasons, it would still allow not having to override the whole updateFilters method but merely provide a callback to extend filtering behavior. |
indeed, so I'll wait for your upcoming PR then 😉 that could be added later anyway, it's just meant to be easier for the end user. We should probably include @jr01 in the discussion as well since he's another great user of the platform 😺 |
@ghiscoding yes, would be cool if there was an easier way for extending filter behavior. This thread reminded me that I still have this in place: ghiscoding/Angular-Slickgrid#808 (comment) |
@jr01 thanks for the feedback, you can probably imagine that I would certainly accept any PR if there's a way to support your use case in a generic way then I'm more than happy to receive a PR to have it built-in. Otherwise, like discussed above, maybe a |
OData Service
GraphQL Service