diff --git a/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx b/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx
index 14169342e0771..428ddad3bafd0 100644
--- a/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx
+++ b/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx
@@ -59,12 +59,12 @@ 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();
@@ -72,11 +72,14 @@ describe('EmbedCodeButton', () => {
});
it('returns correct embed code', () => {
+ const stub = sinon
+ .stub(exploreUtils, 'getURIDirectory')
+ .callsFake(() => 'endpoint_url');
const wrapper = mount();
wrapper.setState({
height: '1000',
width: '2000',
- shortUrl: 'http://localhostendpoint_url&height=1000',
+ shortUrlId: 100,
});
const embedHTML =
'';
expect(wrapper.instance().generateEmbedHTML()).toBe(embedHTML);
+ stub.restore();
});
});
diff --git a/superset-frontend/src/explore/components/EmbedCodeButton.jsx b/superset-frontend/src/explore/components/EmbedCodeButton.jsx
index e44e488223377..9513d8ca109b5 100644
--- a/superset-frontend/src/explore/components/EmbedCodeButton.jsx
+++ b/superset-frontend/src/explore/components/EmbedCodeButton.jsx
@@ -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 = {
@@ -36,7 +36,7 @@ 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);
@@ -44,18 +44,14 @@ export default class EmbedCodeButton extends React.Component {
}
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);
}
@@ -69,6 +65,9 @@ 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 (
''
);