BloodHound icon indicating copy to clipboard operation
BloodHound copied to clipboard

chore: update Zone Selector BED-6846

Open KillahDillah opened this issue 1 month ago โ€ข 1 comments

Description

ZoneSelector will look different on the Details page than seen elsewhere. ZoneSelector, when passed pathParams, will set the path params, updating the view to the selected Zone. User should not see any reference to upgrades or zone analysis unavailable. Zones (within the Details pages) should always be available and never disabled (depending on whether analysis is enabled or not)

To test these changes, ZoneSelector must be manually added to the Details page. Anywhere on the Details page add: ZoneSelector to line 75, within context object and {ZoneSelector && <ZoneSelector pathParams />}

Motivation and Context

Resolves BED-6846

Why is this change required? What problem does it solve?

Allows user to choose their zones from a dropdown

How Has This Been Tested?

Please describe in detail how you tested your changes. Include details of your testing environment, and the tests you ran to see how your change affects other areas of the code, etc.

Visually, new test added, and all tests pass.

Screenshots (optional):

Types of changes

  • Chore (a change that does not modify the application functionality)

Checklist:

  • [x] I have met the contributing prerequisites
    • Assigned myself to this PR
    • Added the appropriate labels
    • Associated an issue: https://github.com/SpecterOps/BloodHound/issues/672
    • Read the Contributing guide: https://github.com/SpecterOps/BloodHound/wiki/Contributing
  • [x] I have ensured that related documentation is up-to-date
    • Open API docs
    • Code comments (GoDocs / JSDocs)
  • [x] I have followed proper test practices
    • Added/updated tests to cover my changes
    • All new and existing tests passed

Summary by CodeRabbit

  • Style

    • Restored default icon sizing in the privilege zone details view.
  • New Features

    • Exposed an optional Zone Selector component for privilege zones.
  • Improvements

    • Context now detects the details page for more accurate UI behavior.
    • Tag selection now supports both path- and query-based selection and always provides a safe fallback so a tag is consistently shown.

โœ๏ธ Tip: You can customize this high-level summary in your review settings.

KillahDillah avatar Nov 24 '25 23:11 KillahDillah

Walkthrough

Adds an isDetailsPage flag to the PZ path params hook, introduces path-based tag resolution and new selection hooks (useSelectedTagQueryParams, useSelectedTagPathParams, useSelectedTag), removes an explicit size='sm' from a FontAwesomeIcon, and adds an optional ZoneSelector prop to the PrivilegeZones context interface.

Changes

Cohort / File(s) Summary
PZ path params hook
packages/javascript/bh-shared-ui/src/hooks/usePZParams/usePZPathParams.tsx
Import detailsPath, compute isDetailsPage = location.pathname.includes(detailsPath), and include isDetailsPage: boolean in the hook return object.
Tag selection hooks
packages/javascript/bh-shared-ui/src/hooks/useSelectedTag.ts, packages/javascript/bh-shared-ui/src/hooks/usePZParams/*, packages/javascript/bh-shared-ui/src/hooks/useAssetGroupTags/*
Add useSelectedTagQueryParams and useSelectedTagPathParams; introduce a placeholderTag fallback; add useSelectedTag(fromPathParams = false) to select path vs query resolution; import usePZPathParams and useOrderedTags; ensure a concrete tag is always returned.
Component tweak
packages/javascript/bh-shared-ui/src/views/PrivilegeZones/Details/DynamicDetails.tsx
Removed size='sm' prop from FontAwesomeIcon in TagDetails (icon now uses default sizing).
Context interface
packages/javascript/bh-shared-ui/src/views/PrivilegeZones/PrivilegeZonesContext.tsx
Added optional ZoneSelector?: FC<{ onZoneClick?: (zone: AssetGroupTag) => void }> to PrivilegeZonesContextValue interface.

Sequence Diagram(s)

sequenceDiagram
  participant Router
  participant usePZPathParams
  participant usePZQueryParams
  participant useSelectedTag
  participant TagsStore
  participant Component
  participant PrivilegeZonesContext

  Router->>usePZPathParams: provide location.pathname
  usePZPathParams->>usePZPathParams: compute isDetailsPage (pathname.includes(detailsPath))
  Router->>usePZQueryParams: provide search/query params

  Component->>useSelectedTag: request selected tag (fromPathParams flag)
  alt fromPathParams == true
    useSelectedTag->>usePZPathParams: read path params
  else
    useSelectedTag->>usePZQueryParams: read query params
  end
  useSelectedTag->>TagsStore: resolve tag (match by id/name)
  TagsStore-->>useSelectedTag: tag | highest-privilege | placeholderTag
  useSelectedTag-->>Component: return selectedTag

  Component->>PrivilegeZonesContext: optionally render ZoneSelector(onZoneClick)
  PrivilegeZonesContext-->>Component: ZoneSelector component (optional)

Estimated code review effort

๐ŸŽฏ 3 (Moderate) | โฑ๏ธ ~25 minutes

  • Areas to inspect closely:
    • packages/javascript/bh-shared-ui/src/hooks/useSelectedTag.ts: correctness of path vs query selection, fallback to placeholderTag, and type signatures.
    • packages/javascript/bh-shared-ui/src/hooks/usePZParams/usePZPathParams.tsx: detailsPath import and isDetailsPage detection (edge-cases like trailing slashes).
    • Consumers of PrivilegeZonesContext: ensure optional ZoneSelector addition is safely handled.
    • packages/javascript/bh-shared-ui/src/views/PrivilegeZones/Details/DynamicDetails.tsx: visual/regression verification after icon size removal.

Possibly related PRs

  • SpecterOps/BloodHound#2012 โ€” touches usePZPathParams; may consume the new isDetailsPage flag.
  • SpecterOps/BloodHound#1836 โ€” overlaps glyph/icon and DynamicDetails changes.
  • SpecterOps/BloodHound#1932 โ€” modifies PrivilegeZones routing/context and may interact with the new ZoneSelector and path params.

Suggested reviewers

  • urangel
  • specter-flq
  • elikmiller

Poem

๐Ÿฐ I hopped the path and found a flag,

A tag that chooses road or tag,
Icons lighter, context wider,
A placeholder waits beside her,
Tiny changes, joyful drag. ๐Ÿฅ•

Pre-merge checks and finishing touches

โœ… Passed checks (3 passed)
Check name Status Explanation
Title check โœ… Passed The title 'chore: update Zone Selector BED-6846' is partially related to the changeset, referring to the real change of updating Zone Selector behavior but lacking specificity about what was updated or the key technical improvement being introduced.
Description check โœ… Passed The pull request description includes all required template sections with sufficient detail: clear description of changes, motivation with linked Jira ticket (BED-6846), testing approach, change type marked as 'Chore', and completed checklist items confirming prerequisites met.
Docstring Coverage โœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
โœจ Finishing touches
  • [ ] ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch BED-6846-zone-dropdown

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

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 24 '25 23:11 coderabbitai[bot]