Fix type errors (tests are failed)

This commit is contained in:
Alexander Zobnin
2022-02-15 18:08:13 +03:00
parent 995249a0b2
commit 709e3ff65a
6 changed files with 24 additions and 18 deletions

View File

@@ -42,7 +42,7 @@ const openInExplore = (problem: ProblemDTO, panelId: number, range: TimeRange) =
}; };
} }
const state: ExploreUrlState = { const state: ExploreUrlState | any = {
datasource: problem.datasource, datasource: problem.datasource,
context: 'explore', context: 'explore',
originPanelId: panelId, originPanelId: panelId,

View File

@@ -1,5 +1,4 @@
import _ from 'lodash'; import _ from 'lodash';
import { Observable } from 'rxjs';
import config from 'grafana/app/core/config'; import config from 'grafana/app/core/config';
import { contextSrv } from 'grafana/app/core/core'; import { contextSrv } from 'grafana/app/core/core';
import * as dateMath from 'grafana/app/core/utils/datemath'; import * as dateMath from 'grafana/app/core/utils/datemath';
@@ -107,7 +106,7 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
* @param {Object} request Contains time range, targets and other info. * @param {Object} request Contains time range, targets and other info.
* @return {Object} Grafana metrics object with timeseries data for each target. * @return {Object} Grafana metrics object with timeseries data for each target.
*/ */
query(request: DataQueryRequest<any>): Promise<DataQueryResponse> | Observable<DataQueryResponse> { query(request: DataQueryRequest<ZabbixMetricsQuery>) {
// Migrate old targets // Migrate old targets
const requestTargets = request.targets.map(t => { const requestTargets = request.targets.map(t => {
// Prevent changes of original object // Prevent changes of original object

View File

@@ -4,6 +4,12 @@ jest.mock('@grafana/runtime', () => ({
getBackendSrv: () => ({ getBackendSrv: () => ({
datasourceRequest: jest.fn().mockResolvedValue({data: {result: ''}}), datasourceRequest: jest.fn().mockResolvedValue({data: {result: ''}}),
}), }),
getBackendSrv: () => ({
datasourceRequest: jest.fn().mockResolvedValue({ data: { result: '' } }),
fetch: () => ({
toPromise: () => jest.fn().mockResolvedValue({ data: { result: '' } })
}),
}),
}), {virtual: true}); }), {virtual: true});
describe('Zabbix', () => { describe('Zabbix', () => {

View File

@@ -1,7 +1,7 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { cx, css } from '@emotion/css'; import { cx, css } from '@emotion/css';
import { ZBX_ACK_ACTION_ADD_MESSAGE, ZBX_ACK_ACTION_ACK, ZBX_ACK_ACTION_CHANGE_SEVERITY, ZBX_ACK_ACTION_CLOSE } from '../../datasource-zabbix/constants'; import { ZBX_ACK_ACTION_ADD_MESSAGE, ZBX_ACK_ACTION_ACK, ZBX_ACK_ACTION_CHANGE_SEVERITY, ZBX_ACK_ACTION_CLOSE } from '../../datasource-zabbix/constants';
import { Button, VerticalGroup, Spinner, Modal, Input, Checkbox, RadioButtonGroup, stylesFactory, withTheme, Themeable, TextArea } from '@grafana/ui'; import { Button, VerticalGroup, Spinner, Modal, Checkbox, RadioButtonGroup, stylesFactory, withTheme, Themeable, TextArea } from '@grafana/ui';
import { FAIcon } from '../../components'; import { FAIcon } from '../../components';
import { GrafanaTheme } from '@grafana/data'; import { GrafanaTheme } from '@grafana/data';
@@ -147,9 +147,9 @@ export class AckModalUnthemed extends PureComponent<Props, State> {
const { canClose } = this.props; const { canClose } = this.props;
const actions = [ const actions = [
<Checkbox css="" key="ack" label="Acknowledge" value={this.state.acknowledge} onChange={this.onAcknowledgeToggle} />, <Checkbox translate="" key="ack" label="Acknowledge" value={this.state.acknowledge} onChange={this.onAcknowledgeToggle} />,
<Checkbox <Checkbox
css="" translate=""
key="change-severity" key="change-severity"
label="Change severity" label="Change severity"
description="" description=""
@@ -166,7 +166,7 @@ export class AckModalUnthemed extends PureComponent<Props, State> {
/>, />,
canClose && canClose &&
<Checkbox <Checkbox
css="" translate=""
key="close" key="close"
label="Close problem" label="Close problem"
disabled={!canClose} disabled={!canClose}
@@ -205,7 +205,7 @@ export class AckModalUnthemed extends PureComponent<Props, State> {
<div className={inputGroupClass}> <div className={inputGroupClass}>
<label className="gf-form-hint"> <label className="gf-form-hint">
<TextArea className={inputClass} <TextArea className={inputClass}
css="" translate=""
type="text" type="text"
name="message" name="message"
placeholder="Message" placeholder="Message"

View File

@@ -10,21 +10,21 @@ import AlertAcknowledges from './AlertAcknowledges';
import AlertIcon from './AlertIcon'; import AlertIcon from './AlertIcon';
import { ProblemDTO, ZBXTag } from '../../../datasource-zabbix/types'; import { ProblemDTO, ZBXTag } from '../../../datasource-zabbix/types';
import { ModalController, Tooltip } from '../../../components'; import { ModalController, Tooltip } from '../../../components';
import { DataSourceRef } from '@grafana/data';
interface AlertCardProps { interface AlertCardProps {
problem: ProblemDTO; problem: ProblemDTO;
panelOptions: ProblemsPanelOptions; panelOptions: ProblemsPanelOptions;
onTagClick?: (tag: ZBXTag, datasource: string, ctrlKey?: boolean, shiftKey?: boolean) => void; onTagClick?: (tag: ZBXTag, datasource: DataSourceRef | string, ctrlKey?: boolean, shiftKey?: boolean) => void;
onProblemAck?: (problem: ProblemDTO, data: AckProblemData) => Promise<any> | any; onProblemAck?: (problem: ProblemDTO, data: AckProblemData) => Promise<any> | any;
} }
export default class AlertCard extends PureComponent<AlertCardProps> { export default class AlertCard extends PureComponent<AlertCardProps> {
handleTagClick = (tag: ZBXTag, datasource: DataSourceRef | string, ctrlKey?: boolean, shiftKey?: boolean) => {
handleTagClick = (tag: ZBXTag, ctrlKey?: boolean, shiftKey?: boolean) => {
if (this.props.onTagClick) { if (this.props.onTagClick) {
this.props.onTagClick(tag, this.props.problem.datasource, ctrlKey, shiftKey); this.props.onTagClick(tag, datasource, ctrlKey, shiftKey);
}
} }
};
ackProblem = (data: AckProblemData) => { ackProblem = (data: AckProblemData) => {
const problem = this.props.problem; const problem = this.props.problem;
@@ -86,6 +86,7 @@ export default class AlertCard extends PureComponent<AlertCardProps> {
<EventTag <EventTag
key={tag.tag + tag.value} key={tag.tag + tag.value}
tag={tag} tag={tag}
datasource={problem.datasource}
highlight={tag.tag === problem.correlation_tag} highlight={tag.tag === problem.correlation_tag}
onClick={this.handleTagClick} onClick={this.handleTagClick}
/> />

View File

@@ -12,7 +12,7 @@ import { GFTimeRange, ProblemsPanelOptions, RTCell, RTResized, TriggerSeverity }
import { ProblemDTO, ZBXAlert, ZBXEvent, ZBXTag } from '../../../datasource-zabbix/types'; import { ProblemDTO, ZBXAlert, ZBXEvent, ZBXTag } from '../../../datasource-zabbix/types';
import { APIExecuteScriptResponse, ZBXScript } from '../../../datasource-zabbix/zabbix/connectors/zabbix_api/types'; import { APIExecuteScriptResponse, ZBXScript } from '../../../datasource-zabbix/zabbix/connectors/zabbix_api/types';
import { AckCell } from './AckCell'; import { AckCell } from './AckCell';
import { TimeRange } from "@grafana/data"; import { DataSourceRef, TimeRange } from "@grafana/data";
export interface ProblemListProps { export interface ProblemListProps {
problems: ProblemDTO[]; problems: ProblemDTO[];
@@ -345,20 +345,20 @@ function LastChangeCell(props: RTCell<ProblemDTO>, customFormat?: string) {
} }
interface TagCellProps extends RTCell<ProblemDTO> { interface TagCellProps extends RTCell<ProblemDTO> {
onTagClick: (tag: ZBXTag, datasource: string, ctrlKey?: boolean, shiftKey?: boolean) => void; onTagClick: (tag: ZBXTag, datasource: DataSourceRef | string, ctrlKey?: boolean, shiftKey?: boolean) => void;
} }
class TagCell extends PureComponent<TagCellProps> { class TagCell extends PureComponent<TagCellProps> {
handleTagClick = (tag: ZBXTag, ctrlKey?: boolean, shiftKey?: boolean) => { handleTagClick = (tag: ZBXTag, datasource: DataSourceRef | string, ctrlKey?: boolean, shiftKey?: boolean) => {
if (this.props.onTagClick) { if (this.props.onTagClick) {
this.props.onTagClick(tag, this.props.original.datasource, ctrlKey, shiftKey); this.props.onTagClick(tag, datasource, ctrlKey, shiftKey);
} }
}; };
render() { render() {
const tags = this.props.value || []; const tags = this.props.value || [];
return [ return [
tags.map(tag => <EventTag key={tag.tag + tag.value} tag={tag} onClick={this.handleTagClick}/>) tags.map(tag => <EventTag key={tag.tag + tag.value} tag={tag} datasource={this.props.original.datasource} onClick={this.handleTagClick}/>)
]; ];
} }
} }