Skip to content
This repository was archived by the owner on Aug 7, 2020. It is now read-only.

Conversation

frenautvh
Copy link
Contributor

UK-42

### Global Actions

```html:preview
<oui-datagrid rows="$ctrl.data" page-size="5" global-actions>
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be best to name the parameter "selectable-rows" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds good

Copy link
Contributor

@AxelPeter AxelPeter Jul 31, 2018

Choose a reason for hiding this comment

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

Yes, selectable-rows is better :)
Don't forget to add the details in the API table below for this attribute

Copy link
Contributor

Choose a reason for hiding this comment

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

Were it only me, I would have named it allows-row-selection but I know you guys won't like it 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

In this way, we keep our logic of *able attributes

this.displayedRows = DatagridController.createEmptyRows(this.paging.getCurrentPageSize());
}

this.selectedRows = this.selectedRows.map(() => false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't this contain the actual rows instead of an array of booleans ? Or something to identify the rows ?

{
	id: rowId,
	isSelected: false
}

If we keep the array of booleans system, then it should be names something like rowSelectionStatus

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since every checkbox needs to have an ng-model i still have to created N booleans for binding ; that's why it made sense to use an array of booleans (i reuse the array)

Copy link
Contributor

Choose a reason for hiding this comment

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

We could react to the checkbox's on-change event and add the corresponding row to the array of rows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think your suggestion would make the code "faster" : no reduce in getSelectedRows since you access array directly ; downside is that you need an additionnal array to store rows which is less clean (you still have to give an ngModel to checkbox so you also need an array of booleans).
did i understand you correcly ?

}, []);
}

onSelectRow (index, selected) {
Copy link
Contributor

Choose a reason for hiding this comment

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

onRowSelection ? Still feels wrong as this method is called even when the row is unselected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

onToggleSelectRow would be better i think

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, good name !

Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, toggleRowSelection seems more appropriate

}, []);
}

onSelectRow (index, selected) {
Copy link
Contributor

Choose a reason for hiding this comment

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

selected could be named isSelected, so we know it's a boolean

} else if (selectedRowsCount === 0) {
this.selectAllRows = false;
} else {
this.selectAllRows = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the global comportement for tri-select box ? null is some items are selected, some are not? Because, if it's not already the selected behavior, this would require a something else than a boolean then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep checkbox component currently use "null"

}
}

toggleSelectAllRows (modelValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

currentSelectionStatus ?

Copy link
Contributor

@AxelPeter AxelPeter Jul 31, 2018

Choose a reason for hiding this comment

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

We could keep the same logic as above, toggleAllRowsSelection

@FredericEspiau
Copy link
Contributor

@frenautvh I've only commented because I feel most point would require a discussion

@AxelPeter AxelPeter requested a review from JeremyDec July 31, 2018 14:48
Copy link
Contributor

@AxelPeter AxelPeter left a comment

Choose a reason for hiding this comment

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

Some improvements needed, but seems good.
Don't forget the unit tests and the documentation :)

### Global Actions

```html:preview
<oui-datagrid rows="$ctrl.data" page-size="5" global-actions>
Copy link
Contributor

@AxelPeter AxelPeter Jul 31, 2018

Choose a reason for hiding this comment

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

Yes, selectable-rows is better :)
Don't forget to add the details in the API table below for this attribute

this._compileCell();
}

this.index = this.index || 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be in $onInit

}, []);
}

onSelectRow (index, selected) {
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case, toggleRowSelection seems more appropriate

}
}

toggleSelectAllRows (modelValue) {
Copy link
Contributor

@AxelPeter AxelPeter Jul 31, 2018

Choose a reason for hiding this comment

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

We could keep the same logic as above, toggleAllRowsSelection

Copy link
Contributor

@AxelPeter AxelPeter left a comment

Choose a reason for hiding this comment

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

@frenautvh From the staging, the first column is not fixed. Can you check it ?
Caution on your CDS builds too :)

}

this.cellScope.$watch(() => this.datagridCtrl.selectedRows[this.index], (isSelected) => {
this.cellScope.$isSelected = isSelected || false;
Copy link
Contributor

Choose a reason for hiding this comment

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

this.cellScope.$isSelected = !!isSelected is possible no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

!! is harder to read by someone not used to this js "trick" but yes it would fit the job

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok :)

@frenautvh
Copy link
Contributor Author

@antleblanc @euhmeuh @FredericEspiau
Thanks for your comments, i know that there is more than one way to do one thing. What i don't know is why you choose your way over mine and that's the interesting part so please tell me why when you're suggesting alternatives! :) Otherwise we could comment every line of code and never make a change because everyone is right

@AxelPeter
Copy link
Contributor

AxelPeter commented Aug 3, 2018

@frenautvh
The right way is the way that works and that keeps the same logic in the project (naming, structure, etc.). That's why I'm here to take the lead on those decisions.
You could still add comments on your choices to explain why you do it that way, and why it's the better choice in your opinion ;)

@antleblanc @euhmeuh @FredericEspiau @JeremyDec
Can you take a position on your review ?
Without approve or request changes label, we can't know your position on your comments. Even if it's for discussing :)
For comments that are not really important, or that haven't an impact on your review, I propose you to add a label (optional) before each comment.

@ovh-ux ovh-ux deleted a comment from ovh-cds Aug 3, 2018
@ovh-ux ovh-ux deleted a comment from ovh-cds Aug 3, 2018
@AxelPeter AxelPeter changed the title feat(oui-datagrid): add global actions feat(oui-datagrid): add selectable rows Aug 3, 2018
@frenautvh
Copy link
Contributor Author

@AxelPeter I'm targeting that kind of comments :

  • "Can't this contain the actual rows instead of an array of booleans ? Or something to identify the rows ?"
  • "this.cellScope.$isSelected = !!isSelected is possible no ?"
  • "We could react to the checkbox's on-change event and add the corresponding row to the array of rows."
    I know we could do that but WHY would we? I think the reviewer should at least gives an hint otherwise it's just noise in the PR review.

Example :

  • "We could react to the checkbox's on-change event because in order to avoids to generate array of row each time the binding is updated"
  • "You could do this.cellScope.$isSelected = !!isSelected; i think the syntax is more readable"

@AxelPeter
Copy link
Contributor

AxelPeter commented Aug 3, 2018

I know and I agree, that's why I suggest some methods to everybody for working together (it works with our previous team) ;)

@AxelPeter AxelPeter merged commit 08d0841 into develop Aug 3, 2018
@AxelPeter AxelPeter deleted the feat/datagrid-global-actions branch August 3, 2018 12:57
@AxelPeter AxelPeter mentioned this pull request Aug 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Development

Successfully merging this pull request may close these issues.

5 participants