Skip to content

Commit e40cae9

Browse files
authored
Table expander checkbox (#738)
* fix: supporting both expander and checkbox state columns * refactor: adding test * refactor: addressing review comments
1 parent d113815 commit e40cae9

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

projects/components/src/table/cells/state-parsers/table-cell-state-parser.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TableRowState } from '../../table-api';
1+
import { StatefulTableRow, TableRowState } from '../../table-api';
22
import { TableCellParser } from '../table-cell-parser';
33
import { TableCellParserBase } from '../table-cell-parser-base';
44
import { CoreTableCellParserType } from '../types/core-table-cell-parser-type';
@@ -7,8 +7,8 @@ import { CoreTableCellParserType } from '../types/core-table-cell-parser-type';
77
type: CoreTableCellParserType.State
88
})
99
export class TableCellStateParser extends TableCellParserBase<TableRowState, TableRowState, undefined> {
10-
public parseValue(cellData: TableRowState): TableRowState {
11-
return cellData;
10+
public parseValue(_: TableRowState, rowData: StatefulTableRow): TableRowState {
11+
return rowData.$$state;
1212
}
1313

1414
public parseFilterValue(): undefined {

projects/components/src/table/cells/types/core-table-cell-parser-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const enum CoreTableCellParserType {
2-
State = 'state',
32
Boolean = 'boolean',
43
Number = 'number',
4+
State = 'state',
55
String = 'string',
66
Timestamp = 'timestamp',
77
Icon = 'icon',

projects/components/src/table/data/table-cdk-data-source.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class TableCdkDataSource implements DataSource<TableRow> {
5959
.pipe(
6060
tap(() => this.loadingStateSubject.next({ loading$: NEVER })),
6161
/**
62-
* Below debouce is needed to handle multiple emission from buildChangeObservable.
62+
* Below debounce is needed to handle multiple emission from buildChangeObservable.
6363
*/
6464
debounceTime(100),
6565
mergeMap(([columnConfigs, pageEvent, filters, queryProperties, changedColumn, changedRow]) =>

projects/components/src/table/table.component.test.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ describe('Table component', () => {
306306
expectObservable(spectator.component.columnConfigs$).toBe('x', {
307307
x: [
308308
expect.objectContaining({
309-
id: '$$state',
309+
id: '$$selected',
310310
display: CoreTableCellRendererType.Checkbox,
311311
visible: true
312312
}),
@@ -371,16 +371,21 @@ describe('Table component', () => {
371371
map(columnConfigs => columnConfigs.map(columnConfig => spectator.component.isExpanderColumn(columnConfig)))
372372
)
373373
).toBe('x', {
374-
x: [true, false, false]
374+
x: [true, false, false, false]
375375
});
376376

377377
expectObservable(spectator.component.columnConfigs$).toBe('x', {
378378
x: [
379379
expect.objectContaining({
380-
id: '$$state',
380+
id: '$$expanded',
381381
display: CoreTableCellRendererType.RowExpander,
382382
visible: true
383383
}),
384+
expect.objectContaining({
385+
id: '$$selected',
386+
display: CoreTableCellRendererType.Checkbox,
387+
visible: true
388+
}),
384389
expect.objectContaining({
385390
id: 'firstId'
386391
}),

projects/components/src/table/table.component.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,15 @@ export class TableComponent
194194
private static readonly SORT_DIRECTION_URL_PARAM: string = 'sort-direction';
195195

196196
private readonly expandableToggleColumnConfig: TableColumnConfig = {
197-
id: '$$state',
197+
id: '$$expanded',
198198
width: '32px',
199199
visible: true,
200200
display: CoreTableCellRendererType.RowExpander,
201201
onClick: (row: StatefulTableRow) => this.toggleRowExpanded(row)
202202
};
203203

204204
private readonly multiSelectRowColumnConfig: TableColumnConfig = {
205-
id: '$$state',
205+
id: '$$selected',
206206
width: '32px',
207207
visible: true,
208208
display: CoreTableCellRendererType.Checkbox,
@@ -569,11 +569,15 @@ export class TableComponent
569569
}
570570

571571
private buildColumnConfigExtendeds(columnConfigs: TableColumnConfig[]): TableColumnConfigExtended[] {
572-
const stateColumns = this.hasExpandableRows()
573-
? [this.expandableToggleColumnConfig]
574-
: this.hasMultiSelect()
575-
? [this.multiSelectRowColumnConfig]
576-
: [];
572+
const stateColumns = [];
573+
574+
if (this.hasExpandableRows()) {
575+
stateColumns.push(this.expandableToggleColumnConfig);
576+
}
577+
578+
if (this.hasMultiSelect()) {
579+
stateColumns.push(this.multiSelectRowColumnConfig);
580+
}
577581

578582
return this.tableService.buildExtendedColumnConfigs(
579583
[...stateColumns, ...columnConfigs],

0 commit comments

Comments
 (0)