Skip to content

Commit 7e7eb60

Browse files
author
Sharma
committed
Added the ability to run Constellation Storybooks
1 parent 2cf313f commit 7e7eb60

File tree

13 files changed

+1249
-479
lines changed

13 files changed

+1249
-479
lines changed

.storybook-constellation/main.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import path from 'path';
2+
3+
/** @type { import('@storybook/react-webpack5').StorybookConfig } */
4+
const config = {
5+
stories: ['../src/app/_components//custom-constellation/**/*.stories.@(js|jsx|ts|tsx)'],
6+
7+
typescript: {
8+
reactDocgen: 'react-docgen-typescript'
9+
},
10+
11+
addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-interactions', '@chromatic-com/storybook'],
12+
framework: '@storybook/react-webpack5',
13+
14+
webpackFinal: async config => {
15+
if (config.resolve?.alias) {
16+
config.resolve.alias['@pega/auth/lib/sdk-auth-manager'] = path.resolve(__dirname, '../__mocks__/authManager.tsx');
17+
}
18+
19+
if (config.module) {
20+
config.module.rules?.push(
21+
{
22+
test: /\.(d.ts)$/,
23+
loader: 'null-loader'
24+
},
25+
{
26+
test: /\.(map)$/,
27+
loader: 'null-loader'
28+
},
29+
{
30+
test: /\.tsx?$/,
31+
use: 'ts-loader',
32+
exclude: /node_modules/
33+
}
34+
);
35+
}
36+
37+
return config;
38+
}
39+
};
40+
41+
export default config;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Preview } from '@storybook/react';
2+
import { Configuration, PopoverManager, Toaster, ModalManager, WorkTheme } from '@pega/cosmos-react-core';
3+
import setPCoreMocks from '../__mocks__/pcoreMocks';
4+
5+
setPCoreMocks();
6+
7+
const decorators = [
8+
(Story, context) => {
9+
return (
10+
<Configuration>
11+
<PopoverManager>
12+
<Toaster dismissAfter={5000}>
13+
<ModalManager>
14+
<Story {...context} />
15+
</ModalManager>
16+
</Toaster>
17+
</PopoverManager>
18+
</Configuration>
19+
);
20+
}
21+
];
22+
23+
const parameters = {
24+
backgrounds: {
25+
default: 'App',
26+
values: [
27+
{
28+
name: 'App',
29+
value: WorkTheme.base.palette['app-background']
30+
},
31+
{
32+
name: 'Primary',
33+
value: WorkTheme.base.palette['primary-background']
34+
},
35+
{
36+
name: 'Secondary',
37+
value: WorkTheme.base.palette['secondary-background']
38+
}
39+
]
40+
},
41+
tags: ['!autodocs']
42+
};
43+
44+
const preview: Preview = {
45+
decorators,
46+
parameters
47+
};
48+
49+
export default preview;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"resolveJsonModule": true,
77
"emitDecoratorMetadata": false
88
},
9-
"exclude": ["../src/test.ts", "../src/**/*.spec.ts", "../src/app/_components/custom-constellation/**"],
9+
"exclude": ["../src/test.ts", "../src/**/*.spec.ts"],
1010
"include": ["../src/**/*", "./preview.ts", "../__mocks__/*"],
1111
"files": ["./typings.d.ts"]
1212
}

__mocks__/react_pconnect.jsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// /* eslint-disable react/jsx-filename-extension */
2+
3+
// import TextInput from '@pega/react-sdk-components/lib/components/field/TextInput';
4+
// import AutoComplete from '@pega/react-sdk-components/lib/components/field/AutoComplete';
5+
// import Email from '@pega/react-sdk-components/lib/components/field/Email';
6+
// import Phone from '@pega/react-sdk-components/lib/components/field/Phone';
7+
// import Operator from '@pega/react-sdk-components/lib/components/designSystemExtension/Operator';
8+
// import Currency from '@pega/react-sdk-components/lib/components/field/Currency';
9+
// import RadioButtons from '@pega/react-sdk-components/lib/components/field/RadioButtons';
10+
11+
// // Making TextInput the default component
12+
// let compType = TextInput;
13+
// let formIndex = 0;
14+
// let detailsIndex = 0;
15+
// let detailsRegionIndex = 0;
16+
17+
// const createPConnectComponent = () => {
18+
// const formComponents = [TextInput, TextInput, TextInput, Phone, AutoComplete, Email];
19+
// const detailsComponents = [TextInput, TextInput, TextInput, Email, Phone, Currency, RadioButtons, Operator];
20+
// const detailsRegionComponents = [
21+
// TextInput,
22+
// TextInput,
23+
// TextInput,
24+
// Email,
25+
// Phone,
26+
// Currency,
27+
// RadioButtons,
28+
// TextInput,
29+
// TextInput,
30+
// TextInput,
31+
// Email,
32+
// Phone,
33+
// Currency,
34+
// Operator
35+
// ];
36+
37+
// let component;
38+
39+
// switch (compType) {
40+
// case 'Details':
41+
// if (detailsIndex >= detailsComponents.length) {
42+
// detailsIndex = 0;
43+
// }
44+
// component = detailsComponents[detailsIndex++];
45+
// break;
46+
47+
// case 'DetailsRegion':
48+
// if (detailsRegionIndex >= detailsRegionComponents.length) {
49+
// detailsRegionIndex = 0;
50+
// }
51+
// component = detailsRegionComponents[detailsRegionIndex++];
52+
// break;
53+
54+
// default:
55+
// if (formIndex >= formComponents.length) {
56+
// formIndex = 0;
57+
// }
58+
// component = formComponents[formIndex++];
59+
// }
60+
61+
// return component;
62+
// };
63+
// export default createPConnectComponent;
64+
65+
// // The decorator to be used in ./storybook/preview to apply the mock to all stories
66+
67+
// export function decorator(story, parameters) {
68+
// compType = parameters.parameters?.type;
69+
// return story();
70+
// }

__mocks__/state-utils.tsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// import { connect, Provider, shallowEqual } from 'react-redux';
2+
3+
// const connectToState = (mapStateToProps = () => {}) => {
4+
// return Component => {
5+
// const ConnectedComponent = connect(mapStateToProps, null, null, {
6+
// areStatePropsEqual: (next, prev: any) => {
7+
// // Compare visibility
8+
// const prevWasVisible = prev.visibility !== false;
9+
// if (next.visibility !== undefined && next.visibility !== prevWasVisible) {
10+
// return false;
11+
// }
12+
// // Compare start props
13+
// const c11nEnv = next.getPConnect();
14+
// const allStateProps = c11nEnv.getStateProps();
15+
// for (const key of Object.keys(allStateProps)) {
16+
// if (!shallowEqual(next[key], prev[key]) || (next.routingInfo && !PCore.isDeepEqual(next.routingInfo, prev.routingInfo))) {
17+
// return false;
18+
// }
19+
// }
20+
// /* TODO For some rawConfig we are not getting routingInfo under allStateProps */
21+
// return !(
22+
// 'routingInfo' in next &&
23+
// (!shallowEqual(next.routingInfo, prev.routingInfo) || !PCore.isDeepEqual(next.routingInfo, prev.routingInfo))
24+
// );
25+
// }
26+
// })(Component);
27+
28+
// return (ownProps = {}) => {
29+
// const store = { getState: () => {}, subscribe: () => {}, dispatch: () => {} };
30+
31+
// return (
32+
// <Provider store={store}>
33+
// <ConnectedComponent {...ownProps} />
34+
// </Provider>
35+
// );
36+
// };
37+
// };
38+
// };
39+
40+
// export default connectToState;

0 commit comments

Comments
 (0)