Skip to content

Comments

[WEB-2043] fix: delete action validation and toast alert#5254

Merged
SatishGandham merged 6 commits intopreviewfrom
fix-delete-action-validation
Jul 29, 2024
Merged

[WEB-2043] fix: delete action validation and toast alert#5254
SatishGandham merged 6 commits intopreviewfrom
fix-delete-action-validation

Conversation

@anmolsinghbhatia
Copy link
Collaborator

@anmolsinghbhatia anmolsinghbhatia commented Jul 29, 2024

Changes:

This PR includes following changes:

  • Added validation for issue, intake, module, and cycle delete actions, along with updated toast messages.
  • Restricted bulk delete operations to project admins only, preventing users with member roles from performing this action.

Reference:

[WEB-2043]

Summary by CodeRabbit

  • New Features

    • Introduced permission checks for project administrative actions, particularly for bulk deletions in the Command Palette.
    • Added a new user store property to manage project admin permissions.
    • Introduced standardized error messages for project management actions.
  • Bug Fixes

    • Improved error handling for deletion processes across various modals, providing clearer feedback based on permission status and other error types.
  • Documentation

    • Enhanced user notifications with tailored messages for permission errors during deletion actions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2024

Walkthrough

Recent changes enhance user feedback and error handling across project and issue management components. A new permission check for project admin actions improves bulk delete functionalities. Error handling has been refined in delete modals to provide specific feedback based on user permissions. These updates significantly enhance the user experience and security by clarifying actions and outcomes related to project management.

Changes

Files Change Summary
web/core/components/command-palette/... Introduced canPerformProjectAdminActions permission check and performProjectBulkDeleteActions function; enhanced command handling for delete actions.
web/core/components/cycles/delete-modal.tsx Improved error handling to differentiate permission errors from general errors; modal closes consistently after deletion attempts.
web/core/components/inbox/modals/delete-issue-modal.tsx Enhanced error handling with specific toast notifications for permission errors; modal behavior remains consistent after actions.
web/core/components/issues/delete-issue-modal.tsx Refined error handling to specify permission errors; dynamically set toast titles based on error type; ensured modal closure post-operation.
web/core/components/modules/delete-module-modal.tsx Enhanced error handling for permission validation during module deletion; focused on closing the modal post-attempt rather than managing loading states.
web/core/store/inbox/project-inbox.store.ts Updated destroy method to log error details and re-throw errors for improved visibility and handling upstream.
web/core/store/user/index.ts Added canPerformProjectAdminActions boolean property to IUserStore interface and class, enabling role-based permission checks for project actions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CommandPalette
    participant DeleteModal
    participant UserStore

    User->>CommandPalette: Press Delete Key
    CommandPalette->>UserStore: Check canPerformProjectAdminActions
    alt User has permissions
        CommandPalette->>DeleteModal: Open Delete Confirmation
    else User lacks permissions
        CommandPalette->>User: Show Permission Denied Toast
    end
Loading

🐇 In the meadow, where bunnies play,
New features hop in, brightening the day!
With permissions checked, and toasts that cheer,
Deletions now clearer, no need for fear.
So jump with joy, let errors be few,
For every change welcomed, we celebrate you! 🎉


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a8c6483 and e3202de.

Files selected for processing (7)
  • web/core/components/command-palette/command-palette.tsx (5 hunks)
  • web/core/components/cycles/delete-modal.tsx (1 hunks)
  • web/core/components/inbox/modals/delete-issue-modal.tsx (2 hunks)
  • web/core/components/issues/delete-issue-modal.tsx (1 hunks)
  • web/core/components/modules/delete-module-modal.tsx (1 hunks)
  • web/core/store/inbox/project-inbox.store.ts (1 hunks)
  • web/core/store/user/index.ts (3 hunks)
Additional comments not posted (13)
web/core/components/inbox/modals/delete-issue-modal.tsx (2)

32-39: Enhance user feedback with detailed success message.

The promise chain correctly handles successful deletion with a success toast notification.


40-49: Improve error handling with specific messages.

The error handling logic correctly distinguishes between permission errors and general errors, providing specific feedback to the user.

web/core/components/issues/delete-issue-modal.tsx (1)

55-65: Improve error handling with specific messages.

The error handling logic correctly distinguishes between permission errors and general errors, providing specific feedback to the user.

web/core/components/modules/delete-module-modal.tsx (1)

57-71: Improve error handling with specific messages.

The error handling logic correctly distinguishes between permission errors and general errors, providing specific feedback to the user.

web/core/components/cycles/delete-modal.tsx (2)

54-67: Enhanced error handling logic.

The changes provide specific feedback for permission errors and general errors, improving user experience.


68-68: Consistent modal behavior.

The finally block ensures the modal closes in all scenarios, enhancing control flow consistency.

web/core/store/user/index.ts (2)

46-46: Added project admin permissions property to interface.

The addition of canPerformProjectAdminActions enhances the interface by providing a clear mechanism to check for project admin permissions.


283-289: Added project admin permissions getter method.

The canPerformProjectAdminActions getter method checks if the current project role is EUserProjectRoles.ADMIN, enhancing role-based access control.

web/core/components/command-palette/command-palette.tsx (4)

49-49: Added project admin permissions variable.

The canPerformProjectAdminActions variable is used to determine if the user has the necessary rights to perform bulk delete actions on projects.


117-129: Added project bulk delete actions function.

The performProjectBulkDeleteActions function checks the user's permissions and sets a toast notification if the user lacks the required permissions, enhancing functionality.


Line range hint 227-251:
Enhanced keydown handler for bulk delete actions.

The handleKeyDown function now includes a check for the delete key and invokes the performProjectBulkDeleteActions function, enhancing control flow and user interaction.


288-288: Updated useCallback hook dependencies.

The performProjectBulkDeleteActions function has been added to the dependencies of the useCallback hook, ensuring proper reference in the component's lifecycle.

web/core/store/inbox/project-inbox.store.ts (1)

458-463: Improved error handling in deleteInboxIssue method.

The changes improve error visibility by logging the actual error message and re-throwing the error to ensure upstream error handling.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e3202de and 0a4e0e5.

Files selected for processing (5)
  • web/core/components/cycles/delete-modal.tsx (2 hunks)
  • web/core/components/inbox/modals/delete-issue-modal.tsx (2 hunks)
  • web/core/components/issues/delete-issue-modal.tsx (2 hunks)
  • web/core/components/modules/delete-module-modal.tsx (2 hunks)
  • web/core/constants/project.ts (1 hunks)
Files skipped from review as they are similar to previous changes (4)
  • web/core/components/cycles/delete-modal.tsx
  • web/core/components/inbox/modals/delete-issue-modal.tsx
  • web/core/components/issues/delete-issue-modal.tsx
  • web/core/components/modules/delete-module-modal.tsx
Additional comments not posted (1)
web/core/constants/project.ts (1)

172-189: LGTM! But verify the usage of the new constant in the codebase.

The code changes are approved.

However, ensure that the new PROJECT_ERROR_MESSAGES constant is correctly used throughout the codebase.

Verification successful

The new PROJECT_ERROR_MESSAGES constant is correctly used throughout the codebase.

The constant is imported and utilized in various components, ensuring consistent error messaging for project-related actions.

  • Files:
    • web/core/components/issues/delete-issue-modal.tsx
    • web/core/components/modules/delete-module-modal.tsx
    • web/core/components/inbox/modals/delete-issue-modal.tsx
    • web/core/components/cycles/delete-modal.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new `PROJECT_ERROR_MESSAGES` constant in the codebase.

# Test: Search for the constant usage. Expect: Occurrences of `PROJECT_ERROR_MESSAGES`.
rg --type js --type ts -A 5 $'PROJECT_ERROR_MESSAGES'

Length of output: 4805

* @description tells if user has project admin actions permissions
* @returns {boolean}
*/
get canPerformProjectAdminActions() {
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be isProjectAdmin.

})
.catch(() => {
.catch((errors) => {
const isPermissionError = errors?.error === "Only admin or creator can delete the module";
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you write this better, instead of checking on the same condition twice.

@SatishGandham SatishGandham merged commit 35e58e9 into preview Jul 29, 2024
@SatishGandham SatishGandham deleted the fix-delete-action-validation branch July 29, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants