diff --git a/public/components/FeatureAnywhereContextMenu/AssociatedMonitors/AssociatedMonitors.tsx b/public/components/FeatureAnywhereContextMenu/AssociatedMonitors/AssociatedMonitors.tsx index 1988a78aa..5f08cffe4 100644 --- a/public/components/FeatureAnywhereContextMenu/AssociatedMonitors/AssociatedMonitors.tsx +++ b/public/components/FeatureAnywhereContextMenu/AssociatedMonitors/AssociatedMonitors.tsx @@ -22,6 +22,7 @@ import { useColumns } from './helpers'; import { ConfirmUnlinkDetectorModal } from './ConfirmUnlinkModal'; import { deleteAlertingAugmentVisSavedObj } from '../../../utils/savedObjectHelper'; import { getNotifications } from '../../../services'; +import { constructUrlFromDataSource } from '../../../pages/utils/helpers'; const AssociatedMonitors = ({ embeddable, closeFlyout, setFlyoutMode, monitors, isAssociateAllowed, limitReachedCallout, setAssociatedMonitors }) => { const title = embeddable.vis.title; @@ -37,7 +38,7 @@ const AssociatedMonitors = ({ embeddable, closeFlyout, setFlyoutMode, monitors, }, []); const onEdit = useCallback( (item) => { - window.open(`alerting#/monitors/${item.id}?action=update-monitor`, '_blank'); + window.open(constructUrlFromDataSource(`alerting#/monitors/${item.id}?action=update-monitor`), '_blank'); }, [] ); diff --git a/public/components/FeatureAnywhereContextMenu/AssociatedMonitors/helpers.js b/public/components/FeatureAnywhereContextMenu/AssociatedMonitors/helpers.js index d26b45460..602e6ca85 100644 --- a/public/components/FeatureAnywhereContextMenu/AssociatedMonitors/helpers.js +++ b/public/components/FeatureAnywhereContextMenu/AssociatedMonitors/helpers.js @@ -8,6 +8,7 @@ import { EuiHealth, EuiLink } from '@elastic/eui'; import { stateToLabel } from '../../../utils/contextMenu/monitors'; import { dateOptionsLong } from '../../../utils/contextMenu/helpers'; import { PLUGIN_NAME } from '../../../../utils/constants'; +import { constructUrlFromDataSource } from '../../../pages/utils/helpers'; export const useColumns = ({ onUnlink, onEdit }) => { const columns = useMemo( @@ -19,7 +20,7 @@ export const useColumns = ({ onUnlink, onEdit }) => { truncateText: true, width: '50%', render: (name, monitor) => ( - + {name} ), diff --git a/public/pages/CreateMonitor/components/AssociateMonitors/AssociateMonitors.js b/public/pages/CreateMonitor/components/AssociateMonitors/AssociateMonitors.js index e9f18aad7..6ea7b0803 100644 --- a/public/pages/CreateMonitor/components/AssociateMonitors/AssociateMonitors.js +++ b/public/pages/CreateMonitor/components/AssociateMonitors/AssociateMonitors.js @@ -9,10 +9,9 @@ import MonitorsList from './components/MonitorsList'; import MonitorsEditor from './components/MonitorsEditor'; import { monitorTypesForComposition } from '../../../../utils/constants'; import { titleTemplate } from '../../../../utils/helpers'; -import { getDataSourceQueryObj } from '../../../utils/helpers'; +import { getDataSourceId } from '../../../utils/helpers'; export const getMonitors = async (httpClient) => { - const dataSourceQuery = getDataSourceQueryObj(); const queryObj = { from: 0, size: 1000, @@ -20,9 +19,10 @@ export const getMonitors = async (httpClient) => { sortField: 'name', sortDirection: 'desc', state: 'all', + dataSourceId: getDataSourceId() }; const response = await httpClient.get('../api/alerting/monitors', { - query: { ...queryObj, ...dataSourceQuery?.query }, + query: queryObj, }); if (response.ok) { diff --git a/public/pages/CreateTrigger/containers/ConfigureTriggers/ConfigureTriggers.js b/public/pages/CreateTrigger/containers/ConfigureTriggers/ConfigureTriggers.js index 1fb4aec34..f662836b3 100644 --- a/public/pages/CreateTrigger/containers/ConfigureTriggers/ConfigureTriggers.js +++ b/public/pages/CreateTrigger/containers/ConfigureTriggers/ConfigureTriggers.js @@ -217,7 +217,7 @@ class ConfigureTriggers extends React.Component { } async onQueryMappings() { - const indices = this.props.monitor.inputs[0].search.indices; + const indices = this.props.monitor.inputs[0].search?.indices || []; try { const mappings = await this.queryMappings(indices); const dataTypes = getPathsPerDataType(mappings); diff --git a/public/pages/CreateTrigger/containers/CreateTrigger/CreateTrigger/CreateTrigger.js b/public/pages/CreateTrigger/containers/CreateTrigger/CreateTrigger/CreateTrigger.js index b1a8af9b4..2b3d9e1ba 100644 --- a/public/pages/CreateTrigger/containers/CreateTrigger/CreateTrigger/CreateTrigger.js +++ b/public/pages/CreateTrigger/containers/CreateTrigger/CreateTrigger/CreateTrigger.js @@ -282,7 +282,7 @@ export default class CreateTrigger extends Component { } async onQueryMappings() { - const indices = this.props.monitor.inputs[0].search.indices; + const indices = this.props.monitor.inputs[0].search?.indices || []; try { const mappings = await this.queryMappings(indices); const dataTypes = getPathsPerDataType(mappings); diff --git a/public/pages/Main/Main.js b/public/pages/Main/Main.js index 1804efc98..48e25a5d0 100644 --- a/public/pages/Main/Main.js +++ b/public/pages/Main/Main.js @@ -49,8 +49,9 @@ class Main extends Component { } async updateBreadcrumbs() { - if (this.props.dataSourceEnabled && this.props.location?.search) { - const dataSourceId = parseQueryStringAndGetDataSource(this.props.location?.search); + if (this.props.dataSourceEnabled && this.props.location) { + const search = this.props.location?.search; + const dataSourceId = search ? parseQueryStringAndGetDataSource(search) : parseQueryStringAndGetDataSource(this.props.location?.pathname); if (dataSourceId) { setDataSource({ dataSourceId }); this.setState({ diff --git a/public/pages/utils/helpers.js b/public/pages/utils/helpers.js index 4683edf82..0a5ebebb2 100644 --- a/public/pages/utils/helpers.js +++ b/public/pages/utils/helpers.js @@ -38,6 +38,5 @@ export function parseQueryStringAndGetDataSource(queryString) { } export function constructUrlFromDataSource(url) { - const dataSourceId = getDataSource()?.dataSourceId; - return dataSourceEnabled() && dataSourceId ? `${url}&dataSourceId=${dataSourceId}` : url; + return dataSourceEnabled() ? `${url}&dataSourceId=${getDataSource()?.dataSourceId}` : url; } diff --git a/public/utils/contextMenu/actions.tsx b/public/utils/contextMenu/actions.tsx index 3ec699901..4e64bd4dd 100644 --- a/public/utils/contextMenu/actions.tsx +++ b/public/utils/contextMenu/actions.tsx @@ -12,7 +12,8 @@ import { createAlertingAction } from '../../actions/alerting_dashboard_action'; import { Action } from '../../../../../src/plugins/ui_actions/public'; import DocumentationTitle from '../../components/FeatureAnywhereContextMenu/DocumentationTitle'; import Container from '../../components/FeatureAnywhereContextMenu/Container'; -import { getOverlays } from '../../services'; +import { getOverlays, setDataSource } from '../../services'; +import { dataSourceEnabled } from '../../pages/utils/helpers'; export const ALERTING_ACTION_CONTEXT = 'ALERTING_ACTION_CONTEXT'; export const ALERTING_ACTION_CONTEXT_GROUP_ID = 'ALERTING_ACTION_CONTEXT_GROUP_ID'; @@ -38,6 +39,12 @@ export const openContainerInFlyout = async ({ embeddable: any; detectorId?: string; }) => { + + if (dataSourceEnabled()) { + const indexPattern = embeddable.vis.data.indexPattern; + setDataSourceIdFromSavedObject(indexPattern); + } + const clonedEmbeddable = await _.cloneDeep(embeddable); const overlayService = getOverlays(); const openFlyout = overlayService.openFlyout; @@ -118,3 +125,14 @@ export const getAdAction = () => defaultFlyoutMode: 'adMonitor', }), }); + +function setDataSourceIdFromSavedObject(indexPattern: any) { + try { + const foundRef = indexPattern.dataSourceRef + const dataSourceId = foundRef ? foundRef.id : ''; + setDataSource({ dataSourceId }); + } catch (error) { + console.error("Error fetching index pattern:", error); + } +} + diff --git a/public/utils/contextMenu/monitors.ts b/public/utils/contextMenu/monitors.ts index 033c061ab..2b88027ff 100644 --- a/public/utils/contextMenu/monitors.ts +++ b/public/utils/contextMenu/monitors.ts @@ -34,7 +34,7 @@ const parseMonitor = (monitor) => { date: latestAlert, // this is the last alert time id: monitor.id, type: monitor.monitor.monitor_type, - indexes: monitor.monitor.inputs[0].search.indices, + indexes: monitor.monitor.inputs[0].search?.indices || [], triggers: [{ name: 'example trigger' }], activeAlerts: monitor.active, };