-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fixed duplicate fields assigned to entry types #8391
Conversation
Changed the method addNewField of class CustomEntryTypeDialogViewModel in order to check if the field already exists. Added DialogService field to class CustomEntryTypeDialogViewModel in order to show warning notification to the user. fixes JabRef#8194
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small changes Can you also check what happens when you add a duplicate entry type (e.g. add a custom entry type article)? It could theoretically be possible, but would not make any sense...
import org.jabref.model.entry.field.FieldFactory; | ||
import org.jabref.model.entry.field.FieldPriority; | ||
import org.jabref.model.entry.field.OrFields; | ||
import org.jabref.model.entry.field.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be something wrong with your codestyle here, no star imports allowed
See https://github.com/JabRef/jabref/tree/main/config
ObservableList<FieldViewModel> entryFields = this.selectedEntryType.getValue().fields(); | ||
|
||
// compare every entry field name with the user field name in order to find out if any of them has the same one. If so, show warning. | ||
for (FieldViewModel fieldViewModel : entryFields) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified
entryFields.stream().anyMatch(fieldViewModel -> fieldViewModel.fieldName().getValue().equals(...)
See https://www.baeldung.com/java-8-streams-introduction#1-iterating
Thanks for your contribution (Congrats on your first 🥇 ) and the explanation of your changes! Very good start! Just some minor things. |
… CustomizeEntryTypeDialogView classes fixes JabRef#8194
…vice warning inside if-else condition. fixes JabRef#8194
I am glad to help! Yeah, it is indeed my first contribution to an open source project. The truth is that I found it kind of hard to navigate among the countless project files. However I managed to make it work. Moreover, I tried adding a duplicate entry type and it works. I also implemented the requested changes. Hope it's ok this time! |
Cool :) And a solid first time contribution! A little issue is still left: |
Thanks! Ok I will check this out. Well you have a very good guide on seting up everything for newcomers. The most difficult thing for me with projects like this on github is actually setting them up in order to start. In other projects, the instructions are kind of vague and if you encounter an issue in the process, it is very difficult to recover and get going again. In your project, the instructions for setting up Intellij for example were very clear and they had every possible error that might show up. Finally, I like java as a language and wanted to find a project that uses it, so I ended up choosing Jabref. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
codewise lgtm now. I will test your changes and wait for a second maintainer to review your code
edit// tested locally looks good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two style issues.
Thanks for your contribution!
// create list with all the entry's fields | ||
ObservableList<FieldViewModel> entryFields = this.selectedEntryType.getValue().fields(); | ||
|
||
// compare every entry field name with the user field name in order to find out if any of them has the same one. | ||
boolean fieldExists = entryFields.stream().anyMatch(fieldViewModel -> fieldViewModel.fieldName().getValue().equals(field.getDisplayName())); | ||
|
||
// if the user field name isn't found inside the list, pass it to the entry as a new one. If that is not the case, show warning. | ||
if (!fieldExists) { | ||
this.selectedEntryType.getValue().addField(model); | ||
} else { | ||
dialogService.showWarningDialogAndWait(Localization.lang("Duplicate fields"), Localization.lang("Warning: You added field \"%0\" twice. Only one will be kept.", field.getDisplayName())); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No code-repeating comments. If the name of the variables are chosen well, then the code is self-explaining and you don't need them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello. I deleted the first and last comment and removed as many as lines possible. Shall I remove the second comment too? I think it is more helpful than the other ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, no comment at all, if it's not really necessary and totally misunderstandable otherwise. The best comment is always the code itself, with meaningful variable names and clean code in 98% you don't need any comment at all.
Whoever works with java nowadays knows how to read streams.
src/main/java/org/jabref/gui/customentrytypes/CustomizeEntryTypeDialogView.java
Outdated
Show resolved
Hide resolved
Thanks for your contribution! |
You're welcome! |
Changed the method addNewField of class CustomEntryTypeDialogViewModel in order to check if the field already exists. Added DialogService field to class CustomEntryTypeDialogViewModel in order to show warning notification to the user. Moreover, passed the existing dialogService field of the class CustomEntryDialogView as a parameter when calling the constructor of the CustomEntryTypeDialogViewModel inside it.
Fixes #8194
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)