2020-12-11 07:49:14 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
2021-02-15 06:56:59 -06:00
|
|
|
import { connect, ConnectedProps } from 'react-redux';
|
2020-12-11 07:49:14 -06:00
|
|
|
import { css } from 'emotion';
|
2021-01-19 07:04:54 -06:00
|
|
|
import { GrafanaTheme } from '@grafana/data';
|
|
|
|
import { RefreshPicker, stylesFactory } from '@grafana/ui';
|
2021-02-15 06:56:59 -06:00
|
|
|
|
2020-12-11 07:49:14 -06:00
|
|
|
import { config } from 'app/core/config';
|
|
|
|
import { QueryGroup } from '../../query/components/QueryGroup';
|
2021-01-19 07:04:54 -06:00
|
|
|
import { onRunQueries, queryOptionsChange } from '../state/actions';
|
|
|
|
import { QueryGroupOptions, StoreState } from 'app/types';
|
2020-12-11 07:49:14 -06:00
|
|
|
|
2021-02-15 06:56:59 -06:00
|
|
|
function mapStateToProps(state: StoreState) {
|
|
|
|
return {
|
|
|
|
queryOptions: state.alertDefinition.getQueryOptions(),
|
|
|
|
queryRunner: state.alertDefinition.queryRunner,
|
|
|
|
};
|
2020-12-11 07:49:14 -06:00
|
|
|
}
|
|
|
|
|
2021-02-15 06:56:59 -06:00
|
|
|
const mapDispatchToProps = {
|
|
|
|
queryOptionsChange,
|
|
|
|
onRunQueries,
|
|
|
|
};
|
|
|
|
|
|
|
|
const connector = connect(mapStateToProps, mapDispatchToProps);
|
2020-12-11 07:49:14 -06:00
|
|
|
|
2021-02-15 06:56:59 -06:00
|
|
|
interface OwnProps {}
|
|
|
|
|
|
|
|
type Props = OwnProps & ConnectedProps<typeof connector>;
|
|
|
|
|
|
|
|
class AlertingQueryEditorUnconnected extends PureComponent<Props> {
|
2020-12-11 07:49:14 -06:00
|
|
|
onQueryOptionsChange = (queryOptions: QueryGroupOptions) => {
|
|
|
|
this.props.queryOptionsChange(queryOptions);
|
|
|
|
};
|
|
|
|
|
|
|
|
onRunQueries = () => {
|
2021-01-19 07:04:54 -06:00
|
|
|
this.props.onRunQueries();
|
|
|
|
};
|
2020-12-11 07:49:14 -06:00
|
|
|
|
2021-01-19 07:04:54 -06:00
|
|
|
onIntervalChanged = (interval: string) => {
|
|
|
|
this.props.queryOptionsChange({ ...this.props.queryOptions, minInterval: interval });
|
2020-12-11 07:49:14 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { queryOptions, queryRunner } = this.props;
|
|
|
|
const styles = getStyles(config.theme);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.wrapper}>
|
|
|
|
<div className={styles.container}>
|
|
|
|
<h4>Queries</h4>
|
2021-01-19 07:04:54 -06:00
|
|
|
<div className={styles.refreshWrapper}>
|
|
|
|
<RefreshPicker
|
|
|
|
onIntervalChanged={this.onIntervalChanged}
|
|
|
|
onRefresh={this.onRunQueries}
|
|
|
|
intervals={['15s', '30s']}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-12-11 07:49:14 -06:00
|
|
|
<QueryGroup
|
2021-03-30 01:23:00 -05:00
|
|
|
queryRunner={queryRunner!} // if the queryRunner is undefined here, somethings very wrong so it's ok to throw an unhandled error
|
2020-12-11 07:49:14 -06:00
|
|
|
options={queryOptions}
|
|
|
|
onRunQueries={this.onRunQueries}
|
|
|
|
onOptionsChange={this.onQueryOptionsChange}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-15 06:56:59 -06:00
|
|
|
export const AlertingQueryEditor = connector(AlertingQueryEditorUnconnected);
|
2020-12-11 07:49:14 -06:00
|
|
|
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => {
|
|
|
|
return {
|
|
|
|
wrapper: css`
|
|
|
|
padding-left: ${theme.spacing.md};
|
2020-12-17 09:11:12 -06:00
|
|
|
height: 100%;
|
2020-12-11 07:49:14 -06:00
|
|
|
`,
|
|
|
|
container: css`
|
|
|
|
padding: ${theme.spacing.md};
|
|
|
|
background-color: ${theme.colors.panelBg};
|
2020-12-17 09:11:12 -06:00
|
|
|
height: 100%;
|
2020-12-11 07:49:14 -06:00
|
|
|
`,
|
2021-01-19 07:04:54 -06:00
|
|
|
refreshWrapper: css`
|
|
|
|
display: flex;
|
|
|
|
justify-content: flex-end;
|
|
|
|
`,
|
2020-12-11 07:49:14 -06:00
|
|
|
editorWrapper: css`
|
|
|
|
border: 1px solid ${theme.colors.panelBorder};
|
|
|
|
border-radius: ${theme.border.radius.md};
|
|
|
|
`,
|
|
|
|
};
|
|
|
|
});
|