Skip to content

Commit 6a4b4a6

Browse files
committed
update getDetectors call in associate existing detector flyout
Signed-off-by: Jackie Han <jkhanjob@gmail.com>
1 parent ea247d1 commit 6a4b4a6

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

public/components/FeatureAnywhereContextMenu/CreateAnomalyDetector/AddAnomalyDetector.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ function AddAnomalyDetector({
651651
embeddableVisId={embeddable.vis.id}
652652
selectedDetector={selectedDetector}
653653
setSelectedDetector={setSelectedDetector}
654-
dataSourceId={dataSourceId}
654+
indexPatternId={indexPatternId}
655655
></AssociateExisting>
656656
)}
657657
{mode === FLYOUT_MODES.create && (

public/components/FeatureAnywhereContextMenu/CreateAnomalyDetector/AssociateExisting/containers/AssociateExisting.tsx

+26-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
import { getDetectorList } from '../../../../../redux/reducers/ad';
3535
import {
3636
getSavedFeatureAnywhereLoader,
37+
getSavedObjectsClient,
3738
getUISettings,
3839
} from '../../../../../services';
3940
import {
@@ -53,7 +54,12 @@ interface AssociateExistingProps {
5354
embeddableVisId: string;
5455
selectedDetector: DetectorListItem | undefined;
5556
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;
5763
}
5864

5965
export function AssociateExisting(
@@ -65,6 +71,18 @@ export function AssociateExisting(
6571
const isRequestingFromES = useSelector(
6672
(state: AppState) => state.ad.requesting
6773
);
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+
}
6886
const uiSettings = getUISettings();
6987
const [isLoadingFinalDetectors, setIsLoadingFinalDetectors] =
7088
useState<boolean>(true);
@@ -145,11 +163,15 @@ export function AssociateExisting(
145163
};
146164

147165
useEffect(() => {
148-
getDetectors();
149-
}, []);
166+
async function fetchData() {
167+
await getDataSourceId();
168+
getDetectors();
169+
}
170+
fetchData();
171+
}, [dataSourceId]);
150172

151173
const getDetectors = async () => {
152-
dispatch(getDetectorList(getAllDetectorsQueryParamsWithDataSourceId(associateExistingProps.dataSourceId)));
174+
dispatch(getDetectorList(getAllDetectorsQueryParamsWithDataSourceId(dataSourceId)));
153175
};
154176

155177
const selectedOptions = useMemo(() => {

0 commit comments

Comments
 (0)