Skip to content

Commit 0d5afad

Browse files
authored
Merge pull request #7854 from plotly/add-newchart-query-string
Add origin as query string to requests to plotlyServerURL
2 parents 02073d3 + d5f4789 commit 0d5afad

3 files changed

Lines changed: 9 additions & 4 deletions

File tree

draftlogs/7802_change.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
- Update `sendDataToCloud` modebar button to upload chart to Plotly Cloud [[#7802](https://github.com/plotly/plotly.js/pull/7802), [#7852](https://github.com/plotly/plotly.js/pull/7852)]
1+
- Update `sendDataToCloud` modebar button to upload chart to Plotly Cloud [[#7802](https://github.com/plotly/plotly.js/pull/7802), [#7852](https://github.com/plotly/plotly.js/pull/7852), [#7854](https://github.com/plotly/plotly.js/pull/7854)]
22
- NOTE: The Plotly Cloud endpoint for receiving charts is not yet functional, so this button won't complete the upload.

src/plots/plots.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,11 @@ plots.sendDataToCloud = function(gd, serverURL) {
213213

214214
// Open the Cloud login page in a new tab. We keep a reference so we can post
215215
// the chart back to it once Cloud reports that authentication succeeded.
216-
var cloudWindow = window.open(serverURL, '_blank');
216+
// Pass the current page's origin as a query string so Cloud knows where to
217+
// send the CHART_AUTH_SUCCESS message back to.
218+
var uploadUrl = new URL(serverURL);
219+
uploadUrl.searchParams.set('origin', window.location.origin);
220+
var cloudWindow = window.open(uploadUrl.href, '_blank');
217221
if(!cloudWindow) {
218222
console.error('Unable to open Plotly Cloud (the popup may have been blocked)');
219223
gd.emit('plotly_exportfail');

test/jasmine/tests/config_test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,9 @@ describe('config argument', function() {
585585
expect(confirmBtn).not.toBe(null, 'confirm button should be shown');
586586
mouseEvent('click', 0, 0, {element: confirmBtn});
587587

588-
// Should open the provided URL's origin in a new tab
589-
expect(openSpy).toHaveBeenCalledWith('https://example.plotly.com/endpoint', '_blank');
588+
// Should open the provided URL's origin in a new tab,
589+
// adding the current page's origin as a query parameter
590+
expect(openSpy).toHaveBeenCalledWith('https://example.plotly.com/endpoint?origin=http%3A%2F%2Flocalhost%3A9876', '_blank');
590591
})
591592
.then(done, done.fail);
592593
});

0 commit comments

Comments
 (0)