-
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
Introduce redux state management for react portion of dashboard #14199
Closed
stacey-gammon
wants to merge
25
commits into
elastic:master
from
stacey-gammon:chore/dashboard-redux
Closed
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
46e57c5
Introduce redux state management for react portion of dashboard
stacey-gammon 11cad7f
Use redux-actions and redux-thunks to reduce boilerplate
stacey-gammon 461c4ed
Make sure all panels are minimized from the start when a dashboard is…
stacey-gammon 63d3e2f
Remove unused file
stacey-gammon 338be97
use classnames dependency instead of manual logic
stacey-gammon 11b9b37
First pass on selectors, handleActions, and more segmented reducers.
stacey-gammon e1d095f
Merge branch 'master' of https://github.com/elastic/kibana into chore…
stacey-gammon beae05e
Fix bugs with selectors and reducers and add tests that would have ca…
stacey-gammon abae5fb
merge with master
stacey-gammon 544875c
Merge branch 'master' of https://github.com/elastic/kibana into chore…
stacey-gammon d77c0ee
Fix issue plus tests
stacey-gammon e7bf212
Make expanding a panel purely a css modification which avoids all re-…
stacey-gammon 3c20f1d
Found another bug with initial state not being set correctly on a har…
stacey-gammon 608a099
Merge branch 'master' of https://github.com/elastic/kibana into chore…
stacey-gammon 802c34c
Remove check for change handlers now that the event handler bug is fixed
stacey-gammon 3f84212
rename dashboardState => dashboard for reducers and redux state tree
stacey-gammon c6c5a9d
Remove unnecessary top level describe in jest tests
stacey-gammon d20bba2
Navigate back to landing page at the end of the newly added test suite
stacey-gammon 4e884a4
Fix lint errors
stacey-gammon e4de737
Stabilize flaky tests by waiting until saved object search is finishe…
stacey-gammon 76034f8
use spread operator over object.assign
stacey-gammon 3b3ccf9
Don't leak subscriptions to the store.
stacey-gammon 3175061
use selectors to grab dashboard panel off state.
stacey-gammon fe86a5c
Remove use of getState in dispatcher to avoid circular reference and …
stacey-gammon 025a62e
Merge with master
stacey-gammon 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
10 changes: 10 additions & 0 deletions
10
src/core_plugins/kibana/public/dashboard/__tests__/get_container_api_mock.js
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,10 @@ | ||
export function getContainerApiMock(config = {}) { | ||
const containerApiMockDefaults = { | ||
addFilter: () => {}, | ||
getAppState: () => {}, | ||
createChildUistate: () => {}, | ||
registerPanelIndexPattern: () => {}, | ||
updatePanel: () => {} | ||
}; | ||
return Object.assign(containerApiMockDefaults, config); | ||
} |
8 changes: 8 additions & 0 deletions
8
src/core_plugins/kibana/public/dashboard/__tests__/get_embeddable_handlers_mock.js
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,8 @@ | ||
export function getEmbeddableHandlerMock(config) { | ||
const embeddableHandlerMockDefaults = { | ||
getEditPath: () => {}, | ||
getTitleFor: () => {}, | ||
render: jest.fn() | ||
}; | ||
return Object.assign(embeddableHandlerMockDefaults, config); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/core_plugins/kibana/public/dashboard/actions/embeddables.js
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,40 @@ | ||
import { createAction } from 'redux-actions'; | ||
|
||
export const destroyEmbeddable = | ||
createAction('DESTROY_EMBEDDABLE', (panelId, embeddableHandler) => { | ||
if (embeddableHandler) { | ||
embeddableHandler.destroy(panelId); | ||
} | ||
return panelId; | ||
}); | ||
|
||
export const embeddableRenderFinished = | ||
createAction('EMBEDDABLE_RENDER_FINISHED', (panelId, embeddable) => ({ embeddable, panelId })); | ||
|
||
export const embeddableRenderError = | ||
createAction('EMBEDDABLE_RENDER_ERROR', (panelId, error) => ({ panelId, error })); | ||
|
||
/** | ||
* | ||
* @param embeddableHandler {EmbeddableHandler} | ||
* @param panelElement {Node} | ||
* @param panel {PanelState} | ||
* @param containerApi {ContainerAPI} | ||
* @return {function(*, *)} | ||
*/ | ||
export function renderEmbeddable(embeddableHandler, panelElement, panel, containerApi) { | ||
return (dispatch) => { | ||
if (!embeddableHandler) { | ||
dispatch(embeddableRenderError(panel.panelIndex, new Error(`Invalid embeddable type "${panel.type}"`))); | ||
return; | ||
} | ||
|
||
return embeddableHandler.render(panelElement, panel, containerApi) | ||
.then(embeddable => { | ||
return dispatch(embeddableRenderFinished(panel.panelIndex, embeddable)); | ||
}) | ||
.catch(error => { | ||
dispatch(embeddableRenderError(panel.panelIndex, error)); | ||
}); | ||
}; | ||
} |
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,19 @@ | ||
export { | ||
updateViewMode, | ||
updateIsFullScreenMode, | ||
minimizePanel, | ||
maximizePanel | ||
} from './view'; | ||
|
||
export { | ||
updatePanel, | ||
updatePanels, | ||
deletePanel, | ||
} from './panels'; | ||
|
||
export { | ||
renderEmbeddable, | ||
embeddableRenderFinished, | ||
embeddableRenderError, | ||
destroyEmbeddable, | ||
} from './embeddables'; |
17 changes: 17 additions & 0 deletions
17
src/core_plugins/kibana/public/dashboard/actions/panels.js
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,17 @@ | ||
import { createAction } from 'redux-actions'; | ||
|
||
export const deletePanel = createAction('DELETE_PANEL', panelId => panelId); | ||
|
||
export const updatePanel = createAction('UPDATE_PANEL', panel => panel); | ||
|
||
/** | ||
* @param panels {Array<PanelState>} | ||
* @return {Object} | ||
*/ | ||
export const updatePanels = createAction('UPDATE_PANELS', panels => { | ||
const panelsMap = {}; | ||
panels.forEach(panel => { | ||
panelsMap[panel.panelIndex] = panel; | ||
}); | ||
return panelsMap; | ||
}); |
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,6 @@ | ||
import { createAction } from 'redux-actions'; | ||
|
||
export const updateViewMode = createAction('UPDATE_VIEW_MODE', viewMode => viewMode); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment in the panels actions; all of these action creators don't need to the second argument. |
||
export const maximizePanel = createAction('MAXIMIZE_PANEl', maximizedPanelId => maximizedPanelId); | ||
export const minimizePanel = createAction('MINIMIZE_PANEL', () => {}); | ||
export const updateIsFullScreenMode = createAction('UPDATE_IS_FULL_SCREEN_MODE', isFullScreenMode => isFullScreenMode); |
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.
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.
This is not required, the default function in
createAction
is_.indentity
, so you can simply write this (and other actions like this that simply pass there parameters to the reducer) like so:The only time you need to provide the function is if you need to map multiple arguments into a single object, or otherwise do something with the action's arguments before passing the values to the reducer (as you do below).