-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
fix(sqllab): Allow opening of SQL Lab in new browser tab #25582
Merged
justinpark
merged 4 commits into
apache:master
from
justinpark:fix--forcefully-open-sql-in-new-browser-tab
Oct 13, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 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 |
---|---|---|
|
@@ -20,7 +20,13 @@ | |
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DatasourceType, styled, t, withTheme } from '@superset-ui/core'; | ||
import { | ||
DatasourceType, | ||
SupersetClient, | ||
styled, | ||
t, | ||
withTheme, | ||
} from '@superset-ui/core'; | ||
import { getTemporalColumns } from '@superset-ui/chart-controls'; | ||
import { getUrlParam } from 'src/utils/urlUtils'; | ||
import { AntdDropdown } from 'src/components'; | ||
|
@@ -44,6 +50,7 @@ import ModalTrigger from 'src/components/ModalTrigger'; | |
import ViewQueryModalFooter from 'src/explore/components/controls/ViewQueryModalFooter'; | ||
import ViewQuery from 'src/explore/components/controls/ViewQuery'; | ||
import { SaveDatasetModal } from 'src/SqlLab/components/SaveDatasetModal'; | ||
import { safeStringify } from 'src/utils/safeStringify'; | ||
import { isString } from 'lodash'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
|
@@ -120,6 +127,7 @@ const Styles = styled.div` | |
`; | ||
|
||
const CHANGE_DATASET = 'change_dataset'; | ||
const VIEW_IN_SQL_LAB = 'view_in_sql_lab'; | ||
const EDIT_DATASET = 'edit_dataset'; | ||
const QUERY_PREVIEW = 'query_preview'; | ||
const SAVE_AS_DATASET = 'save_as_dataset'; | ||
|
@@ -155,6 +163,14 @@ export const getDatasourceTitle = datasource => { | |
return datasource?.name || ''; | ||
}; | ||
|
||
const preventRouterLinkWhileMetaClicked = evt => { | ||
if (evt.metaKey) { | ||
evt.preventDefault(); | ||
} else { | ||
evt.stopPropagation(); | ||
} | ||
}; | ||
|
||
class DatasourceControl extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
@@ -231,6 +247,19 @@ class DatasourceControl extends React.PureComponent { | |
this.toggleEditDatasourceModal(); | ||
break; | ||
|
||
case VIEW_IN_SQL_LAB: | ||
{ | ||
const { datasource } = this.props; | ||
const payload = { | ||
datasourceKey: `${datasource.id}__${datasource.type}`, | ||
sql: datasource.sql, | ||
}; | ||
SupersetClient.postForm('/sqllab/', { | ||
form_data: safeStringify(payload), | ||
}); | ||
} | ||
break; | ||
|
||
case SAVE_AS_DATASET: | ||
this.toggleSaveDatasetModal(); | ||
break; | ||
|
@@ -294,12 +323,13 @@ class DatasourceControl extends React.PureComponent { | |
)} | ||
<Menu.Item key={CHANGE_DATASET}>{t('Swap dataset')}</Menu.Item> | ||
{!isMissingDatasource && canAccessSqlLab && ( | ||
<Menu.Item> | ||
<Menu.Item key={VIEW_IN_SQL_LAB}> | ||
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. |
||
<Link | ||
to={{ | ||
pathname: '/sqllab', | ||
state: { requestedQuery }, | ||
}} | ||
onClick={preventRouterLinkWhileMetaClicked} | ||
> | ||
{t('View in SQL Lab')} | ||
</Link> | ||
|
@@ -333,12 +363,13 @@ class DatasourceControl extends React.PureComponent { | |
/> | ||
</Menu.Item> | ||
{canAccessSqlLab && ( | ||
<Menu.Item> | ||
<Menu.Item key={VIEW_IN_SQL_LAB}> | ||
<Link | ||
to={{ | ||
pathname: '/sqllab', | ||
state: { requestedQuery }, | ||
}} | ||
onClick={preventRouterLinkWhileMetaClicked} | ||
> | ||
{t('View in SQL Lab')} | ||
</Link> | ||
|
This file contains 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -14,6 +14,10 @@ | |
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
import contextlib | ||
|
||
import simplejson as json | ||
from flask import request | ||
from flask_appbuilder import permission_name | ||
from flask_appbuilder.api import expose | ||
from flask_appbuilder.security.decorators import has_access | ||
|
@@ -31,12 +35,16 @@ class SqllabView(BaseSupersetView): | |
|
||
method_permission_name = MODEL_API_RW_METHOD_PERMISSION_MAP | ||
|
||
@expose("/") | ||
@expose("/", methods=["GET", "POST"]) | ||
@has_access | ||
@permission_name("read") | ||
@event_logger.log_this | ||
def root(self) -> FlaskResponse: | ||
return self.render_app_template() | ||
payload = {} | ||
if form_data := request.form.get("form_data"): | ||
with contextlib.suppress(json.JSONDecodeError): | ||
payload["requested_query"] = json.loads(form_data) | ||
return self.render_app_template(payload) | ||
Comment on lines
+44
to
+47
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. |
||
|
||
@expose("/history/", methods=("GET",)) | ||
@has_access | ||
|
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.
restored from https://github.com/apache/superset/pull/25151/files#diff-a612babd68b1abfd9dd4ebeff1bec35c7512602e35846c4058aacbac65c6c7beL583-L584