Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lambda): web-view functionality and fixes for serverless land #6687

Open
wants to merge 9 commits into
base: feature/serverlessland
Choose a base branch
from

Conversation

Vandita2020
Copy link
Contributor

@Vandita2020 Vandita2020 commented Feb 26, 2025

Problem

This PR adds the web view functionality for patterns. It addresses an issue with the metadata.json file path for the extension by specifying the path after the build step in the copyFile.ts file.

Solution


  • 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.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.
  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

@Vandita2020 Vandita2020 marked this pull request as ready for review February 26, 2025 22:38
@Vandita2020 Vandita2020 requested a review from a team as a code owner February 26, 2025 22:38
let createResult: Result = 'Succeeded'
let reason: string | undefined
let metadataManager: MetadataManager

try {
metadataManager = MetadataManager.getInstance()
// Launch the project creation wizard
const config = await launchProjectCreationWizard(extContext)
const config = await launchProjectCreationWizard(extContext, ctx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can just use globals.context instead of plumbing it through everywhere

@@ -32,14 +32,14 @@ export const templateToOpenAppComposer = 'aws.toolkit.appComposer.templateToOpen
* IMPORTANT: Views that should work in all vscode environments (node or web)
* should be setup in {@link activateViewsShared}.
*/
export async function activate(context: ExtContext): Promise<void> {
export async function activate(context: ExtContext, ctx: vscode.ExtensionContext): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context should already have this

@@ -36,15 +37,15 @@ const serverlessLandRepo = 'serverless-patterns'
* 5. Opens the README.md file if available
* 6. Handles errors and emits telemetry
*/
export async function createNewServerlessLandProject(extContext: ExtContext): Promise<void> {
export async function createNewServerlessLandProject(extContext: ExtContext, ctx: ExtensionContext): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extContext should already have this ctx

export class WebviewService {
constructor() {}

public static getWebviewContent(url: string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you help to add a scrnshot for webview?

@@ -142,6 +144,43 @@ export function createQuickPick<T>(
const mergedOptions = { ...defaultQuickpickOptions, ...options }
assign(mergedOptions, picker)
picker.buttons = mergedOptions.buttons ?? []
let serverlessPanel: vscode.WebviewPanel | undefined

picker.onDidTriggerItemButton(async (event) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider something like this to avoid these if/else indents

picker.onDidTriggerItemButton(async (event) => {
    const { button, item: selectedPattern } = event
    const metadataManager = MetadataManager.getInstance()

    // Early return if not handling GitHub or Serverless Land buttons
    if (!['Open in GitHub', 'Open in Serverless Land'].includes(button.tooltip)) {
        return
    }

    // Early return if no pattern is selected
    if (!selectedPattern) {
        return
    }

    const patternUrl = metadataManager.getUrl(selectedPattern.label)
    if (!patternUrl) {
        return
    }

    // Handle GitHub button click
    if (button.tooltip === 'Open in GitHub') {
        await vscode.env.openExternal(vscode.Uri.parse(patternUrl.githubUrl))
        return
    }

    // Handle Serverless Land button click
    if (!serverlessPanel) {
        serverlessPanel = createServerlessPanel(selectedPattern.label)
    } else {
        serverlessPanel.title = selectedPattern.label
    }

    serverlessPanel.webview.html = WebviewService.getWebviewContent(patternUrl.previewUrl)
    serverlessPanel.reveal()
})

@@ -1327,24 +1327,29 @@
"group": "1_account@3"
},
{
"command": "aws.lambda.createNewSamApp",
"command": "aws.toolkit.lambda.createServerlessLandProject",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why changing all these? Seem you just need to add an entry for "aws.toolkit.lambda.createServerlessLandProject"

'serverlessLand',
'metadata.json'
),
destination: path.join('src', 'serverlessLand', 'metadata.json'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it there a reason why we can't put this file directly in this destination?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants