Skip to content

Commit

Permalink
change SVG icon and add settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lokesh-couchbase committed May 28, 2024
1 parent a7340da commit 516221a
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 145 deletions.
6 changes: 6 additions & 0 deletions images/dark/named-parameters.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions images/light/named-parameters.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 32 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,16 @@
"command": "vscode-couchbase.showNamedParameters",
"category": "Couchbase",
"icon": {
"light": "images/light/favorites-list.svg",
"dark": "images/dark/favorites-list.svg"
"light": "images/light/named-parameters.svg",
"dark": "images/dark/named-parameters.svg"
}
},
{
"title": "Refresh Named Parameters List",
"command": "vscode-couchbase.refreshNamedParameters",
"category": "Couchbase",
"icon": "$(refresh)"
},
{
"title": "Apply Query History",
"command": "vscode-couchbase.applyQueryHistory",
Expand Down Expand Up @@ -675,6 +681,12 @@
"title": "Show iQ settings",
"category": "Couchbase",
"icon": "$(gear)"
},
{
"command": "vscode-couchbase.workbench.showSettings",
"title": "Show Workbench settings",
"category": "Couchbase",
"icon": "$(gear)"
}
],
"keybindings": [
Expand Down Expand Up @@ -727,6 +739,20 @@
"category": "Couchbase",
"group": "navigation",
"when": "activeWebviewPanelId == clusterOverview"
},
{
"title": "Refresh Named Parameters List",
"command": "vscode-couchbase.refreshNamedParameters",
"category": "Couchbase",
"group": "navigation@2",
"when": "activeWebviewPanelId == showNamedParameters"
},
{
"title": "Show Named Parameters List",
"command": "vscode-couchbase.workbench.showSettings",
"category": "Couchbase",
"group": "navigation@1",
"when": "activeWebviewPanelId == showNamedParameters"
}
],
"editor/context": [
Expand Down Expand Up @@ -891,6 +917,10 @@
{
"command": "vscode-couchbase.iq.showSettings",
"when": "false"
},
{
"command": "vscode-couchbase.workbench.showSettings",
"when": "false"
}
],
"view/item/context": [
Expand Down
2 changes: 2 additions & 0 deletions src/commands/extensionCommands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export namespace Commands {
export const showFavoriteQueries: string = "vscode-couchbase.showFavoriteQueries";
export const markFavoriteQuery: string = "vscode-couchbase.markFavoriteQuery";
export const showNamedParameters: string = "vscode-couchbase.showNamedParameters";
export const refreshNamedParameters: string = "vscode-couchbase.refreshNamedParameters";
export const applyQueryHistory: string = "vscode-couchbase.applyQueryHistory";
export const deleteQueryHistoryItem: string = "vscode-couchbase.deleteQueryHistoryItem";
export const copyQueryHistoryItem: string = "vscode-couchbase.copyQueryHistoryItem";
Expand All @@ -65,5 +66,6 @@ export namespace Commands {
export const couchbaseIqViewsCommand: string = "couchbase-iq";
export const logoutIq: string = "vscode-couchbase.iq.logout";
export const showIqSettings: string = "vscode-couchbase.iq.showSettings";
export const showWorkbenchSettings: string = "vscode-couchbase.workbench.showSettings";
export const newIqChat: string = "vscode-couchbase.iq.newChat";
}
19 changes: 18 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ export function activate(context: vscode.ExtensionContext) {
)
);

subscriptions.push(
vscode.commands.registerCommand(
Commands.showWorkbenchSettings,
() => {
vscode.commands.executeCommand('workbench.action.openSettings', "couchbase.workbench");
}
)
);

subscriptions.push(
vscode.window.onDidChangeActiveTextEditor(async (editor) => {
Expand Down Expand Up @@ -601,7 +609,16 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand(
Commands.showNamedParameters,
() => {
fetchNamedParameters(context);
fetchNamedParameters();
}
)
);

subscriptions.push(
vscode.commands.registerCommand(
Commands.refreshNamedParameters,
() => {
fetchNamedParameters(true);
}
)
);
Expand Down
17 changes: 12 additions & 5 deletions src/pages/namedParameters/namedParameters.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import * as vscode from 'vscode';
import { logger } from '../../logger/logger';
import { showNamedParameters } from '../../webViews/namedParameters.webview';
import { applyQuery } from '../../commands/queryHistory/applyQuery';
import { Memory, getUUID } from '../../util/util';
import { IConnection } from '../../types/IConnection';
import { Memory } from '../../util/util';
import { Constants } from '../../util/constants';

export interface INamedParametersWebviewState {
webviewPanel: vscode.WebviewPanel
}

export const fetchNamedParameters = (context: vscode.ExtensionContext) => {
export const fetchNamedParameters = (isRefresh:boolean = false) => {
const namedParametersWebviewDetails = Memory.state.get<INamedParametersWebviewState>(Constants.NAMED_PARAMETERS_WEBVIEW);
if (namedParametersWebviewDetails) {
if(isRefresh){
namedParametersWebviewDetails.webviewPanel.webview.html = showNamedParameters();
return;
}
// Named Parameters Webview already exists, Closing existing and creating new
namedParametersWebviewDetails.webviewPanel.dispose();
Memory.state.update(Constants.NAMED_PARAMETERS_WEBVIEW, null);
}

const currentPanel = vscode.window.createWebviewPanel(
"showNamedParameters",
"Named Parameters",
Expand All @@ -31,8 +34,12 @@ export const fetchNamedParameters = (context: vscode.ExtensionContext) => {
try {
currentPanel.webview.html = showNamedParameters();
currentPanel.webview.onDidReceiveMessage(async (message) => {
switch (message.command) {
if (message.command === "openSettings") {
vscode.commands.executeCommand('workbench.action.openSettings', "couchbase.workbench");
} else {
console.debug("Unhandled Message received from named parameters webview", message);
}

});

currentPanel.onDidDispose(() => {
Expand Down
1 change: 0 additions & 1 deletion src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export class Constants {
public static connectionKeys = "clusterConnections";
public static QUERY_HISTORY = "cluster.queryHistory";
public static FAVORITE_QUERY = "cluster.favoriteQueries";
public static NAMED_PARAMETER = "cluster.namedParameters";
public static ACTIVE_CONNECTION = "activeConnection";
public static FAVORITE_QUERIES_WEBVIEW = "favoriteQueriesWebview";
public static NAMED_PARAMETERS_WEBVIEW = "namedParametersWebview";
Expand Down
25 changes: 20 additions & 5 deletions src/util/namedParameters.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { fetchNamedParameters } from "../pages/namedParameters/namedParameters";
import { IKeyValuePair } from "../types/IKeyValuePair";
import { Constants } from "./constants";
import { Global } from "./util";
import * as vscode from "vscode";
const fs = require('fs');
const path = require('path');
import fs from 'fs';
import path from 'path';

export function getUsersNamedParameters(): IKeyValuePair[] {
try {
Expand Down Expand Up @@ -45,3 +42,21 @@ export function getProjectsNamedParameters(): IKeyValuePair[] {
return [];
}
}

export function getAllNamedParameters(): {[key: string]: any} {
const userNamedParameters = getUsersNamedParameters();
const projectNamedParameters = getProjectsNamedParameters();

// if any parameter is repeated, then the user's parameter will be used
let allNamedParameters: {[key: string]: any} = {};

for (let parameter of projectNamedParameters) {
allNamedParameters[parameter.key] = parameter.value;
}

for (let parameter of userNamedParameters) {
allNamedParameters[parameter.key] = parameter.value;
}

return allNamedParameters;
}
2 changes: 1 addition & 1 deletion src/webViews/favoriteQueries.webiew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const showFavoriteQueries = (): string => {
}
.favorite-queries-table {
min-height: 150px;
min-height: 200px;
display: flex;
justify-content: space-between;
width: 100%;
Expand Down
Loading

0 comments on commit 516221a

Please sign in to comment.