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

fix(database-modal): Show a different placeholder text in Snowflake connection form #21172

Merged
merged 2 commits into from
Aug 24, 2022
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 @@ -76,6 +76,7 @@ export const databaseField = ({
changeMethods,
getValidation,
validationErrors,
placeholder,
db,
}: FieldPropTypes) => (
<ValidatedInput
Expand All @@ -85,10 +86,10 @@ export const databaseField = ({
value={db?.parameters?.database}
validationMethods={{ onBlur: getValidation }}
errorMessage={validationErrors?.database}
placeholder={t('e.g. world_population')}
placeholder={placeholder ?? t('e.g. world_population')}
label={t('Database name')}
onChange={changeMethods.onParametersChange}
helpText={t('Copy the name of the database you are trying to connect to.')}
helpText={t('Copy the name of the database you are trying to connect to.')}
/>
);
export const usernameField = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface FieldPropTypes {
required: boolean;
hasTooltip?: boolean;
tooltipText?: (value: any) => string;
placeholder?: string;
onParametersChange: (value: any) => string;
onParametersUploadFileChange: (value: any) => string;
changeMethods: { onParametersChange: (value: any) => string } & {
Expand Down Expand Up @@ -108,6 +109,7 @@ const DatabaseConnectionForm = ({
isEditMode = false,
sslForced,
editNewDb,
getPlaceholder,
}: {
isEditMode?: boolean;
sslForced: boolean;
Expand All @@ -130,6 +132,7 @@ const DatabaseConnectionForm = ({
onRemoveTableCatalog: (idx: number) => void;
validationErrors: JsonObject | null;
getValidation: () => void;
getPlaceholder?: (field: string) => string | undefined;
}) => (
<Form>
<div
Expand Down Expand Up @@ -163,6 +166,7 @@ const DatabaseConnectionForm = ({
isEditMode,
sslForced,
editNewDb,
placeholder: getPlaceholder ? getPlaceholder(field) : undefined,
}),
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
DatabaseForm,
CONFIGURATION_METHOD,
CatalogObject,
Engines,
} from 'src/views/CRUD/data/database/types';
import Loading from 'src/components/Loading';
import ExtraOptions from './ExtraOptions';
Expand Down Expand Up @@ -87,11 +88,6 @@ import {
} from './styles';
import ModalHeader, { DOCUMENTATION_LINK } from './ModalHeader';

enum Engines {
GSheet = 'gsheets',
Snowflake = 'snowflake',
}

const engineSpecificAlertMapping = {
[Engines.GSheet]: {
message: 'Why do I need to create a database?',
Expand Down Expand Up @@ -513,6 +509,18 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
);
};

const getPlaceholder = (field: string) => {
if (field === 'database') {
switch (db?.engine) {
case Engines.Snowflake:
return t('e.g. xy12345.us-east-2.aws');
default:
return t('e.g. world_population');
}
}
return undefined;
};

const removeFile = (removedFile: UploadFile) => {
setFileList(fileList.filter(file => file.uid !== removedFile.uid));
return false;
Expand Down Expand Up @@ -1607,6 +1615,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
}
getValidation={() => getValidation(db)}
validationErrors={validationErrors}
getPlaceholder={getPlaceholder}
/>
<div css={(theme: SupersetTheme) => infoTooltip(theme)}>
{dbModel.engine !== Engines.GSheet && (
Expand Down
5 changes: 5 additions & 0 deletions superset-frontend/src/views/CRUD/data/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,8 @@ export enum CONFIGURATION_METHOD {
SQLALCHEMY_URI = 'sqlalchemy_form',
DYNAMIC_FORM = 'dynamic_form',
}

export enum Engines {
GSheet = 'gsheets',
Snowflake = 'snowflake',
}