From 97761f75026ec8f45928f0e9213ead3dba708a9e Mon Sep 17 00:00:00 2001 From: Lalit Kishore R Date: Mon, 23 Nov 2026 18:23:58 +0000 Subject: [PATCH] Fix subgroups disappearing when added from the All entries context menu (#17803) ### Summary In a new library, right-clicking **All entries** and choosing **Add subgroup** could show a success message even though the subgroup was missing from the tree and the saved library. The action now adds the subgroup to the current **All entries** node after the dialog closes. ### Steps to test 1. Create a new library, add the example entry, and select it. 2. Right-click **All entries** and choose **Add subgroup**. Enter `a` and leave **Include selected entries in created group** checked. ![Add subgroup dialog with the name a and the selected entry included](https://raw.githubusercontent.com/doraem-on/jabref/e43d5ce813cef42128243b5294040c24735e1447/01-add-subgroup.png) 3. Click **OK**. The subgroup should appear under **All entries** with one entry. ![The subgroup a appears with one entry](https://raw.githubusercontent.com/doraem-on/jabref/e43d5ce813cef42128243b5294040c24735e1447/02-subgroup-created.png) 4. Save the library, close the tab, and reopen the file. The subgroup should still contain one entry. ![The reopened library shows the subgroup a with one entry](https://raw.githubusercontent.com/doraem-on/jabref/e43d5ce813cef42128243b5294040c24735e1447/03-library-reopened.png) Verified on macOS. The group tree regression test and GUI Checkstyle checks passed. The test passes the old root to the action after rebuilding the tree and checks the children of the current root. ### Related issues and pull requests Closes #17764. ### AI usage OpenAI GPT-6 assisted with the implementation, regression test under my direction. I ran local verification. I manually reviewed and verified the code ### Checklist - [x] I own the copyright of the code submitted and I license it under the [MIT license](https://github.com/JabRef/jabref/blob/main/LICENSE) - [x] If AI tools were used, I disclosed them in the "AI usage" section and reviewed, understood, and take full ownership of all AI-generated code - [x] I manually tested my changes in running JabRef (always required) - [x] I added JUnit tests for changes (if applicable) - [x] I added screenshots in the PR description (if change is visible to the user) - [x] I added **one sentence (max 20 words)** to `CHANGELOG.md` describing the change from the user's point of view (if the change is visible to the user) - [x] I checked the [user documentation](https://docs.jabref.org/) for up to dateness and submitted a pull request to our [user documentation repository](https://github.com/JabRef/user-documentation/tree/main/en) (cherry picked from commit 9d5bd28f7cfb76fd68c3a89f7590731e9216da48) --- CHANGELOG.md | 1 + .../jabref/gui/groups/GroupTreeViewModel.java | 12 +++++++++--- .../gui/groups/GroupTreeViewModelTest.java | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d4fb5ff2867..9cc2ed1e67b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ Note that this project **does not** adhere to [Semantic Versioning](https://semv - We fixed an issue where back navigation selected a deleted entry instead of skipping it. [#17353](https://github.com/JabRef/jabref/issues/17353) - We fixed the linked file tooltip showing the old file name after renaming or moving the file. [#9277](https://github.com/JabRef/jabref/issues/9277) - We fixed an issue where citationcount, day, and dayfiled columns were sorted alphabetically instead of numerically. [#17459](https://github.com/JabRef/jabref/issues/17459) +- We fixed subgroups disappearing after adding them from the "All entries" context menu in a new library. [#17764](https://github.com/JabRef/jabref/issues/17764) ## [6.0-beta.1] - 2026-09-21 diff --git a/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java b/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java index c3ac2cc10e66..07ee5ac3548e 100644 --- a/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java +++ b/jabgui/src/main/java/org/jabref/gui/groups/GroupTreeViewModel.java @@ -247,11 +247,17 @@ public void addNewSubgroup(GroupNodeViewModel parent, GroupDialogHeader groupDia null, groupDialogHeader)); + if (currentDatabase.filter(active -> active == database).isEmpty()) { + return; + } + + // A context menu can still refer to the old "All entries" node after the tree is rebuilt. + GroupNodeViewModel currentParent = parent.isAllEntriesGroup() ? rootGroup.get() : parent; newGroup.ifPresent(group -> recordTreeChange(Localization.lang("Add group"), _ -> { - GroupTreeNode newSubgroup = parent.addSubgroup(group); + GroupTreeNode newSubgroup = currentParent.addSubgroup(group); // [impl->req~ux.groups.create-explicit-from-selection~1] - GroupNodeViewModel newViewModel = parent.findGroupNodeViewModel(newSubgroup) - .orElseGet(() -> new GroupNodeViewModel(database, stateManager, taskExecutor, newSubgroup, localDragboard, preferences)); + GroupNodeViewModel newViewModel = currentParent.findGroupNodeViewModel(newSubgroup) + .orElseGet(() -> new GroupNodeViewModel(database, stateManager, taskExecutor, newSubgroup, localDragboard, preferences)); selectedGroups.setAll(newViewModel); // TODO: expand the parent so the new group is visible diff --git a/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java b/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java index 4ff08d3c6899..9ab13bf94dca 100644 --- a/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java +++ b/jabgui/src/test/java/org/jabref/gui/groups/GroupTreeViewModelTest.java @@ -105,6 +105,24 @@ void setUp() { groupTree = new GroupTreeViewModel(stateManager, mock(BibEntryTypesManager.class), preferences, dialogService, mock(AiService.class), new CustomLocalDragboard(), taskExecutor); } + @Test + void addSubgroupFromPreviousRootPersistsInCurrentTree() { + JavaFxExtension.invokeAndWait(() -> { + GroupNodeViewModel previousRoot = groupTree.rootGroupProperty().get(); + databaseContext.getDatabase().insertEntry(new BibEntry()); + activeDatabase.setValue(Optional.empty()); + activeDatabase.setValue(Optional.of(databaseContext)); + + try (var ignored = mockConstruction(GroupDialogView.class)) { + when(dialogService.showCustomDialogAndWait(any(GroupDialogView.class))) + .thenReturn(Optional.of(new ExplicitGroup("a", GroupHierarchyType.INDEPENDENT, ','))); + groupTree.addNewSubgroup(previousRoot, GroupDialogHeader.SUBGROUP); + } + }); + + assertEquals(List.of("a"), childNames()); + } + @Test void rootGroupIsAllEntriesByDefault() { AllEntriesGroup allEntriesGroup = new AllEntriesGroup("All entries");