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

unique aggregation return [SetIterator] instead of array #2173

Closed
rantibi opened this issue Apr 15, 2020 · 4 comments · Fixed by #2464
Closed

unique aggregation return [SetIterator] instead of array #2173

rantibi opened this issue Apr 15, 2020 · 4 comments · Fixed by #2464
Labels

Comments

@rantibi
Copy link

rantibi commented Apr 15, 2020

Describe the bug (required)
Seems like the following unique premade aggregation not working well:
https://github.com/tannerlinsley/react-table/blob/master/src/aggregations.js#L70-L72

I have the following column:

{
    variety: 'x',
    Header: 'x',
    accessor: d => d.id,
    aggregate: 'unique',
    aggregateValue: 'unique',
    Aggregated: a => {
      const {
        cell: { value },
      } = a;
      console.log(value);
      return `${value}`;
    },
  },

when I check the log it prints [SetIterator] instead of the unique values as an array.

if I am doing the following it works as expected:

import { unique } from "react-table/src/aggregations";
...
{
    variety: 'x',
    Header: 'x',
    accessor: d => d.id,
    aggregate: unique,
    Aggregated: a => {
      const {
        cell: { value },
      } = a;
      console.log(value);
      return `${value}`;
    },
  },

https://codesandbox.io/s/laughing-pond-ieulg?file=/src/App.js

@tannerlinsley
Copy link
Collaborator

This is strange that it works with importing directly, but not as a string option

@thomasmarr
Copy link

@tannerlinsley I did a little digging on this today. The build process for react-table is converting

https://github.com/tannerlinsley/react-table/blob/f41b82d07deedaa75c48f259f9665c0ce614b679/src/aggregations.js#L71

to

[].concat(new Set(values).values())

The rescripts builder (used by the examples), does not make that conversion (which is why importing the function directly in the example App.js works, but importing it from the react-table bundle does not).

There is probably a way to configure rollup and/or babel not to make that conversion, but I'm not sure how. An alternative is just to use the slightly older fashioned syntax (which the rollup build process does not convert):

Array.from(new Set(values).values())

If you're happy with that approach I'll try and submit a PR tomorrow.

@tannerlinsley
Copy link
Collaborator

That would be great :)

thomasmarr added a commit to thomasmarr/react-table that referenced this issue Jun 18, 2020
Update syntax in return line of unique aggregation function
Use Array.from() instead of the spread operator [...]
Motivation: prevent polyfilling to [].concat() to enable reference by string in column definitions

closes TanStack#2173
thomasmarr added a commit to thomasmarr/react-table that referenced this issue Jun 18, 2020
Update syntax in return line of unique aggregation function
Use Array.from() instead of the spread operator [...]
Motivation: prevent polyfilling to [].concat() to enable reference by string in column definitions

closes TanStack#2173
tannerlinsley pushed a commit that referenced this issue Jun 18, 2020
Update syntax in return line of unique aggregation function
Use Array.from() instead of the spread operator [...]
Motivation: prevent polyfilling to [].concat() to enable reference by string in column definitions

closes #2173

Co-authored-by: Thomas Marr <thomas.marr@arup.com>
@tannerlinsley
Copy link
Collaborator

🎉 This issue has been resolved in version 7.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants