Skip to content
New issue

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

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

Already on GitHub? # to your account

fix(db-connection-ui): Additional Query Parameters render #15150

Merged
merged 3 commits into from
Jun 14, 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 @@ -130,6 +130,7 @@ function dbReducer(
const trimmedState = {
...(state || {}),
};
let query = '';

switch (action.type) {
case ActionType.inputChange:
Expand Down Expand Up @@ -169,10 +170,20 @@ function dbReducer(
[action.payload.name]: action.payload.value,
};
case ActionType.fetched:
if (action.payload?.parameters?.query) {
// convert query into URI params string
query = new URLSearchParams(
action.payload.parameters.query as string,
).toString();
}
return {
engine: trimmedState.engine,
configuration_method: trimmedState.configuration_method,
...action.payload,
parameters: {
...action.payload.parameters,
query,
},
};
case ActionType.dbSelected:
return {
Expand Down Expand Up @@ -265,6 +276,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) {
const result = await updateResource(
db.id as number,
Expand All @@ -287,7 +311,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