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

Tabular UI for naming linked files #12624

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

Conversation

priyanshu16095
Copy link
Contributor

@priyanshu16095 priyanshu16095 commented Mar 5, 2025

Closes #11368

This PR adds a tabular construct similar to "Key patterns" for "Linked files name" in the Linked files tab in preferences.

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.

Screenshot (202)

@priyanshu16095 priyanshu16095 changed the title Tabular UI Tabular UI for naming linked files Mar 5, 2025
@priyanshu16095
Copy link
Contributor Author

I have try to add but I am very unclear about how preference migration works.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

JUnit tests are failing. In the area "Some checks were not successful", locate "Tests / Unit tests (pull_request)" and click on "Details". This brings you to the test output.
You can then run these tests in IntelliJ to reproduce the failing tests locally. We offer a quick test running howto in the section Final build system checks in our setup guide.

@koppor
Copy link
Member

koppor commented Mar 11, 2025

I have try to add but I am very unclear about how preference migration works.

Not sure how to help.

Example method: org.jabref.migrations.PreferencesMigrations#upgradeImportFileAndDirePatterns

It first checks if a prefernce is there. If yes, it checks the content. Then, it check whether the current content is an old content. Then it updates to the new content. Then it wirtes the new string.

Similar at org.jabref.migrations.PreferencesMigrations#upgradeKeyBindingsToJavaFX - and all other migrations.

@priyanshu16095 priyanshu16095 marked this pull request as draft March 20, 2025 01:52
Copy link

trag-bot bot commented Mar 21, 2025

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

@priyanshu16095 priyanshu16095 marked this pull request as ready for review March 21, 2025 02:29
Comment on lines +44 to +48
if ((initialNamePattern.getDefaultValue() == null) || initialNamePattern.getDefaultValue().equals(Pattern.NULL_PATTERN)) {
defaultPattern = "";
} else {
defaultPattern = initialNamePattern.getDefaultValue().stringRepresentation();
}
Copy link

Choose a reason for hiding this comment

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

The code violates the fail-fast principle by nesting logic inside else branch. Should check for valid state first and return/assign early.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it is OK in this context.

@Override
public void setValues() {
viewModel.setValues();
BibEntryTypesManager entryTypesManager = Injector.instantiateModelOrService(BibEntryTypesManager.class);
Copy link

Choose a reason for hiding this comment

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

Direct instantiation through Injector in method body violates separation of concerns. The dependency should be injected through constructor or setter method.

@@ -48,7 +48,7 @@ public static Optional<MetaDataDiff> compare(MetaData originalMetaData, MetaData
return Optional.empty();
} else {
MetaDataDiff diff = new MetaDataDiff(originalMetaData, newMetaData);
List<Difference> differences = diff.getDifferences(new GlobalCitationKeyPatterns(CitationKeyPattern.NULL_CITATION_KEY_PATTERN));
List<Difference> differences = diff.getDifferences(new GlobalCitationKeyPatterns(Pattern.NULL_PATTERN));
Copy link

Choose a reason for hiding this comment

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

Same GlobalCitationKeyPatterns object is created twice in the class - in compare() and toString(). This violates DRY principle and creates redundant object allocations.

@@ -14,12 +14,12 @@
*/
public abstract class AbstractCitationKeyPatterns {

protected CitationKeyPattern defaultPattern = CitationKeyPattern.NULL_CITATION_KEY_PATTERN;
protected Pattern defaultPattern = Pattern.NULL_PATTERN;
Copy link

Choose a reason for hiding this comment

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

Public methods should not return null values. Consider using Optional instead of allowing null patterns, even for internal representation.

Comment on lines +82 to +83
public static List<Pattern> getAllPatterns() {
return Arrays.stream(Pattern.class.getDeclaredFields())
Copy link

Choose a reason for hiding this comment

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

The method lacks JavaDoc despite being a complex public method that uses reflection and handles exceptions. Documentation would help explain its purpose and behavior.

}

/**
* Gets an object for a desired key from this LinkedFileNamePattern or one of it's parents (in the case of
Copy link

Choose a reason for hiding this comment

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

JavaDoc contains grammatical error ('it's' should be 'its') and references Hashtable in description while code uses HashMap, making documentation misleading.

}

public static GlobalLinkedFileNamePatterns fromPattern(String pattern) {
return new GlobalLinkedFileNamePatterns(new Pattern(pattern));
Copy link

Choose a reason for hiding this comment

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

Missing validation for the pattern parameter before creating new Pattern object. Input parameters should be validated to fail fast.

Comment on lines +569 to +571
if (preferenceFileNamePattern != null) {
mainPrefsNode.put(JabRefCliPreferences.LINKED_FILE_NAME_PATTERNS_NODE, "[auth_year]");
if (prefs.hasKey(JabRefCliPreferences.IMPORT_FILENAMEPATTERN)) {
Copy link

Choose a reason for hiding this comment

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

The code violates the fail-fast principle by nesting logic inside conditional blocks instead of returning early. The nested if condition should be restructured.

@@ -68,6 +68,7 @@ public static void runMigrations(JabRefGuiPreferences preferences) {
upgradeCleanups(preferences);
moveApiKeysToKeyring(preferences);
removeCommentsFromCustomEditorTabs(preferences);
upgradeFileImportPatternToLinkedFileNamePattern(preferences, mainPrefsNode);
Copy link

Choose a reason for hiding this comment

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

The method lacks proper JavaDoc documentation explaining the migration process, parameters, and potential side effects, which is important for complex migration operations.

@priyanshu16095
Copy link
Contributor Author

To remove code duplication ,
Renamed LinkedFileNamePattern and CitationKeyPattern to Pattern
Renamed LinkedFileNamePatternsPanelItemModel and CitationKeyPatternsItemModel to PatternsItemModel
Renamed LinkedFileNamePatternsSuggestionCell and CitationKeyPatternsSuggestionCell to PatternsSuggestionCell

The thing I am not sure about is whether the preference migration is correct or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: changes required Pull requests that are not yet complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Citation key generator and Linked files
3 participants