Skip to content

Commit

Permalink
fix: Connect on DB Connection wasn't working (#15201)
Browse files Browse the repository at this point in the history
* fix: add icons (#15122)

* added alerts

* revisions

* added icon

* fixed the connect button
  • Loading branch information
AAfghahi authored Jun 16, 2021
1 parent f452789 commit a03ad40
Showing 1 changed file with 17 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type DBReducerActionType =
| {
type: ActionType.dbSelected;
payload: {
database_name?: string;
engine?: string;
configuration_method: CONFIGURATION_METHOD;
};
Expand Down Expand Up @@ -342,7 +343,6 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const onSave = async () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { id, ...update } = db || {};

if (update?.parameters?.query) {
// convert query params into dictionary
update.parameters.query = JSON.parse(
Expand Down Expand Up @@ -390,15 +390,6 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
credentials_info: JSON.parse(update.encrypted_extra),
});
}
if (update?.parameters?.query) {
// convert query params into dictionary
update.parameters.query = JSON.parse(
`{"${decodeURI((db.parameters?.query as string) || '')
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')}"}`,
);
}

if (update?.extra_json) {
// convert extra_json to back to string
Expand Down Expand Up @@ -452,13 +443,15 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
};

const setDatabaseModel = (engine: string) => {
const isDynamic =
availableDbs?.databases.filter(
(db: DatabaseObject) => db.engine || db.backend === engine,
)[0].parameters !== undefined;
const selectedDbModel = availableDbs?.databases.filter(
(db: DatabaseObject) => db.engine || db.backend === engine,
)[0];
const { name, parameters } = selectedDbModel;
const isDynamic = parameters !== undefined;
setDB({
type: ActionType.dbSelected,
payload: {
database_name: name,
configuration_method: isDynamic
? CONFIGURATION_METHOD.DYNAMIC_FORM
: CONFIGURATION_METHOD.SQLALCHEMY_URI,
Expand Down Expand Up @@ -524,14 +517,16 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const renderModalFooter = () =>
db // if db show back + connect
? [
<StyledFooterButton
key="back"
onClick={() => {
setDB({ type: ActionType.reset });
}}
>
Back
</StyledFooterButton>,
!hasConnectedDb && (
<StyledFooterButton
key="back"
onClick={() => {
setDB({ type: ActionType.reset });
}}
>
Back
</StyledFooterButton>
),
!hasConnectedDb ? ( // if hasConnectedDb show back + finish
<StyledFooterButton
key="submit"
Expand Down

0 comments on commit a03ad40

Please sign in to comment.