Skip to content
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

Search ext: support complex joins & HAVING clause in api4 smart groups #18644

Merged
merged 6 commits into from
Oct 4, 2020

Conversation

colemanw
Copy link
Member

Overview

Improves the new search extension and APIv4 smart groups in core to support any entity that can join with Contact, including full support for calculated fields and the HAVING clause.

Before

Limited smart group support.

After

Improved smart group support; with test.

@civibot
Copy link

civibot bot commented Sep 30, 2020

(Standard links)

@civibot civibot bot added the master label Sep 30, 2020
@colemanw
Copy link
Member Author

colemanw commented Oct 1, 2020

Failure looks unrelated. retest this please

@eileenmcnaughton
Copy link
Contributor

@colemanw I tried to figure out how to test this - I thought I might have been able to create a smart group like this but I can't

civicrm/search#/create/LineItem/?join=%5B%5B"Contribution%20AS%20contribution",false%5D,%5B"PriceField%20AS%20price_field",false%5D%5D&select=%5B"financial_type_id:label","contribution.contact_id","qty","line_total"%5D&where=%5B%5B"line_total",">","2"%5D%5D

Screen Shot 2020-10-02 at 8 38 01 AM

I also can't spot any new 'having' option civicrm/search#/create/LineItem/?join=%5B%5B"Contribution%20AS%20contribution",false%5D,%5B"PriceField%20AS%20price_field",false%5D%5D&select=%5B"GROUP_CONCAT(DISTINCT%20financial_type_id:label)","GROUP_CONCAT(contribution.contact_id)","SUM(qty)","SUM(line_total)"%5D&where=%5B%5B"line_total",">","2"%5D%5D&groupBy=%5B"price_field_value_id","financial_type_id"%5D
Screen Shot 2020-10-02 at 8 40 58 AM

@colemanw
Copy link
Member Author

colemanw commented Oct 1, 2020

@eileenmcnaughton your first screenshot seems to not have this PR applied. The "Missing contact_id" error message is different in this version, so likely you need to ensure the patch is applied and flush caches.

In the Search UI, the "HAVING" clause is named "Filter" and appears in the right column underneath the "Where" criteria. It is only visible when one or more grouping columns is selected... although once more sql functions are allowed it might be useful even when grouping isn't in use, so I'll probably lift that restriction.

@colemanw
Copy link
Member Author

colemanw commented Oct 1, 2020

On the having - this should return rows but doesn't I believe

For me it does return results (for nicety I changed LIST(contact_id) to COUNT(contact_id) but it works either way):
image

@colemanw
Copy link
Member Author

colemanw commented Oct 2, 2020

@eileenmcnaughton I clicked on that link and without tweaking any of the criteria I clicked "Search" and it gave me 3 results:
image

…d in GROUP_BY

The bug was that it wasn't recognizing the column name after a function was added to it.
@colemanw
Copy link
Member Author

colemanw commented Oct 3, 2020

@eileenmcnaughton I've updated this PR. I think everything is now working as it should.
HOWEVER the exact scenario you were testing above does not work, and that's because contact_id is an aggregated column. We still don't have a way to handle that, but I don't think that should block this PR which is generally an improvement.

@eileenmcnaughton
Copy link
Contributor

eileenmcnaughton commented Oct 3, 2020

@colemanw - locally still hitting IDS issues - I'll try on the test site once it's stable - note 'action' is not resolved

Screen Shot 2020-10-03 at 1 58 56 PM

@colemanw
Copy link
Member Author

colemanw commented Oct 3, 2020

@eileenmcnaughton you can always give yourself the IDS bypass permission locally

@eileenmcnaughton
Copy link
Contributor

@colemanw if you want to punt IDS to a separate PR / follow up I'll test as admin - I think it's important to fix but happy to not make it blocking on this

@eileenmcnaughton
Copy link
Contributor

Actually @colemanw I get that unresolved action tag for demo user even when the params are not in the url

Screen Shot 2020-10-03 at 2 09 09 PM

@eileenmcnaughton
Copy link
Contributor

@lcdservices is this on your radar - this will make it possible to create smart groups based on line items. I currently see some limitations (which I'll worry about once these changes are finalised) - but I suspect you will have good input on it.

@eileenmcnaughton
Copy link
Contributor

Just loading the page.... as demo

Screen Shot 2020-10-03 at 2 10 44 PM

@colemanw
Copy link
Member Author

colemanw commented Oct 4, 2020

@eileenmcnaughton I think again the problem was you're using an outdated test site. That error was fixed by 7a56c06 and looks good to me on the latest demo:
http://core-18644-95ouo.test-1.civicrm.org:8001/civicrm/search#/create/Contact/

Angular 1.8 doesn't seem to like it when you try to access component properties
before the init function.
@eileenmcnaughton
Copy link
Contributor

OK - I agree that link works & I was able to

  1. create a smart group based on line item criteria
  2. use HAVING criteria

Let's merge this & then try to put some use cases through it

@colemanw
Copy link
Member Author

colemanw commented Oct 4, 2020

Thanks @eileenmcnaughton I pushed up one more small tweak for code sanitation so we'll wait for this latest test run then merge.

@seamuslee001 seamuslee001 merged commit 0a6868c into civicrm:master Oct 4, 2020
@seamuslee001 seamuslee001 deleted the savedSearch branch October 4, 2020 05:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants