Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(snowflake): Snowflake dynamic form #16861

Merged
merged 2 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ export const FormFieldOrder = [
'catalog',
'query',
'encryption',
'account',
'warehouse',
'role',
];

interface FieldPropTypes {
Expand Down Expand Up @@ -432,6 +435,71 @@ const queryField = ({
/>
);

const warehouseField = ({
required,
changeMethods,
getValidation,
validationErrors,
db,
}: FieldPropTypes) => (
<ValidatedInput
id="warehouse"
name="warehouse"
required={required}
value={db?.parameters?.warehouse}
validationMethods={{ onBlur: getValidation }}
errorMessage={validationErrors?.warehouse}
placeholder="e.g. compute_wh"
label="Warehouse"
onChange={changeMethods.onParametersChange}
className="form-group-w-50"
/>
);

const roleField = ({
required,
changeMethods,
getValidation,
validationErrors,
db,
}: FieldPropTypes) => (
<ValidatedInput
id="role"
name="role"
required={required}
value={db?.parameters?.role}
validationMethods={{ onBlur: getValidation }}
errorMessage={validationErrors?.role}
placeholder="e.g. AccountAdmin"
label="Role"
onChange={changeMethods.onParametersChange}
className="form-group-w-50"
/>
);

const accountField = ({
required,
changeMethods,
getValidation,
validationErrors,
db,
}: FieldPropTypes) => (
<ValidatedInput
id="account"
name="account"
required={required}
value={db?.parameters?.account}
validationMethods={{ onBlur: getValidation }}
errorMessage={validationErrors?.account}
placeholder="e.g. world_population"
label="Account"
onChange={changeMethods.onParametersChange}
helpText={t(
'Copy the account name of that database you are trying to connect to.',
)}
/>
);

const forceSSLField = ({
isEditMode,
changeMethods,
Expand Down Expand Up @@ -473,6 +541,9 @@ const FORM_FIELD_MAP = {
encryption: forceSSLField,
credentials_info: CredentialsInfo,
catalog: TableCatalog,
warehouse: warehouseField,
role: roleField,
account: accountField,
};

const DatabaseConnectionForm = ({
Expand Down
3 changes: 3 additions & 0 deletions superset-frontend/src/views/CRUD/data/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export type DatabaseObject = {
credentials_info?: string;
query?: Record<string, string>;
catalog?: Record<string, string>;
warehouse?: string;
role?: string;
account?: string;
};
configuration_method: CONFIGURATION_METHOD;
engine?: string;
Expand Down
5 changes: 3 additions & 2 deletions superset/db_engine_specs/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.
import json
import re
import urllib
from datetime import datetime
from typing import Any, Dict, List, Optional, Pattern, Tuple, TYPE_CHECKING, TypedDict
from urllib import parse
Expand All @@ -25,7 +26,8 @@
from babel.core import default_locale
from flask_babel import gettext as __
from marshmallow import fields, Schema
from sqlalchemy.engine.url import URL
from marshmallow.exceptions import ValidationError
from sqlalchemy.engine.url import make_url, URL

from superset.db_engine_specs.postgres import PostgresBaseEngineSpec
from superset.errors import SupersetError, SupersetErrorType
Expand Down Expand Up @@ -211,7 +213,6 @@ def get_parameters_from_uri(
cls, uri: str, encrypted_extra: Optional[Dict[str, str]] = None
) -> Any:
value = make_url(uri)

# Building parameters from encrypted_extra and uri
if encrypted_extra:
return {**encrypted_extra, "query": value.query}
Expand Down