Skip to content

Add storybook for help panel#248

Closed
apinkert wants to merge 9 commits intoRedHatInsights:masterfrom
apinkert:add-storybook
Closed

Add storybook for help panel#248
apinkert wants to merge 9 commits intoRedHatInsights:masterfrom
apinkert:add-storybook

Conversation

@apinkert
Copy link
Copy Markdown
Collaborator

@apinkert apinkert commented Mar 3, 2026

For RHCLOUD-45241

This PR just adds the basic npm framework for storybook and the overview/arch docs for the help panel that can be viewed via npm run storybook

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 3, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds Storybook integration: configuration and preview, Storybook scripts and devDependencies, mock hooks for Chrome/RBAC/Unleash, MSW service worker and loader setup, multiple documentation MDX pages, and an ESLint rule tweak to ignore underscore-prefixed unused args.

Changes

Cohort / File(s) Summary
ESLint Configuration
/.eslintrc.js
Adds argsIgnorePattern: "^_" to no-unused-vars in TS/TSX overrides and Storybook overrides so underscore-prefixed unused arguments are ignored.
Storybook Core Config
.storybook/main.ts, .storybook/preview.tsx
Adds Storybook config and preview: story globs, addons (docs, msw, SWC webpack), static assets, webpackFinal aliases to local mock hooks, SCSS loader rules, TypeScript options, IntlProvider decorator, MSW init, preview parameters and decorators.
Storybook Mock Hooks
RBAC
.storybook/hooks/RBACHook.ts
Unleash
.storybook/hooks/unleash.ts
Chrome mock
.storybook/hooks/useChrome.tsx
Adds mock implementations exported for Storybook: usePermissions (RBAC), useFlags/useFlag/useFlagsStatus/FlagProvider (feature flags), and useChrome (Chrome-like API surface).
MSW Service Worker
static/mockServiceWorker.js
Adds a full MSW service worker: client tracking, install/activate handlers, fetch interception, request serialization, client message handshake, and MOCK_RESPONSE vs PASSTHROUGH handling.
Package & Scripts
package.json
Adds Storybook scripts (storybook, build-storybook, test-storybook, test-storybook:ci), updates lint:js/lint:js:fix to ignore Storybook files, adds msw top-level config, and multiple Storybook/MSW/devDependencies and loaders.
Documentation (MDX)
src/docs/Architecture.mdx, src/docs/Introduction.mdx, src/docs/QuickReference.mdx, src/docs/StorybookGuide.mdx
Adds comprehensive documentation pages and Storybook guides (architecture, introduction, quick reference, Storybook best practices and examples).

Sequence Diagram(s)

sequenceDiagram
    participant Story as Storybook
    participant Decorators as Decorators (Intl/Providers)
    participant App as App Component / Hooks
    participant MSW as MSW Service Worker
    participant Network as Network

    rect rgba(135,206,250,0.5)
    Story->>Decorators: Render story with decorators
    Decorators->>App: Provide Intl, FlagProvider, RBAC, Chrome mocks
    end

    rect rgba(144,238,144,0.5)
    App->>Network: fetch(...) (API request)
    Network->>MSW: intercepted by service worker
    MSW->>App: postMessage serialized request to story client
    App->>MSW: respond with MOCK_RESPONSE or PASSTHROUGH
    MSW->>Network: return mocked or passthrough response
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add storybook for help panel' directly and clearly summarizes the main change: adding Storybook framework to the help panel project.
Description check ✅ Passed The description is directly related to the changeset, explaining the purpose (basic npm Storybook framework), the documentation added, and how to use it via 'npm run storybook'.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% 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 unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Copy link
Copy Markdown

@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

Caution

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

⚠️ Outside diff range comments (1)
package.json (1)

6-7: ⚠️ Potential issue | 🟠 Major

Raise Node engine floor to >=20.0.0 to match @storybook/react-webpack5 requirements.

The @storybook/react-webpack5@9.1.19 package requires Node >=20.0.0, but the current constraint allows Node >=16.20.2. Users with Node 16–19 would encounter failures during storybook, storybook dev, build-storybook, and test-storybook commands.

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

In `@package.json` around lines 6 - 7, Update the Node engine constraint in
package.json so Storybook's requirement is met: change the engines.node field
(in package.json) from ">=16.20.2" to ">=20.0.0" and verify any CI configs or
README tooling notes reflect the new minimum Node version; keep engines.npm
as-is unless you also need to raise npm, and run a quick CI/local Storybook
start to confirm compatibility.
🧹 Nitpick comments (3)
.storybook/hooks/useChrome.tsx (1)

3-39: Consider a silent-by-default logger in this mock.

Frequent console.log calls can add noise in Storybook and test runs; a debug toggle keeps this useful without default verbosity.

Proposed refactor
+const debugMocks = Boolean((globalThis as { __STORYBOOK_DEBUG_MOCKS__?: boolean }).__STORYBOOK_DEBUG_MOCKS__);
+const log = (...args: unknown[]) => {
+  if (debugMocks) console.log(...args);
+};
+
 export const useChrome = () => ({
   analytics: {
     track: (event: string, properties?: Record<string, unknown>) => {
-      console.log('Analytics track:', event, properties);
+      log('Analytics track:', event, properties);
     },
   },
@@
   helpTopics: {
     setActiveTopic: (topic: string) => {
-      console.log('Setting active help topic:', topic);
+      log('Setting active help topic:', topic);
     },
     enableTopics: (topics: string[]) => {
-      console.log('Enabling help topics:', topics);
+      log('Enabling help topics:', topics);
     },
     disableTopics: (topics: string[]) => {
-      console.log('Disabling help topics:', topics);
+      log('Disabling help topics:', topics);
     },
   },
   quickStarts: {
     set: (quickStarts: unknown[]) => {
-      console.log('Setting quick starts:', quickStarts);
+      log('Setting quick starts:', quickStarts);
     },
   },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.storybook/hooks/useChrome.tsx around lines 3 - 39, Replace noisy
console.log calls in the Storybook mock with a silent-by-default logger that
only emits when a debug flag is set; create a simple logger object (e.g.,
debugLogger with methods debug/info/warn) and a toggle (e.g., DEBUG_MOCKS or
logger.enabled) and update the mock functions—analytics.track, auth.getUser (if
it needs logging), helpTopics.setActiveTopic, helpTopics.enableTopics,
helpTopics.disableTopics, and quickStarts.set—to call debugLogger.debug(...)
instead of console.log so logs appear only when the debug toggle is enabled
while preserving the same messages and signatures.
.storybook/hooks/RBACHook.ts (1)

2-6: Make RBAC mock state overridable to support denied/loading stories.

This hardcoded return is fine for a default, but it limits scenario testing in Storybook. Consider exposing a lightweight setter for story-level overrides.

Proposed refactor
+type MockPermissionsState = {
+  hasAccess: boolean;
+  isLoading: boolean;
+  permissions: unknown[];
+};
+
+let mockPermissionsState: MockPermissionsState = {
+  hasAccess: true,
+  isLoading: false,
+  permissions: [],
+};
+
+export const __setMockPermissionsState = (
+  next: Partial<MockPermissionsState>
+) => {
+  mockPermissionsState = { ...mockPermissionsState, ...next };
+};
+
 export const usePermissions = () => ({
-  hasAccess: true,
-  isLoading: false,
-  permissions: [],
+  ...mockPermissionsState,
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.storybook/hooks/RBACHook.ts around lines 2 - 6, Replace the hardcoded
usePermissions return with an overridable mock: change the exported function
usePermissions to accept an optional override object (or initialize internal
state) and return both the current permissions state and a setter (e.g.,
setPermissions) so stories can simulate denied/loading states; update any
callers to use the new tuple/object shape (hasAccess, isLoading, permissions,
setPermissions) so Storybook stories can call setPermissions({ hasAccess: false
}) or setPermissions({ isLoading: true }) to override the defaults.
.storybook/preview.tsx (1)

26-29: Call initialize() at module scope instead of beforeAll.

This aligns with the canonical pattern shown in official Storybook documentation for msw-storybook-addon setup. While beforeAll is officially supported, initialize() is typically called once at module scope before the Preview object definition for clarity and consistency.

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

In @.storybook/preview.tsx around lines 26 - 29, The initialize({
onUnhandledRequest: 'warn' }) call should be moved out of the beforeAll property
and invoked at module scope before the Preview object is defined; remove the
beforeAll entry from the exported Preview configuration and keep loaders:
[mswLoader] intact. Locate the existing beforeAll block that calls initialize
and instead call initialize(...) once at top-level of .storybook/preview.tsx
(above where Preview or export const parameters/export default is declared),
preserving the onUnhandledRequest option so msw-storybook-addon is initialized
exactly once at module load.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.storybook/hooks/unleash.ts:
- Around line 2-11: The Storybook hook currently hardcodes all flags as false,
causing feature-gated UI to be hidden; update useFlags to return a configurable
default map (not all false) and update useFlag(flag) to return the lookup from
that map (i.e., return useFlags()[flag]) so stories render realistic states;
also allow overrides via a simple mechanism (e.g., read a global/window override
like window.__UNLEASH_FLAGS__ or Storybook globals/env var) inside useFlags so
individual stories or QA can flip flags without changing code; change
references: useFlag and useFlags.

In @.storybook/main.ts:
- Around line 7-8: The MDX glob '../src/docs/*.mdx' overlaps with and is
subsumed by '../src/**/*.mdx', causing duplicate Storybook entries; remove the
specific '../src/docs/*.mdx' entry from the stories array (leave
'../src/**/*.mdx' intact) so only the recursive glob '../src/**/*.mdx' remains
and duplicates are eliminated.

---

Outside diff comments:
In `@package.json`:
- Around line 6-7: Update the Node engine constraint in package.json so
Storybook's requirement is met: change the engines.node field (in package.json)
from ">=16.20.2" to ">=20.0.0" and verify any CI configs or README tooling notes
reflect the new minimum Node version; keep engines.npm as-is unless you also
need to raise npm, and run a quick CI/local Storybook start to confirm
compatibility.

---

Nitpick comments:
In @.storybook/hooks/RBACHook.ts:
- Around line 2-6: Replace the hardcoded usePermissions return with an
overridable mock: change the exported function usePermissions to accept an
optional override object (or initialize internal state) and return both the
current permissions state and a setter (e.g., setPermissions) so stories can
simulate denied/loading states; update any callers to use the new tuple/object
shape (hasAccess, isLoading, permissions, setPermissions) so Storybook stories
can call setPermissions({ hasAccess: false }) or setPermissions({ isLoading:
true }) to override the defaults.

In @.storybook/hooks/useChrome.tsx:
- Around line 3-39: Replace noisy console.log calls in the Storybook mock with a
silent-by-default logger that only emits when a debug flag is set; create a
simple logger object (e.g., debugLogger with methods debug/info/warn) and a
toggle (e.g., DEBUG_MOCKS or logger.enabled) and update the mock
functions—analytics.track, auth.getUser (if it needs logging),
helpTopics.setActiveTopic, helpTopics.enableTopics, helpTopics.disableTopics,
and quickStarts.set—to call debugLogger.debug(...) instead of console.log so
logs appear only when the debug toggle is enabled while preserving the same
messages and signatures.

In @.storybook/preview.tsx:
- Around line 26-29: The initialize({ onUnhandledRequest: 'warn' }) call should
be moved out of the beforeAll property and invoked at module scope before the
Preview object is defined; remove the beforeAll entry from the exported Preview
configuration and keep loaders: [mswLoader] intact. Locate the existing
beforeAll block that calls initialize and instead call initialize(...) once at
top-level of .storybook/preview.tsx (above where Preview or export const
parameters/export default is declared), preserving the onUnhandledRequest option
so msw-storybook-addon is initialized exactly once at module load.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 9aeba20 and 02912a1.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (12)
  • .eslintrc.js
  • .storybook/hooks/RBACHook.ts
  • .storybook/hooks/unleash.ts
  • .storybook/hooks/useChrome.tsx
  • .storybook/main.ts
  • .storybook/preview.tsx
  • package.json
  • src/docs/Architecture.mdx
  • src/docs/Introduction.mdx
  • src/docs/QuickReference.mdx
  • src/docs/StorybookGuide.mdx
  • static/mockServiceWorker.js

Comment thread .storybook/hooks/unleash.ts Outdated
Comment thread .storybook/main.ts Outdated
Copy link
Copy Markdown

@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

🧹 Nitpick comments (1)
package.json (1)

24-25: test-storybook:ci is not self-contained unless Storybook is started elsewhere.

test-storybook expects a reachable Storybook instance (default :6006). If CI does not start/serve Storybook before this script, it will fail. Either make the script orchestration explicit or document/enforce the precondition.

Reference:

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

In `@package.json` around lines 24 - 25, The CI script test-storybook:ci currently
runs test-storybook against a live Storybook but doesn't start Storybook itself;
update package.json so test-storybook:ci is self-contained by either (A)
composing a new script that starts Storybook in CI mode, waits for it to be
reachable, runs test-storybook --ci --excludeTags test-skip, and then stops the
Storybook process, or (B) add a precondition note and a pretest script (e.g.,
pretest-storybook) that launches Storybook before test-storybook:ci; update or
add scripts referencing the existing "test-storybook" and "test-storybook:ci"
entries so CI always serves Storybook before running tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@package.json`:
- Line 61: Update the Storybook test runner dependency in package.json from
"@storybook/test-runner": "^0.23.0" to the compatible "^0.19.0" (or the latest
0.19.x) to match Storybook ^9.1.19; after changing the version string for
"@storybook/test-runner" run your package manager (npm install / yarn install /
pnpm install) to update node_modules and the lockfile, and then run the
Storybook tests to confirm everything works with the Test Runner change.
- Around line 6-7: Update the engine constraints in package.json so they meet
Storybook 9 requirements by changing the "node" and "npm" engine entries: set
"node" to ">=20.0.0" and "npm" to ">=10.0.0" (modify the existing "node" and
"npm" keys in package.json accordingly) to ensure installs and runtime match
Storybook 9's minimums.

---

Nitpick comments:
In `@package.json`:
- Around line 24-25: The CI script test-storybook:ci currently runs
test-storybook against a live Storybook but doesn't start Storybook itself;
update package.json so test-storybook:ci is self-contained by either (A)
composing a new script that starts Storybook in CI mode, waits for it to be
reachable, runs test-storybook --ci --excludeTags test-skip, and then stops the
Storybook process, or (B) add a precondition note and a pretest script (e.g.,
pretest-storybook) that launches Storybook before test-storybook:ci; update or
add scripts referencing the existing "test-storybook" and "test-storybook:ci"
entries so CI always serves Storybook before running tests.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between beb76ee and 273fc67.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • package.json

Comment thread package.json Outdated
Comment thread package.json
@apinkert apinkert closed this Mar 6, 2026
@apinkert apinkert deleted the add-storybook branch March 6, 2026 15:01
@apinkert apinkert restored the add-storybook branch March 11, 2026 19:19
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