mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* break out new and edit * changed model to match new model in backend * AlertingNG: API modifications (#30683) * Fix API consistency * Change eval alert definition to POST request * Fix eval endpoint to accept custom now parameter * Change JSON input property for create/update endpoints * model adjustments * set mixed datasource, fix put url * update snapshots * run test response through converters * remove edit and add landing page * remove snapshot tests ans snapshots * wrap linkbutton in array * different approaches to massage data * get instead of post * use function to return instances data * hook up test button in view * test endpoint for not saved definitions * function that return query options * Chore: fixes strict error * hide ng alert button * typings * fix setAlertDef error * better message when you have queries but no data * NGAlert: Refactoring that handles cleaning up state (#31087) * Chore: some refactorings of state * Chore: reduces strict null errors Co-authored-by: Sofia Papagiannaki <papagian@users.noreply.github.com> Co-authored-by: Sofia Papagiannaki <sofia@grafana.com> Co-authored-by: Hugo Häggmark <hugo.haggmark@gmail.com> Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>
101 lines
3.0 KiB
TypeScript
101 lines
3.0 KiB
TypeScript
import React, { FC, FormEvent, useMemo } from 'react';
|
|
import { css } from 'emotion';
|
|
import { GrafanaTheme, SelectableValue } from '@grafana/data';
|
|
import { Field, Input, Select, Tab, TabContent, TabsBar, TextArea, useStyles } from '@grafana/ui';
|
|
import { AlertDefinition, QueryGroupOptions } from 'app/types';
|
|
|
|
const intervalOptions: Array<SelectableValue<number>> = [
|
|
{ value: 60, label: '1m' },
|
|
{ value: 300, label: '5m' },
|
|
{ value: 600, label: '10m' },
|
|
];
|
|
|
|
interface Props {
|
|
alertDefinition: AlertDefinition;
|
|
onChange: (event: FormEvent<HTMLElement>) => void;
|
|
onIntervalChange: (interval: SelectableValue<number>) => void;
|
|
onConditionChange: (refId: SelectableValue<string>) => void;
|
|
queryOptions: QueryGroupOptions;
|
|
}
|
|
|
|
export const AlertDefinitionOptions: FC<Props> = ({
|
|
alertDefinition,
|
|
onChange,
|
|
onIntervalChange,
|
|
onConditionChange,
|
|
queryOptions,
|
|
}) => {
|
|
const styles = useStyles(getStyles);
|
|
const refIds = useMemo(() => queryOptions.queries.map((q) => ({ value: q.refId, label: q.refId })), [
|
|
queryOptions.queries,
|
|
]);
|
|
|
|
return (
|
|
<div className={styles.wrapper}>
|
|
<TabsBar>
|
|
<Tab label="Alert definition" active={true} />
|
|
</TabsBar>
|
|
<TabContent className={styles.container}>
|
|
<Field label="Title">
|
|
<Input width={25} name="title" value={alertDefinition.title} onChange={onChange} />
|
|
</Field>
|
|
<Field label="Description" description="What does the alert do and why was it created">
|
|
<TextArea
|
|
rows={5}
|
|
width={25}
|
|
name="description"
|
|
value={alertDefinition.description}
|
|
onChange={onChange}
|
|
readOnly={true}
|
|
/>
|
|
</Field>
|
|
<Field label="Evaluate">
|
|
<div className={styles.optionRow}>
|
|
<span className={styles.optionName}>Every</span>
|
|
<Select
|
|
onChange={onIntervalChange}
|
|
value={intervalOptions.find((i) => i.value === alertDefinition.intervalSeconds)}
|
|
options={intervalOptions}
|
|
width={10}
|
|
/>
|
|
</div>
|
|
</Field>
|
|
<Field label="Conditions">
|
|
<div className={styles.optionRow}>
|
|
<Select
|
|
onChange={onConditionChange}
|
|
value={refIds.find((r) => r.value === alertDefinition.condition)}
|
|
options={refIds}
|
|
noOptionsMessage="No queries added"
|
|
/>
|
|
</div>
|
|
</Field>
|
|
</TabContent>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const getStyles = (theme: GrafanaTheme) => {
|
|
return {
|
|
wrapper: css`
|
|
padding-top: ${theme.spacing.md};
|
|
height: 100%;
|
|
`,
|
|
container: css`
|
|
padding: ${theme.spacing.md};
|
|
background-color: ${theme.colors.panelBg};
|
|
height: 100%;
|
|
border-left: 1px solid ${theme.colors.border1};
|
|
`,
|
|
optionRow: css`
|
|
display: flex;
|
|
align-items: baseline;
|
|
`,
|
|
optionName: css`
|
|
font-size: ${theme.typography.size.md};
|
|
color: ${theme.colors.formInputText};
|
|
margin-right: ${theme.spacing.sm};
|
|
`,
|
|
};
|
|
};
|