Skip to content

Commit 618ccb1

Browse files
committed
undoing changes to deleteModal actions
1 parent 389f324 commit 618ccb1

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

client/services/serviceHelperInstanceActionsModal.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,21 @@ function HelperInstanceActionsModal(
176176
var deletedInstanceName = data.instance.attrs.name;
177177
data.instance.destroy(function (err) {
178178
$rootScope.safeApply();
179-
if (err) {
180-
throw err;
181-
}
182-
if ($stateParams.instanceName === deletedInstanceName) {
183-
$state.go('instance.instance', {
184-
userName: $stateParams.userName,
185-
instanceName: ''
179+
if (err) { throw err; }
180+
// redirect to next instance or new
181+
if (data.instances.models.length) {
182+
data.instances.models = $filter('orderBy')(data.instances.models, 'attrs.name');
183+
// Only change the location if we're still on the page
184+
// If the user switched to a different instance in between, we shouldn't move
185+
if ($stateParams.instanceName === deletedInstanceName) {
186+
$state.go('instance.instance', {
187+
userName: $stateParams.userName,
188+
instanceName: data.instances.models[0].attrs.name
189+
});
190+
}
191+
} else {
192+
$state.go('instance.new', {
193+
userName: $stateParams.userName
186194
});
187195
}
188196
});

test/unit/services/serviceHelperInstanceActionsModal.unit.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,8 @@ describe('serviceHelperInstanceActionsModal'.bold.underline.blue, function() {
307307

308308
sinon.assert.called(fakeGo);
309309
sinon.assert.called($scope.instance.destroy);
310-
sinon.assert.calledWith(fakeGo,'instance.instance', {
311-
userName: 'username',
312-
instanceName: ''
310+
sinon.assert.calledWith(fakeGo,'instance.new', {
311+
userName: 'username'
313312
});
314313
done();
315314
});
@@ -327,7 +326,7 @@ describe('serviceHelperInstanceActionsModal'.bold.underline.blue, function() {
327326
sinon.assert.called($scope.instance.destroy);
328327
sinon.assert.calledWith(fakeGo,'instance.instance', {
329328
userName: 'username',
330-
instanceName: ''
329+
instanceName: 'other'
331330
});
332331
done();
333332
});
@@ -362,7 +361,7 @@ describe('serviceHelperInstanceActionsModal'.bold.underline.blue, function() {
362361
sinon.assert.called($scope.instance.destroy);
363362
sinon.assert.neverCalledWith(fakeGo,'instance.instance', {
364363
userName: 'username',
365-
instanceName: ''
364+
instanceName: 'other'
366365
});
367366
done();
368367
}, 50);

0 commit comments

Comments
 (0)