Skip to content

[NAE-2393] Validation property on set data event#319

Open
Kovy95 wants to merge 2 commits intorelease/6.4.2from
NAE-2393
Open

[NAE-2393] Validation property on set data event#319
Kovy95 wants to merge 2 commits intorelease/6.4.2from
NAE-2393

Conversation

@Kovy95
Copy link
Copy Markdown
Contributor

@Kovy95 Kovy95 commented Mar 31, 2026

Description

  • add a check of property validateData on setData event from frontend
  • if you want to validate all datafields, put property validateData on validating datafield

Implements NAE-2393

Dependencies

none

Third party dependencies

  • No new dependencies were introduced

Blocking Pull requests

There are no dependencies on other PR

How Has Been This Tested?

manually

Test Configuration

<Please describe configuration for tests to run if applicable, like program parameters, host OS, VM configuration etc. You can use >

Name Tested on
OS LinuxMint 22
Runtime Node 20.18.0
Dependency Manager NPM 10.8.2
Framework version Angular 13.3
Run parameters
Other configuration

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes have been checked, personally or remotely, with @...
  • I have commented my code, particularly in hard-to-understand areas
  • I have resolved all conflicts with the target branch of the PR
  • I have updated and synced my code with the target branch
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing tests pass locally with my changes:
    • Lint test
    • Unit tests
    • Integration tests
  • I have checked my contribution with code analysis tools:
  • I have made corresponding changes to the documentation:
    • Developer documentation
    • User Guides
    • Migration Guides

Summary by CodeRabbit

  • New Features
    • Added optional validation support for file upload fields. When enabled on a field, uploads are validated before processing and rejected if validation fails.

Kovy95 added 2 commits March 31, 2026 08:45
- add a check of property validateData on setData event from frontend
- if you want to validate all datafields, put property validateData on validating datafield
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 31, 2026

Walkthrough

This change introduces optional TaskContentService dependency injection across file upload components (file-field and file-list-field) and the task-data service, adding conditional validation gates that check a validateData property. When validation is enabled and the service is present, upload operations and field value changes are gated by task data validation before proceeding.

Changes

Cohort / File(s) Summary
Abstract File Field Components
projects/netgrif-components-core/src/lib/data-fields/file-field/file-default-field/abstract-file-default-field.component.ts, abstract-file-default-field.component.spec.ts
Added optional TaskContentService injection to constructor. Conditional validation gate added to upload() method: when validateData === 'true' and service exists, upload aborts if validateTaskData() returns false. Test component updated to match new constructor signature.
Concrete File Field Component
projects/netgrif-components/src/lib/data-fields/file-field/file-default-field/file-default-field.component.ts
Updated constructor to accept optional TaskContentService and forward it to parent AbstractFileDefaultFieldComponent via super(...) call.
Abstract File List Field Components
projects/netgrif-components-core/src/lib/data-fields/file-list-field/file-list-default-field/abstract-file-list-default-field.component.ts, abstract-file-list-default-field.component.spec.ts
Added optional TaskContentService injection to constructor. Conditional validation gate added to upload() method with same validateData === 'true' check. Test component updated to reflect new constructor signature.
Concrete File List Field Component
projects/netgrif-components/src/lib/data-fields/file-list-field/file-list-default-field/file-list-default-field.component.ts
Updated constructor to accept optional TaskContentService and pass it to parent AbstractFileListDefaultFieldComponent via super(...) call.
Task Data Service
projects/netgrif-components-core/src/lib/task/services/task-data.service.ts
Changed TaskContentService constructor parameter from implicit to explicitly declared protected member. Added conditional validation in field.valueChanges() subscription: when field has validateData === 'true', calls validateTaskData(); if validation fails, sets waitingForResponse = false and aborts further processing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Suggested labels

Medium

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately summarizes the main change: adding validation property support on set data events, which is the core feature across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot added the Medium label Mar 31, 2026
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
projects/netgrif-components-core/src/lib/data-fields/file-field/file-default-field/abstract-file-default-field.component.spec.ts (1)

86-94: 🧹 Nitpick | 🔵 Trivial

Consider adding test coverage for the new validateData behavior.

The current test only verifies component creation. Consider adding tests that verify:

  1. upload() returns early when validateData='true' and validateTaskData() returns false
  2. upload() proceeds when validateData='true' and validateTaskData() returns true
  3. upload() proceeds normally when validateData is not set

This would require providing a mock TaskContentService and configuring the data field with component.properties.validateData.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@projects/netgrif-components-core/src/lib/data-fields/file-field/file-default-field/abstract-file-default-field.component.spec.ts`
around lines 86 - 94, Add unit tests covering the new validateData behavior:
mock or spy TaskContentService/validateTaskData and assert upload() returns
early when component.properties.validateData === 'true' and validateTaskData()
returns false, assert upload() proceeds when validateTaskData() returns true,
and assert upload() proceeds when validateData is not set; locate tests around
abstract-file-default-field.component.spec.ts using the component instance, the
upload() method, and the component.properties.validateData flag to set up the
scenarios and verify expected calls/side effects.
projects/netgrif-components-core/src/lib/data-fields/file-list-field/file-list-default-field/abstract-file-list-default-field.component.spec.ts (1)

86-92: 🧹 Nitpick | 🔵 Trivial

Consider adding test coverage for the validateData behavior.

Same as the file-field spec, consider adding tests that verify the upload() method's behavior when validateData='true' is configured on the data field.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@projects/netgrif-components-core/src/lib/data-fields/file-list-field/file-list-default-field/abstract-file-list-default-field.component.spec.ts`
around lines 86 - 92, Add unit tests for validateData behavior by mirroring the
file-field spec: write two tests that set component.dataField.validateData =
'true', spy on the component.validateData() to return false in one test and true
in the other, then call component.upload(); assert that when validateData()
returns false the internal upload executor (spyOn component.uploadFiles or the
method that actually performs the upload) is not called and that when
validateData() returns true the upload executor is called; use the existing
component variable and method names (validateData, upload, uploadFiles or the
component's actual internal upload method) and add the tests to
abstract-file-list-default-field.component.spec.ts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@projects/netgrif-components-core/src/lib/data-fields/file-list-field/file-list-default-field/abstract-file-list-default-field.component.ts`:
- Around line 158-162: The current placement calling
this._taskContentService.validateTaskData() can cause duplicate side-effectful
validations when multiple fields trigger nearly simultaneously; modify the call
site or the TaskContentService to deduplicate/debounce validations: either wrap
calls from abstract-file-list-default-field.component (check
dataField.component?.properties?.validateData) with a short debounce/throttle so
repeated invocations within, e.g., 300ms are collapsed, or add a guard in
_taskContentService (e.g., track lastValidationTimestamp or an in-flight
validation flag in validateTaskData()) so subsequent calls return early and do
not re-show snackbars; update references to validateTaskData(),
dataField.component?.properties?.validateData and _taskContentService
accordingly.

In `@projects/netgrif-components-core/src/lib/task/services/task-data.service.ts`:
- Around line 203-208: When validation fails inside the block checking
field.component?.properties?.validateData === 'true' and
this._taskContentService.validateTaskData() returns false, perform the same
cleanup as processUnsuccessfulSetDataRequest(): call revertToPreviousValue() on
the current field, clearWaitingForResponseFlag() for all affected fields (not
just field.waitingForResponse = false), and call updateStateInfo() so UI state
is consistent; alternatively, if preserving field.changed is intentional,
document that decision near this validation branch and ensure other
waitingForResponse flags are still cleared and updateStateInfo() is called to
keep the UI consistent.

---

Outside diff comments:
In
`@projects/netgrif-components-core/src/lib/data-fields/file-field/file-default-field/abstract-file-default-field.component.spec.ts`:
- Around line 86-94: Add unit tests covering the new validateData behavior: mock
or spy TaskContentService/validateTaskData and assert upload() returns early
when component.properties.validateData === 'true' and validateTaskData() returns
false, assert upload() proceeds when validateTaskData() returns true, and assert
upload() proceeds when validateData is not set; locate tests around
abstract-file-default-field.component.spec.ts using the component instance, the
upload() method, and the component.properties.validateData flag to set up the
scenarios and verify expected calls/side effects.

In
`@projects/netgrif-components-core/src/lib/data-fields/file-list-field/file-list-default-field/abstract-file-list-default-field.component.spec.ts`:
- Around line 86-92: Add unit tests for validateData behavior by mirroring the
file-field spec: write two tests that set component.dataField.validateData =
'true', spy on the component.validateData() to return false in one test and true
in the other, then call component.upload(); assert that when validateData()
returns false the internal upload executor (spyOn component.uploadFiles or the
method that actually performs the upload) is not called and that when
validateData() returns true the upload executor is called; use the existing
component variable and method names (validateData, upload, uploadFiles or the
component's actual internal upload method) and add the tests to
abstract-file-list-default-field.component.spec.ts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 67247f01-3268-47be-a950-dde6bcc7263f

📥 Commits

Reviewing files that changed from the base of the PR and between 28679ae and 6a9dee8.

📒 Files selected for processing (7)
  • projects/netgrif-components-core/src/lib/data-fields/file-field/file-default-field/abstract-file-default-field.component.spec.ts
  • projects/netgrif-components-core/src/lib/data-fields/file-field/file-default-field/abstract-file-default-field.component.ts
  • projects/netgrif-components-core/src/lib/data-fields/file-list-field/file-list-default-field/abstract-file-list-default-field.component.spec.ts
  • projects/netgrif-components-core/src/lib/data-fields/file-list-field/file-list-default-field/abstract-file-list-default-field.component.ts
  • projects/netgrif-components-core/src/lib/task/services/task-data.service.ts
  • projects/netgrif-components/src/lib/data-fields/file-field/file-default-field/file-default-field.component.ts
  • projects/netgrif-components/src/lib/data-fields/file-list-field/file-list-default-field/file-list-default-field.component.ts

Comment on lines +158 to +162
if (this.dataField.component?.properties?.validateData === 'true' && this._taskContentService) {
if (!this._taskContentService.validateTaskData()) {
return;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Validation gate placement is correct, but beware of duplicate validateTaskData() calls.

The validation check is correctly placed after all file-specific validations and before the upload begins, so no state cleanup is needed on failure here.

However, validateTaskData() has side effects (shows error snackbars, marks all fields as touched). If multiple fields with validateData='true' trigger their actions in close succession (e.g., a text field change and a file upload), users may see duplicate error snackbars. Consider whether a debounce or deduplication mechanism would improve UX.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@projects/netgrif-components-core/src/lib/data-fields/file-list-field/file-list-default-field/abstract-file-list-default-field.component.ts`
around lines 158 - 162, The current placement calling
this._taskContentService.validateTaskData() can cause duplicate side-effectful
validations when multiple fields trigger nearly simultaneously; modify the call
site or the TaskContentService to deduplicate/debounce validations: either wrap
calls from abstract-file-list-default-field.component (check
dataField.component?.properties?.validateData) with a short debounce/throttle so
repeated invocations within, e.g., 300ms are collapsed, or add a guard in
_taskContentService (e.g., track lastValidationTimestamp or an in-flight
validation flag in validateTaskData()) so subsequent calls return early and do
not re-show snackbars; update references to validateTaskData(),
dataField.component?.properties?.validateData and _taskContentService
accordingly.

Comment on lines +203 to +208
if (field.component?.properties?.validateData === 'true') {
if (!this._taskContentService.validateTaskData()) {
field.waitingForResponse = false;
return;
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Incomplete state cleanup on validation failure may leave UI inconsistent.

When validation fails, only field.waitingForResponse = false is set before returning. Compare this to processUnsuccessfulSetDataRequest() which performs more thorough cleanup: revertToPreviousValue(), clearWaitingForResponseFlag() on all affected fields, and updateStateInfo().

The current implementation leaves:

  • field.changed = true, so the field remains marked as changed
  • Other fields with waitingForResponse = true are not cleared
  • No user feedback (snackbar is shown by validateTaskData(), but the field state may appear inconsistent)

Consider whether additional cleanup is needed, or document that the field's changed state is intentionally preserved for retry.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@projects/netgrif-components-core/src/lib/task/services/task-data.service.ts`
around lines 203 - 208, When validation fails inside the block checking
field.component?.properties?.validateData === 'true' and
this._taskContentService.validateTaskData() returns false, perform the same
cleanup as processUnsuccessfulSetDataRequest(): call revertToPreviousValue() on
the current field, clearWaitingForResponseFlag() for all affected fields (not
just field.waitingForResponse = false), and call updateStateInfo() so UI state
is consistent; alternatively, if preserving field.changed is intentional,
document that decision near this validation branch and ensure other
waitingForResponse flags are still cleared and updateStateInfo() is called to
keep the UI consistent.

@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
24.5% Coverage on New Code (required ≥ 50%)

See analysis details on SonarQube Cloud

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.

4 participants