Skip to content

Commit

Permalink
added payload data
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi committed Jun 4, 2021
1 parent 369b5f2 commit 5fd7884
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,7 @@
* under the License.
*/
import React, { FormEvent } from 'react';
import {
SupersetTheme,
JsonObject,
isFeatureEnabled,
FeatureFlag,
t,
} from '@superset-ui/core';
import { SupersetTheme, JsonObject, t } from '@superset-ui/core';
import { InputProps } from 'antd/lib/input';
import { Switch } from 'src/common/components';
import { Tooltip } from 'src/components/Tooltip';
Expand All @@ -37,7 +31,6 @@ import {
infoTooltip,
} from './styles';
import { DatabaseForm, DatabaseObject } from '../types';
import { useTheme } from '@emotion/react';

export const FormFieldOrder = [
'host',
Expand All @@ -58,6 +51,7 @@ interface FieldPropTypes {
getValidation: () => void;
db?: DatabaseObject;
isEditMode?: boolean;
sslForced?: boolean;
}

const hostField = ({
Expand Down Expand Up @@ -179,22 +173,36 @@ const displayField = ({
helpText="Pick a nickname for this database to display as in Superset."
/>
);
const forceSSLField = ({ changeMethods, isEditMode }: FieldPropTypes) =>
!isEditMode && (
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
<Tooltip title={t('SSL is required for Preset')}>
<Switch
checked={isFeatureEnabled(FeatureFlag.FORCE_DATABASE_CONNECTIONS_SSL)}
onClick={changeMethods.onParametersChange}
/>
<span css={toggleStyle}>SSL</span>
</Tooltip>
<InfoTooltip
tooltip={t('SSL mode "require" will be used')}
placement="bottomRight"
const forceSSLField = ({
isEditMode,
changeMethods,
db,
sslForced,
}: FieldPropTypes) => (
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
<Tooltip title={t('SSL is required for Preset')}>
<Switch
disabled={sslForced && !isEditMode}
checked={db?.parameters?.encryption || sslForced}
onChange={changed => {
changeMethods.onParametersChange({
target: {
type: 'toggle',
name: 'encryption',
checked: true,
value: changed,
},
});
}}
/>
</div>
);
<span css={toggleStyle}>SSL</span>
</Tooltip>
<InfoTooltip
tooltip={t('SSL mode "require" will be used')}
placement="bottomRight"
/>
</div>
);

const FORM_FIELD_MAP = {
host: hostField,
Expand All @@ -214,8 +222,10 @@ const DatabaseConnectionForm = ({
getValidation,
db,
isEditMode = false,
sslForced,
}: {
isEditMode?: boolean;
sslForced: boolean;
dbModel: DatabaseForm;
db: Partial<DatabaseObject> | null;
onParametersChange: (
Expand Down Expand Up @@ -257,6 +267,7 @@ const DatabaseConnectionForm = ({
db,
key: field,
isEditMode,
sslForced,
}),
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -195,8 +200,10 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const [dbName, setDbName] = useState('');
const [isLoading, setLoading] = useState<boolean>(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;
Expand Down Expand Up @@ -406,6 +413,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
) : (
<DatabaseConnectionForm
isEditMode
sslForced={sslForced}
dbModel={dbModel}
db={db as DatabaseObject}
onParametersChange={({ target }: { target: HTMLInputElement }) =>
Expand Down Expand Up @@ -517,6 +525,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
<>
<DatabaseConnectionForm
db={db}
sslForced={sslForced}
dbModel={dbModel}
onParametersChange={({ target }: { target: HTMLInputElement }) =>
onChange(ActionType.parametersChange, {
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/views/CRUD/data/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type DatabaseObject = {
database?: string;
username?: string;
password?: string;
encryption?: boolean;
};
configuration_method: CONFIGURATION_METHOD;
engine?: string;
Expand Down

0 comments on commit 5fd7884

Please sign in to comment.