diff --git a/cvat-core/src/cloud-storage.js b/cvat-core/src/cloud-storage.js index c27d7729328..b4799962cc7 100644 --- a/cvat-core/src/cloud-storage.js +++ b/cvat-core/src/cloud-storage.js @@ -34,7 +34,6 @@ key: undefined, secret_key: undefined, session_token: undefined, - key_file_path: undefined, key_file: undefined, specific_attributes: undefined, owner: undefined, @@ -155,21 +154,6 @@ data.session_token = value; }, }, - /** - * Key file path - * @name keyFilePath - * @type {string} - * @memberof module:API.cvat.classes.CloudStorage - * @instance - * @throws {module:API.cvat.exceptions.ArgumentError} - */ - keyFilePath: { - get: () => data.key_file_path, - set: (value) => { - validateNotEmptyString(value); - data.key_file_path = value; - }, - }, /** * Key file * @name keyFile @@ -433,10 +417,6 @@ data.session_token = cloudStorageInstance.token; } - if (cloudStorageInstance.keyFilePath) { - data.key_file_path = cloudStorageInstance.keyFilePath; - } - if (cloudStorageInstance.keyFile) { data.key_file = cloudStorageInstance.keyFile; } diff --git a/cvat-ui/src/components/create-cloud-storage-page/cloud-storage-form.tsx b/cvat-ui/src/components/create-cloud-storage-page/cloud-storage-form.tsx index 62f45e52731..eb06ca76072 100644 --- a/cvat-ui/src/components/create-cloud-storage-page/cloud-storage-form.tsx +++ b/cvat-ui/src/components/create-cloud-storage-page/cloud-storage-form.tsx @@ -19,7 +19,7 @@ import Tooltip from 'antd/lib/tooltip'; import { CombinedState, CloudStorage } from 'reducers/interfaces'; import { createCloudStorageAsync, updateCloudStorageAsync } from 'actions/cloud-storage-actions'; import { ProviderType, CredentialsType } from 'utils/enums'; -import { DeleteOutlined, UploadOutlined } from '@ant-design/icons'; +import { QuestionCircleOutlined, UploadOutlined } from '@ant-design/icons'; import Upload, { RcFile } from 'antd/lib/upload'; import { Space } from 'antd'; import { AzureProvider, S3Provider, GoogleCloudProvider } from '../../icons'; @@ -31,8 +31,8 @@ export interface Props { cloudStorage?: CloudStorage; } -type CredentialsFormNames = 'key' | 'secret_key' | 'account_name' | 'session_token' | 'key_file_path'; -type CredentialsCamelCaseNames = 'key' | 'secretKey' | 'accountName' | 'sessionToken' | 'keyFilePath'; +type CredentialsFormNames = 'key' | 'secret_key' | 'account_name' | 'session_token'; +type CredentialsCamelCaseNames = 'key' | 'secretKey' | 'accountName' | 'sessionToken'; interface CloudStorageForm { credentials_type: CredentialsType; @@ -44,7 +44,6 @@ interface CloudStorageForm { key?: string; secret_key?: string; SAS_token?: string; - key_file_path?: string; key_file?: File; description?: string; region?: string; @@ -53,6 +52,8 @@ interface CloudStorageForm { manifests: string[]; } +const { Dragger } = Upload; + export default function CreateCloudStorageForm(props: Props): JSX.Element { const { cloudStorage } = props; const cloudStorageId = cloudStorage ? cloudStorage.id : null; @@ -76,21 +77,18 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element { sessionToken: 'X'.repeat(300), key: 'X'.repeat(20), secretKey: 'X'.repeat(40), - keyFilePath: 'X'.repeat(10), + keyFile: new File([], 'fakeKey.json'), }; const [keyVisibility, setKeyVisibility] = useState(false); const [secretKeyVisibility, setSecretKeyVisibility] = useState(false); const [sessionTokenVisibility, setSessionTokenVisibility] = useState(false); const [accountNameVisibility, setAccountNameVisibility] = useState(false); - const [keyFilePathVisibility, setKeyFilePathVisibility] = useState(false); const [manifestNames, setManifestNames] = useState([]); - const [keyFilePathIsDisabled, setKeyFilePathIsDisabled] = useState(false); - const [keyFileIsDisabled, setKeyFileIsDisabled] = useState(false); - const [uploadedKeyFile, setUploadedKeyFile] = useState(null); + const [isFakeKeyFileAttached, setIsFakeKeyFileAttached] = useState(!!cloudStorage); function initializeFields(): void { setManifestNames(cloudStorage.manifests); @@ -113,7 +111,7 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element { fieldsValue.key = fakeCredentialsData.key; fieldsValue.secret_key = fakeCredentialsData.secretKey; } else if (cloudStorage.credentialsType === CredentialsType.KEY_FILE_PATH) { - fieldsValue.key_file_path = fakeCredentialsData.keyFilePath; + setUploadedKeyFile(fakeCredentialsData.keyFile); } if (cloudStorage.specificAttributes) { @@ -142,6 +140,7 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element { } else { setManifestNames([]); setSelectedRegion(undefined); + setUploadedKeyFile(null); form.resetFields(); } } @@ -228,7 +227,7 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element { cloudStorageData.specific_attributes = specificAttributes.toString(); - if (uploadedKeyFile) { + if (uploadedKeyFile && !isFakeKeyFileAttached) { cloudStorageData.key_file = uploadedKeyFile; } @@ -259,9 +258,6 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element { if (cloudStorageData.session_token === fakeCredentialsData.sessionToken) { delete cloudStorageData.session_token; } - if (cloudStorageData.key_file_path === fakeCredentialsData.keyFilePath) { - delete cloudStorageData.key_file_path; - } dispatch(updateCloudStorageAsync(cloudStorageData)); } else { dispatch(createCloudStorageAsync(cloudStorageData)); @@ -274,8 +270,8 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element { secret_key: undefined, session_token: undefined, account_name: undefined, - key_file_path: undefined, }); + setUploadedKeyFile(null); }; const onFocusCredentialsItem = (credential: CredentialsCamelCaseNames, key: CredentialsFormNames): void => { @@ -419,64 +415,46 @@ export default function CreateCloudStorageForm(props: Props): JSX.Element { if (providerType === ProviderType.GOOGLE_CLOUD_STORAGE && credentialsType === CredentialsType.KEY_FILE_PATH) { return ( Key file + )} > - { + setIsFakeKeyFileAttached(false); + setUploadedKeyFile(file); + return false; + }} + onRemove={() => setUploadedKeyFile(null)} > - { - setKeyFilePathVisibility(true); - const isDisabled = !!(e.target.value); - setKeyFileIsDisabled(isDisabled); - }} - onFocus={() => onFocusCredentialsItem('keyFilePath', 'key_file_path')} - onBlur={() => onBlurCredentialsItem('keyFilePath', 'key_file_path', setKeyFilePathVisibility)} - disabled={keyFilePathIsDisabled} - /> - - - - { - if (form.getFieldValue('key_file_path')) { - form.setFieldsValue({ - key_file_path: undefined, - }); - } - setKeyFilePathIsDisabled(true); - setUploadedKeyFile(file); - return false; - }} - > -