-
Notifications
You must be signed in to change notification settings - Fork 12
Header cell with unit tests, styling, and new interfaces #8
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8 +/- ##
===========================================
+ Coverage 51.72% 65.07% +13.35%
===========================================
Files 4 6 +2
Lines 29 63 +34
Branches 1 9 +8
===========================================
+ Hits 15 41 +26
- Misses 14 16 +2
- Partials 0 6 +6
Continue to review full report at Codecov.
|
src/HeaderCell.ts
Outdated
export interface HeaderCellProperties extends ThemeableProperties, HasColumn, HasSortDetail, HasSortEvent { } | ||
|
||
@theme(headerCellClasses) | ||
class HeaderCell extends ThemeableMixin(RegistryMixin(WidgetBase))<HeaderCellProperties> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
base type as const
- same as row?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup
src/styles/headerCell.css
Outdated
.sortArrow { | ||
width: 16px; | ||
height: 16px; | ||
background-image: url('images/ui-icons_222222_256x240.png'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just set content
to use a unicode arrow char (like ComboBox does) for now?
src/HeaderCell.ts
Outdated
sortDetail | ||
} = this.properties; | ||
|
||
const classes = [ headerCellClasses.cell ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could do a ternary here and return null for sortable = false. Classes function deals with that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent. Thanks
v('span', [ column.label || column.id ]), | ||
sortDetail && sortDetail.columnId === key ? v('div', { | ||
role: 'presentation', | ||
classes: this.classes(...sortClasses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here re building up the classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
src/styles/headerCell.css
Outdated
.sortArrow { | ||
width: 16px; | ||
height: 16px; | ||
background-image: url('images/ui-icons_222222_256x240.png'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should be adding this png sprite file. We should use unicode as @rishson suggested until we've created an icon widget / chosen an icon approach for widgets
@@ -1 +1,2 @@ | |||
@import 'headerCell.css'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're going to offer up a dgrid.css
file for people using dgrid
outside of our cli-webpack build then you need to ensure you add an exclusion rule for it in your gruntfile otherwise it will be built into a separate css-module and the generated classes will mean zero.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how to exclude this from the poscss task. Right now I'm using the pattern from dojo/widgets that just overwrites the file with its original version.
src/HeaderCell.ts
Outdated
onSortRequest | ||
} = this.properties; | ||
|
||
if (onSortRequest && (column.sortable || !column.hasOwnProperty('sortable'))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think it would be better to not attach the handler if the column is not sortable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just one question.
|
||
onSortRequest({ | ||
columnId: key, | ||
descending: Boolean(sortDetail && sortDetail.columnId === key && !sortDetail.descending) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
descending
is getting set to !sortDetail.descending
, is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't seem like it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is correct. It'll reverse the current sort direction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case the naming seems a little confusing at first glance. Maybe I just need to look at the overall code a bit more for it to make sense.
src/HeaderCell.ts
Outdated
sortDetail && !sortDetail.descending ? headerCellClasses.sortArrowUp : null | ||
]; | ||
|
||
const onclick = (onSortRequest && (column.sortable || !column.hasOwnProperty('sortable'))) ? { onclick: this.onSortRequest } : {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reads really difficultly, I think worked it out that !column.hasOwnProperty('sortable')
is effectively saying all columns are sortable by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can split this out to make it clearer then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched this to just column.sortable !== false
@@ -0,0 +1,60 @@ | |||
import WidgetBase from '@dojo/widget-core/WidgetBase'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/HeaderCell.ts
Outdated
|
||
import * as headerCellClasses from './styles/headerCell.css'; | ||
|
||
export interface HeaderCellProperties extends ThemeableProperties, HasColumn, HasSortDetail, HasSortEvent { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ }
=> {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/HeaderCell.ts
Outdated
|
||
const sortClasses = [ | ||
sortDetail ? headerCellClasses.sortArrow : null, | ||
sortDetail && sortDetail.descending ? headerCellClasses.sortArrowDown : null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think clarity is retained if this line and the following are collapsed into
sortDetail && sortDetail.descending ? headerCellClasses.sortArrowDown : headerClasses.sortArrowUp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these all depend on sortDetail, I did a ternary that either creates this array or an empty array, then used your ternary approach. It does read much better. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several modules could be improved by using consistent import order per the style guide:
https://github.com/dojo/meta/blob/master/STYLE.md#ordering
An issue not specific to this PR:
I'm not convinced of the need for an id
property on columns. It seems like a confusing middle-man for field
. If 99% of the time field
is just going to end being unspecified and defaulting to id
, then let's drop id
and use field
instead. The 1% of cases where the distinction between id
and field
matters can be handled without complicating the 99% of cases where it does not matter.
@MSSK how do you plan on supporting the 1% where the distinction between field and id does matter? |
@agubler The same way dgrid always has: you specify a column definition with an arbitrary field name that doesn't correspond to a field in the data, and provide a |
That would assume the same dgrid1 mechanisms, I just don't want to get to a position where something cannot be supported because there was the consensus that it would never need to be. |
I'm optimistic that #12 will be resolved in a way that provides similar mechanisms to dgrid 1. We definitely want to maintain flexibility and extensibility. I'm just proposing a way of achieving that while keeping the API simple and user-friendly. |
Type: feature
The following has been addressed in the PR:
Description:
Adds the HeaderCell widget with styling and unit tests. Adds interfaces used by the HeaderCell properties.