BloodHound icon indicating copy to clipboard operation
BloodHound copied to clipboard

refactor: additional navigation for edit zone on Privilege Zones BED-6628

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

Description

On Privilege Zones, some changes where made on UI to improve wording and Information displayed when Creating/Editing zones or labels

Motivation and Context

Fixes BED-6628

How Has This Been Tested?

Tested Locally and created new test

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

  • New Features

    • Added a tag-limits hook to report remaining zones and labels during tagging.
  • UI/UX Updates

    • Moved Delete action into the header; action bar now shows only Cancel and Save.
    • Displays remaining availability in the tag form with a contact link for account management.
  • Chores

    • Exposed configuration keys and added shared exports for tag-limits.
    • Added a label-tag factory for mocks.
  • Tests

    • Added unit tests covering zone/label limit scenarios.

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

LucasParraF avatar Nov 25 '25 21:11 LucasParraF

Walkthrough

Adds a new React hook useTagLimits with tests and exports, integrates it into PrivilegeZones TagForm to surface remaining zone/label availability and move the Delete action to the header, exports configurationKeys, and updates mock factory to accept tag type.

Changes

Cohort / File(s) Summary
New hook implementation
\packages/javascript/bh-shared-ui/src/hooks/useTagLimits/useTagLimits.ts``
Implements useTagLimits: queries asset-group tags and tiering configuration, classifies tags (zone vs label), computes zoneLimitReached, labelLimitReached, remainingZonesAvailable, remainingLabelsAvailable, and short-circuits on loading/error/missing config.
Hook barrel & central export
\packages/javascript/bh-shared-ui/src/hooks/useTagLimits/index.ts``, \packages/javascript/bh-shared-ui/src/hooks/index.ts``
Adds export * from './useTagLimits' and re-exports it from the central hooks index.
Hook tests
\packages/javascript/bh-shared-ui/src/hooks/useTagLimits/useTagLimits.test.ts``
Adds unit tests covering zone/label limit reached and remaining-count scenarios using mocked queries and fixtures.
UI integration
\packages/javascript/bh-shared-ui/src/views/PrivilegeZones/Save/TagForm/TagForm.tsx``
Consumes useTagLimits, computes remaining count by page type, displays availability in a CardDescription with an external "Contact sales" link (conditional on Certification), moves Delete action into header and removes footer Delete button.
Configuration API change
\packages/javascript/bh-shared-ui/src/hooks/useConfiguration.ts``
Makes configurationKeys an exported constant (public API addition).
Mocks
\packages/javascript/bh-shared-ui/src/mocks/factories/privilegeZones.ts``
Updates createAssetGroupTag signature to accept an AssetGroupTagType parameter (defaulting to zone) and uses it for the returned object's type field to support zone/label test data.
Views export change
\packages/javascript/bh-shared-ui/src/views/PrivilegeZones/index.tsx``
Exports ZonesLink in addition to PageDescription.

Sequence Diagram(s)

sequenceDiagram
    participant TagForm as TagForm Component
    participant Hook as useTagLimits Hook
    participant AssetTags as useAssetGroupTags (query)
    participant Config as useGetConfiguration (query)

    TagForm->>Hook: call useTagLimits()
    par parallel fetches
        Hook->>AssetTags: fetch asset-group tags
        Hook->>Config: fetch tiering configuration
    end
    alt loading / error / missing config
        Hook-->>TagForm: { zoneLimitReached: true, labelLimitReached: true, remaining*: 0 }
    else success
        Hook->>Hook: classify tags into zone vs label
        Hook->>Hook: read tier_limit & label_limit from parsed config
        Hook-->>TagForm: { zoneLimitReached, labelLimitReached, remainingZonesAvailable, remainingLabelsAvailable }
    end
    TagForm->>UI: render header (Delete moved), CardDescription (remaining), footer (Cancel, Save)

Estimated code review effort

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

  • Focus areas:
    • correctness of tag classification and counting in useTagLimits
    • loading/error/missing-configuration short-circuit behavior
    • UI change in TagForm.tsx (Delete relocation, conditional rendering, accessibility)
    • updated mock signature compatibility with existing tests and fixtures

Possibly related PRs

  • SpecterOps/BloodHound#1836 โ€” edits to PrivilegeZones TagForm that may overlap with the Delete relocation and UI payloads.
  • SpecterOps/BloodHound#1675 โ€” changes to useAssetGroupTags behavior/shape that may affect useTagLimits data consumption.
  • SpecterOps/BloodHound#1924 โ€” other edits to central hook exports that may intersect with adding useTagLimits to the hooks barrel.

Suggested reviewers

  • mistahj67
  • Holocraft
  • urangel

Poem

๐Ÿ‡ I hopped through tags by moonlit beams,
Counting zones and labels into dreams.
A header button, limits to show,
Remaining spots in gentle glow.
Hop on โ€” the UIโ€™s ready to grow.

Pre-merge checks and finishing touches

โœ… Passed checks (3 passed)
Check name Status Explanation
Title check โœ… Passed The title directly references BED-6628 and clearly describes the main change: refactoring to add additional navigation for editing zones on Privilege Zones, which aligns with the core modifications shown in the changeset.
Description check โœ… Passed The description includes key sections (Description, Motivation/Context, Testing, Types of Changes, Checklist) and adequately explains the UI improvements for Privilege Zones while referencing BED-6628. However, it lacks specific implementation details about the changes made.
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-6628-Additional-Navigation-for-Edit-Zone

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 25 '25 21:11 coderabbitai[bot]