<!-- 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` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #
122 lines
4.0 KiB
TypeScript
122 lines
4.0 KiB
TypeScript
/* eslint-disable @nx/enforce-module-boundaries */
|
|
// nx-ignore-next-line
|
|
import type { ProjectGraphProjectNode } from '@nx/devkit';
|
|
|
|
import { TargetConfigurationDetailsListItem } from '../target-configuration-details-list-item/target-configuration-details-list-item';
|
|
import { TargetConfigurationGroupContainer } from '../target-configuration-details-group-container/target-configuration-details-group-container';
|
|
import { groupTargets } from '../utils/group-targets';
|
|
import { useMemo } from 'react';
|
|
|
|
export interface TargetConfigurationGroupListProps {
|
|
project: ProjectGraphProjectNode;
|
|
sourceMap: Record<string, string[]>;
|
|
variant?: 'default' | 'compact';
|
|
onRunTarget?: (data: { projectName: string; targetName: string }) => void;
|
|
onViewInTaskGraph?: (data: {
|
|
projectName: string;
|
|
targetName: string;
|
|
}) => void;
|
|
onNxConnect?: () => void;
|
|
connectedToCloud?: boolean;
|
|
className?: string;
|
|
}
|
|
|
|
export function TargetConfigurationGroupList({
|
|
project,
|
|
variant,
|
|
sourceMap,
|
|
onRunTarget,
|
|
onViewInTaskGraph,
|
|
onNxConnect,
|
|
className = '',
|
|
connectedToCloud,
|
|
}: TargetConfigurationGroupListProps) {
|
|
const targetsGroup = useMemo(() => groupTargets(project), [project]);
|
|
const hasGroups = useMemo(() => {
|
|
for (const group of Object.entries(targetsGroup.groups)) {
|
|
if (group[1]?.length > 0) return true;
|
|
}
|
|
return false;
|
|
}, [targetsGroup]);
|
|
|
|
if (hasGroups) {
|
|
return (
|
|
<>
|
|
{Object.entries(targetsGroup.groups).map(
|
|
([targetGroupName, targets]) => {
|
|
return (
|
|
<TargetConfigurationGroupContainer
|
|
targetGroupName={targetGroupName}
|
|
targetsNumber={targets.length}
|
|
key={targetGroupName}
|
|
>
|
|
<ul className={className}>
|
|
{targets.map((targetName) => (
|
|
<TargetConfigurationDetailsListItem
|
|
project={project}
|
|
sourceMap={sourceMap}
|
|
connectedToCloud={connectedToCloud}
|
|
variant={variant}
|
|
onRunTarget={onRunTarget}
|
|
onViewInTaskGraph={onViewInTaskGraph}
|
|
onNxConnect={onNxConnect}
|
|
targetName={targetName}
|
|
collapsable={true}
|
|
key={targetName}
|
|
/>
|
|
))}
|
|
</ul>
|
|
</TargetConfigurationGroupContainer>
|
|
);
|
|
}
|
|
)}
|
|
<TargetConfigurationGroupContainer
|
|
targetGroupName="Others"
|
|
targetsNumber={targetsGroup.targets.length}
|
|
key="others-group"
|
|
>
|
|
<ul className={`p-2 ${className}`}>
|
|
{targetsGroup.targets.map((targetName) => {
|
|
return (
|
|
<TargetConfigurationDetailsListItem
|
|
project={project}
|
|
sourceMap={sourceMap}
|
|
connectedToCloud={connectedToCloud}
|
|
variant={variant}
|
|
onRunTarget={onRunTarget}
|
|
onViewInTaskGraph={onViewInTaskGraph}
|
|
onNxConnect={onNxConnect}
|
|
targetName={targetName}
|
|
collapsable={true}
|
|
key={targetName}
|
|
/>
|
|
);
|
|
})}
|
|
</ul>
|
|
</TargetConfigurationGroupContainer>
|
|
</>
|
|
);
|
|
} else {
|
|
return (
|
|
<ul className={className}>
|
|
{targetsGroup.targets.map((targetName) => {
|
|
return (
|
|
<TargetConfigurationDetailsListItem
|
|
project={project}
|
|
sourceMap={sourceMap}
|
|
connectedToCloud={connectedToCloud}
|
|
variant={variant}
|
|
onRunTarget={onRunTarget}
|
|
onViewInTaskGraph={onViewInTaskGraph}
|
|
onNxConnect={onNxConnect}
|
|
targetName={targetName}
|
|
collapsable={true}
|
|
key={targetName}
|
|
/>
|
|
);
|
|
})}
|
|
</ul>
|
|
);
|
|
}
|
|
}
|