From 4c62d8b2686c02c87279accbdb2424bb8bd1d74e Mon Sep 17 00:00:00 2001 From: justinpark Date: Tue, 16 Jul 2024 11:55:49 -0700 Subject: [PATCH 1/3] fix(sqllab): Show warning message when deprecated db is selected --- .../components/SqlEditor/SqlEditor.test.tsx | 12 +- .../src/SqlLab/components/SqlEditor/index.tsx | 185 ++++++++++-------- superset-frontend/src/SqlLab/fixtures.ts | 2 +- 3 files changed, 116 insertions(+), 83 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx b/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx index 9697d14a959d2..c554c28fbd4fa 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx @@ -160,13 +160,23 @@ describe('SqlEditor', () => { }); it('does not render SqlEditor if no db selected', async () => { - const queryEditor = initialState.sqlLab.queryEditors[1]; + const queryEditor = initialState.sqlLab.queryEditors[2]; const { findByText } = setup({ ...mockedProps, queryEditor }, store); expect( await findByText('Select a database to write a query'), ).toBeInTheDocument(); }); + it('renders db deprecated message', async () => { + const queryEditor = initialState.sqlLab.queryEditors[1]; + const { findByText } = setup({ ...mockedProps, queryEditor }, store); + expect( + await findByText( + 'The selected database is currently deprecated and cannot be used', + ), + ).toBeInTheDocument(); + }); + it('render a SqlEditorLeftBar', async () => { const { getByTestId } = setup(mockedProps, store); await waitFor(() => diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx b/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx index dd22442deffeb..964b5c1a8637b 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx @@ -99,6 +99,7 @@ import { setItem, } from 'src/utils/localStorageHelpers'; import { EmptyStateBig } from 'src/components/EmptyState'; +import Alert from 'src/components/Alert'; import getBootstrapData from 'src/utils/getBootstrapData'; import useLogAction from 'src/logger/useLogAction'; import { @@ -258,31 +259,38 @@ const SqlEditor: FC = ({ const theme = useTheme(); const dispatch = useDispatch(); - const { database, latestQuery, hideLeftBar, currentQueryEditorId } = - useSelector< - SqlLabRootState, - { - database?: DatabaseObject; - latestQuery?: QueryResponse; - hideLeftBar?: boolean; - currentQueryEditorId: QueryEditor['id']; - } - >(({ sqlLab: { unsavedQueryEditor, databases, queries, tabHistory } }) => { - let { dbId, latestQueryId, hideLeftBar } = queryEditor; - if (unsavedQueryEditor?.id === queryEditor.id) { - dbId = unsavedQueryEditor.dbId || dbId; - latestQueryId = unsavedQueryEditor.latestQueryId || latestQueryId; - hideLeftBar = isBoolean(unsavedQueryEditor.hideLeftBar) - ? unsavedQueryEditor.hideLeftBar - : hideLeftBar; - } - return { - database: databases[dbId || ''], - latestQuery: queries[latestQueryId || ''], - hideLeftBar, - currentQueryEditorId: tabHistory.slice(-1)[0], - }; - }, shallowEqual); + const { + database, + latestQuery, + hideLeftBar, + currentQueryEditorId, + hasSqlStatement, + } = useSelector< + SqlLabRootState, + { + database?: DatabaseObject; + latestQuery?: QueryResponse; + hideLeftBar?: boolean; + currentQueryEditorId: QueryEditor['id']; + hasSqlStatement: boolean; + } + >(({ sqlLab: { unsavedQueryEditor, databases, queries, tabHistory } }) => { + let { dbId, latestQueryId, hideLeftBar } = queryEditor; + if (unsavedQueryEditor?.id === queryEditor.id) { + dbId = unsavedQueryEditor.dbId || dbId; + latestQueryId = unsavedQueryEditor.latestQueryId || latestQueryId; + hideLeftBar = isBoolean(unsavedQueryEditor.hideLeftBar) + ? unsavedQueryEditor.hideLeftBar + : hideLeftBar; + } + return { + hasSqlStatement: Boolean(queryEditor.sql?.trim().length > 0), + database: databases[dbId || ''], + latestQuery: queries[latestQueryId || ''], + hideLeftBar, + currentQueryEditorId: tabHistory.slice(-1)[0], + }; + }, shallowEqual); const logAction = useLogAction({ queryEditorId: queryEditor.id }); const isActive = currentQueryEditorId === queryEditor.id; @@ -728,7 +736,7 @@ const SqlEditor: FC = ({ dispatch(addSavedQueryToTabState(queryEditor, savedQuery)); }; - const renderEditorBottomBar = () => { + const renderEditorBottomBar = (hideActions: boolean) => { const { allow_ctas: allowCTAS, allow_cvas: allowCVAS } = database || {}; const showMenu = allowCTAS || allowCVAS; @@ -767,63 +775,78 @@ const SqlEditor: FC = ({ return ( -
- - - - {isFeatureEnabled(FeatureFlag.EstimateQueryCost) && - database?.allows_cost_estimate && ( + {hideActions ? ( + + ) : ( + <> +
- - )} - - - - {latestQuery && ( - - )} -
-
- - - dispatch(updateSavedQuery(query, remoteId)) - } - saveQueryWarning={saveQueryWarning} - database={database} - /> - - - - - - - -
+ {isFeatureEnabled(FeatureFlag.EstimateQueryCost) && + database?.allows_cost_estimate && ( + + + + )} + + + + {latestQuery && ( + + )} +
+
+ + + dispatch(updateSavedQuery(query, remoteId)) + } + saveQueryWarning={saveQueryWarning} + database={database} + /> + + + + + + + +
+ + )}
); }; @@ -866,7 +889,7 @@ const SqlEditor: FC = ({ height={`${aceEditorHeight}px`} hotkeys={hotkeys} /> - {renderEditorBottomBar()} + {renderEditorBottomBar(showEmptyState)} = ({ > - ) : showEmptyState ? ( + ) : showEmptyState && !hasSqlStatement ? ( Date: Tue, 16 Jul 2024 13:15:57 -0700 Subject: [PATCH 2/3] update warning message --- .../src/SqlLab/components/SqlEditor/SqlEditor.test.tsx | 4 ++-- superset-frontend/src/SqlLab/components/SqlEditor/index.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx b/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx index c554c28fbd4fa..a9980549e4d13 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx @@ -167,12 +167,12 @@ describe('SqlEditor', () => { ).toBeInTheDocument(); }); - it('renders db deprecated message', async () => { + it('renders db unavailable message', async () => { const queryEditor = initialState.sqlLab.queryEditors[1]; const { findByText } = setup({ ...mockedProps, queryEditor }, store); expect( await findByText( - 'The selected database is currently deprecated and cannot be used', + 'The database that was used to generate this query could not be reached', ), ).toBeInTheDocument(); }); diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx b/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx index 964b5c1a8637b..93e92d4199a2b 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx @@ -779,10 +779,10 @@ const SqlEditor: FC = ({ From 1a2889dfe9d2353b5785bce0176ae8941d8fb4b5 Mon Sep 17 00:00:00 2001 From: justinpark Date: Tue, 16 Jul 2024 13:17:08 -0700 Subject: [PATCH 3/3] more generic desc --- .../src/SqlLab/components/SqlEditor/SqlEditor.test.tsx | 2 +- superset-frontend/src/SqlLab/components/SqlEditor/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx b/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx index a9980549e4d13..d24c7e9d8bb67 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/SqlEditor.test.tsx @@ -172,7 +172,7 @@ describe('SqlEditor', () => { const { findByText } = setup({ ...mockedProps, queryEditor }, store); expect( await findByText( - 'The database that was used to generate this query could not be reached', + 'The database that was used to generate this query could not be found', ), ).toBeInTheDocument(); }); diff --git a/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx b/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx index 93e92d4199a2b..c17ac9324bdca 100644 --- a/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx +++ b/superset-frontend/src/SqlLab/components/SqlEditor/index.tsx @@ -779,7 +779,7 @@ const SqlEditor: FC = ({