Skip to content

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

Merged
Kovy95 merged 4 commits intorelease/6.4.2from
NAE-2393
Apr 2, 2026
Merged

[NAE-2393] Validation property on set data event#319
Kovy95 merged 4 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 task-data validation integration for file upload fields; when enabled, uploads are validated and aborted if validation fails.
    • Field change handling now respects the same validation gate, skipping downstream updates when validation fails.
  • Tests

    • Updated component tests to accommodate the new optional validation integration.

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

Adds optional TaskContentService injection to file-field and file-list components and TaskDataService; introduces conditional task-data validation checks that can abort uploads and field value-change processing when validateData === 'true'.

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, projects/netgrif-components-core/src/lib/data-fields/file-field/file-default-field/abstract-file-default-field.component.spec.ts
Constructor now accepts optional TaskContentService. upload() includes conditional validateTaskData() guard when component?.properties?.validateData === 'true'. Test class constructor updated to pass the new param.
Concrete File Field Component
projects/netgrif-components/src/lib/data-fields/file-field/file-default-field/file-default-field.component.ts
Added optional @Optional() _taskContentService: TaskContentService and forward it to the abstract base via super(...).
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, projects/netgrif-components-core/src/lib/data-fields/file-list-field/file-list-default-field/abstract-file-list-default-field.component.spec.ts
Constructor now accepts optional TaskContentService. upload() includes the same conditional validateTaskData() guard. Test class updated to match 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
Added optional @Optional() _taskContentService: TaskContentService and forward it to the abstract base via super(...).
Task Data Service
projects/netgrif-components-core/src/lib/task/services/task-data.service.ts
Stored injected TaskContentService as a protected member. In field.valueChanges() subscription, when field.component?.properties?.validateData === 'true', call validateTaskData() and abort further processing (set waitingForResponse = false) if validation fails.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant UI as File Component
    participant Abstract as Abstract File/List Component
    participant TaskService as TaskContentService
    participant TaskData as TaskDataService
    UI->>Abstract: trigger upload()/field change
    Abstract->>Abstract: checkAllowedTypes()
    alt validateData === 'true' and TaskService present
        Abstract->>TaskService: validateTaskData()
        TaskService-->>Abstract: validation result (true/false)
        alt validation false
            Abstract-->>UI: abort (no upload / set waitingForResponse=false)
        else validation true
            Abstract->>TaskData: proceed with upload / update processing
            TaskData-->>Abstract: response
            Abstract-->>UI: update state
        end
    else no validation required
        Abstract->>TaskData: proceed with upload / update processing
        TaskData-->>Abstract: response
        Abstract-->>UI: update state
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • [NAE-2217] Single Task View #303 — Introduces TaskContentService types, injection token and providers that this change optionally injects and calls for validation.
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically references the ticket (NAE-2393) and describes the main change: adding a validation property mechanism for data events, which aligns with the core functionality implemented across file-field and file-list-field components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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

Retoocs
Retoocs previously approved these changes Mar 31, 2026
mazarijuraj
mazarijuraj previously approved these changes Mar 31, 2026
Smotanka
Smotanka previously approved these changes Mar 31, 2026
machacjozef
machacjozef previously approved these changes Apr 1, 2026
renczesstefan
renczesstefan previously approved these changes Apr 1, 2026
@Kovy95 Kovy95 requested a review from tuplle April 2, 2026 08:38
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

♻️ Duplicate comments (1)
projects/netgrif-components-core/src/lib/task/services/task-data.service.ts (1)

203-206: ⚠️ Potential issue | 🟠 Major

Validation short-circuit still performs partial cleanup.

On Line 204, only the triggering field is reset before returning. If other changed fields are in waitingForResponse, they can stay stuck in a pending state after validation aborts. Please clear waiting flags for all affected changed fields before this return path.

Suggested fix
if (field.component?.properties?.validateData === 'true' && !this._taskContentService.validateTaskData()) {
-    field.waitingForResponse = false;
+    this._safeTask.dataGroups.forEach(group => {
+        group.fields.forEach(f => {
+            if (f.changed && f.waitingForResponse) {
+                f.waitingForResponse = false;
+            }
+        });
+    });
     return;
}
🤖 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 - 206, The validation short-circuit returns after resetting
only the triggering field's waitingForResponse; update the early-return path
(the block checking field.component?.properties?.validateData === 'true' &&
!this._taskContentService.validateTaskData()) to first clear waitingForResponse
on all changed/pending fields before returning. Specifically, iterate over the
service's changed fields collection (e.g., whatever holds the pending/edited
fields in this task data handling code) and set each field.waitingForResponse =
false, then perform the return; keep the existing reset of the triggering field
as well.
🤖 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-field/file-default-field/abstract-file-default-field.component.ts`:
- Around line 216-218: The early-return branch that checks
this.dataField.component?.properties?.validateData and
!this._taskContentService.validateTaskData() should clear the file input and any
internal selected-file state before returning so the user can re-select the same
file; locate the branch in abstract-file-default-field.component (the if using
validateData and validateTaskData()), reset the HTML file input element (e.g.
the file input reference or nativeElement's value) and null out any component
variables tracking the chosen File so a subsequent selection of the same
filename will fire change events and allow retrying the upload.

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-160: When validation blocks the upload in the early-return
inside the file picker handler (the branch that checks
this.dataField.component?.properties?.validateData === 'true' &&
this._taskContentService && !this._taskContentService.validateTaskData()),
clear/reset the file input picker before returning so the input has no selected
files (e.g., reset the element/value used for the picker) and guard for its
existence; this ensures a subsequent selection of the same files will fire
change. Locate the handler in abstract-file-list-default-field.component.ts and
reset the same file input reference used elsewhere in this component before the
return.

---

Duplicate comments:
In `@projects/netgrif-components-core/src/lib/task/services/task-data.service.ts`:
- Around line 203-206: The validation short-circuit returns after resetting only
the triggering field's waitingForResponse; update the early-return path (the
block checking field.component?.properties?.validateData === 'true' &&
!this._taskContentService.validateTaskData()) to first clear waitingForResponse
on all changed/pending fields before returning. Specifically, iterate over the
service's changed fields collection (e.g., whatever holds the pending/edited
fields in this task data handling code) and set each field.waitingForResponse =
false, then perform the return; keep the existing reset of the triggering field
as well.
🪄 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: 2b0c1d1c-c498-4bda-8350-d4d4b5a27040

📥 Commits

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

📒 Files selected for processing (3)
  • 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.ts
  • projects/netgrif-components-core/src/lib/task/services/task-data.service.ts

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 2, 2026

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

@Kovy95 Kovy95 merged commit 0da9108 into release/6.4.2 Apr 2, 2026
9 of 11 checks passed
@Kovy95 Kovy95 deleted the NAE-2393 branch April 2, 2026 10:48
@coderabbitai coderabbitai bot mentioned this pull request Apr 2, 2026
18 tasks
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.

7 participants