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

Add commands to context in tree #57

Merged
merged 3 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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|
Expand Down
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -200,13 +210,21 @@
}
],
"view/item/context": [
{
"command": "bigqueryRunner.copyTableId",
"when": "view == bigqueryRunner.resources && viewItem == table"
},
{
"command": "bigqueryRunner.previewTableInVSCode",
"when": "view == bigqueryRunner.resources && viewItem == table"
},
{
"command": "bigqueryRunner.previewTableOnRemote",
"when": "view == bigqueryRunner.resources && viewItem == table"
},
{
"command": "bigqueryRunner.copyFieldName",
"when": "view == bigqueryRunner.resources && viewItem == field"
}
]
},
Expand Down
8 changes: 7 additions & 1 deletion packages/extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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`);
Expand Down
11 changes: 11 additions & 0 deletions packages/extension/src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
ProjectReference,
TableReference,
} from "shared";
import { getTableName } from "shared";
import type { Disposable, TreeItem } from "vscode";
import {
env,
Expand Down Expand Up @@ -69,8 +70,10 @@ export const createTree = ({
}): Disposable & {
refreshResources(): Promise<void>;
deleteSelectedResources(): Promise<void>;
copyTableId(element: TableElement): Promise<void>;
previewTableInVSCode(element: TableElement): Promise<void>;
previewTableOnRemote(element: TableElement): Promise<void>;
copyFieldName(element: FieldElement): Promise<void>;
} => {
const clients = new Map<ProjectID, Client>();
const emitter = new EventEmitter<null>();
Expand Down Expand Up @@ -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);
},
Expand All @@ -276,6 +283,10 @@ export const createTree = ({
);
},

async copyFieldName(element: FieldElement) {
await env.clipboard.writeText(element.ref.fieldId);
},

dispose() {
clients.clear();
emitter.dispose();
Expand Down
Loading