Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
Signed-off-by: Sajid Alam <sajid_alam@mckinsey.com>
  • Loading branch information
SajidAlamQB committed Jan 31, 2025
1 parent 67b1dc0 commit a916ec3
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/common/activationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
executeServerCommand,
executeServerDefinitionCommand,
setKedroProjectPath,
filterPipelines
} from './commands';

import * as vscode from 'vscode';
Expand Down Expand Up @@ -89,6 +90,7 @@ export const registerCommandsAndEvents = (
const CMD_DEFINITION_REQUEST = `${serverId}.sendDefinitionRequest`;
const CMD_SHOW_OUTPUT_CHANNEL = `${serverId}.showOutputChannel`;
const CMD_SET_PROJECT_PATH = `${serverId}.kedroProjectPath`;
const CMD_FILTER_PIPELINES = `${serverId}.filterPipelines`;

(async () => {
// Status Bar
Expand Down Expand Up @@ -162,6 +164,10 @@ export const registerCommandsAndEvents = (
registerCommand(CMD_SET_PROJECT_PATH, () => {
setKedroProjectPath();
}),
registerCommand(CMD_FILTER_PIPELINES, async () => {
const lsClient = getLSClient();
await filterPipelines(lsClient);
}),
);
})();
};
35 changes: 34 additions & 1 deletion src/common/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export async function executeGetProjectDataCommand(lsClient: LanguageClient | un
return;
}
if (!lsClient.initializeResult) {
await vscode.window.showErrorMessage('The Language Server fail to initialise.');
await vscode.window.showErrorMessage('The Language Server failed to initialize.');
return;
}

Expand All @@ -175,3 +175,36 @@ export async function executeGetProjectDataCommand(lsClient: LanguageClient | un
const result = await vscode.commands.executeCommand(commandName);
return result;
}

export async function filterPipelines(lsClient?: LanguageClient) {
try {
// 1) Fetch pipeline data
const projectData: any = await executeGetProjectDataCommand(lsClient);
console.log('Project Data:', projectData); // Add this line to log the project data
const pipelines = projectData?.pipelines || [];
if (!pipelines.length) {
vscode.window.showInformationMessage('No pipelines found in this Kedro project.');
return;
}

// 2) Show a QuickPick
const pipelineItems: QuickPickItem[] = pipelines.map((p: any) => ({ label: p.name }));
const picked = await vscode.window.showQuickPick(pipelineItems, {
placeHolder: 'Select a pipeline to filter...',
});
if (!picked) {
// User hit ESC or no selection
return;
}

// 3) Send the pipeline name to the webview
vscode.commands.executeCommand('kedro.viz.sendMessage', {
command: 'filterPipeline',
pipelineName: picked.label,
});
} catch (err) {
vscode.window.showErrorMessage(
`Error filtering pipelines: ${err instanceof Error ? err.message : String(err)}`
);
}
}
14 changes: 14 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
} from './common/utilities';

import { runServer, registerCommandsAndEvents } from './common/activationHelper';
import { filterPipelines } from './common/commands';
import KedroVizPanel from './webview/vizWebView';

let lsClient: LanguageClient | undefined;
let isCommandsAndEventsRegistered = false;
Expand Down Expand Up @@ -91,6 +93,18 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
isCommandsAndEventsRegistered = true;
}

context.subscriptions.push(
vscode.commands.registerCommand('kedro.viz.sendMessage', (message) => {
KedroVizPanel.sendMessage(message);
})
);

context.subscriptions.push(
vscode.commands.registerCommand('kedro.viz.sendMessage', (message) => {
KedroVizPanel.sendMessage(message);
})
);

setImmediate(async () => {
const interpreter = getInterpreterFromSetting(serverId);
if (interpreter === undefined || interpreter.length === 0) {
Expand Down
6 changes: 6 additions & 0 deletions src/webview/vizWebView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export default class KedroVizPanel {
KedroVizPanel.currentPanel = new KedroVizPanel(panel, extensionUri);
}

public static sendMessage(message: any) {
if (KedroVizPanel.currentPanel) {
KedroVizPanel.currentPanel._panel.webview.postMessage(message);
}
}

public static revive(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) {
KedroVizPanel.currentPanel = new KedroVizPanel(panel, extensionUri);
}
Expand Down
30 changes: 28 additions & 2 deletions webview/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,42 @@ function App() {
setError(true);
}
break;
case "filterPipeline":
if (message.pipelineName) {
console.log("Filtering pipeline:", message.pipelineName);
// Implement filtering logic here
const filteredData = filterDataByPipeline(data, message.pipelineName);
console.log("Filtered Data:", filteredData);
setData(filteredData);
}
break;
default:
break;
}
});

return () => {
window.removeEventListener("message", () => {console.log("removed")});
window.removeEventListener("message", () => { console.log("removed") });
};

}, []);
}, [data]);

const filterDataByPipeline = (data, pipelineName) => {
console.log("Original Data:", data);
// Implement the logic to filter the data based on the pipeline name
const filteredNodes = data.nodes.filter(node => node.pipelines.includes(pipelineName));
const filteredEdges = data.edges.filter(edge => {
const sourceNode = data.nodes.find(node => node.id === edge.source);
const targetNode = data.nodes.find(node => node.id === edge.target);
return sourceNode && targetNode && sourceNode.pipelines.includes(pipelineName) && targetNode.pipelines.includes(pipelineName);
});
console.log("Filtered Nodes:", filteredNodes);
console.log("Filtered Edges:", filteredEdges);
return {
nodes: filteredNodes,
edges: filteredEdges,
};
};

const handleNodeClick = (node) => {
if (node) {
Expand Down

0 comments on commit a916ec3

Please sign in to comment.