Skip to content

Commit 9cf9bdd

Browse files
authored
fix(lambda): Revert update to function upload directory selection wizard (aws#7624)
fixes aws#7618 ## Problem Introduced in aws#7601 is a bug where choosing to upload a Lambda function from a directory would not allow the user to actually select the directory. In the directory selection window, the button to select is disabled. This was an inadvertent change when adding new functionality. ## Solution Revert the breaking change. In addition to switching `canSelectFolders` to `true` and `canSelectFiles` to `false`, I have reverted the other changes in the upload flow that were added in the original PR. This is because these changes added another flow to the upload modal that doesn't fit with all the other added functionality, and just increases the complexity of the code without much benefit. Because this was the only place that used the `lambdaEdits` array from the `utils`, I removed that as well. --- - 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 eb3ceee commit 9cf9bdd

File tree

6 files changed

+26
-119
lines changed

6 files changed

+26
-119
lines changed

packages/core/src/lambda/commands/editLambda.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
getFunctionInfo,
1313
getLambdaDetails,
1414
getTempLocation,
15-
lambdaEdits,
1615
lambdaTempPath,
1716
setFunctionInfo,
1817
} from '../utils'
@@ -138,7 +137,6 @@ export async function editLambdaCommand(functionNode: LambdaFunctionNode) {
138137
export async function editLambda(lambda: LambdaFunction, onActivation?: boolean) {
139138
return await telemetry.lambda_quickEditFunction.run(async () => {
140139
telemetry.record({ source: onActivation ? 'workspace' : 'explorer' })
141-
const { name, region, configuration } = lambda
142140
const downloadLocation = getTempLocation(lambda.name, lambda.region)
143141
const downloadLocationName = vscode.workspace.asRelativePath(downloadLocation, true)
144142

@@ -201,9 +199,6 @@ export async function editLambda(lambda: LambdaFunction, onActivation?: boolean)
201199
watchForUpdates(lambda, vscode.Uri.file(downloadLocation))
202200
}
203201

204-
const newEdit = { location: downloadLocationName, region, functionName: name, configuration }
205-
lambdaEdits.push(newEdit)
206-
207202
return downloadLocation
208203
})
209204
}

packages/core/src/lambda/commands/uploadLambda.ts

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ import { SamCliBuildInvocation } from '../../shared/sam/cli/samCliBuild'
1919
import { getSamCliContext } from '../../shared/sam/cli/samCliContext'
2020
import { SamTemplateGenerator } from '../../shared/templates/sam/samTemplateGenerator'
2121
import { addCodiconToString } from '../../shared/utilities/textUtilities'
22-
import { getLambdaEditFromNameRegion, getLambdaDetails, listLambdaFunctions } from '../utils'
22+
import { getLambdaDetails, listLambdaFunctions } from '../utils'
2323
import { getIdeProperties } from '../../shared/extensionUtilities'
2424
import { createQuickPick, DataQuickPickItem } from '../../shared/ui/pickerPrompter'
2525
import { createCommonButtons } from '../../shared/ui/buttons'
2626
import { StepEstimator, Wizard, WIZARD_BACK } from '../../shared/wizards/wizard'
2727
import { createSingleFileDialog } from '../../shared/ui/common/openDialog'
2828
import { Prompter, PromptResult } from '../../shared/ui/prompter'
29-
import { SkipPrompter } from '../../shared/ui/common/skipPrompter'
3029
import { ToolkitError } from '../../shared/errors'
3130
import { FunctionConfiguration } from 'aws-sdk/clients/lambda'
3231
import globals from '../../shared/extensionGlobals'
@@ -104,13 +103,6 @@ export async function uploadLambdaCommand(lambdaArg?: LambdaFunction, path?: vsc
104103
} else if (response.uploadType === 'directory' && response.directoryBuildType) {
105104
result = (await runUploadDirectory(lambda, response.directoryBuildType, response.targetUri)) ?? result
106105
result = 'Succeeded'
107-
} else if (response.uploadType === 'edit') {
108-
const functionPath = getLambdaEditFromNameRegion(lambda.name, lambda.region)?.location
109-
if (!functionPath) {
110-
throw new ToolkitError('Function had a local copy before, but not anymore')
111-
} else {
112-
await runUploadDirectory(lambda, 'zip', vscode.Uri.file(functionPath))
113-
}
114106
}
115107
// TODO(sijaden): potentially allow the wizard to easily support tagged-union states
116108
} catch (err) {
@@ -139,8 +131,8 @@ export async function uploadLambdaCommand(lambdaArg?: LambdaFunction, path?: vsc
139131
/**
140132
* Selects the type of file to upload (zip/dir) and proceeds with the rest of the workflow.
141133
*/
142-
function createUploadTypePrompter(lambda?: LambdaFunction) {
143-
const items: DataQuickPickItem<'edit' | 'zip' | 'directory'>[] = [
134+
function createUploadTypePrompter() {
135+
const items: DataQuickPickItem<'zip' | 'directory'>[] = [
144136
{
145137
label: addCodiconToString('file-zip', localize('AWS.generic.filetype.zipfile', 'ZIP Archive')),
146138
data: 'zip',
@@ -151,17 +143,6 @@ function createUploadTypePrompter(lambda?: LambdaFunction) {
151143
},
152144
]
153145

154-
if (lambda !== undefined) {
155-
const { region, name: functionName } = lambda
156-
const lambdaEdit = getLambdaEditFromNameRegion(functionName, region)
157-
if (lambdaEdit) {
158-
items.unshift({
159-
label: addCodiconToString('edit', localize('AWS.generic.filetype.edit', 'Local edit')),
160-
data: 'edit',
161-
})
162-
}
163-
}
164-
165146
return createQuickPick(items, {
166147
title: localize('AWS.lambda.upload.title', 'Select Upload Type'),
167148
buttons: createCommonButtons(),
@@ -215,7 +196,7 @@ function createConfirmDeploymentPrompter(lambda: LambdaFunction) {
215196
}
216197

217198
export interface UploadLambdaWizardState {
218-
readonly uploadType: 'edit' | 'zip' | 'directory'
199+
readonly uploadType: 'zip' | 'directory'
219200
readonly targetUri: vscode.Uri
220201
readonly directoryBuildType: 'zip' | 'sam'
221202
readonly confirmedDeploy: boolean
@@ -234,23 +215,23 @@ export class UploadLambdaWizard extends Wizard<UploadLambdaWizardState> {
234215
this.form.targetUri.setDefault(this.invokePath)
235216
}
236217
} else {
237-
this.form.uploadType.bindPrompter(() => createUploadTypePrompter(this.lambda))
238-
this.form.targetUri.bindPrompter(
239-
({ uploadType }) => {
240-
if (uploadType === 'directory') {
241-
return createSingleFileDialog({
242-
canSelectFolders: false,
243-
canSelectFiles: true,
244-
filters: {
245-
'ZIP archive': ['zip'],
246-
},
247-
})
248-
} else {
249-
return new SkipPrompter()
250-
}
251-
},
252-
{ showWhen: ({ uploadType }) => uploadType !== 'edit' }
253-
)
218+
this.form.uploadType.bindPrompter(() => createUploadTypePrompter())
219+
this.form.targetUri.bindPrompter(({ uploadType }) => {
220+
if (uploadType === 'directory') {
221+
return createSingleFileDialog({
222+
canSelectFolders: true,
223+
canSelectFiles: false,
224+
})
225+
} else {
226+
return createSingleFileDialog({
227+
canSelectFolders: false,
228+
canSelectFiles: true,
229+
filters: {
230+
'ZIP archive': ['zip'],
231+
},
232+
})
233+
}
234+
})
254235
}
255236

256237
this.form.lambda.name.bindPrompter((state) => {
@@ -277,12 +258,7 @@ export class UploadLambdaWizard extends Wizard<UploadLambdaWizardState> {
277258
this.form.directoryBuildType.setDefault('zip')
278259
}
279260

280-
this.form.confirmedDeploy.bindPrompter(
281-
(state) => {
282-
return createConfirmDeploymentPrompter(state.lambda!)
283-
},
284-
{ showWhen: ({ uploadType }) => uploadType !== 'edit' }
285-
)
261+
this.form.confirmedDeploy.bindPrompter((state) => createConfirmDeploymentPrompter(state.lambda!))
286262

287263
return this
288264
}

packages/core/src/lambda/utils.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,23 +202,3 @@ export function getTempRegionLocation(region: string) {
202202
export function getTempLocation(functionName: string, region: string) {
203203
return path.join(getTempRegionLocation(region), functionName)
204204
}
205-
206-
type LambdaEdit = {
207-
location: string
208-
functionName: string
209-
region: string
210-
configuration?: Lambda.FunctionConfiguration
211-
}
212-
213-
// Array to keep the list of functions that are being edited.
214-
export const lambdaEdits: LambdaEdit[] = []
215-
216-
// Given a particular function and region, it returns the full LambdaEdit object
217-
export function getLambdaEditFromNameRegion(name: string, functionRegion: string) {
218-
return lambdaEdits.find(({ functionName, region }) => functionName === name && region === functionRegion)
219-
}
220-
221-
// Given a particular localPath, it returns the full LambdaEdit object
222-
export function getLambdaEditFromLocation(functionLocation: string) {
223-
return lambdaEdits.find(({ location }) => location === functionLocation)
224-
}

packages/core/src/test/lambda/commands/editLambda.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ describe('editLambda', function () {
7575
sinon.replace(require('../../../lambda/commands/editLambda'), 'promptDeploy', promptDeployStub)
7676

7777
// Other stubs
78-
sinon.stub(utils, 'lambdaEdits').value([])
7978
sinon.stub(utils, 'getLambdaDetails').returns({ fileName: 'index.js', functionName: 'test-function' })
8079
sinon.stub(fs, 'readdir').resolves([])
8180
sinon.stub(fs, 'delete').resolves()

packages/core/src/test/lambda/utils.test.ts

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import {
1212
getFunctionInfo,
1313
setFunctionInfo,
1414
compareCodeSha,
15-
lambdaEdits,
16-
getLambdaEditFromNameRegion,
17-
getLambdaEditFromLocation,
1815
} from '../../lambda/utils'
1916
import { LambdaFunction } from '../../lambda/commands/uploadLambda'
2017
import { DefaultLambdaClient } from '../../shared/clients/lambdaClient'
@@ -187,48 +184,4 @@ describe('lambda utils', function () {
187184
assert.strictEqual(result, false)
188185
})
189186
})
190-
191-
describe('lambdaEdits array functions', function () {
192-
beforeEach(function () {
193-
lambdaEdits.length = 0
194-
lambdaEdits.push(
195-
{
196-
location: '/tmp/func1',
197-
functionName: 'func1',
198-
region: 'us-east-1',
199-
},
200-
{
201-
location: '/tmp/func2',
202-
functionName: 'func2',
203-
region: 'us-west-2',
204-
}
205-
)
206-
})
207-
208-
describe('getLambdaEditFromNameRegion', function () {
209-
it('finds edit by name and region', function () {
210-
const result = getLambdaEditFromNameRegion('func1', 'us-east-1')
211-
assert.strictEqual(result?.functionName, 'func1')
212-
assert.strictEqual(result?.region, 'us-east-1')
213-
})
214-
215-
it('returns undefined when not found', function () {
216-
const result = getLambdaEditFromNameRegion('nonexistent', 'us-east-1')
217-
assert.strictEqual(result, undefined)
218-
})
219-
})
220-
221-
describe('getLambdaEditFromLocation', function () {
222-
it('finds edit by location', function () {
223-
const result = getLambdaEditFromLocation('/tmp/func2')
224-
assert.strictEqual(result?.functionName, 'func2')
225-
assert.strictEqual(result?.location, '/tmp/func2')
226-
})
227-
228-
it('returns undefined when not found', function () {
229-
const result = getLambdaEditFromLocation('/tmp/nonexistent')
230-
assert.strictEqual(result, undefined)
231-
})
232-
})
233-
})
234187
})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Lambda upload from directory doesn't allow selection of directory"
4+
}

0 commit comments

Comments
 (0)