Skip to content

Commit 25aa431

Browse files
HDS-4273 Fix issue with selectableRows state when model updates
1 parent 735a63f commit 25aa431

File tree

1 file changed

+18
-5
lines changed
  • packages/components/src/components/hds/table

1 file changed

+18
-5
lines changed

packages/components/src/components/hds/table/index.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default class HdsTable extends Component<HdsTableSignature> {
126126
} else {
127127
// We return a default key to cause an update operation instead of replacement when the model changes to side-step
128128
// a bug in Ember which would cause the table to lose its selection state
129-
return this.args.identityKey ?? 'hds-table-key';
129+
return this.args.identityKey ?? '@identity';
130130
}
131131
}
132132

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

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

316-
this._selectableRows = this._selectableRows.filter(
317-
(row): boolean => row.selectionKey !== selectionKey
316+
// Fix for selectableRows state not being maintained properly when model updates:
317+
// Delete the first row with the given selction key you find from the selectableRows array
318+
// Search for the index of the row to delete. If found, delete it.
319+
// (Fixes issue of not rows not being properly selectable including "select all" functionality)
320+
const rowToDeleteIndex = this._selectableRows.findIndex(
321+
(row): boolean => row.selectionKey === selectionKey
318322
);
323+
324+
if (rowToDeleteIndex > -1) {
325+
this._selectableRows.splice(rowToDeleteIndex, 1);
326+
}
327+
328+
// ORIGINAL:
329+
// this._selectableRows = this._selectableRows.filter(
330+
// (row): boolean => row.selectionKey !== selectionKey
331+
// );
319332
this.setSelectAllState();
320333
}
321334

0 commit comments

Comments
 (0)