FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

refactor: fire select/preview events only for final segment during pa… · patternfly-java/patternfly-java@81ef43f · GitHub

Commit 81ef43f

Browse files
committed
refactor: fire select/preview events only for final segment during path restoration
Finder.select(FinderPath) previously fired SelectHandler and PreviewHandler events for every intermediate segment. Now events are suppressed during the sequential walk and fired once at the end for the deepest resolved item. Also adds SelectHandler notification to ArrowLeft keyboard navigation, which previously only fired PreviewHandler when re-focusing an already-selected item in the previous column.
1 parent 90d922c commit 81ef43f

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

‎extensions/finder/src/main/java/org/patternfly/extension/finder/Finder.java‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,10 @@ public Promise<ResolvedFinderPath> select(String path) {
217217
* already be present in this finder. Each item selection may trigger creation and async loading of the next column (via
218218
* {@link FinderItem#nextColumn(java.util.function.Supplier)}).
219219
* <p>
220-
* Select and preview events are fired for every item in the path. If a segment cannot be resolved (column not found, item
221-
* not found after loading), the promise resolves with a partial {@link ResolvedFinderPath} containing only the successfully
222-
* selected segments.
220+
* Select and preview events are fired only for the deepest successfully resolved item, not for intermediate segments. If a
221+
* segment cannot be resolved (column not found, item not found after loading), the promise resolves with a partial
222+
* {@link ResolvedFinderPath} containing only the successfully selected segments, and events are fired for the last resolved
223+
* item.
223224
*
224225
* @param path the finder path to select
225226
* @return a {@link Promise} that resolves with the {@link ResolvedFinderPath} of successfully selected items
@@ -234,7 +235,10 @@ public Promise<ResolvedFinderPath> select(FinderPath path) {
234235
tasks.add(ctx -> selectSegment(segment.columnId, segment.itemId, ctx));
235236
}
236237
return sequential(context, tasks)
237-
.then(ctx -> Promise.resolve(path()));
238+
.then(ctx -> {
239+
fireSelectAndPreview();
240+
return Promise.resolve(path());
241+
});
238242
}
239243

240244
@Override
@@ -297,6 +301,24 @@ private void internalAdd(FinderColumn column) {
297301
aur.added(column);
298302
}
299303

304+
private void fireSelectAndPreview() {
305+
FinderColumn lastColumn = null;
306+
FinderItem lastItem = null;
307+
for (FinderColumn column : items.values()) {
308+
FinderItem selected = column.selectedItem();
309+
if (selected != null) {
310+
lastColumn = column;
311+
lastItem = selected;
312+
} else {
313+
break;
314+
}
315+
}
316+
if (lastColumn != null && lastItem != null) {
317+
lastColumn.fireSelect(lastItem);
318+
lastItem.previewItem(this, lastColumn, lastItem);
319+
}
320+
}
321+
300322
private Promise<FlowContext> selectSegment(String columnId, String itemId, FlowContext context) {
301323
if (context.get(STOP_SELECT_KEY) != null) {
302324
return context.resolve();
@@ -317,12 +339,11 @@ private Promise<FlowContext> selectSegment(String columnId, String itemId, FlowC
317339
context.set(STOP_SELECT_KEY, true);
318340
return context.resolve();
319341
}
320-
column.select(item);
342+
column.select(item, true, false);
321343
FinderColumn nextColumn = item.supplyNextColumn();
322344
if (nextColumn != null) {
323345
internalAdd(nextColumn);
324346
}
325-
item.previewItem(this, column, item);
326347
return context.resolve();
327348
});
328349
}
@@ -396,6 +417,10 @@ private void handleKeydown(KeyboardEvent event) {
396417
scrollIntoView(previousColumn);
397418
FinderItem previousItem = previousColumn.item(targetItem.dataset.get(Dataset.identifier));
398419
if (previousItem != null) {
420+
// Don't use handleClick() here — it would call Finder.select(column)
421+
// which removes all columns after this one, collapsing the navigation tree.
422+
// Instead, fire select and preview events directly for the already-selected item.
423+
previousColumn.fireSelect(previousItem);
399424
previousItem.previewItem(this, previousColumn, previousItem);
400425
}
401426
}

‎extensions/finder/src/main/java/org/patternfly/extension/finder/FinderColumn.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,12 @@ public void select(FinderItem item, boolean selected, boolean fireEvent) {
476476

477477
// ------------------------------------------------------ internal
478478

479+
void fireSelect(FinderItem item) {
480+
if (item != null) {
481+
selectHandler.forEach(sh -> sh.onSelect(new Event(""), item, true));
482+
}
483+
}
484+
479485
FinderItem findItem(String identifier) {
480486
return items.get(identifier);
481487
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL