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>
This commit is contained in:
Jason Davis 2020-06-26 09:54:55 -07:00 committed by GitHub
parent d8314eeb0d
commit 9de9e1c19d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 8 deletions

View File

@ -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 };

View File

@ -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"

View File

@ -189,6 +189,12 @@ class Database(
and cost_estimate_enabled
)
@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 {
@ -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

View File

@ -136,6 +136,7 @@ class DatabaseRestApi(DatabaseMixin, BaseSupersetModelRestApi):
"allow_csv_upload",
"allows_subquery",
"allows_cost_estimate",
"allows_virtual_table_explore",
"backend",
"function_names",
]

View File

@ -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(

View File

@ -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()

View File

@ -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",