problems: remove tag filter with Ctrl/Shift+click

This commit is contained in:
Alexander Zobnin
2019-02-11 14:09:14 +03:00
parent b292426cb5
commit 12ccba0187
5 changed files with 37 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { ZBXTag } from '../types'; import { ZBXTag } from '../types';
import Tooltip from './Tooltip/Tooltip';
const TAG_COLORS = [ const TAG_COLORS = [
'#E24D42', '#E24D42',
@@ -87,13 +88,13 @@ function djb2(str) {
interface EventTagProps { interface EventTagProps {
tag: ZBXTag; tag: ZBXTag;
highlight?: boolean; highlight?: boolean;
onClick?: (tag: ZBXTag) => void; onClick?: (tag: ZBXTag, ctrlKey?: boolean, shiftKey?: boolean) => void;
} }
export default class EventTag extends PureComponent<EventTagProps> { export default class EventTag extends PureComponent<EventTagProps> {
handleClick = () => { handleClick = (event) => {
if (this.props.onClick) { if (this.props.onClick) {
this.props.onClick(this.props.tag); this.props.onClick(this.props.tag, event.ctrlKey, event.shiftKey);
} }
} }
@@ -105,6 +106,7 @@ export default class EventTag extends PureComponent<EventTagProps> {
borderColor: tagColor.borderColor, borderColor: tagColor.borderColor,
}; };
return ( return (
<Tooltip placement="bottom" content="Click to add tag filter or Ctrl/Shift+click to remove">
<span className={`label label-tag zbx-tag ${highlight ? 'highlighted' : ''}`} <span className={`label label-tag zbx-tag ${highlight ? 'highlighted' : ''}`}
style={style} style={style}
onClick={this.handleClick}> onClick={this.handleClick}>
@@ -113,6 +115,7 @@ export default class EventTag extends PureComponent<EventTagProps> {
`${tag.tag}` `${tag.tag}`
} }
</span> </span>
</Tooltip>
); );
} }
} }

View File

@@ -15,7 +15,7 @@ interface ProblemDetailsProps extends RTRow<ZBXTrigger> {
timeRange: GFTimeRange; timeRange: GFTimeRange;
getProblemEvents: (problem: ZBXTrigger) => Promise<ZBXEvent[]>; getProblemEvents: (problem: ZBXTrigger) => Promise<ZBXEvent[]>;
onProblemAck?: (problem: ZBXTrigger, data: AckProblemData) => Promise<any> | any; onProblemAck?: (problem: ZBXTrigger, data: AckProblemData) => Promise<any> | any;
onTagClick?: (tag: ZBXTag, datasource: string) => void; onTagClick?: (tag: ZBXTag, datasource: string, ctrlKey?: boolean, shiftKey?: boolean) => void;
} }
interface ProblemDetailsState { interface ProblemDetailsState {
@@ -41,9 +41,9 @@ export default class ProblemDetails extends PureComponent<ProblemDetailsProps, P
}); });
} }
handleTagClick = (tag: ZBXTag) => { handleTagClick = (tag: ZBXTag, ctrlKey?: boolean, shiftKey?: boolean) => {
if (this.props.onTagClick) { if (this.props.onTagClick) {
this.props.onTagClick(tag, this.props.original.datasource); this.props.onTagClick(tag, this.props.original.datasource, ctrlKey, shiftKey);
} }
} }
@@ -51,7 +51,6 @@ export default class ProblemDetails extends PureComponent<ProblemDetailsProps, P
const problem = this.props.original; const problem = this.props.original;
this.props.getProblemEvents(problem) this.props.getProblemEvents(problem)
.then(events => { .then(events => {
console.log(events, this.props.timeRange);
this.setState({ events }); this.setState({ events });
}); });
} }

View File

@@ -259,7 +259,6 @@ class TimelineInfoContainer extends PureComponent<TimelineInfoContainerProps> {
const { event, eventInfo, show, className, left } = this.props; const { event, eventInfo, show, className, left } = this.props;
let infoItems, durationItem; let infoItems, durationItem;
if (event) { if (event) {
console.log(event);
const ts = moment(Number(event.clock) * 1000); const ts = moment(Number(event.clock) * 1000);
const tsFormatted = ts.format('HH:mm:ss'); const tsFormatted = ts.format('HH:mm:ss');
infoItems = [ infoItems = [

View File

@@ -20,7 +20,7 @@ export interface ProblemListProps {
fontSize?: number; fontSize?: number;
getProblemEvents: (ids: string[]) => ZBXEvent[]; getProblemEvents: (ids: string[]) => ZBXEvent[];
onProblemAck?: (problem: ZBXTrigger, data: AckProblemData) => void; onProblemAck?: (problem: ZBXTrigger, data: AckProblemData) => void;
onTagClick?: (tag: ZBXTag, datasource: string) => void; onTagClick?: (tag: ZBXTag, datasource: string, ctrlKey?: boolean, shiftKey?: boolean) => void;
onPageSizeChange?: (pageSize: number, pageIndex: number) => void; onPageSizeChange?: (pageSize: number, pageIndex: number) => void;
onColumnResize?: (newResized: RTResized) => void; onColumnResize?: (newResized: RTResized) => void;
} }
@@ -70,9 +70,9 @@ export default class ProblemList extends PureComponent<ProblemListProps, Problem
}); });
} }
handleTagClick = (tag: ZBXTag, datasource: string) => { handleTagClick = (tag: ZBXTag, datasource: string, ctrlKey?: boolean, shiftKey?: boolean) => {
if (this.props.onTagClick) { if (this.props.onTagClick) {
this.props.onTagClick(tag, datasource); this.props.onTagClick(tag, datasource, ctrlKey, shiftKey);
} }
} }

View File

@@ -479,6 +479,17 @@ export class TriggerPanelCtrl extends PanelCtrl {
this.refresh(); this.refresh();
} }
removeTagFilter(tag, ds) {
let tagFilter = this.panel.targets[ds].tags.filter;
let targetTags = this.parseTags(tagFilter);
console.log(targetTags);
_.remove(targetTags, t => t.tag === tag.tag && t.value === tag.value);
targetTags = _.uniqWith(targetTags, _.isEqual);
let newFilter = this.tagsToString(targetTags);
this.panel.targets[ds].tags.filter = newFilter;
this.refresh();
}
getProblemEvents(trigger) { getProblemEvents(trigger) {
const triggerids = [trigger.triggerid]; const triggerids = [trigger.triggerid];
const timeFrom = Math.ceil(dateMath.parse(this.range.from) / 1000); const timeFrom = Math.ceil(dateMath.parse(this.range.from) / 1000);
@@ -646,9 +657,13 @@ export class TriggerPanelCtrl extends PanelCtrl {
const message = data.message; const message = data.message;
return ctrl.acknowledgeTrigger(trigger, message); return ctrl.acknowledgeTrigger(trigger, message);
}, },
onTagClick: (tag, datasource) => { onTagClick: (tag, datasource, ctrlKey, shiftKey) => {
if (ctrlKey || shiftKey) {
ctrl.removeTagFilter(tag, datasource);
} else {
ctrl.addTagFilter(tag, datasource); ctrl.addTagFilter(tag, datasource);
} }
}
}; };
let problemsReactElem; let problemsReactElem;