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 ed45e5f5cf2c3..1eac5de10e057 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx @@ -16,10 +16,11 @@ * specific language governing permissions and limitations * under the License. */ -import React, { FormEvent, useState } from 'react'; -import { SupersetTheme, JsonObject } from '@superset-ui/core'; +import React, { FormEvent, useEvent } from 'react'; +import { SupersetTheme, JsonObject, t } from '@superset-ui/core'; import { InputProps } from 'antd/lib/input'; -import { Select, Button } from 'src/common/components'; +import { Switch, Select, Button } from 'src/common/components'; +import InfoTooltip from 'src/components/InfoTooltip'; import ValidatedInput from 'src/components/Form/LabeledErrorBoundInput'; import { DeleteFilled } from '@ant-design/icons'; import { @@ -27,6 +28,8 @@ import { validatedFormStyles, CredentialInfoForm, StyledFormHeader, + toggleStyle, + infoTooltip, } from './styles'; import { DatabaseForm, DatabaseObject } from '../types'; @@ -42,6 +45,7 @@ export const FormFieldOrder = [ 'username', 'password', 'database_name', + 'encryption', 'credentials_info', ]; @@ -53,6 +57,8 @@ interface FieldPropTypes { validationErrors: JsonObject | null; getValidation: () => void; db?: DatabaseObject; + isEditMode?: boolean; + sslForced?: boolean; } const credentialsInfo = ({ @@ -259,6 +265,34 @@ const displayField = ({ helpText="Pick a nickname for this database to display as in Superset." /> ); +const forceSSLField = ({ + isEditMode, + changeMethods, + db, + sslForced, +}: FieldPropTypes) => ( +
infoTooltip(theme)}> + { + changeMethods.onParametersChange({ + target: { + type: 'toggle', + name: 'encryption', + checked: true, + value: changed, + }, + }); + }} + /> + SSL + +
+); const FORM_FIELD_MAP = { host: hostField, @@ -267,6 +301,7 @@ const FORM_FIELD_MAP = { username: usernameField, password: passwordField, database_name: displayField, + encryption: forceSSLField, credentials_info: credentialsInfo, }; @@ -279,8 +314,10 @@ const DatabaseConnectionForm = ({ getValidation, db, isEditMode = false, + sslForced, }: { isEditMode?: boolean; + sslForced: boolean; dbModel: DatabaseForm; db: Partial | null; onParametersChange: ( @@ -296,13 +333,14 @@ const DatabaseConnectionForm = ({ getValidation: () => void; }) => ( <> - -

Step 2 of 3

-

Enter the required {name} credentials

-

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

-
+ {!isEditMode && ( + +

Enter the required {name} credentials

+

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

+
+ )}
[ @@ -327,6 +365,8 @@ const DatabaseConnectionForm = ({ getValidation, db, key: field, + isEditMode, + sslForced, }), )}
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 39bd5688e667e..a3221f76750a1 100644 --- a/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx +++ b/superset-frontend/src/views/CRUD/data/database/DatabaseModal/index.tsx @@ -16,7 +16,12 @@ * specific language governing permissions and limitations * under the License. */ -import { t, SupersetTheme } from '@superset-ui/core'; +import { + t, + SupersetTheme, + FeatureFlag, + isFeatureEnabled, +} from '@superset-ui/core'; import React, { FunctionComponent, useEffect, @@ -44,7 +49,6 @@ import { } from 'src/views/CRUD/data/database/types'; import ExtraOptions from './ExtraOptions'; import SqlAlchemyForm from './SqlAlchemyForm'; - import DatabaseConnectionForm from './DatabaseConnectionForm'; import { antDAlertStyles, @@ -209,8 +213,10 @@ const DatabaseModal: FunctionComponent = ({ const [dbName, setDbName] = useState(''); const [isLoading, setLoading] = useState(false); const conf = useCommonConf(); - const isEditMode = !!databaseId; + const sslForced = isFeatureEnabled( + FeatureFlag.FORCE_DATABASE_CONNECTIONS_SSL, + ); const useSqlAlchemyForm = db?.configuration_method === CONFIGURATION_METHOD.SQLALCHEMY_URI; const useTabLayout = isEditMode || useSqlAlchemyForm; @@ -309,10 +315,11 @@ const DatabaseModal: FunctionComponent = ({ } }; - const setDatabaseModel = engine => { + const setDatabaseModel = (engine: string) => { const isDynamic = - availableDbs?.databases.filter(db => db.engine === engine)[0] - .parameters !== undefined; + availableDbs?.databases.filter( + (db: DatabaseObject) => db.engine === engine, + )[0].parameters !== undefined; setDB({ type: ActionType.dbSelected, payload: { @@ -329,13 +336,13 @@ const DatabaseModal: FunctionComponent = ({ Or choose from a list of other databases we support{' '} - +