Skip to content

Commit

Permalink
Merge pull request #389 from KxSystems/KXI-50022
Browse files Browse the repository at this point in the history
KXI-50022 - Add labels to the New Connection page
  • Loading branch information
Philip-Carneiro-KX authored Aug 2, 2024
2 parents 93e31ff + f61b160 commit fe0a5bb
Show file tree
Hide file tree
Showing 11 changed files with 731 additions and 27 deletions.
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"onCommand:kdb.newConnection.editInsightsConnection",
"onCommand:kdb.newConnection.editMyQConnection",
"onCommand:kdb.newConnection.editBundledConnection",
"onCommand:kdb.labels.create",
"onView:kdb-datasources-explorer",
"onTerminalProfile:kdb.q-terminal",
"onLanguage:python"
Expand Down Expand Up @@ -179,6 +180,18 @@
"description": "Connection map for workspace files",
"default": {},
"scope": "resource"
},
"kdb.connectionLabels": {
"type": "array",
"description": "List of label names and colorset",
"default": [],
"scope": "resource"
},
"kdb.labelsConnectionMap": {
"type": "array",
"description": "Labels connection map",
"default": [],
"scope": "resource"
}
}
},
Expand Down
24 changes: 23 additions & 1 deletion src/commands/serverCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { Telemetry } from "../utils/telemetryClient";
import { ConnectionManagementService } from "../services/connectionManagerService";
import { InsightsConnection } from "../classes/insightsConnection";
import { MetaContentProvider } from "../services/metaContentProvider";
import { handleLabelsConnMap } from "../utils/connLabel";

export async function addNewConnection(): Promise<void> {
NewConnectionPannel.close();
Expand All @@ -78,7 +79,10 @@ export async function editConnection(viewItem: KdbNode | InsightsNode) {
NewConnectionPannel.render(ext.context.extensionUri, viewItem);
}

export async function addInsightsConnection(insightsData: InsightDetails) {
export async function addInsightsConnection(
insightsData: InsightDetails,
labels?: string[],
) {
const aliasValidation = validateServerAlias(insightsData.alias, false);
if (aliasValidation) {
window.showErrorMessage(aliasValidation);
Expand Down Expand Up @@ -127,12 +131,16 @@ export async function addInsightsConnection(insightsData: InsightDetails) {
await updateInsights(insights);
const newInsights = getInsights();
if (newInsights != undefined) {
if (labels && labels.length > 0) {
handleLabelsConnMap(labels, insightsData.alias);
}
ext.serverProvider.refreshInsights(newInsights);
Telemetry.sendEvent("Connection.Created.Insights");
}
window.showInformationMessage(
`Added Insights connection: ${insightsData.alias}`,
);

NewConnectionPannel.close();
}
}
Expand All @@ -141,6 +149,7 @@ export async function addInsightsConnection(insightsData: InsightDetails) {
export async function editInsightsConnection(
insightsData: InsightDetails,
oldAlias: string,
labels?: string[],
) {
const aliasValidation =
oldAlias === insightsData.alias
Expand Down Expand Up @@ -207,12 +216,16 @@ export async function editInsightsConnection(

const newInsights = getInsights();
if (newInsights != undefined) {
if (labels && labels.length > 0) {
handleLabelsConnMap(labels, insightsData.alias);
}
ext.serverProvider.refreshInsights(newInsights);
Telemetry.sendEvent("Connection.Edited.Insights");
}
window.showInformationMessage(
`Edited Insights connection: ${insightsData.alias}`,
);

NewConnectionPannel.close();
}
}
Expand Down Expand Up @@ -301,6 +314,7 @@ export async function enableTLS(serverKey: string): Promise<void> {
export async function addKdbConnection(
kdbData: ServerDetails,
isLocal?: boolean,
labels?: string[],
): Promise<void> {
const aliasValidation = validateServerAlias(kdbData.serverAlias, isLocal!);
const hostnameValidation = validateServerName(kdbData.serverName);
Expand Down Expand Up @@ -359,6 +373,9 @@ export async function addKdbConnection(
await updateServers(servers);
const newServers = getServers();
if (newServers != undefined) {
if (labels && labels.length > 0) {
handleLabelsConnMap(labels, kdbData.serverAlias);
}
Telemetry.sendEvent("Connection.Created.QProcess");
ext.serverProvider.refresh(newServers);
}
Expand All @@ -368,6 +385,7 @@ export async function addKdbConnection(
window.showInformationMessage(
`Added kdb connection: ${kdbData.serverAlias}`,
);

NewConnectionPannel.close();
}
}
Expand All @@ -378,6 +396,7 @@ export async function editKdbConnection(
oldAlias: string,
isLocal?: boolean,
editAuth?: boolean,
labels?: string[],
) {
const aliasValidation =
oldAlias === kdbData.serverAlias
Expand Down Expand Up @@ -455,6 +474,9 @@ export async function editKdbConnection(
}
const newServers = getServers();
if (newServers != undefined) {
if (labels && labels.length > 0) {
handleLabelsConnMap(labels, kdbData.serverAlias);
}
ext.serverProvider.refresh(newServers);
Telemetry.sendEvent("Connection.Edited.KDB");
}
Expand Down
54 changes: 42 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ import { connectBuildTools, lintCommand } from "./commands/buildToolsCommand";
import { CompletionProvider } from "./services/completionProvider";
import { QuickFixProvider } from "./services/quickFixProvider";
import { connectClientCommands } from "./commands/clientCommands";
import {
createNewLabel,
getWorkspaceLabels,
getWorkspaceLabelsConnMap,
} from "./utils/connLabel";

let client: LanguageClient;

Expand All @@ -112,6 +117,10 @@ export async function activate(context: ExtensionContext) {
ext.outputChannel = window.createOutputChannel("kdb");
ext.openSslVersion = await checkOpenSslInstalled();
ext.isBundleQCreated = false;

getWorkspaceLabelsConnMap();
getWorkspaceLabels();

// clear necessary contexts
commands.executeCommand("setContext", "kdb.connected.active", false);
commands.executeCommand("setContext", "kdb.insightsConnected", false);
Expand Down Expand Up @@ -266,38 +275,53 @@ export async function activate(context: ExtensionContext) {
),
commands.registerCommand(
"kdb.newConnection.createNewInsightConnection",
async (insightsData: InsightDetails) => {
await addInsightsConnection(insightsData);
async (insightsData: InsightDetails, labels: string[]) => {
await addInsightsConnection(insightsData, labels);
},
),
commands.registerCommand(
"kdb.newConnection.createNewConnection",
async (kdbData: ServerDetails) => {
await addKdbConnection(kdbData, false);
async (kdbData: ServerDetails, labels: string[]) => {
await addKdbConnection(kdbData, false, labels);
},
),
commands.registerCommand(
"kdb.newConnection.createNewBundledConnection",
async (kdbData: ServerDetails) => {
await addKdbConnection(kdbData, true);
async (kdbData: ServerDetails, labels: string[]) => {
await addKdbConnection(kdbData, true, labels);
},
),
commands.registerCommand(
"kdb.newConnection.editInsightsConnection",
async (insightsData: InsightDetails, oldAlias: string) => {
await editInsightsConnection(insightsData, oldAlias);
async (
insightsData: InsightDetails,
oldAlias: string,
labels: string[],
) => {
await editInsightsConnection(insightsData, oldAlias, labels);
},
),
commands.registerCommand(
"kdb.newConnection.editMyQConnection",
async (kdbData: ServerDetails, oldAlias: string, editAuth: boolean) => {
await editKdbConnection(kdbData, oldAlias, false, editAuth);
async (
kdbData: ServerDetails,
oldAlias: string,
editAuth: boolean,
labels: string[],
) => {
await editKdbConnection(kdbData, oldAlias, false, editAuth, labels);
},
),
commands.registerCommand(
"kdb.newConnection.editBundledConnection",
async (kdbData: ServerDetails, oldAlias: string) => {
await editKdbConnection(kdbData, oldAlias, true);
async (kdbData: ServerDetails, oldAlias: string, labels: string[]) => {
await editKdbConnection(kdbData, oldAlias, true, false, labels);
},
),
commands.registerCommand(
"kdb.labels.create",
async (name: string, colorName: string) => {
await createNewLabel(name, colorName);
},
),
commands.registerCommand(
Expand Down Expand Up @@ -475,6 +499,12 @@ export async function activate(context: ExtensionContext) {
ext.dataSourceTreeProvider.reload();
ext.scratchpadTreeProvider.reload();
}
if (event.affectsConfiguration("kdb.connectionLabelsMap")) {
ext.serverProvider.reload();
}
if (event.affectsConfiguration("kdb.connectionLabels")) {
ext.serverProvider.reload();
}
}),
);

Expand Down
34 changes: 34 additions & 0 deletions src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { ScratchpadFile } from "./models/scratchpad";
import { LocalConnection } from "./classes/localConnection";
import { InsightsConnection } from "./classes/insightsConnection";
import { DataSourceFiles } from "./models/dataSource";
import { ConnectionLabel, LabelColors, Labels } from "./models/labels";

// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace ext {
Expand Down Expand Up @@ -84,6 +85,8 @@ export namespace ext {
export const kdbNodesWithoutAuth: string[] = [];
export const kdbNodesWithoutTls: string[] = [];
export const kdbConnectionAliasList: string[] = [];
export const connLabelList: Labels[] = [];
export const labelConnMapList: ConnectionLabel[] = [];
export const maxRetryCount = 5;

export let secretSettings: AuthSettings;
Expand Down Expand Up @@ -306,4 +309,35 @@ export namespace ext {

export const diagnosticCollection =
languages.createDiagnosticCollection("kdb");

export const labelColors: LabelColors[] = [
{
name: "White",
colorHex: "#FFFFFF",
},
{
name: "Red",
colorHex: "#CD3131",
},
{
name: "Green",
colorHex: "#10BC7A",
},
{
name: "Yellow",
colorHex: "#E5E50E",
},
{
name: "Blue",
colorHex: "#2371C8",
},
{
name: "Magenta",
colorHex: "#BC3FBC",
},
{
name: "Cyan",
colorHex: "#15A7CD",
},
];
}
27 changes: 27 additions & 0 deletions src/models/labels.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 1998-2023 Kx Systems Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

export type LabelColors = {
name: string;
colorHex: string;
};

export type Labels = {
name: string;
color: LabelColors;
};

export type ConnectionLabel = {
labelName: string;
connections: string[];
};
Loading

0 comments on commit fe0a5bb

Please sign in to comment.