From b0f6913ef6d5f8af51bc2d9e87634c1b44caae36 Mon Sep 17 00:00:00 2001 From: Tom Ratcliffe Date: Tue, 30 Apr 2024 16:17:55 +0100 Subject: [PATCH] Alerting: unify alert rule actions between list and detail view (#86071) * Add mock method for getting a plugin * Update tests to find "more" button via label * Remove test for Silence action in rule details * Unify alert rule actions to pull from same place * Restore behaviour of only showing incident button when firing * Fix identifier and pause permission/logic * Remove TODO comment related to refactor * Update snapshot for useAbilities * Undo optional param * Rename alert rule menu hook to component * Refactor hook to component * Rename Rule action buttons component * Chore: update style syntax for RuleDetails * Add tests for refactored alert rule menu * Only re-fetch Grafana managed alerts after pausing/resuming * Remove console log and check for extensions * Improve share rule generation of GMA rules * Rename component * Update action * Refactor plugins and fix tests * lint --------- Co-authored-by: Konrad Lalik Co-authored-by: Gilles De Mey --- .betterer.results | 12 - .../alerting/unified/RuleList.test.tsx | 2 +- public/app/features/alerting/unified/TODO.md | 1 - .../components/rule-viewer/Actions.tsx | 131 -------- .../components/rule-viewer/AlertRuleMenu.tsx | 139 ++++++++ .../rule-viewer/RuleViewer.test.tsx | 6 +- .../components/rule-viewer/RuleViewer.tsx | 12 +- .../rules/RuleActionsButtons.test.tsx | 126 ++++++++ .../components/rules/RuleActionsButtons.tsx | 299 ++++++------------ .../components/rules/RuleDetails.test.tsx | 28 -- .../unified/components/rules/RuleDetails.tsx | 36 +-- .../rules/RuleDetailsActionButtons.tsx | 257 --------------- .../components/rules/RuleDetailsButtons.tsx | 127 ++++++++ .../components/rules/RulesTable.test.tsx | 11 +- .../unified/components/rules/RulesTable.tsx | 2 +- .../RuleActionsButtons.test.tsx.snap | 28 ++ .../__snapshots__/useAbilities.test.tsx.snap | 8 + .../alerting/unified/hooks/useAbilities.ts | 2 + public/app/features/alerting/unified/mocks.ts | 57 ++-- .../alerting/unified/mocks/folders.ts | 6 + .../alerting/unified/mocks/plugins.ts | 14 +- .../alerting/unified/mocks/server/handlers.ts | 6 + .../alerting/unified/testSetup/plugins.ts | 19 +- .../features/alerting/unified/utils/misc.ts | 8 +- 24 files changed, 608 insertions(+), 729 deletions(-) delete mode 100644 public/app/features/alerting/unified/components/rule-viewer/Actions.tsx create mode 100644 public/app/features/alerting/unified/components/rule-viewer/AlertRuleMenu.tsx create mode 100644 public/app/features/alerting/unified/components/rules/RuleActionsButtons.test.tsx delete mode 100644 public/app/features/alerting/unified/components/rules/RuleDetailsActionButtons.tsx create mode 100644 public/app/features/alerting/unified/components/rules/RuleDetailsButtons.tsx create mode 100644 public/app/features/alerting/unified/components/rules/__snapshots__/RuleActionsButtons.test.tsx.snap create mode 100644 public/app/features/alerting/unified/mocks/folders.ts diff --git a/.betterer.results b/.betterer.results index 8509dde739a..a9aa3e106a9 100644 --- a/.betterer.results +++ b/.betterer.results @@ -2011,22 +2011,10 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "5"], [0, 0, 0, "Styles should be written using objects.", "6"] ], - "public/app/features/alerting/unified/components/rules/RuleActionsButtons.tsx:5381": [ - [0, 0, 0, "Styles should be written using objects.", "0"] - ], "public/app/features/alerting/unified/components/rules/RuleConfigStatus.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], [0, 0, 0, "Styles should be written using objects.", "1"] ], - "public/app/features/alerting/unified/components/rules/RuleDetails.tsx:5381": [ - [0, 0, 0, "Styles should be written using objects.", "0"], - [0, 0, 0, "Styles should be written using objects.", "1"], - [0, 0, 0, "Styles should be written using objects.", "2"] - ], - "public/app/features/alerting/unified/components/rules/RuleDetailsActionButtons.tsx:5381": [ - [0, 0, 0, "\'HorizontalGroup\' import from \'@grafana/ui\' is restricted from being used by a pattern. Use Stack component instead.", "0"], - [0, 0, 0, "Styles should be written using objects.", "1"] - ], "public/app/features/alerting/unified/components/rules/RuleDetailsAnnotations.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] ], diff --git a/public/app/features/alerting/unified/RuleList.test.tsx b/public/app/features/alerting/unified/RuleList.test.tsx index 7cac56a2518..85f00b549ff 100644 --- a/public/app/features/alerting/unified/RuleList.test.tsx +++ b/public/app/features/alerting/unified/RuleList.test.tsx @@ -155,7 +155,7 @@ const ui = { paused: byText(/^Paused/), }, actionButtons: { - more: byRole('button', { name: 'More' }), + more: byRole('button', { name: /more-actions/ }), }, moreActionItems: { pause: byRole('menuitem', { name: /pause evaluation/i }), diff --git a/public/app/features/alerting/unified/TODO.md b/public/app/features/alerting/unified/TODO.md index 86e60811548..749ed2e388b 100644 --- a/public/app/features/alerting/unified/TODO.md +++ b/public/app/features/alerting/unified/TODO.md @@ -17,7 +17,6 @@ If the item needs more rationale and you feel like a single sentence is inedequa ## Refactoring - Get rid of "+ Add new" in drop-downs : Let's see if is there a way we can make it work with `