-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Actionable Observability] Add rule details locator and make AlertSum…
…maryWidget clickable (#147103) Resolves #141467 ## 📝 Summary - Added a [locator](https://docs.elastic.dev/kibana-dev-docs/routing-and-navigation#specifying-state) for the rule details page - Made AlertSummaryWidget clickable and implemented the related navigation for rule details page ## 🧪 How to test - Create a rule and go to the rule details page - You should be able to click on all/active/recovered sections in Alert Summary Widget and upon click going to alert tables with the correct filter https://user-images.githubusercontent.com/12370520/205959565-6c383910-763f-4214-9baa-cf191f012de9.mp4
- Loading branch information
1 parent
313537c
commit a30d225
Showing
14 changed files
with
244 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
x-pack/plugins/observability/public/locators/rule_details.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ACTIVE_ALERTS } from '../components/shared/alert_search_bar/constants'; | ||
import { EXECUTION_TAB, ALERTS_TAB } from '../pages/rule_details/constants'; | ||
import { getRuleDetailsPath, RuleDetailsLocatorDefinition } from './rule_details'; | ||
|
||
describe('RuleDetailsLocator', () => { | ||
const locator = new RuleDetailsLocatorDefinition(); | ||
const mockedRuleId = '389d3318-7e10-4996-bb45-128e1607fb7e'; | ||
|
||
it('should return correct url when only ruleId is provided', async () => { | ||
const location = await locator.getLocation({ ruleId: mockedRuleId }); | ||
expect(location.app).toEqual('observability'); | ||
expect(location.path).toEqual(getRuleDetailsPath(mockedRuleId)); | ||
}); | ||
|
||
it('should return correct url when tabId is execution', async () => { | ||
const location = await locator.getLocation({ ruleId: mockedRuleId, tabId: EXECUTION_TAB }); | ||
expect(location.path).toMatchInlineSnapshot( | ||
`"/alerts/rules/389d3318-7e10-4996-bb45-128e1607fb7e?tabId=execution"` | ||
); | ||
}); | ||
|
||
it('should return correct url when tabId is alerts without extra search params', async () => { | ||
const location = await locator.getLocation({ ruleId: mockedRuleId, tabId: ALERTS_TAB }); | ||
expect(location.path).toMatchInlineSnapshot( | ||
`"/alerts/rules/389d3318-7e10-4996-bb45-128e1607fb7e?tabId=alerts&searchBarParams=(kuery:'',rangeFrom:now-15m,rangeTo:now,status:all)"` | ||
); | ||
}); | ||
|
||
it('should return correct url when tabId is alerts with search params', async () => { | ||
const location = await locator.getLocation({ | ||
ruleId: mockedRuleId, | ||
tabId: ALERTS_TAB, | ||
rangeFrom: 'mockedRangeTo', | ||
rangeTo: 'mockedRangeFrom', | ||
kuery: 'mockedKuery', | ||
status: ACTIVE_ALERTS.status, | ||
}); | ||
expect(location.path).toMatchInlineSnapshot( | ||
`"/alerts/rules/389d3318-7e10-4996-bb45-128e1607fb7e?tabId=alerts&searchBarParams=(kuery:mockedKuery,rangeFrom:mockedRangeTo,rangeTo:mockedRangeFrom,status:active)"` | ||
); | ||
}); | ||
}); |
72 changes: 72 additions & 0 deletions
72
x-pack/plugins/observability/public/locators/rule_details.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { setStateToKbnUrl } from '@kbn/kibana-utils-plugin/public'; | ||
import type { SerializableRecord } from '@kbn/utility-types'; | ||
import type { LocatorDefinition } from '@kbn/share-plugin/public'; | ||
import { ruleDetailsLocatorID } from '../../common'; | ||
import { ALL_ALERTS } from '../components/shared/alert_search_bar/constants'; | ||
import { | ||
ALERTS_TAB, | ||
EXECUTION_TAB, | ||
SEARCH_BAR_URL_STORAGE_KEY, | ||
} from '../pages/rule_details/constants'; | ||
import type { TabId } from '../pages/rule_details/types'; | ||
import type { AlertStatus } from '../../common/typings'; | ||
|
||
export interface RuleDetailsLocatorParams extends SerializableRecord { | ||
ruleId: string; | ||
tabId?: TabId; | ||
rangeFrom?: string; | ||
rangeTo?: string; | ||
kuery?: string; | ||
status?: AlertStatus; | ||
} | ||
|
||
export const getRuleDetailsPath = (ruleId: string) => { | ||
return `/alerts/rules/${encodeURI(ruleId)}`; | ||
}; | ||
|
||
export class RuleDetailsLocatorDefinition implements LocatorDefinition<RuleDetailsLocatorParams> { | ||
public readonly id = ruleDetailsLocatorID; | ||
|
||
public readonly getLocation = async (params: RuleDetailsLocatorParams) => { | ||
const { ruleId, kuery, rangeTo, tabId, rangeFrom, status } = params; | ||
const appState: { | ||
tabId?: TabId; | ||
rangeFrom?: string; | ||
rangeTo?: string; | ||
kuery?: string; | ||
status?: AlertStatus; | ||
} = {}; | ||
|
||
appState.rangeFrom = rangeFrom || 'now-15m'; | ||
appState.rangeTo = rangeTo || 'now'; | ||
appState.kuery = kuery || ''; | ||
appState.status = status || ALL_ALERTS.status; | ||
|
||
let path = getRuleDetailsPath(ruleId); | ||
|
||
if (tabId === ALERTS_TAB) { | ||
path = `${path}?tabId=${tabId}`; | ||
path = setStateToKbnUrl( | ||
SEARCH_BAR_URL_STORAGE_KEY, | ||
appState, | ||
{ useHash: false, storeInHashQuery: false }, | ||
path | ||
); | ||
} else if (tabId === EXECUTION_TAB) { | ||
path = `${path}?tabId=${tabId}`; | ||
} | ||
|
||
return { | ||
app: 'observability', | ||
path, | ||
state: {}, | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.