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(stark-ui): initial implementation of Stark Table component (supporting nested data, sorting and filtering) #501

Merged

Conversation

christophercr
Copy link
Collaborator

@christophercr christophercr commented Jul 12, 2018

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[X] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #406

What is the new behavior?

New stark-table component integrated in stark-ui package.

Does this PR introduce a breaking change?

[ ] Yes
[X] No

@christophercr
Copy link
Collaborator Author

I've added some interfaces related to the Action bar but those should be removed once the PR about the Action Bar component is merged.

So please don't merge this PR yet, I have to rebase it as soon as the other PR is merged.

@christophercr
Copy link
Collaborator Author

I've updated #406 to include the list of features that should be supported.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 93.533% when pulling d2ad745 on christophercr:feature/stark-table into 765e5ef on NationalBankBelgium:master.

@christophercr christophercr force-pushed the feature/stark-table branch 3 times, most recently from fd73d6a to ee07179 Compare July 13, 2018 14:52
@christophercr
Copy link
Collaborator Author

I've rebased this PR so the action bar interfaces are removed from the Table folder ;)

* Whether the column is sortable or not. Default: true
*/
@Input() public sortable: boolean = false;
@Input() public sortPriority: number;
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add some documentation for the bindings ? 😊

<th mat-header-cell *matHeaderCellDef [ngClass]="{'sortable': sortable, 'filtering': filterValue}">
<div class="header-cell-content">
<div [ngSwitch]="sortDirection" class="sort-header" (click)="onSortChange()">
<span>{{ headerLabel || name }}</span>
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 this should be translated as it was the case in the old Stark.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not for now, translation is not part of this PR, as I mentioned in the description, this is only about nested data, sorting and filtering, otherwise this PR will be huge.

Translation and other features will be part of another PR 😉

Copy link
Member

Choose a reason for hiding this comment

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

Ok. That means we'll have to be really careful to not forget anything in the next PR which will contain translations

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed

(keyup)="onFilterChange()">
</mat-form-field>
<button mat-icon-button (click)="onClearFilter()">
<mat-icon svgIcon="close"></mat-icon>
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a tooltip here ?

<span *ngIf="sortPriority < 1000 && sortDirection" class="priority">{{ sortPriority }}</span>
</div>
<button *ngIf="filterable" class="button-filter" [matMenuTriggerFor]="filterMenu" mat-icon-button>
<mat-icon svgIcon="filter"></mat-icon>
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a tooltip ?

* Name of the property that will be the source of the column.
*/
@Input()
public get name(): string {
Copy link
Member

Choose a reason for hiding this comment

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

I guess this implementation replaces ngOnChanges(simplesChanges: SimpleChanges).
Is it working in the same way ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, it has the same functionality. It is done like this for the moment because this is just the initial implementation of the table, we will see if we need to refactor this when we implement the rest of functionalities..

<table #matTable mat-table [dataSource]="dataSource" [ngClass]="{'multi-sorting': isMultiSorting}">
<ng-container *ngIf="multiselect" matColumnDef="select">
<th mat-header-cell *matHeaderCellDef>
<mat-checkbox (change)="$event ? masterToggle() : null" [checked]="selection.hasValue() && isAllSelected()"
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a tooltip ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

?? where exactly?

Copy link
Member

Choose a reason for hiding this comment

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

On the th or, ideally, on the mat-checkbox element. But I'm not sure we can add tooltip directly on mat-checkbox component

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see, ok, I'll add it 😉

<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>

<mat-paginator [pageSizeOptions]="[5, 10, 20]" showFirstLastButtons></mat-paginator>
Copy link
Member

Choose a reason for hiding this comment

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

Previously, it was possible to customize pagination options as those ones. Could you please put this back ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Nop, pagination is not part of this PR, as I mentioned in the description, this is only about nested data, sorting and filtering. Pagination and other features will be part of another PR 😉

Copy link
Member

Choose a reason for hiding this comment

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

Okido

import { FormsModule } from "@angular/forms";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { MatButtonModule } from "@angular/material/button";
import { MatCheckboxModule } from "@angular/material/checkbox";
Copy link
Member

Choose a reason for hiding this comment

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

Why import every Angular Material elements separately instead of together as this:

import {
  MatCheckboxModule,
  MatButtonModule,
  ...
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good question, in fact I am not sure whether there are still some issues regarding the "tree-shaking" of the material components. See angular/components#4137 and angular/components#6210.

I think we can do some checks to verify it, but I would prefer to do it in another PR...

Copy link
Member

Choose a reason for hiding this comment

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

Okido. My question is there because we didn't split the imports in other UI modules. But I guess we can merge them 😊 But let's do in another PR if you prefer

@Input() public filter: StarkTableFilter;

/**
* FIXME: should be "true" by default
Copy link
Member

Choose a reason for hiding this comment

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

If it should be true, what are we waiting for setting it as true?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, wrong FIXME, I'll remove it 😉

}
}

if (changes["filter"]) {
Copy link
Member

@SuperITMan SuperITMan Jul 16, 2018

Choose a reason for hiding this comment

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

Could we move this in the @Input declaration as it is the case in column component (with get/set) ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Why? In this ngOnChanges we handle the updates of 3 inputs: data, orderProperties and filter. Whereas in the ColumnComponent we only handle 1 input: name. In any case, as I said in the other comment of the ColumnComponent, we might refactor the getter/setter in case we need it. But this ngOnChanges block should not change in my opinion

Copy link
Member

Choose a reason for hiding this comment

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

Okido. Let's keep it as this so 😊

@@ -39,6 +39,7 @@
"@angular/common": "6.x",
"@angular/compiler": "6.x",
"@angular/core": "6.x",
"@angular/flex-layout": "6.x",
Copy link
Contributor

Choose a reason for hiding this comment

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

Flex Layout should not be used

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Indeed, it is not yet used. I'll remove it so we will add it in another PR once we really need it 😉

* @param obj2 - Second object in the comparison
*/
@Input() public compareFn?: ((obj1: any, obj2: any) => number);
@Input() public dataAccessor?: ((data: any, name: string) => string); // TODO: really needed?
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing JSDoc

* @param columnName - The column that the cell belongs to
*/
@Input() public cellFormatter?: ((value: any, row?: any, columnName?: string) => string);
@Input() public sortDirection: StarkTableColumnSortingDirection;
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing JSDoc

* Use "\*" and "\?" to match exactly the characters "*" and "?"
*/
@Input() public filterValue: string;
@Input() public headerLabel: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing JSDoc

* Whether the column is sortable or not. Default: true
*/
@Input() public sortable: boolean = false;
@Input() public sortPriority: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing JSDoc

*/
@Input() public sortable: boolean = false;
@Input() public sortPriority: number;
@Input() public visibility: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing JSDoc

@Input() public sortPriority: number;
@Input() public visibility: number;

@Output() public filterChanged: EventEmitter<StarkTableColumnComponent> = new EventEmitter<StarkTableColumnComponent>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing JSDoc

@Input() public visibility: number;

@Output() public filterChanged: EventEmitter<StarkTableColumnComponent> = new EventEmitter<StarkTableColumnComponent>();
@Output() public sortChanged: EventEmitter<StarkTableColumnComponent> = new EventEmitter<StarkTableColumnComponent>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing JSDoc

.stark-table table {
border-radius: map-get($theme, border-radius);
}
}
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 those styles can be removed. As we discussed, we will only provided styles related to the color and font of the component in the theme SCSS.
For other styles, code should be placed in the _table.component.scss

In this specific case, we won't provide any border radius theme variable. If we want to change the angular material default radius, we should then put our style in the _table.component.scss. The end user can then either use it or not by importing this file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I'll remove them 😉

StarkTableMultisortDialogComponent,
StarkTableMultisortDialogData
>(StarkTableMultisortDialogComponent, {
width: "500px",
Copy link
Contributor

Choose a reason for hiding this comment

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

We should try to set this width through the SCSS, shall we create a ticket for that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok. A ticket is not necessary, I'll fix it 😉

@christophercr
Copy link
Collaborator Author

christophercr commented Jul 16, 2018

@catlabs @SuperITMan I've updated this PR. Apart from the changes for yout remarks, I've added a demo page in the showcase for the Table component ;)

Could you please have a look and re-review this PR?

@christophercr christophercr removed the request for review from RobbyDeLaet July 16, 2018 10:59
@SuperITMan SuperITMan merged commit 9cbceb7 into NationalBankBelgium:master Jul 16, 2018
@christophercr christophercr deleted the feature/stark-table branch July 16, 2018 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants