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

distinct_on support #67

Closed
bell-steven opened this issue Jul 13, 2021 · 6 comments · Fixed by #124
Closed

distinct_on support #67

bell-steven opened this issue Jul 13, 2021 · 6 comments · Fixed by #124

Comments

@bell-steven
Copy link

I have been trying to figure out how to get the distinct_on variable working.

I played around with customBuildFields and queries, but I have been coming up short.

There is this answer on StackOverflow, which doesn't work.

Has anyone ever come across this and got it working?

@bharatkashyap
Copy link
Contributor

Extend the default buildVariables function

    // buildGetListVariables 
    // L24 
   const { customFilters = [] } = params;
     
    // ...
    /** Setting "distinct_on" to be the `filters` object attribute to be used inside RA
     * and setting to a `distinct_on` variable
     * and removing from the filter object
     */

    const distinctOnField = "distinct_on";
    const { distinct_on = "" } = filterObj;
    filterObj = omit(filterObj, [distinctOnField]);
    
    // ... 
    
    // L150 
     if (params.sort) {
      result["order_by"] = set(
        {},
        params.sort.field,
        params.sort.order.toLowerCase()
      );
    }
    
    // Add the "distinct_on" attribute to the result object
    if (distinct_on) {
      result["distinct_on"] = distinct_on;
    }
  • Use this to pass to your buildHasuraProvider

Here's the implementation - customVariables.js and app.js

@bell-steven
Copy link
Author

bell-steven commented Jul 18, 2021

Thanks!

Would the maintainers be open to adding this to the library? I would be more than happy to open a PR.

Edit: I have a form with the changes here. Will put in a PR if anyone else seems interested these changes.

@bharatkashyap
Copy link
Contributor

@praveenweb: Adding distinct_on support to the library

@arjunyel
Copy link
Contributor

@bell-steven hey friend, could you please open a PR with your distinct_on changes? Thank you so much!

@bell-steven
Copy link
Author

@arjunyel The repo has changed quite a bit since those changes, will have to try and find the time to rebase.

@crates
Copy link

crates commented Jul 28, 2022

I'd like to throw in my support for this to be part of the library, as well. It's a pretty valuable addition. Let us know if you find time to include it, please!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants