import React , { Fragment } from 'react' ; import { FormattedMessage } from '@kbn/i18n-react' ; import { EuiDescribedFormGroup , EuiFieldText , EuiFormRow , EuiSwitch , EuiTitle } from '@elastic/eui' ; import { GCSRepository , Repository } from '../../../../../common/types' ; import { RepositorySettingsValidation } from '../../../services/validation' ; import { ChunkSizeField , MaxSnapshotsField , MaxRestoreField } from './common' ; interface Props { repository : GCSRepository ; updateRepositorySettings : ( updatedSettings : Partial < Repository [ 'settings' ] > , replaceSettings ? : boolean ) => void ; settingErrors : RepositorySettingsValidation ; } export const GCSSettings = ( { repository , updateRepositorySettings , settingErrors , } ) => { const { settings : { bucket , client , basePath , compress , chunkSize , maxRestoreBytesPerSec , maxSnapshotBytesPerSec , readonly , } , } = repository ; const hasErrors = Boolean ( Object . keys ( settingErrors ) . length ) ; const updateSettings = ( name , value ) => { updateRepositorySettings ( { [ name ] : value , } ) ; } ; return ( < Fragment > { } < EuiDescribedFormGroup title = { < EuiTitle size = "s" > < h3 > < FormattedMessage id = "xpack.snapshotRestore.repositoryForm.typeGCS.clientTitle" defaultMessage = "Client" / > < /h3> < /EuiTitle>} description={<FormattedMessage id="xpack.snapshotRestore.repositoryForm.typeGCS.clientDescription" defaultMessage="The name of the Google Cloud Storage client."/ > } fullWidth > < EuiFormRow label = { < FormattedMessage id = "xpack.snapshotRestore.repositoryForm.typeGCS.clientLabel" defaultMessage = "Client" / > } fullWidth isInvalid = { Boolean ( hasErrors && settingErrors . client ) } error = { settingErrors . client } > < EuiFieldText defaultValue = { client || '' } fullWidth onChange = { ( e ) => { updateRepositorySettings ( { client : e . target . value , } ) ; } } data - test - subj = "clientInput" / > < /EuiFormRow> < /EuiDescribedFormGroup> { } < EuiDescribedFormGroup title = { < EuiTitle size = "s" > < h3 > < FormattedMessage id = "xpack.snapshotRestore.repositoryForm.typeGCS.bucketTitle" defaultMessage = "Bucket" / > < /h3> < /EuiTitle>} description={<FormattedMessage id="xpack.snapshotRestore.repositoryForm.typeGCS.bucketDescription" defaultMessage="The name of the Google Cloud Storage bucket to use for snapshots."/ > } fullWidth > < EuiFormRow label = { < FormattedMessage id = "xpack.snapshotRestore.repositoryForm.typeGCS.bucketLabel" defaultMessage = "Bucket (required)" / > } fullWidth isInvalid = { Boolean ( hasErrors && settingErrors . bucket ) } error = { settingErrors . bucket } > < EuiFieldText defaultValue = { bucket || '' } fullWidth onChange = { ( e ) => { updateRepositorySettings ( { bucket : e . target . value , } ) ; } } data - test - subj = "bucketInput" / > < /EuiFormRow> < /EuiDescribedFormGroup> { } < EuiDescribedFormGroup title = { < EuiTitle size = "s" > < h3 > < FormattedMessage id = "xpack.snapshotRestore.repositoryForm.typeGCS.basePathTitle" defaultMessage = "Base path" / > < /h3> < /EuiTitle>} description={<FormattedMessage id="xpack.snapshotRestore.repositoryForm.typeGCS.basePathDescription" defaultMessage="The bucket path to the repository data."/ > } fullWidth > < EuiFormRow label = { < FormattedMessage id = "xpack.snapshotRestore.repositoryForm.typeGCS.basePathLabel" defaultMessage = "Base path" / > } fullWidth isInvalid = { Boolean ( hasErrors && settingErrors . basePath ) } error = { settingErrors . basePath } > < EuiFieldText defaultValue = { basePath || '' } fullWidth onChange = { ( e ) => { updateRepositorySettings ( { basePath : e . target . value , } ) ; } } data - test - subj = "basePathInput" / > < /EuiFormRow> < /EuiDescribedFormGroup> { } < EuiDescribedFormGroup title = { < EuiTitle size = "s" > < h3 > < FormattedMessage id = "xpack.snapshotRestore.repositoryForm.typeGCS.compressTitle" defaultMessage = "Compress snapshots" / > < /h3> < /EuiTitle>} description={<FormattedMessage id="xpack.snapshotRestore.repositoryForm.typeGCS.compressDescription" defaultMessage="Compresses the index mapping and setting files for snapshots. Data files are not compressed."/ > } fullWidth > < EuiFormRow hasEmptyLabelSpace = { true } fullWidth isInvalid = { Boolean ( hasErrors && settingErrors . compress ) } error = { settingErrors . compress } > < EuiSwitch label = { < FormattedMessage id = "xpack.snapshotRestore.repositoryForm.typeGCS.compressLabel" defaultMessage = "Compress snapshots" / > } checked = { ! ( compress === false ) } onChange = { ( e ) => { updateRepositorySettings ( { compress : e . target . checked , } ) ; } } data - test - subj = "compressToggle" / > < /EuiFormRow> < /EuiDescribedFormGroup> { } < ChunkSizeField isInvalid = { Boolean ( hasErrors && settingErrors . chunkSize ) } error = { settingErrors . chunkSize } defaultValue = { chunkSize || '' } updateSettings = { updateSettings } / > { } < MaxSnapshotsField isInvalid = { Boolean ( hasErrors && settingErrors . maxSnapshotBytesPerSec ) } error = { settingErrors . maxSnapshotBytesPerSec } defaultValue = { maxSnapshotBytesPerSec || '' } updateSettings = { updateSettings } / > { } < MaxRestoreField isInvalid = { Boolean ( hasErrors && settingErrors . maxRestoreBytesPerSec ) } error = { settingErrors . maxRestoreBytesPerSec } defaultValue = { maxRestoreBytesPerSec || '' } updateSettings = { updateSettings } / > { } < EuiDescribedFormGroup title = { < EuiTitle size = "s" > < h3 > < FormattedMessage id = "xpack.snapshotRestore.repositoryForm.typeGCS.readonlyTitle" defaultMessage = "Read-only" / > < /h3> < /EuiTitle>} description={<FormattedMessage id="xpack.snapshotRestore.repositoryForm.typeGCS.readonlyDescription" defaultMessage="Only one cluster should have write access to this repository. All other clusters should be read-only."/ > } fullWidth > < EuiFormRow hasEmptyLabelSpace = { true } fullWidth isInvalid = { Boolean ( hasErrors && settingErrors . readonly ) } error = { settingErrors . readonly } > < EuiSwitch label = { < FormattedMessage id = "xpack.snapshotRestore.repositoryForm.typeGCS.readonlyLabel" defaultMessage = "Read-only repository" / > } checked = { ! ! readonly } onChange = { ( e ) => { updateRepositorySettings ( { readonly : e . target . checked , } ) ; } } data - test - subj = "readOnlyToggle" / > < /EuiFormRow> < /EuiDescribedFormGroup> < /Fragment>); } ;