Skip to content

Conversation

@animehart
Copy link
Contributor

@animehart animehart commented Jul 31, 2025

Summary

This PR addresses the Issue where after user clicks on Distribution bar segments to filter data, the tooltips defaults to Last Segment instead of Chosen filter (It should only default to Last segment IF there are no filter)

Screen.Recording.2025-07-30.at.8.11.25.PM.mov

@animehart animehart added Team:Cloud Security Cloud Security team related v9.2.0 release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting labels Jul 31, 2025
@animehart animehart marked this pull request as ready for review July 31, 2025 14:08
@animehart animehart requested a review from a team as a code owner July 31, 2025 14:08
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-cloud-security-posture (Team:Cloud Security)

Copy link
Contributor

@opauloh opauloh left a comment

Choose a reason for hiding this comment

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

Nice work, just a few suggestions

const parts = stats.map((stat) => {

const [hoveredKey, setHoveredKey] = useState<string | null>(null);
const hasCurrentFilter = stats.some((item) => item.isCurrentFilter === true);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: add useMemo to prevent recalculating on every render.:

Suggested change
const hasCurrentFilter = stats.some((item) => item.isCurrentFilter === true);
const hasCurrentFilter = useMemo(
() => stats.some((item) => item.isCurrentFilter),
[stats]
);

Comment on lines 151 to 155
// Only show tooltip for segments thats hovered OR Set as Filter OR Last
const showTooltip =
isHovered ||
(!hoveredKey &&
((stat.isCurrentFilter ?? false) || (!hideLastTooltip && !hasCurrentFilter && isLast)));
Copy link
Contributor

Choose a reason for hiding this comment

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

So the complexity grew here and there are a few business logic in these lines, I suggest splitting into a separate function with each condition split into variables, example (feel free to improve):

 // Only show tooltip for segments thats hovered OR Set as Filter OR Last
const shouldShowTooltip = ({
  isHovered,
  isCurrentFilter,
  isLast,
  hasFilterActive,
  hideLastTooltip,
  isHoveringAnyStatsBar,
}: {
  isHovered: boolean;
  isCurrentFilter: boolean;
  isLast: boolean;
  hasFilterActive: boolean;
  hideLastTooltip?: boolean;
  isHoveringAnyStatsBar: boolean;
}) => {
  if (isHovered) return true;

  const shouldShowBecauseOfFilter = isCurrentFilter;
  const shouldShowBecauseItIsLast = isLast && !hideLastTooltip && !hasFilterActive;

  return !isHoveringAnyStatsBar && (shouldShowBecauseOfFilter || shouldShowBecauseItIsLast);
};

usage

const isCurrentFilter = stat.isCurrentFilter ?? false;
const showTooltip = shouldShowTooltip({
  isHovered,
  isCurrentFilter,
  isLast,
  hasFilterActive: hasCurrentFilter,
  hideLastTooltip,
  isHoveringAnyStatsBar: Boolean(hoveredKey),
});

@animehart animehart requested a review from opauloh July 31, 2025 22:26
Copy link
Contributor

@opauloh opauloh left a comment

Choose a reason for hiding this comment

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

LGTM

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 9.8MB 9.8MB +436.0B

History

@animehart animehart merged commit 252fa4a into elastic:main Aug 1, 2025
12 checks passed
szaffarano pushed a commit to szaffarano/kibana that referenced this pull request Aug 5, 2025
## Summary

This PR addresses the Issue where after user clicks on Distribution bar
segments to filter data, the tooltips defaults to Last Segment instead
of Chosen filter (It should only default to Last segment IF there are no
filter)


https://github.com/user-attachments/assets/c3dbc3ac-846d-41ea-8a9a-6b05c53a7cab
delanni pushed a commit to delanni/kibana that referenced this pull request Aug 5, 2025
## Summary

This PR addresses the Issue where after user clicks on Distribution bar
segments to filter data, the tooltips defaults to Last Segment instead
of Chosen filter (It should only default to Last segment IF there are no
filter)


https://github.com/user-attachments/assets/c3dbc3ac-846d-41ea-8a9a-6b05c53a7cab
@wildemat wildemat mentioned this pull request Aug 7, 2025
10 tasks
NicholasPeretti pushed a commit to NicholasPeretti/kibana that referenced this pull request Aug 18, 2025
## Summary

This PR addresses the Issue where after user clicks on Distribution bar
segments to filter data, the tooltips defaults to Last Segment instead
of Chosen filter (It should only default to Last segment IF there are no
filter)


https://github.com/user-attachments/assets/c3dbc3ac-846d-41ea-8a9a-6b05c53a7cab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Cloud Security Cloud Security team related v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security Solution] [Bug] Filter applied of Alert severity under Insights is not visible.

3 participants