-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Add ability to use custom URL in cloud upload dialog #7896
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
Open
marthacryan
wants to merge
14
commits into
v4.0
Choose a base branch
from
custom-server-url
base: v4.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+157
−25
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ea44ed3
Add ability to use custom URL in cloud upload dialog
marthacryan 9b9c0d1
Update docstring and draftlogs
marthacryan 4fb6bf9
update schema
emilykl f051fe2
format draftlog
emilykl b03fb13
add https:// protocol if no protocol specified
emilykl 5ced48c
Reset defaults in plot config
marthacryan 4a66d68
Merge branch 'custom-server-url' of github.com:plotly/plotly.js into …
marthacryan 7c6d279
Remove incorrect CSS from cloud upload dialog
marthacryan 11cc8e1
Update dist plot-schema.json
marthacryan dd0a79a
Update dist plot-schema.json
marthacryan f34bc9c
Update test plot-schema.json
marthacryan 1543deb
Remove newline in test plot-schema.json
marthacryan 28b2af3
Update plotcss
marthacryan 5ad9932
update wording and layout for DE sharing
emilykl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - Add ability to use custom URL for chart upload from the dialog UI [[#7896](https://github.com/plotly/plotly.js/pull/7896)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,15 @@ var _ = require('../../lib')._; | |
| * so it is centered over the plot rather than the whole viewport. It can be | ||
| * dismissed by clicking Cancel, clicking the backdrop, or pressing Escape. | ||
| * | ||
| * By default the chart is uploaded to the configured plotlyServerURL. A | ||
| * "Use a custom server URL" link reveals an editable "Server URL" field | ||
| * pre-filled with that default; whatever the user leaves in the field when they | ||
| * confirm becomes the destination, so a custom URL entered here overrides the | ||
| * plotlyServerURL config for that upload. | ||
| * | ||
| * @param {DOM node} gd - the graph div, used to scope the dialog to the plot | ||
| * @param {string} serverUrl - destination shown in the dialog message | ||
| * @param {function} onConfirm - called when the user confirms the upload | ||
| * @param {string} serverUrl - default destination | ||
| * @param {function} onConfirm - called with the (possibly edited) server URL when confirmed | ||
| */ | ||
| module.exports = function confirmCloudDialog(gd, serverUrl, onConfirm) { | ||
| var container = d3.select(gd._fullLayout._paperdiv.node()); | ||
|
|
@@ -30,11 +36,38 @@ module.exports = function confirmCloudDialog(gd, serverUrl, onConfirm) { | |
|
|
||
| dialog.append('div') | ||
| .classed('plotly-cloud-dialog-title', true) | ||
| .text(_(gd, 'Share with Plotly Cloud')); | ||
| .text(_(gd, 'Share Chart')); | ||
|
|
||
| dialog.append('div') | ||
| .classed('plotly-cloud-dialog-message', true) | ||
| .text(_(gd, 'This chart and its data will be sent to') + ' ' + serverUrl + '.'); | ||
| var serverUrlText = new URL(serverUrl).hostname; | ||
|
|
||
| var description = dialog.append('div'); | ||
| description.classed('plotly-cloud-dialog-message', true); | ||
| description.append('span').text(_(gd, 'This chart and its data will be sent to ')); | ||
| description.append('span').text(serverUrlText).classed('plotly-cloud-dialog-message--hostname', true); | ||
| description.append('span').text('. '); | ||
|
|
||
| // The custom-URL field stays hidden until the user opts in. By default the | ||
| // chart is shared to the configured serverUrl; a button in the button row | ||
| // reveals this input for anyone who wants to override that destination. | ||
| var urlField = dialog.append('div') | ||
| .classed('plotly-cloud-dialog-url-field', true) | ||
| .style('display', 'none'); | ||
|
|
||
| urlField.append('label') | ||
| .classed('plotly-cloud-dialog-label', true) | ||
| .attr('for', 'plotly-cloud-dialog-url') | ||
| .text(_(gd, 'Dash Enterprise URL')); | ||
|
|
||
| var input = urlField.append('input') | ||
| .classed('plotly-cloud-dialog-input', true) | ||
| .attr('id', 'plotly-cloud-dialog-url') | ||
| .attr('type', 'text') | ||
| .attr('spellcheck', false) | ||
| .attr('placeholder', 'https://<your-dash-enterprise-instance>/'); | ||
|
|
||
| var error = dialog.append('div') | ||
| .classed('plotly-cloud-dialog-error', true) | ||
| .style('display', 'none'); | ||
|
|
||
| var buttons = dialog.append('div') | ||
| .classed('plotly-cloud-dialog-buttons', true); | ||
|
|
@@ -54,6 +87,52 @@ module.exports = function confirmCloudDialog(gd, serverUrl, onConfirm) { | |
| if(d3.event.target === overlay.node()) close(); | ||
| }); | ||
|
|
||
| function confirm() { | ||
| var url = (input.property('value') || serverUrl).trim(); | ||
|
|
||
| if(!url) { | ||
| error.text(_(gd, 'Please enter a server URL.')).style('display', ''); | ||
| input.node().focus(); | ||
| return; | ||
| } | ||
|
|
||
| if (!url.startsWith('http://') && !url.startsWith('https://')) { | ||
| url = 'https://' + url; | ||
| } | ||
|
|
||
| try { | ||
| new URL(url); | ||
| } catch(e) { | ||
| error.text(_(gd, 'Please enter a valid server URL.')).style('display', ''); | ||
| input.node().focus(); | ||
| return; | ||
| } | ||
|
|
||
| close(); | ||
| onConfirm(url); | ||
| } | ||
|
|
||
| // Hide the error and allow Enter to confirm from the input. | ||
| input.on('input', function() { | ||
| error.style('display', 'none'); | ||
| }); | ||
| input.on('keydown', function() { | ||
| if(d3.event.key === 'Enter' || d3.event.keyCode === 13) confirm(); | ||
| }); | ||
|
|
||
| var customBtn = buttons.append('button') | ||
| .classed('plotly-cloud-dialog-btn', true) | ||
| .classed('plotly-cloud-dialog-btn--custom', true) | ||
| .attr('type', 'button') | ||
| .text(_(gd, 'Share to Dash Enterprise')); | ||
|
|
||
| customBtn.on('click', function() { | ||
| customBtn.style('display', 'none'); | ||
| urlField.style('display', ''); | ||
| description.text(_(gd, 'If your Dash Enterprise instance supports chart sharing, you can enter its URL below. This chart and its data will be sent to the URL you provide.')); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Enter the url of your Dash Enterprise chart server below or contact Plotly support to get set up. This chart and its data will be sent to the URL you provide." |
||
| input.node().focus(); | ||
| }); | ||
|
|
||
| buttons.append('button') | ||
| .classed('plotly-cloud-dialog-btn', true) | ||
| .classed('plotly-cloud-dialog-btn--cancel', true) | ||
|
|
@@ -64,8 +143,5 @@ module.exports = function confirmCloudDialog(gd, serverUrl, onConfirm) { | |
| .classed('plotly-cloud-dialog-btn', true) | ||
| .classed('plotly-cloud-dialog-btn--confirm', true) | ||
| .text(_(gd, 'Share')) | ||
| .on('click', function() { | ||
| close(); | ||
| onConfirm(); | ||
| }); | ||
| .on('click', confirm); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chart Server URL