-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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): add row when predicate #6795
Conversation
_getRowDef(data: T, i: number): CdkRowDef<T> { | ||
if (this._rowDefs.length == 1) { return this._rowDefs.first; } | ||
|
||
let rowDef = this._rowDefs.find(def => def.when && def.when(data, i)) || this._defaultRowDef; |
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.
Could just default when
to () => false
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.
Would this mean everyone would need to include a when function when defining their rows? I figured we wanted to let them leave it off for a row and it'll be the 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.
In that case would defaulting to () => true
do the same thing? The first row with no when
will be the default, all other rows with no when
will be ignored.
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, that's fine with me. I think I was trying to catch the user's error ahead of time if they didn't provide a default. But it's not a perfect thing to catch anyways (all rows could have when but still catch 100% of cases)
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.
Righto - I remember why its needed. If we default to true, that row is already our match when we look for a row def. If we default to () => false
then it forces users to always define a when function
src/lib/table/table.spec.ts
Outdated
@@ -7,17 +7,17 @@ import {MdTableModule} from './index'; | |||
import {MdTable} from './table'; | |||
|
|||
describe('MdTable', () => { | |||
let fixture: ComponentFixture<SimpleMdTableApp>; | |||
let fixture: ComponentFixture<MdTableApp>; |
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.
- Add test case for
when
missing on multiple rows? - Add test case for using the default row def?
There's also no test now for a table that just has one row def
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.
Added test for missing when on multiple rows. Default row def is used for any case where there is no when
, e.g. SimpleCdkTableApp
Note, majority of testing for the when logic is in cdk/table.ts
. Goal of the lib/table.ts
test is to show that the MdRowDef
successfully reads the when
input and passes it on to the CdkRowDef
.
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.
LGTM
18ef7b5
to
99657e1
Compare
99657e1
to
3cb3ed4
Compare
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes #5887