Skip to content

feat(style-editor): implement duplicate identifier validation for fields#35219

Merged
KevinDavilaDotCMS merged 3 commits intomainfrom
34703-introduce-visual-schema-builder-for-content-types-II
Apr 6, 2026
Merged

feat(style-editor): implement duplicate identifier validation for fields#35219
KevinDavilaDotCMS merged 3 commits intomainfrom
34703-introduce-visual-schema-builder-for-content-types-II

Conversation

@KevinDavilaDotCMS
Copy link
Copy Markdown
Member

@KevinDavilaDotCMS KevinDavilaDotCMS commented Apr 6, 2026

2026-04-06.12-33-01.mov

This PR fixes: #34703

This PR fixes: #34703

- Added functionality to detect duplicate identifiers across sections in the style editor.
- Updated the UI to show error messages when duplicate identifiers are present.
- Enhanced tests to cover scenarios for duplicate identifier detection and error handling.
- Introduced a new utility function  to facilitate validation logic.

This improves the user experience by preventing conflicts and ensuring unique identifiers for fields.
@github-actions github-actions bot added Area : Backend PR changes Java/Maven backend code Area : Frontend PR changes Angular/TypeScript frontend code labels Apr 6, 2026
@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 6, 2026

Claude finished @KevinDavilaDotCMS's task in 2m 43s —— View job


PR Review: feat(style-editor): implement duplicate identifier validation for fields

  • Read changed files
  • Analyze code and write review

Issues Found

1. Untrimmed identifier saved to backend (new)

dot-style-editor-field-form.component.ts:261-263setIdentifier stores the raw typed value and #emitChange passes it up unchanged. getDuplicateIdentifiers trims identifiers before comparing (models.ts:73), so two fields with "myField" and "myField " are correctly detected as duplicates — but if the user saves, #toStyleEditorField writes field.identifier verbatim (builder.component.ts:339), so the stored schema ends up with a trailing-space identifier. Fix: trim in setIdentifier or in #toStyleEditorField.

2. Duplicated validation logic

dot-style-editor-field-form.component.ts:179-204 re-implements the same logic as fieldHasErrors in models.ts:90-116, with the only additions being the $showErrors() short-circuit and the $isDuplicateIdentifier() check. If a new validation rule is added to fieldHasErrors, the panel's red-border signal $hasErrors will silently miss it. Consider passing isDuplicate into fieldHasErrors and inverting the $showErrors guard at the call site.

3. console.warn fires on every new content type

dot-style-editor-builder.component.ts:261-263 logs [StyleEditorBuilder] Invalid schema in metadata when !raw || typeof raw !== 'string', which is the expected state for any content type that has never had a schema saved. Every first load of a new content type hits this branch.

4. typeInIdentifierInput integration test is fragile

dot-style-editor-builder.component.spec.ts:80-86 dispatches a native DOM input event deep inside a grandchild component and relies on the full cascade (DefaultValueAccessorngModelChangesetIdentifierfieldChangeupdateField) firing synchronously. If the identifier input ever moves to reactive forms, or if OnPush blocks synchronous propagation, the test at line 310 will silently pass without actually calling updateField. A direct call to spectator.component.updateField(0, modifiedField) would be more robust.

5. Missing test: error state clears after duplicate is resolved

The new tests verify that a duplicate blocks saving, but none assert that $duplicateIdentifiers() becomes empty once the user gives the conflicting field a unique identifier. The existing test at line 310 only asserts the API was called, not that the error state cleared.


The core logic in getDuplicateIdentifiers, $isFormValid, $hasFieldErrors, and the [isDuplicateIdentifier] template binding is correct. Item #1 (untrimmed identifier) is a new bug; items #2–5 carry over from the previous review cycle and remain unaddressed.

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Apr 6, 2026

Claude finished @KevinDavilaDotCMS's task in 4m 2s —— View job


PR Review: feat(style-editor): implement duplicate identifier validation for fields

  • Read changed files
  • Analyze code and write review

Issues Found

1. Duplicated validation logic

dot-style-editor-field-form.component.ts:179-204 reimplements virtually the same logic as fieldHasErrors in models.ts:90-116, with the only difference being the this.$isDuplicateIdentifier() check. If a new validation rule is added to fieldHasErrors, it must also be mirrored in $hasErrors; otherwise the field-level error indicator and the builder's save gate silently diverge. Consider adding an isDuplicate param to fieldHasErrors so it stays the single source of truth.

2. typeInIdentifierInput integration test is fragile

dot-style-editor-builder.component.spec.ts:80-86 dispatches native DOM input events to drive state changes deep inside a child component. This relies on an implicit cascade: DefaultValueAccessor picks up the native event -> ngModelChange fires -> field-form updates its state -> emits fieldChange -> builder calls updateField(). This chain can break silently if the identifier input moves from ngModel to reactive forms, or if OnPush prevents synchronous propagation. The test at line 310-321 is only reliable if the full cascade fires synchronously. A more robust approach is to call spectator.component.updateField() directly with a modified field.

3. console.warn fires on normal first load

dot-style-editor-builder.component.ts:258-260 logs '[StyleEditorBuilder] Invalid schema in metadata' when a content type has no stored schema yet, which is the expected state for every new content type. Pre-existing, but produces noise in logs for every new content type.

4. Missing test: error clears after duplicate is resolved

The new tests verify that duplicates block saving, but none verify that $duplicateIdentifiers() becomes empty once the user gives the conflicting field a unique identifier. The test at line 310 only asserts the API was called, not that the error state cleared.


The core logic in getDuplicateIdentifiers and its wiring into $isFormValid, $hasFieldErrors (section), and the [isDuplicateIdentifier] binding in the template is correct. Main risk is item #1: validation logic split across two near-identical code paths.

@KevinDavilaDotCMS KevinDavilaDotCMS added this pull request to the merge queue Apr 6, 2026
@dario-daza dario-daza removed this pull request from the merge queue due to a manual request Apr 6, 2026
…ections

- Updated the style editor to ensure that sections must contain at least one field to be considered valid.
- Introduced a new computed property to display an error message when a section is empty and errors are being shown.
- Enhanced the UI to reflect this validation by displaying an error message when applicable.
- Added unit tests to verify the new validation logic and error display behavior.

This improves user experience by providing clear feedback when sections are incorrectly configured.
@KevinDavilaDotCMS KevinDavilaDotCMS added this pull request to the merge queue Apr 6, 2026
Merged via the queue into main with commit 92bf91a Apr 6, 2026
52 checks passed
@KevinDavilaDotCMS KevinDavilaDotCMS deleted the 34703-introduce-visual-schema-builder-for-content-types-II branch April 6, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Safe To Rollback Area : Backend PR changes Java/Maven backend code Area : Frontend PR changes Angular/TypeScript frontend code

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Introduce Visual Schema Builder for Content Types

2 participants