From 4b888d105dc5209e2807c75e2f334d8078257ada Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Tue, 19 Jan 2021 14:04:54 +0100 Subject: [PATCH] NgAlerting: View query result (#30218) * Fix query preview add tabs to options * break out tabs to components * add refresh button * minor things after PR review * hide queries * Add simple error screen if there's an error * dropdown with different frames * move onrunqueries to redux * cleanup * show actual error --- public/app/core/utils/query.ts | 1 + .../components/AlertDefinitionOptions.tsx | 84 ++++++++++++------- .../components/AlertingQueryEditor.tsx | 36 ++++---- .../components/AlertingQueryPreview.tsx | 63 +++++++++++--- .../components/PreviewInstancesTab.tsx | 23 +++++ .../alerting/components/PreviewQueryTab.tsx | 52 ++++++++++++ public/app/features/alerting/state/actions.ts | 20 ++++- .../app/features/alerting/state/reducers.ts | 2 +- .../PanelEditor/PanelEditorQueries.tsx | 2 +- .../query/components/QueryEditorRow.tsx | 4 +- .../features/query/components/QueryGroup.tsx | 3 +- .../query/components/QueryGroupOptions.tsx | 22 +---- public/app/features/sandbox/TestStuffPage.tsx | 2 +- public/app/types/alerting.ts | 2 +- public/app/types/index.ts | 1 + public/app/types/query.ts | 20 +++++ 16 files changed, 251 insertions(+), 86 deletions(-) create mode 100644 public/app/features/alerting/components/PreviewInstancesTab.tsx create mode 100644 public/app/features/alerting/components/PreviewQueryTab.tsx create mode 100644 public/app/types/query.ts diff --git a/public/app/core/utils/query.ts b/public/app/core/utils/query.ts index 6fd904ce22a..e09ecb1a71f 100644 --- a/public/app/core/utils/query.ts +++ b/public/app/core/utils/query.ts @@ -16,6 +16,7 @@ export const getNextRefIdChar = (queries: DataQuery[]): string => { export function addQuery(queries: DataQuery[], query?: Partial): DataQuery[] { const q = query || {}; q.refId = getNextRefIdChar(queries); + q.hide = false; return [...queries, q as DataQuery]; } diff --git a/public/app/features/alerting/components/AlertDefinitionOptions.tsx b/public/app/features/alerting/components/AlertDefinitionOptions.tsx index e70ffba47e1..6df1ed8beb6 100644 --- a/public/app/features/alerting/components/AlertDefinitionOptions.tsx +++ b/public/app/features/alerting/components/AlertDefinitionOptions.tsx @@ -1,9 +1,8 @@ -import React, { FC, FormEvent } from 'react'; +import React, { FC, FormEvent, useState } from 'react'; import { css } from 'emotion'; import { GrafanaTheme } from '@grafana/data'; -import { Field, Input, Select, TextArea, useStyles } from '@grafana/ui'; +import { Field, Input, Tab, TabContent, TabsBar, TextArea, useStyles } from '@grafana/ui'; import { AlertDefinition, NotificationChannelType } from 'app/types'; -import { mapChannelsToSelectableValue } from '../utils/notificationChannels'; interface Props { alertDefinition: AlertDefinition; @@ -11,45 +10,70 @@ interface Props { onChange: (event: FormEvent) => void; } -export const AlertDefinitionOptions: FC = ({ alertDefinition, notificationChannelTypes, onChange }) => { +enum Tabs { + Alert = 'alert', + Panel = 'panel', +} + +const tabs = [ + { id: Tabs.Alert, text: 'Alert definition' }, + { id: Tabs.Panel, text: 'Panel' }, +]; + +export const AlertDefinitionOptions: FC = ({ alertDefinition, onChange }) => { const styles = useStyles(getStyles); + const [activeTab, setActiveTab] = useState(Tabs.Alert); return ( -
-
-

Alert definition

- - - - -