From 7887accb07c06834b36fff78be542f8b9eeae9a2 Mon Sep 17 00:00:00 2001 From: Emily Xiong Date: Fri, 14 Jun 2024 14:27:14 -0400 Subject: [PATCH] feat(graph): add description and tags to details page (#26252) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Current Behavior ## Expected Behavior Screenshot 2024-05-29 at 5 47 20 PM Screenshot 2024-05-29 at 5 47 04 PM Screenshot 2024-06-04 at 11 56 54 PM ## Related Issue(s) Fixes # (cherry picked from commit e9b7439ce260630b55a7b92ebe170daf96a79f1a) --- .../ui-code-block/src/lib/json-code-block.tsx | 7 +-- .../lib/project-details/project-details.tsx | 41 +++++++------- ...arget-configuration-details-group-list.tsx | 3 ++ .../src/lib/project-node-tooltip.tsx | 2 +- graph/ui-tooltips/src/lib/tooltip.tsx | 2 +- .../nx/src/config/to-project-name.spec.ts | 10 ++-- .../src/config/workspace-json-project-json.ts | 1 + .../create-nodes.spec.ts | 54 ++++++++++++++----- .../package-json-workspaces/create-nodes.ts | 2 + .../package-json-next-to-project-json.spec.ts | 6 +++ .../package-json-next-to-project-json.ts | 2 + packages/nx/src/utils/package-json.ts | 18 ++++++- 12 files changed, 101 insertions(+), 47 deletions(-) diff --git a/graph/ui-code-block/src/lib/json-code-block.tsx b/graph/ui-code-block/src/lib/json-code-block.tsx index e335df75bdb82..1142025c50157 100644 --- a/graph/ui-code-block/src/lib/json-code-block.tsx +++ b/graph/ui-code-block/src/lib/json-code-block.tsx @@ -103,13 +103,10 @@ export function sourcesRenderer( } } return ( - + {element} {sourceElement && ( - + {sourceElement} )} diff --git a/graph/ui-project-details/src/lib/project-details/project-details.tsx b/graph/ui-project-details/src/lib/project-details/project-details.tsx index 155ed3be13d4f..dd2b4cc532d8c 100644 --- a/graph/ui-project-details/src/lib/project-details/project-details.tsx +++ b/graph/ui-project-details/src/lib/project-details/project-details.tsx @@ -34,18 +34,6 @@ const typeToProjectType = { e2e: 'E2E', }; -function getDisplayType(project: ProjectGraphProjectNode) { - if (project.data.projectType) { - return ( - project.data.projectType && - project.data.projectType?.charAt(0)?.toUpperCase() + - project.data.projectType?.slice(1) - ); - } else { - return typeToProjectType[project.type] ?? 'Library'; - } -} - export const ProjectDetails = ({ project, sourceMap, @@ -58,8 +46,6 @@ export const ProjectDetails = ({ const projectData = project.data; const isCompact = variant === 'compact'; - const displayType = getDisplayType(project); - const technologies = [ ...new Set( [ @@ -112,24 +98,33 @@ export const ProjectDetails = ({
+ {projectData.metadata?.description ? ( +

+ {projectData.metadata?.description} +

+ ) : null} {projectData.tags && projectData.tags.length ? (

- Tags: + Tags: {projectData.tags?.map((tag) => ( - + ))}

) : null} -

- Root: - {projectData.root} -

- {displayType ? ( + {projectData.root ? ( +

+ Root: + {projectData.root.trim()} +

+ ) : null} + {projectData.projectType ?? typeToProjectType[project.type] ? (

- Type: - {displayType} + Type: + + {projectData.projectType ?? typeToProjectType[project.type]} +

) : null}
diff --git a/graph/ui-project-details/src/lib/target-configuration-details-group-list/target-configuration-details-group-list.tsx b/graph/ui-project-details/src/lib/target-configuration-details-group-list/target-configuration-details-group-list.tsx index 05f91fd7fa11c..f9bb4cc4d1df7 100644 --- a/graph/ui-project-details/src/lib/target-configuration-details-group-list/target-configuration-details-group-list.tsx +++ b/graph/ui-project-details/src/lib/target-configuration-details-group-list/target-configuration-details-group-list.tsx @@ -31,6 +31,9 @@ export function TargetConfigurationGroupList({ return ( <> {Object.entries(targetsGroup.groups).map(([targetGroupName, targets]) => { + if (targets.length === 0) { + return null; + } return ( {tags.length > 0 ? ( -

+

tags

{tags.join(', ')} diff --git a/graph/ui-tooltips/src/lib/tooltip.tsx b/graph/ui-tooltips/src/lib/tooltip.tsx index d428d63c7655c..4af4b8e044f1b 100644 --- a/graph/ui-tooltips/src/lib/tooltip.tsx +++ b/graph/ui-tooltips/src/lib/tooltip.tsx @@ -138,7 +138,7 @@ export function Tooltip({ width: 'max-content', ...animationStyles, }} - className="z-10 min-w-[250px] rounded-md border border-slate-500" + className="z-10 min-w-[250px] max-w-prose rounded-md border border-slate-500" {...getFloatingProps()} > {showTooltipArrow && ( diff --git a/packages/nx/src/config/to-project-name.spec.ts b/packages/nx/src/config/to-project-name.spec.ts index bb3eec34801d8..208997128a118 100644 --- a/packages/nx/src/config/to-project-name.spec.ts +++ b/packages/nx/src/config/to-project-name.spec.ts @@ -26,9 +26,11 @@ describe('Workspaces', () => { await fs.createFiles({ 'packages/my-package/package.json': JSON.stringify({ name: 'my-package', + description: 'my-package description', }), 'package.json': JSON.stringify({ name: 'package-name', + description: 'package description', workspaces: ['packages/**'], }), }); @@ -54,13 +56,15 @@ describe('Workspaces', () => { expect(projects['packages/my-package']).toMatchInlineSnapshot(` { "metadata": { - "targetGroups": { - "NPM Scripts": [], - }, + "description": "my-package description", + "targetGroups": {}, }, "name": "my-package", "root": "packages/my-package", "sourceRoot": "packages/my-package", + "tags": [ + "npm:public", + ], "targets": { "nx-release-publish": { "configurations": {}, diff --git a/packages/nx/src/config/workspace-json-project-json.ts b/packages/nx/src/config/workspace-json-project-json.ts index d2ef9a8987425..29cad1d7c2cf6 100644 --- a/packages/nx/src/config/workspace-json-project-json.ts +++ b/packages/nx/src/config/workspace-json-project-json.ts @@ -119,6 +119,7 @@ export interface ProjectConfiguration { } export interface ProjectMetadata { + description?: string; technologies?: string[]; targetGroups?: Record; } diff --git a/packages/nx/src/plugins/package-json-workspaces/create-nodes.spec.ts b/packages/nx/src/plugins/package-json-workspaces/create-nodes.spec.ts index ede15e6afed68..3bb8afcae0717 100644 --- a/packages/nx/src/plugins/package-json-workspaces/create-nodes.spec.ts +++ b/packages/nx/src/plugins/package-json-workspaces/create-nodes.spec.ts @@ -23,10 +23,12 @@ describe('nx package.json workspaces plugin', () => { }), 'packages/lib-a/package.json': JSON.stringify({ name: 'lib-a', + description: 'lib-a description', scripts: { test: 'jest' }, }), 'packages/lib-b/package.json': JSON.stringify({ name: 'lib-b', + description: 'lib-b description', scripts: { build: 'tsc', test: 'jest', @@ -52,6 +54,7 @@ describe('nx package.json workspaces plugin', () => { "projects": { ".": { "metadata": { + "description": undefined, "targetGroups": { "NPM Scripts": [ "echo", @@ -61,6 +64,9 @@ describe('nx package.json workspaces plugin', () => { "name": "root", "root": ".", "sourceRoot": ".", + "tags": [ + "npm:public", + ], "targets": { "echo": { "executor": "nx:run-script", @@ -90,6 +96,7 @@ describe('nx package.json workspaces plugin', () => { "projects": { "packages/lib-a": { "metadata": { + "description": "lib-a description", "targetGroups": { "NPM Scripts": [ "test", @@ -99,6 +106,9 @@ describe('nx package.json workspaces plugin', () => { "name": "lib-a", "root": "packages/lib-a", "sourceRoot": "packages/lib-a", + "tags": [ + "npm:public", + ], "targets": { "nx-release-publish": { "dependsOn": [ @@ -135,6 +145,7 @@ describe('nx package.json workspaces plugin', () => { "test", ], "metadata": { + "description": "lib-b description", "targetGroups": { "NPM Scripts": [ "build", @@ -145,6 +156,9 @@ describe('nx package.json workspaces plugin', () => { "name": "lib-b", "root": "packages/lib-b", "sourceRoot": "packages/lib-b", + "tags": [ + "npm:public", + ], "targets": { "build": { "executor": "nx:run-script", @@ -227,13 +241,15 @@ describe('nx package.json workspaces plugin', () => { "projects": { "packages/vite": { "metadata": { - "targetGroups": { - "NPM Scripts": [], - }, + "description": undefined, + "targetGroups": {}, }, "name": "vite", "root": "packages/vite", "sourceRoot": "packages/vite", + "tags": [ + "npm:public", + ], "targets": { "nx-release-publish": { "dependsOn": [ @@ -313,13 +329,15 @@ describe('nx package.json workspaces plugin', () => { "projects": { "packages/vite": { "metadata": { - "targetGroups": { - "NPM Scripts": [], - }, + "description": undefined, + "targetGroups": {}, }, "name": "vite", "root": "packages/vite", "sourceRoot": "packages/vite", + "tags": [ + "npm:public", + ], "targets": { "nx-release-publish": { "dependsOn": [ @@ -395,13 +413,15 @@ describe('nx package.json workspaces plugin', () => { "projects": { "packages/vite": { "metadata": { - "targetGroups": { - "NPM Scripts": [], - }, + "description": undefined, + "targetGroups": {}, }, "name": "vite", "root": "packages/vite", "sourceRoot": "packages/vite", + "tags": [ + "npm:public", + ], "targets": { "nx-release-publish": { "dependsOn": [ @@ -465,6 +485,7 @@ describe('nx package.json workspaces plugin', () => { "projects": { "packages/a": { "metadata": { + "description": undefined, "targetGroups": { "NPM Scripts": [ "build", @@ -474,6 +495,9 @@ describe('nx package.json workspaces plugin', () => { "name": "root", "root": "packages/a", "sourceRoot": "packages/a", + "tags": [ + "npm:public", + ], "targets": { "build": { "executor": "nx:run-script", @@ -529,6 +553,7 @@ describe('nx package.json workspaces plugin', () => { "projects": { "packages/a": { "metadata": { + "description": undefined, "targetGroups": { "NPM Scripts": [ "build", @@ -538,6 +563,9 @@ describe('nx package.json workspaces plugin', () => { "name": "root", "root": "packages/a", "sourceRoot": "packages/a", + "tags": [ + "npm:public", + ], "targets": { "build": { "executor": "nx:run-script", @@ -593,13 +621,15 @@ describe('nx package.json workspaces plugin', () => { "projects": { "packages/a": { "metadata": { - "targetGroups": { - "NPM Scripts": [], - }, + "description": undefined, + "targetGroups": {}, }, "name": "root", "root": "packages/a", "sourceRoot": "packages/a", + "tags": [ + "npm:public", + ], "targets": { "nx-release-publish": { "dependsOn": [ diff --git a/packages/nx/src/plugins/package-json-workspaces/create-nodes.ts b/packages/nx/src/plugins/package-json-workspaces/create-nodes.ts index e50d26fe01d43..e3d0e8963e0d3 100644 --- a/packages/nx/src/plugins/package-json-workspaces/create-nodes.ts +++ b/packages/nx/src/plugins/package-json-workspaces/create-nodes.ts @@ -12,6 +12,7 @@ import { output } from '../../utils/output'; import { getMetadataFromPackageJson, PackageJson, + getTagsFromPackageJson, readTargetsFromPackageJson, } from '../../utils/package-json'; import { joinPathFragments } from '../../utils/path'; @@ -119,6 +120,7 @@ export function buildProjectConfigurationFromPackageJson( name, ...packageJson.nx, targets: readTargetsFromPackageJson(packageJson), + tags: getTagsFromPackageJson(packageJson), metadata: getMetadataFromPackageJson(packageJson), }; diff --git a/packages/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json.spec.ts b/packages/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json.spec.ts index 125601cb9679e..f0e3b0be23bf9 100644 --- a/packages/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json.spec.ts +++ b/packages/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json.spec.ts @@ -23,6 +23,7 @@ describe('nx project.json plugin', () => { { 'packages/lib-a/project.json': JSON.stringify({ name: 'lib-a', + description: 'lib-a project description', targets: { build: { executor: 'nx:run-commands', @@ -32,6 +33,7 @@ describe('nx project.json plugin', () => { }), 'packages/lib-a/package.json': JSON.stringify({ name: 'lib-a', + description: 'lib-a package description', scripts: { test: 'jest', }, @@ -47,6 +49,7 @@ describe('nx project.json plugin', () => { "projects": { "lib-a": { "metadata": { + "description": "lib-a package description", "targetGroups": { "NPM Scripts": [ "test", @@ -55,6 +58,9 @@ describe('nx project.json plugin', () => { }, "name": "lib-a", "root": "packages/lib-a", + "tags": [ + "npm:public", + ], "targets": { "nx-release-publish": { "dependsOn": [ diff --git a/packages/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json.ts b/packages/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json.ts index cd748ce872975..112c4798c54ef 100644 --- a/packages/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json.ts +++ b/packages/nx/src/plugins/project-json/build-nodes/package-json-next-to-project-json.ts @@ -6,6 +6,7 @@ import { ProjectConfiguration } from '../../../config/workspace-json-project-jso import { PackageJson, getMetadataFromPackageJson, + getTagsFromPackageJson, readTargetsFromPackageJson, } from '../../../utils/package-json'; @@ -56,6 +57,7 @@ function createProjectFromPackageJsonNextToProjectJson( root, targets: readTargetsFromPackageJson(packageJson), metadata: getMetadataFromPackageJson(packageJson), + tags: getTagsFromPackageJson(packageJson), } as ProjectConfiguration; } catch (e) { console.log(e); diff --git a/packages/nx/src/utils/package-json.ts b/packages/nx/src/utils/package-json.ts index d6996dfd11f82..00315999d5ad8 100644 --- a/packages/nx/src/utils/package-json.ts +++ b/packages/nx/src/utils/package-json.ts @@ -78,6 +78,8 @@ export interface PackageJson { 'nx-migrations'?: string | NxMigrationsConfiguration; 'ng-update'?: string | NxMigrationsConfiguration; packageManager?: string; + description?: string; + keywords?: string[]; } export function normalizePackageGroup( @@ -144,15 +146,27 @@ let packageManagerCommand: PackageManagerCommands | undefined; export function getMetadataFromPackageJson( packageJson: PackageJson ): ProjectMetadata { - const { scripts, nx } = packageJson ?? {}; + const { scripts, nx, description } = packageJson ?? {}; const includedScripts = nx?.includedScripts || Object.keys(scripts ?? {}); return { targetGroups: { - 'NPM Scripts': includedScripts, + ...(includedScripts.length ? { 'NPM Scripts': includedScripts } : {}), }, + description, }; } +export function getTagsFromPackageJson(packageJson: PackageJson): string[] { + const tags = packageJson.private ? ['npm:private'] : ['npm:public']; + if (packageJson.keywords?.length) { + tags.push(...packageJson.keywords.map((k) => `npm:${k}`)); + } + if (packageJson?.nx?.tags?.length) { + tags.push(...packageJson?.nx.tags); + } + return tags; +} + export function readTargetsFromPackageJson(packageJson: PackageJson) { const { scripts, nx, private: isPrivate } = packageJson ?? {}; const res: Record = {};