-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Possibly related PRs
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 readabilityThe 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 updatesThe current implementation makes direct API calls on every change. Consider implementing optimistic updates to improve the user experience:
- Update the UI immediately
- Show loading states during mutations
- 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
📒 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.
onValueChange={(value: "manual" | "automatic") => | ||
updatePolicy | ||
.mutateAsync({ id, data: { approvalRequirement: value } }) | ||
.then(invalidatePolicy) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
<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" | ||
/> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add validation and improve input handling
The number input needs several improvements:
- Missing min/max validation
- No error handling for the mutation
- 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.
There was a problem hiding this 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
📒 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
:
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
:
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))
}}
/>
const invalidatePolicy = () => { | ||
utils.environment.policy.byId.invalidate(id); | ||
utils.environment.policy.bySystemId.invalidate(systemId); | ||
}; |
There was a problem hiding this comment.
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.
Summary by CodeRabbit
New Features
Bug Fixes
UI Improvements