Skip to content

Commit

Permalink
refactor(core): convert confirmation modal to react
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherchrisberry authored and mergify[bot] committed Jan 7, 2020
1 parent abf39e7 commit a59b2c3
Show file tree
Hide file tree
Showing 39 changed files with 521 additions and 498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ export class ALBListeners extends React.Component<IALBListenersProps, IALBListen
}
return $q.resolve();
},
windowClass: 'zindex-top',
});
} else {
this.removeAuthActionInternal(listener, actions, authIndex, ruleIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export class AmazonServerGroupActions extends React.Component<IAmazonServerGroup
const taskMonitor = {
application: app,
title: 'Destroying ' + serverGroup.name,
onTaskComplete: () => {
if (ReactInjector.$state.includes('**.serverGroup', stateParams)) {
ReactInjector.$state.go('^');
}
},
};

const submitMethod = (params: IServerGroupJob) =>
Expand All @@ -110,11 +115,6 @@ export class AmazonServerGroupActions extends React.Component<IAmazonServerGroup
askForReason: true,
platformHealthOnlyShowOverride: app.attributes.platformHealthOnlyShowOverride,
platformHealthType: 'Amazon',
onTaskComplete: () => {
if (ReactInjector.$state.includes('**.serverGroup', stateParams)) {
ReactInjector.$state.go('^');
}
},
};

ServerGroupWarningMessageService.addDestroyWarningMessage(app, serverGroup, confirmationModalParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,24 @@ class AppengineServerGroupDetailsController implements IController {
}

public destroyServerGroup(): void {
const stateParams = {
name: this.serverGroup.name,
accountId: this.serverGroup.account,
region: this.serverGroup.region,
};

const taskMonitor = {
application: this.app,
title: 'Destroying ' + this.serverGroup.name,
onTaskComplete: () => {
if (this.$state.includes('**.serverGroup', stateParams)) {
this.$state.go('^');
}
},
};

const submitMethod = (params: any) => this.serverGroupWriter.destroyServerGroup(this.serverGroup, this.app, params);

const stateParams = {
name: this.serverGroup.name,
accountId: this.serverGroup.account,
region: this.serverGroup.region,
};

const confirmationModalParams = {
header: 'Really destroy ' + this.serverGroup.name + '?',
buttonText: 'Destroy ' + this.serverGroup.name,
Expand All @@ -149,11 +154,6 @@ class AppengineServerGroupDetailsController implements IController {
platformHealthOnlyShowOverride: this.app.attributes.platformHealthOnlyShowOverride,
platformHealthType: AppengineHealth.PLATFORM,
body: this.getBodyTemplate(this.serverGroup, this.app),
onTaskComplete: () => {
if (this.$state.includes('**.serverGroup', stateParams)) {
this.$state.go('^');
}
},
interestingHealthProviderNames: [] as string[],
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {
FirewallLabels,
} from '@spinnaker/core';
import UIROUTER_ANGULARJS from '@uirouter/angularjs';
import ANGULAR_UI_BOOTSTRAP from 'angular-ui-bootstrap';

export const AZURE_LOADBALANCER_DETAILS_LOADBALANCERDETAIL_CONTROLLER =
'spinnaker.azure.loadBalancer.details.controller';
export const name = AZURE_LOADBALANCER_DETAILS_LOADBALANCERDETAIL_CONTROLLER; // for backwards compatibility
angular
.module(AZURE_LOADBALANCER_DETAILS_LOADBALANCERDETAIL_CONTROLLER, [
ANGULAR_UI_BOOTSTRAP,
UIROUTER_ANGULARJS,
SECURITY_GROUP_READER,
LOAD_BALANCER_READ_SERVICE,
Expand Down Expand Up @@ -174,7 +176,6 @@ angular
header: 'Really delete ' + loadBalancer.name + '?',
buttonText: 'Delete ' + loadBalancer.name,
account: loadBalancer.accountId,
applicationName: app.name,
taskMonitorConfig: taskMonitor,
submitMethod: submitMethod,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,32 +150,32 @@ angular
this.destroyServerGroup = function destroyServerGroup() {
const serverGroup = $scope.serverGroup;

const stateParams = {
name: serverGroup.name,
accountId: serverGroup.account,
region: serverGroup.region,
};

const taskMonitor = {
application: app,
title: 'Destroying ' + serverGroup.name,
onTaskComplete: function() {
if ($state.includes('**.serverGroup', stateParams)) {
$state.go('^');
}
},
};

const submitMethod = function() {
return serverGroupWriter.destroyServerGroup(serverGroup, app);
};

const stateParams = {
name: serverGroup.name,
accountId: serverGroup.account,
region: serverGroup.region,
};

const confirmationModalParams = {
header: 'Really destroy ' + serverGroup.name + '?',
buttonText: 'Destroy ' + serverGroup.name,
account: serverGroup.account,
taskMonitorConfig: taskMonitor,
submitMethod: submitMethod,
onTaskComplete: function() {
if ($state.includes('**.serverGroup', stateParams)) {
$state.go('^');
}
},
};

ServerGroupWarningMessageService.addDestroyWarningMessage(app, serverGroup, confirmationModalParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,27 @@ export class CloudFoundryServerGroupActions extends React.Component<ICloudFoundr
private destroyServerGroup = (): void => {
const { app, serverGroup } = this.props;

const stateParams = {
name: serverGroup.name,
accountId: serverGroup.account,
region: serverGroup.region,
};

const taskMonitor = {
application: app,
title: 'Destroying ' + serverGroup.name,
onTaskComplete: () => {
if (ReactInjector.$state.includes('**.serverGroup', stateParams)) {
ReactInjector.$state.go('^');
}
},
};

const submitMethod = (params: ICloudFoundryServerGroupJob) => {
params.serverGroupName = serverGroup.name;
return ReactInjector.serverGroupWriter.destroyServerGroup(serverGroup, app, params);
};

const stateParams = {
name: serverGroup.name,
accountId: serverGroup.account,
region: serverGroup.region,
};

const confirmationModalParams = {
header: 'Really destroy ' + serverGroup.name + '?',
buttonText: 'Destroy ' + serverGroup.name,
Expand All @@ -97,11 +102,6 @@ export class CloudFoundryServerGroupActions extends React.Component<ICloudFoundr
askForReason: true,
platformHealthOnlyShowOverride: app.attributes.platformHealthOnlyShowOverride,
platformHealthType: 'Cloud Foundry',
onTaskComplete: () => {
if (ReactInjector.$state.includes('**.serverGroup', stateParams)) {
ReactInjector.$state.go('^');
}
},
};

ServerGroupWarningMessageService.addDestroyWarningMessage(app, serverGroup, confirmationModalParams);
Expand Down
135 changes: 135 additions & 0 deletions app/scripts/modules/core/src/confirmationModal/ConfirmModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import React from 'react';
import { Modal } from 'react-bootstrap';

import { TaskMonitor, TaskReason, UserVerification } from 'core/task';
import { IModalComponentProps, Markdown } from 'core/presentation';
import { NgReact } from 'core/reactShims';
import { MultiTaskMonitor } from 'core/task/monitor/MultiTaskMonitor';
import { ModalClose } from 'core/modal';
import { PlatformHealthOverride } from 'core/application/modal/PlatformHealthOverride';
import { IConfirmationModalPassthroughProps } from './confirmationModal.service';

export interface IConfirmModalProps extends IModalComponentProps, IConfirmationModalPassthroughProps {
taskMonitor?: TaskMonitor;
taskMonitors?: TaskMonitor[];
}

export const ConfirmModal = (props: IConfirmModalProps) => {
const { account, verificationLabel, textToVerify, taskMonitor, taskMonitors, closeModal, dismissModal } = props;
const { useState, useEffect } = React;

const [isSubmitting, setIsSubmitting] = useState(false);
const [isRetry, setIsRetry] = useState(false);
const [isValid, setIsValid] = useState(!account && !verificationLabel && !textToVerify);
const [error, setError] = useState<{ isError: boolean; message?: string }>({ isError: false });

const [reason, setReason] = useState<string>();
const [interestingHealthProviderNames, setInterestingHealthProviderNames] = useState<string[]>();

useEffect(() => {
if (taskMonitor && !taskMonitor.modalInstance) {
taskMonitor.modalInstance = TaskMonitor.modalInstanceEmulation(closeModal, dismissModal);
}
if (taskMonitor?.onTaskRetry) {
const { onTaskRetry } = taskMonitor;
taskMonitor.onTaskRetry = () => {
setIsRetry(true);
setIsSubmitting(false);
onTaskRetry();
};
}
}, [taskMonitor]);

const requiresVerification = account || (verificationLabel && textToVerify);
const isDisabled = isSubmitting || !isValid;

const showError = (e: string) => {
setError({ isError: true, message: e });
setIsSubmitting(false);
};

const submit = () => {
const { submitMethod, submitJustWithReason } = props;
if (isDisabled) {
return;
}
setIsSubmitting(true);
if (taskMonitors) {
taskMonitors.forEach(m => m.callPreconfiguredSubmit({ reason }));
} else if (taskMonitor) {
taskMonitor.submit(() => {
return submitMethod({
interestingHealthProviderNames,
reason,
});
});
} else if (submitJustWithReason) {
submitMethod({ reason }).then(dismissModal);
} else {
if (submitMethod) {
submitMethod().then(dismissModal, showError);
} else {
closeModal();
}
}
};

const { TaskMonitorWrapper, ButtonBusyIndicator } = NgReact;
const includeBody =
(isRetry && props.retryBody) ||
props.bodyContent ||
error.isError ||
props.platformHealthOnlyShowOverride ||
props.askForReason ||
props.submitJustWithReason;

return (
<div>
<TaskMonitorWrapper monitor={taskMonitor} />
<MultiTaskMonitor monitors={taskMonitors} title={props.multiTaskTitle} closeModal={dismissModal} />
<ModalClose dismiss={dismissModal} />
<Modal.Header>
<Modal.Title>{props.header}</Modal.Title>
</Modal.Header>
{includeBody && (
<Modal.Body>
{props.bodyContent}
{props.platformHealthOnlyShowOverride && (
<PlatformHealthOverride
interestingHealthProviderNames={interestingHealthProviderNames}
showHelpDetails={true}
platformHealthType={props.platformHealthType}
onChange={setInterestingHealthProviderNames}
/>
)}
{error.isError && (
<div className="alert alert-danger">
<h4>An error occurred:</h4>
<p>{error.message || 'No details provided.'}</p>
</div>
)}
{isRetry && props.retryBody && <Markdown message={props.retryBody} />}
{((taskMonitor || taskMonitors) && props.askForReason) ||
(props.submitJustWithReason && <TaskReason reason={reason} onChange={setReason} />)}
</Modal.Body>
)}
<Modal.Footer>
{!isSubmitting && requiresVerification && (
<UserVerification
onValidChange={setIsValid}
account={account}
expectedValue={textToVerify}
label={verificationLabel}
/>
)}
<button className="btn btn-default" type="button" onClick={dismissModal}>
{props.cancelButtonText}
</button>
<button className="btn btn-primary" type="button" onClick={submit} disabled={isDisabled}>
{isSubmitting && <ButtonBusyIndicator />}
{props.buttonText}
</button>
</Modal.Footer>
</div>
);
};
59 changes: 0 additions & 59 deletions app/scripts/modules/core/src/confirmationModal/confirm.html

This file was deleted.

Loading

0 comments on commit a59b2c3

Please sign in to comment.