Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Add JabRef suggested groups" #12746

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

gepetton
Copy link
Contributor

Closes (#12659)

This PR resolves #12659 by adding a "Add JabRef suggested groups" option to the "All entries" context menu, which appends the groups "Entries without linked files" and "Entries without groups" to the list if they don’t already exist, and disables the option when both are present; it includes the logic and UI implementation, unit tests covering all cases (no groups, one group, both existing), and an update to CHANGELOG.md .

스크린샷 2025-03-16 오후 6 14 34 스크린샷 2025-03-16 오후 6 16 32 스크린샷 2025-03-16 오후 6 16 08

Mandatory checks

  • I own the copyright of the code submitted and I licence it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (for UI changes)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

Add new feature to automatically create useful suggested groups:
- "Entries without linked files" group to find entries missing file attachments
- "Entries without groups" group to find entries not assigned to any group

The feature is accessible through context menu on the "All entries" group.

Add comprehensive test cases that verify:
- Groups are correctly created with search expressions "file !=~.*" and "groups !=~.*"
- Duplicate groups are not created when the feature is used multiple times
- Only missing groups are added when some suggested groups already exist
- Both scenarios are tested: adding missing "files" group and missing "groups" group
- Changes are properly written to metadata
- Selected groups are updated after adding suggested groups

Add required localization strings to support this feature.
Add new feature to automatically create useful suggested groups:
- "Entries without linked files" group to find entries missing file attachments
- "Entries without groups" group to find entries not assigned to any group

The feature is accessible through context menu on the "All entries" group.

Add comprehensive test cases that verify:
- Groups are correctly created with search expressions "file !=~.*" and "groups !=~.*"
- Duplicate groups are not created when the feature is used multiple times
- Only missing groups are added when some suggested groups already exist
- Both scenarios are tested: adding missing "files" group and missing "groups" group
- Changes are properly written to metadata
- Selected groups are updated after adding suggested groups

Add required localization strings to support this feature.
Copy link

trag-bot bot commented Mar 16, 2025

@trag-bot didn't find any issues in the code! ✅✨

@gepetton gepetton marked this pull request as ready for review March 16, 2025 12:27
@gepetton
Copy link
Contributor Author

I’ve fixed it as you suggested. Thanks a lot for your help, @Siedlerchr!!

@gepetton gepetton requested a review from Siedlerchr March 16, 2025 18:53
Comment on lines +188 to +201
// Check for existing suggested subgroups to avoid duplicates
boolean hasEntriesWithoutFiles = false;
boolean hasEntriesWithoutGroups = false;
for (GroupNodeViewModel child : parent.getChildren()) {
String name = child.getGroupNode().getName();
// Check if "Entries without linked files" already exists
if (Localization.lang("Entries without linked files").equals(name)) {
hasEntriesWithoutFiles = true;
}
// Check if "Entries without groups" already exists
if (Localization.lang("Entries without groups").equals(name)) {
hasEntriesWithoutGroups = true;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this existing? I think, this method can only be called if the action is availble?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the check could be helpful since the method needs to handle cases where only one group exists, per issue #12659’s requirements. I’m wondering if there’s a way to adjust the logic or preconditions to make it simpler—do you have any suggestions?


for (GroupNodeViewModel child : getChildren()) {
String name = child.getDisplayName();
if (Localization.lang("Entries without linked files").equals(name)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localization.lang("Entries without linked files") should be private static final constant.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very weird to depend on the name of the group. Can't we set some id or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree—relying on the group’s name like Localization.lang("Entries without linked files") does feel shaky, especially with localization involved. Using an id or something similar, as you suggested, seems way more robust.

I was thinking about adding an enum GroupType to GroupNodeViewModel, like WITHOUT_LINKED_FILES, to keep the logic clean and separate from the display. It’d need a one-time migration for existing data, though. A boolean flag crossed my mind too, but I’m not sure it’d scale well if we add more group types later.

If you have any good suggestions, I’d greatly appreciate your input!

if (Localization.lang("Entries without linked files").equals(name)) {
hasEntriesWithoutFiles = true;
}
if (Localization.lang("Entries without groups").equals(name)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Localization.lang should be private static final constant.

Moreover use } else if ..., because only one of the conditions can match


List<GroupTreeNode> newSubgroups = new ArrayList<>();

if (!hasEntriesWithoutFiles) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not necessary, is it? (See comment above)

dialogService.notify(Localization.lang("Added group \"%0\".", withoutFilesGroup.getName()));
}

if (!hasEntriesWithoutGroups) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not necessary, is it? (See comment above)

Comment on lines +234 to +236
} else {
dialogService.notify(Localization.lang("All suggested groups already exist."));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary, is it? (See comment above)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add "Add JabRef suggested groups"
3 participants