-
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.
[Logs+] Replace usages of link-to routes in infra server (#158994)
closes [#157985](#157985) ## 📝 Summary This PR moves the previously implemented [infra locators](#155156) to infra common and replaces the last usage of `link-to` routes in the infra public with the appropriate locator. ## ✅ Testing 1. Navigate to Observability Alerts 2. Create a new Log Threshold Rule that should fire 3. Open the alert details flyout 4. Click on the `View in app` button 5. Should correctly navigate to Stream view or Discover in case of serverless. * All other links to Logs should still work properly as before as well https://github.com/elastic/kibana/assets/11225826/9af85ea6-5fdd-4505-9707-6489b760f311
- Loading branch information
1 parent
52f3113
commit 3785c93
Showing
37 changed files
with
242 additions
and
255 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
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
File renamed without changes.
File renamed without changes.
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
89 changes: 89 additions & 0 deletions
89
x-pack/plugins/infra/common/log_views/url_state_storage_service.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,89 @@ | ||
/* | ||
* 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 { url } from '@kbn/kibana-utils-plugin/common'; | ||
import { encode } from '@kbn/rison'; | ||
import type { Query } from '@kbn/es-query'; | ||
import { parse, stringify } from 'query-string'; | ||
import moment, { DurationInputObject } from 'moment'; | ||
import type { FilterStateInUrl } from '../../public/observability_logs/log_stream_query_state'; | ||
import type { PositionStateInUrl } from '../../public/observability_logs/log_stream_position_state/src/url_state_storage_service'; | ||
import { | ||
defaultFilterStateKey, | ||
defaultPositionStateKey, | ||
DEFAULT_REFRESH_INTERVAL, | ||
LogViewReference, | ||
} from '.'; | ||
import type { TimeRange } from '../time'; | ||
|
||
export const defaultLogViewKey = 'logView'; | ||
|
||
const encodeRisonUrlState = (state: any) => encode(state); | ||
|
||
// Used by linkTo components | ||
export const replaceLogPositionInQueryString = (time?: number) => | ||
Number.isNaN(time) || time == null | ||
? (value: string) => value | ||
: replaceStateKeyInQueryString<PositionStateInUrl>(defaultPositionStateKey, { | ||
position: { | ||
time, | ||
tiebreaker: 0, | ||
}, | ||
}); | ||
|
||
// NOTE: Used by link-to components | ||
export const replaceLogViewInQueryString = (logViewReference: LogViewReference) => | ||
replaceStateKeyInQueryString(defaultLogViewKey, logViewReference); | ||
|
||
export const replaceStateKeyInQueryString = | ||
<UrlState extends any>(stateKey: string, urlState: UrlState | undefined) => | ||
(queryString: string) => { | ||
const previousQueryValues = parse(queryString, { sort: false }); | ||
const newValue = | ||
typeof urlState === 'undefined' | ||
? previousQueryValues | ||
: { | ||
...previousQueryValues, | ||
[stateKey]: encodeRisonUrlState(urlState), | ||
}; | ||
return stringify(url.encodeQuery(newValue), { sort: false, encode: false }); | ||
}; | ||
|
||
export const replaceLogFilterInQueryString = (query: Query, time?: number, timeRange?: TimeRange) => | ||
replaceStateKeyInQueryString<FilterStateInUrl>(defaultFilterStateKey, { | ||
query, | ||
...getTimeRange(time, timeRange), | ||
refreshInterval: DEFAULT_REFRESH_INTERVAL, | ||
}); | ||
|
||
const getTimeRange = (time?: number, timeRange?: TimeRange) => { | ||
if (timeRange) { | ||
return { | ||
timeRange: { | ||
from: new Date(timeRange.startTime).toISOString(), | ||
to: new Date(timeRange.endTime).toISOString(), | ||
}, | ||
}; | ||
} else if (time) { | ||
return { | ||
timeRange: { | ||
from: getTimeRangeStartFromTime(time), | ||
to: getTimeRangeEndFromTime(time), | ||
}, | ||
}; | ||
} else { | ||
return {}; | ||
} | ||
}; | ||
|
||
const defaultTimeRangeFromPositionOffset: DurationInputObject = { hours: 1 }; | ||
|
||
export const getTimeRangeStartFromTime = (time: number): string => | ||
moment(time).subtract(defaultTimeRangeFromPositionOffset).toISOString(); | ||
|
||
export const getTimeRangeEndFromTime = (time: number): string => | ||
moment(time).add(defaultTimeRangeFromPositionOffset).toISOString(); |
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.