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: Auto save for approval and governance #264

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

adityachoudhari26
Copy link
Contributor

@adityachoudhari26 adityachoudhari26 commented Dec 12, 2024

Summary by CodeRabbit

  • New Features

    • Updated the "Approval & Governance" component to improve user interaction and clarity.
    • Introduced direct form handling for better responsiveness.
  • Bug Fixes

    • Enhanced error handling and control flow for policy updates.
  • UI Improvements

    • Restructured layout for improved usability and added spacing for better visual appeal.
    • Changed section title to "Approval gates" with updated description for clarity.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Walkthrough

The changes in this pull request focus on the ApprovalAndGovernance component within the ApprovalAndGovernance.tsx file. The update involves a significant restructuring of form handling and user interface elements. The Zod schema for form validation has been removed, and form state management has been simplified by directly invoking the updatePolicy mutation through the onValueChange callbacks of the Select and RadioGroup components. Additionally, the UI has been enhanced for clarity, with changes to titles, descriptions, and layout adjustments.

Changes

File Change Summary
apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx - Removed Zod schema for form validation.
- Eliminated useForm hook.
- Updated UI structure and layout.
- Changed section title to "Approval gates".
- Modified description for approval requirement.
- Adjusted successMinimum handling to default to 0.
- Simplified error handling and control flow.

Possibly related PRs

  • Fix: Approval Usability #172: This PR modifies the PolicyApprovalRow component, which is related to the ApprovalAndGovernance component as both deal with approval processes and user interactions.
  • fix user id #184: This PR also modifies the FlowPolicyNode.tsx, which includes the ApprovalDialog component that interacts with the approval process, directly linking it to the changes made in the ApprovalAndGovernance component regarding user ID handling.

Suggested reviewers

  • jsbroks

🐰 In the meadow, changes bloom,
Approval gates, make room,
Forms now flow with ease and grace,
A clearer path in this bright space.
With every click, a policy's fate,
Hopping forward, we celebrate! 🌼


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. (Experiment)
  • @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.

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
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: 2

🧹 Outside diff range and nitpick comments (2)
apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx (2)

33-39: Consider improving description text readability

The description text is quite long. Consider breaking it into bullet points or shorter paragraphs for better readability.

 <span className="text-sm text-muted-foreground">
-  This category defines policies that govern the oversight and approval
-  process for deployments. These policies ensure that deployments meet
-  specific criteria or gain necessary approvals before proceeding,
-  contributing to compliance, quality assurance, and overall governance
-  of the deployment process.
+  This category defines policies that govern the oversight and approval process for deployments.
+  <ul className="mt-2 list-disc pl-4">
+    <li>Ensures deployments meet specific criteria</li>
+    <li>Requires necessary approvals before proceeding</li>
+    <li>Contributes to compliance and quality assurance</li>
+    <li>Maintains overall governance of the deployment process</li>
+  </ul>
 </span>

Line range hint 1-127: Consider implementing optimistic updates

The current implementation makes direct API calls on every change. Consider implementing optimistic updates to improve the user experience:

  1. Update the UI immediately
  2. Show loading states during mutations
  3. Revert on failure

This would make the interface feel more responsive while maintaining data consistency.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 80e10a9 and 3f27c86.

📒 Files selected for processing (2)
  • apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx (2 hunks)
  • apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/EnvironmentPolicyDrawer.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/EnvironmentPolicyDrawer.tsx
🧰 Additional context used
📓 Path-based instructions (1)
apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx (1)

Pattern **/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

🔇 Additional comments (1)
apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx (1)

24-27: LGTM: Well-structured cache invalidation logic

The invalidation helper function is well-organized, ensuring both policy queries are properly invalidated after updates.

Comment on lines +54 to +58
onValueChange={(value: "manual" | "automatic") =>
updatePolicy
.mutateAsync({ id, data: { approvalRequirement: value } })
.then(invalidatePolicy)
}
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

Add error handling for the approval requirement update

The mutation lacks error handling and could fail silently. Consider adding error handling and loading states.

 onValueChange={(value: "manual" | "automatic") =>
   updatePolicy
     .mutateAsync({ id, data: { approvalRequirement: value } })
-    .then(invalidatePolicy)
+    .then(invalidatePolicy)
+    .catch((error) => {
+      console.error('Failed to update approval requirement:', error);
+      // TODO: Add toast or other user notification
+    })
 }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 103 to 115
<Input
disabled={environmentPolicy.successType !== "some"}
type="number"
value={environmentPolicy.successMinimum}
onChange={(e) => {
const value = e.target.valueAsNumber;
const successMinimum = Number.isNaN(value) ? 0 : value;
updatePolicy
.mutateAsync({ id, data: { successMinimum } })
.then(invalidatePolicy);
}}
className="border-b-1 h-6 w-16 text-xs"
/>
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

Add validation and improve input handling

The number input needs several improvements:

  1. Missing min/max validation
  2. No error handling for the mutation
  3. Non-standard border styling
 <Input
   disabled={environmentPolicy.successType !== "some"}
   type="number"
+  min={0}
+  max={100}
   value={environmentPolicy.successMinimum}
   onChange={(e) => {
     const value = e.target.valueAsNumber;
     const successMinimum = Number.isNaN(value) ? 0 : value;
+    if (successMinimum < 0 || successMinimum > 100) return;
     updatePolicy
       .mutateAsync({ id, data: { successMinimum } })
-      .then(invalidatePolicy);
+      .then(invalidatePolicy)
+      .catch((error) => {
+        console.error('Failed to update success minimum:', error);
+        // TODO: Add toast or other user notification
+      });
   }}
-  className="border-b-1 h-6 w-16 text-xs"
+  className="h-6 w-16 border-b text-xs"
 />

Committable suggestion skipped: line range outside the PR's diff.

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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f27c86 and 217e641.

📒 Files selected for processing (1)
  • apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx (1)

Pattern **/*.{ts,tsx}: Note on Error Handling:
Avoid strict enforcement of try/catch blocks. Code may use early returns, Promise chains (.then().catch()), or other patterns for error handling. These are acceptable as long as they maintain clarity and predictability.

🔇 Additional comments (3)
apps/webservice/src/app/[workspaceSlug]/(app)/_components/environment-policy-drawer/ApprovalAndGovernance.tsx (3)

30-40: Well-structured UI with clear sections and descriptions

The component layout is well organized with proper spacing, typography, and clear descriptions that help users understand the purpose of each section.


52-68: ⚠️ Potential issue

Add error handling and loading state to approval requirement selector

The mutation lacks error handling and could fail silently. Also, the select should be disabled while updating.

 <Select
+  disabled={isUpdating}
   value={environmentPolicy.approvalRequirement}
   onValueChange={(value: "manual" | "automatic") => {
+    setIsUpdating(true);
     updatePolicy
       .mutateAsync({ id, data: { approvalRequirement: value } })
-      .then(invalidatePolicy)
+      .then(invalidatePolicy)
+      .catch((error) => {
+        console.error('Failed to update approval requirement:', error);
+        // Show error notification to user
+      })
+      .finally(() => setIsUpdating(false))
   }}
 >

83-124: ⚠️ Potential issue

Add validation and loading states to deploy status controls

The radio group and number input need proper validation and loading state handling.

 <RadioGroup
+  disabled={isUpdating}
   value={environmentPolicy.successType}
   onValueChange={(value: "all" | "some" | "optional") => {
+    setIsUpdating(true);
     updatePolicy
       .mutateAsync({ id, data: { successType: value } })
-      .then(invalidatePolicy)
+      .then(invalidatePolicy)
+      .catch((error) => {
+        console.error('Failed to update success type:', error);
+        // Show error notification to user
+      })
+      .finally(() => setIsUpdating(false))
   }}
 >

For the number input:

 <Input
-  disabled={environmentPolicy.successType !== "some"}
+  disabled={environmentPolicy.successType !== "some" || isUpdating}
   type="number"
+  min={0}
+  max={100}
   value={environmentPolicy.successMinimum}
   onChange={(e) => {
     const value = e.target.valueAsNumber;
     const successMinimum = Number.isNaN(value) ? 0 : value;
+    if (successMinimum < 0 || successMinimum > 100) return;
+    setIsUpdating(true);
     updatePolicy
       .mutateAsync({ id, data: { successMinimum } })
-      .then(invalidatePolicy)
+      .then(invalidatePolicy)
+      .catch((error) => {
+        console.error('Failed to update success minimum:', error);
+        // Show error notification to user
+      })
+      .finally(() => setIsUpdating(false))
   }}
 />

Comment on lines +24 to +27
const invalidatePolicy = () => {
utils.environment.policy.byId.invalidate(id);
utils.environment.policy.bySystemId.invalidate(systemId);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add loading state handling for mutations

The cache invalidation logic is good, but the component should handle loading states to prevent multiple simultaneous updates and provide better UX.

 const updatePolicy = api.environment.policy.update.useMutation();
+const [isUpdating, setIsUpdating] = useState(false);
 
 const invalidatePolicy = () => {
   utils.environment.policy.byId.invalidate(id);
   utils.environment.policy.bySystemId.invalidate(systemId);
 };

Committable suggestion skipped: line range outside the PR's diff.

@adityachoudhari26 adityachoudhari26 merged commit 258e436 into main Dec 12, 2024
5 of 6 checks passed
@adityachoudhari26 adityachoudhari26 deleted the remove-save-approval branch December 12, 2024 23:55
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