Skip to content

Refactor Discover v2 rules menu: merge alerts into legacy-rules submenu#259649

Merged
jasonrhodes merged 4 commits intoelastic:alerting_v2from
jasonrhodes:fix/alerts-menu-refactor
Mar 26, 2026
Merged

Refactor Discover v2 rules menu: merge alerts into legacy-rules submenu#259649
jasonrhodes merged 4 commits intoelastic:alerting_v2from
jasonrhodes:fix/alerts-menu-refactor

Conversation

@jasonrhodes
Copy link
Copy Markdown
Member

Summary

Refactors how the v2 "Rules" menu in Discover handles legacy (v1) rule types, replacing the legacyRules registry indirection with a simpler merge-and-delete approach.

Before: A new AppMenuActionId.legacyRules was introduced as a hidden container. Profile extensions had to dual-register items to both alerts and legacyRules. The legacyRules container caused an empty menu item bug in overflow popovers.

After: Profile extensions register to alerts as they always have. When v2 is enabled, items from alerts are merged into the createRule menu's legacy-rules submenu, then alerts is removed. No new registry IDs, no dual registration, no empty menu items.

Changes

  • app_menu_registry.ts: Added deleteItem() method to remove menu items by ID
  • types.ts: Removed AppMenuActionId.legacyRules enum value
  • get_create_rule.tsx: Removed hardcoded legacy items from the v2 menu (empty legacy-rules submenu is populated by merge). Updated labels to "Create v2 ES|QL rule" and "Create v1 rules"
  • use_top_nav_links.tsx: Removed legacyRules container registration. Changed merge source from legacyRules to alerts. Added deleteItem call to remove alerts after merge. Always register alerts menu (not gated by showLegacyAlerts)
  • get_app_menu.tsx (observability profile): Removed duplicate registerPopoverItem calls to legacyRules, keeping only alerts registration

Net effect: -88 lines, +18 lines

Test plan

  • Enable alerting v2 flag, go to Discover → ES|QL mode
  • Verify "Rules" menu shows "Create v2 ES|QL rule" and "Create v1 rules" submenu
  • Verify "Create v1 rules" submenu contains items from profile extensions (e.g. search threshold, custom threshold for o11y)
  • Verify no empty menu items appear in the overflow popover
  • Disable alerting v2 flag, verify "Alerts" menu appears as before with no regressions
  • Test in Observability profile to confirm custom threshold + SLO actions appear correctly

Made with Cursor

Instead of introducing a separate `legacyRules` registry ID and requiring
profile extensions to dual-register items, this keeps the existing `alerts`
registration path intact. When v2 is enabled, items from the `alerts` menu
are merged into the `createRule` menu's `legacy-rules` submenu, and the
`alerts` menu item is removed.

This eliminates the `AppMenuActionId.legacyRules` indirection, removes
duplicate item registration in profile extensions, and fixes the empty
menu item bug caused by the hidden `legacyRules` container appearing
in overflow popovers.

Made-with: Cursor
@github-actions github-actions bot added the author:actionable-obs PRs authored by the actionable obs team label Mar 25, 2026
@jasonrhodes jasonrhodes marked this pull request as ready for review March 25, 2026 20:27
@jasonrhodes jasonrhodes requested review from a team as code owners March 25, 2026 20:27
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Mar 25, 2026

Approvability

Verdict: Needs human review

The author doesn't own any of the changed files (all owned by @elastic/kibana-data-discovery or @elastic/obs-exploration-team), and there's an unresolved design question from another reviewer about exposing the deleteItem API. The changes affect UI menu structure and runtime behavior, warranting review by designated code owners.

You can customize Macroscope's approvability policy. Learn more.

href: getManageRulesUrl(services),
});
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We no longer need to re-craft this manually, it comes over when we merge in the Alerts menu into the v2 Rules sub-menu

order: 1,
label: i18n.translate('discover.localMenu.createRuleTitle', {
defaultMessage: 'Create rule',
defaultMessage: 'Create v2 ES|QL rule',
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We will be explicit for M1, decide on much better naming and labeling for M2

order: 2,
label: i18n.translate('discover.localMenu.legacyRulesTitle', {
defaultMessage: 'Create legacy rules',
defaultMessage: 'Create v1 rules',
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Must avoid the word "legacy" for v1 rules (v1 is also terrible but we will fix for M2)

items: [],
});
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We don't need to register this "dummy" item, we re-use the alerts one, then remove/delete it after we've merged its contents into the sub-nav.

AppMenuActionId.legacyRules
AppMenuActionId.alerts
);
registry.deleteItem(AppMenuActionId.alerts);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

new line to remove the old "alerts" menu item, we've merged its contents into the v2 Rules sub-nav item for M1

@dominiqueclarke dominiqueclarke self-requested a review March 26, 2026 00:01
Copy link
Copy Markdown
Contributor

@dominiqueclarke dominiqueclarke left a comment

Choose a reason for hiding this comment

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

Code review plus manual test. LGTM!

AppMenuActionId.legacyRules
AppMenuActionId.alerts
);
registry.deleteItem(AppMenuActionId.alerts);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: is there any benefit in exposing the deleteItem method from the registry over just deleting it in mergePopoverItems?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fair point, I think I like how explicit it is here, so we can see the flow in line.

The refactor removed the only usage of canCreateESQLRule inside the
memo body (the showLegacyAlerts condition), but left it in the
dependency array. ESLint's react-hooks/exhaustive-deps flagged it.

Made-with: Cursor
- Add deleteItem() tests to AppMenuRegistry (3 new tests)
- Update get_create_rule tests to match new labels ("Create v2 ES|QL
  rule", "Create v1 rules") and empty legacy-rules submenu (items are
  now merged in at runtime from the alerts menu, not hardcoded)
- Remove tests for items that are no longer pre-populated in the
  legacy-rules submenu (search threshold, manage rules)

Made-with: Cursor
@dominiqueclarke dominiqueclarke self-requested a review March 26, 2026 14:52
@elasticmachine
Copy link
Copy Markdown
Contributor

⏳ Build in-progress, with failures

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #11 / SearchBar add filter
  • [job] [logs] Jest Integration Tests #3 / scripts/generate_plugin builds a generated plugin into a viable archive

History

@jasonrhodes jasonrhodes merged commit 80ef2d9 into elastic:alerting_v2 Mar 26, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author:actionable-obs PRs authored by the actionable obs team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants