From 811f022229eedf593a15d866e310859857696de9 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 4 May 2021 12:30:18 -0500 Subject: [PATCH] Add custom S3 items --- src/constants.js | 11 ++- src/containers/AddMount/AddMount.js | 79 ++++++++++++++++--- src/containers/Configuration/Configuration.js | 18 ++--- 3 files changed, 85 insertions(+), 23 deletions(-) diff --git a/src/constants.js b/src/constants.js index 28e36dc..42d16df 100644 --- a/src/constants.js +++ b/src/constants.js @@ -76,9 +76,16 @@ exports.REPERTORY_LOCATIONS = { win32: '%LOCALAPPDATA%\\repertory', }; -exports.S3_PROVIDER_LIST = ['Filebase']; +const _S3_CUSTOM_PROVIDER = 'Custom...'; +exports.S3_CUSTOM_PROVIDER = _S3_CUSTOM_PROVIDER; +exports.S3_PROVIDER_LIST = ['Filebase', _S3_CUSTOM_PROVIDER]; -exports.S3_REGION_PROVIDER_REGION = ['us-east-1']; +const _S3_CUSTOM_REGION = 'Custom...'; +exports.S3_CUSTOM_REGION = _S3_CUSTOM_REGION; +exports.S3_REGION_PROVIDER_REGION = [ + ['us-east-1', _S3_CUSTOM_REGION], + ['any', _S3_CUSTOM_REGION], +]; exports.S3_PROVIDER_URL = { Filebase: 'https://s3.filebase.com', diff --git a/src/containers/AddMount/AddMount.js b/src/containers/AddMount/AddMount.js index 061dd88..d3da298 100644 --- a/src/containers/AddMount/AddMount.js +++ b/src/containers/AddMount/AddMount.js @@ -21,9 +21,11 @@ const default_state = { Name: '', Port: 20000, Provider: Constants.S3_PROVIDER_LIST[0], - Region: Constants.S3_REGION_PROVIDER_REGION[0], + Region: Constants.S3_REGION_PROVIDER_REGION[0][0], SecretKey: '', Token: '', + CustomURL: '', + CustomRegion: '', }; class AddMount extends Component { @@ -55,12 +57,18 @@ class AddMount extends Component { }; addS3Mount = () => { + const isCustomProvider = this.state.Provider === Constants.S3_CUSTOM_PROVIDER; + const isCustomRegion = this.state.Region === Constants.S3_CUSTOM_REGION; if (this.state.Name.length === 0) { this.props.notifyError('Name cannot be empty.'); } else if (this.state.AccessKey.length === 0) { this.props.notifyError('AccessKey cannot be empty.'); } else if (this.state.SecretKey.length === 0) { this.props.notifyError('SecretKey cannot be empty.'); + } else if (isCustomProvider && !this.state.CustomURL.trim()) { + this.props.notifyError('Custom URL cannot be empty.'); + } else if (isCustomRegion && !this.state.CustomRegion.trim()) { + this.props.notifyError('Custom Region cannot be empty.'); } else { const provider = 'S3' + this.state.Name; if (this.props.S3Mounts.includes(provider)) { @@ -75,9 +83,11 @@ class AddMount extends Component { this.state.Name, this.state.AccessKey, this.state.SecretKey, - this.state.Region, + isCustomRegion ? this.state.CustomRegion : this.state.Region, this.state.BucketName, - Constants.S3_PROVIDER_URL[this.state.Provider] + isCustomProvider + ? this.state.CustomURL + : Constants.S3_PROVIDER_URL[this.state.Provider] ); this.setState({ ...default_state, @@ -190,12 +200,37 @@ class AddMount extends Component { />
this.setState({ Provider: e.target.value })} + changed={(e) => + this.setState({ + Provider: e.target.value, + Region: + Constants.S3_REGION_PROVIDER_REGION[ + Constants.S3_PROVIDER_LIST.indexOf(e.target.value) + ][0], + }) + } items={Constants.S3_PROVIDER_LIST} selected={this.state.Provider} />
+ {this.state.Provider === Constants.S3_CUSTOM_PROVIDER ? ( +
+
+ +
+
+ this.setState({ CustomURL: e.target.value })} + className={'ConfigurationItemInput'} + style={{ width: '100%' }} + type={'text'} + value={this.state.CustomURL} + /> +
+
+
+ ) : null}
@@ -210,14 +245,40 @@ class AddMount extends Component { value={this.state.BucketName} />
- this.setState({ Region: e.target.value })} - className={'ConfigurationItemInput'} - type={'text'} - value={this.state.Region} + + this.setState({ + Region: e.target.value, + }) + } + items={ + Constants.S3_REGION_PROVIDER_REGION[ + Constants.S3_PROVIDER_LIST.indexOf(this.state.Provider) + ] + } + selected={this.state.Region} />
+ {this.state.Region === Constants.S3_CUSTOM_REGION ? ( +
+
+
+ +
+
+
+ this.setState({ CustomRegion: e.target.value })} + className={'ConfigurationItemInput'} + style={{ width: '100%' }} + type={'text'} + value={this.state.CustomRegion} + /> +
+
+
+ ) : null}
diff --git a/src/containers/Configuration/Configuration.js b/src/containers/Configuration/Configuration.js index e07f03a..3a81b09 100644 --- a/src/containers/Configuration/Configuration.js +++ b/src/containers/Configuration/Configuration.js @@ -61,23 +61,17 @@ class Configuration extends IPCContainer { }; checkSaveRequired = () => { - const changedItems = []; let i = 0; - for (const item of this.state.ItemList) { - if (this.checkItemChanged(this.state.OriginalItemList[i++], item)) { - changedItems.push(item); - } - } + const changedItems = this.state.ItemList.filter((item) => { + return this.checkItemChanged(this.state.OriginalItemList[i++], item); + }); let changedObjectLookup = null; for (const key of Object.keys(this.state.ObjectLookup)) { - const changedObjectItems = []; let j = 0; - for (const item of this.state.ObjectLookup[key]) { - if (this.checkItemChanged(this.state.OriginalObjectLookup[key][j++], item)) { - changedObjectItems.push(item); - } - } + const changedObjectItems = this.state.ObjectLookup[key].filter((item) => { + return this.checkItemChanged(this.state.OriginalObjectLookup[key][j++], item); + }); if (changedObjectItems.length > 0) { if (changedObjectLookup === null) {