Color Picker: Validate uniqueness of selected colors#20431
Conversation
|
Hi there @Programeerik, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
There was a problem hiding this comment.
Pull Request Overview
This PR adds validation to prevent duplicate color values in the Color Picker property editor configuration. The validation normalizes color values (converting 3-digit hex to 6-digit format and ensuring case-insensitive comparison) before checking for duplicates.
Key changes:
- Added duplicate color validation logic with normalization for proper comparison
- Modernized the validator implementation using source-generated regex and collection expressions
- Added comprehensive unit tests to verify the duplicate validation functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs | Added duplicate validation logic, normalization method, and modernized code with source-generated regex |
| tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/ColorListValidatorTest.cs | Added unit test to verify duplicate color validation works correctly |
src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs
Show resolved
Hide resolved
src/Umbraco.Infrastructure/PropertyEditors/ColorPickerConfigurationEditor.cs
Show resolved
Hide resolved
AndyButland
left a comment
There was a problem hiding this comment.
Thanks for this contribution @Programeerik. I tested out and found an issue via the unit test (so that was very valuable to add), which I've fixed up and just done a little tidy up of the file since we are editing it.
Please let me know if all looks good to you and we can merge this in.
Moving forward I'd like to see better surfacing of this validation in the backoffice itself (which works well for content, but less so for data type configuration), but having this improved check on the server-side is worth having anyway.
|
@AndyButland Great point about the continue addition. When you talk about the validation in the backoffice, do you mean so that the user get realtime feedback? The serverside code check can be merged. Thanks for the additions and help. |
Could be real-time, but more that we better surface the server-side validation when managing data type configurations. |
|
@AndyButland should we consider some of these changes in It seems |
|
Looks like it, certainly the |
Prerequisites
If there's an existing issue for this PR then this fixes #20359
Description
I've added an check on duplicates after the valid color check, so it's only checked when it's an valid color.
I've added an function normalize to the internal ColorListValidator class so the logic is much better readable.
The normalize function is for removing the # before checking for duplicate values.
When the count of duplicates is higher than 0 it's not possible to save the data.
I've also added an unittest which check if the test returns the duplicate value