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

minor refactor to JabRefDialogService #11767

Merged
merged 5 commits into from
Sep 18, 2024

Conversation

leaf-soba
Copy link
Contributor

  1. replace multiple if-else to switch case
  2. remove unused generics <V>
  3. replace .collect(Collectors.toList()) to .toList()
  4. remove unnecessary braces
  • I'm no sure do we really need this kind of small refactor, please review and let me know if this change aligns with our goals.

Mandatory checks

  • Change in CHANGELOG.md described in a way that is understandable for the average user (if applicable)
  • 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.

1. replace multiple if-else to switch case
2. remove unused generics `<V>`
3. replace `.collect(Collectors.toList())` to `.toList()`
4. remove unnecessary braces
Comment on lines 229 to 238
switch (statusCode) {
case 401 ->
this.showInformationDialogAndWait(failedTitle, Localization.lang("Access denied. You are not authorized to access this resource. Please check your credentials and try again. If you believe you should have access, please contact the administrator for assistance.") + "\n\n" + localizedMessage);
case 403 ->
this.showInformationDialogAndWait(failedTitle, Localization.lang("Access denied. You do not have permission to access this resource. Please contact the administrator for assistance or try a different action.") + "\n\n" + localizedMessage);
case 404 ->
this.showInformationDialogAndWait(failedTitle, Localization.lang("The requested resource could not be found. It seems that the file you are trying to download is not available or has been moved. Please verify the URL and try again. If you believe this is an error, please contact the administrator for further assistance.") + "\n\n" + localizedMessage);
default ->
this.showErrorDialogAndWait(failedTitle, Localization.lang("Something is wrong on JabRef side. Please check the URL and try again.") + "\n\n" + localizedMessage);
}
Copy link
Member

Choose a reason for hiding this comment

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

This can be refactored even more?

content = switch (statusCode) { 401 -> Localization.lang"..");

 this.showInformationDialogAndWait(failedTitle, content);

I would just not care about info and error. I think "info" is OK even in the default case.

@@ -472,7 +470,7 @@ public Optional<Path> showDirectorySelectionDialog(DirectoryDialogConfiguration
public List<Path> showFileOpenDialogAndGetMultipleFiles(FileDialogConfiguration fileDialogConfiguration) {
FileChooser chooser = getConfiguredFileChooser(fileDialogConfiguration);
List<File> files = chooser.showOpenMultipleDialog(mainWindow);
return files != null ? files.stream().map(File::toPath).collect(Collectors.toList()) : Collections.emptyList();
return files != null ? files.stream().map(File::toPath).toList() : Collections.emptyList();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return files != null ? files.stream().map(File::toPath).toList() : Collections.emptyList();
return files != null ? files.stream().map(File::toPath).toList() : List.of();

.hideAfter(TOAST_MESSAGE_DISPLAY_TIME)
.owner(mainWindow)
.threshold(5,
Notifications.create()
Copy link
Member

Choose a reason for hiding this comment

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

This new indent is a bit strange - maybe keep the old indent - on line 428 it also "felt" better, because it is indented 4 spaces, not 30 or so ^^

@koppor koppor added the type: code-quality Issues related to code or architecture decisions label Sep 16, 2024
@Siedlerchr
Copy link
Member

Thanks for your contribution, however due to our limited time for reviews (we are all working at JabRef in our spare time), we prefer such code quality only refactorings more in the context of bugs/feature implementations

@calixtus
Copy link
Member

calixtus commented Sep 16, 2024

Thanks for your interest in JabRef.
As @Siedlerchr said, we as the maintainers try to focus on Bugfixes and features und prefer small refactorings as part of bigger feature PRs or as part of our long term development roadmap. we would like to encourage you to pick a good first issue or another issue to fix or even create a new issue with an new feature idea we could discuss with you.
Since the work is already done (please integrate @koppor s suggestions), we can probably integrate them, when it's done.

@koppor
Copy link
Member

koppor commented Sep 16, 2024

  • I'm no sure do we really need this kind of small refactor, please review and let me know if this change aligns with our goals.

For me, it is currently OK, because the batch sizes are small enough to cope with it in some spare minutes 😅.

@leaf-soba
Copy link
Contributor Author

Thanks for your interest in JabRef. As @Siedlerchr said, we as the maintainers try to focus on Bugfixes and features und prefer small refactorings as part of bigger feature PRs or as part of our long term development roadmap. we would like to encourage you to pick a good first issue or another issue to fix or even create a new issue with an new feature idea we could discuss with you. Since the work is already done (please integrate @koppor s suggestions), we can probably integrate them, when it's done.

OK, I'll try my best to solve some bigger issue from now on. Would you and @koppor mind review the comments in #10371 (comment), I'm not sure where to start solve this issue so I break down into small task, but I didn't get reply in two weeks, I think I may make a mistake, such as not @ anyone, so there wasn't any notification to others.

1. remove `type` parameter in createDialogWithOptOut, since it always be `AlertType.CONFIRMATION`
2. remove `Math.min` in `shortenDialogMessage`, since it after a if compare, it means the dialogMessage.length() is always not less than JabRefDialogService.DIALOG_SIZE_LIMIT
3. refactor the switch case more.
4. fix the indent issue.
private String getContentByCode(int statusCode) {
return switch (statusCode) {
case 401 ->
"Access denied. You are not authorized to access this resource. Please check your credentials and try again. If you believe you should have access, please contact the administrator for assistance.";
Copy link
Member

Choose a reason for hiding this comment

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

fix missing Localization.lang
add missing newline character and localizedMessage
} else {
this.showErrorDialogAndWait(failedTitle, Localization.lang("Something is wrong on JabRef side. Please check the URL and try again.") + "\n\n" + localizedMessage);
}
this.showInformationDialogAndWait(failedTitle, Localization.lang(getContentByCode(httpResponse.get().statusCode())) + "\n\n" + localizedMessage);
Copy link
Member

Choose a reason for hiding this comment

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

No, that does not work.

Localization.lang has to be parameterized with a literal (!) string. Otherwise, our tooling does nt work. Please see https://devdocs.jabref.org/code-howtos/localization.html

Copy link
Contributor Author

@leaf-soba leaf-soba Sep 17, 2024

Choose a reason for hiding this comment

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

I found this TODO in org.jabref.logic.l10n.LocalizationConsistencyTest:

TODO: Localization.lang(var1 + "test" + var2) not covered

In my code is a var1 + "test" + var2 case, so it failed. maybe I should finish this TODO to pass the unit test?


sorry I made a mistake, my code is not var1 + "test" + var2 case, it just a var case which is illegal in LocalizationConsistencyTest

Copy link
Member

Choose a reason for hiding this comment

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

Finishing that ToDo would require several hours of work and design planning. Localization requires full sentences to be translated as in different languages word order and grammar changes d pending on what that var may be. So please just do as @koppor said, fix your strings.

Copy link
Contributor Author

@leaf-soba leaf-soba Sep 18, 2024

Choose a reason for hiding this comment

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

Finishing that ToDo would require several hours of work and design planning. Localization requires full sentences to be translated as in different languages word order and grammar changes d pending on what that var may be. So please just do as @koppor said, fix your strings.

I did as @koppor said, have fixed my strings before I commented. I just want to make this unit test better by finishing ToDo. And I think it may not require several hours work, such as this simple way:

  • assert code in LocalizationConsistencyTest now:
assertTrue(e.getKey().startsWith("\"") || e.getKey().endsWith("\""), "Illegal localization parameter found. Must include a String with potential concatenation or replacement parameters. Illegal parameter: Localization.lang(" + e.getKey());
  • a little fix, add StringUtils.countMatches(e.getKey(), "\"") >= 2 to cover Localization.lang(var1 + "test" + var2) case:
assertTrue(e.getKey().startsWith("\"") || e.getKey().endsWith("\"") || StringUtils.countMatches(e.getKey(), "\"") >= 2, "Illegal localization parameter found. Must include a String with potential concatenation or replacement parameters. Illegal parameter: Localization.lang(" + e.getKey());

Copy link
Member

Choose a reason for hiding this comment

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

Discussion follow-up at #11784

need to use plain string not a method result or a var to pass the unit test.
@koppor koppor added this pull request to the merge queue Sep 18, 2024
Merged via the queue into JabRef:main with commit 88fc846 Sep 18, 2024
23 checks passed
Siedlerchr added a commit that referenced this pull request Sep 20, 2024
…xArxivHtmlImport

* 'fixArxivHtmlImport' of github.com:JabRef/jabref:
  Fix focus for keywords and crossref fields (#11792)
  Fix ai chat not on fx thread (#11796)
  [AI] Add more uses statements (#11788)
  Update djl api dependency (#11787)
  Improve pdf content parser for DOIs (#11782)
  minor refactor to JabRefDialogService (#11767)
  Add more OS-dependent context to panel freeze dev documentation. (#11781)
@leaf-soba leaf-soba deleted the refactor-JabRefDialogService branch September 26, 2024 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: code-quality Issues related to code or architecture decisions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants