-
Notifications
You must be signed in to change notification settings - Fork 261
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
[ACA-3368] Update datatable columns when presetColumn schema changes #5732
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ import { DataTableAdapter } from '../../data/datatable-adapter'; | |
import { DataTableRowComponent } from './datatable-row.component'; | ||
|
||
import { ObjectDataRow } from '../../data/object-datarow.model'; | ||
import { ObjectDataColumn } from '../../data/object-datacolumn.model'; | ||
import { ObjectDataTableAdapter } from '../../data/object-datatable-adapter'; | ||
import { DataCellEvent } from './data-cell.event'; | ||
import { DataRowActionEvent } from './data-row-action.event'; | ||
|
@@ -244,6 +245,15 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck, | |
return; | ||
} | ||
|
||
if (this.isPropertyChanged(changes['columns'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we rewrite it like
|
||
if (this.isTableEmpty()) { | ||
this.initTable(); | ||
} else { | ||
this.setTableColumns(changes['columns'].currentValue); | ||
} | ||
return; | ||
} | ||
|
||
if (changes.selectionMode && !changes.selectionMode.isFirstChange()) { | ||
this.resetSelection(); | ||
this.emitRowSelectionEvent('row-unselect', null); | ||
|
@@ -280,6 +290,10 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck, | |
return rows.map((row) => new ObjectDataRow(row, row.isSelected)); | ||
} | ||
|
||
convertToColumnsData(columns: any []): ObjectDataColumn[] { | ||
return columns.map((column) => new ObjectDataColumn(column)); | ||
} | ||
|
||
convertToDataSorting(sorting: any[]): DataSorting | null { | ||
if (sorting && sorting.length > 0) { | ||
return new DataSorting(sorting[0], sorting[1]); | ||
|
@@ -366,7 +380,16 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck, | |
private setTableRows(rows: any[]) { | ||
if (this.data) { | ||
this.resetSelection(); | ||
this.data.setRows(this.convertToRowsData(rows)); | ||
const rowsData = this.convertToRowsData(rows); | ||
this.data.setRows(rowsData); | ||
} | ||
} | ||
|
||
private setTableColumns(columns: any[]) { | ||
if (this.data) { | ||
this.resetSelection(); | ||
const columnsData = this.convertToColumnsData(columns); | ||
this.data.setColumns(columnsData); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -437,6 +437,14 @@ describe('ProcessInstanceListComponent', () => { | |
|
||
component.ngOnChanges({'processInstanceId': change}); | ||
}); | ||
|
||
it('should update columns when presetColumn schema changes', () => { | ||
component.ngAfterContentInit(); | ||
component.columns = []; | ||
const presetColumnChange = new SimpleChange(null, 'fakeProcessCustomSchema', false); | ||
component.ngOnChanges({ 'presetColumn': presetColumnChange }); | ||
expect(component.columns).toEqual(component.mergeJsonAndHtmlSchema()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't get it. |
||
}); | ||
}); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -533,6 +533,14 @@ describe('TaskListComponent', () => { | |
responseText: JSON.stringify(fakeGlobalTask) | ||
}); | ||
}); | ||
|
||
it('should update columns when presetColumn schema changes', () => { | ||
component.ngAfterContentInit(); | ||
component.columns = []; | ||
const presetColumnChange = new SimpleChange(null, 'fakeCustomSchema', false); | ||
component.ngOnChanges({ 'presetColumn': presetColumnChange }); | ||
expect(component.columns).toEqual(component.mergeJsonAndHtmlSchema()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as before |
||
}); | ||
}); | ||
|
||
it('should show the updated list when pagination changes', async(() => { | ||
|
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 use column-1 column-2 to make clear what we are testing?