eschutho commented on a change in pull request #14829:
URL: https://github.com/apache/superset/pull/14829#discussion_r641647148



##########
File path: 
superset-frontend/src/views/CRUD/data/database/DatabaseModal/DatabaseConnectionForm.tsx
##########
@@ -34,17 +37,103 @@ export const FormFieldOrder = [
   'username',
   'password',
   'database_name',
+  'credentials_info',
 ];
 
 interface FieldPropTypes {
   required: boolean;
   changeMethods: { onParametersChange: (value: any) => string } & {
     onChange: (value: any) => string;
-  };
+  } & { onParametersUploadFileChange: (value: any) => string };
   validationErrors: JsonObject | null;
   getValidation: () => void;
 }
 
+const credentialsInfo = ({
+  required,
+  changeMethods,
+  getValidation,
+  validationErrors,
+}: FieldPropTypes) => {
+  const [uploadOption, setUploadOption] = useState<string>('upload');
+  const [fileToUpload, setFileToUpload] = useState<string>(null);
+  return (
+    <CredentialInfoForm>
+      <>
+        <label className="label-select">
+          How do you want to enter service account credentials?
+        </label>
+        <Select
+          defaultValue={'file'}
+          style={{ width: '100%' }}
+          onChange={option => setUploadOption(option)}
+        >
+          <Select value="file">Upload JSON file</Select>
+          <Select value="paste">Copy and Paste JSON credentials</Select>
+        </Select>
+        {uploadOption === 'paste' ? (
+          <div className="input-container" onChange={changeMethods.onChange}>
+            <label className="label-select">Service Account</label>
+            <textarea className="input-form" name="encrypted_extra" />
+            <label className="label-paste">
+              Copy and paste the entire service account .json file here
+            </label>
+          </div>
+        ) : (
+          <div className="input-container">
+            <label className="label-select">Upload Credentials</label>
+            {!fileToUpload && (
+              <>
+                <Button
+                  className="input-upload-btn"
+                  onClick={() =>
+                    document.getElementById('selectedFile').click()
+                  }
+                >
+                  Choose File
+                </Button>
+              </>
+            )}
+            {fileToUpload && (
+              <div className="input-upload-current">
+                {fileToUpload}
+                <DeleteFilled
+                  onClick={() => {
+                    setFileToUpload(null);
+                    changeMethods.onParametersUploadFileChange({
+                      target: {
+                        name: 'encrypted_extra',
+                        value: '',
+                      },
+                    });
+                  }}
+                />
+              </div>
+            )}
+
+            <input
+              id="selectedFile"
+              className="input-upload"
+              type="file"
+              onChange={async event => {
+                const file = event?.target?.files[0];
+                setFileToUpload(file.name);
+                changeMethods.onParametersUploadFileChange({
+                  target: {
+                    name: 'encrypted_extra',
+                    value: await file.text(),
+                  },
+                });
+                document.getElementById('selectedFile').value = null;

Review comment:
       ref here would be better




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to