mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-27 21:26:38 +00:00
fix: deselect drive if its not available anymore (#513)
If the user has a selected drive, but a new scan shows that such drive is no longer available, then the selected drive should be de-selected. Signed-off-by: Juan Cruz Viotti <jviottidc@gmail.com>
This commit is contained in:
parent
e16139af03
commit
c2c5eb59b9
@ -162,11 +162,6 @@ app.controller('AppController', function(
|
|||||||
DriveScannerService.on('drives', function(drives) {
|
DriveScannerService.on('drives', function(drives) {
|
||||||
self.drives.setDrives(drives);
|
self.drives.setDrives(drives);
|
||||||
|
|
||||||
// Cover the case where you select a drive, but then eject it.
|
|
||||||
if (self.selection.hasDrive() && !_.find(drives, self.selection.isCurrentDrive)) {
|
|
||||||
self.selection.removeDrive();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_.isEmpty(drives)) {
|
if (_.isEmpty(drives)) {
|
||||||
DriveSelectorService.close();
|
DriveSelectorService.close();
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,16 @@ module.exports = redux.createStore(function(state, action) {
|
|||||||
throw new Error(`Invalid drives: ${action.data}`);
|
throw new Error(`Invalid drives: ${action.data}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return state.set('availableDrives', Immutable.fromJS(action.data));
|
const newState = state.set('availableDrives', Immutable.fromJS(action.data));
|
||||||
|
const selectedDevice = state.getIn([ 'selection', 'drive', 'device' ]);
|
||||||
|
|
||||||
|
if (selectedDevice && !_.find(action.data, {
|
||||||
|
device: selectedDevice
|
||||||
|
})) {
|
||||||
|
return newState.deleteIn([ 'selection', 'drive' ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'SET_FLASH_STATE': {
|
case 'SET_FLASH_STATE': {
|
||||||
|
@ -7,15 +7,18 @@ require('angular-mocks');
|
|||||||
describe('Browser: DrivesModel', function() {
|
describe('Browser: DrivesModel', function() {
|
||||||
|
|
||||||
beforeEach(angular.mock.module(
|
beforeEach(angular.mock.module(
|
||||||
require('../../../lib/gui/models/drives')
|
require('../../../lib/gui/models/drives'),
|
||||||
|
require('../../../lib/gui/models/selection-state')
|
||||||
));
|
));
|
||||||
|
|
||||||
describe('DrivesModel', function() {
|
describe('DrivesModel', function() {
|
||||||
|
|
||||||
let DrivesModel;
|
let DrivesModel;
|
||||||
|
let SelectionStateModel;
|
||||||
|
|
||||||
beforeEach(angular.mock.inject(function(_DrivesModel_) {
|
beforeEach(angular.mock.inject(function(_DrivesModel_, _SelectionStateModel_) {
|
||||||
DrivesModel = _DrivesModel_;
|
DrivesModel = _DrivesModel_;
|
||||||
|
SelectionStateModel = _SelectionStateModel_;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should have no drives by default', function() {
|
it('should have no drives by default', function() {
|
||||||
@ -85,23 +88,59 @@ describe('Browser: DrivesModel', function() {
|
|||||||
this.drives = [
|
this.drives = [
|
||||||
{
|
{
|
||||||
device: '/dev/sdb',
|
device: '/dev/sdb',
|
||||||
description: 'Foo',
|
name: 'SD Card',
|
||||||
size: '14G',
|
size: 9999999,
|
||||||
mountpoint: '/mnt/foo',
|
mountpoint: '/mnt/foo',
|
||||||
system: false
|
system: false,
|
||||||
|
protected: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
device: '/dev/sdc',
|
device: '/dev/sdc',
|
||||||
description: 'Bar',
|
name: 'USB Drive',
|
||||||
size: '14G',
|
size: 9999999,
|
||||||
mountpoint: '/mnt/bar',
|
mountpoint: '/mnt/bar',
|
||||||
system: false
|
system: false,
|
||||||
|
protected: false
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
DrivesModel.setDrives(this.drives);
|
DrivesModel.setDrives(this.drives);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('given one of the drives was selected', function() {
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
SelectionStateModel.setDrive({
|
||||||
|
device: '/dev/sdc',
|
||||||
|
name: 'USB Drive',
|
||||||
|
size: 9999999,
|
||||||
|
mountpoint: '/mnt/bar',
|
||||||
|
system: false,
|
||||||
|
protected: false
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
SelectionStateModel.removeDrive();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be delected if its not contain in the available drives anymore', function() {
|
||||||
|
m.chai.expect(SelectionStateModel.hasDrive()).to.be.true;
|
||||||
|
DrivesModel.setDrives([
|
||||||
|
{
|
||||||
|
device: '/dev/sdb',
|
||||||
|
name: 'SD Card',
|
||||||
|
size: 9999999,
|
||||||
|
mountpoint: '/mnt/foo',
|
||||||
|
system: false,
|
||||||
|
protected: false
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
m.chai.expect(SelectionStateModel.hasDrive()).to.be.false;
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('.hasAvailableDrives()', function() {
|
describe('.hasAvailableDrives()', function() {
|
||||||
|
|
||||||
it('should return true', function() {
|
it('should return true', function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user