Skip to content

Commit

Permalink
fix: shorten url with extra request parameters (apache#10693)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grace Guo authored and Ofeknielsen committed Oct 5, 2020
1 parent 1d8daf9 commit 0f8b957
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,27 @@ describe('EmbedCodeButton', () => {
wrapper.setState({
height: '1000',
width: '2000',
shortUrl: 'http://localhostendpoint_url&height=1000',
shortUrlId: 100,
});

const trigger = wrapper.find(OverlayTrigger);
trigger.simulate('click');
expect(spy1.args[0][1]).toBe('standalone');
expect(spy1.callCount).toBe(1);
expect(spy2.callCount).toBe(1);

spy1.restore();
spy2.restore();
});

it('returns correct embed code', () => {
const stub = sinon
.stub(exploreUtils, 'getURIDirectory')
.callsFake(() => 'endpoint_url');
const wrapper = mount(<EmbedCodeButton {...defaultProps} />);
wrapper.setState({
height: '1000',
width: '2000',
shortUrl: 'http://localhostendpoint_url&height=1000',
shortUrlId: 100,
});
const embedHTML =
'<iframe\n' +
Expand All @@ -85,9 +88,10 @@ describe('EmbedCodeButton', () => {
' seamless\n' +
' frameBorder="0"\n' +
' scrolling="no"\n' +
' src="http://localhostendpoint_url&height=1000"\n' +
' src="http://localhostendpoint_url?r=100&standalone=true&height=1000"\n' +
'>\n' +
'</iframe>';
expect(wrapper.instance().generateEmbedHTML()).toBe(embedHTML);
stub.restore();
});
});
19 changes: 9 additions & 10 deletions superset-frontend/src/explore/components/EmbedCodeButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { t } from '@superset-ui/translation';

import FormLabel from 'src/components/FormLabel';
import CopyToClipboard from 'src/components/CopyToClipboard';
import { getExploreLongUrl } from '../exploreUtils';
import { getExploreLongUrl, getURIDirectory } from '../exploreUtils';
import { getShortUrl } from '../../utils/common';

const propTypes = {
Expand All @@ -36,26 +36,22 @@ export default class EmbedCodeButton extends React.Component {
this.state = {
height: '400',
width: '600',
shortUrl: '',
shortUrlId: 0,
};
this.handleInputChange = this.handleInputChange.bind(this);
this.getCopyUrl = this.getCopyUrl.bind(this);
this.onShortUrlSuccess = this.onShortUrlSuccess.bind(this);
}

onShortUrlSuccess(shortUrl) {
const shortUrlId = shortUrl.substring(shortUrl.indexOf('/r/') + 3);
this.setState(() => ({
shortUrl,
shortUrlId,
}));
}

getCopyUrl() {
const srcLink = `${
window.location.origin +
getExploreLongUrl(this.props.latestQueryFormData, 'standalone')
}&height=${this.state.height}`;

return getShortUrl(srcLink)
return getShortUrl(getExploreLongUrl(this.props.latestQueryFormData))
.then(this.onShortUrlSuccess)
.catch(this.props.addDangerToast);
}
Expand All @@ -69,14 +65,17 @@ export default class EmbedCodeButton extends React.Component {
}

generateEmbedHTML() {
const srcLink = `${window.location.origin + getURIDirectory()}?r=${
this.state.shortUrlId
}&standalone=true&height=${this.state.height}`;
return (
'<iframe\n' +
` width="${this.state.width}"\n` +
` height="${this.state.height}"\n` +
' seamless\n' +
' frameBorder="0"\n' +
' scrolling="no"\n' +
` src="${this.state.shortUrl}"\n` +
` src="${srcLink}"\n` +
'>\n' +
'</iframe>'
);
Expand Down

0 comments on commit 0f8b957

Please sign in to comment.