-
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.
Add Locator for Rules page (#155799)
Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
559d928
commit 53daa33
Showing
8 changed files
with
210 additions
and
17 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
55 changes: 55 additions & 0 deletions
55
x-pack/plugins/observability/public/locators/rules.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,55 @@ | ||
/* | ||
* 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 { RulesLocatorDefinition, RULES_PATH } from './rules'; | ||
|
||
describe('RulesLocator', () => { | ||
const locator = new RulesLocatorDefinition(); | ||
|
||
it('should return correct url when empty params are provided', async () => { | ||
const location = await locator.getLocation({}); | ||
expect(location.app).toEqual('observability'); | ||
expect(location.path).toEqual( | ||
`${RULES_PATH}?_a=(lastResponse:!(),params:(),search:'',status:!(),type:!())` | ||
); | ||
}); | ||
|
||
it('should return correct url when lastResponse is provided', async () => { | ||
const location = await locator.getLocation({ lastResponse: ['foo'] }); | ||
expect(location.path).toEqual( | ||
`${RULES_PATH}?_a=(lastResponse:!(foo),params:(),search:'',status:!(),type:!())` | ||
); | ||
}); | ||
|
||
it('should return correct url when params is provided', async () => { | ||
const location = await locator.getLocation({ params: { sloId: 'foo' } }); | ||
expect(location.path).toEqual( | ||
`${RULES_PATH}?_a=(lastResponse:!(),params:(sloId:foo),search:'',status:!(),type:!())` | ||
); | ||
}); | ||
|
||
it('should return correct url when search is provided', async () => { | ||
const location = await locator.getLocation({ search: 'foo' }); | ||
expect(location.path).toEqual( | ||
`${RULES_PATH}?_a=(lastResponse:!(),params:(),search:foo,status:!(),type:!())` | ||
); | ||
}); | ||
|
||
it('should return correct url when status is provided', async () => { | ||
const location = await locator.getLocation({ status: ['enabled'] }); | ||
expect(location.path).toEqual( | ||
`${RULES_PATH}?_a=(lastResponse:!(),params:(),search:'',status:!(enabled),type:!())` | ||
); | ||
}); | ||
|
||
it('should return correct url when type is provided', async () => { | ||
const location = await locator.getLocation({ type: ['foo'] }); | ||
expect(location.path).toEqual( | ||
`${RULES_PATH}?_a=(lastResponse:!(),params:(),search:'',status:!(),type:!(foo))` | ||
); | ||
}); | ||
}); |
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,54 @@ | ||
/* | ||
* 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 type { RuleStatus } from '@kbn/triggers-actions-ui-plugin/public'; | ||
import { rulesLocatorID } from '../../common'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions | ||
export type RulesParams = { | ||
lastResponse?: string[]; | ||
params?: Record<string, string | number>; | ||
search?: string; | ||
status?: RuleStatus[]; | ||
type?: string[]; | ||
}; | ||
|
||
export interface RulesLocatorParams extends RulesParams, SerializableRecord {} | ||
|
||
export const RULES_PATH = '/alerts/rules'; | ||
|
||
export class RulesLocatorDefinition implements LocatorDefinition<RulesLocatorParams> { | ||
public readonly id = rulesLocatorID; | ||
|
||
public readonly getLocation = async ({ | ||
lastResponse = [], | ||
params = {}, | ||
search = '', | ||
status = [], | ||
type = [], | ||
}: RulesLocatorParams) => { | ||
return { | ||
app: 'observability', | ||
path: setStateToKbnUrl( | ||
'_a', | ||
{ | ||
lastResponse, | ||
params, | ||
search, | ||
status, | ||
type, | ||
}, | ||
{ useHash: false, storeInHashQuery: false }, | ||
RULES_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
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