Refactoring

This commit is contained in:
2021-05-05 01:17:01 -05:00
parent bb3dee68ca
commit 5061121424

View File

@@ -246,9 +246,8 @@ class Configuration extends IPCContainer {
Saving: true, Saving: true,
}, },
() => { () => {
const changedItems = []; let changedItems = this.state.ChangedItems.map((item) => {
for (const item of this.state.ChangedItems) { return {
changedItems.push({
Name: item.label, Name: item.label,
Value: Value:
item.type === 'string_array' item.type === 'string_array'
@@ -256,22 +255,24 @@ class Configuration extends IPCContainer {
: item.type === 'host_list' : item.type === 'host_list'
? JSON.stringify(item.value) ? JSON.stringify(item.value)
: item.value, : item.value,
}); };
} });
if (this.state.ChangedObjectLookup) { if (this.state.ChangedObjectLookup) {
for (const key of Object.keys(this.state.ChangedObjectLookup)) { for (const key of Object.keys(this.state.ChangedObjectLookup)) {
for (const item of this.state.ChangedObjectLookup[key]) { changedItems = changedItems.concat(
changedItems.push({ this.state.ChangedObjectLookup[key].map((item) => {
Name: key + '.' + item.label, return {
Value: Name: key + '.' + item.label,
item.type === 'string_array' Value:
? item.value.join(';') item.type === 'string_array'
: item.type === 'host_list' ? item.value.join(';')
? JSON.stringify(item.value) : item.type === 'host_list'
: item.value, ? JSON.stringify(item.value)
}); : item.value,
} };
})
);
} }
} }
@@ -346,39 +347,40 @@ class Configuration extends IPCContainer {
autoFocus = value; autoFocus = value;
}; };
let objectItems = []; const objectItems = Object.keys(this.state.ObjectLookup).map((key) => {
for (const key of Object.keys(this.state.ObjectLookup)) { return (
objectItems.push(
<div key={key}> <div key={key}>
<h2>{key}</h2> <h2>{key}</h2>
<div> <div>
{this.state.ObjectLookup[key].map((k, i) => { {this.state.ObjectLookup[key]
const shouldFocus = getAutoFocus(); .map((k, i) => {
setAutoFocus(false); const shouldFocus = getAutoFocus();
return !k.advanced || setAutoFocus(false);
(this.state.ShowAdvanced && k.advanced && !k.remote) || return !k.advanced ||
this.showRemoteConfigItem(k, this.state.ObjectLookup[key]) ? ( (this.state.ShowAdvanced && k.advanced && !k.remote) ||
<ConfigurationItem this.showRemoteConfigItem(k, this.state.ObjectLookup[key]) ? (
advanced={k.advanced} <ConfigurationItem
autoFocus={shouldFocus} advanced={k.advanced}
changed={(e) => this.handleObjectItemChanged(e, key, i)} autoFocus={shouldFocus}
grouping={key} changed={(e) => this.handleObjectItemChanged(e, key, i)}
items={this.state.Template[key].template[k.label].items} grouping={key}
key={i} items={this.state.Template[key].template[k.label].items}
label={k.label} key={i}
readOnly={ label={k.label}
this.state.IsRemoteMount && readOnly={
(k.label === 'RemoteHostNameOrIp' || k.label === 'RemotePort') this.state.IsRemoteMount &&
} (k.label === 'RemoteHostNameOrIp' || k.label === 'RemotePort')
template={this.state.Template[key].template[k.label]} }
value={k.value} template={this.state.Template[key].template[k.label]}
/> value={k.value}
) : null; />
})} ) : null;
})
.filter((i) => i !== null)}
</div> </div>
</div> </div>
); );
} });
const configurationItems = this.state.ItemList.map((k, i) => { const configurationItems = this.state.ItemList.map((k, i) => {
const shouldFocus = autoFocus; const shouldFocus = autoFocus;
@@ -397,7 +399,7 @@ class Configuration extends IPCContainer {
value={k.value} value={k.value}
/> />
) : null; ) : null;
}); }).filter((i) => i !== null);
return ( return (
<div className={'Configuration'}> <div className={'Configuration'}>