Skip to content

Commit

Permalink
Merge pull request #12 from merenbach/update-status-on-sync
Browse files Browse the repository at this point in the history
Refactor app sync and delete
  • Loading branch information
merenbach committed Jul 11, 2018
2 parents 87f706a + 73452f7 commit bf9f634
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,8 @@ export class ApplicationDetails extends React.Component<RouteComponentProps<{ na
}

private async syncApplication(revision: string, prune: boolean) {
try {
await services.applications.sync(this.props.match.params.name, revision, prune);
this.setDeployPanelVisible(false);
} catch (e) {
this.appContext.apis.notifications.show({
content: <ErrorNotification title='Unable to deploy revision' e={e}/>,
type: NotificationType.Error,
});
}
await AppUtils.syncApplication(this.props.match.params.name, revision, prune, this.appContext);
this.setDeployPanelVisible(false);
}

private async rollbackApplication(deploymentInfo: appModels.DeploymentInfo) {
Expand Down Expand Up @@ -342,9 +335,8 @@ export class ApplicationDetails extends React.Component<RouteComponentProps<{ na
}

private async deleteApplication() {
AppUtils.deleteApplication(this.props.match.params.name, this.appContext, () => {
this.appContext.apis.navigation.goto('/applications');
});
await AppUtils.deleteApplication(this.props.match.params.name, this.appContext);
this.appContext.apis.navigation.goto('/applications');
}

private getResourceLabels(resource: appModels.ResourceNode | appModels.ResourceState): string[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,15 @@ export class ApplicationsList extends React.Component<Props, State> {
}

private async syncApplication(appName: string, revision: string) {
try {
await services.applications.sync(appName, revision, false).then(() => {
this.appContext.apis.notifications.show({
type: NotificationType.Success,
content: `Synced revision`,
});
});
} catch (e) {
this.appContext.apis.notifications.show({
content: <ErrorNotification title='Unable to deploy revision' e={e}/>,
type: NotificationType.Error,
});
}
await AppUtils.syncApplication(appName, revision, false, this.appContext);
this.appContext.apis.notifications.show({
type: NotificationType.Success,
content: `Synced revision`,
});
}

private async deleteApplication(appName: string) {
AppUtils.deleteApplication(appName, this.appContext, () => {
this.appContext.router.history.push('/applications');
});
await AppUtils.deleteApplication(appName, this.appContext);
this.appContext.router.history.push('/applications');
}
}
14 changes: 12 additions & 2 deletions src/app/applications/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ import { AppContext } from '../../shared/context';
import * as appModels from '../../shared/models';
import { services } from '../../shared/services';

export async function deleteApplication(appName: string, context: AppContext, success: () => void) {
export async function syncApplication(appName: string, revision: string, prune: boolean, context: AppContext) {
try {
await services.applications.sync(appName, revision, prune);
} catch (e) {
context.apis.notifications.show({
content: <ErrorNotification title='Unable to deploy revision' e={e}/>,
type: NotificationType.Error,
});
}
}

export async function deleteApplication(appName: string, context: AppContext) {
let cascade = false;
const confirmationForm = class extends React.Component<{}, { cascade: boolean } > {
constructor(props: any) {
Expand All @@ -29,7 +40,6 @@ export async function deleteApplication(appName: string, context: AppContext, su
if (confirmed) {
try {
await services.applications.delete(appName, cascade);
success();
} catch (e) {
this.appContext.apis.notifications.show({
content: <ErrorNotification title='Unable to delete application' e={e}/>,
Expand Down

0 comments on commit bf9f634

Please sign in to comment.