-
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.
[Infra UI] Selectively persist UI state in the url (via container com…
…ponents) (#22980) This PR implements syncing of local redux state to the URL via container components. The persisted pieces of state are: * waffle map time * waffle map auto-reload state * waffle map filter * log scroll position * log live-stream state * log filter * log minimap scale * log text size and wrap
- Loading branch information
1 parent
3773fe2
commit d9f423d
Showing
18 changed files
with
735 additions
and
235 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
50 changes: 0 additions & 50 deletions
50
x-pack/plugins/infra/public/containers/logs/with_log_minimap.ts
This file was deleted.
Oops, something went wrong.
101 changes: 101 additions & 0 deletions
101
x-pack/plugins/infra/public/containers/logs/with_log_minimap.tsx
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,101 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { createSelector } from 'reselect'; | ||
|
||
import { logMinimapActions, logMinimapSelectors, State } from '../../store'; | ||
import { asChildFunctionRenderer } from '../../utils/typed_react'; | ||
import { bindPlainActionCreators } from '../../utils/typed_redux'; | ||
import { UrlStateContainer } from '../../utils/url_state'; | ||
|
||
export const withLogMinimap = connect( | ||
(state: State) => ({ | ||
availableIntervalSizes, | ||
intervalSize: logMinimapSelectors.selectMinimapIntervalSize(state), | ||
urlState: selectMinimapUrlState(state), | ||
}), | ||
bindPlainActionCreators({ | ||
setIntervalSize: logMinimapActions.setMinimapIntervalSize, | ||
}) | ||
); | ||
|
||
export const WithLogMinimap = asChildFunctionRenderer(withLogMinimap); | ||
|
||
export const availableIntervalSizes = [ | ||
{ | ||
label: '1 Year', | ||
intervalSize: 1000 * 60 * 60 * 24 * 365, | ||
}, | ||
{ | ||
label: '1 Month', | ||
intervalSize: 1000 * 60 * 60 * 24 * 30, | ||
}, | ||
{ | ||
label: '1 Week', | ||
intervalSize: 1000 * 60 * 60 * 24 * 7, | ||
}, | ||
{ | ||
label: '1 Day', | ||
intervalSize: 1000 * 60 * 60 * 24, | ||
}, | ||
{ | ||
label: '1 Hour', | ||
intervalSize: 1000 * 60 * 60, | ||
}, | ||
{ | ||
label: '1 Minute', | ||
intervalSize: 1000 * 60, | ||
}, | ||
]; | ||
|
||
/** | ||
* Url State | ||
*/ | ||
|
||
interface LogMinimapUrlState { | ||
intervalSize?: ReturnType<typeof logMinimapSelectors.selectMinimapIntervalSize>; | ||
} | ||
|
||
export const WithLogMinimapUrlState = () => ( | ||
<WithLogMinimap> | ||
{({ urlState, setIntervalSize }) => ( | ||
<UrlStateContainer | ||
urlState={urlState} | ||
urlStateKey="logMinimap" | ||
mapToUrlState={mapToUrlState} | ||
onChange={newUrlState => { | ||
if (newUrlState && newUrlState.intervalSize) { | ||
setIntervalSize(newUrlState.intervalSize); | ||
} | ||
}} | ||
onInitialize={newUrlState => { | ||
if (newUrlState && newUrlState.intervalSize) { | ||
setIntervalSize(newUrlState.intervalSize); | ||
} | ||
}} | ||
/> | ||
)} | ||
</WithLogMinimap> | ||
); | ||
|
||
const mapToUrlState = (value: any): LogMinimapUrlState | undefined => | ||
value | ||
? { | ||
intervalSize: mapToIntervalSizeUrlState(value.intervalSize), | ||
} | ||
: undefined; | ||
|
||
const mapToIntervalSizeUrlState = (value: any) => | ||
value && typeof value === 'number' ? value : undefined; | ||
|
||
const selectMinimapUrlState = createSelector( | ||
logMinimapSelectors.selectMinimapIntervalSize, | ||
intervalSize => ({ | ||
intervalSize, | ||
}) | ||
); |
34 changes: 0 additions & 34 deletions
34
x-pack/plugins/infra/public/containers/logs/with_log_position.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.