Skip to content

Fix undefined subcontrols #1321

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 3 commits into
base: develop
Choose a base branch
from
Open

Conversation

HarshP4585
Copy link
Collaborator

@HarshP4585 HarshP4585 commented May 8, 2025

Describe your changes

  • Fix undefined sub-controls due to API changes
image

Write your issue number after "Fixes "

Fixes #1320

Please ensure all items are checked off before requesting a review:

  • I deployed the code locally.
  • I have performed a self-review of my code.
  • I have included the issue # in the PR.
  • I have labelled the PR correctly.
  • The issue I am working on is assigned to me.
  • I didn't use any hardcoded values (otherwise it will not scale, and will make it difficult to maintain consistency across the application).
  • I made sure font sizes, color choices etc are all referenced from the theme.
  • My PR is granular and targeted to one specific feature.
  • I took a screenshot or a video and attached to this PR if there is a UI change.

Summary by CodeRabbit

  • New Features

    • Controls in the Compliance Tracker now display detailed subcontrol information, including counts of total and completed subcontrols.
  • Bug Fixes

    • Progress metrics in project assessment and compliance responses are now consistently returned as integers.
  • Refactor

    • Improved the way control data is managed and displayed in modals for a more streamlined user experience.
    • Enhanced update functions to avoid unnecessary database queries when no changes are provided.

@HarshP4585 HarshP4585 self-assigned this May 8, 2025
@HarshP4585 HarshP4585 added bug Something isn't working frontend Frontend related tasks/issues backend Backend related tasks/issues labels May 8, 2025
Copy link
Contributor

coderabbitai bot commented May 8, 2025

Walkthrough

The changes refactor the NewControlPane component to remove internal data fetching and state management, instead relying on enriched control data passed as props. The controls table page now fetches and attaches subcontrol counts to each control before rendering. Server-side, helper functions and return types are updated to provide subcontrol aggregation and type consistency.

Changes

File(s) Change Summary
Clients/src/presentation/components/Modals/Controlpane/NewControlPane.tsx Refactored to remove internal state and async data fetching; expects fully populated data prop; prop renamed from _data to data; removed projectFrameworkId prop.
Clients/src/presentation/pages/ComplianceTracker/1.0ComplianceTracker/ControlsTable.tsx Fetches subcontrol details for each control and augments control objects with subcontrol counts before updating state; updates prop name to data for NewControlPane and removes projectFrameworkId prop.
Servers/controllers/eu.ctrl.ts Ensures numeric fields in API responses are explicitly converted to integers using parseInt() in assessment and compliance progress endpoints.
Servers/utils/eu.utils.ts Adds getSubControlsCalculations helper for subcontrol counts; augments control object with subcontrol counts; improves update functions to avoid empty updates and clarifies return types.

Sequence Diagram(s)

sequenceDiagram
    participant UI as ControlsTable
    participant API as API Server
    participant DB as Database

    UI->>API: Fetch controls by category ID
    API->>DB: Query controls list
    DB-->>API: Return controls
    loop For each control
        UI->>API: Fetch subcontrol counts for control ID
        API->>DB: Query subcontrol count and done count
        DB-->>API: Return subcontrol counts
        API-->>UI: Return subcontrol counts
        UI->>UI: Attach subcontrol counts to control
    end
    UI->>UI: Render ControlsTable with enriched controls
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Ensure subcontrol counts/details are defined and available for controls (#1320)

Poem

A hop and a leap through code anew,
Subcontrols now counted, their numbers in view.
No more undefined, the data flows right,
From backend to frontend, all clear in sight.
With carrots and queries, the tracker’s refined—
A rabbit’s delight in the progress we find! 🥕


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1d415bf and 8ce7b23.

📒 Files selected for processing (2)
  • Clients/src/presentation/components/Modals/Controlpane/NewControlPane.tsx (3 hunks)
  • Clients/src/presentation/pages/ComplianceTracker/1.0ComplianceTracker/ControlsTable.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • Clients/src/presentation/pages/ComplianceTracker/1.0ComplianceTracker/ControlsTable.tsx
  • Clients/src/presentation/components/Modals/Controlpane/NewControlPane.tsx
✨ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

@HarshP4585 HarshP4585 mentioned this pull request May 8, 2025
@charurajput16
Copy link
Contributor

@HarshP4585 - Thank you Harsh! This is working now.

Comment on lines +130 to +137
let _response = []
for (let control of response) {
const subControlsResponse = await getEntityById({
routeUrl: `eu-ai-act/controlById?controlId=${control.id}&projectFrameworkId=${projectFrameworkId}`,
});
_response.push({...subControlsResponse.data, ...control});
}
setControls(_response);
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a few issues to address here. First, we are making multiple asynchronous requests inside a for loop, which results in sequential execution. This means that the next fetch will not start until the previous one has completed, significantly slowing down performance.

To improve this, we should create a specific endpoint that retrieves all the data from the controls and subcontrols in a single call.

Additionally, it would be beneficial to move the logic for calling the API to a dedicated hook, which we can name useControls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Backend related tasks/issues bug Something isn't working frontend Frontend related tasks/issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Undefined Subcontrols
3 participants