Skip to content

Commit e937e91

Browse files
[canvas] fix embeddables not refreshing on manual refresh or auto-refresh (#221326)
Fixes #221321 ### test instructions 1) install sample web logs 2) import canvas saved object https://github.com/nreese/notes/blob/master/empty-canvas-workpad-saved-object-export.ndjson 3) refresh kibana 4) open canvas and add map embeddable 5) open browser network tab 6) click "Refresh data" button. Verify map requests new data 7) open "View" menu. Click "Refresh data". Verify map requests new data 8) set auto internal to "5s". Verify map requests new data on each interval --------- Co-authored-by: Elastic Machine <[email protected]>
1 parent c87ff28 commit e937e91

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

x-pack/platform/plugins/private/canvas/public/components/hooks/use_canvas_api.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ import { getSelectedPage } from '../../state/selectors/workpad';
2020
import { CANVAS_APP } from '../../../common/lib';
2121
import { coreServices } from '../../services/kibana_services';
2222

23+
const reload$ = new Subject<void>();
24+
25+
export function forceReload() {
26+
reload$.next();
27+
}
28+
2329
export const useCanvasApi: () => CanvasContainerApi = () => {
2430
const selectedPageId = useSelector(getSelectedPage);
2531
const dispatch = useDispatch();
@@ -39,7 +45,6 @@ export const useCanvasApi: () => CanvasContainerApi = () => {
3945

4046
const getCanvasApi = useCallback((): CanvasContainerApi => {
4147
const panelStateMap: Record<string, BehaviorSubject<SerializedPanelState<object>>> = {};
42-
const reload$ = new Subject<void>();
4348

4449
function getSerializedStateForChild(childId: string) {
4550
return panelStateMap[childId]?.value ?? { rawState: {} };
@@ -55,9 +60,6 @@ export const useCanvasApi: () => CanvasContainerApi = () => {
5560
currentAppId: CANVAS_APP,
5661
}),
5762
reload$,
58-
reload: () => {
59-
reload$.next();
60-
},
6163
viewMode$: new BehaviorSubject<ViewMode>('edit'), // always in edit mode
6264
addNewPanel: async ({
6365
panelType,

x-pack/platform/plugins/private/canvas/public/components/workpad/workpad_shortcuts.component.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import React from 'react';
99
import { Shortcuts } from 'react-shortcuts';
1010
import { isTextInput } from '../../lib/is_text_input';
1111
import { Props } from './workpad.component';
12+
import { forceReload } from '../hooks/use_canvas_api';
1213

1314
type ShortcutProps = Pick<
1415
Props,
@@ -69,7 +70,10 @@ export class WorkpadShortcuts extends React.Component<ShortcutProps> {
6970

7071
// handle keypress events for editor events
7172
_keyMap: Shortcuts = {
72-
REFRESH: this.props.fetchAllRenderables,
73+
REFRESH: () => {
74+
forceReload();
75+
this.props.fetchAllRenderables();
76+
},
7377
UNDO: this.props.undoHistory,
7478
REDO: this.props.redoHistory,
7579
GRID: () => this.props.setGrid(!this.props.grid),

x-pack/platform/plugins/private/canvas/public/components/workpad_header/fullscreen_control/fullscreen_control.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import PropTypes from 'prop-types';
1010
// @ts-expect-error no @types definition
1111
import { Shortcuts } from 'react-shortcuts';
1212
import { isTextInput } from '../../../lib/is_text_input';
13+
import { forceReload } from '../../hooks/use_canvas_api';
1314

1415
interface ChildrenProps {
1516
isFullscreen: boolean;
@@ -64,7 +65,10 @@ export class FullscreenControl extends React.PureComponent<Props> {
6465

6566
// handle keypress events for presentation events
6667
_keyMap: { [key: string]: (...args: any[]) => void } = {
67-
REFRESH: this.props.fetchAllRenderables,
68+
REFRESH: () => {
69+
forceReload();
70+
this.props.fetchAllRenderables();
71+
},
6872
PREV: this.previousPage,
6973
NEXT: this.nextPage,
7074
FULLSCREEN: this._toggleFullscreen,

x-pack/platform/plugins/private/canvas/public/components/workpad_header/refresh_control/refresh_control.component.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useDispatch, useSelector } from 'react-redux';
1515
import { fetchAllRenderables } from '../../../state/actions/elements';
1616
import { getInFlight } from '../../../state/selectors/resolved_args';
1717
import { ToolTipShortcut } from '../../tool_tip_shortcut';
18-
import { useCanvasApi } from '../../hooks/use_canvas_api';
18+
import { forceReload } from '../../hooks/use_canvas_api';
1919

2020
const strings = {
2121
getRefreshAriaLabel: () =>
@@ -31,11 +31,10 @@ const strings = {
3131
export const RefreshControl = () => {
3232
const dispatch = useDispatch();
3333
const inFlight = useSelector(getInFlight);
34-
const canvasApi = useCanvasApi();
3534
const doRefresh = useCallback(() => {
36-
canvasApi.reload();
35+
forceReload();
3736
dispatch(fetchAllRenderables());
38-
}, [canvasApi, dispatch]);
37+
}, [dispatch]);
3938

4039
return (
4140
<EuiToolTip

x-pack/platform/plugins/private/canvas/public/components/workpad_header/view_menu/view_menu.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { WorkpadRoutingContext } from '../../../routes/workpad';
2626
import { ViewMenu as Component, Props as ComponentProps } from './view_menu.component';
2727
import { getFitZoomScale } from './lib/get_fit_zoom_scale';
28+
import { forceReload } from '../../hooks/use_canvas_api';
2829

2930
interface StateProps {
3031
zoomScale: number;
@@ -61,7 +62,10 @@ const mapStateToProps = (state: State) => {
6162
const mapDispatchToProps = (dispatch: Dispatch) => ({
6263
setZoomScale: (scale: number) => dispatch(setZoomScale(scale)),
6364
setWriteable: (isWorkpadWriteable: boolean) => dispatch(setWriteable(isWorkpadWriteable)),
64-
doRefresh: () => dispatch(fetchAllRenderables()),
65+
doRefresh: () => {
66+
forceReload();
67+
dispatch(fetchAllRenderables());
68+
},
6569
});
6670

6771
const mergeProps = (

x-pack/platform/plugins/private/canvas/public/routes/workpad/hooks/use_refresh_helper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { WorkpadRoutingContext } from '../workpad_routing_context';
1111
import { getInFlight } from '../../../state/selectors/resolved_args';
1212
// @ts-expect-error untyped local
1313
import { fetchAllRenderables } from '../../../state/actions/elements';
14+
import { forceReload } from '../../../components/hooks/use_canvas_api';
1415

1516
export const useRefreshHelper = () => {
1617
const dispatch = useDispatch();
@@ -25,6 +26,7 @@ export const useRefreshHelper = () => {
2526

2627
if (refreshInterval > 0 && !inFlight) {
2728
timer.current = window.setTimeout(() => {
29+
forceReload();
2830
dispatch(fetchAllRenderables());
2931
}, refreshInterval);
3032
}

x-pack/platform/plugins/private/canvas/types/embeddables.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@ export type CanvasContainerApi = PublishesViewMode &
3131
Partial<PublishesUnifiedSearch> &
3232
Partial<HasAppContext & PublishesUnifiedSearch> & {
3333
setSerializedStateForChild: (childId: string, panelState: SerializedPanelState<object>) => void;
34-
reload: () => void;
3534
};

0 commit comments

Comments
 (0)