From 260564884cfa6c3a3ee90059bbb244b460c1761a Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Sun, 16 Dec 2018 13:10:48 +0300 Subject: [PATCH] problem timeline: show event info --- .../components/ProblemTimeline.tsx | 81 +++++++++++++++---- src/sass/_panel-problems.scss | 12 ++- 2 files changed, 78 insertions(+), 15 deletions(-) diff --git a/src/panel-triggers/components/ProblemTimeline.tsx b/src/panel-triggers/components/ProblemTimeline.tsx index a636abe..615a570 100644 --- a/src/panel-triggers/components/ProblemTimeline.tsx +++ b/src/panel-triggers/components/ProblemTimeline.tsx @@ -1,4 +1,5 @@ import React, { PureComponent } from 'react'; +import moment from 'moment'; import { GFTimeRange, ZBXEvent } from 'panel-triggers/types'; const DEFAULT_OK_COLOR = 'rgb(56, 189, 113)'; @@ -14,6 +15,8 @@ export interface ProblemTimelineProps { interface ProblemTimelineState { width: number; + highlightedEvent?: ZBXEvent | null; + showEventInfo?: boolean; } export default class ProblemTimeline extends PureComponent { @@ -38,6 +41,14 @@ export default class ProblemTimeline extends PureComponent { + this.setState({ highlightedEvent: event, showEventInfo: true }); + } + + hideEventInfo = () => { + this.setState({ showEventInfo: false }); + } + render() { if (!this.rootRef) { return
; @@ -100,10 +111,11 @@ export default class ProblemTimeline extends PureComponent -
- Info: -
- + + @@ -136,6 +148,8 @@ export default class ProblemTimeline extends PureComponent @@ -145,6 +159,36 @@ export default class ProblemTimeline extends PureComponent { + render() { + const { show, className } = this.props; + const event = this.props.event; + let infoItems; + if (event) { + console.log(event); + const ts = moment(Number(event.clock) * 1000); + const tsFormatted = ts.format('HH:mm:ss'); + infoItems = [ + {tsFormatted} + ]; + } + const containerStyle: React.CSSProperties = { + opacity: show ? 1 : 0, + }; + return ( +
+ {infoItems} +
+ ); + } +} + function TimelineRegion(props) { return ( @@ -157,6 +201,8 @@ interface TimelinePointsProps { width: number; okColor: string; problemColor: string; + onPointHighlight?: (event: ZBXEvent) => void; + onPointUnHighlight?: () => void; } interface TimelinePointsState { @@ -170,19 +216,26 @@ class TimelinePoints extends PureComponent { - const length = this.props.events.length; - const order = this.props.events.map((v, i) => i); + const { events } = this.props; + const length = events.length; + const order = events.map((v, i) => i); order.splice(index, 1); order.push(index); this.setState({ order }); } highlightPoint = index => () => { + if (this.props.onPointHighlight) { + this.props.onPointHighlight(this.props.events[index]); + } this.bringToFront(index); } unHighlightPoint = index => () => { + if (this.props.onPointUnHighlight) { + this.props.onPointUnHighlight(); + } const order = this.props.events.map((v, i) => i); this.setState({ order }); } @@ -203,8 +256,8 @@ class TimelinePoints extends PureComponent ); }); @@ -220,8 +273,8 @@ interface TimelinePointProps { r: number; color: string; className?: string; - onHighlightPoint?: () => void; - onUnHighlightPoint?: () => void; + onPointHighlight?: () => void; + onPointUnHighlight?: () => void; } interface TimelinePointState { @@ -235,15 +288,15 @@ class TimelinePoint extends PureComponent { - if (this.props.onHighlightPoint) { - this.props.onHighlightPoint(); + if (this.props.onPointHighlight) { + this.props.onPointHighlight(); } this.setState({ highlighted: true }); } handleMouseLeave = () => { - if (this.props.onUnHighlightPoint) { - this.props.onUnHighlightPoint(); + if (this.props.onPointUnHighlight) { + this.props.onPointUnHighlight(); } this.setState({ highlighted: false }); } diff --git a/src/sass/_panel-problems.scss b/src/sass/_panel-problems.scss index 62d1681..e04f96d 100644 --- a/src/sass/_panel-problems.scss +++ b/src/sass/_panel-problems.scss @@ -340,17 +340,27 @@ .event-timeline { display: flex; position: relative; - margin: 1.6rem 0; + margin-bottom: 1.6rem; + padding-top: 0.4rem; // margin-top: auto; .timeline-info-container { position: absolute; top: 0; left: 0; + transition: all 0.2s ease-out; + // border: 1px solid $text-color-muted; + // border-radius: 2px; + + .event-timestamp { + font-weight: 500; + color: $text-color-muted; + } } svg.event-timeline-canvas { height: 40px; + margin-top: 1.6rem; g.event-timeline-group { height: 40px;