Skip to content

[NAE-2047] Fulltext search and advanced search usability with multichoice caseRef #272

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

Open
wants to merge 5 commits into
base: release/6.5.0
Choose a base branch
from

Conversation

Kovy95
Copy link
Contributor

@Kovy95 Kovy95 commented Feb 20, 2025

Description

Implements NAE-2047

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

Name Tested on
OS LinuxMint 22
Runtime Node 20.18.0
Dependency Manager NPM 10.8.2
Framework version Angular 13.3.1
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 support for partial selection and improved handling of approval data fields in header components, including detection of indeterminate states and type identification for approval fields.
    • Synchronous access to the current list of cases is now available alongside the existing observable stream.
  • Enhancements
    • Pagination controls in task and case lists now offer an additional page size option of 100.
  • Bug Fixes
    • Improved stability by preventing errors when handling undefined or null header properties.

…oice caseRef

- fix the problem with selecting all things in multichoice caseref
- move logic to components-core
- add 100 item option to pagination
Copy link

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

Copy link

coderabbitai bot commented Jun 5, 2025

Walkthrough

The changes introduce enhancements to approval data field handling in header components, add synchronous access to cases in the case view service, and expand pagination options to include a page size of 100. The header component logic is refactored to delegate approval form control management to its abstract superclass.

Changes

File(s) Change Summary
...abstract-case-ref-base-field-component.ts Added optional chaining to safely call split(',') on potentially undefined headers property.
...abstract-header.component.ts Enhanced constructor to inject CaseViewService and approval data field portal; added logic for reactive approval data field synchronization; added public methods for indeterminate state and approval type detection.
...abstract-header.component.spec.ts Updated test setup and TestHeaderComponent constructor to include new dependencies (CaseViewService, approval data field portal).
...header.component.ts Removed local approval form control logic; constructor updated to inject new dependencies and delegate all logic to superclass; removed related public methods.
...case-view-service.ts Added protected _cases array and public getter for synchronous case access; updated observable pipeline to keep _cases in sync.
...abstract-task-list-pagination.component.ts
...abstract-case-list-paginator.component.ts
Expanded page size options from [10, 20, 50] to [10, 20, 50, 100].

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant HeaderComponent
    participant AbstractHeaderComponent
    participant CaseViewService
    participant DataField (MultichoiceField/EnumerationField)

    User->>HeaderComponent: Interacts with approval form control
    HeaderComponent->>AbstractHeaderComponent: Delegates approval logic
    AbstractHeaderComponent->>CaseViewService: Gets current cases
    AbstractHeaderComponent->>DataField: Reads/writes approval value
    AbstractHeaderComponent-->>HeaderComponent: Updates form control state
    HeaderComponent-->>User: Reflects updated approval state
Loading
sequenceDiagram
    participant Consumer
    participant CaseViewService

    Consumer->>CaseViewService: Accesses cases via cases getter
    CaseViewService-->>Consumer: Returns current cases array
    Note right of CaseViewService: _cases kept in sync with observable emissions
Loading
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 1

🧹 Nitpick comments (6)
projects/netgrif-components-core/src/lib/panel/task-panel-list/task-panel-list-pagination/abstract-task-list-pagination.component.ts (1)

21-21: Style consistency: use number[] for pageSizeOptions.

Align the type annotation with the case list paginator to reduce inconsistencies.

Apply this diff:

- public pageSizeOptions: Array<number> = [10, 20, 50, 100];
+ public pageSizeOptions: number[] = [10, 20, 50, 100];
projects/netgrif-components-core/src/lib/view/case-view/service/case-view-service.ts (3)

117-118: Remove redundant type casting in tap operator

The type casting as Array<Case> is unnecessary since the map operator on line 117 already returns Array<Case>.

-tap(cases => this._cases = cases as Array<Case>),
+tap(cases => this._cases = cases),

140-142: Add documentation for the synchronous cases getter

The new synchronous getter should be documented to clarify its purpose and usage, especially since it exposes internal state that could become stale.

+/**
+ * Returns the current synchronous snapshot of cases.
+ * Note: This is a snapshot that gets updated via the observable stream.
+ * For reactive updates, prefer using cases$ observable instead.
+ */
 public get cases(): Array<Case> {
     return this._cases;
 }

50-50: Consider memory implications for large case datasets

The synchronous _cases array duplicates data from the observable stream. For applications handling large numbers of cases, this could impact memory usage. Consider if the synchronous access pattern is essential or if the components could be refactored to work with the observable stream directly.

Also applies to: 71-71, 117-118, 140-142

projects/netgrif-components-core/src/lib/header/abstract-header.component.ts (2)

60-65: Consider documenting the _changeValue initialization.

The constructor properly injects the new optional dependencies. However, initializing _changeValue to true might be counterintuitive. Consider adding a comment explaining why it starts as true rather than false.

 constructor(protected _injector: Injector,
             protected _translate: TranslateService,
             @Optional() protected _overflowService: OverflowService,
             @Optional() protected _caseViewService: CaseViewService,
             @Optional() @Inject(DATA_FIELD_PORTAL_DATA) protected _dataFieldPortalData: DataFieldPortalData<MultichoiceField | EnumerationField>) {
     this.initializeFormControls(this._overflowService !== null);
+    // Initialize to true to allow the first value change to propagate
     this._changeValue = true;
 }

262-267: Consider optimizing the selection check for better performance.

The current implementation uses every() with includes() which has O(n*m) complexity. For large datasets, this could be optimized using a Set.

 protected resolveApprovalValue() {
     if (this._caseViewService.cases.length === 0) {
         return false;
     }
-    return this._caseViewService.cases.every(value => this._dataFieldPortalData?.dataField.value.includes(value.stringId));
+    const selectedIds = new Set(this._dataFieldPortalData?.dataField.value || []);
+    return this._caseViewService.cases.every(value => selectedIds.has(value.stringId));
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 19f6085 and 3cecc0a.

📒 Files selected for processing (7)
  • projects/netgrif-components-core/src/lib/data-fields/case-ref-field/model/abstract-case-ref-base-field-component.ts (1 hunks)
  • projects/netgrif-components-core/src/lib/header/abstract-header.component.spec.ts (3 hunks)
  • projects/netgrif-components-core/src/lib/header/abstract-header.component.ts (6 hunks)
  • projects/netgrif-components-core/src/lib/panel/task-panel-list/task-panel-list-pagination/abstract-task-list-pagination.component.ts (1 hunks)
  • projects/netgrif-components-core/src/lib/view/case-view/components/case-list-paginator/abstract-case-list-paginator.component.ts (1 hunks)
  • projects/netgrif-components-core/src/lib/view/case-view/service/case-view-service.ts (4 hunks)
  • projects/netgrif-components/src/lib/header/header.component.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
projects/netgrif-components-core/src/lib/header/abstract-header.component.ts (3)
projects/netgrif-components-core/src/lib/data-fields/models/data-field-portal-data-injection-token.ts (2)
  • DATA_FIELD_PORTAL_DATA (15-15)
  • DataFieldPortalData (6-13)
projects/netgrif-components-core/src/lib/data-fields/multichoice-field/models/multichoice-field.ts (1)
  • MultichoiceField (15-64)
projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts (1)
  • EnumerationField (22-88)
projects/netgrif-components-core/src/lib/header/abstract-header.component.spec.ts (3)
projects/netgrif-components-core/src/lib/data-fields/models/data-field-portal-data-injection-token.ts (2)
  • DATA_FIELD_PORTAL_DATA (15-15)
  • DataFieldPortalData (6-13)
projects/netgrif-components-core/src/lib/data-fields/multichoice-field/models/multichoice-field.ts (1)
  • MultichoiceField (15-64)
projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts (1)
  • EnumerationField (22-88)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Test with SonarCloud
  • GitHub Check: Matrix Test (16)
  • GitHub Check: Matrix Test (18)
  • GitHub Check: Matrix Test (14)
🔇 Additional comments (8)
projects/netgrif-components-core/src/lib/view/case-view/components/case-list-paginator/abstract-case-list-paginator.component.ts (1)

20-20: Approve: Added support for 100 items per page.

Including 100 in pageSizeOptions aligns this paginator with user expectations for bulk navigation.

projects/netgrif-components-core/src/lib/panel/task-panel-list/task-panel-list-pagination/abstract-task-list-pagination.component.ts (1)

21-21: Approve: Added support for 100 items per page.

Aligns task list pagination with the case list paginator for consistency in large lists.

projects/netgrif-components-core/src/lib/data-fields/case-ref-field/model/abstract-case-ref-base-field-component.ts (1)

35-35: Good defensive programming practice!

Adding the optional chaining operator prevents potential runtime errors when headers is undefined or null.

projects/netgrif-components/src/lib/header/header.component.ts (1)

25-33: Clean refactoring to delegate logic to parent class!

The simplification appropriately moves the approval data field handling logic to AbstractHeaderComponent, following the DRY principle and maintaining proper separation of concerns.

projects/netgrif-components-core/src/lib/header/abstract-header.component.spec.ts (1)

7-7: Test setup properly updated for new dependencies.

The test file correctly reflects the changes made to AbstractHeaderComponent by adding the necessary imports and updating the constructor signature to include the new optional dependencies.

Also applies to: 32-38, 99-102

projects/netgrif-components-core/src/lib/header/abstract-header.component.ts (3)

1-1: Well-structured imports and property declarations.

The new imports are properly organized, and the added properties are appropriately typed. The _changeValue flag for preventing feedback loops is a good practice for bidirectional data binding scenarios.

Also applies to: 15-21, 55-56


108-108: Proper lifecycle management.

Good implementation of lifecycle hooks with appropriate initialization in ngOnInit and proper cleanup of subscriptions in ngOnDestroy to prevent memory leaks.

Also applies to: 117-119


219-227:

❓ Verification inconclusive

Inconsistent logic between branches in indeterminate() method.

The method has fundamentally different logic depending on whether _caseViewService is available:

  • With service: checks if some (but not all) cases are selected
  • Without service: compares value length with choices length

This could lead to unexpected behavior in different contexts. Consider unifying the logic or documenting why different approaches are needed.

Can you clarify the intended behavior when _caseViewService is not available? The current implementation might not correctly represent an indeterminate state.


Clarify indeterminate() logic when _caseViewService is unavailable.

The two branches in indeterminate() behave quite differently:

  • With _caseViewService: checks if any case IDs are selected and not all approvals are resolved.
  • Without _caseViewService: simply compares the length of value against the number of choices.

This divergence may lead to inconsistent “indeterminate” states across contexts.
• File: projects/netgrif-components-core/src/lib/header/abstract-header.component.ts
• Lines: 219–227

Can you confirm the intended behavior when _caseViewService isn’t injected? Should both paths use the same criteria for “indeterminate,” or is there a specific reason for the discrepancy? Consider aligning the logic or documenting why they differ.

Comment on lines +233 to +260
protected resolveApprovalDatafields() {
if (this._dataFieldPortalData !== null && this._dataFieldPortalData.dataField instanceof MultichoiceField && this._caseViewService) {
this.approvalFormControl.setValue(this.resolveApprovalValue());
this.approvalFormControl.valueChanges.subscribe(value => {
if (this._changeValue) {
if (value) {
this._dataFieldPortalData.dataField.value = this._caseViewService.cases.map(caze => caze.stringId);
} else {
this._dataFieldPortalData.dataField.value = [];
}
}
this._changeValue = true;
})
this._dataFieldPortalData.dataField.valueChanges().subscribe(() => {
this._changeValue = false;
this.approvalFormControl.setValue(this.resolveApprovalValue());
})
this._subCases = this._caseViewService.cases$.subscribe(() => {
this._changeValue = false;
this.approvalFormControl.setValue(this.resolveApprovalValue());
})
}
if (this._dataFieldPortalData !== null && this._dataFieldPortalData.dataField instanceof EnumerationField) {
this.approvalFormControl.valueChanges.subscribe(value => {
this._dataFieldPortalData.dataField.value = null;
})
}
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Improve null checks and clarify EnumerationField behavior.

  1. The null check should also handle undefined:
-if (this._dataFieldPortalData !== null && this._dataFieldPortalData.dataField instanceof MultichoiceField && this._caseViewService) {
+if (this._dataFieldPortalData && this._dataFieldPortalData.dataField instanceof MultichoiceField && this._caseViewService) {
  1. For EnumerationField, the approval control always sets the field value to null. Is this the intended behavior? It seems destructive and might confuse users.

Consider splitting this method into separate handlers for each field type to improve readability and maintainability.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
protected resolveApprovalDatafields() {
if (this._dataFieldPortalData !== null && this._dataFieldPortalData.dataField instanceof MultichoiceField && this._caseViewService) {
this.approvalFormControl.setValue(this.resolveApprovalValue());
this.approvalFormControl.valueChanges.subscribe(value => {
if (this._changeValue) {
if (value) {
this._dataFieldPortalData.dataField.value = this._caseViewService.cases.map(caze => caze.stringId);
} else {
this._dataFieldPortalData.dataField.value = [];
}
}
this._changeValue = true;
})
this._dataFieldPortalData.dataField.valueChanges().subscribe(() => {
this._changeValue = false;
this.approvalFormControl.setValue(this.resolveApprovalValue());
})
this._subCases = this._caseViewService.cases$.subscribe(() => {
this._changeValue = false;
this.approvalFormControl.setValue(this.resolveApprovalValue());
})
}
if (this._dataFieldPortalData !== null && this._dataFieldPortalData.dataField instanceof EnumerationField) {
this.approvalFormControl.valueChanges.subscribe(value => {
this._dataFieldPortalData.dataField.value = null;
})
}
}
protected resolveApprovalDatafields() {
if (this._dataFieldPortalData && this._dataFieldPortalData.dataField instanceof MultichoiceField && this._caseViewService) {
this.approvalFormControl.setValue(this.resolveApprovalValue());
this.approvalFormControl.valueChanges.subscribe(value => {
if (this._changeValue) {
if (value) {
this._dataFieldPortalData.dataField.value = this._caseViewService.cases.map(caze => caze.stringId);
} else {
this._dataFieldPortalData.dataField.value = [];
}
}
this._changeValue = true;
})
this._dataFieldPortalData.dataField.valueChanges().subscribe(() => {
this._changeValue = false;
this.approvalFormControl.setValue(this.resolveApprovalValue());
})
this._subCases = this._caseViewService.cases$.subscribe(() => {
this._changeValue = false;
this.approvalFormControl.setValue(this.resolveApprovalValue());
})
}
if (this._dataFieldPortalData !== null && this._dataFieldPortalData.dataField instanceof EnumerationField) {
this.approvalFormControl.valueChanges.subscribe(value => {
this._dataFieldPortalData.dataField.value = null;
})
}
}
🤖 Prompt for AI Agents
In projects/netgrif-components-core/src/lib/header/abstract-header.component.ts
around lines 233 to 260, update the null checks to also handle undefined values
for _dataFieldPortalData to make the checks more robust. Review the logic for
EnumerationField where approvalFormControl.valueChanges always sets the
dataField value to null, confirm if this is intended or if it should preserve or
update the value differently to avoid unintended data loss. Refactor the
resolveApprovalDatafields method by splitting the logic into separate handler
methods for MultichoiceField and EnumerationField to improve code readability
and maintainability.

Copy link

sonarqubecloud bot commented Jun 5, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
14.8% 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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants