Skip to content

[Controls Anywhere] Fix reordering controls on delete#241045

Merged
Zacqary merged 2 commits intoelastic:controlsAnywherefrom
Zacqary:control-reorder-fix
Oct 30, 2025
Merged

[Controls Anywhere] Fix reordering controls on delete#241045
Zacqary merged 2 commits intoelastic:controlsAnywherefrom
Zacqary:control-reorder-fix

Conversation

@Zacqary
Copy link
Copy Markdown
Contributor

@Zacqary Zacqary commented Oct 28, 2025

Summary

Prevents a Kibana-crashing runtime error that can occur when deleting multiple controls.

From control_display_settings_popover.tsx:

 const isToRightOfGrowControl = useMemo(
    () => layoutEntry.order > 0 && Object.values(layoutState.controls)[layoutEntry.order - 1].grow,
    [layoutEntry.order, layoutState.controls]
  );

This can lead to a situation where layoutEntry.order - 1 might return undefined, and then throw a Kibana-crashing type error when undefined.grow didn't exist.

This is because when you delete controls, the remaining controls' order property doesn't get updated. So we could get into a situation where there are 3 controls, one of them has an order of 2, and if we delete controls 0 and 1, the sole existing control still has order: 2. It then tries to look up control at index 1, gets undefined, and errors out.

This PR recomputes control order when a control is deleted, preventing this error and any future situations that might arise from trying to look up controls based on their order

@Zacqary Zacqary requested a review from a team as a code owner October 28, 2025 21:53
@Zacqary Zacqary added Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t// Project:Controls labels Oct 28, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-presentation (Team:Presentation)

…out_manager/layout_manager.ts

Co-authored-by: Hannah Mudge <Heenawter@users.noreply.github.com>
@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Oct 29, 2025

💔 Build Failed

Failed CI Steps

History

@Zacqary Zacqary merged commit 845b9b1 into elastic:controlsAnywhere Oct 30, 2025
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Project:Controls Team:Presentation Presentation Team for Dashboard, Input Controls, and Canvas t//

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants