forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(slo): add slo list page locator (elastic#169453)
- Loading branch information
Showing
7 changed files
with
148 additions
and
51 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
30 changes: 30 additions & 0 deletions
30
x-pack/plugins/observability/public/locators/slo_list.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,30 @@ | ||
/* | ||
* 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 { SloListLocatorDefinition } from './slo_list'; | ||
|
||
describe('SloListLocator', () => { | ||
const locator = new SloListLocatorDefinition(); | ||
|
||
it("returns the correct url with the default search state when no 'kqlQuery' provided", async () => { | ||
const location = await locator.getLocation({}); | ||
expect(location.app).toEqual('observability'); | ||
expect(location.path).toEqual( | ||
"/slos?search=(kqlQuery:'',page:0,sort:(by:status,direction:desc))" | ||
); | ||
}); | ||
|
||
it("returns the correct url with the 'kqlQuery' provided", async () => { | ||
const location = await locator.getLocation({ | ||
kqlQuery: 'slo.name: "Service Availability" and slo.indicator.type : "sli.kql.custom"', | ||
}); | ||
expect(location.app).toEqual('observability'); | ||
expect(location.path).toEqual( | ||
"/slos?search=(kqlQuery:'slo.name:%20%22Service%20Availability%22%20and%20slo.indicator.type%20:%20%22sli.kql.custom%22',page:0,sort:(by:status,direction:desc))" | ||
); | ||
}); | ||
}); |
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,44 @@ | ||
/* | ||
* 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 { LocatorDefinition } from '@kbn/share-plugin/public'; | ||
import type { SerializableRecord } from '@kbn/utility-types'; | ||
import deepmerge from 'deepmerge'; | ||
import { sloListLocatorID } from '../../common'; | ||
import { SLOS_PATH } from '../../common/locators/paths'; | ||
import { | ||
DEFAULT_STATE, | ||
SearchState, | ||
SLO_LIST_SEARCH_URL_STORAGE_KEY, | ||
} from '../pages/slos/hooks/use_url_search_state'; | ||
|
||
export interface SloListLocatorParams extends SerializableRecord { | ||
kqlQuery?: string; | ||
} | ||
|
||
export class SloListLocatorDefinition implements LocatorDefinition<SloListLocatorParams> { | ||
public readonly id = sloListLocatorID; | ||
|
||
public readonly getLocation = async ({ kqlQuery = '' }: SloListLocatorParams) => { | ||
const state: SearchState = deepmerge<SearchState>(DEFAULT_STATE, { kqlQuery }); | ||
|
||
return { | ||
app: 'observability', | ||
path: setStateToKbnUrl( | ||
SLO_LIST_SEARCH_URL_STORAGE_KEY, | ||
state, | ||
{ | ||
useHash: false, | ||
storeInHashQuery: false, | ||
}, | ||
SLOS_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