Skip to content

feat(bricks): CSS bundle selector in admin panel, remove legacy admin page - #134

Merged
jackgranatowski merged 3 commits into
mainfrom
claude/bricks-css-admin-panel-Az1Qv
May 28, 2026
Merged

feat(bricks): CSS bundle selector in admin panel, remove legacy admin page#134
jackgranatowski merged 3 commits into
mainfrom
claude/bricks-css-admin-panel-Az1Qv

Conversation

@jackgranatowski

@jackgranatowski jackgranatowski commented May 28, 2026

Copy link
Copy Markdown
Contributor
  • Add css_bundle plugin setting (essential / optimal / full) so admins
    can choose which SLASHED CSS file is loaded on the frontend
  • Add slashed_bricks_get_css_bundle() helper; update slashed_bricks_get_css_url()
    and class-enqueue.php to use the configured bundle instead of hardcoded optimal
  • Extend REST /settings endpoint to accept and persist css_bundle;
    both html_font_size and css_bundle are now optional (partial-update semantics)
  • Add CSS Bundle selector to BundleTab.svelte, send both settings on save
  • Promote Svelte admin page to the top-level SLASHED menu (slug slashed-bricks,
    position 59, dashicons-art); remove the legacy jQuery admin page from the load chain
  • Rebuild admin-app bundle

https://claude.ai/code/session_01Gq4QNEeg6sk74oSWqatzH4

Summary by CodeRabbit

  • New Features

    • Added configurable CSS Bundle setting with three options (essential, optimal, full) to optimize CSS loading.
  • UI Changes

    • Moved admin settings to a top-level menu and updated admin text and loading message.
    • Increased spacing between settings rows for improved readability.
  • Settings

    • Settings can be updated partially (individual fields optional), and saving now persists the CSS bundle choice.

Review Change Stack

… page

- Add `css_bundle` plugin setting (essential / optimal / full) so admins
  can choose which SLASHED CSS file is loaded on the frontend
- Add `slashed_bricks_get_css_bundle()` helper; update `slashed_bricks_get_css_url()`
  and `class-enqueue.php` to use the configured bundle instead of hardcoded optimal
- Extend REST `/settings` endpoint to accept and persist `css_bundle`;
  both `html_font_size` and `css_bundle` are now optional (partial-update semantics)
- Add CSS Bundle selector to BundleTab.svelte, send both settings on save
- Promote Svelte admin page to the top-level SLASHED menu (slug `slashed-bricks`,
  position 59, dashicons-art); remove the legacy jQuery admin page from the load chain
- Rebuild admin-app bundle

https://claude.ai/code/session_01Gq4QNEeg6sk74oSWqatzH4
@coderabbitai

coderabbitai Bot commented May 28, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 43f15572-9cec-442f-8a81-adb9a7eb0f13

📥 Commits

Reviewing files that changed from the base of the PR and between e30d2b2 and a0c6bd3.

📒 Files selected for processing (4)
  • integrations/bricks/includes/class-enqueue.php
  • integrations/bricks/includes/class-rest-controller.php
  • integrations/bricks/includes/class-token-store.php
  • integrations/bricks/slashed-bricks.php
✅ Files skipped from review due to trivial changes (1)
  • integrations/bricks/includes/class-token-store.php
🚧 Files skipped from review as they are similar to previous changes (2)
  • integrations/bricks/includes/class-rest-controller.php
  • integrations/bricks/slashed-bricks.php

📝 Walkthrough

Walkthrough

This PR migrates the Bricks admin integration from a PHP-based form to a Svelte-based SPA mounted as a top-level menu page, and adds a CSS bundle selection (essential, optimal, full) that is validated, persisted, surfaced in the Svelte UI, and used to choose/cache-bust the frontend CSS URL.

Changes

CSS Bundle Selection & Admin Page Migration

Layer / File(s) Summary
CSS Bundle Persistence & Validation
integrations/bricks/includes/class-rest-controller.php, integrations/bricks/includes/class-token-store.php, integrations/bricks/slashed-bricks.php
REST /settings POST now makes html_font_size optional and adds css_bundle with validation limited to `essential
CSS Bundle Frontend UI & Binding
integrations/bricks/admin-app/src/components/BundleTab.svelte, integrations/bricks/assets/admin-app/app.css
BundleTab adds bundle state initialized from hydrated pluginSettings, a select control for essential/optimal/full, and updates handleSave() to persist css_bundle alongside html_font_size. Component and shared CSS increase .setting-row bottom margin.
CSS Enqueue & Cache-Busting
integrations/bricks/includes/class-enqueue.php
enqueue_frontend_styles() now parses the resolved $css_url to extract the filename (e.g., slashed.optimal.css) and uses that filename to construct repo/local paths for filemtime() cache-busting, falling back to SLASHED_BRICKS_VERSION if no local file exists.
Admin Page Refactoring — Top-Level Menu
integrations/bricks/includes/class-admin-page-svelte.php
Registers the SPA as a top-level admin page (PAGE_SLUG changed), replaces submenu registration with register_menu() using add_menu_page(), updates constructor hook, and simplifies some UI strings and comments (noscript/loading text).
Admin Initialization & Legacy Cleanup
integrations/bricks/slashed-bricks.php
Loads token store earlier, adds slashed_bricks_get_css_bundle(), updates slashed_bricks_get_css_url() for bundle variants, and updates slashed_bricks_admin_init() to instantiate the Svelte admin page instead of the legacy PHP admin page.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • codeslash-dev/SLASHED#74: Modifies slashed_bricks_get_css_url()/CSS bundle URL selection logic (CDN/local precedence).
  • codeslash-dev/SLASHED#98: Extends BundleTab and REST /settings flow for admin settings that this PR further expands to persist css_bundle.
  • codeslash-dev/SLASHED#81: Adds CSS inventory parsing that consumes the active css_bundle selection to derive design tokens.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 78.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes both main changes: adding a CSS bundle selector to the admin panel and removing the legacy admin page.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 claude/bricks-css-admin-panel-Az1Qv

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.

- Use Slashed_Bricks_Token_Store::get_plugin_settings() in
  slashed_bricks_get_css_bundle() instead of direct get_option() call,
  consistent with the Token Store's single-source-of-truth design
- Move class-token-store.php require_once to the top of the file so it
  is available before the helper functions that depend on it
- Eliminate duplicate settings read in enqueue_frontend_styles() by
  deriving the CSS filename from the already-resolved URL via
  wp_parse_url/basename instead of calling get_css_bundle() a second time
- Guard REST POST /settings against empty requests: return current settings
  without a write when neither field is present
- Delete orphaned class-admin-page.php (was no longer loaded; keeping it
  on disk risked "class not found" errors for any code using its
  backwards-compat OPTION_NAME / SETTINGS_OPTION_NAME constants)
- Fix trailing double space in slashed_bricks_get_css_url() docblock
- Update stale slashed_bricks_admin_init() docblock
- Restore explanatory comments in class-admin-page-svelte.php (hook suffix
  capture rationale, type=module regex reasoning, missing-bundle dev hint)

https://claude.ai/code/session_01Gq4QNEeg6sk74oSWqatzH4

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
integrations/bricks/includes/class-enqueue.php (1)

67-75: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard empty filename before local filemtime() checks.

When a filtered CSS URL has no file path, $filename can be empty and file_exists()/filemtime() may run against a directory path. Add a filename guard and fall back to SLASHED_BRICKS_VERSION.

Suggested patch
-        $filename   = basename( (string) wp_parse_url( $css_url, PHP_URL_PATH ) );
-        $repo_path  = SLASHED_BRICKS_PATH . '../../dist/' . $filename;
-        $local_path = SLASHED_BRICKS_PATH . 'dist/' . $filename;
+        $filename = basename( (string) wp_parse_url( $css_url, PHP_URL_PATH ) );
+        if ( '' === $filename ) {
+            $version = SLASHED_BRICKS_VERSION;
+        } else {
+            $repo_path  = SLASHED_BRICKS_PATH . '../../dist/' . $filename;
+            $local_path = SLASHED_BRICKS_PATH . 'dist/' . $filename;
 
-        if ( file_exists( $repo_path ) ) {
-            $version = (string) filemtime( $repo_path );
-        } elseif ( file_exists( $local_path ) ) {
-            $version = (string) filemtime( $local_path );
+            if ( file_exists( $repo_path ) ) {
+                $version = (string) filemtime( $repo_path );
+            } elseif ( file_exists( $local_path ) ) {
+                $version = (string) filemtime( $local_path );
+            } else {
+                $version = SLASHED_BRICKS_VERSION;
+            }
-        } else {
-            $version = SLASHED_BRICKS_VERSION;
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integrations/bricks/includes/class-enqueue.php` around lines 67 - 75, Add a
guard to ensure $filename is non-empty before calling file_exists()/filemtime()
on $repo_path/$local_path: if empty($filename) set $version =
SLASHED_BRICKS_VERSION and skip the file checks; otherwise proceed with the
existing file_exists($repo_path)/file_exists($local_path) branches and set
$version = (string) filemtime(...) as before (variables: $filename, $repo_path,
$local_path, SLASHED_BRICKS_VERSION).
🧹 Nitpick comments (1)
integrations/bricks/includes/class-rest-controller.php (1)

126-133: ⚡ Quick win

Consolidate CSS bundle allowlist into one source of truth.

The essential|optimal|full allowlist is duplicated here and in runtime resolution logic. Please centralize it (shared constant/helper) to prevent contract drift across REST validation and URL resolution.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@integrations/bricks/includes/class-rest-controller.php` around lines 126 -
133, Extract the CSS bundle allowlist ('essential','optimal','full') into a
single shared constant or helper (e.g., ALLOWED_CSS_BUNDLES or
get_allowed_css_bundles()) and replace the duplicated literal array in the
'css_bundle' field's validate_callback (the anonymous function in
class-rest-controller.php) and in the runtime URL resolution logic to reference
that constant/helper; keep the existing strict in_array casting/true flags and
ensure the validate_callback still returns a boolean and sanitize as string
before validation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@integrations/bricks/includes/class-enqueue.php`:
- Around line 67-75: Add a guard to ensure $filename is non-empty before calling
file_exists()/filemtime() on $repo_path/$local_path: if empty($filename) set
$version = SLASHED_BRICKS_VERSION and skip the file checks; otherwise proceed
with the existing file_exists($repo_path)/file_exists($local_path) branches and
set $version = (string) filemtime(...) as before (variables: $filename,
$repo_path, $local_path, SLASHED_BRICKS_VERSION).

---

Nitpick comments:
In `@integrations/bricks/includes/class-rest-controller.php`:
- Around line 126-133: Extract the CSS bundle allowlist
('essential','optimal','full') into a single shared constant or helper (e.g.,
ALLOWED_CSS_BUNDLES or get_allowed_css_bundles()) and replace the duplicated
literal array in the 'css_bundle' field's validate_callback (the anonymous
function in class-rest-controller.php) and in the runtime URL resolution logic
to reference that constant/helper; keep the existing strict in_array
casting/true flags and ensure the validate_callback still returns a boolean and
sanitize as string before validation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e1bef3ed-34a9-441e-b504-a6e65bf1c3a2

📥 Commits

Reviewing files that changed from the base of the PR and between 4f4f709 and e30d2b2.

📒 Files selected for processing (8)
  • integrations/bricks/admin-app/src/components/BundleTab.svelte
  • integrations/bricks/assets/admin-app/app.css
  • integrations/bricks/assets/admin-app/app.js
  • integrations/bricks/includes/class-admin-page-svelte.php
  • integrations/bricks/includes/class-admin-page.php
  • integrations/bricks/includes/class-enqueue.php
  • integrations/bricks/includes/class-rest-controller.php
  • integrations/bricks/slashed-bricks.php
💤 Files with no reviewable changes (1)
  • integrations/bricks/includes/class-admin-page.php

- Guard empty $filename in enqueue_frontend_styles() so a filtered CSS
  URL with no file path falls back to SLASHED_BRICKS_VERSION without
  running file_exists()/filemtime() against an unintended path
- Centralise the css_bundle allowlist as Slashed_Bricks_Token_Store::ALLOWED_CSS_BUNDLES
  and replace the duplicated literal arrays in slashed_bricks_get_css_bundle()
  and the REST validate_callback to reference the single constant

https://claude.ai/code/session_01Gq4QNEeg6sk74oSWqatzH4
@jackgranatowski
jackgranatowski merged commit 5ad2eb3 into main May 28, 2026
5 checks passed
@jackgranatowski
jackgranatowski deleted the claude/bricks-css-admin-panel-Az1Qv branch May 31, 2026 18:01
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