diff --git a/package.json b/package.json index 1c64313..e2cd115 100644 --- a/package.json +++ b/package.json @@ -555,6 +555,11 @@ "command": "vscode-appwrite.openFunctionSettingsInBrowser", "when": "viewItem =~ /^functionSettings$/", "group": "inline" + }, + { + "command": "vscode-appwrite.CreateTag", + "when": "viewItem =~ /^tags$/", + "group": "inline" } ], "explorer/context": [ diff --git a/src/commands/functions/createTag.ts b/src/commands/functions/createTag.ts index c44888e..5b28d45 100644 --- a/src/commands/functions/createTag.ts +++ b/src/commands/functions/createTag.ts @@ -1,10 +1,29 @@ -import { Uri } from "vscode"; +import { ProgressLocation, Uri, window } from "vscode"; import { functionsClient, storageClient } from "../../client"; import { getTarReadStream } from "../../utils/tar"; import { ext } from "../../extensionVariables"; import * as fs from "fs"; -export async function createTag(folder: Uri): Promise { - const tarFilePath = await getTarReadStream(folder); +import { TagsTreeItem } from "../../tree/functions/tags/TagsTreeItem"; +import { selectWorkspaceFolder } from "../../utils/workspace"; +export async function createTag(item: TagsTreeItem | Uri): Promise { + if (item instanceof Uri) { + window.withProgress({ location: ProgressLocation.Notification, title: "Creating tag..." }, async (progress, token) => { + await createTagFromUri(item); + }); + return; + } + + if (item instanceof TagsTreeItem) { + const folder = await selectWorkspaceFolder("Select folder of your function code."); + console.log(folder); + window.withProgress({ location: ProgressLocation.Notification, title: "Creating tag..." }, async (progress, token) => { + await createTagFromUri(Uri.parse(folder)); + }); + } +} + +async function createTagFromUri(uri: Uri): Promise { + const tarFilePath = await getTarReadStream(uri); if (functionsClient === undefined) { return; } diff --git a/src/tree/functions/tags/TagTreeItem.ts b/src/tree/functions/tags/TagTreeItem.ts index 5e4c821..2a468fa 100644 --- a/src/tree/functions/tags/TagTreeItem.ts +++ b/src/tree/functions/tags/TagTreeItem.ts @@ -1,5 +1,6 @@ -import { ThemeIcon, TreeItem } from "vscode"; +import { MarkdownString, ThemeIcon, TreeItem } from "vscode"; import { Tag } from '../../../appwrite'; +import { msToDate } from '../../../utils/date'; import { TagsTreeItem } from './TagsTreeItem'; export class TagTreeItem extends TreeItem { @@ -7,8 +8,10 @@ export class TagTreeItem extends TreeItem { super(tag.$id); const func = parent.parent.func; const active = func.tag === tag.$id; - this.label = `${tag.$id}${active ? ' (Active)' : ''}`; + this.label = `${msToDate(tag.dateCreated)}${active ? ' (Active)' : ''}`; + this.description = tag.$id; this.iconPath = new ThemeIcon(active ? 'circle-filled' : 'circle-outline'); this.contextValue = `tag${active ? '_active' : ''}`; + this.tooltip = new MarkdownString(`ID: ${tag.$id} \nCreated: ${msToDate(tag.dateCreated)} \nCommand: ${tag.command} \nSize: ${tag.size}B`); } } diff --git a/src/utils/workspace.ts b/src/utils/workspace.ts new file mode 100644 index 0000000..27f5dd8 --- /dev/null +++ b/src/utils/workspace.ts @@ -0,0 +1,84 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as path from "path"; +import * as vscode from "vscode"; +import { QuickPickItem } from 'vscode'; + +export interface IAzureQuickPickItem extends QuickPickItem { + /** + * An optional id to uniquely identify this item across sessions, used in persisting previous selections + * If not specified, a hash of the label will be used + */ + id?: string; + + data: T; + + /** + * Callback to use when this item is picked, instead of returning the pick + * Only applies when used as part of an `AzureWizard` + * This is not compatible with `canPickMany` + */ + onPicked?: () => void | Promise; + + /** + * The group that this pick belongs to. Set `IAzureQuickPickOptions.enableGrouping` for this property to take effect + * Only applies when used as part of an `AzureWizard` + */ + group?: string; + + /** + * Optionally used to suppress persistence for this item, defaults to `false` + */ + suppressPersistence?: boolean; +} + + +export async function selectWorkspaceFolder(placeHolder: string): Promise { + return await selectWorkspaceItem(placeHolder, { + canSelectFiles: false, + canSelectFolders: true, + canSelectMany: false, + defaultUri: + vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0 + ? vscode.workspace.workspaceFolders[0].uri + : undefined, + openLabel: "Select", + }); +} + +export async function selectWorkspaceFile(placeHolder: string, fileExtensions?: string[]): Promise { + const filters: { [name: string]: string[] } = {}; + if (fileExtensions) { + filters.Artifacts = fileExtensions; + } + return await selectWorkspaceItem(placeHolder, { + canSelectFiles: true, + canSelectFolders: false, + canSelectMany: false, + openLabel: "Select", + filters: filters, + }); +} + +export async function selectWorkspaceItem(placeHolder: string, options: vscode.OpenDialogOptions): Promise { + let folder: IAzureQuickPickItem | undefined; + if (vscode.workspace.workspaceFolders) { + const folderPicks: IAzureQuickPickItem[] = await Promise.all( + vscode.workspace.workspaceFolders.map((f: vscode.WorkspaceFolder) => { + return { label: path.basename(f.uri.fsPath), description: f.uri.fsPath, data: f.uri.fsPath }; + }) + ); + + folderPicks.push({ label: "$(file-directory) Browse...", description: "", data: undefined }); + folder = await vscode.window.showQuickPick(folderPicks, { placeHolder }); + } + + if (folder?.data) { + return folder.data; + } else { + return (await vscode.window.showOpenDialog(options))?.[0].fsPath ?? ''; + } +}