Skip to content

Commit

Permalink
feat(graph): add description and tags to details page (#26252)
Browse files Browse the repository at this point in the history
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
<img width="1155" alt="Screenshot 2024-05-29 at 5 47 20 PM"
src="https://github.com/nrwl/nx/assets/16211801/025f08d5-52cf-4087-94a5-e3319c89f8b1">
<img width="1127" alt="Screenshot 2024-05-29 at 5 47 04 PM"
src="https://github.com/nrwl/nx/assets/16211801/ff19514d-2513-4b13-ac9c-4b124ac0ce4a">
<img width="387" alt="Screenshot 2024-06-04 at 11 56 54 PM"
src="https://github.com/nrwl/nx/assets/16211801/ea2f0c47-a444-4be8-9ccd-60fd2b534e12">

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

(cherry picked from commit e9b7439)
  • Loading branch information
xiongemi authored and FrozenPandaz committed Jun 21, 2024
1 parent 7ac7d71 commit 7887acc
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 47 deletions.
7 changes: 2 additions & 5 deletions graph/ui-code-block/src/lib/json-code-block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,10 @@ export function sourcesRenderer(
}
}
return (
<span
className="group/line shrink-1 flex flex min-w-0"
key={`code-group${idx}`}
>
<span className="group/line flex" key={`code-group${idx}`}>
<span>{element}</span>
{sourceElement && (
<span className="shrink-1 inline flex min-w-0 pl-2 opacity-0 transition-opacity duration-150 ease-in-out group-hover/line:opacity-100">
<span className="min-w-0 flex-1 pl-2 opacity-0 transition-opacity duration-150 ease-in-out group-hover/line:opacity-100">
{sourceElement}
</span>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -58,8 +46,6 @@ export const ProjectDetails = ({
const projectData = project.data;
const isCompact = variant === 'compact';

const displayType = getDisplayType(project);

const technologies = [
...new Set(
[
Expand Down Expand Up @@ -112,24 +98,33 @@ export const ProjectDetails = ({
</div>
<div className="flex justify-between py-2">
<div>
{projectData.metadata?.description ? (
<p className="mb-2 text-sm capitalize text-gray-500 dark:text-slate-400">
{projectData.metadata?.description}
</p>
) : null}
{projectData.tags && projectData.tags.length ? (
<p>
<span className="inline-block w-10 font-medium">Tags:</span>
<span className="font-medium">Tags:</span>
{projectData.tags?.map((tag) => (
<span className="ml-2 font-mono">
<span className="ml-2 font-mono lowercase">
<Pill text={tag} />
</span>
))}
</p>
) : null}
<p>
<span className="inline-block w-10 font-medium">Root:</span>
<span className="font-mono"> {projectData.root}</span>
</p>
{displayType ? (
{projectData.root ? (
<p>
<span className="font-medium">Root:</span>
<span className="font-mono"> {projectData.root.trim()}</span>
</p>
) : null}
{projectData.projectType ?? typeToProjectType[project.type] ? (
<p>
<span className="inline-block w-10 font-medium">Type:</span>
<span className="font-mono"> {displayType}</span>
<span className="font-medium">Type:</span>
<span className="ml-2 font-mono capitalize">
{projectData.projectType ?? typeToProjectType[project.type]}
</span>
</p>
) : null}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export function TargetConfigurationGroupList({
return (
<>
{Object.entries(targetsGroup.groups).map(([targetGroupName, targets]) => {
if (targets.length === 0) {
return null;
}
return (
<TargetConfigurationGroupContainer
targetGroupName={targetGroupName}
Expand Down
2 changes: 1 addition & 1 deletion graph/ui-tooltips/src/lib/project-node-tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function ProjectNodeToolTip({
)}
</h4>
{tags.length > 0 ? (
<p className="my-2">
<p className="my-2 lowercase">
<strong>tags</strong>
<br></br>
{tags.join(', ')}
Expand Down
2 changes: 1 addition & 1 deletion graph/ui-tooltips/src/lib/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 && (
Expand Down
10 changes: 7 additions & 3 deletions packages/nx/src/config/to-project-name.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'],
}),
});
Expand All @@ -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": {},
Expand Down
1 change: 1 addition & 0 deletions packages/nx/src/config/workspace-json-project-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export interface ProjectConfiguration {
}

export interface ProjectMetadata {
description?: string;
technologies?: string[];
targetGroups?: Record<string, string[]>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -52,6 +54,7 @@ describe('nx package.json workspaces plugin', () => {
"projects": {
".": {
"metadata": {
"description": undefined,
"targetGroups": {
"NPM Scripts": [
"echo",
Expand All @@ -61,6 +64,9 @@ describe('nx package.json workspaces plugin', () => {
"name": "root",
"root": ".",
"sourceRoot": ".",
"tags": [
"npm:public",
],
"targets": {
"echo": {
"executor": "nx:run-script",
Expand Down Expand Up @@ -90,6 +96,7 @@ describe('nx package.json workspaces plugin', () => {
"projects": {
"packages/lib-a": {
"metadata": {
"description": "lib-a description",
"targetGroups": {
"NPM Scripts": [
"test",
Expand All @@ -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": [
Expand Down Expand Up @@ -135,6 +145,7 @@ describe('nx package.json workspaces plugin', () => {
"test",
],
"metadata": {
"description": "lib-b description",
"targetGroups": {
"NPM Scripts": [
"build",
Expand All @@ -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",
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -465,6 +485,7 @@ describe('nx package.json workspaces plugin', () => {
"projects": {
"packages/a": {
"metadata": {
"description": undefined,
"targetGroups": {
"NPM Scripts": [
"build",
Expand All @@ -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",
Expand Down Expand Up @@ -529,6 +553,7 @@ describe('nx package.json workspaces plugin', () => {
"projects": {
"packages/a": {
"metadata": {
"description": undefined,
"targetGroups": {
"NPM Scripts": [
"build",
Expand All @@ -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",
Expand Down Expand Up @@ -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": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { output } from '../../utils/output';
import {
getMetadataFromPackageJson,
PackageJson,
getTagsFromPackageJson,
readTargetsFromPackageJson,
} from '../../utils/package-json';
import { joinPathFragments } from '../../utils/path';
Expand Down Expand Up @@ -119,6 +120,7 @@ export function buildProjectConfigurationFromPackageJson(
name,
...packageJson.nx,
targets: readTargetsFromPackageJson(packageJson),
tags: getTagsFromPackageJson(packageJson),
metadata: getMetadataFromPackageJson(packageJson),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
},
Expand All @@ -47,6 +49,7 @@ describe('nx project.json plugin', () => {
"projects": {
"lib-a": {
"metadata": {
"description": "lib-a package description",
"targetGroups": {
"NPM Scripts": [
"test",
Expand All @@ -55,6 +58,9 @@ describe('nx project.json plugin', () => {
},
"name": "lib-a",
"root": "packages/lib-a",
"tags": [
"npm:public",
],
"targets": {
"nx-release-publish": {
"dependsOn": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ProjectConfiguration } from '../../../config/workspace-json-project-jso
import {
PackageJson,
getMetadataFromPackageJson,
getTagsFromPackageJson,
readTargetsFromPackageJson,
} from '../../../utils/package-json';

Expand Down Expand Up @@ -56,6 +57,7 @@ function createProjectFromPackageJsonNextToProjectJson(
root,
targets: readTargetsFromPackageJson(packageJson),
metadata: getMetadataFromPackageJson(packageJson),
tags: getTagsFromPackageJson(packageJson),
} as ProjectConfiguration;
} catch (e) {
console.log(e);
Expand Down
Loading

0 comments on commit 7887acc

Please sign in to comment.