Skip to content

Commit

Permalink
fix(core/modal): avoid throwing errors on modal $dismiss (#4233)
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry authored Oct 8, 2017
1 parent 9b55134 commit ed9c20f
Show file tree
Hide file tree
Showing 26 changed files with 197 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module.exports = angular.module('spinnaker.amazon.pipeline.stage.bakeStage', [
}
}).result.then(function(extendedAttribute) {
$scope.stage.extendedAttributes[extendedAttribute.key] = extendedAttribute.value;
});
}).catch(() => {});
};

this.removeExtendedAttribute = function (key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AppengineEditLoadBalancerStageCtrl implements IController {
}
}).result.then((newLoadBalancer: ILoadBalancer) => {
this.$scope.stage.loadBalancers.push(newLoadBalancer);
});
}).catch(() => {});
}

public editLoadBalancer(index: number) {
Expand All @@ -42,7 +42,7 @@ class AppengineEditLoadBalancerStageCtrl implements IController {
}
}).result.then((updatedLoadBalancer: ILoadBalancer) => {
this.$scope.stage.loadBalancers[index] = updatedLoadBalancer;
});
}).catch(() => {});
}

public removeLoadBalancer(index: number): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ module.exports = angular.module('spinnaker.azure.pipeline.stage.bakeStage', [
}
}).result.then(function(extendedAttribute) {
$scope.stage.extendedAttributes[extendedAttribute.key] = extendedAttribute.value;
});
}).catch(() => {});
};

this.removeExtendedAttribute = function (key) {
Expand Down
4 changes: 2 additions & 2 deletions app/scripts/modules/canary/canary/canaryStage.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ module.exports = angular.module('spinnaker.canary.canaryStage', [
cleanupClusterConfig(baselineCluster, 'baseline');
cleanupClusterConfig(canaryCluster, 'canary');
$scope.stage.clusterPairs.push({baseline: baselineCluster, canary: canaryCluster});
});
}).catch(() => {});
});
};

Expand Down Expand Up @@ -447,7 +447,7 @@ module.exports = angular.module('spinnaker.canary.canaryStage', [
var stageCluster = awsServerGroupTransformer.convertServerGroupCommandToDeployConfiguration(command);
cleanupClusterConfig(stageCluster, type);
$scope.stage.clusterPairs[index][type.toLowerCase()] = stageCluster;
});
}).catch(() => {});
};

this.deleteClusterPair = function(index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ApplicationsController implements IController {
templateUrl: this.overrideRegistry.getTemplate('createApplicationModal', require('./modal/newapplication.html')),
controller: this.overrideRegistry.getController('CreateApplicationModalCtrl'),
controllerAs: 'newAppModal'
}).result.then((app) => this.routeToApplication(app));
}).result.then((app) => this.routeToApplication(app)).catch(() => {});
}
}
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ module.exports = angular
this.application.attributes = newAttributes;
setHealthMessage();
setPermissions();
});
}).catch(() => {});
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,16 @@ describe('Controller: Config', function () {

it('should copy attributes when edit application is successful', function() {
var newAttributes = { foo: 'bar' };
spyOn($uibModal, 'open').and.returnValue({
const modalStub = {
result: {
then: function(method) {
method(newAttributes);
}
return modalStub.result;
},
catch: () => {}
}
});
};
spyOn($uibModal, 'open').and.returnValue(modalStub);

configController.editApplication();
expect(application.attributes).toBe(newAttributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = angular
}).result.then(newSections => {
this.sections = newSections;
this.configChanged();
});
}).catch(() => {});
};

this.sortOptions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class ExecutionGroup extends React.Component<IExecutionGroupProps, IExecu
application: () => this.props.application,
currentlyRunningExecutions: () => this.props.group.runningExecutions,
}
}).result.then((command) => this.startPipeline(command));
}).result.then((command) => this.startPipeline(command)).catch(() => {});
}

public componentDidMount(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,6 @@ module.exports = angular.module('spinnaker.core.delivery.executions.controller',
pipeline: () => null,
application: () => this.application,
}
}).result.then(startPipeline);
}).result.then(startPipeline).catch(() => {});
};
});
24 changes: 24 additions & 0 deletions app/scripts/modules/core/src/modal/dismiss.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { module } from 'angular';
import IProvideService = angular.auto.IProvideService;

import { IModalStackService } from 'angular-ui-bootstrap';

export const DISMISS_DECORATOR = 'spinnaker.core.modal.dismiss.decorator';
module(DISMISS_DECORATOR, [])
.config(($provide: IProvideService) => {
// Prevents an error from escaping when the user dismisses a modal created via the ReactInjector
// (error looks like: "Possibly unhandled rejection: undefined undefined")
$provide.decorator('$uibModalStack', ($delegate: IModalStackService) => {
const originalDismiss: Function = $delegate.dismiss;
$delegate.dismiss = (...args: any[]) => {
originalDismiss.apply(this, args);
const [ modalInstance ] = args;
if (modalInstance && modalInstance.result) {
modalInstance.result
.catch(() => {});
}
};

return $delegate;
});
});
10 changes: 6 additions & 4 deletions app/scripts/modules/core/src/modal/modal.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

const angular = require('angular');

import {V2_MODAL_WIZARD_COMPONENT} from './wizard/v2modalWizard.component';
import {V2_MODAL_WIZARD_SERVICE} from './wizard/v2modalWizard.service';
import {MODAL_CLOSE_COMPONENT} from './buttons/modalClose.component';
import {SUBMIT_BUTTON_COMPONENT} from './buttons/submitButton.component';
import { DISMISS_DECORATOR } from './dismiss.decorator';
import { V2_MODAL_WIZARD_COMPONENT } from './wizard/v2modalWizard.component';
import { V2_MODAL_WIZARD_SERVICE } from './wizard/v2modalWizard.service';
import { MODAL_CLOSE_COMPONENT } from './buttons/modalClose.component';
import { SUBMIT_BUTTON_COMPONENT } from './buttons/submitButton.component';

import './modals.less';

Expand All @@ -15,6 +16,7 @@ module.exports = angular
require('./modalPage.directive.js').name,
require('./wizard/wizardSubFormValidation.service').name,
require('./closeable/closeable.modal.controller').name,
DISMISS_DECORATOR,
MODAL_CLOSE_COMPONENT,
SUBMIT_BUTTON_COMPONENT,
V2_MODAL_WIZARD_SERVICE,
Expand Down
Loading

0 comments on commit ed9c20f

Please sign in to comment.