Skip to content

Commit

Permalink
Merge branch 'pexdax/db-connection-ui' into hugh/db-connection-ui-extra
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh authored Jun 15, 2021
2 parents 4fd4629 + ad706d2 commit 128d952
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ function dbReducer(
const trimmedState = {
...(state || {}),
};
let query = '';

let extra_json = {
...JSON.parse(action.payload.extra || ''),
Expand Down Expand Up @@ -220,11 +221,23 @@ function dbReducer(
extra_json.schemas_allowed_for_csv_upload,
),
};

if (action.payload?.parameters?.query) {
// convert query into URI params string
query = new URLSearchParams(
action.payload.parameters.query as string,
).toString();
}

return {
...action.payload,
engine: trimmedState.engine,
configuration_method: trimmedState.configuration_method,
extra_json,
parameters: {
...action.payload.parameters,
query,
},
};
case ActionType.dbSelected:
return {
Expand Down Expand Up @@ -317,6 +330,19 @@ 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(
`{"${decodeURI((update?.parameters?.query as string) || '')
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')}"}`,
);
} else if (update.parameters) {
update.parameters.query = {};
}

if (db?.id) {
if (update?.extra_json) {
// convert extra_json to back to string
Expand Down Expand Up @@ -351,7 +377,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
if (update?.parameters?.query) {
// convert query params into dictionary
update.parameters.query = JSON.parse(
`{"${decodeURI(db.parameters?.query || '')
`{"${decodeURI((db.parameters?.query as string) || '')
.replace(/"/g, '\\"')
.replace(/&/g, '","')
.replace(/=/g, '":"')}"}`,
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/views/CRUD/data/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type DatabaseObject = {
username?: string;
password?: string;
encryption?: boolean;
query?: string;
query?: string | object;
};
configuration_method: CONFIGURATION_METHOD;
engine?: string;
Expand Down

0 comments on commit 128d952

Please sign in to comment.