diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ebe5d5..d786b5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to the "BigQuery Runner" extension will be documented in this file. +## v1.22.0 + +### Added + +- Add "Copy Table ID" and "Copy Field Name" to the context menu of the tree view. + - [#57](https://github.com/minodisk/bigquery-runner/issues/57) + ## v1.21.13 ### Changed diff --git a/README.md b/README.md index fed2e41..75f515b 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,14 @@ Run the query in BigQuery and save the results to a file in plain text Refresh the BigQuery Runner's Resources +### BigQuery Runner: Copy Table ID + +|ID| +|---| +|bigqueryRunner.copyTableId| + +Copy the selected table ID to the clipboard + ### BigQuery Runner: Preview Table in VS Code |ID| @@ -252,6 +260,14 @@ Preview the selected table in VS Code Preview the selected table in Google Cloud Console +### BigQuery Runner: Copy Field Name + +|ID| +|---| +|bigqueryRunner.copyFieldName| + +Copy the selected field name to the clipboard + ### BigQuery Runner: Clear Parameters |ID| diff --git a/package.json b/package.json index a98cf64..f1ccafc 100644 --- a/package.json +++ b/package.json @@ -145,6 +145,11 @@ "icon": "$(refresh)", "description": "Refresh the BigQuery Runner's Resources" }, + { + "command": "bigqueryRunner.copyTableId", + "title": "BigQuery Runner: Copy Table ID", + "description": "Copy the selected table ID to the clipboard" + }, { "command": "bigqueryRunner.previewTableInVSCode", "title": "BigQuery Runner: Preview Table in VS Code", @@ -155,6 +160,11 @@ "title": "BigQuery Runner: Preview Table on Remote", "description": "Preview the selected table in Google Cloud Console" }, + { + "command": "bigqueryRunner.copyFieldName", + "title": "BigQuery Runner: Copy Field Name", + "description": "Copy the selected field name to the clipboard" + }, { "command": "bigqueryRunner.clearParams", "title": "BigQuery Runner: Clear Parameters", @@ -200,6 +210,10 @@ } ], "view/item/context": [ + { + "command": "bigqueryRunner.copyTableId", + "when": "view == bigqueryRunner.resources && viewItem == table" + }, { "command": "bigqueryRunner.previewTableInVSCode", "when": "view == bigqueryRunner.resources && viewItem == table" @@ -207,6 +221,10 @@ { "command": "bigqueryRunner.previewTableOnRemote", "when": "view == bigqueryRunner.resources && viewItem == table" + }, + { + "command": "bigqueryRunner.copyFieldName", + "when": "view == bigqueryRunner.resources && viewItem == field" } ] }, diff --git a/packages/extension/src/index.ts b/packages/extension/src/index.ts index 27d0076..d10b4c5 100644 --- a/packages/extension/src/index.ts +++ b/packages/extension/src/index.ts @@ -31,7 +31,7 @@ import { createStatusBarItemCreator, createStatusManager, } from "./statusManager"; -import type { TableElement } from "./tree"; +import type { FieldElement, TableElement } from "./tree"; import { createTree } from "./tree"; import { showError, showInformation } from "./window"; @@ -187,12 +187,18 @@ export async function activate(ctx: ExtensionContext) { [`${section}.deleteSelectedResources`]: async () => { await tree.deleteSelectedResources(); }, + [`${section}.copyTableId`]: async (element: TableElement) => { + await tree.copyTableId(element); + }, [`${section}.previewTableInVSCode`]: async (element: TableElement) => { await tree.previewTableInVSCode(element); }, [`${section}.previewTableOnRemote`]: async (element: TableElement) => { await tree.previewTableOnRemote(element); }, + [`${section}.copyFieldName`]: async (element: FieldElement) => { + await tree.copyFieldName(element); + }, [`${section}.clearParams`]: async () => { if (!window.activeTextEditor) { throw new Error(`no active text editor`); diff --git a/packages/extension/src/tree.ts b/packages/extension/src/tree.ts index 1b03caf..d765943 100644 --- a/packages/extension/src/tree.ts +++ b/packages/extension/src/tree.ts @@ -9,6 +9,7 @@ import type { ProjectReference, TableReference, } from "shared"; +import { getTableName } from "shared"; import type { Disposable, TreeItem } from "vscode"; import { env, @@ -69,8 +70,10 @@ export const createTree = ({ }): Disposable & { refreshResources(): Promise; deleteSelectedResources(): Promise; + copyTableId(element: TableElement): Promise; previewTableInVSCode(element: TableElement): Promise; previewTableOnRemote(element: TableElement): Promise; + copyFieldName(element: FieldElement): Promise; } => { const clients = new Map(); const emitter = new EventEmitter(); @@ -263,6 +266,10 @@ export const createTree = ({ await this.refreshResources(); }, + async copyTableId(element: TableElement) { + await env.clipboard.writeText(getTableName(element.ref)); + }, + async previewTableInVSCode(element: TableElement) { await previewer.preview(element.ref); }, @@ -276,6 +283,10 @@ export const createTree = ({ ); }, + async copyFieldName(element: FieldElement) { + await env.clipboard.writeText(element.ref.fieldId); + }, + dispose() { clients.clear(); emitter.dispose();