You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2020/09/11 12:07:16 UTC
[incubator-superset] 18/34: fix: shorten url with extra request
parameters (#10693)
This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch 0.38
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit da2f9070a058fbdd163a9ca061a9de36c7b319d4
Author: Grace Guo <gr...@airbnb.com>
AuthorDate: Thu Aug 27 09:53:20 2020 -0700
fix: shorten url with extra request parameters (#10693)
---
.../explore/components/EmbedCodeButton_spec.jsx | 12 ++++++++----
.../src/explore/components/EmbedCodeButton.jsx | 19 +++++++++----------
2 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx b/superset-frontend/spec/javascripts/explore/components/EmbedCodeButton_spec.jsx
index 1416934..428ddad 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(<EmbedCodeButton {...defaultProps} />);
wrapper.setState({
height: '1000',
width: '2000',
- shortUrl: 'http://localhostendpoint_url&height=1000',
+ shortUrlId: 100,
});
const embedHTML =
'<iframe\n' +
@@ -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();
});
});
diff --git a/superset-frontend/src/explore/components/EmbedCodeButton.jsx b/superset-frontend/src/explore/components/EmbedCodeButton.jsx
index e44e488..9513d8c 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 (
'<iframe\n' +
` width="${this.state.width}"\n` +
@@ -76,7 +75,7 @@ export default class EmbedCodeButton extends React.Component {
' seamless\n' +
' frameBorder="0"\n' +
' scrolling="no"\n' +
- ` src="${this.state.shortUrl}"\n` +
+ ` src="${srcLink}"\n` +
'>\n' +
'</iframe>'
);