Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Header cell with unit tests, styling, and new interfaces #8

Merged
merged 8 commits into from
Mar 14, 2017

Conversation

pottedmeat
Copy link
Contributor

Type: feature

The following has been addressed in the PR:

  • There is a related issue
  • All code matches the style guide
  • Unit or Functional tests are included in the PR

Description:

Adds the HeaderCell widget with styling and unit tests. Adds interfaces used by the HeaderCell properties.

@codecov-io
Copy link

codecov-io commented Feb 24, 2017

Codecov Report

Merging #8 into master will increase coverage by 13.35%.
The diff coverage is 78.57%.

@@             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
Impacted Files Coverage Δ
src/HeaderCell.ts 78.57% <78.57%> (ø)
_build/src/styles/headerCell.css.js 66.66% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 759acd7...e20b1e2. Read the comment docs.

@dylans dylans added this to the 2017.02 milestone Feb 24, 2017
export interface HeaderCellProperties extends ThemeableProperties, HasColumn, HasSortDetail, HasSortEvent { }

@theme(headerCellClasses)
class HeaderCell extends ThemeableMixin(RegistryMixin(WidgetBase))<HeaderCellProperties> {
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup

.sortArrow {
width: 16px;
height: 16px;
background-image: url('images/ui-icons_222222_256x240.png');
Copy link
Contributor

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?

sortDetail
} = this.properties;

const classes = [ headerCellClasses.cell ];
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

.sortArrow {
width: 16px;
height: 16px;
background-image: url('images/ui-icons_222222_256x240.png');
Copy link
Member

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';
Copy link
Member

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.

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'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.

@dylans dylans modified the milestones: 2017.02, 2017.03 Mar 1, 2017
onSortRequest
} = this.properties;

if (onSortRequest && (column.sortable || !column.hasOwnProperty('sortable'))) {
Copy link
Member

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?

Copy link

@maier49 maier49 left a 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)
Copy link

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link

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.

sortDetail && !sortDetail.descending ? headerCellClasses.sortArrowUp : null
];

const onclick = (onSortRequest && (column.sortable || !column.hasOwnProperty('sortable'))) ? { onclick: this.onSortRequest } : {};
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Member

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.

Copy link
Contributor Author

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';
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


import * as headerCellClasses from './styles/headerCell.css';

export interface HeaderCellProperties extends ThemeableProperties, HasColumn, HasSortDetail, HasSortEvent { }
Copy link
Contributor

Choose a reason for hiding this comment

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

{ } => {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


const sortClasses = [
sortDetail ? headerCellClasses.sortArrow : null,
sortDetail && sortDetail.descending ? headerCellClasses.sortArrowDown : null,
Copy link
Contributor

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

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 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.

Copy link
Contributor

@msssk msssk left a 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.

@pottedmeat pottedmeat merged commit 937b80a into dojo:master Mar 14, 2017
@pottedmeat pottedmeat deleted the initial-header-cell branch March 14, 2017 19:31
@agubler
Copy link
Member

agubler commented Mar 15, 2017

@MSSK how do you plan on supporting the 1% where the distinction between field and id does matter?

@msssk
Copy link
Contributor

msssk commented Mar 15, 2017

@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 get method that returns the desired value. And honestly, it's probably well under 1% of the time that someone might want to do this. I can't even recall ever seeing it in ~5 years of using dgrid - anyone else?

@agubler
Copy link
Member

agubler commented Mar 15, 2017

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.

@msssk
Copy link
Contributor

msssk commented Mar 15, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants