Skip to content

fix: add indicator for notifications#62

Open
Arukuen wants to merge 2 commits into
developfrom
feat/57/58/indicator
Open

fix: add indicator for notifications#62
Arukuen wants to merge 2 commits into
developfrom
feat/57/58/indicator

Conversation

@Arukuen

@Arukuen Arukuen commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

fixes #57
fixes #58

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a rating notice badge to the Admin Settings menu once cumulative storage savings reach the 5MB threshold
    • Users can dismiss the rating notice, and the choice is remembered across sessions
  • Improvements

    • Dismissing the rating notice now updates the admin sidebar immediately, without a page reload
    • The “Rate Now” button follows the same dismiss flow to keep the UI consistent

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f58d185f-a5ad-40f2-902e-aa31f6578a4d

📥 Commits

Reviewing files that changed from the base of the PR and between 8e159f8 and fda3901.

📒 Files selected for processing (1)
  • src/admin/js/page/admin-settings.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/admin/js/page/admin-settings.js

📝 Walkthrough

Walkthrough

Adds a RATING_NOTICE_THRESHOLD_BYTES constant and two new methods to Cimo_Stats for cached-only rating-notice evaluation. Stats are now refreshed after instant optimization in Cimo_Metadata. The PHP result is surfaced as a dynamic admin submenu badge and a showRatingNotice JS flag, replacing frontend MB-parsing logic and adding immediate badge removal on dismiss.

Changes

Rating Notice Indicator

Layer / File(s) Summary
Cimo_Stats threshold and cached rating-notice logic
src/admin/class-stats.php
Adds RATING_NOTICE_THRESHOLD_BYTES (5 MB), should_show_rating_notice() (checks cimo_rating_dismissed option and compares cached bytes to threshold), and private get_cached_saved_bytes() (reads OPTION_KEY, clamps KB saved, converts to bytes).
Stats refresh on instant optimization
src/admin/class-metadata.php
After writing cimo metadata in add_attachment_metadata(), conditionally calls Cimo_Stats::get_stats() when the class exists, keeping cached stats current after each instant optimization.
Admin submenu badge and JS payload wiring
src/admin/class-admin.php
add_admin_menu() conditionally appends an update-plugins HTML badge to the submenu title; enqueue_admin_scripts() computes $show_rating_notice and exposes it as showRatingNotice ('1'/'0') in the cimoAdmin localized JS object.
Frontend flag-driven notice and dismiss cleanup
src/admin/js/page/admin-settings.js
Rating notice visibility now depends on window.cimoAdmin?.showRatingNotice === '1' instead of parsing total_storage_saved; handleDismissRating immediately removes .update-plugins indicators from the menu item after dismissal, and the "Rate Now" button invokes the dismissal handler.

Sequence Diagram(s)

sequenceDiagram
    participant Browser as Admin Browser
    participant WPAdmin as WordPress Admin (PHP)
    participant CimoStats as Cimo_Stats
    participant CimoMeta as Cimo_Metadata

    CimoMeta->>CimoStats: get_stats() after saving attachment metadata
    WPAdmin->>CimoStats: should_show_rating_notice()
    CimoStats->>CimoStats: get_cached_saved_bytes() from OPTION_KEY
    CimoStats-->>WPAdmin: bool (threshold met & not dismissed)
    WPAdmin->>WPAdmin: append .update-plugins badge to submenu title
    WPAdmin->>Browser: cimoAdmin.showRatingNotice = '1' | '0'
    Browser->>Browser: render rating notice if showRatingNotice === '1'
    Browser->>WPAdmin: POST dismiss rating setting
    Browser->>Browser: remove .update-plugins from menu item
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop hop, the stats are tracked anew,
Each optimized image updates the queue.
Five megabytes saved? A badge appears!
Dismiss with a click and the dot disappears.
The rabbit checks cache — no heavy recount,
Just a swift little flag, no extra amount! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: add indicator for notifications' is vague and generic. While it refers to adding an indicator, it doesn't specify what indicator or where it appears (admin menu, submenu, notifications area, etc.). Use a more descriptive title like 'fix: add indicator badge to Cimo submenu when rating notice conditions are met' to clearly convey the specific change.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The pull request successfully addresses both linked issues: #57 is resolved by updating stats in metadata saving, and #58 is resolved by adding the submenu indicator badge with proper threshold checks.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issues: stats updates during metadata saving (#57) and submenu indicator display (#58). No unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/57/58/indicator

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.

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown

🤖 Pull request artifacts

file commit
pr62-cimo-62-merge.zip fda3901

github-actions Bot added a commit that referenced this pull request Jun 15, 2026
github-actions Bot added a commit that referenced this pull request Jun 22, 2026
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.

Add an indicator beside Cimo's submenu entry for rating Update cimo_stats_data during instant optimize

1 participant