File tree 7 files changed +26
-12
lines changed
x-pack/platform/plugins/private/canvas
7 files changed +26
-12
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,12 @@ import { getSelectedPage } from '../../state/selectors/workpad';
20
20
import { CANVAS_APP } from '../../../common/lib' ;
21
21
import { coreServices } from '../../services/kibana_services' ;
22
22
23
+ const reload$ = new Subject < void > ( ) ;
24
+
25
+ export function forceReload ( ) {
26
+ reload$ . next ( ) ;
27
+ }
28
+
23
29
export const useCanvasApi : ( ) => CanvasContainerApi = ( ) => {
24
30
const selectedPageId = useSelector ( getSelectedPage ) ;
25
31
const dispatch = useDispatch ( ) ;
@@ -39,7 +45,6 @@ export const useCanvasApi: () => CanvasContainerApi = () => {
39
45
40
46
const getCanvasApi = useCallback ( ( ) : CanvasContainerApi => {
41
47
const panelStateMap : Record < string , BehaviorSubject < SerializedPanelState < object > > > = { } ;
42
- const reload$ = new Subject < void > ( ) ;
43
48
44
49
function getSerializedStateForChild ( childId : string ) {
45
50
return panelStateMap [ childId ] ?. value ?? { rawState : { } } ;
@@ -55,9 +60,6 @@ export const useCanvasApi: () => CanvasContainerApi = () => {
55
60
currentAppId : CANVAS_APP ,
56
61
} ) ,
57
62
reload$,
58
- reload : ( ) => {
59
- reload$ . next ( ) ;
60
- } ,
61
63
viewMode$ : new BehaviorSubject < ViewMode > ( 'edit' ) , // always in edit mode
62
64
addNewPanel : async ( {
63
65
panelType,
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import React from 'react';
9
9
import { Shortcuts } from 'react-shortcuts' ;
10
10
import { isTextInput } from '../../lib/is_text_input' ;
11
11
import { Props } from './workpad.component' ;
12
+ import { forceReload } from '../hooks/use_canvas_api' ;
12
13
13
14
type ShortcutProps = Pick <
14
15
Props ,
@@ -69,7 +70,10 @@ export class WorkpadShortcuts extends React.Component<ShortcutProps> {
69
70
70
71
// handle keypress events for editor events
71
72
_keyMap : Shortcuts = {
72
- REFRESH : this . props . fetchAllRenderables ,
73
+ REFRESH : ( ) => {
74
+ forceReload ( ) ;
75
+ this . props . fetchAllRenderables ( ) ;
76
+ } ,
73
77
UNDO : this . props . undoHistory ,
74
78
REDO : this . props . redoHistory ,
75
79
GRID : ( ) => this . props . setGrid ( ! this . props . grid ) ,
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import PropTypes from 'prop-types';
10
10
// @ts -expect-error no @types definition
11
11
import { Shortcuts } from 'react-shortcuts' ;
12
12
import { isTextInput } from '../../../lib/is_text_input' ;
13
+ import { forceReload } from '../../hooks/use_canvas_api' ;
13
14
14
15
interface ChildrenProps {
15
16
isFullscreen : boolean ;
@@ -64,7 +65,10 @@ export class FullscreenControl extends React.PureComponent<Props> {
64
65
65
66
// handle keypress events for presentation events
66
67
_keyMap : { [ key : string ] : ( ...args : any [ ] ) => void } = {
67
- REFRESH : this . props . fetchAllRenderables ,
68
+ REFRESH : ( ) => {
69
+ forceReload ( ) ;
70
+ this . props . fetchAllRenderables ( ) ;
71
+ } ,
68
72
PREV : this . previousPage ,
69
73
NEXT : this . nextPage ,
70
74
FULLSCREEN : this . _toggleFullscreen ,
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ import { useDispatch, useSelector } from 'react-redux';
15
15
import { fetchAllRenderables } from '../../../state/actions/elements' ;
16
16
import { getInFlight } from '../../../state/selectors/resolved_args' ;
17
17
import { ToolTipShortcut } from '../../tool_tip_shortcut' ;
18
- import { useCanvasApi } from '../../hooks/use_canvas_api' ;
18
+ import { forceReload } from '../../hooks/use_canvas_api' ;
19
19
20
20
const strings = {
21
21
getRefreshAriaLabel : ( ) =>
@@ -31,11 +31,10 @@ const strings = {
31
31
export const RefreshControl = ( ) => {
32
32
const dispatch = useDispatch ( ) ;
33
33
const inFlight = useSelector ( getInFlight ) ;
34
- const canvasApi = useCanvasApi ( ) ;
35
34
const doRefresh = useCallback ( ( ) => {
36
- canvasApi . reload ( ) ;
35
+ forceReload ( ) ;
37
36
dispatch ( fetchAllRenderables ( ) ) ;
38
- } , [ canvasApi , dispatch ] ) ;
37
+ } , [ dispatch ] ) ;
39
38
40
39
return (
41
40
< EuiToolTip
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
25
25
import { WorkpadRoutingContext } from '../../../routes/workpad' ;
26
26
import { ViewMenu as Component , Props as ComponentProps } from './view_menu.component' ;
27
27
import { getFitZoomScale } from './lib/get_fit_zoom_scale' ;
28
+ import { forceReload } from '../../hooks/use_canvas_api' ;
28
29
29
30
interface StateProps {
30
31
zoomScale : number ;
@@ -61,7 +62,10 @@ const mapStateToProps = (state: State) => {
61
62
const mapDispatchToProps = ( dispatch : Dispatch ) => ( {
62
63
setZoomScale : ( scale : number ) => dispatch ( setZoomScale ( scale ) ) ,
63
64
setWriteable : ( isWorkpadWriteable : boolean ) => dispatch ( setWriteable ( isWorkpadWriteable ) ) ,
64
- doRefresh : ( ) => dispatch ( fetchAllRenderables ( ) ) ,
65
+ doRefresh : ( ) => {
66
+ forceReload ( ) ;
67
+ dispatch ( fetchAllRenderables ( ) ) ;
68
+ } ,
65
69
} ) ;
66
70
67
71
const mergeProps = (
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import { WorkpadRoutingContext } from '../workpad_routing_context';
11
11
import { getInFlight } from '../../../state/selectors/resolved_args' ;
12
12
// @ts -expect-error untyped local
13
13
import { fetchAllRenderables } from '../../../state/actions/elements' ;
14
+ import { forceReload } from '../../../components/hooks/use_canvas_api' ;
14
15
15
16
export const useRefreshHelper = ( ) => {
16
17
const dispatch = useDispatch ( ) ;
@@ -25,6 +26,7 @@ export const useRefreshHelper = () => {
25
26
26
27
if ( refreshInterval > 0 && ! inFlight ) {
27
28
timer . current = window . setTimeout ( ( ) => {
29
+ forceReload ( ) ;
28
30
dispatch ( fetchAllRenderables ( ) ) ;
29
31
} , refreshInterval ) ;
30
32
}
Original file line number Diff line number Diff line change @@ -31,5 +31,4 @@ export type CanvasContainerApi = PublishesViewMode &
31
31
Partial < PublishesUnifiedSearch > &
32
32
Partial < HasAppContext & PublishesUnifiedSearch > & {
33
33
setSerializedStateForChild : ( childId : string , panelState : SerializedPanelState < object > ) => void ;
34
- reload : ( ) => void ;
35
34
} ;
You can’t perform that action at this time.
0 commit comments