Form migrations: Teams and alert list (#23810)

* Basic migration

* Update test

* Fix feedback
pull/23845/head
Tobias Skarhed 5 years ago committed by GitHub
parent e4d492fd35
commit 3fbdcf1070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      public/app/features/alerting/AlertRuleItem.tsx
  2. 2
      public/app/features/alerting/AlertRuleList.test.tsx
  3. 33
      public/app/features/alerting/AlertRuleList.tsx
  4. 42
      public/app/features/alerting/__snapshots__/AlertRuleItem.test.tsx.snap
  5. 172
      public/app/features/alerting/__snapshots__/AlertRuleList.test.tsx.snap
  6. 8
      public/app/features/teams/TeamList.tsx
  7. 24
      public/app/features/teams/__snapshots__/TeamList.test.tsx.snap

@ -2,7 +2,7 @@ import React, { PureComponent } from 'react';
// @ts-ignore // @ts-ignore
import Highlighter from 'react-highlight-words'; import Highlighter from 'react-highlight-words';
import { AlertRule } from '../../types'; import { AlertRule } from '../../types';
import { Icon, IconName } from '@grafana/ui'; import { Icon, IconName, Button, Tooltip, LinkButton, HorizontalGroup } from '@grafana/ui';
export interface Props { export interface Props {
rule: AlertRule; rule: AlertRule;
@ -43,16 +43,19 @@ class AlertRuleItem extends PureComponent<Props> {
</div> </div>
<div className="alert-rule-item__actions"> <div className="alert-rule-item__actions">
<button <HorizontalGroup spacing="sm">
className="btn btn-small btn-inverse alert-list__btn width-2" <Tooltip placement="bottom" content="Pausing an alert rule prevents it from executing">
title="Pausing an alert rule prevents it from executing" <Button
onClick={onTogglePause} variant="secondary"
> size="sm"
<Icon name={rule.state === 'paused' ? 'play' : 'pause'} /> icon={rule.state === 'paused' ? 'play' : 'pause'}
</button> onClick={onTogglePause}
<a className="btn btn-small btn-inverse alert-list__btn width-2" href={ruleUrl} title="Edit alert rule"> />
<Icon name="cog" /> </Tooltip>
</a> <Tooltip placement="right" content="Edit alert rule">
<LinkButton size="sm" variant="secondary" href={ruleUrl} icon="cog" />
</Tooltip>
</HorizontalGroup>
</div> </div>
</li> </li>
); );

@ -127,7 +127,7 @@ describe('Functions', () => {
describe('State filter changed', () => { describe('State filter changed', () => {
it('should update location', () => { it('should update location', () => {
const { instance } = setup(); const { instance } = setup();
const mockEvent = { target: { value: 'alerting' } } as React.ChangeEvent<HTMLSelectElement>; const mockEvent = { value: 'alerting' };
instance.onStateFilterChanged(mockEvent); instance.onStateFilterChanged(mockEvent);

@ -10,8 +10,9 @@ import { AlertRule, CoreEvents, StoreState } from 'app/types';
import { getAlertRulesAsync, togglePauseAlertRule } from './state/actions'; import { getAlertRulesAsync, togglePauseAlertRule } from './state/actions';
import { getAlertRuleItems, getSearchQuery } from './state/selectors'; import { getAlertRuleItems, getSearchQuery } from './state/selectors';
import { FilterInput } from 'app/core/components/FilterInput/FilterInput'; import { FilterInput } from 'app/core/components/FilterInput/FilterInput';
import { NavModel } from '@grafana/data'; import { NavModel, SelectableValue } from '@grafana/data';
import { setSearchQuery } from './state/reducers'; import { setSearchQuery } from './state/reducers';
import { Button, Select } from '@grafana/ui';
export interface Props { export interface Props {
navModel: NavModel; navModel: NavModel;
@ -27,13 +28,13 @@ export interface Props {
export class AlertRuleList extends PureComponent<Props, any> { export class AlertRuleList extends PureComponent<Props, any> {
stateFilters = [ stateFilters = [
{ text: 'All', value: 'all' }, { label: 'All', value: 'all' },
{ text: 'OK', value: 'ok' }, { label: 'OK', value: 'ok' },
{ text: 'Not OK', value: 'not_ok' }, { label: 'Not OK', value: 'not_ok' },
{ text: 'Alerting', value: 'alerting' }, { label: 'Alerting', value: 'alerting' },
{ text: 'No Data', value: 'no_data' }, { label: 'No Data', value: 'no_data' },
{ text: 'Paused', value: 'paused' }, { label: 'Paused', value: 'paused' },
{ text: 'Pending', value: 'pending' }, { label: 'Pending', value: 'pending' },
]; ];
componentDidMount() { componentDidMount() {
@ -58,9 +59,9 @@ export class AlertRuleList extends PureComponent<Props, any> {
return 'all'; return 'all';
} }
onStateFilterChanged = (evt: React.ChangeEvent<HTMLSelectElement>) => { onStateFilterChanged = (option: SelectableValue) => {
this.props.updateLocation({ this.props.updateLocation({
query: { state: evt.target.value }, query: { state: option.value },
}); });
}; };
@ -108,15 +109,17 @@ export class AlertRuleList extends PureComponent<Props, any> {
<label className="gf-form-label">States</label> <label className="gf-form-label">States</label>
<div className="gf-form-select-wrapper width-13"> <div className="gf-form-select-wrapper width-13">
<select className="gf-form-input" onChange={this.onStateFilterChanged} value={this.getStateFilter()}> <Select
{this.stateFilters.map(this.alertStateFilterOption)} options={this.stateFilters}
</select> onChange={this.onStateFilterChanged}
value={this.getStateFilter()}
/>
</div> </div>
</div> </div>
<div className="page-action-bar__spacer" /> <div className="page-action-bar__spacer" />
<a className="btn btn-secondary" onClick={this.onOpenHowTo}> <Button variant="secondary" onClick={this.onOpenHowTo}>
How to add an alert How to add an alert
</a> </Button>
</div> </div>
<section> <section>
<ol className="alert-rule-list"> <ol className="alert-rule-list">

@ -60,24 +60,32 @@ exports[`Render should render component 1`] = `
<div <div
className="alert-rule-item__actions" className="alert-rule-item__actions"
> >
<button <Component
className="btn btn-small btn-inverse alert-list__btn width-2" spacing="sm"
onClick={[MockFunction]}
title="Pausing an alert rule prevents it from executing"
> >
<Icon <Component
name="pause" content="Pausing an alert rule prevents it from executing"
/> placement="bottom"
</button> >
<a <Button
className="btn btn-small btn-inverse alert-list__btn width-2" icon="pause"
href="https://something.something.darkside?editPanel=1&tab=alert" onClick={[MockFunction]}
title="Edit alert rule" size="sm"
> variant="secondary"
<Icon />
name="cog" </Component>
/> <Component
</a> content="Edit alert rule"
placement="right"
>
<LinkButton
href="https://something.something.darkside?editPanel=1&tab=alert"
icon="cog"
size="sm"
variant="secondary"
/>
</Component>
</Component>
</div> </div>
</li> </li>
`; `;

@ -32,65 +32,53 @@ exports[`Render should render alert rules 1`] = `
<div <div
className="gf-form-select-wrapper width-13" className="gf-form-select-wrapper width-13"
> >
<select <Select
className="gf-form-input"
onChange={[Function]} onChange={[Function]}
options={
Array [
Object {
"label": "All",
"value": "all",
},
Object {
"label": "OK",
"value": "ok",
},
Object {
"label": "Not OK",
"value": "not_ok",
},
Object {
"label": "Alerting",
"value": "alerting",
},
Object {
"label": "No Data",
"value": "no_data",
},
Object {
"label": "Paused",
"value": "paused",
},
Object {
"label": "Pending",
"value": "pending",
},
]
}
value="all" value="all"
> />
<option
key="all"
value="all"
>
All
</option>
<option
key="ok"
value="ok"
>
OK
</option>
<option
key="not_ok"
value="not_ok"
>
Not OK
</option>
<option
key="alerting"
value="alerting"
>
Alerting
</option>
<option
key="no_data"
value="no_data"
>
No Data
</option>
<option
key="paused"
value="paused"
>
Paused
</option>
<option
key="pending"
value="pending"
>
Pending
</option>
</select>
</div> </div>
</div> </div>
<div <div
className="page-action-bar__spacer" className="page-action-bar__spacer"
/> />
<a <Button
className="btn btn-secondary"
onClick={[Function]} onClick={[Function]}
variant="secondary"
> >
How to add an alert How to add an alert
</a> </Button>
</div> </div>
<section> <section>
<ol <ol
@ -176,65 +164,53 @@ exports[`Render should render component 1`] = `
<div <div
className="gf-form-select-wrapper width-13" className="gf-form-select-wrapper width-13"
> >
<select <Select
className="gf-form-input"
onChange={[Function]} onChange={[Function]}
options={
Array [
Object {
"label": "All",
"value": "all",
},
Object {
"label": "OK",
"value": "ok",
},
Object {
"label": "Not OK",
"value": "not_ok",
},
Object {
"label": "Alerting",
"value": "alerting",
},
Object {
"label": "No Data",
"value": "no_data",
},
Object {
"label": "Paused",
"value": "paused",
},
Object {
"label": "Pending",
"value": "pending",
},
]
}
value="all" value="all"
> />
<option
key="all"
value="all"
>
All
</option>
<option
key="ok"
value="ok"
>
OK
</option>
<option
key="not_ok"
value="not_ok"
>
Not OK
</option>
<option
key="alerting"
value="alerting"
>
Alerting
</option>
<option
key="no_data"
value="no_data"
>
No Data
</option>
<option
key="paused"
value="paused"
>
Paused
</option>
<option
key="pending"
value="pending"
>
Pending
</option>
</select>
</div> </div>
</div> </div>
<div <div
className="page-action-bar__spacer" className="page-action-bar__spacer"
/> />
<a <Button
className="btn btn-secondary"
onClick={[Function]} onClick={[Function]}
variant="secondary"
> >
How to add an alert How to add an alert
</a> </Button>
</div> </div>
<section> <section>
<ol <ol

@ -1,7 +1,7 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { hot } from 'react-hot-loader'; import { hot } from 'react-hot-loader';
import Page from 'app/core/components/Page/Page'; import Page from 'app/core/components/Page/Page';
import { DeleteButton } from '@grafana/ui'; import { DeleteButton, LinkButton } from '@grafana/ui';
import { NavModel } from '@grafana/data'; import { NavModel } from '@grafana/data';
import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA'; import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA';
import { OrgRole, StoreState, Team } from 'app/types'; import { OrgRole, StoreState, Team } from 'app/types';
@ -109,9 +109,9 @@ export class TeamList extends PureComponent<Props, any> {
<div className="page-action-bar__spacer" /> <div className="page-action-bar__spacer" />
<a className={`btn btn-primary${disabledClass}`} href={newTeamHref}> <LinkButton className={disabledClass} href={newTeamHref}>
New team New Team
</a> </LinkButton>
</div> </div>
<div className="admin-list-table"> <div className="admin-list-table">

@ -52,12 +52,12 @@ exports[`Render should render teams table 1`] = `
<div <div
className="page-action-bar__spacer" className="page-action-bar__spacer"
/> />
<a <LinkButton
className="btn btn-primary" className=""
href="org/teams/new" href="org/teams/new"
> >
New team New Team
</a> </LinkButton>
</div> </div>
<div <div
className="admin-list-table" className="admin-list-table"
@ -387,12 +387,12 @@ exports[`Render when feature toggle editorsCanAdmin is turned on and signedin us
<div <div
className="page-action-bar__spacer" className="page-action-bar__spacer"
/> />
<a <LinkButton
className="btn btn-primary disabled" className=" disabled"
href="#" href="#"
> >
New team New Team
</a> </LinkButton>
</div> </div>
<div <div
className="admin-list-table" className="admin-list-table"
@ -514,12 +514,12 @@ exports[`Render when feature toggle editorsCanAdmin is turned on and signedin us
<div <div
className="page-action-bar__spacer" className="page-action-bar__spacer"
/> />
<a <LinkButton
className="btn btn-primary" className=""
href="org/teams/new" href="org/teams/new"
> >
New team New Team
</a> </LinkButton>
</div> </div>
<div <div
className="admin-list-table" className="admin-list-table"

Loading…
Cancel
Save