Skip to content

Conversation

Aryanak47
Copy link
Contributor

  • Added missing "Deprecated" status option to dropdown
  • Set default status for new policies to "Under Review"
  • Added comprehensive client-side validation for title, content length, and initial status
  • Implemented server error handling and mapping to display validation errors in UI

Provide a concise description of the changes made and their intended purpose.

Write your issue number after "Fixes "

Fixes #2279

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 have avoided using hardcoded values to ensure scalability and maintain consistency across the application.
  • I have ensured that font sizes, color choices, and other UI elements are referenced from the theme.
  • My pull request is focused and addresses a single, specific feature.
  • If there are UI changes, I have attached a screenshot or video to this PR.
image image

… server expectations

  - Add missing "Deprecated" status option to dropdown
  - Set default status for new policies to "Under Review"
  - Add comprehensive client-side validation for title, content length, and initial status
  - Implement server error handling and mapping to display validation errors in UI
Copy link
Contributor

coderabbitai bot commented Oct 2, 2025

Walkthrough

Adds policy content field and validation to PolicyDetailsModal, updates default status to "Under Review", enhances server-side error extraction/mapping (including content and tags), and displays inline error messages. PolicyForm updates status options ("Under Review", adds "Deprecated") and shows inline tags error.

Changes

Cohort / File(s) Summary of Edits
Policy Modal: content + error handling
Clients/src/presentation/components/Policies/PolicyDetailsModal.tsx
- Extend FormErrors with optional content
- Add content field to form state and validate it
- Default status set to "Under Review"
- Enhance save error handling: parse nested server validation errors and map to local fields (title, status, tags, content, nextReviewDate, assignedReviewers)
- Render content-specific error under editor
Policy Form: status options + tags error UI
Clients/src/presentation/components/Policies/PolicyForm.tsx
- Replace "In review" with "Under Review"; add "Deprecated"
- Show inline tags error message under Tags Autocomplete

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant M as PolicyDetailsModal
  participant API as Policies API

  U->>M: Click Save
  M->>API: POST/PUT policy {title, status, tags, content, ...}
  alt Success
    API-->>M: 200 OK {policy}
    M-->>U: Close modal / refresh
  else Validation Error
    API-->>M: 400 {errors: {title|status|tags|content|...}}
    M->>M: Map server fields to FormErrors
    M-->>U: Show inline errors (incl. content & tags)
  else Other Error
    API-->>M: 5xx / network error
    M->>M: Log extended error info
    M-->>U: Show generic failure
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I nibble through forms with careful delight,
New “Under Review” gleams crisp and bright.
Tags and content, errors now speak,
Server whispers mapped, field by field, sleek.
A hop, a save—no burrowed doubt,
Policies polished—approved with a sprout! 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 2 inconclusive)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The pull request introduces a new “Deprecated” status option and tag error UI enhancements that were not specified in the QA/QC CRUD testing objectives of issue #2279, suggesting these additions fall outside the linked issue’s scope. Please remove or split out the new “Deprecated” status addition and tag error display changes into a separate pull request or link them to the relevant issue where these features were requested.
Title Check ❓ Inconclusive The title “Fix CRUD issue in policy manager” is overly generic and fails to specify which CRUD operations or changes were made in the Policy Manager form, such as adding content validation, new status options, and enhanced error handling. Please update the title to something more specific and focused, for example “Add content validation and default status update in Policy Manager form,” to clearly reflect the key changes.
Linked Issues Check ❓ Inconclusive The changes add missing status options, default status updates, client-side validation, and server error mapping which correspond to improving the create and update flows in the Policy Manager, but the linked issue #2279 only broadly covers QA/QC of CRUD operations without detailing specific coding requirements, making it unclear if all test scenarios are addressed. Please verify that these updates satisfy each of the specific CRUD test scenarios defined in issue #2268 and document which cases are now passing as a result of this work.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed The pull request description provides a detailed list of changes, includes the “Fixes #2279” identifier, a full checklist, and attached screenshots, so it covers the template’s required content even though the explicit “## Describe your changes” heading was not used.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch yb-oct-2-fix-policy-manager

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.

Copy link
Contributor

@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 (1)
Clients/src/presentation/components/Policies/PolicyDetailsModal.tsx (1)

90-131: Consider adding client-side content validation.

The validateForm function validates title, status, tags, nextReviewDate, and assignedReviewers, but does not validate the content field despite FormErrors.content being defined. While server-side validation exists (lines 246-247), adding client-side validation would provide immediate feedback to users.

Consider adding content validation:

     if (policyAssignedReviewers.length === 0) {
       newErrors.assignedReviewers = "At least one reviewer is required";
     }
+
+    // Content validation
+    const contentHtml = await serializeHtml(editor);
+    const contentText = contentHtml.replace(/<[^>]*>/g, '').trim();
+    if (contentText.length === 0) {
+      newErrors.content = "Content is required";
+    } else if (contentText.length > 10000) {
+      newErrors.content = "Content exceeds maximum length of 10,000 characters";
+    }
 
     setErrors(newErrors);
     return Object.keys(newErrors).length === 0;

Note: This would require making validateForm async or moving content validation to the save function.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 566e48c and 0e996b7.

📒 Files selected for processing (2)
  • Clients/src/presentation/components/Policies/PolicyDetailsModal.tsx (7 hunks)
  • Clients/src/presentation/components/Policies/PolicyForm.tsx (2 hunks)
🔇 Additional comments (5)
Clients/src/presentation/components/Policies/PolicyForm.tsx (2)

36-43: LGTM! Status options updated correctly.

The status list now includes "Under Review" (replacing "In review") and the new "Deprecated" option, aligning with the PR objectives and maintaining consistency with PolicyDetailsModal.tsx.


276-288: LGTM! Tags error display implemented correctly.

The inline error message for tags follows consistent styling patterns and uses theme colors appropriately. The implementation aligns well with the content error display in PolicyDetailsModal.tsx.

Clients/src/presentation/components/Policies/PolicyDetailsModal.tsx (3)

44-51: LGTM! FormErrors interface appropriately extended.

The addition of the optional content field enables validation error tracking for the policy content, consistent with other form fields.


133-140: LGTM! Default status correctly set to "Under Review".

Both the initial formData state (line 135) and the reset state for new policies (line 161) now default to "Under Review", fulfilling the PR objective and maintaining consistency with the updated status options.

Also applies to: 159-166


492-504: LGTM! Content error display implemented correctly.

The inline error message for content follows consistent styling patterns, uses theme colors with an appropriate fallback, and maintains visual consistency with the tags error display in PolicyForm.tsx.

Comment on lines +225 to 259
} catch (err: any) {
// setIsSubmitting(false);
console.error(err);
console.error("Full error object:", err);
console.error("Original error:", err?.originalError);
console.error("Original error response:", err?.originalError?.response);

// Handle server validation errors - the CustomException is in originalError
const errorData = err?.originalError?.response || err?.response?.data || err?.response;
console.error("Error data:", errorData);

if (errorData?.errors) {
console.error("Processing server errors:", errorData.errors);
const serverErrors: FormErrors = {};
errorData.errors.forEach((error: any) => {
console.error("Processing error:", error);
if (error.field === 'title') {
serverErrors.title = error.message;
} else if (error.field === 'status') {
serverErrors.status = error.message;
} else if (error.field === 'tags') {
serverErrors.tags = error.message;
} else if (error.field === 'content_html') {
serverErrors.content = error.message;
} else if (error.field === 'next_review_date') {
serverErrors.nextReviewDate = error.message;
} else if (error.field === 'assigned_reviewer_ids') {
serverErrors.assignedReviewers = error.message;
}
});
console.error("Setting server errors:", serverErrors);
setErrors(serverErrors);
} else {
console.error("No errors found in response");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove excessive console.error statements before production.

The error handling logic correctly extracts and maps server validation errors to the form state. However, there are 8 console.error statements (lines 227-230, 233, 236, 239, 254, 257) that appear to be debugging artifacts.

Apply this diff to remove debugging console statements:

     } catch (err: any) {
       // setIsSubmitting(false);
-      console.error("Full error object:", err);
-      console.error("Original error:", err?.originalError);
-      console.error("Original error response:", err?.originalError?.response);
-      
       // Handle server validation errors - the CustomException is in originalError
       const errorData = err?.originalError?.response || err?.response?.data || err?.response;
-      console.error("Error data:", errorData);
       
       if (errorData?.errors) {
-        console.error("Processing server errors:", errorData.errors);
         const serverErrors: FormErrors = {};
         errorData.errors.forEach((error: any) => {
-          console.error("Processing error:", error);
           if (error.field === 'title') {
             serverErrors.title = error.message;
           } else if (error.field === 'status') {
             serverErrors.status = error.message;
           } else if (error.field === 'tags') {
             serverErrors.tags = error.message;
           } else if (error.field === 'content_html') {
             serverErrors.content = error.message;
           } else if (error.field === 'next_review_date') {
             serverErrors.nextReviewDate = error.message;
           } else if (error.field === 'assigned_reviewer_ids') {
             serverErrors.assignedReviewers = error.message;
           }
         });
-        console.error("Setting server errors:", serverErrors);
         setErrors(serverErrors);
-      } else {
-        console.error("No errors found in response");
       }
     }
📝 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
} catch (err: any) {
// setIsSubmitting(false);
console.error(err);
console.error("Full error object:", err);
console.error("Original error:", err?.originalError);
console.error("Original error response:", err?.originalError?.response);
// Handle server validation errors - the CustomException is in originalError
const errorData = err?.originalError?.response || err?.response?.data || err?.response;
console.error("Error data:", errorData);
if (errorData?.errors) {
console.error("Processing server errors:", errorData.errors);
const serverErrors: FormErrors = {};
errorData.errors.forEach((error: any) => {
console.error("Processing error:", error);
if (error.field === 'title') {
serverErrors.title = error.message;
} else if (error.field === 'status') {
serverErrors.status = error.message;
} else if (error.field === 'tags') {
serverErrors.tags = error.message;
} else if (error.field === 'content_html') {
serverErrors.content = error.message;
} else if (error.field === 'next_review_date') {
serverErrors.nextReviewDate = error.message;
} else if (error.field === 'assigned_reviewer_ids') {
serverErrors.assignedReviewers = error.message;
}
});
console.error("Setting server errors:", serverErrors);
setErrors(serverErrors);
} else {
console.error("No errors found in response");
}
}
} catch (err: any) {
// setIsSubmitting(false);
// Handle server validation errors - the CustomException is in originalError
const errorData = err?.originalError?.response || err?.response?.data || err?.response;
if (errorData?.errors) {
const serverErrors: FormErrors = {};
errorData.errors.forEach((error: any) => {
if (error.field === 'title') {
serverErrors.title = error.message;
} else if (error.field === 'status') {
serverErrors.status = error.message;
} else if (error.field === 'tags') {
serverErrors.tags = error.message;
} else if (error.field === 'content_html') {
serverErrors.content = error.message;
} else if (error.field === 'next_review_date') {
serverErrors.nextReviewDate = error.message;
} else if (error.field === 'assigned_reviewer_ids') {
serverErrors.assignedReviewers = error.message;
}
});
setErrors(serverErrors);
}
}
🤖 Prompt for AI Agents
In Clients/src/presentation/components/Policies/PolicyDetailsModal.tsx around
lines 225 to 259, remove the debugging console.error statements (the multiple
logs printing the full error object, originalError, response, intermediate
"Processing..." logs and "Setting server errors"/"No errors found" logs) and
leave only the functional error-handling logic that extracts errorData, maps
server validation errors into the serverErrors object and calls
setErrors(serverErrors); ensure no other behavior is changed.

@gorkem-bwl
Copy link
Contributor

LGTM!

@MuhammadKhalilzadeh MuhammadKhalilzadeh merged commit 264e28c into develop Oct 3, 2025
2 checks passed
@MuhammadKhalilzadeh MuhammadKhalilzadeh deleted the yb-oct-2-fix-policy-manager branch October 3, 2025 08:00
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.

- Policy Manager - QA/QC - CRUD operations test
3 participants