Skip to content

Commit 4d565be

Browse files
committed
[canvas] fix embeddables not refreshing on manual refresh or auto-refresh (elastic#221326)
Fixes elastic#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]> (cherry picked from commit e937e91) # Conflicts: # x-pack/platform/plugins/private/canvas/public/components/hooks/use_canvas_api.tsx # x-pack/plugins/canvas/types/embeddables.ts
1 parent a56b543 commit 4d565be

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import { getSelectedPage } from '../../state/selectors/workpad';
2121

2222
const reload$ = new Subject<void>();
2323

24+
export function forceReload() {
25+
reload$.next();
26+
}
27+
2428
export const useCanvasApi: () => CanvasContainerApi = () => {
2529
const selectedPageId = useSelector(getSelectedPage);
2630
const dispatch = useDispatch();
@@ -41,9 +45,6 @@ export const useCanvasApi: () => CanvasContainerApi = () => {
4145
const getCanvasApi = useCallback((): CanvasContainerApi => {
4246
return {
4347
reload$,
44-
reload: () => {
45-
reload$.next();
46-
},
4748
viewMode: new BehaviorSubject<ViewMode>('edit'), // always in edit mode
4849
addNewPanel: async ({
4950
panelType,

x-pack/plugins/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/plugins/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/plugins/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/plugins/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/plugins/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/plugins/canvas/types/embeddables.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,4 @@ export type CanvasContainerApi = PublishesViewMode &
3030
HasType &
3131
HasSerializedChildState &
3232
PublishesReload &
33-
Partial<HasAppContext & PublishesUnifiedSearch> & {
34-
reload: () => void;
35-
};
33+
Partial<HasAppContext & PublishesUnifiedSearch>;

0 commit comments

Comments
 (0)