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

Ensure unique volume layer names when changing names in frontend #6289

Merged
merged 11 commits into from
Jul 4, 2022

Conversation

MichaelBuessemeyer
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer commented Jun 20, 2022

This PR makes it impossible for the user to set layer names of volume annotation layers that already exist. The reason is to prevent duplicate names. The prevention is done when changing a name of a layer and when adding a new volume annotation layer. This pr does not change the names of existing volume layers but it marks them red if there are duplicates and asks the user to rename the layer with duplicated names.

URL of deployed dev instance (used for testing):

Steps to test:

I suggest testing this locally as the first step required is not (easily) possible on a dev branch.

  • Create a volume annotation with multiple layers. Give the layers the same name. Add another layer that includes a / in its name.
  • Now checkout the new branch, there layer names in the layer settings should now be red and a tooltip should say that these layers should be renamed to avoid duplicated names. The layer with the / should say that this character is not allowed and it should also be marked red.
  • Try renaming the layers. This should work. Trying to enter a name that already exists should not be possible. Instead, an error toast should pop up. Entering a name that contains a / should also result in an error toast.
  • Rename the layer so no names are duplicated and no name contains a /. This should then work.
  • Try adding a new annotation layer. The suggested name should not match any of the existing names. Entering an existing name or one containing a / and then trying to confirm should result in an error toast.

Issues:


(Please delete unneeded items, merge only when none are left open)

Comment on lines +70 to +85
const validateAndUpdateValue = () => {
if (this.validateFields()) {
this.props.onChange(this.state.value);
this.setState({
isEditing: false,
});
}
};
if (this.props.trimValue) {
this.setState(
(prevState) => ({ value: prevState.value.trim() }),
// afterwards validate
validateAndUpdateValue,
);
} else {
validateAndUpdateValue();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I avoid having a volume layer name with trailing white spaces. Previous Layer1 and Layer1 was possible and not counted as a name duplication. This is fixed by setting the prop trimValue in the EditableTextLabel.

@MichaelBuessemeyer MichaelBuessemeyer marked this pull request as ready for review June 21, 2022 12:07
Copy link
Member

@daniel-wer daniel-wer left a comment

Choose a reason for hiding this comment

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

Please see my round of rather high-level suggestions. My hope is to be able to simplify the code and make it easier to understand for future readers. Let me know whether this makes sense to you. Happy to jump on a call :)

Also, my impression was that not only forward slashes should be forbidden, but more characters. Since the internal discussion about that was not clear, I asked again. It would be great if you could incorporate the result of that discussion once it converged.

Copy link
Contributor Author

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

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

Hi Daniel,
thanks for the review. I applied all your feedback and adjusted the validation of invalid characters so that URI encoding does not change them.
I had two ideas on how to approach this. The first is the "brute force" method: I remove invalid chars from the new layer name until the URI encoded version matches the original version. While doing so I track the invalid chars that are then shown to the user as invalid. This method should be 100% correct.
The second method uses a regex that removes all save uri characters that will not be encoded in uris according to (this post)[https://perishablepress.com/stop-using-unsafe-characters-in-urls/#character-encoding-chart]. The left over chars are invalid ones.
The second version is shorter and easier to understand, while I am not 100% sure whether the uri safe chars from the post are correct. But I would personally prefer the second version.

You can compare both versions in commit e281c4a

Copy link
Member

@daniel-wer daniel-wer left a comment

Choose a reason for hiding this comment

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

Thank you for applying the feedback, the code already looks better and is easier to understand, agreed! 👍 There are a couple of functional issues left, please see my comments.

Copy link
Contributor Author

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

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

@daniel-wer Thanks a lot for the quick review yesterday. And thanks for already finding the bugs in the code and providing a solution 🙏.
Sorry, for not testing before pinging you. I did not have the time for it.

Copy link
Member

@daniel-wer daniel-wer left a comment

Choose a reason for hiding this comment

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

Great fixes, everything works as advertised 👍

Sorry, for not testing before pinging you. I did not have the time for it.

No worries :)

@MichaelBuessemeyer MichaelBuessemeyer merged commit ed90316 into master Jul 4, 2022
@MichaelBuessemeyer MichaelBuessemeyer deleted the unique-annotation-layer-names branch July 4, 2022 10:59
hotzenklotz added a commit that referenced this pull request Jul 4, 2022
…type

* 'master' of github.com:scalableminds/webknossos:
  Ensure unique volume layer names when changing names in frontend (#6289)
  X-Auth Tokens everywhere (in datastore & tracingstore) (#6312)
  add mapping name param for rawcuboid (#6311)
  Fix zooming out for datasets with very large scale (#6304)
  Release 22.07.0 (#6307)
  added Sahil's publication to list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make annotation layer names unique per annotation
2 participants