@@ -26,6 +26,7 @@ import {
26
26
getSavedFeatureAnywhereLoader ,
27
27
getNotifications ,
28
28
getUISettings ,
29
+ getSavedObjectsClient ,
29
30
} from '../../../../services' ;
30
31
import {
31
32
GET_ALL_DETECTORS_QUERY_PARAMS ,
@@ -47,6 +48,7 @@ import {
47
48
} from '../../../../../../../src/plugins/vis_augmenter/public' ;
48
49
import { ASSOCIATED_DETECTOR_ACTION } from '../utils/constants' ;
49
50
import { PLUGIN_AUGMENTATION_MAX_OBJECTS_SETTING } from '../../../../../public/expressions/constants' ;
51
+ import { getAllDetectorsQueryParamsWithDataSourceId } from '../../../../../public/pages/utils/helpers' ;
50
52
51
53
interface ConfirmModalState {
52
54
isOpen : boolean ;
@@ -56,6 +58,12 @@ interface ConfirmModalState {
56
58
affectedDetector : DetectorListItem ;
57
59
}
58
60
61
+ interface References {
62
+ id : string ;
63
+ name : string ;
64
+ type : string ;
65
+ }
66
+
59
67
function AssociatedDetectors ( { embeddable, closeFlyout, setMode } ) {
60
68
const dispatch = useDispatch ( ) ;
61
69
const allDetectors = useSelector ( ( state : AppState ) => state . ad . detectorList ) ;
@@ -69,6 +77,20 @@ function AssociatedDetectors({ embeddable, closeFlyout, setMode }) {
69
77
( state : AppState ) => state . ad . errorMessage
70
78
) ;
71
79
const embeddableTitle = embeddable . getTitle ( ) ;
80
+ const indexPatternId = embeddable . vis . data . aggs . indexPattern . id ;
81
+ const [ dataSourceId , setDataSourceId ] = useState < string | undefined > ( undefined ) ;
82
+
83
+ async function getDataSourceId ( ) {
84
+ try {
85
+ const indexPattern = await getSavedObjectsClient ( ) . get ( 'index-pattern' , indexPatternId ) ;
86
+ const refs = indexPattern . references as References [ ] ;
87
+ const foundDataSourceId = refs . find ( ref => ref . type === 'data-source' ) ?. id ;
88
+ setDataSourceId ( foundDataSourceId ) ;
89
+ } catch ( error ) {
90
+ console . error ( "Error fetching index pattern:" , error ) ;
91
+ }
92
+ }
93
+
72
94
const [ selectedDetectors , setSelectedDetectors ] = useState (
73
95
[ ] as DetectorListItem [ ]
74
96
) ;
@@ -135,8 +157,12 @@ function AssociatedDetectors({ embeddable, closeFlyout, setMode }) {
135
157
} , [ confirmModalState . isRequestingToClose , isLoading ] ) ;
136
158
137
159
useEffect ( ( ) => {
138
- getDetectors ( ) ;
139
- } , [ ] ) ;
160
+ async function fetchData ( ) {
161
+ await getDataSourceId ( ) ;
162
+ getDetectors ( ) ;
163
+ }
164
+ fetchData ( ) ;
165
+ } , [ dataSourceId ] ) ;
140
166
141
167
// Handles all changes in the assoicated detectors such as unlinking or new detectors associated
142
168
useEffect ( ( ) => {
@@ -175,9 +201,9 @@ function AssociatedDetectors({ embeddable, closeFlyout, setMode }) {
175
201
) => {
176
202
// Map all detector IDs for all the found augmented vis objects
177
203
const savedAugmentDetectorsSet = new Set (
178
- savedAugmentForThisVisualization . map ( ( savedObject ) =>
179
- get ( savedObject , 'pluginResource.id' , '' )
180
- )
204
+ savedAugmentForThisVisualization
205
+ . map ( savedObject => get ( savedObject , 'pluginResource.id' , '' ) )
206
+ . filter ( id => id !== '' )
181
207
) ;
182
208
183
209
// filter out any detectors that aren't on the set of detectors IDs from the augmented vis objects.
@@ -240,7 +266,11 @@ function AssociatedDetectors({ embeddable, closeFlyout, setMode }) {
240
266
} ;
241
267
242
268
const getDetectors = async ( ) => {
243
- dispatch ( getDetectorList ( GET_ALL_DETECTORS_QUERY_PARAMS ) ) ;
269
+ dispatch (
270
+ getDetectorList (
271
+ getAllDetectorsQueryParamsWithDataSourceId ( dataSourceId )
272
+ )
273
+ ) ;
244
274
} ;
245
275
246
276
const handleUnlinkDetectorAction = ( detector : DetectorListItem ) => {
0 commit comments