From b01a48eaaa3c4e721bef11b0757c6fd6e36e962b Mon Sep 17 00:00:00 2001 From: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com> Date: Wed, 22 Jun 2022 13:33:44 -0400 Subject: [PATCH] feat(SQL Lab): Make SQL Lab explore use the default viz from the config file (#20056) * Modified SQL Lab so it uses the default viz to explore a new dataset with * Added a comment to the config file * Remove trailing whitespace * [CLDN-1312] Removed the 'viz_type' variable so that when it is undefinded in the back-end, it gets set to the default viz * [CLDN-1312] Only sets the 'all_columns' variable if the default viz type is a 'table' * Will only pop 'selectedColumns' out of 'form_data' if it is present * [CLDN-1312] Updated files so that the default viz is now being used again in SQL Lab Explore --- .../SqlLab/components/SaveDatasetModal/index.tsx | 7 ++----- superset-frontend/src/SqlLab/types.ts | 1 - superset/config.py | 2 +- superset/views/core.py | 13 +++++++++++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx b/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx index 94b67a6fb309f..9a8366ba56bb2 100644 --- a/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx +++ b/superset-frontend/src/SqlLab/components/SaveDatasetModal/index.tsx @@ -159,9 +159,7 @@ export const SaveDatasetModal: FunctionComponent = ({ exploreChart({ ...EXPLORE_CHART_DEFAULT, datasource: `${datasetToOverwrite.datasetId}__table`, - all_columns: query.results.selected_columns.map( - (d: { name: string; type: string; is_dttm: boolean }) => d.name, - ), + selected_columns: query.results.selected_columns, }); }; @@ -243,8 +241,7 @@ export const SaveDatasetModal: FunctionComponent = ({ metrics: [], groupby: [], time_range: 'No filter', - viz_type: 'table', - all_columns: selectedColumns.map(c => c.name), + selectedColumns, row_limit: 1000, }); }) diff --git a/superset-frontend/src/SqlLab/types.ts b/superset-frontend/src/SqlLab/types.ts index fb3993fe84f6b..bc04277054ea5 100644 --- a/superset-frontend/src/SqlLab/types.ts +++ b/superset-frontend/src/SqlLab/types.ts @@ -91,7 +91,6 @@ export const EXPLORE_CHART_DEFAULT = { metrics: [], groupby: [], time_range: 'No filter', - viz_type: 'table', }; export interface DatasetOwner { diff --git a/superset/config.py b/superset/config.py index 8ab257e511fe6..e718828d1bc0b 100644 --- a/superset/config.py +++ b/superset/config.py @@ -142,7 +142,7 @@ def _try_json_readsha(filepath: str, length: int) -> Optional[str]: # can be replaced at build time to expose build information. BUILD_NUMBER = None -# default viz used in chart explorer +# default viz used in chart explorer & SQL Lab explore DEFAULT_VIZ_TYPE = "table" # default row limit when requesting chart data diff --git a/superset/views/core.py b/superset/views/core.py index 04d3835f60322..6c308b0624c01 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -837,6 +837,19 @@ def explore( if not viz_type and datasource and datasource.default_endpoint: return redirect(datasource.default_endpoint) + selectedColumns = [] + + if "selectedColumns" in form_data: + selectedColumns = form_data.pop("selectedColumns") + + if "viz_type" not in form_data: + form_data["viz_type"] = app.config["DEFAULT_VIZ_TYPE"] + if app.config["DEFAULT_VIZ_TYPE"] == "table": + all_columns = [] + for x in selectedColumns: + all_columns.append(x["name"]) + form_data["all_columns"] = all_columns + # slc perms slice_add_perm = security_manager.can_access("can_write", "Chart") slice_overwrite_perm = is_owner(slc, g.user) if slc else False