Skip to content

Commit

Permalink
HDS-4273 Fix issue with selectableRows state when model updates
Browse files Browse the repository at this point in the history
  • Loading branch information
KristinLBradley committed Jan 16, 2025
1 parent 735a63f commit 25aa431
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions packages/components/src/components/hds/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class HdsTable extends Component<HdsTableSignature> {
} else {
// We return a default key to cause an update operation instead of replacement when the model changes to side-step
// a bug in Ember which would cause the table to lose its selection state
return this.args.identityKey ?? 'hds-table-key';
return this.args.identityKey ?? '@identity';
}
}

Expand Down Expand Up @@ -295,7 +295,7 @@ export default class HdsTable extends Component<HdsTableSignature> {
console.log(
`[${this.args.caption}] Did insert row checkbox`,
selectionKey,
this._selectableRows.map((row) => row.selectionKey)
this._selectableRows.map((row): string => row.selectionKey)
);

if (selectionKey) {
Expand All @@ -310,12 +310,25 @@ export default class HdsTable extends Component<HdsTableSignature> {
console.log(
`[${this.args.caption}] Will destroy row checkbox`,
selectionKey,
this._selectableRows.map((row) => row.selectionKey)
this._selectableRows.map((row): string => row.selectionKey)
);

this._selectableRows = this._selectableRows.filter(
(row): boolean => row.selectionKey !== selectionKey
// Fix for selectableRows state not being maintained properly when model updates:
// Delete the first row with the given selction key you find from the selectableRows array
// Search for the index of the row to delete. If found, delete it.
// (Fixes issue of not rows not being properly selectable including "select all" functionality)
const rowToDeleteIndex = this._selectableRows.findIndex(
(row): boolean => row.selectionKey === selectionKey
);

if (rowToDeleteIndex > -1) {
this._selectableRows.splice(rowToDeleteIndex, 1);
}

// ORIGINAL:
// this._selectableRows = this._selectableRows.filter(
// (row): boolean => row.selectionKey !== selectionKey
// );
this.setSelectAllState();
}

Expand Down

0 comments on commit 25aa431

Please sign in to comment.