Skip to content
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

fix evidence statuses across app #80

Merged
merged 3 commits into from
Feb 25, 2025
Merged

fix evidence statuses across app #80

merged 3 commits into from
Feb 25, 2025

Conversation

Marfuen
Copy link
Contributor

@Marfuen Marfuen commented Feb 25, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced control processing by generating evidence records before evaluating requirements.
    • Dashboard now reflects updated control statuses based on the publication state of evidence.
    • Additional organization evidence data is now included in various data retrieval processes.
  • Refactor

    • Streamlined data fetching and display logic for control details, ensuring a clearer overview.
    • Improved type safety and clarity in data handling within the DataTable component.
  • Chores

    • Improved database relationships and applied schema migrations to better integrate evidence and policy data.

Copy link

vercel bot commented Feb 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 25, 2025 7:25pm
comp-portal ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 25, 2025 7:25pm
web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 25, 2025 7:25pm

Copy link

coderabbitai bot commented Feb 25, 2025

Walkthrough

This pull request modifies the ordering and handling of organization evidence and control requirements. In the business logic, evidence is now created before control requirements, and the related functions are updated to fetch and link the evidence appropriately. The data queries for controls and categories have been enhanced to include nested relations for evidence and policy, and UI components have been refactored to use new types and data sources. Additionally, the database schema and migrations are adjusted to add new columns and relationships for organization evidence and policies, and the seeding function now explicitly links evidence records to control requirements.

Changes

File(s) Change Summary
apps/app/src/actions/framework/select-frameworks-action.ts Modified selectFrameworksAction to create organization evidence before control requirements; added createOrganizationEvidence and updated evidence fetching and linking logic.
apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Actions/getOrganizationControl.ts
apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Actions/getOrganizationControlProgress.ts
apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Actions/getOrganizationControlRequirements.ts
Updated control actions: removed obsolete interfaces, enhanced database queries to include nested relations (evidence, policy, controlRequirement), and refined completion criteria for evidence requirements by checking the published state.
apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/SingleControl.tsx
apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/columns.tsx
apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/data-table-header.tsx
apps/app/src/app/(...)/data-table/data-table.tsx
apps/app/src/app/(...)/data-table/types.ts
Refactored UI components for control displays: removed a redundant hook, replaced RequirementType with RequirementTableData, updated props and cell-rendering logic, and introduced a new type (RequirementWithRelations) for clearer data handling.
apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/hooks/useOrganizationControl.ts Simplified hook implementation by removing the explicit OrganizationControlResponse type and deducing types with useSWR.
apps/app/src/app/[locale]/(app)/(dashboard)/frameworks/[frameworkId]/Actions/getOrganizationCategories.ts Enhanced the database query to include the published field from organizationEvidence when fetching organization categories.
apps/app/src/components/tables/frameworks/columns.tsx Added an organizationEvidence property (with a published flag) to the type definitions and updated the control status logic to utilize this property.
packages/db/prisma/migrations/*migration.sql Grouped Migrations: Added new columns (organizationPolicyId and organizationEvidenceId) to the OrganizationControlRequirement table along with foreign key constraints to OrganizationPolicy and OrganizationEvidence, respectively.
packages/db/prisma/schema.prisma Modified Prisma schema: added organizationEvidenceId to the OrganizationControlRequirement model and defined a relation to OrganizationEvidence; updated the OrganizationEvidence model to associate with control requirements; applied formatting adjustments.
packages/db/prisma/seed.ts Updated the seedEvidence function to upsert evidence records and subsequently update control requirements with the new evidence record IDs, including added logging for confirmation.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant SF as selectFrameworksAction
  participant OE as createOrganizationEvidence
  participant CCR as createOrganizationControlRequirements
  participant DB as Database

  U->>SF: Initiate framework selection
  SF->>OE: Create organization evidence
  OE->>DB: Insert new evidence record
  DB-->>OE: Return evidence data
  SF->>CCR: Create control requirements
  CCR->>DB: Query with evidence & policy inclusions
  DB-->>CCR: Return control requirements
  SF-->>U: Return updated control data
Loading
sequenceDiagram
  participant S as seedEvidence
  participant DB as Prisma
  participant CR as ControlRequirement

  S->>DB: Upsert evidence record
  DB-->>S: New evidence created
  S->>DB: Update control requirement with evidenceId
  DB-->>S: Control requirement linked
  S->>Console: Log success message
Loading

Possibly related PRs

  • add baseline migrations #48: Involves modifications to the handling of organization evidence and control requirements, specifically affecting database relations and queries.
  • Add statuses and keep track of policies across controls #64: Addresses changes in the selectFrameworksAction function and the creation of control requirements with enhanced evidence handling.
  • Mariano/stuff #77: Focuses on adjustments to the createOrganizationEvidence function and related data structures, aligning closely with the current PR modifications.

Poem

I'm a bunny with code so neat,
Hopping through functions with a rhythmic beat.
Evidence comes first, then controls align,
In our schema and UI—everything's fine.
With each migration and logical tweak,
I celebrate changes with a happy squeak!
🐇✨


📜 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 414d840 and d395ebb.

⛔ Files ignored due to path filters (2)
  • bun.lockb is excluded by !**/bun.lockb
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/SingleControl.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/SingleControl.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.

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. (Beta)
  • @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: 2

🧹 Nitpick comments (2)
apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/data-table.tsx (1)

38-55: Improved navigation logic with switch statement.

The refactored onRowClick function with a switch statement is cleaner and more maintainable than nested conditions. It provides a clear and scalable way to handle different requirement types.

Consider removing the console.log statements in lines 39-41 before deploying to production:

-  console.log({
-    requirement,
-  });
apps/app/src/actions/framework/select-frameworks-action.ts (1)

246-260: Remove debug logging statements.

The console.log statements should be removed before merging to production as they may impact performance and pollute the logs.

-        console.log({
-          evidenceId,
-        });

-        console.log({
-          organizationEvidence,
-        });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 12550f7 and 414d840.

📒 Files selected for processing (16)
  • apps/app/src/actions/framework/select-frameworks-action.ts (4 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Actions/getOrganizationControl.ts (2 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Actions/getOrganizationControlProgress.ts (2 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Actions/getOrganizationControlRequirements.ts (1 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/SingleControl.tsx (3 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/columns.tsx (2 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/data-table-header.tsx (1 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/data-table.tsx (2 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/types.ts (1 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/hooks/useOrganizationControl.ts (2 hunks)
  • apps/app/src/app/[locale]/(app)/(dashboard)/frameworks/[frameworkId]/Actions/getOrganizationCategories.ts (1 hunks)
  • apps/app/src/components/tables/frameworks/columns.tsx (3 hunks)
  • packages/db/prisma/migrations/20250218202303_add_organization_policy_to_org_control_req/migration.sql (1 hunks)
  • packages/db/prisma/migrations/20250225000803_add_org_ev_relation_to_org_ctrl_req/migration.sql (1 hunks)
  • packages/db/prisma/schema.prisma (3 hunks)
  • packages/db/prisma/seed.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/db/prisma/migrations/20250218202303_add_organization_policy_to_org_control_req/migration.sql
🔇 Additional comments (26)
apps/app/src/app/[locale]/(app)/(dashboard)/frameworks/[frameworkId]/Actions/getOrganizationCategories.ts (1)

65-69: Appropriate inclusion of organizationEvidence

The addition of organizationEvidence in the query's include clause is well-structured and consistent with the PR objective of fixing evidence statuses across the app. This change allows the published status of evidence to be retrieved alongside policy status, which will help in determining the overall status of control requirements.

apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Actions/getOrganizationControl.ts (1)

34-39: Improved data retrieval with related entities

The inclusion of OrganizationControlRequirement with its related organizationPolicy and organizationEvidence entities enhances the data retrieval process. This change aligns well with the PR objective of fixing evidence statuses across the app by ensuring all required data is fetched in a single query.

apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/SingleControl.tsx (1)

65-67:

✅ Verification successful

Verify that the DataTable component accepts the correct data format

The conditional check and data passing might need adjustment depending on the actual structure of control.OrganizationControlRequirement. If it's an array (as suggested by database queries in other files), consider checking the array length instead.

-{control.OrganizationControlRequirement && (
+{control.OrganizationControlRequirement?.length > 0 && (
  <DataTable data={control.OrganizationControlRequirement} />
)}

Additionally, ensure that the DataTable component is designed to accept the data in this format, as it was previously receiving data from the now-removed useOrganizationControlRequirements hook.


🏁 Script executed:

#!/bin/bash
# Check the DataTable component implementation to verify expected props

echo "Checking DataTable component implementation:"
cat "apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/data-table.tsx" | grep -A 10 "interface" || echo "No interface definition found"

echo "\nChecking DataTable usage elsewhere:"
rg "DataTable\s+data=" --type=tsx -A 2

Length of output: 620


Action: Confirm the proper array check for DataTable usage

  • The DataTable component’s interface clearly defines its data prop as an array (RequirementTableData[]), so verifying that the data is non-empty by performing a length check is appropriate.
  • Changing the conditional from checking a truthy value to checking that control.OrganizationControlRequirement?.length > 0 ensures that the component is only rendered when an array with at least one element is available.
  • Diff Suggestion:
    -  {control.OrganizationControlRequirement && (
    +  {control.OrganizationControlRequirement?.length > 0 && (
         <DataTable data={control.OrganizationControlRequirement} />
    -)}
    +)}
  • Please ensure that control.OrganizationControlRequirement is always returned as an array (even if empty) to maintain consistency across the codebase.
apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Actions/getOrganizationControlRequirements.ts (2)

38-47: Enhanced query with nested includes for comprehensive data retrieval

The addition of nested includes for organizationControl and controlRequirement improves the data fetching strategy by retrieving related entities in a single query. This change ensures you have access to the control and evidence data when processing control requirements.


53-53: Included organizationEvidence in the query

Including organizationEvidence in the query is essential for the PR objective of fixing evidence statuses across the app. This change works in conjunction with the database schema modifications and UI status checks.

packages/db/prisma/seed.ts (3)

391-407: Improved evidence record tracking with variable assignment

Storing the result of the upsert operation in the evidence variable enables the link-back operation in the next step. This is good practice as it avoids duplicate database queries.


409-417: Added explicit linking between evidence and control requirements

This change ensures a bidirectional relationship between evidence records and control requirements, which is crucial for maintaining data integrity and the proper functioning of evidence status tracking across the application.


419-419: Added helpful logging for tracking seeding progress

The log message clearly indicates both processing and linking, providing better visibility into the seeding process. This is especially helpful when debugging data relationship issues.

packages/db/prisma/migrations/20250225000803_add_org_ev_relation_to_org_ctrl_req/migration.sql (2)

1-2: Added organizationEvidenceId column to support evidence relationship

This migration adds the necessary database column to store the association between organization control requirements and organization evidence. This is a foundational change for the PR objective of fixing evidence statuses.


4-5: Added cascade foreign key constraint for data integrity

The foreign key constraint ensures referential integrity between the OrganizationControlRequirement and OrganizationEvidence tables. The cascade behavior on delete and update ensures that related records stay in sync, preventing orphaned references.

apps/app/src/components/tables/frameworks/columns.tsx (3)

35-37: Added organizationEvidence type with published flag

This type definition enhancement properly models the relationship between organization control requirements and organization evidence, with the published flag being crucial for status tracking.


54-54: Updated evidence status check to use published flag

This change fixes the status logic for evidence requirements by checking the published state of the related organization evidence rather than content existence. This aligns with the PR objective of fixing evidence statuses.


115-115: Consistent evidence status implementation in table columns

The same status check logic is correctly applied in the table columns, ensuring consistent status determination throughout the UI. This parallel change maintains code consistency and prevents status discrepancies.

apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/data-table-header.tsx (1)

4-5: Good type safety improvements.

The changes correctly implement proper type safety by:

  1. Importing the specific Table type from @tanstack/react-table
  2. Using the RequirementTableData type for table data
  3. Making the table prop required rather than optional
  4. Removing optional chaining where it's no longer needed

These changes will help prevent type-related bugs and improve code maintainability.

Also applies to: 8-8, 16-16

apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Actions/getOrganizationControlProgress.ts (2)

45-45: Good addition to include organizationEvidence in the query.

Including organizationEvidence in the query ensures that the evidence data is available for status checking, which aligns with the PR objective of fixing evidence statuses.


78-78: Correct implementation of evidence status check.

The logic update properly checks for published status on organization evidence, consistent with how other requirement types are handled (e.g., policy type).

apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/hooks/useOrganizationControl.ts (1)

4-4:

✅ Verification successful

Type simplification looks good but ensure type inference works correctly.

The removal of explicit type annotations simplifies the code but relies on TypeScript's type inference. This should be fine as long as the inferred types match the expected types throughout the application.

Also applies to: 6-6, 22-29


🏁 Script executed:

#!/bin/bash
# Check the return type of getOrganizationControl to ensure type inference works correctly
rg -A 5 "export const getOrganizationControl" --type ts

Length of output: 3438


Subject: Type Inference Validated for Organization Control Hook

The explicit type annotations have been removed, and our check confirms that TypeScript correctly infers the return types from the associated zod schema in getOrganizationControl (as defined in Actions/getOrganizationControl.ts). The inferred types appear to match the expected structure, ensuring that the type simplification does not introduce discrepancies.

  • In apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/hooks/useOrganizationControl.ts (line 4), the import and subsequent usage rely on inferred types from getOrganizationControl.
  • Similar patterns at lines 6-6 and 22-29 follow the same inference mechanism, which is consistent with our investigation.

Given these findings, the refactoring to depend on type inference is sound.

apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/columns.tsx (1)

5-5: Good update to use RequirementTableData type.

The column definitions now properly use the RequirementTableData type, which aligns with the changes in the rest of the application.

Also applies to: 7-7

apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/data-table.tsx (1)

19-23: Good addition of RequirementTableData type that extends OrganizationControlRequirement.

This type definition improves type safety by explicitly defining the shape of data expected from your data source, including the relationships to OrganizationPolicy and OrganizationEvidence.

packages/db/prisma/schema.prisma (3)

293-298: Improved formatting for consistency.

The realignment of the OrganizationControl model properties improves readability and maintains consistent formatting across the schema file.


975-976: Proper relation between OrganizationControlRequirement and OrganizationEvidence.

The new bidirectional relation allows for efficient queries in both directions and ensures referential integrity with the Cascade delete behavior, which is appropriate for this parent-child relationship.


1064-1066: Established proper reverse relation for OrganizationEvidence.

Completing the bidirectional relation from the OrganizationEvidence side enables efficient querying of related requirements, enhancing the overall data model integrity.

apps/app/src/actions/framework/select-frameworks-action.ts (4)

46-50: Correctly reordered operations to create evidence before requirements.

This change ensures that organization evidence records exist before control requirements are created, fixing a potential issue where requirements might reference non-existent evidence.


214-215: Good inclusion of evidence in control requirements query.

Including the evidence relationship in the query ensures you have all necessary data to establish the proper connections between requirements and evidence.


225-231: Added comprehensive fetch of organization evidences.

Retrieving all organization evidences for the user's organization is an efficient approach to have the complete dataset available for linking with requirements.


267-268: Proper linking of evidence to control requirements.

Including the organizationEvidenceId in the createMany operation ensures that control requirements are correctly linked to their respective organization evidence, which is essential for the status tracking functionality.

Comment on lines +8 to +14
// Define a type for the data returned by the useOrganizationControlRequirements hook
export type RequirementWithRelations = OrganizationControl & {
OrganizationControlRequirement: OrganizationControlRequirement & {
organizationPolicy: OrganizationPolicy;
organizationEvidence: OrganizationEvidence;
};
};
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Type definition may need an array notation

The type definition suggests that an OrganizationControl has a single OrganizationControlRequirement, but based on the query structure in other files (like getOrganizationCategories.ts), it appears that an OrganizationControl can have multiple requirements.

Consider updating the type definition to use an array:

export type RequirementWithRelations = OrganizationControl & {
-  OrganizationControlRequirement: OrganizationControlRequirement & {
+  OrganizationControlRequirement: (OrganizationControlRequirement & {
     organizationPolicy: OrganizationPolicy;
     organizationEvidence: OrganizationEvidence;
-  };
+  })[];
};

🏁 Script executed:

#!/bin/bash
# Check if OrganizationControlRequirement is defined as an array in database schema or other type definitions

# Look for OrganizationControl relation definitions
echo "Checking OrganizationControl relation definitions:"
rg -A 5 "OrganizationControl\s*{" --type=ts

# Check how OrganizationControlRequirement is used in queries
echo "\nChecking how OrganizationControlRequirement is queried:"
rg "OrganizationControlRequirement\W+\{" --type=ts -A 2

Length of output: 2924


Action Required: Update type definition for OrganizationControlRequirement to an array

Based on our review of the code and how OrganizationControlRequirement is used across the codebase (e.g., in the getOrganizationCategories.ts file), it appears that an OrganizationControl can have multiple requirements. To maintain consistency with other parts of the code (where the property is declared with array notation), please update the type definition in:

apps/app/src/app/[locale]/(app)/(dashboard)/controls/[id]/Components/data-table/types.ts

Specifically, change the current definition:

export type RequirementWithRelations = OrganizationControl & {
-  OrganizationControlRequirement: OrganizationControlRequirement & {
-    organizationPolicy: OrganizationPolicy;
-    organizationEvidence: OrganizationEvidence;
-  };
+  OrganizationControlRequirement: (OrganizationControlRequirement & {
+    organizationPolicy: OrganizationPolicy;
+    organizationEvidence: OrganizationEvidence;
+  })[];
};

This change will align the type with how it's handled in other query files (such as getOrganizationCategories.ts) and avoid potential runtime issues where multiple requirements are expected.

📝 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
// Define a type for the data returned by the useOrganizationControlRequirements hook
export type RequirementWithRelations = OrganizationControl & {
OrganizationControlRequirement: OrganizationControlRequirement & {
organizationPolicy: OrganizationPolicy;
organizationEvidence: OrganizationEvidence;
};
};
// Define a type for the data returned by the useOrganizationControlRequirements hook
export type RequirementWithRelations = OrganizationControl & {
OrganizationControlRequirement: (OrganizationControlRequirement & {
organizationPolicy: OrganizationPolicy;
organizationEvidence: OrganizationEvidence;
})[];
};

Comment on lines +31 to +33
: requirement.type === "evidence"
? requirement.organizationEvidence?.published
: false;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Inconsistent handling of different requirement types.

While the evidence type logic is correctly implemented, the current implementation only handles "policy" and "evidence" types, defaulting all other types to false. This doesn't match the more comprehensive switch statement in getOrganizationControlProgress.ts which also handles "file" type and has a different default case.

Consider updating the logic to handle all requirement types consistently:

      const isCompleted =
        requirement.type === "policy"
          ? requirement.organizationPolicy?.status === "published"
-          : requirement.type === "evidence"
-            ? requirement.organizationEvidence?.published
-            : false;
+          : requirement.type === "evidence"
+            ? requirement.organizationEvidence?.published === true
+            : requirement.type === "file"
+              ? !!requirement.fileUrl
+              : requirement.published;
📝 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
: requirement.type === "evidence"
? requirement.organizationEvidence?.published
: false;
const isCompleted =
requirement.type === "policy"
? requirement.organizationPolicy?.status === "published"
: requirement.type === "evidence"
? requirement.organizationEvidence?.published === true
: requirement.type === "file"
? !!requirement.fileUrl
: requirement.published;

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.

1 participant