-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Infra UI] Selectively persist UI state in the url (via container components) #22980
Merged
weltenwort
merged 8 commits into
elastic:feature-infra-ui
from
weltenwort:infra-ui-enhancement-add-url-sync-container
Sep 18, 2018
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7b18970
Only show autocomplete suggestions when focused
weltenwort c75c6f2
Prevent angular-route from reloading on URL state sync
weltenwort b93c8ee
Add container component to sync store to url
weltenwort 5298056
Sync local waffle filter and time state to url
weltenwort 5505525
Sync log scroll, filter and minimap state to url
weltenwort 694461e
Merge text scale and wrap containers into one
weltenwort 272bb73
Sync text scale and wrap state to url
weltenwort a3e1097
Move url state container types annotation
weltenwort File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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<LogMinimapUrlState> | ||
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) => | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mixing TS generics and JSX together reads weird. Can you assign that to a variable then just use the variable? I haven't tried that before so I'm not sure if it will work but it if it does it might make it more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately that is not easily possible. The generic type argument has to be passed at instantiation time, which is handled by JSX. If I would convert the
UrlStateContainer
component into a class-based component, a no-op inheritance could nail down the type. Alternatively, we could manually type the passed properties sufficiently so the inference figures it out. Typing the return type ofmapToUrlState
should do it. Would you think that improves the situation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... that's a lot easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, change coming up...