Skip to content

actions: keep newest entries when limit is reached#34207

Closed
Maverick-666 wants to merge 2 commits into
storybookjs:nextfrom
Maverick-666:codex/actions-limit-keeps-latest
Closed

actions: keep newest entries when limit is reached#34207
Maverick-666 wants to merge 2 commits into
storybookjs:nextfrom
Maverick-666:codex/actions-limit-keeps-latest

Conversation

@Maverick-666
Copy link
Copy Markdown

@Maverick-666 Maverick-666 commented Mar 19, 2026

Summary

Fixes Actions panel retention logic when options.limit is reached so Storybook keeps the newest entries instead of the oldest.

Changes

  • Updated code/core/src/actions/containers/ActionLogger/index.tsx:
    • switched retention from slice(0, limit) to latest-window behavior (slice(-limit))
    • removed mutable state updates in setActions updater (immutable updates for count and new entries)
  • Added regression tests in code/core/src/actions/containers/ActionLogger/index.test.ts:
    • keeps newest entries at capacity
    • increments count immutably for repeated payloads
  • Added a story scenario in code/core/template/stories/basics.stories.ts:
    • OptionLimit to showcase panel behavior with a small limit
  • Updated docs in docs/essentials/actions.mdx:
    • documents action(..., { limit })
    • clarifies that oldest entries are dropped and newest are retained once limit is reached

Notes

I couldn’t run local vitest in this environment because dependency installation timed out; CI should validate the full suite.

Summary by CodeRabbit

  • New Features

    • Action logging supports a configurable limit option to retain only the most recent entries (default: 50).
    • Added a demo story showing limited action logging with an incrementing sequence.
  • Documentation

    • Updated docs to describe the new action options, including limit, defaults, and retention behavior.
  • Tests

    • Added tests covering limit behavior and immutable updates to logged actions.
  • Refactor

    • Improved internal handling to produce immutable action list updates.

@Maverick-666
Copy link
Copy Markdown
Author

Implemented and pushed.

This PR fixes Actions panel retention at limit capacity to keep the most recent entries, adds a regression test for the behavior, and documents limit semantics in the Actions docs.
Also included a template story (OptionLimit) to make the behavior easy to observe manually.

Please take a look when convenient.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 19, 2026

📝 Walkthrough

Walkthrough

Extracted action-list update logic into an exported helper applyActionToList that immutably updates, deduplicates, increments counts, and enforces a configurable limit. Added tests, a Storybook example using options.limit, and documentation updates for the action options.

Changes

Cohort / File(s) Summary
ActionLogger implementation
code/core/src/actions/containers/ActionLogger/index.tsx
Added exported applyActionToList(prevActions, action) implementing immutable updates: returns [] when limit<=0, increments count for matching latest data, appends otherwise, and enforces retention with slice(-limit). Refactored addAction to delegate to this helper.
ActionLogger tests
code/core/src/actions/containers/ActionLogger/index.test.ts
Added Vitest suite for applyActionToList: verifies zero-limit behavior, trimming to limit keeping most recent entries, and immutable update/increment when incoming action matches existing entry.
Storybook & docs
code/core/template/stories/basics.stories.ts, docs/essentials/actions.mdx
Added OptionLimit story demonstrating repeated clicks with { limit: 3 }. Updated actions docs to accept optional options (including limit, depth, clearOnStoryChange) and documented options.limit behavior and default.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can customize the high-level summary generated by CodeRabbit.

Configure the reviews.high_level_summary_instructions setting to provide custom instructions for generating the high-level summary.

Copy link
Copy Markdown
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: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/core/src/actions/containers/ActionLogger/index.tsx`:
- Around line 31-41: The trimming logic uses slice(-limit) which treats limit <=
0 as "no trim", so update the reducer in ActionLogger to special-case when limit
<= 0 (e.g., if (limit <= 0) return [] for zero or return prevActions / updated
without slice if negative semantics desired) before both return paths that call
slice(-limit) — adjust the branch that updates the last repeated action (uses
previous, updated, previous.count) and the branch that appends newAction to
handle limit <= 0 explicitly; also add a regression test asserting that
options.limit = 0 results in an empty retained list (or the intended zero
retention) to prevent future regressions.

In `@docs/essentials/actions.mdx`:
- Around line 107-119: Update the documented signature for action() to reflect
the full options shape instead of only { limit?: number } — use options?:
ActionOptions (or describe options as supporting limit, depth,
clearOnStoryChange, etc.) so calls using depth or clearOnStoryChange are shown
as valid; keep the separate subsection documenting options.limit (Type: number,
Default: 50) as an additional supported field while referencing ActionOptions
for the complete schema and examples.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6c0bb039-b3a5-4a4f-a221-e8437c36e7c3

📥 Commits

Reviewing files that changed from the base of the PR and between 8e95824 and 17eb398.

📒 Files selected for processing (4)
  • code/core/src/actions/containers/ActionLogger/index.test.ts
  • code/core/src/actions/containers/ActionLogger/index.tsx
  • code/core/template/stories/basics.stories.ts
  • docs/essentials/actions.mdx

Comment thread code/core/src/actions/containers/ActionLogger/index.tsx
Comment thread docs/essentials/actions.mdx Outdated
@Maverick-666
Copy link
Copy Markdown
Author

Thanks for the review! Addressed both points in the latest commit:

  • Added a guard for non-positive limits (limit <= 0) in applyActionToList.
  • Added a regression test to verify options.limit = 0 retains an empty list.
  • Updated docs to keep the action options signature aligned with broader ActionOptions, while still documenting options.limit behavior.

Please take another look.

Copy link
Copy Markdown
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.

🧹 Nitpick comments (1)
code/core/src/actions/containers/ActionLogger/index.tsx (1)

61-65: Minor: clearOnStoryChange check may reference stale config after retention trim.

With the new slice(-limit) retention keeping the newest entries, actions[0] becomes the oldest retained action rather than the first action ever added. If actions with different clearOnStoryChange settings are mixed, this check could behave unexpectedly.

This is pre-existing logic and not introduced by this PR, so it's low priority. Consider storing the clearOnStoryChange preference separately (e.g., from the first action ever received, or from configuration) if consistent behavior across mixed settings is desired.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/core/src/actions/containers/ActionLogger/index.tsx` around lines 61 -
65, handleStoryChange currently checks actions[0].options.clearOnStoryChange
which can be stale after retention trimming (slice(-limit)) because actions[0]
is the oldest retained action, not the first-ever; change the logic to track the
desired clearOnStoryChange flag separately (e.g., store a module/state variable
or a ref like firstActionClearOnStoryChange when the very first action is
received or read from config) and have handleStoryChange consult that stored
flag instead of actions[0]; ensure the flag is set when actions are
initialized/first pushed (update the code paths that populate actions and apply
retention) and preserved across trims so clearActions is invoked consistently
based on the original preference (references: handleStoryChange,
clearOnStoryChange, clearActions, actions).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@code/core/src/actions/containers/ActionLogger/index.tsx`:
- Around line 61-65: handleStoryChange currently checks
actions[0].options.clearOnStoryChange which can be stale after retention
trimming (slice(-limit)) because actions[0] is the oldest retained action, not
the first-ever; change the logic to track the desired clearOnStoryChange flag
separately (e.g., store a module/state variable or a ref like
firstActionClearOnStoryChange when the very first action is received or read
from config) and have handleStoryChange consult that stored flag instead of
actions[0]; ensure the flag is set when actions are initialized/first pushed
(update the code paths that populate actions and apply retention) and preserved
across trims so clearActions is invoked consistently based on the original
preference (references: handleStoryChange, clearOnStoryChange, clearActions,
actions).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3b372372-1520-4559-952b-c694e6289503

📥 Commits

Reviewing files that changed from the base of the PR and between 17eb398 and 5a9ff21.

📒 Files selected for processing (3)
  • code/core/src/actions/containers/ActionLogger/index.test.ts
  • code/core/src/actions/containers/ActionLogger/index.tsx
  • docs/essentials/actions.mdx
✅ Files skipped from review due to trivial changes (1)
  • code/core/src/actions/containers/ActionLogger/index.test.ts

@valentinpalkovic
Copy link
Copy Markdown
Contributor

Is already handled by #34053

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants