From 2be9a0127298e7fbdc13544d24b78659dc430f47 Mon Sep 17 00:00:00 2001 From: Philip Fulcher Date: Wed, 9 Nov 2022 16:58:28 -0700 Subject: [PATCH] chore(graph): consume task graph data in client (#13092) --- .gitignore | 3 +- graph/client-e2e/src/e2e/app.cy.ts | 16 +- .../src/release-integration/release.cy.ts | 2 +- graph/client/project.json | 17 +- .../panels}/collapse-edges-panel.stories.tsx | 0 .../panels}/collapse-edges-panel.tsx | 0 .../panels}/focused-project-panel.stories.tsx | 0 .../panels}/focused-project-panel.tsx | 0 .../panels}/group-by-folder-panel.stories.tsx | 0 .../panels}/group-by-folder-panel.tsx | 0 .../panels}/rankdir-panel.stories.tsx | 0 .../panels}/rankdir-panel.tsx | 2 +- .../panels}/search-depth.stories.tsx | 0 .../panels}/search-depth.tsx | 0 .../panels}/show-hide-projects.stories.tsx | 0 .../panels}/show-hide-projects.tsx | 0 .../panels}/text-filter-panel.stories.tsx | 0 .../panels}/text-filter-panel.tsx | 4 +- .../panels}/theme-panel.stories.tsx | 0 .../panels}/theme-panel.tsx | 6 +- .../panels}/tracing-panel.stories.tsx | 0 .../panels}/tracing-panel.tsx | 2 +- .../project-list.tsx | 0 .../app/feature-projects/projects-sidebar.tsx | 16 +- .../task-list.stories.tsx | 0 .../{sidebar => feature-tasks}/task-list.tsx | 14 +- .../src/app/feature-tasks/tasks-sidebar.tsx | 77 +- .../src/app/fetch-project-graph-service.ts | 13 +- .../src/app/hooks/use-task-graph-selector.ts | 15 + graph/client/src/app/interfaces.ts | 15 +- .../src/app/local-project-graph-service.ts | 9 +- graph/client/src/app/machines/app.machine.ts | 155 ++++ .../src/app/machines/dep-graph.service.ts | 15 - .../client/src/app/machines/dep-graph.spec.ts | 180 +++-- graph/client/src/app/machines/externalApi.ts | 4 +- graph/client/src/app/machines/get-services.ts | 25 + graph/client/src/app/machines/interfaces.ts | 37 +- ...ph.machine.ts => project-graph.machine.ts} | 28 +- .../src/app/machines/route-listener.actor.ts | 10 +- .../src/app/machines/route-setter.machine.ts | 22 +- .../src/app/machines/task-graph.machine.ts | 75 ++ .../src/app/mock-project-graph-service.ts | 29 +- graph/client/src/app/routes.tsx | 2 +- graph/client/src/app/shell.tsx | 95 ++- graph/client/src/app/state.provider.tsx | 10 +- .../debugger-panel.stories.tsx | 2 +- .../{ => ui-components}/debugger-panel.tsx | 24 +- .../edge-tooltip.stories.tsx | 2 +- .../app/{ => ui-tooltips}/edge-tooltip.tsx | 2 +- .../app/ui-tooltips/graph-tooltip-display.tsx | 35 + .../project-node-tooltip.stories.tsx | 0 .../project-node-tooltip.tsx | 6 +- .../app/{ => ui-tooltips}/tooltip-service.ts | 2 +- .../client/src/assets/dev-e2e/environment.js | 10 +- .../src/assets/nx-console/environment.js | 7 +- .../{graphs => project-graphs}/affected.json | 0 .../collapsing-edges-testing.json | 0 .../{graphs => project-graphs}/e2e.json | 0 .../focus-testing.json | 0 .../nested-workspace-layout.json | 0 .../{graphs => project-graphs}/sub-apps.json | 0 .../src/assets/release-static/environment.js | 7 +- .../client/src/assets/release/environment.js | 7 +- graph/client/src/assets/watch/environment.js | 7 +- graph/client/src/globals.d.ts | 6 +- graph/ui-graph/src/lib/graph.ts | 695 ++---------------- .../util-cytoscape/project-traversal-graph.ts | 340 +++++++++ .../src/lib/util-cytoscape/render-graph.ts | 336 +++++++++ package.json | 8 +- packages/nx/src/command-line/dep-graph.ts | 7 +- scripts/generate-graph-environment.ts | 33 +- scripts/generate-graph.ts | 25 +- yarn.lock | 47 +- 73 files changed, 1490 insertions(+), 1016 deletions(-) rename graph/client/src/app/{sidebar => feature-projects/panels}/collapse-edges-panel.stories.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/collapse-edges-panel.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/focused-project-panel.stories.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/focused-project-panel.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/group-by-folder-panel.stories.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/group-by-folder-panel.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/rankdir-panel.stories.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/rankdir-panel.tsx (97%) rename graph/client/src/app/{sidebar => feature-projects/panels}/search-depth.stories.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/search-depth.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/show-hide-projects.stories.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/show-hide-projects.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/text-filter-panel.stories.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/text-filter-panel.tsx (93%) rename graph/client/src/app/{sidebar => feature-projects/panels}/theme-panel.stories.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/theme-panel.tsx (97%) rename graph/client/src/app/{sidebar => feature-projects/panels}/tracing-panel.stories.tsx (100%) rename graph/client/src/app/{sidebar => feature-projects/panels}/tracing-panel.tsx (98%) rename graph/client/src/app/{sidebar => feature-projects}/project-list.tsx (100%) rename graph/client/src/app/{sidebar => feature-tasks}/task-list.stories.tsx (100%) rename graph/client/src/app/{sidebar => feature-tasks}/task-list.tsx (93%) create mode 100644 graph/client/src/app/hooks/use-task-graph-selector.ts create mode 100644 graph/client/src/app/machines/app.machine.ts delete mode 100644 graph/client/src/app/machines/dep-graph.service.ts create mode 100644 graph/client/src/app/machines/get-services.ts rename graph/client/src/app/machines/{dep-graph.machine.ts => project-graph.machine.ts} (95%) create mode 100644 graph/client/src/app/machines/task-graph.machine.ts rename graph/client/src/app/{ => ui-components}/debugger-panel.stories.tsx (92%) rename graph/client/src/app/{ => ui-components}/debugger-panel.tsx (69%) rename graph/client/src/app/{ => ui-tooltips}/edge-tooltip.stories.tsx (92%) rename graph/client/src/app/{ => ui-tooltips}/edge-tooltip.tsx (97%) create mode 100644 graph/client/src/app/ui-tooltips/graph-tooltip-display.tsx rename graph/client/src/app/{ => ui-tooltips}/project-node-tooltip.stories.tsx (100%) rename graph/client/src/app/{ => ui-tooltips}/project-node-tooltip.tsx (90%) rename graph/client/src/app/{ => ui-tooltips}/tooltip-service.ts (97%) rename graph/client/src/assets/{graphs => project-graphs}/affected.json (100%) rename graph/client/src/assets/{graphs => project-graphs}/collapsing-edges-testing.json (100%) rename graph/client/src/assets/{graphs => project-graphs}/e2e.json (100%) rename graph/client/src/assets/{graphs => project-graphs}/focus-testing.json (100%) rename graph/client/src/assets/{graphs => project-graphs}/nested-workspace-layout.json (100%) rename graph/client/src/assets/{graphs => project-graphs}/sub-apps.json (100%) create mode 100644 graph/ui-graph/src/lib/util-cytoscape/project-traversal-graph.ts create mode 100644 graph/ui-graph/src/lib/util-cytoscape/render-graph.ts diff --git a/.gitignore b/.gitignore index 4c15a2a836..7772e9a465 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,8 @@ jest.debug.config.js /.verdaccio/build/local-registry /graph/client/src/assets/environment.js /graph/client/src/assets/dev/environment.js -/graph/client/src/assets/generated-graphs +/graph/client/src/assets/generated-project-graphs +/graph/client/src/assets/generated-task-graphs /nx-dev/nx-dev/public/documentation /nx-dev/nx-dev/public/images/open-graph # Lerna creates this diff --git a/graph/client-e2e/src/e2e/app.cy.ts b/graph/client-e2e/src/e2e/app.cy.ts index f36588ccf6..6032d538f5 100644 --- a/graph/client-e2e/src/e2e/app.cy.ts +++ b/graph/client-e2e/src/e2e/app.cy.ts @@ -23,9 +23,9 @@ import * as nxExamplesJson from '../fixtures/nx-examples.json'; describe('graph-client', () => { before(() => { - cy.intercept('/assets/graphs/e2e.json', { fixture: 'nx-examples.json' }).as( - 'getGraph' - ); + cy.intercept('/assets/project-graphs/e2e.json', { + fixture: 'nx-examples.json', + }).as('getGraph'); cy.visit('/'); // wait for initial graph to finish loading @@ -140,7 +140,7 @@ describe('graph-client', () => { }); it('should check all affected project items', () => { - cy.intercept('/assets/graphs/affected.json', { + cy.intercept('/assets/project-graphs/affected.json', { fixture: 'affected.json', }).as('getAffectedGraph'); @@ -155,7 +155,7 @@ describe('graph-client', () => { ); // switch back to Nx Examples graph before proceeding - cy.intercept('/assets/graphs/e2e.json', { + cy.intercept('/assets/project-graphs/e2e.json', { fixture: 'nx-examples.json', }).as('getGraph'); cy.get('[data-cy=project-select]').select('e2e', { force: true }); @@ -308,9 +308,9 @@ describe('graph-client', () => { describe('loading graph client with url params', () => { beforeEach(() => { - cy.intercept('/assets/graphs/*', { fixture: 'nx-examples.json' }).as( - 'getGraph' - ); + cy.intercept('/assets/project-graphs/*', { + fixture: 'nx-examples.json', + }).as('getGraph'); }); // check that params work from old base url of / diff --git a/graph/client-e2e/src/release-integration/release.cy.ts b/graph/client-e2e/src/release-integration/release.cy.ts index ce16ef8d6e..db19b3b16a 100644 --- a/graph/client-e2e/src/release-integration/release.cy.ts +++ b/graph/client-e2e/src/release-integration/release.cy.ts @@ -1,6 +1,6 @@ describe('graph-client release', () => { beforeEach(() => { - cy.intercept('/assets/graphs/*').as('getGraph'); + cy.intercept('/assets/project-graphs/*').as('getGraph'); cy.visit('/'); diff --git a/graph/client/project.json b/graph/client/project.json index dfb366a256..f55afbe9cd 100644 --- a/graph/client/project.json +++ b/graph/client/project.json @@ -62,8 +62,9 @@ "dev": { "assets": [ "graph/client/src/favicon.ico", - "graph/client/src/assets/graphs/", - "graph/client/src/assets/generated-graphs/", + "graph/client/src/assets/project-graphs/", + "graph/client/src/assets/generated-project-graphs/", + "graph/client/src/assets/generated-task-graphs/", { "input": "graph/client/src/assets/dev", "output": "/", @@ -74,7 +75,7 @@ "dev-e2e": { "assets": [ "graph/client/src/favicon.ico", - "graph/client/src/assets/graphs/", + "graph/client/src/assets/project-graphs/", { "input": "graph/client/src/assets/dev-e2e", "output": "/", @@ -86,8 +87,8 @@ "assets": [ "graph/client/src/favicon.ico", { - "input": "graph/client/src/assets/graphs", - "output": "/assets/graphs", + "input": "graph/client/src/assets/project-graphs", + "output": "/assets/project-graphs", "glob": "e2e.json" }, { @@ -101,8 +102,8 @@ "assets": [ "graph/client/src/favicon.ico", { - "input": "graph/client/src/assets/graphs", - "output": "/assets/graphs", + "input": "graph/client/src/assets/project-graphs", + "output": "/assets/project-graphs", "glob": "e2e.json" }, { @@ -129,7 +130,7 @@ "assets": [ "graph/client/src/favicon.ico", { - "input": "graph/client/src/assets/graphs", + "input": "graph/client/src/assets/project-graphs", "output": "/assets/graphs", "glob": "e2e.json" }, diff --git a/graph/client/src/app/sidebar/collapse-edges-panel.stories.tsx b/graph/client/src/app/feature-projects/panels/collapse-edges-panel.stories.tsx similarity index 100% rename from graph/client/src/app/sidebar/collapse-edges-panel.stories.tsx rename to graph/client/src/app/feature-projects/panels/collapse-edges-panel.stories.tsx diff --git a/graph/client/src/app/sidebar/collapse-edges-panel.tsx b/graph/client/src/app/feature-projects/panels/collapse-edges-panel.tsx similarity index 100% rename from graph/client/src/app/sidebar/collapse-edges-panel.tsx rename to graph/client/src/app/feature-projects/panels/collapse-edges-panel.tsx diff --git a/graph/client/src/app/sidebar/focused-project-panel.stories.tsx b/graph/client/src/app/feature-projects/panels/focused-project-panel.stories.tsx similarity index 100% rename from graph/client/src/app/sidebar/focused-project-panel.stories.tsx rename to graph/client/src/app/feature-projects/panels/focused-project-panel.stories.tsx diff --git a/graph/client/src/app/sidebar/focused-project-panel.tsx b/graph/client/src/app/feature-projects/panels/focused-project-panel.tsx similarity index 100% rename from graph/client/src/app/sidebar/focused-project-panel.tsx rename to graph/client/src/app/feature-projects/panels/focused-project-panel.tsx diff --git a/graph/client/src/app/sidebar/group-by-folder-panel.stories.tsx b/graph/client/src/app/feature-projects/panels/group-by-folder-panel.stories.tsx similarity index 100% rename from graph/client/src/app/sidebar/group-by-folder-panel.stories.tsx rename to graph/client/src/app/feature-projects/panels/group-by-folder-panel.stories.tsx diff --git a/graph/client/src/app/sidebar/group-by-folder-panel.tsx b/graph/client/src/app/feature-projects/panels/group-by-folder-panel.tsx similarity index 100% rename from graph/client/src/app/sidebar/group-by-folder-panel.tsx rename to graph/client/src/app/feature-projects/panels/group-by-folder-panel.tsx diff --git a/graph/client/src/app/sidebar/rankdir-panel.stories.tsx b/graph/client/src/app/feature-projects/panels/rankdir-panel.stories.tsx similarity index 100% rename from graph/client/src/app/sidebar/rankdir-panel.stories.tsx rename to graph/client/src/app/feature-projects/panels/rankdir-panel.stories.tsx diff --git a/graph/client/src/app/sidebar/rankdir-panel.tsx b/graph/client/src/app/feature-projects/panels/rankdir-panel.tsx similarity index 97% rename from graph/client/src/app/sidebar/rankdir-panel.tsx rename to graph/client/src/app/feature-projects/panels/rankdir-panel.tsx index 5fe0873f77..00c266db43 100644 --- a/graph/client/src/app/sidebar/rankdir-panel.tsx +++ b/graph/client/src/app/feature-projects/panels/rankdir-panel.tsx @@ -8,7 +8,7 @@ import { localStorageRankDirKey, RankDir, rankDirResolver, -} from '../rankdir-resolver'; +} from '../../rankdir-resolver'; export default function RankdirPanel(): JSX.Element { const [rankDir, setRankDir] = useState( diff --git a/graph/client/src/app/sidebar/search-depth.stories.tsx b/graph/client/src/app/feature-projects/panels/search-depth.stories.tsx similarity index 100% rename from graph/client/src/app/sidebar/search-depth.stories.tsx rename to graph/client/src/app/feature-projects/panels/search-depth.stories.tsx diff --git a/graph/client/src/app/sidebar/search-depth.tsx b/graph/client/src/app/feature-projects/panels/search-depth.tsx similarity index 100% rename from graph/client/src/app/sidebar/search-depth.tsx rename to graph/client/src/app/feature-projects/panels/search-depth.tsx diff --git a/graph/client/src/app/sidebar/show-hide-projects.stories.tsx b/graph/client/src/app/feature-projects/panels/show-hide-projects.stories.tsx similarity index 100% rename from graph/client/src/app/sidebar/show-hide-projects.stories.tsx rename to graph/client/src/app/feature-projects/panels/show-hide-projects.stories.tsx diff --git a/graph/client/src/app/sidebar/show-hide-projects.tsx b/graph/client/src/app/feature-projects/panels/show-hide-projects.tsx similarity index 100% rename from graph/client/src/app/sidebar/show-hide-projects.tsx rename to graph/client/src/app/feature-projects/panels/show-hide-projects.tsx diff --git a/graph/client/src/app/sidebar/text-filter-panel.stories.tsx b/graph/client/src/app/feature-projects/panels/text-filter-panel.stories.tsx similarity index 100% rename from graph/client/src/app/sidebar/text-filter-panel.stories.tsx rename to graph/client/src/app/feature-projects/panels/text-filter-panel.stories.tsx diff --git a/graph/client/src/app/sidebar/text-filter-panel.tsx b/graph/client/src/app/feature-projects/panels/text-filter-panel.tsx similarity index 93% rename from graph/client/src/app/sidebar/text-filter-panel.tsx rename to graph/client/src/app/feature-projects/panels/text-filter-panel.tsx index 9fae0c6312..d6e58dd4c0 100644 --- a/graph/client/src/app/sidebar/text-filter-panel.tsx +++ b/graph/client/src/app/feature-projects/panels/text-filter-panel.tsx @@ -1,8 +1,8 @@ import { useEffect, useState } from 'react'; import type { KeyboardEvent } from 'react'; -import { useDebounce } from '../hooks/use-debounce'; +import { useDebounce } from '../../hooks/use-debounce'; import { BackspaceIcon, FunnelIcon } from '@heroicons/react/24/outline'; -import DebouncedTextInput from '../ui-components/debounced-text-input'; +import DebouncedTextInput from '../../ui-components/debounced-text-input'; export interface TextFilterPanelProps { textFilter: string; diff --git a/graph/client/src/app/sidebar/theme-panel.stories.tsx b/graph/client/src/app/feature-projects/panels/theme-panel.stories.tsx similarity index 100% rename from graph/client/src/app/sidebar/theme-panel.stories.tsx rename to graph/client/src/app/feature-projects/panels/theme-panel.stories.tsx diff --git a/graph/client/src/app/sidebar/theme-panel.tsx b/graph/client/src/app/feature-projects/panels/theme-panel.tsx similarity index 97% rename from graph/client/src/app/sidebar/theme-panel.tsx rename to graph/client/src/app/feature-projects/panels/theme-panel.tsx index 461feb1a9c..4500d19d0a 100644 --- a/graph/client/src/app/sidebar/theme-panel.tsx +++ b/graph/client/src/app/feature-projects/panels/theme-panel.tsx @@ -6,7 +6,11 @@ import { } from '@heroicons/react/24/outline'; import classNames from 'classnames'; import { Fragment, useEffect, useState } from 'react'; -import { localStorageThemeKey, Theme, themeResolver } from '../theme-resolver'; +import { + localStorageThemeKey, + Theme, + themeResolver, +} from '../../theme-resolver'; export default function ThemePanel(): JSX.Element { const [theme, setTheme] = useState( diff --git a/graph/client/src/app/sidebar/tracing-panel.stories.tsx b/graph/client/src/app/feature-projects/panels/tracing-panel.stories.tsx similarity index 100% rename from graph/client/src/app/sidebar/tracing-panel.stories.tsx rename to graph/client/src/app/feature-projects/panels/tracing-panel.stories.tsx diff --git a/graph/client/src/app/sidebar/tracing-panel.tsx b/graph/client/src/app/feature-projects/panels/tracing-panel.tsx similarity index 98% rename from graph/client/src/app/sidebar/tracing-panel.tsx rename to graph/client/src/app/feature-projects/panels/tracing-panel.tsx index 88a13833dc..0610b973f8 100644 --- a/graph/client/src/app/sidebar/tracing-panel.tsx +++ b/graph/client/src/app/feature-projects/panels/tracing-panel.tsx @@ -5,7 +5,7 @@ import { XCircleIcon, } from '@heroicons/react/24/outline'; import { memo } from 'react'; -import { TracingAlgorithmType } from '../machines/interfaces'; +import { TracingAlgorithmType } from '../../machines/interfaces'; export interface TracingPanelProps { start: string; diff --git a/graph/client/src/app/sidebar/project-list.tsx b/graph/client/src/app/feature-projects/project-list.tsx similarity index 100% rename from graph/client/src/app/sidebar/project-list.tsx rename to graph/client/src/app/feature-projects/project-list.tsx diff --git a/graph/client/src/app/feature-projects/projects-sidebar.tsx b/graph/client/src/app/feature-projects/projects-sidebar.tsx index d91ce061b1..4b6fafbf11 100644 --- a/graph/client/src/app/feature-projects/projects-sidebar.tsx +++ b/graph/client/src/app/feature-projects/projects-sidebar.tsx @@ -13,14 +13,14 @@ import { searchDepthSelector, textFilterSelector, } from '../machines/selectors'; -import CollapseEdgesPanel from '../sidebar/collapse-edges-panel'; -import FocusedProjectPanel from '../sidebar/focused-project-panel'; -import GroupByFolderPanel from '../sidebar/group-by-folder-panel'; -import ProjectList from '../sidebar/project-list'; -import SearchDepth from '../sidebar/search-depth'; -import ShowHideProjects from '../sidebar/show-hide-projects'; -import TextFilterPanel from '../sidebar/text-filter-panel'; -import TracingPanel from '../sidebar/tracing-panel'; +import CollapseEdgesPanel from './panels/collapse-edges-panel'; +import FocusedProjectPanel from './panels/focused-project-panel'; +import GroupByFolderPanel from './panels/group-by-folder-panel'; +import ProjectList from './project-list'; +import SearchDepth from './panels/search-depth'; +import ShowHideProjects from './panels/show-hide-projects'; +import TextFilterPanel from './panels/text-filter-panel'; +import TracingPanel from './panels/tracing-panel'; import { TracingAlgorithmType } from '../machines/interfaces'; import { useEnvironmentConfig } from '../hooks/use-environment-config'; diff --git a/graph/client/src/app/sidebar/task-list.stories.tsx b/graph/client/src/app/feature-tasks/task-list.stories.tsx similarity index 100% rename from graph/client/src/app/sidebar/task-list.stories.tsx rename to graph/client/src/app/feature-tasks/task-list.stories.tsx diff --git a/graph/client/src/app/sidebar/task-list.tsx b/graph/client/src/app/feature-tasks/task-list.tsx similarity index 93% rename from graph/client/src/app/sidebar/task-list.tsx rename to graph/client/src/app/feature-tasks/task-list.tsx index db2f02aaba..0bef024d8e 100644 --- a/graph/client/src/app/sidebar/task-list.tsx +++ b/graph/client/src/app/feature-tasks/task-list.tsx @@ -1,6 +1,6 @@ import { DocumentMagnifyingGlassIcon } from '@heroicons/react/24/solid'; // nx-ignore-next-line -import type { ProjectGraphNode, Task } from '@nrwl/devkit'; +import type { ProjectGraphNode } from '@nrwl/devkit'; import { parseParentDirectoriesFromFilePath } from '../util'; import { WorkspaceLayout } from '../interfaces'; import Tag from '../ui-components/tag'; @@ -55,6 +55,7 @@ function groupProjectsByDirectory( function ProjectListItem({ project, selectTask, + selectedTaskId, }: { project: SidebarProjectWithTargets; selectTask: ( @@ -62,6 +63,7 @@ function ProjectListItem({ targetName: string, configurationName: string ) => void; + selectedTaskId: string; }) { return (
  • @@ -73,6 +75,10 @@ function ProjectListItem({
    {target.configurations.map((configuration) => (
    + {selectedTaskId === + `${project.projectGraphNode.name}:${target.targetName}:${configuration.name}` ? ( + selected + ) : null}