mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-27 21:26:38 +00:00
Merge pull request #2112 from resin-io/store-fix-autoselect-stale
fix: stop autoselecting empty value in store
This commit is contained in:
commit
98dcb13201
@ -177,6 +177,23 @@ const storeReducer = (state = DEFAULT_STATE, action) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newState = state.set('availableDrives', Immutable.fromJS(drives))
|
const newState = state.set('availableDrives', Immutable.fromJS(drives))
|
||||||
|
const selectedDevices = newState.getIn([ 'selection', 'devices' ]).toJS()
|
||||||
|
|
||||||
|
// Remove selected drives that are stale, i.e. missing from availableDrives
|
||||||
|
const nonStaleNewState = _.reduce(selectedDevices, (accState, device) => {
|
||||||
|
// Check whether the drive still exists in availableDrives
|
||||||
|
if (device && !_.find(drives, {
|
||||||
|
device
|
||||||
|
})) {
|
||||||
|
// Deselect this drive gone from availableDrives
|
||||||
|
return storeReducer(accState, {
|
||||||
|
type: ACTIONS.DESELECT_DRIVE,
|
||||||
|
data: device
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return accState
|
||||||
|
}, newState)
|
||||||
|
|
||||||
const AUTOSELECT_DRIVE_COUNT = 1
|
const AUTOSELECT_DRIVE_COUNT = 1
|
||||||
const numberOfDrives = drives.length
|
const numberOfDrives = drives.length
|
||||||
@ -200,36 +217,20 @@ const storeReducer = (state = DEFAULT_STATE, action) => {
|
|||||||
|
|
||||||
])) {
|
])) {
|
||||||
// Auto-select this drive
|
// Auto-select this drive
|
||||||
return storeReducer(newState, {
|
return storeReducer(nonStaleNewState, {
|
||||||
type: ACTIONS.SELECT_DRIVE,
|
type: ACTIONS.SELECT_DRIVE,
|
||||||
data: drive.device
|
data: drive.device
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deselect this drive in case it still is selected
|
// Deselect this drive in case it still is selected
|
||||||
return storeReducer(newState, {
|
return storeReducer(nonStaleNewState, {
|
||||||
type: ACTIONS.DESELECT_DRIVE,
|
type: ACTIONS.DESELECT_DRIVE,
|
||||||
data: drive.device
|
data: drive.device
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectedDevices = newState.getIn([ 'selection', 'devices' ]).toJS()
|
return nonStaleNewState
|
||||||
|
|
||||||
// Remove selected drives that are stale, i.e. missing from availableDrives
|
|
||||||
return _.reduce(selectedDevices, (accState, device) => {
|
|
||||||
// Check whether the drive still exists in availableDrives
|
|
||||||
if (device && !_.find(drives, {
|
|
||||||
device
|
|
||||||
})) {
|
|
||||||
// Deselect this drive gone from availableDrives
|
|
||||||
return storeReducer(accState, {
|
|
||||||
type: ACTIONS.DESELECT_DRIVE,
|
|
||||||
data: device
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return accState
|
|
||||||
}, newState)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case ACTIONS.SET_FLASH_STATE: {
|
case ACTIONS.SET_FLASH_STATE: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user