Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX issue where the customQueryParams weren't being applied to the eject iframe button #6817

Merged
merged 2 commits into from
May 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion addons/knobs/src/components/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default class KnobPanel extends PureComponent {

handleChange = changedKnob => {
this.lastEdit = getTimestamp();
const { api } = this.props;
const { knobs } = this.state;
const { name } = changedKnob;
const newKnobs = { ...knobs };
Expand All @@ -135,7 +136,18 @@ export default class KnobPanel extends PureComponent {
...changedKnob,
};

this.setState({ knobs: newKnobs }, this.emitChange(changedKnob));
this.setState({ knobs: newKnobs }, () => {
this.emitChange(changedKnob);

const queryParams = {};

Object.keys(newKnobs).forEach(n => {
const knob = newKnobs[n];
queryParams[`knob-${n}`] = Types[knob.type].serialize(knob.value);
});

api.setQueryParams(queryParams);
});
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
};

handleClick = knob => {
Expand Down
5 changes: 3 additions & 2 deletions lib/ui/src/components/preview/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,15 @@ const getTools = memoize(10)(
);

class Preview extends Component {
shouldComponentUpdate({ storyId, viewMode, options }) {
shouldComponentUpdate({ storyId, viewMode, options, queryParams }) {
const { props } = this;

return (
options.isFullscreen !== props.options.isFullscreen ||
options.isToolshown !== props.options.isToolshown ||
viewMode !== props.viewMode ||
storyId !== props.storyId
storyId !== props.storyId ||
queryParams !== props.queryParams
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down
3 changes: 2 additions & 1 deletion lib/ui/src/containers/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const addExtraWhiteSpace = input =>
const createPreviewActions = memoize(1)(api => ({
toggleFullscreen: () => api.toggleFullscreen(),
}));
const mapper = ({ api, state: { layout, location, selected } }) =>
const mapper = ({ api, state: { layout, location, selected, customQueryParams } }) =>
api.renderPreview
? { renderPreview: api.renderPreview }
: {
Expand All @@ -24,6 +24,7 @@ const mapper = ({ api, state: { layout, location, selected } }) =>
options: layout,
description: selected ? addExtraWhiteSpace(`${selected.kind} - ${selected.name}`) : '',
...api.getUrlState(),
queryParams: customQueryParams,
location,
};

Expand Down