Skip to content

Commit

Permalink
Merge pull request #3263 from cloudfoundry-incubator/confirm-restage
Browse files Browse the repository at this point in the history
Add confirmation dialog to `Restage` app
  • Loading branch information
nwmac authored Dec 7, 2018
2 parents 1732d73 + 7bf1fe3 commit 905d709
Showing 1 changed file with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { applicationSchemaKey, appStatsSchemaKey, entityFactory } from '../../..
import { endpointEntitiesSelector } from '../../../../store/selectors/endpoint.selectors';
import { APIResource } from '../../../../store/types/api.types';
import { EndpointModel } from '../../../../store/types/endpoint.types';
import { ApplicationService } from '../../application.service';
import { ApplicationService, ApplicationData } from '../../application.service';
import { EndpointsService } from './../../../../core/endpoints.service';
import { RestageApplication } from '../../../../store/actions/application.actions';
import { ApplicationStateData } from '../../../../shared/components/application-state/application-state.service';
Expand Down Expand Up @@ -49,6 +49,11 @@ const appRestartConfirmation = new ConfirmationDialogConfig(
'Are you sure you want to restart this Application?',
'Restart'
);
const appRestageConfirmation = new ConfirmationDialogConfig(
'Restage Application',
'Are you sure you want to restage this Application?',
'Restage'
);

@Component({
selector: 'app-application-tabs-base',
Expand Down Expand Up @@ -202,13 +207,17 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy {
];
}

private startStopApp(confirmConfig: ConfirmationDialogConfig, updateKey: string, requiredAppState: string, onSuccess: () => void) {
private confirmAndPollForState(
confirmConfig: ConfirmationDialogConfig,
onConfirm: (appData: ApplicationData) => void,
updateKey: string,
requiredAppState: string,
onSuccess: () => void) {
this.applicationService.application$.pipe(
first(),
tap(appData => {
this.confirmDialog.open(confirmConfig, () => {
// Once the state changes always make a request to app stats via [AppMetadataTypes.STATS] below
this.applicationService.updateApplication({ state: requiredAppState }, [AppMetadataTypes.STATS], appData.app.entity);
onConfirm(appData);
this.pollEntityService(updateKey, requiredAppState).pipe(
first(),
).subscribe(onSuccess);
Expand All @@ -217,8 +226,18 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy {
).subscribe();
}

private updateApp(confirmConfig: ConfirmationDialogConfig, updateKey: string, requiredAppState: string, onSuccess: () => void) {
this.confirmAndPollForState(
confirmConfig,
appData => this.applicationService.updateApplication({ state: requiredAppState }, [AppMetadataTypes.STATS], appData.app.entity),
updateKey,
requiredAppState,
onSuccess
);
}

stopApplication() {
this.startStopApp(appStopConfirmation, 'stopping', 'STOPPED', () => {
this.updateApp(appStopConfirmation, 'stopping', 'STOPPED', () => {
// On app reaching the 'STOPPED' state clear the app's stats pagination section
const { cfGuid, appGuid } = this.applicationService;
this.store.dispatch(new ResetPagination(appStatsSchemaKey, new GetAppStatsAction(appGuid, cfGuid).paginationKey));
Expand All @@ -227,7 +246,13 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy {

restageApplication() {
const { cfGuid, appGuid } = this.applicationService;
this.store.dispatch(new RestageApplication(appGuid, cfGuid));
this.confirmAndPollForState(
appRestageConfirmation,
() => this.store.dispatch(new RestageApplication(appGuid, cfGuid)),
'starting',
'STARTED',
() => { }
);
}

pollEntityService(state, stateString): Observable<any> {
Expand All @@ -241,7 +266,7 @@ export class ApplicationTabsBaseComponent implements OnInit, OnDestroy {
}

startApplication() {
this.startStopApp(appStartConfirmation, 'starting', 'STARTED', () => { });
this.updateApp(appStartConfirmation, 'starting', 'STARTED', () => { });
}

private dispatchAppStats = () => {
Expand Down

0 comments on commit 905d709

Please sign in to comment.