Skip to content

Conversation

@ryanwilsonperkin
Copy link
Member

WHY are these changes introduced?

Fixes #4076

Introduces a variant of the IndexTable that has no checkboxes in the leftmost column when the selectable prop is false. This is inline with the naming of the prop and makes the table usable for resources where the user may not need to support selection, and is instead just using the table as a resource-specific version of a DataTable.

WHAT is this pull request doing?

  • Updates the IndexProvider to pass through the selectable prop into the context. This was one of the allowed props on the context but wasn't actually being passed into the context object itself. Instead the context was deriving its own value of "selectable" to mean "there are more than 0 items present" which is renamed to "hasSelections"
  • Updates previous uses of the term "selectable" where it meant "has bulk actions" to be "actionable" instead to indicate intent, and to differentiate it from "selectable" which indicates "rows in this table should be able to be selected"
  • Refactored the renderHeading inline-component to have a simpler signature by separating out a new renderCheckboxCell inline-component. Previously, renderHeading would return a 2-tuple of JSX on the first heading, and a single JSX otherwise, which was a bit confusing and harder to manage when checkbox is optional. Instead we'll do a simple map with renderHeading and then insert the checkbox content at the front of the array if desired.

A screenshot of the approach rendered with many columns so that it scrolls horizontally. Note the lack of checkbox:

image

TODO

  • Still needs some additional work in order to get the styling of the sticky columns correct when a checkbox is not rendered. Currently our code makes a lot of assumptions that the first column will be there, and uses it to calculate the offset width for the second column. When the checkbox isn't present, the sticky column calculation doesn't work.

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

Copy-paste the code from the parent ticket into the Playground in order to test this out.

🎩 checklist

Within the IndexProvider the value is accepted as a prop but isn't being
used, when it should be. There's already an existing identifier
"selectable" which can be renamed as "actionable" because it indicates
whether or not actions can be made (are there bulk actions available).
Similarly in the useBulkSelectionData hook there's an existing
identifier "selectable" where it means "does it currently have any
selections. It's a temporary variable created to indicate whether or not
any selections have been made, so we rename it to "hasSelections" even
though the scope doesn't conflict - just to make it clearer.
This was previously always the case, and when the selectable prop is not
provided we would still expect it to default to true, because the main
behaviour of this component is for use as a selectable index.

This provides backwards compatibility, while still supporting explicitly
passing this value as true/false.
Simplifies the closure function because it no longer has multiple return
signatures (returning either JSX or JSX[], depending on whether or not
its the first element).

Splits out a second one that's specifically for rendering the checkbox,
and then explicitly calling that and pushing it into the array when
selectable.
@github-actions
Copy link
Contributor

size-limit report

Path Size
cjs 142.12 KB (+0.01% 🔺)
esm 95.84 KB (-0.01% 🔽)
esnext 138.85 KB (-0.01% 🔽)
css 33.56 KB (0%)

@ryanwilsonperkin
Copy link
Member Author

Got a good start on this so far, but looks like it'll still need a fair bit of refactoring in the IndexTable component in order to ensure that it makes the correct column(s) sticky when scrolling horizontally. Right now it's hardcoded to always assume that the first two columns should be sticky, and calculates the offset accordingly. When selectable=false only the first column should be sticky, because there's no initial checkbox column anymore.

@brydonm
Copy link
Contributor

brydonm commented Aug 6, 2021

@ryanwilsonperkin happy to provide support on this if needed! Looking forward to this change.

@chloerice
Copy link
Member

chloerice commented Aug 9, 2021

Hey @ryanwilsonperkin 👋🏽 I didn't realize #4076 existed so I missed that you were already working on this bug! 🤦🏽‍♀️ I've got a draft PR working as well (#4367), I just need to fix CI failing over the Row tests 👀

@brendanatshopify
Copy link
Contributor

👀 Just a heads up that the Shop channel team is working on a solution to this at #4376 that branches off @chloerice's work

@ryanwilsonperkin
Copy link
Member Author

Thanks folks! I'll close this one out in favour of the new PR being created, feel free to re-open if it proves useful.

@alex-page alex-page deleted the fix-selectable-index-table branch March 22, 2022 04:18
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.

[IndexTable] selectable prop being set to false has no effect

4 participants