You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by bk...@apache.org on 2020/06/26 16:55:18 UTC
[incubator-superset] branch master updated: feat: Added
configuration to SQL Lab results "Explore" button (#10164)
This is an automated email from the ASF dual-hosted git repository.
bkyryliuk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 9de9e1c feat: Added configuration to SQL Lab results "Explore" button (#10164)
9de9e1c is described below
commit 9de9e1c19d8606340efa9849b2176704e4916e9b
Author: Jason Davis <32...@users.noreply.github.com>
AuthorDate: Fri Jun 26 09:54:55 2020 -0700
feat: Added configuration to SQL Lab results "Explore" button (#10164)
* added configuration to virtual table explore button
* added description to mixin
* fixed unit tests
Co-authored-by: Jason Davis <@dropbox.com>
---
.../spec/javascripts/sqllab/ResultSet_spec.jsx | 1 +
.../src/SqlLab/components/ResultSet.jsx | 16 ++++++++-------
superset/models/core.py | 7 +++++++
superset/views/database/api.py | 1 +
superset/views/database/mixins.py | 4 +++-
tests/core_tests.py | 23 ++++++++++++++++++++++
tests/database_api_tests.py | 1 +
7 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx b/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx
index 114755c..e77b1c8 100644
--- a/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx
+++ b/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx
@@ -37,6 +37,7 @@ describe('ResultSet', () => {
cache: true,
query: queries[0],
height: 0,
+ database: { allows_virtual_table_explore: true },
};
const stoppedQueryProps = { ...mockedProps, query: stoppedQuery };
const runningQueryProps = { ...mockedProps, query: runningQuery };
diff --git a/superset-frontend/src/SqlLab/components/ResultSet.jsx b/superset-frontend/src/SqlLab/components/ResultSet.jsx
index 5ccc089..71f3f46 100644
--- a/superset-frontend/src/SqlLab/components/ResultSet.jsx
+++ b/superset-frontend/src/SqlLab/components/ResultSet.jsx
@@ -145,13 +145,15 @@ export default class ResultSet extends React.PureComponent {
return (
<div className="ResultSetControls">
<div className="ResultSetButtons">
- {this.props.visualize && (
- <ExploreResultsButton
- query={this.props.query}
- database={this.props.database}
- actions={this.props.actions}
- />
- )}
+ {this.props.visualize &&
+ this.props.database &&
+ this.props.database.allows_virtual_table_explore && (
+ <ExploreResultsButton
+ query={this.props.query}
+ database={this.props.database}
+ actions={this.props.actions}
+ />
+ )}
{this.props.csv && (
<Button
bsSize="small"
diff --git a/superset/models/core.py b/superset/models/core.py
index 42c4345..25922ac 100755
--- a/superset/models/core.py
+++ b/superset/models/core.py
@@ -190,6 +190,12 @@ class Database(
)
@property
+ def allows_virtual_table_explore(self) -> bool:
+ extra = self.get_extra()
+
+ return bool(extra.get("allows_virtual_table_explore", True))
+
+ @property
def data(self) -> Dict[str, Any]:
return {
"id": self.id,
@@ -198,6 +204,7 @@ class Database(
"allow_multi_schema_metadata_fetch": self.allow_multi_schema_metadata_fetch,
"allows_subquery": self.allows_subquery,
"allows_cost_estimate": self.allows_cost_estimate,
+ "allows_virtual_table_explore": self.allows_virtual_table_explore,
}
@property
diff --git a/superset/views/database/api.py b/superset/views/database/api.py
index aec49f3..212dc8b 100644
--- a/superset/views/database/api.py
+++ b/superset/views/database/api.py
@@ -136,6 +136,7 @@ class DatabaseRestApi(DatabaseMixin, BaseSupersetModelRestApi):
"allow_csv_upload",
"allows_subquery",
"allows_cost_estimate",
+ "allows_virtual_table_explore",
"backend",
"function_names",
]
diff --git a/superset/views/database/mixins.py b/superset/views/database/mixins.py
index 77a2b7d..3fe52e3 100644
--- a/superset/views/database/mixins.py
+++ b/superset/views/database/mixins.py
@@ -144,7 +144,9 @@ class DatabaseMixin:
"If database flavor does not support schema or any schema is allowed "
"to be accessed, just leave the list empty<br/>"
"4. the ``version`` field is a string specifying the this db's version. "
- "This should be used with Presto DBs so that the syntax is correct",
+ "This should be used with Presto DBs so that the syntax is correct<br/>"
+ "5. The ``allows_virtual_table_explore`` field is a boolean specifying "
+ "whether or not the Explore button in SQL Lab results is shown.",
True,
),
"encrypted_extra": utils.markdown(
diff --git a/tests/core_tests.py b/tests/core_tests.py
index 4b4a9bf..bb26a85 100644
--- a/tests/core_tests.py
+++ b/tests/core_tests.py
@@ -1284,6 +1284,29 @@ class CoreTests(SupersetTestCase):
payload = views.Superset._get_sqllab_tabs(user_id=user_id)
self.assertEqual(len(payload["queries"]), 1)
+ def test_virtual_table_explore_visibility(self):
+ # test that default visibility it set to True
+ database = utils.get_example_database()
+ self.assertEqual(database.allows_virtual_table_explore, True)
+
+ # test that visibility is disabled when extra is set to False
+ extra = database.get_extra()
+ extra["allows_virtual_table_explore"] = False
+ database.extra = json.dumps(extra)
+ self.assertEqual(database.allows_virtual_table_explore, False)
+
+ # test that visibility is enabled when extra is set to True
+ extra = database.get_extra()
+ extra["allows_virtual_table_explore"] = True
+ database.extra = json.dumps(extra)
+ self.assertEqual(database.allows_virtual_table_explore, True)
+
+ # test that visibility is not broken with bad values
+ extra = database.get_extra()
+ extra["allows_virtual_table_explore"] = "trash value"
+ database.extra = json.dumps(extra)
+ self.assertEqual(database.allows_virtual_table_explore, True)
+
if __name__ == "__main__":
unittest.main()
diff --git a/tests/database_api_tests.py b/tests/database_api_tests.py
index f636a29..1b9e1ca 100644
--- a/tests/database_api_tests.py
+++ b/tests/database_api_tests.py
@@ -49,6 +49,7 @@ class DatabaseApiTests(SupersetTestCase):
"allow_run_async",
"allows_cost_estimate",
"allows_subquery",
+ "allows_virtual_table_explore",
"backend",
"database_name",
"expose_in_sqllab",