Skip to content

Commit 2f67a42

Browse files
authored
fix(cloudformation): Hide deployment button when change set is not CR… (#8338)
…EATE_COMPLETE and add delete button for CREATE_FAILED change sets ## Problem - The "Deploy Changes" button is present when viewing a change set even if the change set does not have CREATE_COMPLETE status - Additionally, the "Delete Changeset" button is not present when no changes are detected in the change set ## Solution - Added logic to check if the change set has CREATE_COMPLETE status before enabling the deploy changes button - Added the "Delete Changeset" button for the view when no changes are detected - Additionally, upon pressing the "Delete Changeset" button on the "no changes are detected" view, the button disappears to prevent additional delete attempts --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent d03a985 commit 2f67a42

File tree

5 files changed

+303
-16
lines changed

5 files changed

+303
-16
lines changed

packages/core/src/awsService/cloudformation/commands/cfnCommands.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ export function viewChangeSetCommand(client: LanguageClient, diffProvider: DiffW
135135
params.changeSetName,
136136
true,
137137
[],
138-
describeChangeSetResult.deploymentMode
138+
describeChangeSetResult.deploymentMode,
139+
describeChangeSetResult.status
139140
)
140141
void commands.executeCommand(commandKey('diff.focus'))
141142
} catch (error) {
@@ -483,7 +484,7 @@ async function changeSetSteps(
483484
try {
484485
environmentFile = await environmentManager.selectEnvironmentFile(templateUri, paramDefinition)
485486
} catch (error) {
486-
getLogger().warn(`Failed to select environment file:: ${extractErrorMessage(error)}`)
487+
getLogger().warn(`Failed to select environment file: ${extractErrorMessage(error)}`)
487488
}
488489

489490
if (paramDefinition.length > 0) {

packages/core/src/awsService/cloudformation/stacks/actions/validationWorkflow.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import { v4 as uuidv4 } from 'uuid'
7-
import { Parameter, Capability } from '@aws-sdk/client-cloudformation'
7+
import { Parameter, Capability, ChangeSetStatus } from '@aws-sdk/client-cloudformation'
88
import {
99
StackActionPhase,
1010
StackChange,
@@ -163,7 +163,8 @@ export class Validation {
163163
this.changeSetName,
164164
this.shouldEnableDeployment,
165165
validationDetail,
166-
deploymentMode
166+
deploymentMode,
167+
ChangeSetStatus.CREATE_COMPLETE
167168
)
168169
void commands.executeCommand(commandKey('diff.focus'))
169170
}

packages/core/src/awsService/cloudformation/ui/diffWebviewProvider.ts

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DiffViewHelper } from './diffViewHelper'
99
import { commandKey } from '../utils'
1010
import { StackViewCoordinator } from './stackViewCoordinator'
1111
import { showWarningConfirmation } from './message'
12+
import { ChangeSetStatus } from '@aws-sdk/client-cloudformation'
1213

1314
const webviewCommandOpenDiff = 'openDiff'
1415

@@ -24,6 +25,7 @@ export class DiffWebviewProvider implements WebviewViewProvider, Disposable {
2425
private readonly disposables: Disposable[] = []
2526
private validationDetail: ValidationDetail[] = []
2627
private deploymentMode?: DeploymentMode
28+
private changeSetStatus?: string
2729

2830
constructor(private readonly coordinator: StackViewCoordinator) {
2931
this.disposables.push(
@@ -46,7 +48,8 @@ export class DiffWebviewProvider implements WebviewViewProvider, Disposable {
4648
changeSetName?: string,
4749
enableDeployments = false,
4850
validationDetail?: ValidationDetail[],
49-
deploymentMode?: DeploymentMode
51+
deploymentMode?: DeploymentMode,
52+
changeSetStatus?: string
5053
) {
5154
this.stackName = stackName
5255
this.changes = changes
@@ -58,6 +61,7 @@ export class DiffWebviewProvider implements WebviewViewProvider, Disposable {
5861
this.validationDetail = validationDetail
5962
}
6063
this.deploymentMode = deploymentMode
64+
this.changeSetStatus = changeSetStatus
6165

6266
await this.coordinator.setChangeSetMode(stackName, true)
6367
if (this._view) {
@@ -120,6 +124,23 @@ export class DiffWebviewProvider implements WebviewViewProvider, Disposable {
120124
const displayedChanges = changes.slice(startIndex, endIndex)
121125
const hasNext = this.currentPage < this.totalPages - 1
122126
const hasPrev = this.currentPage > 0
127+
const terminalChangeSetStatuses: string[] = [
128+
ChangeSetStatus.CREATE_COMPLETE,
129+
ChangeSetStatus.FAILED,
130+
ChangeSetStatus.DELETE_FAILED,
131+
]
132+
133+
const deletionButton = `
134+
<button id="deleteChangeSet" onclick="deleteChangeSet()" style="
135+
background-color: var(--vscode-button-secondaryBackground);
136+
color: var(--vscode-button-secondaryForeground);
137+
border: none;
138+
padding: 8px 16px;
139+
margin: 0 5px;
140+
cursor: pointer;
141+
border-radius: 2px;
142+
">Delete Changeset</button>
143+
`
123144

124145
if (!changes || changes.length === 0) {
125146
return `
@@ -137,6 +158,23 @@ export class DiffWebviewProvider implements WebviewViewProvider, Disposable {
137158
</head>
138159
<body>
139160
<p>No changes detected for stack: ${this.stackName}</p>
161+
${
162+
this.changeSetName &&
163+
this.changeSetStatus &&
164+
terminalChangeSetStatuses.includes(this.changeSetStatus)
165+
? `
166+
<div class="deletion-button" style="margin: 10px 0; text-align: left; display: inline-block;">
167+
${deletionButton}
168+
</div>
169+
<script>
170+
const vscode = acquireVsCodeApi();
171+
function deleteChangeSet() {
172+
vscode.postMessage({ command: 'deleteChangeSet' });
173+
}
174+
</script>
175+
`
176+
: ''
177+
}
140178
</body>
141179
</html>
142180
`
@@ -351,9 +389,15 @@ export class DiffWebviewProvider implements WebviewViewProvider, Disposable {
351389
`
352390

353391
const deploymentButtons =
354-
this.changeSetName && this.enableDeployments
392+
this.changeSetName &&
393+
this.enableDeployments &&
394+
this.changeSetStatus &&
395+
terminalChangeSetStatuses.includes(this.changeSetStatus)
355396
? `
356397
<div class="deployment-actions" style="margin: 10px 0; text-align: left; display: inline-block;">
398+
${
399+
this.changeSetStatus === ChangeSetStatus.CREATE_COMPLETE
400+
? `
357401
<button id="confirmDeploy" onclick="confirmDeploy()" style="
358402
background-color: var(--vscode-button-background);
359403
color: var(--vscode-button-foreground);
@@ -362,16 +406,10 @@ export class DiffWebviewProvider implements WebviewViewProvider, Disposable {
362406
margin: 0 5px;
363407
cursor: pointer;
364408
border-radius: 2px;
365-
">Deploy Changes</button>
366-
<button id="deleteChangeSet" onclick="deleteChangeSet()" style="
367-
background-color: var(--vscode-button-secondaryBackground);
368-
color: var(--vscode-button-secondaryForeground);
369-
border: none;
370-
padding: 8px 16px;
371-
margin: 0 5px;
372-
cursor: pointer;
373-
border-radius: 2px;
374-
">Delete Changeset</button>
409+
">Deploy Changes</button>`
410+
: ''
411+
}
412+
${deletionButton}
375413
</div>
376414
`
377415
: ''

0 commit comments

Comments
 (0)