Skip to content

Commit e44ec50

Browse files
committed
fix: disableUsingOriginal bug
1 parent 93dcfd1 commit e44ec50

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

packages/mock-addon/src/Panel.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ 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, { mockData: [], disableUsingOriginal: false });
1111
const emit = useChannel({
12-
[EVENTS.SEND]: (newMockData) => {
13-
setState(newMockData);
12+
[EVENTS.SEND]: (newState) => {
13+
setState(newState);
1414
},
1515
});
1616

1717
const onChange = (item, key, value) => {
1818
emit(EVENTS.UPDATE, { item, key, value });
1919
};
2020

21+
const { mockData, disableUsingOriginal } = state;
2122
if (!mockData || mockData.length === 0) {
2223
return (
2324
<AddonPanel {...props}>
@@ -51,6 +52,7 @@ export const Panel = (props) => {
5152
onChange={(key, value) =>
5253
onChange(item, key, value)
5354
}
55+
disableUsingOriginal={disableUsingOriginal}
5456
{...rest}
5557
/>
5658
);

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: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ 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 } = mockAddonConfigs;
2324
const data = [...globalMockData, ...paramData];
2425

2526
/**
@@ -29,7 +30,10 @@ export const withRoundTrip = (storyFn, context) => {
2930
if (INITIAL_MOUNT_STATE) {
3031
faker.makeInitialRequestMap(data);
3132

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

3438
channel.on(STORY_CHANGED, () => {
3539
STORY_CHANGED_STATE = true;
@@ -38,7 +42,10 @@ export const withRoundTrip = (storyFn, context) => {
3842
channel.on(EVENTS.UPDATE, ({ item, key, value }) => {
3943
faker.update(item, key, value);
4044
const req = faker.getRequests();
41-
channel.emit(EVENTS.SEND, req);
45+
channel.emit(EVENTS.SEND, {
46+
mockData: req,
47+
disableUsingOriginal,
48+
});
4249
refreshStoryOnUpdate && channel.emit(FORCE_RE_RENDER);
4350
});
4451

@@ -51,7 +58,10 @@ export const withRoundTrip = (storyFn, context) => {
5158
*/
5259
if (STORY_CHANGED_STATE) {
5360
faker.makeInitialRequestMap(data);
54-
channel.emit(EVENTS.SEND, faker.getRequests());
61+
channel.emit(EVENTS.SEND, {
62+
mockData: faker.getRequests(),
63+
disableUsingOriginal,
64+
});
5565
STORY_CHANGED_STATE = false;
5666
}
5767
return storyFn(context);

0 commit comments

Comments
 (0)