-
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
Changes from 3 commits
46e57c5
11cad7f
461c4ed
63d3e2f
338be97
11b9b37
e1d095f
beae05e
abae5fb
544875c
d77c0ee
e7bf212
3c20f1d
608a099
802c34c
3f84212
c6c5a9d
d20bba2
4e884a4
e4de737
76034f8
3b3ccf9
3175061
fe86a5c
025a62e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} |
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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export { | ||
updateViewMode, | ||
updateIsFullScreenMode, | ||
minimizePanel, | ||
maximizePanel | ||
} from './view'; | ||
|
||
export { | ||
updatePanel, | ||
updatePanels, | ||
renderEmbeddable, | ||
embeddableRenderFinished, | ||
embeddableRenderError, | ||
deletePanel, | ||
} from './panels'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { createAction } from 'redux-actions'; | ||
|
||
export const deletePanel = createAction('DELETE_PANEL', panelId => panelId); | ||
|
||
export const embeddableRenderFinished = | ||
createAction('EMBEDDABLE_RENDER_FINISHED', (panelId, embeddable) => ({ embeddable, panelId })); | ||
|
||
export const embeddableRenderError = | ||
createAction('EMBEDDABLE_RENDER_ERROR', (panelId, error) => ({ panelId, error })); | ||
|
||
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; | ||
}); | ||
|
||
/** | ||
* | ||
* @param embeddableHandler {EmbeddableHandler} | ||
* @param panelElement {Node} | ||
* @param panelId {string} | ||
* @param containerApi {ContainerAPI} | ||
* @return {function(*, *)} | ||
*/ | ||
export function renderEmbeddable(embeddableHandler, panelElement, panelId, containerApi) { | ||
return (dispatch, getState) => { | ||
const { dashboardState } = getState(); | ||
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. In general 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. I definitely understand the sentiment, but I ran into this same pattern and the reason I wanted to stick with Any thoughts on that? 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. Why is a re-render a problem? If this state updates multiple times per second, I might agree (though, I'd likely push towards implementing a 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. Nothing inherently wrong, but just felt off to do it that way. I definitely understand the hesitation around calling 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. I'm inclined to agree with @chrisronline on this one, though perhaps because it makes my life easier. If the only reason your putting a prop in a component is to pass it to a function, which goes back to the container, seems like an unnecessary loop. I was actually surprised I couldn't get the state inside of
But because I couldn't do that, I just pushed the Seems silly to make the DashboardPanelContainer require panel as a prop instead of just panelId. But, that's just my gut feel. 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. You can try messing with the |
||
const panelState = dashboardState.panels[panelId]; | ||
|
||
if (!embeddableHandler) { | ||
dispatch(embeddableRenderError(panelId, new Error(`Invalid embeddable type "${panelState.type}"`))); | ||
return; | ||
} | ||
|
||
return embeddableHandler.render(panelElement, panelState, containerApi) | ||
.then(embeddable => { | ||
return dispatch(embeddableRenderFinished(panelId, embeddable)); | ||
}) | ||
.catch(error => { | ||
dispatch(embeddableRenderError(panelId, error)); | ||
}); | ||
}; | ||
} |
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); |
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).