Skip to content

Commit

Permalink
feat(graph): add expandedTargets to project details on nx dev
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed May 10, 2024
1 parent 88ac601 commit fffe3f9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/shared/tutorials/gradle.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ that we've installed reflects Gradle's tasks to Nx, which allows it to run any o
./nx show project application --web
```

{% project-details title="Project Details View" jsonFile="shared/tutorials/gradle-pdv.json" %}
{% project-details title="Project Details View" jsonFile="shared/tutorials/gradle-pdv.json" expandedTargets=["build"] %}
{% /project-details %}

The Nx command to run the `build` task for the `application` project is:
Expand Down
12 changes: 10 additions & 2 deletions graph/shared/src/lib/expanded-targets-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ export const ExpandedTargetsContext = createContext<{
collapseAllTargets?: () => void;
}>({});

export const ExpandedTargetsProvider = ({ children }) => {
const [expandedTargets, setExpandedTargets] = useState<string[]>([]);
export const ExpandedTargetsProvider = ({
children,
initialExpanededTargets = [],
}: {
children: React.ReactNode;
initialExpanededTargets?: string[];
}) => {
const [expandedTargets, setExpandedTargets] = useState<string[]>(
initialExpanededTargets
);

const toggleTarget = (targetName: string) => {
setExpandedTargets((prevExpandedTargets) => {
Expand Down
4 changes: 3 additions & 1 deletion nx-dev/ui-markdoc/src/lib/tags/project-details.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ export function ProjectDetails({
height,
title,
jsonFile,
expandedTargets = [],
children,
}: {
height: string;
title: string;
jsonFile?: string;
expandedTargets?: string[];
children: ReactElement;
}): JSX.Element {
const [parsedProps, setParsedProps] = useState<any>();
Expand Down Expand Up @@ -81,7 +83,7 @@ export function ProjectDetails({
height ? `p-4 h-[${height}] overflow-y-auto` : 'p-4'
}`}
>
<ExpandedTargetsProvider>
<ExpandedTargetsProvider initialExpanededTargets={expandedTargets}>
<ProjectDetailsUi
project={parsedProps.project}
sourceMap={parsedProps.sourceMap}
Expand Down
3 changes: 3 additions & 0 deletions nx-dev/ui-markdoc/src/lib/tags/project-details.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ export const projectDetails: Schema = {
height: {
type: 'String',
},
expandedTargets: {
type: 'Array',
},
},
};

0 comments on commit fffe3f9

Please sign in to comment.