-
Notifications
You must be signed in to change notification settings - Fork 11
fix: Release channel dialog bug #233
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
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThe pull request introduces significant changes across multiple components related to release channels and conditions. Key modifications include the removal of the Changes
Possibly related PRs
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: 1
🧹 Outside diff range and nitpick comments (5)
apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-condition/useReleaseFilter.ts (1)
37-41: Add error handling for JSON stringificationWhile the compression logic is sound, consider adding try-catch for JSON.stringify to handle potential circular references or other stringification errors.
- const filterJsonHash = LZString.compressToEncodedURIComponent( - JSON.stringify(filter), - ); + let filterJsonHash; + try { + filterJsonHash = LZString.compressToEncodedURIComponent( + JSON.stringify(filter), + ); + } catch (error) { + console.error('Failed to stringify filter:', error); + return; + }apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-channel-drawer/ReleaseChannelDropdown.tsx (1)
41-51: Consider extracting deletion logic into a custom hookThe deletion logic handles multiple concerns (API call, drawer state, filter state, navigation, dialog state). Consider extracting this into a dedicated hook like
useReleaseChannelDeletionto improve maintainability and reusability.Example structure:
const useReleaseChannelDeletion = () => { const { removeReleaseChannelId } = useReleaseChannelDrawer(); const { setFilter } = useReleaseFilter(); const router = useRouter(); const deleteReleaseChannel = api.deployment.releaseChannel.delete.useMutation(); const deleteChannel = async (releaseChannelId: string) => { try { await deleteReleaseChannel.mutateAsync(releaseChannelId); await removeReleaseChannelId(); await setFilter(undefined, null); router.refresh(); return true; } catch (error) { console.error('Failed to delete release channel:', error); // Handle error appropriately return false; } }; return { deleteChannel, isDeleting: deleteReleaseChannel.isPending }; };apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-condition/ReleaseConditionDialog.tsx (2)
84-91: Consider handling undefined localCondition explicitlyWhile the tab selection logic is generally sound, there's a potential edge case when switching to the "new-filter" tab where
localConditioncould be undefined, causing it to fall back todefaultCondition. Consider making this fallback behavior more explicit:- if (value === "new-filter") - setLocalCondition(localCondition ?? defaultCondition); + if (value === "new-filter") + setLocalCondition((prev) => prev ?? defaultCondition);
143-146: Consider adding user feedback for failed channel lookupWhile the implementation correctly sets the filter and channel ID, consider providing feedback to the user if the release channel lookup fails (when
releaseChannelis null).const releaseChannel = releaseChannels.find( (rc) => rc.id === localReleaseChannelId, ); - if (releaseChannel == null) return; + if (releaseChannel == null) { + setError("Selected release channel not found"); + return; + }apps/webservice/src/app/[workspaceSlug]/(app)/systems/[systemSlug]/deployments/[deploymentSlug]/releases/DeploymentPageContent.tsx (1)
Line range hint
1-300: Consider implementing error boundaries and loading states.The component handles complex state management and multiple async operations. To improve reliability and user experience, consider:
- Implementing error boundaries to gracefully handle failures
- Adding loading states for async operations beyond the release list
- Memoizing expensive computations, especially in the environments map operation
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (4)
apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-channel-drawer/ReleaseChannelDropdown.tsx(1 hunks)apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-condition/ReleaseConditionDialog.tsx(5 hunks)apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-condition/useReleaseFilter.ts(1 hunks)apps/webservice/src/app/[workspaceSlug]/(app)/systems/[systemSlug]/deployments/[deploymentSlug]/releases/DeploymentPageContent.tsx(2 hunks)
🔇 Additional comments (8)
apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-condition/useReleaseFilter.ts (2)
26-26: LGTM: Improved function signature
The updated signature consolidates release channel management into a single function, making the API more cohesive while maintaining type safety.
30-32: Verify the URL parameter management behavior
The implementation handles all releaseChannelId cases correctly, but let's verify the behavior across different scenarios.
Also applies to: 41-44
✅ Verification successful
Let me analyze the usage patterns to verify the URL parameter management behavior. I'll check the implementation of useReleaseFilter to ensure it handles all cases correctly.
Based on the comprehensive analysis of the code, I can now generate the final response:
URL parameter management is correctly implemented
The implementation in useReleaseFilter.ts properly handles all cases for the release-channel parameter:
- Deletes the parameter when releaseChannelId is null
- Sets the parameter when releaseChannelId has a value
- Maintains existing behavior when releaseChannelId is undefined
The code is used consistently across multiple components (ReleaseChannelDropdown, ReleaseConditionDialog, Overview) and follows the same URL parameter management patterns as other similar hooks in the codebase (useTargetFilter, useJobFilter).
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Search for all usages of setFilter to ensure correct parameter passing
# Search for direct setFilter calls
rg -A 2 'setFilter\(' --type ts
# Search for components using useReleaseFilter
ast-grep --pattern 'const { setFilter } = useReleaseFilter()'
Length of output: 2595
Script:
#!/bin/bash
# Check the implementation of useReleaseFilter
rg -A 10 'useReleaseFilter' --type ts
# Check for any URL parameter handling patterns
rg -A 5 'query\.(set|delete)' --type ts
Length of output: 23072
apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-channel-drawer/ReleaseChannelDropdown.tsx (1)
41-41: Verify the necessity of maintaining both release channel management patterns
The code now uses both setFilter from useReleaseFilter and removeReleaseChannelId from useReleaseChannelDrawer. This mixing of patterns might indicate incomplete migration.
✅ Verification successful
Let me gather more information about the useReleaseFilter hook to understand its relationship with useReleaseChannelDrawer.
Based on the results, I can now generate the final response:
Both release channel management patterns are correctly implemented
The coexistence of setFilter and removeReleaseChannelId is intentional and serves different purposes:
setFilterfromuseReleaseFiltermanages the release condition filter state in the URLremoveReleaseChannelIdfromuseReleaseChannelDrawerhandles the drawer's open/close state
The implementation shows they work together in the delete flow:
setFilter(undefined, null)clears the filter stateremoveReleaseChannelId()closes the drawer
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for other usages of removeReleaseChannelId to understand if this pattern is still needed
ast-grep --pattern 'removeReleaseChannelId'
# Search for the implementation of useReleaseChannelDrawer to verify its current usage
rg -A 5 'export.*useReleaseChannelDrawer'
Length of output: 1435
Script:
#!/bin/bash
# Search for useReleaseFilter implementation and usages
rg -A 5 'export.*useReleaseFilter'
# Search for setFilter usage patterns
ast-grep --pattern 'setFilter($$$)'
# Look for any other filter-related patterns in release channel components
rg 'filter' apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-channel-drawer/
Length of output: 2585
apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-condition/ReleaseConditionDialog.tsx (3)
41-44: LGTM: Props type enhancement
The addition of the optional releaseChannelId parameter to the onChange callback improves type safety and provides better flexibility in handling both new filters and existing release channels.
58-58: LGTM: Simplified state management
The switch to using setFilter from the useReleaseFilter hook streamlines the state management by combining filter and channel ID updates into a single operation.
192-192: LGTM: Proper null handling for new filters
The explicit passing of null as the release channel ID for new filters maintains clear separation between channel-based and custom filters.
apps/webservice/src/app/[workspaceSlug]/(app)/systems/[systemSlug]/deployments/[deploymentSlug]/releases/DeploymentPageContent.tsx (2)
225-225: LGTM! Performance improvement added.
Adding the key prop to the TableCell component improves React's reconciliation process and prevents potential issues with component reuse.
Line range hint 90-103: Verify the impact of simplified condition.
The condition for displaying release channel information has been simplified from checking both filter and releaseChannel to only checking releaseChannel. While this makes the code cleaner, we should ensure this change doesn't affect the filter functionality.
| .then(() => setFilter(undefined, null)) | ||
| .then(() => router.refresh()) | ||
| .then(() => setOpen(false)); |
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 error handling to the deletion flow
The promise chain lacks error handling, which could lead to an inconsistent state if any operation fails. Consider adding proper error handling and user feedback.
const onDelete = () =>
deleteReleaseChannel
.mutateAsync(releaseChannelId)
.then(() => removeReleaseChannelId())
.then(() => setFilter(undefined, null))
.then(() => router.refresh())
- .then(() => setOpen(false));
+ .then(() => setOpen(false))
+ .catch((error) => {
+ console.error('Failed to delete release channel:', error);
+ // TODO: Show error notification to user
+ });Committable suggestion skipped: line range outside the PR's diff.
apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-condition/useReleaseFilter.ts
Outdated
Show resolved
Hide resolved
apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-condition/useReleaseFilter.ts
Outdated
Show resolved
Hide resolved
apps/webservice/src/app/[workspaceSlug]/(app)/_components/release-condition/useReleaseFilter.ts
Outdated
Show resolved
Hide resolved
Signed-off-by: Justin Brooks <jsbroks@gmail.com>
Summary by CodeRabbit
Release Notes
New Features
ReleaseChannelDropdownandReleaseConditionDialogcomponents for improved user experience.DeploymentPageContentcomponent.Bug Fixes
ReleaseConditionDialogto ensure validation before saving conditions.Refactor
setFilterfunction to manage both filter and release channel parameters more efficiently.