From 45048ebc4b3b1aae4e3c5338ff6016bb8735b8be Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Tue, 25 May 2021 10:19:11 +0100 Subject: [PATCH] Alerting: Remove unused NGAlerting components (#34568) (#34583) (cherry picked from commit a0b78313f3b863b8a1504b59b97333a4910fe00c) Co-authored-by: Peter Holmberg --- .../features/alerting/AlertRuleList.test.tsx | 1 - .../app/features/alerting/AlertRuleList.tsx | 24 +-- .../features/alerting/NextGenAlertingPage.tsx | 179 ---------------- .../components/AlertDefinitionItem.tsx | 55 ----- .../components/AlertDefinitionOptions.tsx | 83 -------- .../components/AlertingQueryPreview.tsx | 118 ----------- .../alerting/components/EmptyState.tsx | 37 ---- .../components/PreviewInstancesTab.tsx | 23 -- .../alerting/components/PreviewQueryTab.tsx | 74 ------- public/app/features/alerting/state/actions.ts | 198 +----------------- .../app/features/alerting/state/reducers.ts | 74 +------ .../app/features/alerting/state/selectors.ts | 24 +-- public/app/routes/routes.tsx | 14 -- public/app/types/alerting.ts | 39 +--- public/app/types/store.ts | 3 +- 15 files changed, 18 insertions(+), 928 deletions(-) delete mode 100644 public/app/features/alerting/NextGenAlertingPage.tsx delete mode 100644 public/app/features/alerting/components/AlertDefinitionItem.tsx delete mode 100644 public/app/features/alerting/components/AlertDefinitionOptions.tsx delete mode 100644 public/app/features/alerting/components/AlertingQueryPreview.tsx delete mode 100644 public/app/features/alerting/components/EmptyState.tsx delete mode 100644 public/app/features/alerting/components/PreviewInstancesTab.tsx delete mode 100644 public/app/features/alerting/components/PreviewQueryTab.tsx diff --git a/public/app/features/alerting/AlertRuleList.test.tsx b/public/app/features/alerting/AlertRuleList.test.tsx index 19621dd3ed0..935b3d309db 100644 --- a/public/app/features/alerting/AlertRuleList.test.tsx +++ b/public/app/features/alerting/AlertRuleList.test.tsx @@ -25,7 +25,6 @@ const setup = (propOverrides?: object) => { togglePauseAlertRule: jest.fn(), search: '', isLoading: false, - ngAlertDefinitions: [], }; Object.assign(props, propOverrides); diff --git a/public/app/features/alerting/AlertRuleList.tsx b/public/app/features/alerting/AlertRuleList.tsx index cd9c75bbec3..b44a2aba32a 100644 --- a/public/app/features/alerting/AlertRuleList.tsx +++ b/public/app/features/alerting/AlertRuleList.tsx @@ -5,7 +5,7 @@ import Page from 'app/core/components/Page/Page'; import AlertRuleItem from './AlertRuleItem'; import appEvents from 'app/core/app_events'; import { getNavModel } from 'app/core/selectors/navModel'; -import { AlertDefinition, AlertRule, StoreState } from 'app/types'; +import { AlertRule, StoreState } from 'app/types'; import { getAlertRulesAsync, togglePauseAlertRule } from './state/actions'; import { getAlertRuleItems, getSearchQuery } from './state/selectors'; import { FilterInput } from 'app/core/components/FilterInput/FilterInput'; @@ -13,7 +13,6 @@ import { SelectableValue } from '@grafana/data'; import { config, locationService } from '@grafana/runtime'; import { setSearchQuery } from './state/reducers'; import { Button, LinkButton, Select, VerticalGroup } from '@grafana/ui'; -import { AlertDefinitionItem } from './components/AlertDefinitionItem'; import { GrafanaRouteComponentProps } from 'app/core/navigation/types'; import { ShowModalReactEvent } from '../../types/events'; import { AlertHowToModal } from './AlertHowToModal'; @@ -24,7 +23,6 @@ function mapStateToProps(state: StoreState) { alertRules: getAlertRuleItems(state), search: getSearchQuery(state.alertRules), isLoading: state.alertRules.isLoading, - ngAlertDefinitions: state.alertDefinition.alertDefinitions, }; } @@ -125,23 +123,13 @@ export class AlertRuleListUnconnected extends PureComponent { - {alertRules.map((rule, index) => { - // Alert definition has "title" as name property. - if (rule.hasOwnProperty('name')) { - return ( - this.onTogglePause(rule as AlertRule)} - /> - ); - } + {alertRules.map((rule) => { return ( - this.onTogglePause(rule as AlertRule)} /> ); })} diff --git a/public/app/features/alerting/NextGenAlertingPage.tsx b/public/app/features/alerting/NextGenAlertingPage.tsx deleted file mode 100644 index 1d84dc6a46b..00000000000 --- a/public/app/features/alerting/NextGenAlertingPage.tsx +++ /dev/null @@ -1,179 +0,0 @@ -import React, { FormEvent, PureComponent } from 'react'; -import { hot } from 'react-hot-loader'; -import { connect, ConnectedProps } from 'react-redux'; -import { css } from '@emotion/css'; -import { GrafanaTheme2, SelectableValue } from '@grafana/data'; -import { locationService } from '@grafana/runtime'; -import { PageToolbar, stylesFactory, ToolbarButton, withTheme2, Themeable2 } from '@grafana/ui'; -import { config } from 'app/core/config'; -import { SplitPaneWrapper } from 'app/core/components/SplitPaneWrapper/SplitPaneWrapper'; -import { AlertingQueryEditor } from './components/AlertingQueryEditor'; -import { AlertDefinitionOptions } from './components/AlertDefinitionOptions'; -import { AlertingQueryPreview } from './components/AlertingQueryPreview'; -import { - cleanUpDefinitionState, - createAlertDefinition, - evaluateAlertDefinition, - evaluateNotSavedAlertDefinition, - getAlertDefinition, - updateAlertDefinition, - updateAlertDefinitionOption, - updateAlertDefinitionUiState, -} from './state/actions'; -import { StoreState } from 'app/types'; -import { GrafanaRouteComponentProps } from 'app/core/navigation/types'; -import { GrafanaQuery } from '../../types/unified-alerting-dto'; - -function mapStateToProps(state: StoreState, props: RouteProps) { - return { - uiState: state.alertDefinition.uiState, - getInstances: state.alertDefinition.getInstances, - alertDefinition: state.alertDefinition.alertDefinition, - pageId: props.match.params.id as string, - }; -} - -const mapDispatchToProps = { - updateAlertDefinitionUiState, - updateAlertDefinitionOption, - evaluateAlertDefinition, - updateAlertDefinition, - createAlertDefinition, - getAlertDefinition, - evaluateNotSavedAlertDefinition, - cleanUpDefinitionState, -}; - -const connector = connect(mapStateToProps, mapDispatchToProps); - -interface RouteProps extends GrafanaRouteComponentProps<{ id: string }> {} - -interface OwnProps extends Themeable2 { - saveDefinition: typeof createAlertDefinition | typeof updateAlertDefinition; -} - -type Props = OwnProps & ConnectedProps; - -class UnthemedNextGenAlertingPage extends PureComponent { - componentDidMount() { - const { getAlertDefinition, pageId } = this.props; - - if (pageId) { - getAlertDefinition(pageId); - } - } - - componentWillUnmount() { - this.props.cleanUpDefinitionState(); - } - - onChangeAlertOption = (event: FormEvent) => { - const formEvent = event as FormEvent; - this.props.updateAlertDefinitionOption({ [formEvent.currentTarget.name]: formEvent.currentTarget.value }); - }; - - onChangeInterval = (interval: SelectableValue) => { - this.props.updateAlertDefinitionOption({ - intervalSeconds: interval.value, - }); - }; - - onConditionChange = (condition: SelectableValue) => { - this.props.updateAlertDefinitionOption({ - condition: condition.value, - }); - }; - - onSaveAlert = () => { - const { alertDefinition, createAlertDefinition, updateAlertDefinition } = this.props; - - if (alertDefinition.uid) { - updateAlertDefinition(); - } else { - createAlertDefinition(); - } - }; - - onDiscard = () => { - locationService.replace(`${config.appSubUrl}/alerting/ng/list`); - }; - - onTest = () => { - const { alertDefinition, evaluateAlertDefinition, evaluateNotSavedAlertDefinition } = this.props; - if (alertDefinition.uid) { - evaluateAlertDefinition(); - } else { - evaluateNotSavedAlertDefinition(); - } - }; - - renderToolbarActions() { - return [ - - Discard - , - - Test - , - - Save - , - ]; - } - - render() { - const { alertDefinition, uiState, updateAlertDefinitionUiState, getInstances, theme } = this.props; - - const styles = getStyles(theme); - - return ( -
- - {this.renderToolbarActions()} - -
- , - {}} />, - ]} - uiState={uiState} - updateUiState={updateAlertDefinitionUiState} - rightPaneComponents={ - - } - /> -
-
- ); - } -} - -const NextGenAlertingPageUnconnected = withTheme2(UnthemedNextGenAlertingPage); - -export default hot(module)(connector(NextGenAlertingPageUnconnected)); - -const getStyles = stylesFactory((theme: GrafanaTheme2) => ({ - wrapper: css` - width: calc(100% - 55px); - height: 100%; - position: fixed; - top: 0; - bottom: 0; - background: ${theme.colors.background.canvas}; - display: flex; - flex-direction: column; - `, - splitPanesWrapper: css` - display: flex; - flex-direction: column; - height: 100%; - width: 100%; - position: relative; - `, -})); diff --git a/public/app/features/alerting/components/AlertDefinitionItem.tsx b/public/app/features/alerting/components/AlertDefinitionItem.tsx deleted file mode 100644 index 64407a22207..00000000000 --- a/public/app/features/alerting/components/AlertDefinitionItem.tsx +++ /dev/null @@ -1,55 +0,0 @@ -import React, { FC } from 'react'; -// @ts-ignore -import Highlighter from 'react-highlight-words'; -import { FeatureState } from '@grafana/data'; -import { Card, FeatureBadge, Icon, LinkButton } from '@grafana/ui'; -import { AlertDefinition } from 'app/types'; -import { config } from '@grafana/runtime'; - -interface Props { - alertDefinition: AlertDefinition; - search: string; -} - -export const AlertDefinitionItem: FC = ({ alertDefinition, search }) => { - return ( - - - - - - - {alertDefinition.description} - - - - {[ - - Edit alert - , - ]} - - - ); -}; - -const CardTitle = (title: string, search: string) => ( -
- - -
-); diff --git a/public/app/features/alerting/components/AlertDefinitionOptions.tsx b/public/app/features/alerting/components/AlertDefinitionOptions.tsx deleted file mode 100644 index db22fb8d801..00000000000 --- a/public/app/features/alerting/components/AlertDefinitionOptions.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import React, { FC, FormEvent } from 'react'; -import { css } from '@emotion/css'; -import { GrafanaTheme, SelectableValue } from '@grafana/data'; -import { Field, Input, Select, Tab, TabContent, TabsBar, TextArea, useStyles } from '@grafana/ui'; -import { AlertDefinition } from 'app/types'; - -const intervalOptions: Array> = [ - { value: 60, label: '1m' }, - { value: 300, label: '5m' }, - { value: 600, label: '10m' }, -]; - -interface Props { - alertDefinition: AlertDefinition; - onChange: (event: FormEvent) => void; - onIntervalChange: (interval: SelectableValue) => void; - onConditionChange: (refId: SelectableValue) => void; -} - -export const AlertDefinitionOptions: FC = ({ alertDefinition, onChange, onIntervalChange }) => { - const styles = useStyles(getStyles); - - return ( -
- - - - - - - - -