Skip to content

Conversation

@CXZHANG0508
Copy link
Contributor

Closes #14647

This PR fixes a bug where exporting an AI chat session initiated via "Chat with group" resulted in an empty entries list in the exported file.

The Fix:
I updated the AiChatComponent constructor logic to prioritize the entries list passed as an argument. The component now falls back to stateManager.getSelectedEntries() only if the passed list is null or empty. This ensures that the correct context is used for export in both "Chat with group" and "Chat with selected entry" modes.

Steps to test

  1. Open a library that contains groups and entries.
  2. Right-click on a Group in the side panel -> Select "Chat with group".
  3. Send a message (e.g., "Summarize") to generate some chat history (even if it errors due to no API key, as long as user messages appear).
  4. Click the Export button (select JSON format).
  5. Open the exported JSON file.
  6. Verify: The "entries" array should now contain the bibliographic data of the papers in that group (previously it was empty []).

Mandatory checks

@github-actions github-actions bot added the good first issue An issue intended for project-newcomers. Varies in difficulty. label Dec 18, 2025
@github-actions github-actions bot added status: changes-required Pull requests that are not yet complete and removed status: changes-required Pull requests that are not yet complete labels Dec 18, 2025
Comment on lines 110 to 112
this.entries = stateManager.getSelectedEntries();
this.entries = (entries != null && !entries.isEmpty())
? entries
: stateManager.getSelectedEntries();
Copy link
Member

Choose a reason for hiding this comment

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

Strange code!

When is entries null? Is it a different mode? Is the caller doing something wrong?

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 realized that while the previous code fixed the "chat with group" issue, it introduced a regression for standard multi-selection.
Specifically, when right-clicking a multi-selection to start a chat, the UI often passes only the single focused row, causing the multi-selection to be lost.
I have now modified the logic to handle both scenarios:

  1. It detects if the passed entry is just a subset of the current multi-selection (fixing the right-click issue).
  2. It correctly prioritizes the passed entries for Group Chat .
    I believe that if we don't add the option to directly chat with a group when creating a new library, the entries will be empty when exported. However, I think this might be permissible; otherwise, this option should be disabled.

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 18, 2025
@github-actions github-actions bot removed the status: changes-required Pull requests that are not yet complete label Dec 18, 2025

ObservableList<BibEntry> currentSelection = stateManager.getSelectedEntries();

if (entries != null && !entries.isEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

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

How can entries be null? I would have thought it's an empty list

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Siedlerchr You are right. I re-verified the behavior. I initially assumed that the conflict resolution between the passed entries and the global selection might lead to a null value in some edge cases. However, when the issue was solved, I see that it consistently results in an empty list[] when no selection is active, not null.
I have removed the unnecessary null check. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Dont use AI to communicate with us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@calixtus OK,I will not use the translator with the function of AI, last week I did my work so that I did not response immediately. Is there any issue with my PR now?

@github-actions github-actions bot added the status: changes-required Pull requests that are not yet complete label Dec 20, 2025
@github-actions
Copy link
Contributor

Your pull request conflicts with the target branch.

Please merge with your code. For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line.

@github-actions github-actions bot added status: changes-required Pull requests that are not yet complete and removed status: changes-required Pull requests that are not yet complete labels Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: ai good first issue An issue intended for project-newcomers. Varies in difficulty. status: changes-required Pull requests that are not yet complete

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Entries should not be empty when exporting group chat

4 participants