Skip to content

feat(plugins): Optimize plugin badge fetching and rendering to preven…#1580

Merged
jokob-sk merged 2 commits intomainfrom
next_release
Mar 27, 2026
Merged

feat(plugins): Optimize plugin badge fetching and rendering to preven…#1580
jokob-sk merged 2 commits intomainfrom
next_release

Conversation

@jokob-sk
Copy link
Copy Markdown
Collaborator

@jokob-sk jokob-sk commented Mar 27, 2026

…t flicker and enhance visibility

Summary by CodeRabbit

  • Refactor
    • Plugin badge counts are shown immediately and empty plugins are filtered out earlier to avoid flicker.
    • Inner sub-tabs with zero items are hidden automatically; the first visible sub-tab becomes active when needed.
    • Inactive sub-tabs are initialized on demand to improve load performance and responsiveness.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e2ddd0b7-05a8-4527-82c1-d65cca22ed7e

📥 Commits

Reviewing files that changed from the base of the PR and between 77369c3 and b18cf98.

📒 Files selected for processing (1)
  • front/pluginsCore.php
✅ Files skipped from review due to trivial changes (1)
  • front/pluginsCore.php

📝 Walkthrough

Walkthrough

Moved plugin badge/count fetching before tab DOM creation, replacing prefetchPluginBadges() with fetchPluginCounts() and applyPluginBadges(). Tabs are generated only for plugins with non-zero counts (fail-open on error); inner sub-tabs with zero totals are hidden and initialization order for data tables was adjusted.

Changes

Cohort / File(s) Summary
Plugin Count and Tab Logic Refactoring
front/pluginsCore.php
Added global pluginCounts; replaced prefetchPluginBadges() with fetchPluginCounts(prefixes) (returns counts or null) and applyPluginBadges(counts, prefixes) (updates badges, hides zero-count inner sub-tabs); moved count fetch to before generateTabs() so only non-empty plugins create tabs; simplified autoHideEmptyTabs() to only hide inner sub-tabs; updated createTabHeader/createTabContent/generateTabNavigation to accept counts and render badges immediately; refactored initializeDataTables() to init the active inner sub-tab immediately and defer others via shown.bs.tab.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Frontend as Frontend JS
  participant API as Backend API
  participant DOM as Browser DOM

  User->>Frontend: open Plugins page
  Frontend->>API: fetchPluginCounts(prefixes)
  API-->>Frontend: counts JSON / error
  alt counts received
    Frontend->>Frontend: compute visiblePlugins from counts
    Frontend->>DOM: generateTabs(visiblePlugins, counts)
    Frontend->>Frontend: applyPluginBadges(counts, prefixes)
    Frontend->>DOM: initialize active inner sub-tab (Objects/Events/History)
  else fetch error (fail-open)
    Frontend->>Frontend: generateTabs(all show_ui plugins, null)
    Frontend->>DOM: initialize default tab flow
  end
Loading

Possibly related PRs

Poem

🐰
Hopped through tabs with nimble paws,
Split one fetch into clearer laws,
Counts arrive before the frame,
Empty sub-tabs hide—no blame,
Cleaner hops, a brighter GUI clause.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(plugins): Optimize plugin badge fetching and rendering to prevent...' clearly and specifically summarizes the main change in the PR, which focuses on optimizing badge fetching/rendering and preventing flicker while enhancing visibility.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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 next_release

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.

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: 3

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

Inline comments:
In `@front/pluginsCore.php`:
- Around line 288-290: The prefetch of badge counts (fetchPluginCounts called
with pluginDefinitions.map p=>p.unique_prefix) currently treats errors/empty
responses as zero and skips rendering tabs; change it to "fail open": when
fetchPluginCounts rejects or response.errors exists, set pluginCounts to
null/undefined (or leave it unset) and log the error, but do not block tab
creation; update any rendering logic that checks pluginCounts (and the prefixes
handling) to treat a missing count as "unknown" (i.e., show the plugin if
p.show_ui) instead of hiding it so DataTable queries still render; ensure the
same change is applied to the other occurrences referenced (around the sections
using fetchPluginCounts at the other ranges) and keep fetchPluginCounts error
handling robust (catch exceptions and continue).
- Around line 381-393: The code is directly interpolating foreignKey into the
GraphQL document via fkOpt and the query built from prefixes.map, which allows
injection from the ?mac= URL param; change this to use GraphQL variables instead
of string concatenation: remove fkOpt interpolation and build the fragments
without embedding foreignKey, create a variables object (e.g., { foreignKey })
and send the query and variables to the server using the same pattern as
postPluginGraphQL(), and update the AJAX call to JSON.stringify({ query,
variables }) so pluginsObjects/pluginsEvents/pluginsHistory receive the
foreignKey via variables rather than inline text.
- Around line 460-466: The bug is that initializeDataTables() always targets the
Objects inner tab even when autoHideEmptyTabs() has hidden it and a different
inner sub-tab is active; update the logic where activeSubHidden is handled (the
block using activeSubHidden, $pane.find('ul.nav-tabs li:visible:first a',
$firstVisibleSubA, and $firstVisibleSubA.tab('show')) so that instead of forcing
the first visible sub-tab to show, you detect which inner sub-tab is currently
active (or was programmatically activated by autoHideEmptyTabs()) and explicitly
initialize that active sub-tab's DataTable via the same DataTable initialization
routine (the code path used by initializeDataTables()), and if necessary trigger
shown.bs.tab only for deferred initialization listeners for that specific active
sub-tab so its table gets initialized when the outer tab opens.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8befec67-9554-427f-8da5-8ed051d0accd

📥 Commits

Reviewing files that changed from the base of the PR and between 49b72ac and 77369c3.

📒 Files selected for processing (1)
  • front/pluginsCore.php

@jokob-sk jokob-sk merged commit 82dafbb into main Mar 27, 2026
6 checks passed
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.

1 participant