3
3
* SPDX-License-Identifier: Apache-2.0
4
4
*/
5
5
6
- import { uniqBy } from 'lodash' ;
7
6
import React , { memo , useState , useEffect } from 'react' ;
8
7
import { Filter , IndexPattern } from 'src/plugins/data/public' ;
9
8
import { useCallback } from 'react' ;
@@ -13,7 +12,6 @@ import { getTopNavConfig } from '../top_nav/get_top_nav_config';
13
12
import { DashboardAppStateContainer , DashboardAppState , DashboardServices } from '../../types' ;
14
13
import { getNavActions } from '../utils/get_nav_actions' ;
15
14
import { DashboardContainer } from '../embeddable' ;
16
- import { isErrorEmbeddable } from '../../embeddable_plugin' ;
17
15
import { Dashboard } from '../../dashboard' ;
18
16
19
17
interface DashboardTopNavProps {
@@ -23,6 +21,7 @@ interface DashboardTopNavProps {
23
21
dashboard : Dashboard ;
24
22
currentAppState : DashboardAppState ;
25
23
isEmbeddableRendered : boolean ;
24
+ indexPatterns : IndexPattern [ ] ;
26
25
dashboardContainer ?: DashboardContainer ;
27
26
}
28
27
@@ -42,16 +41,14 @@ const TopNav = ({
42
41
currentAppState,
43
42
isEmbeddableRendered,
44
43
dashboardContainer,
44
+ indexPatterns,
45
45
} : DashboardTopNavProps ) => {
46
- const [ filters , setFilters ] = useState < Filter [ ] > ( [ ] ) ;
47
46
const [ topNavMenu , setTopNavMenu ] = useState < any > ( ) ;
48
47
const [ isFullScreenMode , setIsFullScreenMode ] = useState < any > ( ) ;
49
- const [ indexPatterns , setIndexPatterns ] = useState < IndexPattern [ ] > ( ) ;
50
48
51
49
const { services } = useOpenSearchDashboards < DashboardServices > ( ) ;
52
50
const { TopNavMenu } = services . navigation . ui ;
53
- const { data, dashboardConfig, setHeaderActionMenu } = services ;
54
- const { query : queryService } = data ;
51
+ const { dashboardConfig, setHeaderActionMenu } = services ;
55
52
56
53
const location = useLocation ( ) ;
57
54
const queryParameters = new URLSearchParams ( location . search ) ;
@@ -76,10 +73,6 @@ const TopNav = ({
76
73
const shouldShowNavBarComponent = ( forceShow : boolean ) : boolean =>
77
74
( forceShow || isChromeVisible ) && ! currentAppState ?. fullScreenMode ;
78
75
79
- useEffect ( ( ) => {
80
- setFilters ( queryService . filterManager . getFilters ( ) ) ;
81
- } , [ services , queryService ] ) ;
82
-
83
76
useEffect ( ( ) => {
84
77
if ( isEmbeddableRendered ) {
85
78
const navActions = getNavActions (
@@ -112,33 +105,6 @@ const TopNav = ({
112
105
setIsFullScreenMode ( currentAppState ?. fullScreenMode ) ;
113
106
} , [ currentAppState , services ] ) ;
114
107
115
- useEffect ( ( ) => {
116
- const asyncSetIndexPattern = async ( ) => {
117
- if ( dashboardContainer ) {
118
- let panelIndexPatterns : IndexPattern [ ] = [ ] ;
119
- dashboardContainer . getChildIds ( ) . forEach ( ( id ) => {
120
- const embeddableInstance = dashboardContainer . getChild ( id ) ;
121
- if ( isErrorEmbeddable ( embeddableInstance ) ) return ;
122
- const embeddableIndexPatterns = ( embeddableInstance . getOutput ( ) as any ) . indexPatterns ;
123
- if ( ! embeddableIndexPatterns ) return ;
124
- panelIndexPatterns . push ( ...embeddableIndexPatterns ) ;
125
- } ) ;
126
- panelIndexPatterns = uniqBy ( panelIndexPatterns , 'id' ) ;
127
-
128
- if ( panelIndexPatterns . length > 0 ) {
129
- setIndexPatterns ( panelIndexPatterns ) ;
130
- } else {
131
- const defaultIndex = await services . data . indexPatterns . getDefault ( ) ;
132
- if ( defaultIndex ) {
133
- setIndexPatterns ( [ defaultIndex ] ) ;
134
- }
135
- }
136
- }
137
- } ;
138
-
139
- asyncSetIndexPattern ( ) ;
140
- } , [ dashboardContainer , stateContainer , currentAppState , services . data . indexPatterns ] ) ;
141
-
142
108
const shouldShowFilterBar = ( forceHide : boolean ) : boolean =>
143
109
! forceHide && ( currentAppState . filters ! . length > 0 || ! currentAppState ?. fullScreenMode ) ;
144
110
@@ -156,7 +122,6 @@ const TopNav = ({
156
122
return (
157
123
< TopNavMenu
158
124
appName = { 'dashboard' }
159
- savedQueryId = { currentAppState ?. savedQuery }
160
125
config = { showTopNavMenu ? topNavMenu : undefined }
161
126
className = { isFullScreenMode ? 'osdTopNavMenu-isFullScreen' : undefined }
162
127
screenTitle = { currentAppState . title }
@@ -169,7 +134,10 @@ const TopNav = ({
169
134
indexPatterns = { indexPatterns }
170
135
showSaveQuery = { services . dashboardCapabilities . saveQuery as boolean }
171
136
savedQuery = { undefined }
172
- onSavedQueryIdChange = { ( ) => { } }
137
+ onSavedQueryIdChange = { ( savedQueryId ?: string ) => {
138
+ stateContainer . transitions . set ( 'savedQuery' , savedQueryId ) ;
139
+ } }
140
+ savedQueryId = { currentAppState ?. savedQuery }
173
141
onQuerySubmit = { handleRefresh }
174
142
setMenuMountPoint = { isEmbeddedExternally ? undefined : setHeaderActionMenu }
175
143
/>
0 commit comments