Skip to content

Commit 82b3cfd

Browse files
authored
Merge pull request #185 from linearlabs-workspace/fix/disableUsingOriginal-bug
fix: disableUsingOriginal bug
2 parents 93dcfd1 + 38c7242 commit 82b3cfd

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

packages/mock-addon/src/Panel.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@ import { MockItem } from './components/MockItem';
77
import { ErrorItem } from './components/ErrorItem';
88

99
export const Panel = (props) => {
10-
const [mockData, setState] = useAddonState(ADDON_ID, []);
10+
const [state, setState] = useAddonState(ADDON_ID, {
11+
mockData: [],
12+
disableUsingOriginal: false,
13+
});
1114
const emit = useChannel({
12-
[EVENTS.SEND]: (newMockData) => {
13-
setState(newMockData);
15+
[EVENTS.SEND]: (newState) => {
16+
setState(newState);
1417
},
1518
});
1619

1720
const onChange = (item, key, value) => {
1821
emit(EVENTS.UPDATE, { item, key, value });
1922
};
2023

24+
const { mockData, disableUsingOriginal } = state;
2125
if (!mockData || mockData.length === 0) {
2226
return (
2327
<AddonPanel {...props}>
@@ -51,6 +55,7 @@ export const Panel = (props) => {
5155
onChange={(key, value) =>
5256
onChange(item, key, value)
5357
}
58+
disableUsingOriginal={disableUsingOriginal}
5459
{...rest}
5560
/>
5661
);

packages/mock-addon/src/components/MockItem/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { useParameter } from '@storybook/manager-api';
43
import { styled } from '@storybook/theming';
54
import { ObjectControl, RangeControl } from '@storybook/blocks';
65
import { Form, Placeholder, TabsState } from '@storybook/components';
@@ -86,8 +85,8 @@ export const MockItem = ({
8685
response,
8786
delay,
8887
onChange,
88+
disableUsingOriginal,
8989
}) => {
90-
const { disableUsingOriginal } = useParameter();
9190
return (
9291
<Card
9392
onToggle={(value) => onChange('skip', !value)}
@@ -159,4 +158,5 @@ MockItem.propTypes = {
159158
response: PropTypes.any,
160159
delay: PropTypes.number.isRequired,
161160
onChange: PropTypes.func.isRequired,
161+
disableUsingOriginal: PropTypes.bool.isRequired,
162162
};

packages/mock-addon/src/withRoundTrip.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ export const withRoundTrip = (storyFn, context) => {
1818
const mockAddonConfigs = getParameter(parameters, GLOBAL_PARAM_KEY, {
1919
refreshStoryOnUpdate: false,
2020
globalMockData: [],
21+
disableUsingOriginal: false,
2122
});
22-
const { globalMockData, refreshStoryOnUpdate } = mockAddonConfigs;
23+
const { globalMockData, refreshStoryOnUpdate, disableUsingOriginal } =
24+
mockAddonConfigs;
2325
const data = [...globalMockData, ...paramData];
2426

2527
/**
@@ -29,7 +31,10 @@ export const withRoundTrip = (storyFn, context) => {
2931
if (INITIAL_MOUNT_STATE) {
3032
faker.makeInitialRequestMap(data);
3133

32-
channel.emit(EVENTS.SEND, faker.getRequests());
34+
channel.emit(EVENTS.SEND, {
35+
mockData: faker.getRequests(),
36+
disableUsingOriginal,
37+
});
3338

3439
channel.on(STORY_CHANGED, () => {
3540
STORY_CHANGED_STATE = true;
@@ -38,7 +43,10 @@ export const withRoundTrip = (storyFn, context) => {
3843
channel.on(EVENTS.UPDATE, ({ item, key, value }) => {
3944
faker.update(item, key, value);
4045
const req = faker.getRequests();
41-
channel.emit(EVENTS.SEND, req);
46+
channel.emit(EVENTS.SEND, {
47+
mockData: req,
48+
disableUsingOriginal,
49+
});
4250
refreshStoryOnUpdate && channel.emit(FORCE_RE_RENDER);
4351
});
4452

@@ -51,7 +59,10 @@ export const withRoundTrip = (storyFn, context) => {
5159
*/
5260
if (STORY_CHANGED_STATE) {
5361
faker.makeInitialRequestMap(data);
54-
channel.emit(EVENTS.SEND, faker.getRequests());
62+
channel.emit(EVENTS.SEND, {
63+
mockData: faker.getRequests(),
64+
disableUsingOriginal,
65+
});
5566
STORY_CHANGED_STATE = false;
5667
}
5768
return storyFn(context);

0 commit comments

Comments
 (0)