Skip to content

improvement(Table): implement indeterminate checkbox state#3909

Closed
michpetrov wants to merge 3 commits intopatternfly:masterfrom
michpetrov:selectable-table
Closed

improvement(Table): implement indeterminate checkbox state#3909
michpetrov wants to merge 3 commits intopatternfly:masterfrom
michpetrov:selectable-table

Conversation

@michpetrov
Copy link
Copy Markdown
Contributor

What: Closes #3648

Added indeterminate state; this cannot be achieved simply through HTML attributes, hence the use of hooks. Left in the allRowsSelected prop in case it's used somewhere but it's made redundant with this change.

(Kinda new to React, please correct me if I went against conventions)

@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented Mar 13, 2020

@michpetrov michpetrov force-pushed the selectable-table branch 3 times, most recently from a25602f to 05da5e8 Compare March 16, 2020 18:43
@michpetrov
Copy link
Copy Markdown
Contributor Author

Okay, I think I fixed the tests; one question regarding Selectable table with selected expandable row, is the purpose of the test to simply check the presence of a prop, or to check that the check-all checkbox is indeed checked? Since those two are somewhat independent.

Should I add test for "some rows are selected"?

@tlabaj tlabaj requested review from evwilkin, kmcfaul and seanforyou23 and removed request for evwilkin March 19, 2020 16:05
Copy link
Copy Markdown
Contributor

@seanforyou23 seanforyou23 left a comment

Choose a reason for hiding this comment

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

Nice work! I think unfortunately we don't yet utilize hooks in patternfly react due to legacy react version support. As much as I'd love to change this, I'd have to ask for the moment - can we refactor this to a class-based solution?

Another thing worth considering is the usage of the name amount - might it better be named cardinalityType? Interested to hear other opinions on this.

@michpetrov
Copy link
Copy Markdown
Contributor Author

@seanforyou23 I see useRef being used in TextInput but I can refactor the component.

@seanforyou23
Copy link
Copy Markdown
Contributor

Thx for pointing this out! Checking into what we can do, keep you posted!

@tlabaj tlabaj requested a review from mcarrano March 23, 2020 17:11
Copy link
Copy Markdown
Member

@mcarrano mcarrano left a comment

Choose a reason for hiding this comment

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

@kriker can you help me out with this one? For bulk selection in a table, I believe the way we said it should work is for selecting the checkbox to clear selection (not select all) when you start with partial selection. That's what I remember but I can't find it written down anywhere. Can you confirm? It's currently working the opposite here.

@tlabaj
Copy link
Copy Markdown
Contributor

tlabaj commented Mar 25, 2020

@michpetrov useRef is only used int the TextInput example to show how a PF consumer might be able to use it. We do not yet utilize hooks in our PF library as @seanforyou23 mentioned above.

@michpetrov
Copy link
Copy Markdown
Contributor Author

Refactored the component, rebased the branch. There is still the one test failing, I don't know what it is testing so I don't know what to fix.

@jenny-s51 jenny-s51 self-requested a review March 30, 2020 19:31
@seanforyou23
Copy link
Copy Markdown
Contributor

@michpetrov I'll take a look later today and see if I can help find out what gives with the test. Thanks for the refactoring!

@seanforyou23
Copy link
Copy Markdown
Contributor

seanforyou23 commented Apr 15, 2020

Hi there @michpetrov - just a heads up I sent a PR to your working branch - seems to be related to this commit bd3f49f

Looking into the issue I think I found some problems that while unrelated to this work item - is impacted by it. I'm going to see if I can isolate the unrelated problem (described in the cypress test) without these changes and maybe that will fix the problem without having to do anything further here. It's just a guess at this point though, so feel free to proceed investigating on your end with the demo I provided in the mean time. Hope it helps, keep you posted!

compact = 'compact'
}

export enum SelectedRowsAmount {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you think we could assign strings to represent these enum values? I think using the enum indices is really elegant but makes it a little difficult to debug when comparing against the resulting markup. In other words I thought data-rowsamount="1" meant there was a single row selected instead of it referring to "some".

Comment thread packages/react-table/src/components/Table/utils/decorators/selectable.tsx Outdated
) => {
const {
extraParams: { onSelect, allRowsSelected, rowLabeledBy = 'simple-node' }
extraParams: { onSelect, allRowsSelected, selectedRowsAmount, rowLabeledBy = 'simple-node' }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we no longer need allRowsSelected, can we remove it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll remove it, I kept it in in case something depended on it.

'aria-labelledby': rowLabeledBy + rowIndex
}
: {
checked: allRowsSelected,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems like this may be what's causing that test to fail.

@michpetrov michpetrov force-pushed the selectable-table branch 3 times, most recently from 3d31538 to 3220c67 Compare June 3, 2020 17:14
@michpetrov
Copy link
Copy Markdown
Contributor Author

@seanforyou23 I've changed the failing test and added your cypress tests

Copy link
Copy Markdown
Member

@dlabrecq dlabrecq left a comment

Choose a reason for hiding this comment

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

Looking... Can you please rebase to fix the merge conflict?

@michpetrov
Copy link
Copy Markdown
Contributor Author

@dlabrecq rebased

Copy link
Copy Markdown
Member

@dlabrecq dlabrecq left a comment

Choose a reason for hiding this comment

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

After reviewing the code, I realized we already have a "Bulk select table" feature, which performs the same functionality and more. It shows how many items are selected, it selects one or more pages at a time, etc.

Do we want to support both features?

See http://patternfly-react.surge.sh/documentation/react/demos/bulkselecttable

Regarding the example itself, I found the behavior a little confusing. I expect the "select all" toggle to show the same behavior as if I manually clicked on each checkbox. That is, similar to the "Bulk select table" example.

  1. When I click the "select all" toggle, all checkboxes are selected, including the disabled one.

Screen Shot 2020-06-24 at 2 02 55 PM

  1. When I select each checkbox manually, the "select all" toggle is shown in the indeterminate state. I presume that's because one of the checkboxes is disabled and cannot be selected.

Screen Shot 2020-06-24 at 2 03 40 PM

  1. Now if I click on the "select all" toggle, then deselect each checkbox manually, the "select all" toggle remains in an indeterminate state. I cannot deselect the remaining checkbox because it's disabled. I have to select all again, then deselect all to remove the selection.

Screen Shot 2020-06-24 at 2 09 59 PM

@mcarrano
Copy link
Copy Markdown
Member

I think that @dlabrecq makes some good points. This show work in the same way as the bulk selection from the toolbar. The only reason to still include this was for cases where you might want to use a table without a toolbar.

@Venefilyn
Copy link
Copy Markdown
Contributor

Venefilyn commented Jul 18, 2020

I can see how the bulk selection could work if you have a toolbar, but at the same time it will increase the size of the toolbar, which might already be full enough. Unless the select all functionality in the Table will be deprecated I believe having a select-all checkbox that can be indeterminate makes sense

I've got a question: If the user would never select all due to the Table contents but you still want to display that something has been selected, how would you go about doing that without a the select-all or bulk select component?

@stale
Copy link
Copy Markdown

stale Bot commented Sep 20, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

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 this pull request may close these issues.

Add indeterminate checkbox to table header

7 participants