Skip to content

Commit 8f6bdbd

Browse files
committed
feat: add user journey support + learn panel
1 parent 4039845 commit 8f6bdbd

17 files changed

Lines changed: 2174 additions & 2 deletions

.storybook/hooks/scalprum.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Mock @scalprum/react-core for Storybook
3+
* Based on insights-rbac-ui pattern
4+
*/
5+
6+
// Mock Models object for virtual assistant
7+
const mockModels = {
8+
ASK_RED_HAT: 'mock-ask-red-hat-model',
9+
};
10+
11+
// Mock useLoadModule hook - returns mock module and loading: false
12+
export const useLoadModule = () => [mockModels, { loading: false }];
13+
14+
// Mock useRemoteHook - returns empty hook result and loading: false
15+
export const useRemoteHook = () => ({
16+
hookResult: [null, () => {}], // Mock state and setState
17+
loading: false
18+
});
19+
20+
// Mock useGetState - returns empty state
21+
export const useGetState = () => ({});
22+
23+
// Mock other exports that might be needed
24+
export const initialize = () => {};
25+
export const getScalprum = () => ({});

.storybook/hooks/unleash.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Mock @unleash/proxy-client-react for Storybook
3+
* Based on insights-rbac-ui pattern
4+
*/
5+
6+
// Mock useFlag hook - always returns false
7+
export const useFlag = () => false;
8+
9+
// Mock other exports
10+
export const FlagProvider = ({ children }) => children;
11+
export const UnleashClient = class {};
12+
export const useUnleashContext = () => ({});
13+
export const useVariant = () => ({ name: 'disabled', enabled: false });
14+
export const useFlags = () => [];

.storybook/hooks/useChrome.tsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* Mock useChrome for Storybook
3+
* Based on insights-rbac-ui pattern
4+
*/
5+
6+
export default function useChrome() {
7+
// Return the mock chrome from window if available
8+
if (typeof window !== 'undefined' && window.insights?.chrome) {
9+
// @ts-ignore
10+
return window.insights.chrome;
11+
}
12+
13+
// Fallback mock
14+
return {
15+
auth: {
16+
getUser: async () => ({
17+
identity: {
18+
account_number: '12345',
19+
org_id: '67890',
20+
user: {
21+
username: 'testuser',
22+
email: 'test@example.com',
23+
first_name: 'Test',
24+
last_name: 'User',
25+
is_active: true,
26+
is_org_admin: false,
27+
},
28+
internal: {
29+
account_id: '12345',
30+
},
31+
},
32+
}),
33+
},
34+
getBundleData: () => ({ bundleId: 'insights' }),
35+
getAvailableBundles: () => [
36+
{ id: 'insights', title: 'Red Hat Insights' },
37+
{ id: 'ansible', title: 'Ansible Automation Platform' },
38+
{ id: 'openshift', title: 'OpenShift' },
39+
{ id: 'settings', title: 'Settings' },
40+
],
41+
updateDocumentTitle: (title: string) => {
42+
if (typeof document !== 'undefined') {
43+
document.title = title;
44+
}
45+
},
46+
hideGlobalFilter: () => {},
47+
isBeta: () => false,
48+
isProd: () => false,
49+
getEnvironment: () => 'stage',
50+
};
51+
}
52+
53+
// Named export for compatibility
54+
export { useChrome };

.storybook/main.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { StorybookConfig } from '@storybook/react-webpack5';
22
import remarkGfm from 'remark-gfm';
3+
import path from 'path';
34

45
const config: StorybookConfig = {
56
stories: ['../src/docs/*.mdx', '../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
@@ -15,6 +16,7 @@ const config: StorybookConfig = {
1516
},
1617
},
1718
},
19+
'msw-storybook-addon',
1820
],
1921
framework: {
2022
name: '@storybook/react-webpack5',
@@ -24,6 +26,27 @@ const config: StorybookConfig = {
2426
defaultName: 'Documentation',
2527
},
2628
webpackFinal: async (config) => {
29+
// Mock external dependencies for Storybook (same pattern as insights-rbac-ui)
30+
config.resolve = {
31+
...config.resolve,
32+
alias: {
33+
...config.resolve?.alias,
34+
// External dependency mocks
35+
'@redhat-cloud-services/frontend-components/useChrome': path.resolve(
36+
process.cwd(),
37+
'.storybook/hooks/useChrome.tsx'
38+
),
39+
'@unleash/proxy-client-react': path.resolve(
40+
process.cwd(),
41+
'.storybook/hooks/unleash.js'
42+
),
43+
'@scalprum/react-core': path.resolve(
44+
process.cwd(),
45+
'.storybook/hooks/scalprum.js'
46+
),
47+
},
48+
};
49+
2750
// Add SCSS support
2851
config.module = config.module || {};
2952
config.module.rules = config.module.rules || [];
@@ -44,6 +67,7 @@ const config: StorybookConfig = {
4467
propFilter: (prop) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
4568
},
4669
},
70+
staticDirs: ['../public'],
4771
};
4872

4973
export default config;

.storybook/preview.tsx

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,61 @@
11
import type { Preview } from '@storybook/react-webpack5';
22
import '@patternfly/react-core/dist/styles/base.css';
33
import React from 'react';
4+
import { initialize, mswLoader } from 'msw-storybook-addon';
5+
6+
// Set up global chrome mock immediately
7+
if (typeof window !== 'undefined') {
8+
const defaultMockChrome = {
9+
auth: {
10+
getUser: async () => ({
11+
identity: {
12+
account_number: '12345',
13+
org_id: '67890',
14+
user: {
15+
username: 'testuser',
16+
email: 'test@example.com',
17+
first_name: 'Test',
18+
last_name: 'User',
19+
is_active: true,
20+
is_org_admin: false,
21+
},
22+
internal: {
23+
account_id: '12345',
24+
},
25+
},
26+
}),
27+
},
28+
getBundleData: () => ({ bundleId: 'insights' }),
29+
getAvailableBundles: () => [
30+
{ id: 'insights', title: 'Red Hat Insights' },
31+
{ id: 'ansible', title: 'Ansible Automation Platform' },
32+
{ id: 'openshift', title: 'OpenShift' },
33+
{ id: 'settings', title: 'Settings' },
34+
],
35+
updateDocumentTitle: (title: string) => {
36+
document.title = title;
37+
},
38+
hideGlobalFilter: () => {},
39+
isBeta: () => false,
40+
isProd: () => false,
41+
getEnvironment: () => 'stage',
42+
};
43+
44+
// @ts-ignore
45+
window.insights = { chrome: defaultMockChrome };
46+
}
447

548
const preview: Preview = {
49+
beforeAll: async () => {
50+
// Initialize MSW with error on unhandled requests to catch missing mocks
51+
initialize({ onUnhandledRequest: 'warn' });
52+
},
53+
loaders: [mswLoader],
654
parameters: {
755
options: {
856
storySort: {
957
method: 'alphabetical',
10-
order: ['Documentation', '*'],
58+
order: ['Documentation', 'User Journeys', 'Components', '*'],
1159
},
1260
},
1361
layout: 'fullscreen',

0 commit comments

Comments
 (0)