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

feat(table): update select all on addition or removal of rows #632

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

conor-darcy
Copy link
Collaborator

Select all checkbox will update if a row is deleted from the dom.
I've also added a new method to manually set the state of gux-all-row-select.

Copy link

@@ -49,6 +50,26 @@ export class GuxAllRowSelect {
this.inputElement.indeterminate = indeterminate;
}

@Method()
async setCheckedState(checkedState: GuxAllRowSelectState): Promise<void> {
switch (checkedState) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe it is an too "clever" and what you have is clearer but I would have

async setCheckedState(checkedState: GuxAllRowSelectState): Promise<void> {
  this.inputElement.checked = checkedState === 'checked';
  this.inputElement.indeterminate = checkedState === 'indeterminate';
}

@@ -49,6 +50,26 @@ export class GuxAllRowSelect {
this.inputElement.indeterminate = indeterminate;
}

@Method()
async setCheckedState(checkedState: GuxAllRowSelectState): Promise<void> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The naming of this function might be a bit off as it sets the checked state and the indeterminate state on the internal input.

async setCheckedState(checkedState: GuxAllRowSelectState): Promise<void> {
switch (checkedState) {
case 'checked':
this.inputElement.checked = true;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is ignoring the components selected property which I think is wrong.
Should it be this.selected = true;

@@ -49,6 +50,26 @@ export class GuxAllRowSelect {
this.inputElement.indeterminate = indeterminate;
}

@Method()
async setCheckedState(checkedState: GuxAllRowSelectState): Promise<void> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this function is useful we should be able to use it in the updateSelectAllBoxState method of gux-table and it should simplify the code/make it easier to read.

forceUpdate(this)
);
private slotObserver: MutationObserver = new MutationObserver(() => {
if (this.selectAllCheckbox) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I am not sure this if guard is needed. The updateSelectAllBoxState method that is eventually calls has a guard against the select all checkbox not existing already.

@gavin-everett-genesys
Copy link
Collaborator

What should the behaviour be if this is set dynamically ? At the moment if I set the checked state dynamically using the function it does work for example I pass setCheckedState('checked') it sets the gux-all-row-select to checked but all of the gux-row-select do not change to checked which I think they should or no ?

@conor-darcy
Copy link
Collaborator Author

@daragh-king-genesys Keeping the setting of checked & indeterminate states separate to keep it inline with the native checkbox. If we try & update the table rows themeselves based on a possible 3 states we won't know what to do with 'indeterminate' without a lot of work.

<gux-table object-table selectable-rows>
<table slot="data">
<thead>
<tr data-row-id="head">
<th><gux-all-row-select></gux-all-row-select></th>
<th><gux-all-row-select id="allRowSelect"></gux-all-row-select></th>
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it might be easier to just query select the gux-all-row-select element instead of adding an id.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would select all the gux-all-row-select's on the page, I just want to select that particular one as it relates to one particular table.

const allRowSelect = document.getElementById('allRowSelect');

selectAll.addEventListener('click', () => {
allRowSelect.setIndeterminate(false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be better to house this within the setChecked method in the shadowDOM like,

async setChecked(checked: boolean): Promise<void> {
    this.selected = checked;
   this.setIndeterminate(false);
    this.internalallrowselectchange.emit(this.selected);
  }

or

async setChecked(checked: boolean): Promise<void> {
    this.selected = checked;
   this.inputElement.indeterminate = false
    this.internalallrowselectchange.emit(this.selected);
  }

as I am not sure is it valid to call a method with a Watch decorator internally.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I did initially look at that but decided to keep the setting of checked & indeterminate states separate to keep it inline with the native checkbox as there were a few issues.

Apparently 'indeterminate' is a presentational state, just visual, while the value of a checkbox is either checked or unchecked. I thought it best to stick with this to avoid any unforeseen issues down the road by diverging from the native checkbox.

@conor-darcy
Copy link
Collaborator Author

What should the behaviour be if this is set dynamically ? At the moment if I set the checked state dynamically using the function it does work for example I pass setCheckedState('checked') it sets the gux-all-row-select to checked but all of the gux-row-select do not change to checked which I think they should or no ?

I've an example with select/deselect all buttons using the methods on the gux-all-row-select.
I don't have an example setting the indeterminate alone as I would not know what rows should be selected or not.

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.

3 participants