8000 feat(SigmaChart): add pathfinding edge filter context menu option by TheNando · Pull Request #1631 · SpecterOps/BloodHound · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat(SigmaChart): add pathfinding edge filter context menu option #1631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

TheNando
Copy link
Contributor
@TheNando TheNando commented Jun 30, 2025

Description

When in Explore -> Pathfinding tab, right-clicking on an edge will show a new context menu allowing to easily update pathfinding filters.

Motivation and Context

Resolves BED-5180

This will allow users to remove complexity from the graph while being able to identify and simulate changes in the graph.

How Has This Been Tested?

Manual testing and new/updated unit tests

  1. Load ad_sampledata.zip
  2. Visit link https://bloodhound.localhost/ui/explore?exploreSearchTab=pathfinding&primarySearch=PHANTOM.CORP-S-1-5-11&searchType=pathfinding&secondarySearch=S-1-5-21-2697957641-2271029196-387917394
  3. Right click an edge to add it to pathfinding edge filter

Screenshots:

image

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added right-click context menu support on graph edges.
    • Introduced edge filtering directly from the context menu to exclude specific edge types.
    • Unified pathfinding filter state management with new functions for applying and removing filters.
    • Added new components for edge and node context menu items.
  • Improvements

    • Modularized context menu items into separate components for edges and nodes.
    • Improved context menu positioning using standardized coordinate types.
    • Enhanced utility functions for event handling and type checking.
    • Restricted copy menu actions to node selections only.
    • Simplified event handling to support both node and edge context menus.
  • Refactor

    • Streamlined pathfinding filter hook and removed deprecated functions.
    • Optimized edge type validation with a lookup set.
    • Updated test files and component props to reflect new coordinate and filter APIs.
    • Removed obsolete utility functions and reorganized imports.
    • Refactored context menu components to use new props and subcomponents.
  • Tests

    • Added tests for new utility functions and filter handling.
    • Updated existing tests to accommodate new props and component structures.

@TheNando TheNando added enhancement New feature or request user interface A pull request containing changes affecting the UI code. labels Jun 30, 2025
Copy link
Contributor
coderabbitai bot commented Jun 30, 2025

Walkthrough

This change introduces right-click context menu support for graph edges in the UI, modularizes context menu rendering for nodes and edges, and refactors pathfinding filter logic for better state management and usability. Several utility functions are added or moved, and related hooks, types, and tests are updated to reflect the new event handling and filtering capabilities.

Changes

File(s) Change Summary
cmd/ui/src/components/SigmaChart/GraphEdgeEvents.tsx Added required onRightClickEdge prop; unified edge event handling for click and context menu; updated event handler logic.
cmd/ui/src/components/SigmaChart/SigmaChart.tsx Updated handleContextMenu prop type to accept edge events; passed new onRightClickEdge prop to GraphEdgeEvents.
cmd/ui/src/components/SigmaChart/GraphEvents.tsx Changed import source for preventAllDefaults utility.
cmd/ui/src/rendering/utils/utils.ts
cmd/ui/src/rendering/utils/utils.test.ts
Removed preventAllDefaults function and its tests from this location.
cmd/ui/src/utils.ts
cmd/ui/src/utils.test.ts
Added isNodeEvent type guard and new preventAllDefaults utility; introduced tests for both.
cmd/ui/src/views/Explore/ContextMenu/ContextMenu.tsx Refactored to modularize node and edge menu items; added edge filtering; updated positioning logic and props.
cmd/ui/src/views/Explore/ContextMenu/ContextMenu.test.tsx
cmd/ui/src/views/Explore/ContextMenu/ContextMenuZoneManagementEnabled.test.tsx
Updated test setup and prop names for new context menu coordinates and pathfinding filters.
cmd/ui/src/views/Explore/ContextMenu/ContextMenuZoneManagementEnabled.tsx Changed context menu prop type and coordinate references to use Coordinates.
cmd/ui/src/views/Explore/ContextMenu/CopyMenuItem.tsx Limited copy options to node selections; minor formatting changes.
cmd/ui/src/views/Explore/ExploreSearch/ExploreSearch.tsx
cmd/ui/src/views/Explore/ExploreSearch/ExploreSearch.test.tsx
Refactored to accept pathfindingFilters prop instead of using internal hook; updated tests.
cmd/ui/src/views/Explore/GraphView.tsx Integrated pathfinding filters hook and utilities; updated context menu and event handlers for node/edge distinction.
packages/javascript/bh-shared-ui/src/edgeTypes.tsx Added isEdgeType export and supporting lookup for edge type validation.
packages/javascript/bh-shared-ui/src/hooks/useExploreGraph/usePathfindingFilters.ts
packages/javascript/bh-shared-ui/src/hooks/useExploreGraph/usePathfindingFilters.test.tsx
Added handleRemoveEdgeType; replaced handleCancelFilters with initialize; updated filter application logic and tests.
packages/javascript/bh-shared-ui/src/hooks/useExploreGraph/utils.ts Removed compareEdgeTypes function; replaced by areArraysSimilar.
packages/javascript/bh-shared-ui/src/utils/array.ts
packages/javascript/bh-shared-ui/src/utils/array.test.ts
Added areArraysSimilar utility function with tests for unordered array equality.
packages/javascript/bh-shared-ui/src/utils/index.ts Exported all from './array' to extend utils API.
packages/javascript/bh-shared-ui/src/views/Explore/ExploreSearch/EdgeFilter.tsx Removed handleCancelFilters; reordered filter state properties; replaced cancel calls with initialize.
packages/javascript/bh-shared-ui/src/components/ContextMenuItems/EdgeMenuItems.tsx Added EdgeMenuItems component rendering filter menu item for edges with valid edge types.
packages/javascript/bh-shared-ui/src/components/ContextMenuItems/NodeMenuItems.tsx Added NodeMenuItems component rendering starting/ending node menu items with explore param updates.
packages/javascript/bh-shared-ui/src/components/ContextMenuItems/index.ts Added index file re-exporting EdgeMenuItems and NodeMenuItems.
packages/javascript/bh-shared-ui/src/components/index.ts Exported all from './ContextMenuItems' to centralize component exports.
packages/javascript/bh-shared-ui/src/types.ts Added Coordinates interface with x and y numeric properties.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant GraphEdgeEvents
  participant SigmaChart
  participant ContextMenu

  User->>GraphEdgeEvents: Right-click on edge
  GraphEdgeEvents->>SigmaChart: onRightClickEdge(payload)
  SigmaChart->>ContextMenu: handleContextMenu(payload)
  ContextMenu->>ContextMenu: Render edge-specific menu items
Loading
sequenceDiagram
  participant User
  participant ContextMenu
  participant PathfindingFilters

  User->>ContextMenu: Select "Filter out Edge"
  ContextMenu->>PathfindingFilters: handleRemoveEdgeType(edgeType)
  PathfindingFilters->>PathfindingFilters: Update selectedFilters and apply
Loading

Possibly related PRs

  • SpecterOps/BloodHound#1549: Refactors GraphEdgeEvents to remove internal state and add an optional onClickEdge prop for left-click handling, directly overlapping with changes to edge event handling in this PR.

Suggested reviewers

  • urangel
  • mvlipka

Poem

In the garden of edges and nodes I hop,
Right-clicks now bloom, context menus pop!
Filters and props, all neat and spry,
With modular menus, options multiply.
A bunny’s delight in code so refined—
Edge or node, the path you’ll find!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94cc2ce and 9965603.

📒 Files selected for processing (3)
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/EdgeMenuItems.tsx (1 hunks)
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/NodeMenuItems.tsx (1 hunks)
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/index.ts
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/EdgeMenuItems.tsx
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/NodeMenuItems.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build BloodHound Container Image / Build and Package Container
  • GitHub Check: run-tests
  • GitHub Check: build-ui
  • GitHub Check: run-analysis
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot]

This comment was marked as outdated.

@TheNando TheNando marked this pull request as draft July 1, 2025 03:05
@@ -68,34 +61,3 @@ describe('getNodeRadius', () => {
expect(getNodeRadius(false, 1, nodeSize)).not.toEqual(getNodeRadius(false, 0.5, nodeSize));
});
});

describe('preventAllDefaults', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why I originally put this in the rendering utils. Moving it to a more appropriate module.

};

const ContextMenu: FC<{
contextMenu: Coordinates | null;
Copy link
Contributor Author
@TheNando TheNando Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched from the inline { mouseX, mouseY } to the Coordinates interface, which is already compatible with event mouse data (the source of this prop).

</>
}>
<MenuItem sx={{ justifyContent: 'space-between' }} => e.stopPropagation()}>
<MenuItem
sx={{ justifyContent: 'space-between', minWidth: '8rem' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

min-width ensures that the submenu arrow isn't right up against the Copy when no other options are shown.

@TheNando TheNando force-pushed the BED-5180--filter-edge branch from d146343 to d4726fa Compare July 2, 2025 17:00
@TheNando TheNando marked this pull request as ready for review July 2, 2025 17:06
selectedItemType: 'node',
} as any;

const fakeSelectedEdge = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many new variables. Caching mocks to keep test implementation less noisey.

@@ -66,7 +83,14 @@ beforeAll(() => server.listen());
afterEach(() => server.resetHandlers());
afterAll(() => server.close());

const setup = async (permissions?: Permission[], primarySearch?: string, secondarySearch?: string) => {
interface SetupOptions {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Options object is a little more flexible and scales better, since additional params are needed now.

} as any);

const mockPathfindingFilters: PathfindingFilters = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now a required prop for the ContextMenu.

coderabbitai[bot]

This comment was marked as outdated.

};

describe('ContextMenu', async () => {
describe('ContextMenu - Nodes', async () => {
beforeEach(() => mockSelectedItemQuery.mockReturnValue(fakeSelectedNode));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that there are scenarios where the return varies (for 'edge' tests), this mock is selectively applied.

import { selectOwnedAssetGroupId, selectTierZeroAssetGroupId } from 'src/ducks/assetgroups/reducer';
import { useAppSelector } from 'src/store';
import AssetGroupMenuItem from './AssetGroupMenuItem';
import CopyMenuItem from './CopyMenuItem';

const ContextMenu: FC<{
Copy link
Contributor Author
@TheNando TheNando Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component has been modified to show the ContextMenu when right clicking a node in any tab or an edge if in the pathfiltering tab. I also refactored for modularity, moving many of the menu items into the shared lib. Not all of it can be moved since it relies on Redux state, but this is a start.

6302
@@ -93,6 +94,7 @@ const GraphView: FC = () => {
const sigmaChartRef = useRef<any>(null);

const customIcons = useCustomNodeKinds({ select: transformIconDictionary });
const pathfindingFilters = usePathfindingFilters();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was lifted from a child so that it could be shared by the ExploreSearch and the ContextMenu. We should get an alternative to Redux for sharable state. React Contexts are ok, but there are some nice, simple options out there.

@@ -27,13 +27,6 @@ export const mapParamsToFilters = (params: string[], initial: EdgeCheckboxType[]
}));
};

export const compareEdgeTypes = (initial: string[], comparison: string[]): boolean => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was generalized into areArraysSimilar and moved to the utils folder.

@TheNando TheNando force-pushed the BED-5180--filter-edge branch from d4726fa to 366bba0 Compare July 7, 2025 16:14
coderabbitai[bot]

This comment was marked as outdated.

@TheNando TheNando force-pushed the BED-5180--filter-edge branch from 366bba0 to 0f6bb6f Compare July 7, 2025 17:11
@TheNando TheNando self-assigned this Jul 8, 2025
coderabbitai[bot]

This comment was marked as outdated.

@TheNando TheNando force-pushed the BED-5180--filter-edge branch from 1a05112 to 94cc2ce Compare July 8, 2025 17:56
Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
cmd/ui/src/views/Explore/ContextMenu/ContextMenu.test.tsx (2)

31-54: Consider using factory functions for better maintainability.

The approach of using JSON.parse(JSON.stringify()) for creating mock variations works but is fragile and not type-safe. Consider using factory functions for better maintainability and type safety.

-const fakeSelectedNonFilterable = JSON.parse(JSON.stringify(fakeSelectedEdge));
-fakeSelectedNonFilterable.selectedItemQuery.data.id = '123_CrossForestTrust_456';
-
-const fakeSelectedNonEdge = JSON.parse(JSON.stringify(fakeSelectedEdge));
-fakeSelectedNonEdge.selectedItemQuery.data.id = '345';
+const createFakeSelectedEdge = (id: string, objectId: string = fakeSelectedItemId) => ({
+    selectedItemQuery: {
+        data: {
+            objectId,
+            id,
+        },
+    },
+    selectedItemType: 'edge',
+} as any);
+
+const fakeSelectedEdge = createFakeSelectedEdge('123_MemberOf_456');
+const fakeSelectedNonFilterable = createFakeSelectedEdge('123_CrossForestTrust_456');
+const fakeSelectedNonEdge = createFakeSelectedEdge('345');

296-296: Consider verifying the exact parameters passed to the handler.

The test verifies that handleRemoveEdgeType is called, but doesn't verify the parameters. Consider checking that the correct edge type is passed to ensure the filtering logic works as expected.

-        expect(mockPathfindingFilters.handleRemoveEdgeType).toBeCalled();
+        expect(mockPathfindingFilters.handleRemoveEdgeType).toBeCalledWith('MemberOf');
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a05112 and 94cc2ce.

📒 Files selected for processing (28)
  • cmd/ui/src/components/SigmaChart/GraphEdgeEvents.tsx (5 hunks)
  • cmd/ui/src/components/SigmaChart/GraphEvents.tsx (1 hunks)
  • cmd/ui/src/components/SigmaChart/SigmaChart.tsx (3 hunks)
  • cmd/ui/src/rendering/utils/utils.test.ts (1 hunks)
  • cmd/ui/src/rendering/utils/utils.ts (1 hunks)
  • cmd/ui/src/utils.test.ts (1 hunks)
  • cmd/ui/src/utils.ts (2 hunks)
  • cmd/ui/src/views/Explore/ContextMenu/ContextMenu.test.tsx (11 hunks)
  • cmd/ui/src/views/Explore/ContextMenu/ContextMenu.tsx (1 hunks)
  • cmd/ui/src/views/Explore/ContextMenu/ContextMenuZoneManagementEnabled.test.tsx (7 hunks)
  • cmd/ui/src/views/Explore/ContextMenu/ContextMenuZoneManagementEnabled.tsx (4 hunks)
  • cmd/ui/src/views/Explore/ContextMenu/CopyMenuItem.tsx (2 hunks)
  • cmd/ui/src/views/Explore/ExploreSearch/ExploreSearch.test.tsx (2 hunks)
  • cmd/ui/src/views/Explore/ExploreSearch/ExploreSearch.tsx (3 hunks)
  • cmd/ui/src/views/Explore/GraphView.tsx (6 hunks)
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/EdgeMenuItems.tsx (1 hunks)
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/NodeMenuItems.tsx (1 hunks)
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/index.ts (1 hunks)
  • packages/javascript/bh-shared-ui/src/components/index.ts (1 hunks)
  • packages/javascript/bh-shared-ui/src/edgeTypes.tsx (1 hunks)
  • packages/javascript/bh-shared-ui/src/hooks/useExploreGraph/usePathfindingFilters.test.tsx (1 hunks)
  • packages/javascript/bh-shared-ui/src/hooks/useExploreGraph/usePathfindingFilters.ts (2 hunks)
  • packages/javascript/bh-shared-ui/src/hooks/useExploreGraph/utils.ts (0 hunks)
  • packages/javascript/bh-shared-ui/src/types.ts (1 hunks)
  • packages/javascript/bh-shared-ui/src/utils/array.test.ts (1 hunks)
  • packages/javascript/bh-shared-ui/src/utils/array.ts (1 hunks)
  • packages/javascript/bh-shared-ui/src/utils/index.ts (1 hunks)
  • packages/javascript/bh-shared-ui/src/views/Explore/ExploreSearch/EdgeFilter.tsx (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/javascript/bh-shared-ui/src/hooks/useExploreGraph/utils.ts
🚧 Files skipped from review as they are similar to previous changes (26)
  • packages/javascript/bh-shared-ui/src/types.ts
  • packages/javascript/bh-shared-ui/src/hooks/useExploreGraph/usePathfindingFilters.test.tsx
  • cmd/ui/src/components/SigmaChart/GraphEvents.tsx
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/index.ts
  • packages/javascript/bh-shared-ui/src/utils/index.ts
  • packages/javascript/bh-shared-ui/src/components/index.ts
  • cmd/ui/src/views/Explore/ContextMenu/ContextMenuZoneManagementEnabled.test.tsx
  • packages/javascript/bh-shared-ui/src/utils/array.ts
  • cmd/ui/src/views/Explore/ContextMenu/CopyMenuItem.tsx
  • cmd/ui/src/rendering/utils/utils.test.ts
  • packages/javascript/bh-shared-ui/src/utils/array.test.ts
  • cmd/ui/src/rendering/utils/utils.ts
  • cmd/ui/src/utils.test.ts
  • cmd/ui/src/views/Explore/ExploreSearch/ExploreSearch.tsx
  • cmd/ui/src/views/Explore/ContextMenu/ContextMenuZoneManagementEnabled.tsx
  • cmd/ui/src/views/Explore/GraphView.tsx
  • packages/javascript/bh-shared-ui/src/views/Explore/ExploreSearch/EdgeFilter.tsx
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/EdgeMenuItems.tsx
  • packages/javascript/bh-shared-ui/src/edgeTypes.tsx
  • cmd/ui/src/components/SigmaChart/SigmaChart.tsx
  • cmd/ui/src/views/Explore/ExploreSearch/ExploreSearch.test.tsx
  • cmd/ui/src/utils.ts
  • packages/javascript/bh-shared-ui/src/components/ContextMenuItems/NodeMenuItems.tsx
  • cmd/ui/src/components/SigmaChart/GraphEdgeEvents.tsx
  • cmd/ui/src/views/Explore/ContextMenu/ContextMenu.tsx
  • packages/javascript/bh-shared-ui/src/hooks/useExploreGraph/usePathfindingFilters.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Build BloodHound Container Image / Build and Package Container
  • GitHub Check: build-ui
  • GitHub Check: run-tests
  • GitHub Check: run-analysis
🔇 Additional comments (6)
cmd/ui/src/views/Explore/ContextMenu/ContextMenu.test.tsx (6)

19-19: LGTM: Import addition supports new functionality.

The PathfindingFilters import is correctly added to support the new edge filtering functionality being tested.


86-92: LGTM: Options object pattern improves flexibility.

The refactoring to use an options object pattern makes the setup function more maintainable and flexible as new parameters can be added without breaking existing calls.


115-122: LGTM: Comprehensive pathfinding filters mock.

The PathfindingFilters mock includes all necessary methods for testing edge filtering functionality. The mock is well-structured and supports the new edge context menu features.


126-126: LGTM: Coordinate property names updated correctly.

The coordinate properties have been correctly updated from mouseX/mouseY to x/y to align with the new Coordinates type.


140-141: LGTM: Well-organized test structure.

The addition of a describe block for node tests and the beforeEach hook provides good separation and ensures consistent test state setup.


254-298: LGTM: Comprehensive edge test coverage.

The edge tests provide excellent coverage of the new functionality:

  • Tests filtering options appear only on pathfinding tab
  • Tests behavior with invalid edge IDs
  • Tests non-filterable edge scenarios
  • Tests the actual filtering behavior

The test cases are well-structured and cover both positive and negative scenarios effectively.

@SpecterOps SpecterOps deleted a comment from coderabbitai bot Jul 8, 2025
@SpecterOps SpecterOps deleted a comment from coderabbitai bot Jul 8, 2025
Comment on lines -227 to +229
contextMenu={isNode(selectedItemQuery.data) ? contextMenu : null}
contextMenu={contextMenu}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have this edge context capability work for the ContextMenuZoneManagementEnabled component as well as it may look like a bug if the edge menu doesn't show when the tier_management_engine feature flag is enabled.

@@ -44,7 +48,7 @@ export const GraphEdgeEvents: FC<GraphEdgeEventProps> = ({ onClickEdge }) => {
(event: any) => {
const context = edgeLabelsCanvas.getContext('2d');
if (!context) return;
if (event.type === 'click' || event.type === 'mousemove') {
if (EDGE_EVENTS.includes(event.type)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the EDGE_EVENTS declaration for this condition checking here. Reads nicer than two ||

Comment on lines +222 to +225
// Used to quickly determine if a given string is an edge type
const EDGE_TYPE_SET = new Set(
AllEdgeTypes.flatMap((category) => category.subcategories.flatMap((sub) => sub.edgeTypes))
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat!

pathfindingFilters: PathfindingFilters;
};

const RX_EDGE_TYPE = /^[^_]+_(.+)_[^_]+$/;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for the use case today as no pathfinding edges contain underscores in the name but I don't think there are gates prohibiting the use of them for new edges. There are actually some edges in our schema that do have underscores in the name, AZMGAppRoleAssignment_ReadWrite_All for example. These edges happen to not be pathfinding edges though so do not conflict with the expected behavior.

I think it would be good to add a test that pulls the list of pathfinding edges and looks for the presence of underscores and asserts that there are none. This way if one does get added in the future the failing test would be a good reminder to update the logic to account for that case.

Alternatively we could update the useGraphItem hook to additionally return the edge name without the source and target node appended at the ends so that we don't have to parse it out again here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request user interface A pull request containing changes affecting the UI code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0