Skip to content

feat: discard only current active action #602

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

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

Conversation

RohitR311
Copy link
Collaborator

@RohitR311 RohitR311 commented May 20, 2025

What this PR does?

Functionality to discard only the current active actions on clicking discard.

Closes: #586

Summary by CodeRabbit

  • New Features

    • Added the ability to group and track steps by an associated action.
    • Introduced a new option to remove all steps linked to a specific action.
  • Improvements

    • Enhanced step management by allowing steps to be added with an action reference for better organization.
    • Extended global state to manage current action identifiers for text, list, and screenshot steps, improving tracking and association.
    • Enabled selective deletion of steps associated with a specific action when discarding captures, improving cleanup precision.

@RohitR311 RohitR311 added Type: Enhancement Improvements to existing features Scope: UI/UX Issues/PRs related to UI/UX Status: Work In Progess This issue/PR is actively being worked on labels May 20, 2025
Copy link

coderabbitai bot commented May 20, 2025

Walkthrough

The code update adds an optional actionId property to all BrowserStep types to track their originating actions. The context interface and provider are updated to require actionId when adding steps and to support deleting all steps associated with a given actionId. Existing functions are modified to propagate this property. Additionally, the BrowserWindow component now uses explicit action IDs from the global store when adding text and list steps. The global info context is extended to hold and manage current action ID states for text, list, and screenshot steps. The RightSidePanel component manages these action IDs during capture workflows, enabling scoped step deletion and state cleanup.

Changes

File(s) Change Summary
src/context/browserSteps.tsx Added optional actionId to all BrowserStep variants; updated context interface and provider methods to handle actionId; added deleteStepsByActionId method; modified step addition logic to propagate actionId.
src/components/browser/BrowserWindow.tsx Updated calls to addTextStep and addListStep to pass explicit actionId values retrieved from global info store or fallback timestamps.
src/context/globalInfo.tsx Extended GlobalInfo interface and GlobalInfoStore with new state properties and setters for currentTextActionId, currentListActionId, and currentScreenshotActionId; added React state hooks and context provider values for these properties.
src/components/recorder/RightSidePanel.tsx Added management of current action IDs for text, list, and screenshot captures; generated unique action IDs on capture start; used deleteStepsByActionId to discard steps scoped by action ID; cleared action IDs on confirm or discard; updated addScreenshotStep to accept action ID.

Sequence Diagram(s)

sequenceDiagram
    participant RightSidePanel
    participant GlobalInfoStore
    participant BrowserStepsContext

    RightSidePanel->>GlobalInfoStore: get/set currentTextActionId, currentListActionId, currentScreenshotActionId
    RightSidePanel->>GlobalInfoStore: generate new actionId on capture start
    RightSidePanel->>BrowserStepsContext: addTextStep(label, data, selectorObj, actionId)
    BrowserStepsContext->>BrowserStepsContext: Create TextStep with actionId
    BrowserStepsContext-->>RightSidePanel: Step added

    RightSidePanel->>BrowserStepsContext: addListStep(listSelector, fields, listId, actionId, ...)
    BrowserStepsContext->>BrowserStepsContext: Assign actionId to list and fields
    BrowserStepsContext-->>RightSidePanel: ListStep added

    RightSidePanel->>BrowserStepsContext: addScreenshotStep(fullPage, actionId)
    BrowserStepsContext->>BrowserStepsContext: Create ScreenshotStep with actionId
    BrowserStepsContext-->>RightSidePanel: ScreenshotStep added

    RightSidePanel->>BrowserStepsContext: deleteStepsByActionId(actionId)
    BrowserStepsContext->>BrowserStepsContext: Remove all steps with matching actionId
    BrowserStepsContext-->>RightSidePanel: Steps deleted

    RightSidePanel->>GlobalInfoStore: clear actionId on confirm or discard
Loading

Suggested reviewers

  • amhsirak

Poem

A hop and a skip, with an action in tow,
Now every step knows where it came from, you know!
With actionId tags, we can tidy with glee,
And delete all the steps as quick as can be.
The browser hops forward, more nimble and spry—
A rabbit’s delight, as the code multiplies!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

@RohitR311 RohitR311 requested a review from amhsirak May 20, 2025 12:29
@RohitR311 RohitR311 removed the Status: Work In Progess This issue/PR is actively being worked on label May 20, 2025
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

🔭 Outside diff range comments (2)
src/components/recorder/RightSidePanel.tsx (2)

523-528: ⚠️ Potential issue

Forgot to clear currentScreenshotActionId after the capture

Once the screenshot is taken we call finishAction('screenshot'), but the global store still retains the old currentScreenshotActionId. This stale value will be:

• Exposed to any component reading the store
• Passed to addScreenshotStep on the next capture before it is overwritten, risking mis-association

Quick fix:

 addScreenshotStep(fullPage, currentScreenshotActionId);
 stopGetScreenshot();
+setCurrentScreenshotActionId('');   // clear scoped action id
 resetInterpretationLog();
 finishAction('screenshot');
 onFinishCapture();

Please make the same adjustment in the inline discard handler a few lines below (onClick that stops screenshot capture).


785-789: 🛠️ Refactor suggestion

Clear screenshot action ID when the user discards a screenshot capture

For consistency with text and list discards, add:

    stopGetScreenshot();
    setActiveAction('none');
+   setCurrentScreenshotActionId('');

Without this, the stale ID issue described above also occurs on a discard flow.

♻️ Duplicate comments (1)
src/components/recorder/RightSidePanel.tsx (1)

486-512: Same duplication pattern as above

discardGetList re-implements the same clean-up loops; applying the helper proposed in the previous comment removes ~25 lines here as well and prevents the two functions from drifting apart.

🧹 Nitpick comments (1)
src/components/recorder/RightSidePanel.tsx (1)

443-482: Large block of near-duplicate clean-up logic – extract a helper

discardGetText manually:

  1. Finds steps for the current action
  2. Deletes them through deleteStepsByActionId
  3. Mirrors that deletion into three separate local state maps (textLabels, errors, confirmedTextSteps)

discardGetList (↓) repeats the same idea with slightly different state maps, and a future screenshot discard will likely do it again.

Duplicated, state-specific loops are easy to forget to update and are prone to bugs (e.g. an extra local map is added later and not cleared here).

Suggestion:

+const clearMaps = <T extends Record<number | string, any>>(
+  ids: number[],
+  ...maps: React.Dispatch<React.SetStateAction<T>>[]
+) => {
+  maps.forEach(setMap =>
+    setMap(prev => {
+      const copy = { ...prev };
+      ids.forEach(id => delete copy[id]);
+      return copy;
+    })
+  );
+};
const discardGetText = useCallback(() => {
  stopGetText();

  if (currentTextActionId) {
    const stepsToDelete = browserSteps
      .filter(s => s.actionId === currentTextActionId)
      .map(s => s.id);

    deleteStepsByActionId(currentTextActionId);

    clearMaps(stepsToDelete, setTextLabels, setErrors, setConfirmedTextSteps);
  }

  setCurrentTextActionId('');
  setIsCaptureTextConfirmed(false);
  notify('error', t('right_panel.errors.capture_text_discarded'));
}, [currentTextActionId, browserSteps, ...]);

Benefits: DRY, safer, and easier to extend.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9da3f7f and 515ad5b.

📒 Files selected for processing (1)
  • src/components/recorder/RightSidePanel.tsx (7 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/components/recorder/RightSidePanel.tsx (2)
src/context/globalInfo.tsx (1)
  • useGlobalInfoStore (123-123)
src/context/browserSteps.tsx (1)
  • useBrowserSteps (230-236)

Comment on lines 140 to 157
const handleStartGetText = () => {
setIsCaptureTextConfirmed(false);
const newActionId = `text-${Date.now()}`;
setCurrentTextActionId(newActionId);
startGetText();
}

const handleStartGetList = () => {
setIsCaptureListConfirmed(false);
const newActionId = `list-${Date.now()}`;
setCurrentListActionId(newActionId);
startGetList();
}

const handleStartGetScreenshot = () => {
const newActionId = `screenshot-${Date.now()}`;
setCurrentScreenshotActionId(newActionId);
startGetScreenshot();
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Generate truly-unique actionIds

Date.now() is generally “unique enough”, but two quick successive clicks can still produce the same timestamp (e.g. on fast hardware or in unit tests with mocked timers). A collision would cause two different capture sessions to share the same actionId, defeating the whole purpose of scoping.

Consider using crypto.randomUUID() (native in modern browsers / Node ≥ 14.17) or a tiny uuid helper to guarantee uniqueness:

-const newActionId = `text-${Date.now()}`;
+const newActionId = `text-${crypto.randomUUID()}`;   // likewise for list- and screenshot-flows

This small change fully eliminates the collision risk without adding any noticeable overhead.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleStartGetText = () => {
setIsCaptureTextConfirmed(false);
const newActionId = `text-${Date.now()}`;
setCurrentTextActionId(newActionId);
startGetText();
}
const handleStartGetList = () => {
setIsCaptureListConfirmed(false);
const newActionId = `list-${Date.now()}`;
setCurrentListActionId(newActionId);
startGetList();
}
const handleStartGetScreenshot = () => {
const newActionId = `screenshot-${Date.now()}`;
setCurrentScreenshotActionId(newActionId);
startGetScreenshot();
const handleStartGetText = () => {
setIsCaptureTextConfirmed(false);
- const newActionId = `text-${Date.now()}`;
+ const newActionId = `text-${crypto.randomUUID()}`; // likewise for list- and screenshot-flows
setCurrentTextActionId(newActionId);
startGetText();
}
🤖 Prompt for AI Agents
In src/components/recorder/RightSidePanel.tsx around lines 140 to 157, the
current use of Date.now() to generate action IDs can lead to collisions if two
actions start in the same millisecond. Replace Date.now() with
crypto.randomUUID() to generate truly unique action IDs for text, list, and
screenshot actions, ensuring no collisions even on rapid successive clicks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: UI/UX Issues/PRs related to UI/UX Type: Enhancement Improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: Discard single current action
1 participant