Browse Source

do not flush selection on "old" boot source

This fixes an issue introduced by watchers:
when page initialized images watchers called before
select boot source watcher.it leads to sutiation when
we specify selection from user input and flush it on
updateBootSource. as a result page come to
inconsistent state described in the bug.
Perhaps, this requires big refactoring but  in the
current patch we do not flush selection if boot type
was not changed. it allows to use image, snapshot,
volume from context as ctrl.selection.

Change-Id: I4b23071a2a9e2c02cc1f46713165e5cb5155894f
Closes-Bug: #1710890
(cherry picked from commit 48862eb9b7)
kairat_kushaev 1 year ago
parent
commit
2fe66f444a

+ 5
- 2
openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.js View File

@@ -428,7 +428,10 @@
428 428
     ////////////////////
429 429
 
430 430
     function updateBootSourceSelection(selectedSource) {
431
-      ctrl.currentBootSource = selectedSource;
431
+      if (ctrl.currentBootSource !== selectedSource) {
432
+        ctrl.selection.length = 0;
433
+        ctrl.currentBootSource = selectedSource;
434
+      }
432 435
       if ((selectedSource === bootSourceTypes.IMAGE ||
433 436
            selectedSource === bootSourceTypes.INSTANCE_SNAPSHOT) && $scope.model.volumeBootable) {
434 437
         $scope.model.newInstanceSpec.vol_create =
@@ -451,8 +454,8 @@
451 454
     }
452 455
 
453 456
     function updateDataSource(key, preSelection) {
454
-      selection.length = 0;
455 457
       if (preSelection) {
458
+        ctrl.selection.length = 0;
456 459
         push.apply(selection, preSelection);
457 460
       }
458 461
       angular.extend(ctrl.tableData, bootSources[key]);

+ 14
- 0
openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/source/source.controller.spec.js View File

@@ -290,6 +290,20 @@
290 290
             scope.$apply();
291 291
             expect(scope.$broadcast).toHaveBeenCalled();
292 292
           });
293
+          it('should not flush selection if boot source still the same', function() {
294
+            ctrl.currentBootSource = 'image';
295
+            ctrl.selection = ['test_selection'];
296
+            ctrl.updateBootSourceSelection('image');
297
+            scope.$apply();
298
+            expect(ctrl.selection).toEqual(['test_selection']);
299
+          });
300
+          it('should flush selection on new boot source', function() {
301
+            ctrl.currentBootSource = 'image';
302
+            ctrl.selection = ['test_selection'];
303
+            ctrl.updateBootSourceSelection('volume');
304
+            scope.$apply();
305
+            expect(ctrl.selection).toEqual([]);
306
+          });
293 307
         });
294 308
 
295 309
         describe('source allocation', function() {

Loading…
Cancel
Save