@@ -34,6 +34,7 @@ import {
34
34
import { getDetectorList } from '../../../../../redux/reducers/ad' ;
35
35
import {
36
36
getSavedFeatureAnywhereLoader ,
37
+ getSavedObjectsClient ,
37
38
getUISettings ,
38
39
} from '../../../../../services' ;
39
40
import {
@@ -53,7 +54,12 @@ interface AssociateExistingProps {
53
54
embeddableVisId : string ;
54
55
selectedDetector : DetectorListItem | undefined ;
55
56
setSelectedDetector ( detector : DetectorListItem | undefined ) : void ;
56
- dataSourceId : string | undefined ;
57
+ indexPatternId : string ;
58
+ }
59
+ interface References {
60
+ id : string ;
61
+ name : string ;
62
+ type : string ;
57
63
}
58
64
59
65
export function AssociateExisting (
@@ -65,6 +71,18 @@ export function AssociateExisting(
65
71
const isRequestingFromES = useSelector (
66
72
( state : AppState ) => state . ad . requesting
67
73
) ;
74
+ const [ dataSourceId , setDataSourceId ] = useState < string | undefined > ( undefined ) ;
75
+
76
+ async function getDataSourceId ( ) {
77
+ try {
78
+ const indexPattern = await getSavedObjectsClient ( ) . get ( 'index-pattern' , associateExistingProps . indexPatternId ) ;
79
+ const refs = indexPattern . references as References [ ] ;
80
+ const foundDataSourceId = refs . find ( ref => ref . type === 'data-source' ) ?. id ;
81
+ setDataSourceId ( foundDataSourceId ) ;
82
+ } catch ( error ) {
83
+ console . error ( "Error fetching index pattern:" , error ) ;
84
+ }
85
+ }
68
86
const uiSettings = getUISettings ( ) ;
69
87
const [ isLoadingFinalDetectors , setIsLoadingFinalDetectors ] =
70
88
useState < boolean > ( true ) ;
@@ -145,11 +163,15 @@ export function AssociateExisting(
145
163
} ;
146
164
147
165
useEffect ( ( ) => {
148
- getDetectors ( ) ;
149
- } , [ ] ) ;
166
+ async function fetchData ( ) {
167
+ await getDataSourceId ( ) ;
168
+ getDetectors ( ) ;
169
+ }
170
+ fetchData ( ) ;
171
+ } , [ dataSourceId ] ) ;
150
172
151
173
const getDetectors = async ( ) => {
152
- dispatch ( getDetectorList ( getAllDetectorsQueryParamsWithDataSourceId ( associateExistingProps . dataSourceId ) ) ) ;
174
+ dispatch ( getDetectorList ( getAllDetectorsQueryParamsWithDataSourceId ( dataSourceId ) ) ) ;
153
175
} ;
154
176
155
177
const selectedOptions = useMemo ( ( ) => {
0 commit comments