Skip to content

Commit 44b23ad

Browse files
authored
Merge pull request #401 from smiclea/update-storage-default
Update storage mapping default behaviour
2 parents e2ac43f + 05f53fc commit 44b23ad

10 files changed

Lines changed: 35 additions & 31 deletions

File tree

src/components/organisms/EditReplica/EditReplica.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,11 @@ class EditReplica extends React.Component<Props, State> {
259259
source: this.state.sourceData,
260260
destination: this.state.destinationData,
261261
network: this.state.selectedNetworks.length > 0 ? this.getSelectedNetworks() : [],
262-
storage: this.state.destinationData.default_storage || this.state.storageMap.length > 0 ? this.getStorageMap() : [],
262+
storage: this.state.storageMap,
263263
}
264264
if (this.props.type === 'replica') {
265-
replicaStore.update(this.props.replica, this.props.destinationEndpoint, updateData).then(() => {
265+
let storageConfigDefault = this.getFieldValue('destination', 'default_storage') || endpointStore.storageConfigDefault
266+
replicaStore.update(this.props.replica, this.props.destinationEndpoint, updateData, storageConfigDefault).then(() => {
266267
this.props.onRequestClose()
267268
this.props.onUpdateComplete(`/replica/executions/${this.props.replica.id}`)
268269
}).catch(() => {
@@ -360,7 +361,7 @@ class EditReplica extends React.Component<Props, State> {
360361
this.state.storageMap.forEach(mapping => {
361362
let fieldName = mapping.type === 'backend' ? 'storage_backend_identifier' : 'id'
362363
let existingMapping = storageMap.find(m => m.type === mapping.type &&
363-
m.source[fieldName] === mapping.source[fieldName]
364+
m.source[fieldName] === String(mapping.source[fieldName])
364365
)
365366
if (existingMapping) {
366367
existingMapping.target = mapping.target
@@ -388,6 +389,7 @@ class EditReplica extends React.Component<Props, State> {
388389
fields={fields}
389390
hasStorageMap={type === 'source' ? false : this.hasStorageMap()}
390391
storageBackends={endpointStore.storageBackends}
392+
storageConfigDefault={endpointStore.storageConfigDefault}
391393
onChange={(f, v) => { this.handleFieldChange(type, f, v) }}
392394
oneColumnStyle={{ marginTop: '-16px', display: 'flex', flexDirection: 'column', width: '100%', alignItems: 'center' }}
393395
columnStyle={{ marginRight: 0 }}
@@ -412,7 +414,6 @@ class EditReplica extends React.Component<Props, State> {
412414
storageBackends={endpointStore.storageBackends}
413415
instancesDetails={this.props.instancesDetails}
414416
storageMap={this.getStorageMap()}
415-
defaultStorage={this.getFieldValue('destination', 'default_storage')}
416417
onChange={(s, t, type) => { this.handleStorageChange(s, t, type) }}
417418
/>
418419
)

src/components/organisms/WizardOptions/WizardOptions.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type Props = {
8181
useAdvancedOptions?: boolean,
8282
hasStorageMap: boolean,
8383
storageBackends?: StorageBackend[],
84+
storageConfigDefault?: string,
8485
onAdvancedOptionsToggle?: (showAdvanced: boolean) => void,
8586
wizardType: string,
8687
loading?: boolean,
@@ -145,7 +146,12 @@ class WizardOptions extends React.Component<Props> {
145146
}
146147

147148
if (this.props.hasStorageMap && this.props.useAdvancedOptions && this.props.storageBackends && this.props.storageBackends.length > 0) {
148-
fieldsSchema.push({ name: 'default_storage', type: 'string', enum: this.props.storageBackends.map(s => s.name) })
149+
fieldsSchema.push({
150+
name: 'default_storage',
151+
type: 'string',
152+
enum: this.props.storageBackends.map(s => s.name),
153+
default: this.props.storageConfigDefault,
154+
})
149155
}
150156

151157
return fieldsSchema

src/components/organisms/WizardPageContent/WizardPageContent.jsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ class WizardPageContent extends React.Component<Props, State> {
355355
useAdvancedOptions={this.state.useAdvancedOptions}
356356
hasStorageMap={this.props.hasStorageMap}
357357
storageBackends={this.props.endpointStore.storageBackends}
358+
storageConfigDefault={this.props.endpointStore.storageConfigDefault}
358359
wizardType={this.props.type}
359360
onAdvancedOptionsToggle={useAdvancedOptions => { this.handleAdvancedOptionsToggle(useAdvancedOptions) }}
360361
/>
@@ -378,7 +379,6 @@ class WizardPageContent extends React.Component<Props, State> {
378379
storageBackends={this.props.endpointStore.storageBackends}
379380
instancesDetails={this.props.instanceStore.instancesDetails}
380381
storageMap={this.props.storageMap}
381-
defaultStorage={String(this.props.wizardData.destOptions ? this.props.wizardData.destOptions.default_storage : '')}
382382
onChange={this.props.onStorageChange}
383383
/>
384384
)
@@ -404,13 +404,6 @@ class WizardPageContent extends React.Component<Props, State> {
404404
storageMap={this.props.storageMap}
405405
wizardType={this.props.type}
406406
instancesDetails={this.props.instanceStore.instancesDetails}
407-
defaultStorage={
408-
this.props.endpointStore.storageBackends.find(
409-
s => this.props.wizardData.destOptions ?
410-
s.name === this.props.wizardData.destOptions.default_storage :
411-
false
412-
)
413-
}
414407
/>
415408
)
416409
break

src/components/organisms/WizardStorage/WizardStorage.jsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ export type Props = {
143143
storageBackends: StorageBackend[],
144144
instancesDetails: Instance[],
145145
storageMap: ?StorageMap[],
146-
defaultStorage: ?string,
147146
onChange: (sourceStorage: Disk, targetStorage: StorageBackend, type: 'backend' | 'disk') => void,
148147
}
149148
@observer
@@ -184,8 +183,8 @@ class WizardStorage extends React.Component<Props> {
184183
}
185184
return false
186185
}).map(i => i.instance_name)
187-
let selectedItem = storageMap && storageMap.find(s => s.type === type && s.source[diskFieldName] === disk[diskFieldName])
188-
selectedItem = selectedItem ? selectedItem.target : storageItems.find(i => i.name === this.props.defaultStorage)
186+
let selectedItem = storageMap && storageMap.find(s => s.type === type && String(s.source[diskFieldName]) === String(disk[diskFieldName]))
187+
selectedItem = selectedItem ? selectedItem.target : null
189188
return (
190189
<StorageItem key={disk[diskFieldName]}>
191190
<StorageImage backend={type === 'backend'} />

src/components/organisms/WizardSummary/WizardSummary.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ type Props = {
144144
schedules: Schedule[],
145145
storageMap: StorageMap[],
146146
instancesDetails: Instance[],
147-
defaultStorage: ?StorageBackend,
148147
}
149148
@observer
150149
class WizardSummary extends React.Component<Props> {
@@ -297,7 +296,6 @@ class WizardSummary extends React.Component<Props> {
297296
if (
298297
optionName === 'execute_now' ||
299298
optionName === 'separate_vm' ||
300-
optionName === 'default_storage' ||
301299
!data.destOptions || data.destOptions[optionName] == null
302300
) {
303301
return null
@@ -323,7 +321,7 @@ class WizardSummary extends React.Component<Props> {
323321
let storageMap = this.props.storageMap.filter(mapping => mapping.type === type)
324322
let disks = getDisks(this.props.instancesDetails, type)
325323

326-
if (disks.length === 0 || (storageMap.length === 0 && !this.props.defaultStorage)) {
324+
if (disks.length === 0 || storageMap.length === 0) {
327325
return null
328326
}
329327
let fieldName = type === 'backend' ? 'storage_backend_identifier' : 'id'
@@ -333,12 +331,17 @@ class WizardSummary extends React.Component<Props> {
333331
if (diskMapped) {
334332
return { source: diskMapped.source, target: diskMapped.target }
335333
}
336-
return { source: disk, target: this.props.defaultStorage }
334+
return { source: disk, target: null }
337335
})
338336

339337
fullStorageMap.sort((m1, m2) => String(m1.source[fieldName]).localeCompare(String(m2.source[fieldName])))
338+
fullStorageMap = fullStorageMap.filter(fsm => fsm.target && fsm.target.id)
340339
let title = type === 'backend' ? 'Storage Backend Mapping' : 'Disk Mapping'
341340

341+
if (fullStorageMap.length === 0) {
342+
return null
343+
}
344+
342345
return (
343346
<Section>
344347
<SectionTitle>{title}</SectionTitle>

src/plugins/endpoint/default/OptionsSchemaPlugin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export default class OptionsSchemaParser {
137137
return payload
138138
}
139139

140-
static getStorageMap(defaultStorage: ?string, storageMap: ?StorageMap[]) {
140+
static getStorageMap(defaultStorage: ?string, storageMap: ?StorageMap[], configDefault?: ?string) {
141141
if (!defaultStorage && !storageMap) {
142142
return null
143143
}
@@ -152,7 +152,7 @@ export default class OptionsSchemaParser {
152152
}
153153

154154
storageMap.forEach(mapping => {
155-
if (mapping.target.id === null) {
155+
if (mapping.target.id === null && !configDefault) {
156156
return
157157
}
158158

@@ -162,15 +162,15 @@ export default class OptionsSchemaParser {
162162
}
163163
payload.backend_mappings.push({
164164
source: mapping.source.storage_backend_identifier,
165-
destination: mapping.target.name,
165+
destination: mapping.target.id === null ? configDefault : mapping.target.name,
166166
})
167167
} else {
168168
if (!payload.disk_mappings) {
169169
payload.disk_mappings = []
170170
}
171171
payload.disk_mappings.push({
172172
disk_id: mapping.source.id.toString(),
173-
destination: mapping.target.name,
173+
destination: mapping.target.id === null ? configDefault : mapping.target.name,
174174
})
175175
}
176176
})

src/sources/ReplicaSource.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class ReplicaSource {
160160
}).then(response => response.data.execution)
161161
}
162162

163-
static update(replica: MainItem, destinationEndpoint: Endpoint, updateData: UpdateData): Promise<Execution> {
163+
static update(replica: MainItem, destinationEndpoint: Endpoint, updateData: UpdateData, storageConfigDefault: string): Promise<Execution> {
164164
const parser = OptionsSchemaPlugin[destinationEndpoint.type] || OptionsSchemaPlugin.default
165165
let payload = { replica: {} }
166166

@@ -180,9 +180,9 @@ class ReplicaSource {
180180
payload.replica.source_environment = parser.getDestinationEnv(updateData.source, replica.source_environment)
181181
}
182182

183-
if (updateData.storage.length > 0) {
184-
payload.replica.storage_mappings = parser.getStorageMap(
185-
updateData.destination && updateData.destination.default_storage, updateData.storage)
183+
let defaultStorage = updateData.destination && updateData.destination.default_storage
184+
if (defaultStorage || updateData.storage.length > 0) {
185+
payload.replica.storage_mappings = parser.getStorageMap(defaultStorage, updateData.storage, storageConfigDefault)
186186
}
187187

188188
return Api.send({

src/stores/EndpointStore.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class EndpointStore {
4141
@observable connectionsInfoLoading = false
4242
@observable storageBackends: StorageBackend[] = []
4343
@observable storageLoading: boolean = false
44+
@observable storageConfigDefault: string = ''
4445

4546
@action getEndpoints(options?: { showLoading: boolean }) {
4647
if (options && options.showLoading) {
@@ -185,6 +186,7 @@ class EndpointStore {
185186
this.storageLoading = true
186187
return EndpointSource.loadStorage(endpointId, data).then(storage => {
187188
this.storageBackends = storage.storage_backends
189+
this.storageConfigDefault = storage.config_default || ''
188190
this.storageLoading = false
189191
}).catch(ex => {
190192
this.storageLoading = false

src/stores/ReplicaStore.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ class ReplicaStore {
163163
this.replicaDetails = null
164164
}
165165

166-
@action update(replica: MainItem, destinationEndpoint: Endpoint, updateData: UpdateData) {
167-
return ReplicaSource.update(replica, destinationEndpoint, updateData)
166+
@action update(replica: MainItem, destinationEndpoint: Endpoint, updateData: UpdateData, storageConfigDefault: string) {
167+
return ReplicaSource.update(replica, destinationEndpoint, updateData, storageConfigDefault)
168168
}
169169
}
170170

src/stores/WizardStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class WizardStore {
101101
@action updateStorage(storage: StorageMap) {
102102
let diskFieldName = storage.type === 'backend' ? 'storage_backend_identifier' : 'id'
103103
this.storageMap = this.storageMap
104-
.filter(n => n.type !== storage.type || n.source[diskFieldName] !== storage.source[diskFieldName])
104+
.filter(n => n.type !== storage.type || String(n.source[diskFieldName]) !== String(storage.source[diskFieldName]))
105105
this.storageMap.push(storage)
106106
}
107107

0 commit comments

Comments
 (0)