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: Edit for all dynamic forms #15244

Merged
merged 5 commits into from
Jun 18, 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 @@ -94,12 +94,13 @@ const CredentialsInfo = ({ changeMethods, isEditMode, db }: FieldPropTypes) => {
</>
)}
{uploadOption === CredentialInfoOptions.copyPaste || isEditMode ? (
<div className="input-container" onChange={changeMethods.onChange}>
<div className="input-container">
<span className="label-select">Service Account</span>
<textarea
className="input-form"
name="encrypted_extra"
name="credentials_info"
value={db?.parameters?.credentials_info}
onChange={changeMethods.onParametersChange}
/>
<span className="label-paste">
Copy and paste the entire service account .json file here
Expand All @@ -124,7 +125,7 @@ const CredentialsInfo = ({ changeMethods, isEditMode, db }: FieldPropTypes) => {
setFileToUpload(null);
changeMethods.onParametersChange({
target: {
name: 'encrypted_extra',
name: 'credentials_info',
value: '',
},
});
Expand All @@ -146,7 +147,7 @@ const CredentialsInfo = ({ changeMethods, isEditMode, db }: FieldPropTypes) => {
changeMethods.onParametersChange({
target: {
type: null,
name: 'encrypted_extra',
name: 'credentials_info',
value: await file?.text(),
checked: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,6 @@ function dbReducer(
[action.payload.name]: action.payload.value,
};
case ActionType.parametersChange:
if (action.payload.name === 'encrypted_extra') {
return {
...trimmedState,
encrypted_extra: action.payload.value,
parameters: {},
};
}
return {
...trimmedState,
parameters: {
Expand Down Expand Up @@ -242,6 +235,21 @@ function dbReducer(
).toString();
}

if (action.payload.backend === 'bigquery') {
return {
...action.payload,
engine: trimmedState.engine,
configuration_method: action.payload.configuration_method,
extra_json: deserializeExtraJSON,
parameters: {
query,
credentials_info: JSON.stringify(
action.payload?.parameters?.credentials_info || '',
),
},
};
}

return {
...action.payload,
engine: trimmedState.engine,
Expand All @@ -250,9 +258,6 @@ function dbReducer(
parameters: {
...action.payload.parameters,
query,
credentials_info: JSON.stringify(
action.payload?.parameters?.credentials_info || '',
),
},
};
case ActionType.dbSelected:
Expand Down Expand Up @@ -354,6 +359,20 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
.replace(/&/g, '","')
.replace(/=/g, '":"')}"}`,
);
} else if (update?.parameters?.query === '') {
update.parameters.query = {};
}

const engine = update.backend || update.engine;
if (
engine === 'bigquery' &&
update.configuration_method === CONFIGURATION_METHOD.DYNAMIC_FORM &&
update.parameters?.credentials_info
) {
// wrap encrypted_extra in credentials_info only for BigQuery
update.encrypted_extra = JSON.stringify({
credentials_info: JSON.parse(update.parameters?.credentials_info),
});
}

if (db?.id) {
Expand Down Expand Up @@ -385,17 +404,6 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
}
} else if (db) {
// Create
if (
update.engine === 'bigquery' &&
update.configuration_method === CONFIGURATION_METHOD.DYNAMIC_FORM &&
update.encrypted_extra
) {
// wrap encrypted_extra in credentials_info only for BigQuery
update.encrypted_extra = JSON.stringify({
credentials_info: JSON.parse(update.encrypted_extra),
});
}

if (update?.extra_json) {
// convert extra_json to back to string
update.extra = JSON.stringify({
Expand Down Expand Up @@ -602,7 +610,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({

const isDynamic = (engine: string | undefined) =>
availableDbs?.databases.filter(
(DB: DatabaseObject) => DB.engine === engine,
(DB: DatabaseObject) => DB.backend === engine || DB.engine === engine,
)[0].parameters !== undefined;

return useTabLayout ? (
Expand Down