Skip to content

Commit

Permalink
feat(graph): remove select target group state
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Apr 26, 2024
1 parent 29327d6 commit 746a5e0
Show file tree
Hide file tree
Showing 38 changed files with 404 additions and 758 deletions.
2 changes: 1 addition & 1 deletion graph/client/src/app/external-api-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class ExternalApiImpl extends ExternalApi {
const currentLocation = this.router.state.location;

const searchParams = new URLSearchParams(currentLocation.search);
searchParams.set('targetName', targetName);
searchParams.set('expanded', targetName);

const newUrl = `${currentLocation.pathname}?${searchParams.toString()}`;
this.router.navigate(newUrl);
Expand Down
6 changes: 3 additions & 3 deletions graph/client/src/app/feature-projects/project-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '@heroicons/react/24/outline';
/* eslint-disable @nx/enforce-module-boundaries */
// nx-ignore-next-line
import type { ProjectGraphNode } from '@nx/devkit';
import type { ProjectGraphProjectNode } from '@nx/devkit';
/* eslint-enable @nx/enforce-module-boundaries */
import { useProjectGraphSelector } from './hooks/use-project-graph-selector';
import {
Expand All @@ -23,7 +23,7 @@ import { Link, useNavigate } from 'react-router-dom';
import { useRouteConstructor } from '@nx/graph/shared';

interface SidebarProject {
projectGraphNode: ProjectGraphNode;
projectGraphNode: ProjectGraphProjectNode;
isSelected: boolean;
}

Expand All @@ -36,7 +36,7 @@ interface TracingInfo {
}

function groupProjectsByDirectory(
projects: ProjectGraphNode[],
projects: ProjectGraphProjectNode[],
selectedProjects: string[],
workspaceLayout: { appsDir: string; libsDir: string }
): DirectoryProjectRecord {
Expand Down
6 changes: 4 additions & 2 deletions graph/client/src/app/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable @nx/enforce-module-boundaries */
// nx-ignore-next-line
import { ProjectGraphDependency, ProjectGraphProjectNode } from '@nx/devkit';
import { getEnvironmentConfig } from '@nx/graph/shared';
import type {
ProjectGraphDependency,
ProjectGraphProjectNode,
} from '@nx/devkit';
/* eslint-enable @nx/enforce-module-boundaries */

export function parseParentDirectoriesFromFilePath(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import {
RootState,
expandTargetActions,
getExpandedTargets,
getSelectedTarget,
selectTargetActions,
} from '@nx/graph/state';

const mapStateToProps = (state: RootState) => {
return {
expandTargets: getExpandedTargets(state),
getSelectedTarget: getSelectedTarget(state),
};
};

Expand All @@ -19,15 +16,9 @@ const mapDispatchToProps = (dispatch: AppDispatch) => {
setExpandTargets(targets: string[]) {
dispatch(expandTargetActions.setExpandTargets(targets));
},
selectTarget(targetGroup: string) {
dispatch(selectTargetActions.selectTarget(targetGroup));
},
collapseAllTargets() {
dispatch(expandTargetActions.collapseAllTargets());
},
clearTargetGroup() {
dispatch(selectTargetActions.clearSelectedTarget());
},
};
};

Expand Down
62 changes: 10 additions & 52 deletions graph/project-details/src/lib/project-details-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import {
useEnvironmentConfig,
useRouteConstructor,
} from '@nx/graph/shared';
import {
ProjectDetails,
defaultSelectTargetGroup,
getTargetGroupForTarget,
} from '@nx/graph/ui-project-details';
import { ProjectDetails } from '@nx/graph/ui-project-details';
import { useCallback, useEffect } from 'react';
import {
mapStateToProps,
Expand All @@ -32,9 +28,6 @@ export function ProjectDetailsWrapperComponent({
sourceMap,
setExpandTargets,
expandTargets,
getSelectedTarget,
selectTarget,
clearTargetGroup,
collapseAllTargets,
}: ProjectDetailsProps) {
const environment = useEnvironmentConfig()?.environment;
Expand Down Expand Up @@ -101,89 +94,54 @@ export function ProjectDetailsWrapperComponent({

const updateSearchParams = (
params: URLSearchParams,
targetGroup: string | null,
targetNames: string[]
) => {
if (targetGroup) {
params.set('targetGroup', targetGroup);
} else {
params.delete('targetGroup');
}
if (targetNames.length === 0) {
params.delete('targetName');
params.delete('expanded');
} else {
params.set('targetName', targetNames.join(','));
params.set('expanded', targetNames.join(','));
}
};

/* useEffect(() => {
useEffect(() => {
if (!project.data.targets) return;

const selectedTargetNameParam = searchParams.get('targetName');
if (
selectedTargetNameParam &&
selectedTarget !== selectedTargetNameParam
) {
selectTarget(selectedTargetNameParam);
}
const expandedTargetsParams =
searchParams.get('targetName')?.split(',') || [];
if (expandedTargetsParams.length > 0) {
const expandedTargetsParams = searchParams.get('expanded')?.split(',');
if (expandedTargetsParams && expandedTargetsParams.length > 0) {
setExpandTargets(expandedTargetsParams);
}

const targetName = searchParams.get('targetName');
if (targetName) {
const targetGroup = getTargetGroupForTarget(targetName, project);
selectTarget(targetGroup);
setExpandTargets([targetName]);
}
return () => {
clearTargetGroup();
collapseAllTargets();
searchParams.delete('targetGroup');
searchParams.delete('targetName');
searchParams.delete('expanded');
setSearchParams(searchParams, { replace: true });
};
}, []); // only run on mount

useEffect(() => {
if (!project.data.targets) return;

const selectedTargetGroupParams = searchParams.get('targetGroup');
const expandedTargetsParams =
searchParams.get('targetName')?.split(',') || [];
searchParams.get('expanded')?.split(',') || [];

if (
selectedTargetGroup === selectedTargetGroupParams &&
expandedTargetsParams.join(',') === expandTargets.join(',')
) {
if (expandedTargetsParams.join(',') === expandTargets.join(',')) {
return;
}

setSearchParams(
(currentSearchParams) => {
updateSearchParams(
currentSearchParams,
selectedTargetGroup,
expandTargets
);
updateSearchParams(currentSearchParams, expandTargets);
return currentSearchParams;
},
{ replace: true, preventScrollReset: true }
);
}, [
expandTargets,
selectedTargetGroup,
project.data.targets,
setExpandTargets,
searchParams,
setSearchParams,
]);
*/

return (
<ProjectDetails
Expand Down
1 change: 0 additions & 1 deletion graph/state/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './lib/expand-targets/expand-targets.slice';
export * from './lib/select-target/select-target.slice';
export * from './lib/root/root-state.initial';
export * from './lib/root/root-state.interface';
export * from './lib/root/root.reducer';
Expand Down
5 changes: 0 additions & 5 deletions graph/state/src/lib/root/root-state.initial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@ import {
EXPAND_TARGETS_KEY,
initialExpandTargets,
} from '../expand-targets/expand-targets.slice';
import {
SELECT_TARGET_KEY,
initialSelectTarget,
} from '../select-target/select-target.slice';
import { RootState } from './root-state.interface';

export const initialRootState: RootState = {
[EXPAND_TARGETS_KEY]: initialExpandTargets,
[SELECT_TARGET_KEY]: initialSelectTarget,
};
2 changes: 0 additions & 2 deletions graph/state/src/lib/root/root-state.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { EXPAND_TARGETS_KEY } from '../expand-targets/expand-targets.slice';
import { SELECT_TARGET_KEY } from '../select-target/select-target.slice';

export interface RootState {
[EXPAND_TARGETS_KEY]: string[];
[SELECT_TARGET_KEY]: string;
}
5 changes: 0 additions & 5 deletions graph/state/src/lib/root/root.reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ import {
EXPAND_TARGETS_KEY,
expandTargetReducer,
} from '../expand-targets/expand-targets.slice';
import {
SELECT_TARGET_KEY,
selectTargetReducer,
} from '../select-target/select-target.slice';
import { RootState } from './root-state.interface';

export const rootReducer = combineReducers<RootState>({
[EXPAND_TARGETS_KEY]: expandTargetReducer,
[SELECT_TARGET_KEY]: selectTargetReducer as any,
});
29 changes: 0 additions & 29 deletions graph/state/src/lib/select-target/select-target.slice.ts

This file was deleted.

6 changes: 1 addition & 5 deletions graph/ui-icons/src/lib/framework-icons.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ const meta: Meta<typeof frameworkIcons> = {
export default meta;
type Story = StoryObj<typeof frameworkIcons>;

export const Primary = {
args: {},
};

export const Heading: Story = {
export const Primary: Story = {
args: {},
};
Loading

0 comments on commit 746a5e0

Please sign in to comment.