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 23, 2024
1 parent 412d6a3 commit c2574f1
Show file tree
Hide file tree
Showing 30 changed files with 288 additions and 642 deletions.
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
54 changes: 6 additions & 48 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');
} else {
params.set('targetName', 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('targetName')?.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');
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(',') || [];

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 c2574f1

Please sign in to comment.