Skip to content

Commit

Permalink
fix(database-modal): Show a different placeholder text in Snowflake c…
Browse files Browse the repository at this point in the history
…onnection form (#21172)

* Add new Database Modal

When adding a new database and selecting Snowflake, the database and account fields had the same placeholder. This PR adds a placeholder prop so values can be sent dynamically by field

* Call translation function for string literals

Co-authored-by: Herbert Gainor <herbert.gainor@preset.io>
  • Loading branch information
agl-developer and Herbert Gainor authored Aug 24, 2022
1 parent d568999 commit da3401a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
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 @@ -59,6 +59,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 @@ -519,6 +515,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 @@ -1617,6 +1625,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',
}

0 comments on commit da3401a

Please sign in to comment.