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 filtering of pipelines on Kedro-Viz flowchart in VSCode #167

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@
"command": "kedro.kedroProjectPath",
"title": "Set Project Path",
"category": "kedro"
},
{
"command": "kedro.filterPipelines",
"title": "Filter Pipelines",
"category": "kedro"
}
]
},
Expand Down
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);
}),
);
})();
};
42 changes: 41 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,43 @@ export async function executeGetProjectDataCommand(lsClient: LanguageClient | un
const result = await vscode.commands.executeCommand(commandName);
return result;
}

export async function filterPipelines(lsClient?: LanguageClient) {
try {
const projectData: any = await executeGetProjectDataCommand(lsClient);
console.log('Full projectData:', projectData);
const pipelineArray = projectData?.pipelines;
if (!pipelineArray || !Array.isArray(pipelineArray) || !pipelineArray.length) {
vscode.window.showInformationMessage('No pipelines found in this Kedro project.');
return;
}

const pipelineItems = pipelineArray.map((p: any) => {
return {
label: p.id,
description: p.name,
};
});

const picked = await vscode.window.showQuickPick(pipelineItems, {
placeHolder: 'Select a pipeline to filter...',
});
if (!picked) {
// user canceled the pick
return;
}

// Update the selected_pipeline property
projectData.selected_pipeline = picked.label;

// Send the updated projectData to the webview
vscode.commands.executeCommand('kedro.sendMessage', {
command: 'updateData',
data: projectData,
});
} catch (err) {
vscode.window.showErrorMessage(
`Error filtering pipelines: ${err instanceof Error ? err.message : String(err)}`,
);
}
}
8 changes: 8 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,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
isCommandsAndEventsRegistered = true;
}

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

setImmediate(async () => {
const interpreter = getInterpreterFromSetting(serverId);
if (interpreter === undefined || interpreter.length === 0) {
Expand Down
9 changes: 9 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 Expand Up @@ -77,6 +83,9 @@ export default class KedroVizPanel {
case 'showOutput':
await vscode.commands.executeCommand('kedro.showOutputChannel');
return;
case 'showPipelineFilter':
await vscode.commands.executeCommand('kedro.filterPipelines');
return;
}
},
null,
Expand Down
11 changes: 10 additions & 1 deletion webview/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function App() {
layerBtn: true,
expandPipelinesBtn: false,
exportBtn: false,
filterBtn: true,
};

useEffect(() => {
Expand All @@ -38,7 +39,6 @@ function App() {
return () => {
window.removeEventListener("message", () => {console.log("removed")});
};

}, []);

const handleNodeClick = (node) => {
Expand All @@ -53,6 +53,12 @@ function App() {
}
};

const handlePipelineFilterClick = () => {
vscodeApi.postMessage({
command: "showPipelineFilter",
});
};

const handleOutputClick = () => {
vscodeApi.postMessage({
command: "showOutput",
Expand Down Expand Up @@ -85,6 +91,9 @@ function App() {
switch (action.type) {
case "TOGGLE_NODE_CLICKED":
handleNodeClick(action.payload);
break;
case "SHOW_PIPELINE_FILTER":
handlePipelineFilterClick();
break;
default:
break;
Expand Down