Skip to content

Commit 1161a17

Browse files
committed
feat: Implement Peer State Adoption for Grid Multi-Body Row Selection (#9839)
1 parent 99b5f92 commit 1161a17

2 files changed

Lines changed: 55 additions & 7 deletions

File tree

src/selection/grid/BaseModel.mjs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,26 @@ class BaseModel extends Model {
224224
me.updateRows(recordId, silent)
225225
}
226226

227+
/**
228+
* Retrieves sibling Selection Models in a Multi-Body environment.
229+
* @returns {Neo.selection.grid.BaseModel[]}
230+
*/
231+
getActivePeers() {
232+
let me = this,
233+
container = me.view?.gridContainer,
234+
peers = [];
235+
236+
if (container) {
237+
peers = [
238+
container.bodyStart?.selectionModel,
239+
container.body?.selectionModel,
240+
container.bodyEnd?.selectionModel
241+
].filter(sm => sm && sm !== me)
242+
}
243+
244+
return peers
245+
}
246+
227247
/**
228248
* @param {Object} path
229249
* @returns {Number|String|null}
@@ -317,6 +337,22 @@ class BaseModel extends Model {
317337
return this.selectedRows.includes(recordId)
318338
}
319339

340+
/**
341+
* @param {Neo.component.Base} component
342+
*/
343+
register(component) {
344+
super.register(component);
345+
346+
let me = this,
347+
peers = me.getActivePeers();
348+
349+
// Peer State Adoption: if siblings are already initialized, natively
350+
// adopt their state references to enforce a single state truth globally.
351+
if (peers.length > 0) {
352+
me.selectedRows = peers[0].selectedRows
353+
}
354+
}
355+
320356
/**
321357
* @param {Number|String} recordId
322358
* @param {Boolean} [silent=false]

src/selection/grid/RowModel.mjs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,20 @@ class RowModel extends BaseModel {
2727
*
2828
*/
2929
addDomListener() {
30-
let me = this;
30+
let me = this,
31+
target = me.view.gridContainer || me.view.parent;
3132

32-
me.view.parent.on('rowClick', me.onRowClick, me)
33+
target.on('rowClick', me.onRowClick, me)
3334
}
3435

3536
/**
3637
* @param args
3738
*/
3839
destroy(...args) {
39-
let me = this;
40+
let me = this,
41+
target = me.view.gridContainer || me.view.parent;
4042

41-
me.view.parent.un('rowClick', me.onRowClick, me);
43+
target.un('rowClick', me.onRowClick, me);
4244

4345
super.destroy(...args)
4446
}
@@ -91,14 +93,21 @@ class RowModel extends BaseModel {
9193
}
9294

9395
/**
94-
* @param {Object} data
96+
* @param {Object} event
9597
*/
96-
onRowClick({data}) {
98+
onRowClick(event) {
9799
let me = this,
98100
{view} = me,
99-
record = me.getRecord(data.path),
101+
{data} = event,
102+
record = event.record || me.getRecord(data.path),
100103
recordId;
101104

105+
// In a multi-body architecture, ensure we only toggle the state once per click
106+
// by restricting the state mutation to the specific body that fired the event.
107+
if (event.body && event.body !== view) {
108+
return
109+
}
110+
102111
if (record) {
103112
if (me.hasAnnotations(record)) {
104113
me.updateAnnotations(record)
@@ -107,6 +116,9 @@ class RowModel extends BaseModel {
107116

108117
me.toggleRowSelection(recordId);
109118

119+
// Sync visual state to sibling sub-grids
120+
me.getActivePeers().forEach(peer => peer.updateRows(recordId));
121+
110122
view.fire(me.isSelectedRow(recordId) ? 'select' : 'deselect', {record})
111123
}
112124
}

0 commit comments

Comments
 (0)