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

Use tanstack table for Competitors #10778

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kr-matthews
Copy link
Contributor

See slack discussion about my concerns.

@kr-matthews kr-matthews requested a review from gregorbg February 6, 2025 05:12
@kr-matthews kr-matthews self-assigned this Feb 6, 2025
Copy link
Member

@gregorbg gregorbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I see your point much more clearly now. The configuration is indeed cumbersome, and especially in terms of footer counts the setup is much more complicated than I anticipated.

I'll leave it up to you whether you want to use it and merge this PR or if you prefer to discard it.

Comment on lines +30 to +32
) : (
info.getValue()
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get this with regards to the ternary condition. If getValue is truthy, you return an <a> link, but if it's falsey you just return... that falsey value explicitly? Why not just info.getValue() && (<a>)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure I just put the wrong condition, it should be checking that the wca id exists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case info.getValue() ? is definitely not right, because that cell is linked to user.name as accessor.

Comment on lines +60 to +63
const { countryCount } = getTotals(
info.table.getCoreRowModel().rows.map((row) => row.original),
eventIds,
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, this is indeed quite unintuitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things here:

  1. getTotals is a helper function which is shared with the psych sheet which is using the original registrations data. So to keep it as a shared helper function I had to pass in the original rows. That helper could be modified though, to take in the tanstack table data in some other format.
  2. I made the cell value just the country name, to get automatic sorting capabilities from tanstack table. I could instead make the cell value be the country object. That would make getting the flag classname simpler, and possibly make the footer calculation easier. But, then a custom sort function would need to be passed in.

Even with those changes, the footer would still not be the most intuitive thing. And this just highlights that there are so many ways to approach tables that it will be hard for us to be consistent across the codebase - especially with non-WST contributors.

The existing (non-tanstack) code is quite easy to understand, and you can explicitly see the data being sorted/etc. If you want to update the footer, it's easy you just go to the footer component and that component has the data immediately available.

As I mentioned elsewhere, I really like that the column definitions centralize the header/body/footer of a column in one spot. But that's about it. The automatic sorting/filtering can be nice - but not if the cell values are 'complicated, such as names with links or countries with flags, etc.

So I'm undecided whether I want to finish off this PR, or cancel it. 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I admit I might have been seduced by the notion of a formless library a bit. But now I definitely see your points...

The bright side here is that Tanstack has a pretty active GitHub account, including Discussions (as in, the GitHub feature called "Discussions"). Could I compel you to post a summarized version of your thoughts there, and see what people think? I feel like our use-case is totally not unreasonable, and especially the cases of

  • "complex" values for a cell (i.e. country name but also flag, person name but also link based on ID)
  • footer counts / totals
    would be interesting to debate.

If an answer is forthcoming in the next few days, you can pick it up for this PR. Otherwise, I suppose we'll just put Tanstack-Table into the drawer again for the time being.

}
},
...eventIds.map((id) => ({
id,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe something like event-${id}?

))}
</Table.Header>
<Table.Body>
{table.getSortedRowModel().rows.length > 0 ? (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you return early if no columns are found?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean rows? Returning early would omit the header/footer. That could work, I guess. I prefer having the header/footer, and I think many of our other tables do that, including as the psych sheet.

@kr-matthews kr-matthews mentioned this pull request Feb 12, 2025
14 tasks
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 this pull request may close these issues.

2 participants