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

feat: show confirmation modal for deleting recordings and runs #319

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

AmitChauhan63390
Copy link
Contributor

@AmitChauhan63390 AmitChauhan63390 commented Jan 4, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added confirmation dialogs for deleting recordings and runs
    • Enhanced localization support with new UI text sections
  • Improvements

    • Improved error handling for recordings and runs
    • Updated user interface text for better clarity and consistency
  • Bug Fixes

    • Added safeguards to prevent accidental deletions
    • Standardized code formatting and error management

Copy link

coderabbitai bot commented Jan 4, 2025

Walkthrough

This pull request introduces significant improvements to the localization and user interface of the application. The changes focus on enhancing user experience through more robust error handling, adding confirmation dialogs for deletion actions, and expanding the localization structure. The modifications span across localization files, the recordings table, and the runs table components, with an emphasis on improving user interaction, preventing accidental deletions, and providing clearer feedback.

Changes

File Change Summary
public/locales/en.json Comprehensive restructuring of localization strings, adding new sections for recording, browser, interpretation, runs table, and navigation
src/components/molecules/RecordingsTable.tsx Enhanced error handling, added deletion confirmation dialog, improved code formatting
src/components/molecules/RunsTable.tsx Implemented delete confirmation dialog with new state variables and handler methods

Sequence Diagram

sequenceDiagram
    participant User
    participant UI
    participant DeleteConfirmation
    participant Backend

    User->>UI: Initiate Delete Action
    UI->>DeleteConfirmation: Open Confirmation Dialog
    DeleteConfirmation->>User: Prompt for Confirmation
    User->>DeleteConfirmation: Confirm Deletion
    DeleteConfirmation->>Backend: Execute Delete
    Backend-->>UI: Deletion Completed
    UI->>User: Show Success Notification
Loading

Poem

🐰 A Rabbit's Ode to Deletion's Grace

Clicks and confirmations, a safety embrace,
No more accidental data's sad trace,
Dialogs pop up with a whimsical flair,
Protecting our records with delicate care,
A dance of protection, both gentle and wise! 🗑️


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

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

@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 (4)
src/components/molecules/RunsTable.tsx (2)

132-138: Potential improvement for selective item deletion
Currently, calling setRows([]) removes all rows briefly before re-fetching them. This can cause unnecessary flicker and overhead if only one run needs to be deleted. Consider directly removing the specific run from rows prior to re-fetching to maintain a smoother UX.

  const handleDeleteConfirm = () => {
-   setRows([]);
+   setRows((prevRows) => prevRows.filter((r) => r.id !== runToDelete?.id));
    notify('success', t('runstable.notifications.delete_success'));
    fetchRuns();
    setDeleteDialogOpen(false);
    setRunToDelete(null);
  };

228-250: Hard-coded text in dialog title
Currently, "Delete Run" is hard-coded. For localization synergy, consider using something like t('runstable.delete_confirmation.title') if that exists. This will further align with the approach seen in RecordingsTable.

 <DialogTitle id="alert-dialog-title">
-  Delete Run
+  {t('runstable.delete_confirmation.title', 'Delete Run')}
 </DialogTitle>
src/components/molecules/RecordingsTable.tsx (2)

156-156: Use optional chaining here
The static analysis hint suggests using optional chaining. In line 156, you can safely check if recording?.recording_meta exists before accessing it, preventing potential runtime errors.

- if (recording && recording.recording_meta) {
+ if (recording?.recording_meta) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 156-156: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


371-388: Delete recording flow
Deletion logic is triggered inline. While this works, you might consider a dedicated confirmation dialog—similar to the OptionsButton approach—for consistency. Right now, line 385 ensures errors are reported, which is good.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c132f27 and 1d7f9ed.

📒 Files selected for processing (3)
  • public/locales/en.json (1 hunks)
  • src/components/molecules/RecordingsTable.tsx (7 hunks)
  • src/components/molecules/RunsTable.tsx (5 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/components/molecules/RecordingsTable.tsx

[error] 156-156: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (11)
src/components/molecules/RunsTable.tsx (5)

12-16: Imports for Material-UI Dialog components
These imports properly introduce the required Material-UI dialog components.


88-89: Use of new state for dialog management
deleteDialogOpen and runToDelete are sensible additions for tracking deletion state and which run is to be removed.


127-130: Method rename and usage
handleDeleteClick cleanly shifts deletion logic into a confirmation-based flow. This readably sets runToDelete and opens the dialog.


140-142: Graceful dialog close
handleDeleteCancel properly resets state when the user cancels the deletion, preserving consistency.


204-204: Delegation to handleDeleteClick
Linking handleDelete to handleDeleteClick(row) is consistent, ensuring each row triggers the Dialog.

src/components/molecules/RecordingsTable.tsx (2)

178-184: Robust error handling
Catching errors on stopRecording(browserId) is beneficial. Kudos for adding user-facing notifications here, enhancing clarity when a recording fails to stop.


Line range hint 548-586: Enhanced confirmation flow in OptionsButton
This approach includes a separate confirmation dialog for deletion, ensuring user safeguards. The interplay with checkRunsForRecording is well-handled, but if the user has many runs, you might consider a loading state or a direct approach to gracefully handle the asynchronous checks.

public/locales/en.json (4)

46-51: Addition of delete confirmation strings
Including "delete_confirmation" fosters improved user interaction by clarifying irreversible deletion steps. Good approach for multi-lingual support.


62-74: Updates to runstable notifications
Providing distinct success and fail notifications helps thoroughly convey the system state to users.


156-173: List extraction and pagination instructions
These localized strings thoroughly guide users in setting pagination and list extraction limits. This is valuable for user education.


Line range hint 568-580: Detailed error and success messages
Comprehensive error notifications, especially referencing variables (e.g. {{message}}), ensure clarity for debugging. Keep verifying placeholders to avoid mismatches.

Comment on lines +566 to +587
const handleDeleteConfirm = async () => {
try {
checkRunsForRecording(recordingName).then((result: boolean) => {
if (result) {
notify('warning', t('recordingtable.notifications.delete_warning'));
setDeleteDialogOpen(false);
}
})




// Only proceed with deletion if there are no runs
handleDelete();
setDeleteDialogOpen(false);
notify("success", t("recordingtable.notifications.delete_success"));
} catch (error) {
console.error('Error during deletion:', error);
notify("error", t("recordingtable.notifications.delete_error"));
setDeleteDialogOpen(false);
}
};
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Race condition in deletion logic needs to be fixed

The verification reveals a serious race condition in the deletion logic. The code calls handleDelete() immediately after starting the checkRunsForRecording promise, without waiting for its result. This means:

  1. The deletion will always proceed regardless of whether there are associated runs
  2. The comment "Only proceed with deletion if there are no runs" is incorrect as the code doesn't enforce this condition
  3. The warning notification about existing runs may appear after the deletion is already completed

Here's what needs to be fixed:

  • Move the handleDelete() call inside the .then() block
  • Only call it when result is false (no runs exist)
  • Use proper async/await syntax instead of mixing with .then()
🔗 Analysis chain

Conditionally skipping actual delete
Your logic at lines 568–580 could skip the actual removal if runs are associated. As a follow-up, consider placing that skip logic inside or after the promise’s .then block, clarifying if the code still calls handleDelete() once checkRunsForRecording returns true.

  const handleDeleteConfirm = async () => {
    try {
      checkRunsForRecording(recordingName).then((result: boolean) => {
        if (result) {
          notify('warning', t('recordingtable.notifications.delete_warning'));
          setDeleteDialogOpen(false);
-         // Potentially still calls handleDelete() below
+         return; // ensure we skip the actual delete if runs exist
        }
      });
      handleDelete();
      ...

Let me gather more information about the code to verify the concern.


Let me search for the actual handleDelete implementation in the RecordingsTable component since the one found is from a different component.


Let me search for the actual delete operation in the file.

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Search for handleDeleteConfirm implementation and its related functions
ast-grep --pattern 'const handleDeleteConfirm = async () => {
  $$$
}'

# Also search for checkRunsForRecording function to understand its implementation
ast-grep --pattern 'const checkRunsForRecording = $_'

# Search for handleDelete implementation
ast-grep --pattern 'const handleDelete = $_'

Length of output: 3090


Script:

#!/bin/bash
# Search for handleDelete in RecordingsTable.tsx
rg "const handleDelete" src/components/molecules/RecordingsTable.tsx -A 5

Length of output: 528


Script:

#!/bin/bash
# Search for delete-related operations in RecordingsTable.tsx
rg "delete" src/components/molecules/RecordingsTable.tsx -B 2 -A 5

Length of output: 3346

@amhsirak amhsirak added the Type: Enhancement Improvements to existing features label Jan 5, 2025
@amhsirak amhsirak changed the title Confirmation modal feat: show confirmation modal for deleting recordings and runs Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants