query.datasourceUid === ExpressionDatasourceUID)) { + // Get the last data query's refId to use as the source for the reduce expression + const lastDataQueryRefId = grafanaQueries[grafanaQueries.length - 1].refId; + const reduceRefId = getNextRefId(grafanaQueries); + const queriesWithReduce = [...grafanaQueries, { refId: reduceRefId, datasourceUid: '', queryType: '', model: {} }]; + const thresholdRefId = getNextRefId(queriesWithReduce); + const expressions = getDefaultExpressions(reduceRefId, thresholdRefId, lastDataQueryRefId); + grafanaQueries.push(...expressions); + } + const { folderTitle, folderUid } = dashboard.state.meta; const folder = @@ -866,8 +959,7 @@ export const scenesPanelToRuleFormValues = async (vizPanel: VizPanel): Promise
{ + logInfo(LogMessages.alertRuleFromPanel); setIsOpen(true); }} > diff --git a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/__snapshots__/PanelDataAlertingTab.test.tsx.snap b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/__snapshots__/PanelDataAlertingTab.test.tsx.snap index 858dc3812c1..0f2b54da1d0 100644 --- a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/__snapshots__/PanelDataAlertingTab.test.tsx.snap +++ b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/__snapshots__/PanelDataAlertingTab.test.tsx.snap @@ -65,7 +65,7 @@ exports[`PanelAlertTabContent Will render alerts belonging to panel and a button "refId": "B", "type": "reduce", }, - "queryType": "", + "queryType": "expression", "refId": "B", }, { @@ -100,7 +100,7 @@ exports[`PanelAlertTabContent Will render alerts belonging to panel and a button "refId": "C", "type": "threshold", }, - "queryType": "", + "queryType": "expression", "refId": "C", }, ],