From ec39fc0c3c74d113a7d390256dde96fe1af6fb90 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 17 Feb 2021 12:47:19 -0500 Subject: [PATCH 1/9] split test --- .../views/CRUD/data/database/DatabaseList_spec.jsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseList_spec.jsx b/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseList_spec.jsx index 96639df9bd642..607f65e9335e3 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseList_spec.jsx +++ b/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseList_spec.jsx @@ -109,11 +109,22 @@ describe('DatabaseList', () => { it('fetches Databases', () => { const callsD = fetchMock.calls(/database\/\?q/); - expect(callsD).toHaveLength(1); + expect(callsD).toHaveLength(2); expect(callsD[0][0]).toMatchInlineSnapshot( `"http://localhost/api/v1/database/?q=(order_column:changed_on_delta_humanized,order_direction:desc,page:0,page_size:25)"`, ); }); +}); + +describe('DatabaseList async', () => { + const wrapper = mount( + + + , + ); + beforeAll(async () => { + await waitForComponentToPaint(wrapper); + }); it('deletes', async () => { act(() => { From 19f72e2add8db7ace5f2a79ab81a274f37aa4ac8 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 17 Feb 2021 12:54:31 -0500 Subject: [PATCH 2/9] this test is working --- .../CRUD/data/database/DatabaseList_spec.jsx | 18 ++++++------------ superset-frontend/src/views/App.tsx | 1 + .../views/CRUD/data/database/DatabaseModal.tsx | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseList_spec.jsx b/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseList_spec.jsx index 607f65e9335e3..56455779d06f0 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseList_spec.jsx +++ b/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseList_spec.jsx @@ -57,6 +57,11 @@ const mockdatabases = [...new Array(3)].map((_, i) => ({ id: i, })); +jest.mock('react-redux', () => ({ + ...jest.requireActual('react-redux'), + useSelector: jest.fn(), +})); + const mockUser = { userId: 1, }; @@ -109,22 +114,11 @@ describe('DatabaseList', () => { it('fetches Databases', () => { const callsD = fetchMock.calls(/database\/\?q/); - expect(callsD).toHaveLength(2); + expect(callsD).toHaveLength(1); expect(callsD[0][0]).toMatchInlineSnapshot( `"http://localhost/api/v1/database/?q=(order_column:changed_on_delta_humanized,order_direction:desc,page:0,page_size:25)"`, ); }); -}); - -describe('DatabaseList async', () => { - const wrapper = mount( - - - , - ); - beforeAll(async () => { - await waitForComponentToPaint(wrapper); - }); it('deletes', async () => { act(() => { diff --git a/superset-frontend/src/views/App.tsx b/superset-frontend/src/views/App.tsx index 9e3fcbb3d5b3a..0e8dc243f4d3f 100644 --- a/superset-frontend/src/views/App.tsx +++ b/superset-frontend/src/views/App.tsx @@ -51,6 +51,7 @@ initFeatureFlags(bootstrap.common.feature_flags); const store = createStore( combineReducers({ messageToasts: messageToastReducer, + common: () => common, }), {}, compose(applyMiddleware(thunk), initEnhancer(false)), diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx index 081fb35809c64..f2541dac467d8 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx @@ -17,6 +17,7 @@ * under the License. */ import React, { FunctionComponent, useState, useEffect } from 'react'; +import { useSelector } from 'react-redux'; import { styled, t, SupersetClient } from '@superset-ui/core'; import InfoTooltip from 'src/common/components/InfoTooltip'; import { useSingleViewResource } from 'src/views/CRUD/hooks'; @@ -39,6 +40,16 @@ interface DatabaseModalProps { database?: DatabaseObject | null; // If included, will go into edit mode } +// todo: define common type fully in types file +interface RootState { + common: { + conf: { + SQLALCHEMY_DOCS_URL: string; + }; + }; + messageToast: Array; +} + const DEFAULT_TAB_KEY = '1'; const StyledIcon = styled(Icon)` @@ -132,6 +143,10 @@ const DatabaseModal: FunctionComponent = ({ const [db, setDB] = useState(null); const [isHidden, setIsHidden] = useState(true); const [tabKey, setTabKey] = useState(DEFAULT_TAB_KEY); + const conf = useSelector((state: RootState) => { + console.log(state); + return state.common.conf; + }); const isEditMode = database !== null; const defaultExtra = @@ -402,7 +417,7 @@ const DatabaseModal: FunctionComponent = ({
{t('Refer to the ')} From a9aabf837dff14fde08aa9ae213cc6f900870207 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 17 Feb 2021 13:00:13 -0500 Subject: [PATCH 3/9] working test --- .../src/views/CRUD/data/database/DatabaseModal.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx index f2541dac467d8..98b83ccd290fa 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx @@ -51,6 +51,7 @@ interface RootState { } const DEFAULT_TAB_KEY = '1'; +const DEFAULT_SQLALCHEMY_DOCS_URL = "https://docs.sqlalchemy.org/en/rel_1_2/core/engines.html#" const StyledIcon = styled(Icon)` margin: auto ${({ theme }) => theme.gridUnit * 2}px auto 0; @@ -417,7 +418,7 @@ const DatabaseModal: FunctionComponent = ({
{t('Refer to the ')} From 576ad16a27171bade8be06fd78caac93fe772fc1 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 17 Feb 2021 13:01:40 -0500 Subject: [PATCH 4/9] this --- superset/config.py | 3 +++ superset/views/base.py | 1 + 2 files changed, 4 insertions(+) diff --git a/superset/config.py b/superset/config.py index 79eca21628d31..90512642a2cc7 100644 --- a/superset/config.py +++ b/superset/config.py @@ -1092,6 +1092,9 @@ class CeleryConfig: # pylint: disable=too-few-public-methods # It will get executed each time when user open a chart's explore view. DATASET_HEALTH_CHECK = None +# SQLAlchema link doc reference +SQLALCHEMY_DOCS_URL = "https://docs.sqlalchemy.org/en/rel_1_2/core/engines.html#" + # ------------------------------------------------------------------- # * WARNING: STOP EDITING HERE * # ------------------------------------------------------------------- diff --git a/superset/views/base.py b/superset/views/base.py index 69c9383ffccc1..e71bb2001cfe1 100644 --- a/superset/views/base.py +++ b/superset/views/base.py @@ -80,6 +80,7 @@ "DISPLAY_MAX_ROW", "GLOBAL_ASYNC_QUERIES_TRANSPORT", "GLOBAL_ASYNC_QUERIES_POLLING_DELAY", + "SQLALCHEMY_DOCS_URL", ) logger = logging.getLogger(__name__) From d2f89888d81d9151262826991043f369e8cee3d3 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 17 Feb 2021 13:55:37 -0500 Subject: [PATCH 5/9] fix --- .../src/views/CRUD/data/database/DatabaseModal.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx index 98b83ccd290fa..bf5fb7e00ac11 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx @@ -51,7 +51,8 @@ interface RootState { } const DEFAULT_TAB_KEY = '1'; -const DEFAULT_SQLALCHEMY_DOCS_URL = "https://docs.sqlalchemy.org/en/rel_1_2/core/engines.html#" +const DEFAULT_SQLALCHEMY_DOCS_URL = + 'https://docs.sqlalchemy.org/en/rel_1_2/core/engines.html#'; const StyledIcon = styled(Icon)` margin: auto ${({ theme }) => theme.gridUnit * 2}px auto 0; From c88bcf268c20349ea01263055f0c3beb4a67d744 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 17 Feb 2021 14:35:16 -0500 Subject: [PATCH 6/9] add jest --- .../views/CRUD/data/database/DatabaseModal_spec.jsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseModal_spec.jsx b/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseModal_spec.jsx index fb1e6e0d020c7..901b18a67e361 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseModal_spec.jsx +++ b/superset-frontend/spec/javascripts/views/CRUD/data/database/DatabaseModal_spec.jsx @@ -43,6 +43,11 @@ const dbProps = { }, }; +jest.mock('react-redux', () => ({ + ...jest.requireActual('react-redux'), + useSelector: jest.fn(), +})); + const DATABASE_ENDPOINT = 'glob:*/api/v1/database/*'; fetchMock.get(DATABASE_ENDPOINT, {}); From 97c590a3368d01f0f354c074bc386340718dce1b Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 17 Feb 2021 15:44:17 -0500 Subject: [PATCH 7/9] address comments --- superset/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset/config.py b/superset/config.py index 90512642a2cc7..78e7177c13aa8 100644 --- a/superset/config.py +++ b/superset/config.py @@ -1092,8 +1092,8 @@ class CeleryConfig: # pylint: disable=too-few-public-methods # It will get executed each time when user open a chart's explore view. DATASET_HEALTH_CHECK = None -# SQLAlchema link doc reference -SQLALCHEMY_DOCS_URL = "https://docs.sqlalchemy.org/en/rel_1_2/core/engines.html#" +# SQLalchemy link doc reference +SQLALCHEMY_DOCS_URL = "https://docs.sqlalchemy.org/en/13/core/engines.html" # ------------------------------------------------------------------- # * WARNING: STOP EDITING HERE * From bd45793237ac92f4995df7370d38db8c8bbdd063 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 17 Feb 2021 15:47:06 -0500 Subject: [PATCH 8/9] cleanup somemore --- .../src/views/CRUD/data/database/DatabaseModal.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx index bf5fb7e00ac11..359b06b9303d2 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx @@ -145,10 +145,7 @@ const DatabaseModal: FunctionComponent = ({ const [db, setDB] = useState(null); const [isHidden, setIsHidden] = useState(true); const [tabKey, setTabKey] = useState(DEFAULT_TAB_KEY); - const conf = useSelector((state: RootState) => { - console.log(state); - return state.common.conf; - }); + const conf = useSelector((state: RootState) => state.common.conf); const isEditMode = database !== null; const defaultExtra = From 65456013483ad432b584160b1a3937b9c82c3e13 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Wed, 17 Feb 2021 15:48:33 -0500 Subject: [PATCH 9/9] remove default --- .../src/views/CRUD/data/database/DatabaseModal.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx index 359b06b9303d2..f2467def87533 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal.tsx @@ -51,9 +51,6 @@ interface RootState { } const DEFAULT_TAB_KEY = '1'; -const DEFAULT_SQLALCHEMY_DOCS_URL = - 'https://docs.sqlalchemy.org/en/rel_1_2/core/engines.html#'; - const StyledIcon = styled(Icon)` margin: auto ${({ theme }) => theme.gridUnit * 2}px auto 0; `; @@ -416,7 +413,7 @@ const DatabaseModal: FunctionComponent = ({