From 05a1bb7793e4c3447a046373ab654217920bd487 Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Wed, 21 Apr 2021 12:18:55 -0700 Subject: [PATCH 1/4] split db modal file --- .../views/CRUD/data/database/DatabaseList.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx index 51808dffed045..d2400458541d0 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx @@ -147,10 +147,13 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) { ); } - function handleDatabaseEdit(database: DatabaseObject) { - // Set database and open modal + function handleDatabaseEditModal({ + database = null, + modalOpen = false, + }: { database?: DatabaseObject | null; modalOpen?: boolean } = {}) { + // Set database and modal setCurrentDatabase(database); - setDatabaseModalOpen(true); + setDatabaseModalOpen(modalOpen); } const canCreate = hasPerm('can_write'); @@ -176,8 +179,7 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) { buttonStyle: 'primary', onClick: () => { // Ensure modal will be opened in add mode - setCurrentDatabase(null); - setDatabaseModalOpen(true); + handleDatabaseEditModal({ modalOpen: true }); }, }, ]; @@ -298,7 +300,8 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) { }, { Cell: ({ row: { original } }: any) => { - const handleEdit = () => handleDatabaseEdit(original); + const handleEdit = () => + handleDatabaseEditModal({ database: original, modalOpen: true }); const handleDelete = () => openDatabaseDeleteModal(original); const handleExport = () => handleDatabaseExport(original); if (!canEdit && !canDelete && !canExport) { @@ -416,7 +419,7 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) { setDatabaseModalOpen(false)} + onHide={handleDatabaseEditModal} onDatabaseAdd={() => { refreshData(); }} From a8afce998d03d968c535c2e43ff2196740a5fb1d Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Wed, 21 Apr 2021 12:18:55 -0700 Subject: [PATCH 2/4] split db modal file --- superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx index d2400458541d0..46522754ddbbf 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx @@ -30,7 +30,7 @@ import Icons from 'src/components/Icons'; import ListView, { FilterOperator, Filters } from 'src/components/ListView'; import { commonMenuData } from 'src/views/CRUD/data/common'; import ImportModelsModal from 'src/components/ImportModal/index'; -import DatabaseModal from './DatabaseModal'; +import DatabaseModal from './databaseModal'; import { DatabaseObject } from './types'; const PAGE_SIZE = 25; From b69bf16a6e21e65872f351fa1231d880a13e49b2 Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Tue, 27 Apr 2021 17:08:49 -0700 Subject: [PATCH 3/4] hook up available databases --- .../views/CRUD/data/database/DatabaseList.tsx | 2 +- .../DatabaseModal/DatabaseConnectionForm.tsx | 158 +++++++++++++ .../database/DatabaseModal/ExtraOptions.tsx | 11 +- .../database/DatabaseModal/SqlAlchemyForm.tsx | 8 +- .../database/DatabaseModal/index.test.jsx | 84 ++++++- .../data/database/DatabaseModal/index.tsx | 207 +++++++++++++++--- .../data/database/DatabaseModal/styles.ts | 140 +++++++++--- .../src/views/CRUD/data/database/types.ts | 48 ++++ superset-frontend/src/views/CRUD/hooks.ts | 18 +- superset/databases/schemas.py | 1 + 10 files changed, 596 insertions(+), 81 deletions(-) create mode 100644 superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx index 46522754ddbbf..d1105e7062229 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseList.tsx @@ -29,8 +29,8 @@ import { Tooltip } from 'src/components/Tooltip'; import Icons from 'src/components/Icons'; import ListView, { FilterOperator, Filters } from 'src/components/ListView'; import { commonMenuData } from 'src/views/CRUD/data/common'; +import DatabaseModal from 'src/views/CRUD/data/database/DatabaseModal'; import ImportModelsModal from 'src/components/ImportModal/index'; -import DatabaseModal from './databaseModal'; import { DatabaseObject } from './types'; const PAGE_SIZE = 25; diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx new file mode 100644 index 0000000000000..c8d98d73e0f83 --- /dev/null +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx @@ -0,0 +1,158 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React, { FormEvent } from 'react'; +import cx from 'classnames'; +import { FormGroup, FormControl } from 'react-bootstrap'; +import FormLabel from 'src/components/Form/FormLabel'; +import { StyledFormHeader, formScrollableStyles } from './styles'; +import { DatabaseForm } from '../types'; + +export const FormFieldOrder = [ + 'host', + 'port', + 'database', + 'username', + 'password', + 'database_name', +]; + +const CHANGE_METHOD = { + onChange: 'onChange', + onPropertiesChange: 'onPropertiesChange', +}; + +const FORM_FIELD_MAP = { + host: { + description: 'Host', + type: 'text', + className: 'w-50', + placeholder: 'e.g. 127.0.0.1', + changeMethod: CHANGE_METHOD.onPropertiesChange, + }, + port: { + description: 'Port', + type: 'text', + className: 'w-50', + placeholder: 'e.g. 5432', + changeMethod: CHANGE_METHOD.onPropertiesChange, + }, + database: { + description: 'Database name', + type: 'text', + label: + 'Copy the name of the PostgreSQL database you are trying to connect to.', + placeholder: 'e.g. world_population', + changeMethod: CHANGE_METHOD.onPropertiesChange, + }, + username: { + description: 'Username', + type: 'text', + placeholder: 'e.g. Analytics', + changeMethod: CHANGE_METHOD.onPropertiesChange, + }, + password: { + description: 'Password', + type: 'text', + placeholder: 'e.g. ********', + changeMethod: CHANGE_METHOD.onPropertiesChange, + }, + database_name: { + description: 'Display Name', + type: 'text', + label: 'Pick a nickname for this database to display as in Superset.', + changeMethod: CHANGE_METHOD.onChange, + }, + query: { + additionalProperties: {}, + description: 'Additional parameters', + type: 'object', + changeMethod: CHANGE_METHOD.onPropertiesChange, + }, +}; + +const DatabaseConnectionForm = ({ + dbModel: { name, parameters }, + onParametersChange, + onChange, +}: { + dbModel: DatabaseForm; + onParametersChange: ( + event: FormEvent | { target: HTMLInputElement }, + ) => void; + onChange: ( + event: FormEvent | { target: HTMLInputElement }, + ) => void; +}) => ( + <> + +

Enter the required {name} credentials

+

+ Need help? Learn more about connecting to {name}. +

+
+
+ {parameters && + FormFieldOrder.filter( + (key: string) => + Object.keys(parameters.properties).includes(key) || + key === 'database_name', + ).map(field => { + const { + className, + description, + type, + placeholder, + label, + changeMethod, + } = FORM_FIELD_MAP[field]; + const onEdit = + changeMethod === CHANGE_METHOD.onChange + ? onChange + : onParametersChange; + return ( + + + {description} + + +

{label}

+
+ ); + })} +
+ +); + +export const FormFieldMap = FORM_FIELD_MAP; + +export default DatabaseConnectionForm; diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/ExtraOptions.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/ExtraOptions.tsx index 8f005f9411ea2..e3987ad7ea7f1 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/ExtraOptions.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/ExtraOptions.tsx @@ -18,7 +18,7 @@ */ import React, { ChangeEvent, EventHandler } from 'react'; import cx from 'classnames'; -import { t } from '@superset-ui/core'; +import { t, SupersetTheme } from '@superset-ui/core'; import InfoTooltip from 'src/components/InfoTooltip'; import IndeterminateCheckbox from 'src/components/IndeterminateCheckbox'; import Collapse from 'src/components/Collapse'; @@ -26,7 +26,8 @@ import { StyledInputContainer, StyledJsonEditor, StyledExpandableForm, -} from 'src/views/CRUD/data/database/DatabaseModal/styles'; + antdCollapseStyles, +} from './styles'; import { DatabaseObject } from '../types'; const defaultExtra = @@ -48,7 +49,11 @@ const ExtraOptions = ({ const createAsOpen = !!(db?.allow_ctas || db?.allow_cvas); return ( - + antdCollapseStyles(theme)} + > diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/SqlAlchemyForm.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/SqlAlchemyForm.tsx index 0bc2e0c816e0b..d4c6278515ff0 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/SqlAlchemyForm.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/SqlAlchemyForm.tsx @@ -45,7 +45,7 @@ const SqlAlchemyTab = ({ type="text" name="database_name" value={db?.database_name || ''} - placeholder={t('Name your dataset')} + placeholder={t('Name your database')} onChange={onInputChange} /> @@ -71,15 +71,15 @@ const SqlAlchemyTab = ({ />
- {t('Refer to the ')} + {t('Refer to the')}{' '} {conf?.SQLALCHEMY_DISPLAY_TEXT ?? ''} - - {t(' for more information on how to structure your URI.')} + {' '} + {t('for more information on how to structure your URI.')}
+ + )} + ); }; diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/styles.ts b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/styles.ts index 38f5de7045cbc..638b06b9d94d8 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/styles.ts +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/styles.ts @@ -17,8 +17,7 @@ * under the License. */ -import { styled } from '@superset-ui/core'; -import Modal from 'src/components/Modal'; +import { styled, css, SupersetTheme } from '@superset-ui/core'; import { JsonEditor } from 'src/components/AsyncAceEditor'; import Tabs from 'src/components/Tabs'; @@ -28,60 +27,126 @@ const EXPOSE_ALL_FORM_HEIGHT = EXPOSE_IN_SQLLAB_FORM_HEIGHT + 102; const anticonHeight = 12; -export const StyledModal = styled(Modal)` - .ant-collapse { - .ant-collapse-header { - padding-top: ${({ theme }) => theme.gridUnit * 3.5}px; - padding-bottom: ${({ theme }) => theme.gridUnit * 2.5}px; +export const StyledFormHeader = styled.header` + border-bottom: ${({ theme }) => `${theme.gridUnit * 0.25}px solid + ${theme.colors.grayscale.light2};`} + padding-left: ${({ theme }) => theme.gridUnit * 4}px; + padding-right: ${({ theme }) => theme.gridUnit * 4}px; + margin-bottom: ${({ theme }) => theme.gridUnit * 4}px; + .helper { + color: ${({ theme }) => theme.colors.grayscale.base}; + font-size: ${({ theme }) => theme.typography.sizes.s - 1}px; + } + h4 { + color: ${({ theme }) => theme.colors.grayscale.dark2}; + font-weight: bold; + font-size: ${({ theme }) => theme.typography.sizes.l}px; + } +`; - .anticon.ant-collapse-arrow { - top: calc(50% - ${anticonHeight / 2}px); - } - .helper { - color: ${({ theme }) => theme.colors.grayscale.base}; - } - } - h4 { - font-size: 16px; - font-weight: bold; - margin-top: 0; - margin-bottom: ${({ theme }) => theme.gridUnit}px; +export const antdCollapseStyles = (theme: SupersetTheme) => css` + .ant-collapse-header { + padding-top: ${theme.gridUnit * 3.5}px; + padding-bottom: ${theme.gridUnit * 2.5}px; + + .anticon.ant-collapse-arrow { + top: calc(50% - ${anticonHeight / 2}px); } - p.helper { - margin-bottom: 0; - padding: 0; + .helper { + color: ${theme.colors.grayscale.base}; } } - .ant-modal-header { - padding: 18px 16px 16px; + h4 { + font-size: 16px; + font-weight: bold; + margin-top: 0; + margin-bottom: ${theme.gridUnit}px; + } + p.helper { + margin-bottom: 0; + padding: 0; + } +`; + +export const antDTabsStyles = css` + .ant-tabs-top > .ant-tabs-nav { + margin-bottom: 0; + } + .ant-tabs-tab { + margin-right: 0; } +`; + +export const antDModalNoPaddingStyles = css` .ant-modal-body { padding-left: 0; padding-right: 0; margin-bottom: 110px; } - .ant-tabs-top > .ant-tabs-nav { - margin-bottom: 0; +`; + +export const formScrollableStyles = (theme: SupersetTheme) => css` + overflow-y: scroll; + padding-left: ${theme.gridUnit * 4}px; + padding-right: ${theme.gridUnit * 4}px; +`; + +export const antDModalStyles = (theme: SupersetTheme) => css` + .ant-modal-header { + padding: ${theme.gridUnit * 4.5}px ${theme.gridUnit * 4}px + ${theme.gridUnit * 4}px; } + .ant-modal-close-x .close { - color: ${({ theme }) => theme.colors.grayscale.dark1}; + color: ${theme.colors.grayscale.dark1}; opacity: 1; } + .ant-modal-title > h4 { + font-weight: bold; + } +`; +export const formHelperStyles = (theme: SupersetTheme) => css` .required { - margin-left: ${({ theme }) => theme.gridUnit / 2}px; - color: ${({ theme }) => theme.colors.error.base}; + margin-left: ${theme.gridUnit / 2}px; + color: ${theme.colors.error.base}; } .helper { display: block; - padding: ${({ theme }) => theme.gridUnit}px 0; - color: ${({ theme }) => theme.colors.grayscale.light1}; - font-size: ${({ theme }) => theme.typography.sizes.s - 1}px; + padding: ${theme.gridUnit}px 0; + color: ${theme.colors.grayscale.light1}; + font-size: ${theme.typography.sizes.s - 1}px; text-align: left; } - .ant-modal-title > h4 { - font-weight: bold; +`; + +export const formStyles = (theme: SupersetTheme) => css` + .form-group { + margin-bottom: ${theme.gridUnit * 4}px; + &-w-50 { + display: inline-block; + width: ${`calc(50% - ${theme.gridUnit * 4}px)`}; + & + .form-group-w-50 { + margin-left: ${theme.gridUnit * 8}px; + } + } + .text-danger { + color: ${theme.colors.error.base}; + font-size: ${theme.typography.sizes.s - 1}px; + strong { + font-weight: normal; + } + } + } + .control-label { + color: ${theme.colors.grayscale.dark1}; + font-size: ${theme.typography.sizes.s - 1}px; + } + .helper { + color: ${theme.colors.grayscale.light1}; + font-size: ${theme.typography.sizes.s - 1}px; + margin-top: ${theme.gridUnit * 1.5}px; } .ant-alert { @@ -219,7 +284,12 @@ export const StyledExpandableForm = styled.div` export const StyledBasicTab = styled(Tabs.TabPane)` padding-left: ${({ theme }) => theme.gridUnit * 4}px; padding-right: ${({ theme }) => theme.gridUnit * 4}px; - margin-top: ${({ theme }) => theme.gridUnit * 4}px; + margin-top: ${({ theme }) => theme.gridUnit * 6}px; +`; + +export const buttonLinkStyles = css` + font-weight: 400; + text-transform: initial; `; export const EditHeader = styled.div` diff --git a/superset-frontend/src/views/CRUD/data/database/types.ts b/superset-frontend/src/views/CRUD/data/database/types.ts index d0e6f5114d43f..920f4b6881cf3 100644 --- a/superset-frontend/src/views/CRUD/data/database/types.ts +++ b/superset-frontend/src/views/CRUD/data/database/types.ts @@ -30,6 +30,8 @@ export type DatabaseObject = { created_by?: null | DatabaseUser; changed_on_delta_humanized?: string; changed_on?: string; + parameters?: { database_name?: string; engine?: string }; + configuration_method: CONFIGURATION_METHOD; // Performance cache_timeout?: string; @@ -52,3 +54,49 @@ export type DatabaseObject = { allow_csv_upload?: boolean; extra?: string; }; + +export type DatabaseForm = { + engine: string; + name: string; + parameters: { + properties: { + database: { + description: string; + type: string; + }; + host: { + description: string; + type: string; + }; + password: { + description: string; + nullable: boolean; + type: string; + }; + port: { + description: string; + format: string; + type: string; + }; + query: { + additionalProperties: {}; + description: string; + type: string; + }; + username: { + description: string; + nullable: boolean; + type: string; + }; + }; + required: string[]; + type: string; + }; + preferred: boolean; + sqlalchemy_uri_placeholder: string; +}; + +export enum CONFIGURATION_METHOD { + SQLALCHEMY_URI = 'sqlalchemy_form', + DYNAMIC_FORM = 'dynamic_form', +} diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts index 9ec1104341cc3..427549997cafc 100644 --- a/superset-frontend/src/views/CRUD/hooks.ts +++ b/superset-frontend/src/views/CRUD/hooks.ts @@ -18,7 +18,7 @@ */ import rison from 'rison'; import { useState, useEffect, useCallback } from 'react'; -import { makeApi, SupersetClient, t } from '@superset-ui/core'; +import { makeApi, SupersetClient, t, JsonObject } from '@superset-ui/core'; import { createErrorHandler } from 'src/views/CRUD/utils'; import { FetchDataConfig } from 'src/components/ListView'; @@ -277,7 +277,7 @@ export function useSingleViewResource( .then( ({ json = {} }) => { updateState({ - resource: json.result, + resource: { id: json.id, ...json.result }, error: null, }); return json.id; @@ -643,3 +643,17 @@ export const testDatabaseConnection = ( }), ); }; + +export function useAvailableDatabases() { + const [availableDbs, setAvailableDbs] = useState(null); + + const getAvailable = useCallback(() => { + SupersetClient.get({ + endpoint: `/api/v1/database/available`, + }).then(({ json }) => { + setAvailableDbs(json); + }); + }, [setAvailableDbs]); + + return [availableDbs, getAvailable] as const; +} diff --git a/superset/databases/schemas.py b/superset/databases/schemas.py index a23659fc0fbf8..924ac9496ed70 100644 --- a/superset/databases/schemas.py +++ b/superset/databases/schemas.py @@ -40,6 +40,7 @@ } database_name_description = "A database name to identify this connection." +port_description = "Port number for the database connection." cache_timeout_description = ( "Duration (in seconds) of the caching timeout for charts of this database. " "A timeout of 0 indicates that the cache never expires. " From 6eae68cb0e54c037eba336afd60fd9048d8fbc8d Mon Sep 17 00:00:00 2001 From: Elizabeth Thompson Date: Mon, 17 May 2021 17:33:27 -0700 Subject: [PATCH 4/4] add comment --- .../DatabaseModal/DatabaseConnectionForm.tsx | 16 ++--- .../database/DatabaseModal/SqlAlchemyForm.tsx | 9 +-- .../data/database/DatabaseModal/index.tsx | 42 ++++++------ .../data/database/DatabaseModal/styles.ts | 64 +++++++++++-------- .../src/views/CRUD/data/database/types.ts | 2 + 5 files changed, 71 insertions(+), 62 deletions(-) diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx index c8d98d73e0f83..f0542e481c121 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx @@ -18,8 +18,9 @@ */ import React, { FormEvent } from 'react'; import cx from 'classnames'; -import { FormGroup, FormControl } from 'react-bootstrap'; -import FormLabel from 'src/components/Form/FormLabel'; +import { InputProps } from 'antd/lib/input'; +import { FormLabel, FormItem } from 'src/components/Form'; +import { Input } from 'src/common/components'; import { StyledFormHeader, formScrollableStyles } from './styles'; import { DatabaseForm } from '../types'; @@ -93,10 +94,10 @@ const DatabaseConnectionForm = ({ }: { dbModel: DatabaseForm; onParametersChange: ( - event: FormEvent | { target: HTMLInputElement }, + event: FormEvent | { target: HTMLInputElement }, ) => void; onChange: ( - event: FormEvent | { target: HTMLInputElement }, + event: FormEvent | { target: HTMLInputElement }, ) => void; }) => ( <> @@ -126,7 +127,7 @@ const DatabaseConnectionForm = ({ ? onChange : onParametersChange; return ( - @@ -136,17 +137,16 @@ const DatabaseConnectionForm = ({ > {description} -

{label}

-
+ ); })} diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/SqlAlchemyForm.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/SqlAlchemyForm.tsx index d4c6278515ff0..cf442b4a57e2b 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/SqlAlchemyForm.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/SqlAlchemyForm.tsx @@ -17,9 +17,9 @@ * under the License. */ import React, { EventHandler, ChangeEvent, MouseEvent } from 'react'; -import { t, supersetTheme } from '@superset-ui/core'; +import { t, SupersetTheme } from '@superset-ui/core'; import Button from 'src/components/Button'; -import { StyledInputContainer } from './styles'; +import { StyledInputContainer, wideButton } from './styles'; import { DatabaseObject } from '../types'; @@ -86,10 +86,7 @@ const SqlAlchemyTab = ({ onClick={testConnection} cta buttonStyle="link" - style={{ - width: '100%', - border: `1px solid ${supersetTheme.colors.primary.base}`, - }} + css={(theme: SupersetTheme) => wideButton(theme)} > {t('Test connection')} diff --git a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx index f47214c371f94..5cecee7880066 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx @@ -45,22 +45,20 @@ import SqlAlchemyForm from './SqlAlchemyForm'; import DatabaseConnectionForm from './DatabaseConnectionForm'; import { - StyledBasicTab, - StyledModal, - EditHeader, - EditHeaderTitle, - EditHeaderSubtitle, + antDAlertStyles, + antDModalNoPaddingStyles, + antDModalStyles, + antDTabsStyles, + buttonLinkStyles, CreateHeader, CreateHeaderSubtitle, CreateHeaderTitle, - Divider, - StyledBasicTab, - antDModalStyles, - antDModalNoPaddingStyles, + EditHeader, + EditHeaderSubtitle, + EditHeaderTitle, formHelperStyles, formStyles, - antDTabsStyles, - buttonLinkStyles, + StyledBasicTab, } from './styles'; const DOCUMENTATION_LINK = @@ -76,14 +74,14 @@ interface DatabaseModalProps { } enum ActionType { - textChange, - inputChange, + configMethodChange, + dbSelected, editorChange, fetched, - reset, - dbSelected, + inputChange, parametersChange, - configMethodChange, + reset, + textChange, } interface DBReducerPayloadType { @@ -312,9 +310,7 @@ const DatabaseModal: FunctionComponent = ({ if (dbFetched) { setDB({ type: ActionType.fetched, - payload: { - ...dbFetched, - }, + payload: dbFetched, }); } }, [dbFetched]); @@ -381,11 +377,12 @@ const DatabaseModal: FunctionComponent = ({ )} - +
{t('Basic')}} key="1"> {useSqlAlchemyForm ? ( @@ -408,12 +405,13 @@ const DatabaseModal: FunctionComponent = ({ )} antDAlertStyles(theme)} message="Additional fields may be required" description={ <> Select databases require additional fields to be completed in - the next step to successfully connect the database. Learn what - requirements your databases has{' '} + the Advanced tab to successfully connect the database. Learn + what requirements your databases has{' '} css` } `; +export const antDAlertStyles = (theme: SupersetTheme) => css` + border: 1px solid ${theme.colors.info.base}; + padding: ${theme.gridUnit * 4}px; + margin: ${theme.gridUnit * 8}px 0 0; + .ant-alert-message { + color: ${theme.colors.info.dark2}; + font-size: ${theme.typography.sizes.s + 1}px; + font-weight: bold; + } + .ant-alert-description { + color: ${theme.colors.info.dark2}; + font-size: ${theme.typography.sizes.s + 1}px; + line-height: ${theme.gridUnit * 4}px; + .ant-alert-icon { + margin-right: ${theme.gridUnit * 2.5}px; + font-size: ${theme.typography.sizes.l + 1}px; + position: relative; + top: ${theme.gridUnit / 4}px; + } + } +`; + export const formHelperStyles = (theme: SupersetTheme) => css` .required { margin-left: ${theme.gridUnit / 2}px; @@ -121,6 +143,17 @@ export const formHelperStyles = (theme: SupersetTheme) => css` } `; +export const wideButton = (theme: SupersetTheme) => css` + width: 100%; + border: 1px solid ${theme.colors.primary.dark2}; + color: ${theme.colors.primary.dark2}; + &:hover, + &:focus { + border: 1px solid ${theme.colors.primary.dark1}; + color: ${theme.colors.primary.dark1}; + } +`; + export const formStyles = (theme: SupersetTheme) => css` .form-group { margin-bottom: ${theme.gridUnit * 4}px; @@ -148,21 +181,6 @@ export const formStyles = (theme: SupersetTheme) => css` font-size: ${theme.typography.sizes.s - 1}px; margin-top: ${theme.gridUnit * 1.5}px; } - - .ant-alert { - color: ${({ theme }) => theme.colors.info.dark2}; - border: 1px solid ${({ theme }) => theme.colors.info.base}; - font-size: ${({ theme }) => theme.gridUnit * 3}px; - padding: ${({ theme }) => theme.gridUnit * 4}px; - margin: ${({ theme }) => theme.gridUnit * 4}px 0 0; - } - .ant-alert-with-description { - .ant-alert-message, - .alert-with-description { - color: ${({ theme }) => theme.colors.info.dark2}; - font-weight: bold; - } - } .ant-modal-body { padding-top: 0; margin-bottom: 0; @@ -307,22 +325,20 @@ export const CreateHeader = styled.div` flex-direction: column; justify-content: center; padding: 0px; - margin: ${({ theme }) => theme.gridUnit * 4}px - ${({ theme }) => theme.gridUnit * 4}px - ${({ theme }) => theme.gridUnit * 9}px; + margin: 0 ${({ theme }) => theme.gridUnit * 4}px + ${({ theme }) => theme.gridUnit * 6}px; `; export const CreateHeaderTitle = styled.div` - color: ${({ theme }) => theme.colors.grayscale.dark1}; + color: ${({ theme }) => theme.colors.grayscale.dark2}; font-weight: bold; - font-size: ${({ theme }) => theme.typography.sizes.l}px; - padding: ${({ theme }) => theme.gridUnit * 1}px; + font-size: ${({ theme }) => theme.typography.sizes.m}px; + padding: ${({ theme }) => theme.gridUnit * 1}px 0; `; export const CreateHeaderSubtitle = styled.div` color: ${({ theme }) => theme.colors.grayscale.dark1}; font-size: ${({ theme }) => theme.typography.sizes.s}px; - padding: ${({ theme }) => theme.gridUnit * 1}px; `; export const EditHeaderTitle = styled.div` @@ -336,7 +352,3 @@ export const EditHeaderSubtitle = styled.div` font-size: ${({ theme }) => theme.typography.sizes.xl}px; font-weight: bold; `; - -export const Divider = styled.hr` - border-top: 1px solid ${({ theme }) => theme.colors.grayscale.light1}; -`; diff --git a/superset-frontend/src/views/CRUD/data/database/types.ts b/superset-frontend/src/views/CRUD/data/database/types.ts index 920f4b6881cf3..2c386b5796a60 100644 --- a/superset-frontend/src/views/CRUD/data/database/types.ts +++ b/superset-frontend/src/views/CRUD/data/database/types.ts @@ -96,6 +96,8 @@ export type DatabaseForm = { sqlalchemy_uri_placeholder: string; }; +// the values should align with the database +// model enum in superset/superset/models/core.py export enum CONFIGURATION_METHOD { SQLALCHEMY_URI = 'sqlalchemy_form', DYNAMIC_FORM = 'dynamic_form',