Skip to content

Commit

Permalink
feat: add show all projects in graph command (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless authored Nov 22, 2022
1 parent bd59c56 commit 2871066
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
13 changes: 12 additions & 1 deletion apps/vscode/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@
}
],
"view/title": [
{
"command": "nx.graph.showAll",
"when": "view == nxProjects",
"group": "navigation@0"
},
{
"command": "nxConsole.refreshWorkspace",
"when": "view == nxProjects",
"group": "navigation"
"group": "navigation@1"
},
{
"command": "nxConsole.refreshWorkspace",
Expand Down Expand Up @@ -548,6 +553,12 @@
"command": "nx.graph.select.button",
"icon": "$(eye)"
},
{
"category": "Nx",
"title": "Show full project graph",
"command": "nx.graph.showAll",
"icon": "$(source-control)"
},
{
"category": "Nx",
"title": "run-many",
Expand Down
1 change: 1 addition & 0 deletions libs/vscode/project-graph/src/lib/graph-message-type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export const enum MessageType {
focus = 'FOCUS',
select = 'SELECT',
all = 'ALL',
}
19 changes: 18 additions & 1 deletion libs/vscode/project-graph/src/lib/graph-webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class GraphWebView implements Disposable {
graphService.send('GET_CONTENT');
}

async projectInWebview(projectName: string | undefined, type: MessageType) {
projectInWebview(projectName: string | undefined, type: MessageType) {
getOutputChannel().appendLine(`Graph - Opening graph for ${projectName}`);
if (!this.panel) {
this._webview();
Expand All @@ -95,6 +95,23 @@ export class GraphWebView implements Disposable {
});
}

showAllProjects() {
getOutputChannel().appendLine(`Graph - Opening full graph`);

if (!this.panel) {
this._webview();
}

this.panel?.reveal();

graphService.send('PROJECT_SELECTED', {
data: {
type: MessageType.all,
projectName: '',
},
});
}

refresh() {
graphService.send('REFRESH');
}
Expand Down
11 changes: 10 additions & 1 deletion libs/vscode/project-graph/src/lib/load-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ function injectedScript() {
function waitForAndClickOnElement(data) {
function clickOnElement() {
if(data.type === "${MessageType.all}") {
const allProjectsElement = document.querySelector(\`[data-cy="selectAllButton"]\`);
if(allProjectsElement) {
allProjectsElement.click();
return true;
} else {
return false;
}
}
const projectElement = document.querySelector(\`[data-project="\${data.projectName}"]\`);
if(projectElement) {
if (data.type === "${MessageType.focus}") {
Expand Down Expand Up @@ -271,7 +280,7 @@ function injectedScript() {
//noop
}
waitForAndClickOnElement(data);
setTimeout(() => waitForAndClickOnElement(data), 0);
})
}())
`;
Expand Down
4 changes: 4 additions & 0 deletions libs/vscode/project-graph/src/lib/project-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export function projectGraph() {
getTelemetry().featureUsed('nx.graph.refresh');
graphWebView.refresh();
}),
commands.registerCommand('nx.graph.showAll', () => {
getTelemetry().featureUsed('nx.graph.showAll');
graphWebView.showAllProjects();
}),
commands.registerCommand('nx.graph.focus', async (uri: Uri | undefined) => {
getTelemetry().featureUsed('nx.graph.focus');
await openProjectWithFile(graphWebView, uri, MessageType.focus);
Expand Down

0 comments on commit 2871066

Please sign in to comment.