import React, { PureComponent } from 'react'; import * as utils from '../../datasource-zabbix/utils'; import { Trigger, ZBXItem, ZBXAcknowledge, ZBXHost, ZBXGroup, ZBXEvent, GFTimeRange, RTRow } from '../types'; import { Modal, AckProblemData } from './Modal'; import EventTag from './EventTag'; import Tooltip from './Tooltip'; import ProblemTimeline from './ProblemTimeline'; import FAIcon from './FAIcon'; interface ProblemDetailsProps extends RTRow { rootWidth: number; timeRange: GFTimeRange; getProblemEvents: (problem: Trigger) => Promise; onProblemAck: (problem: Trigger, data: AckProblemData) => Promise | any; } interface ProblemDetailsState { events: ZBXEvent[]; show: boolean; showAckDialog: boolean; } export default class ProblemDetails extends PureComponent { constructor(props) { super(props); this.state = { events: [], show: false, showAckDialog: false, }; } componentDidMount() { this.fetchProblemEvents(); requestAnimationFrame(() => { this.setState({ show: true }); }); } fetchProblemEvents() { const problem = this.props.original; this.props.getProblemEvents(problem) .then(events => { console.log(events, this.props.timeRange); this.setState({ events }); }); } ackProblem = (data: AckProblemData) => { const problem = this.props.original as Trigger; console.log('acknowledge: ', problem.lastEvent && problem.lastEvent.eventid, data); return this.props.onProblemAck(problem, data).then(result => { this.closeAckDialog(); }).catch(err => { console.log(err); this.closeAckDialog(); }); } showAckDialog = () => { this.setState({ showAckDialog: true }); } closeAckDialog = () => { this.setState({ showAckDialog: false }); } render() { const problem = this.props.original as Trigger; const rootWidth = this.props.rootWidth; const displayClass = this.state.show ? 'show' : ''; const wideLayout = rootWidth > 1000; const compactStatusBar = rootWidth < 800 || problem.acknowledges && wideLayout && rootWidth < 1200; return (
{problem.age}
{problem.items && }
{problem.comments &&
Description:  {problem.comments}
} {problem.tags && problem.tags.length > 0 &&
{problem.tags && problem.tags.map(tag => ) }
} {this.state.events.length > 0 && } {problem.acknowledges && !wideLayout &&
Acknowledges
}
{problem.acknowledges && wideLayout &&
Acknowledges
}
{problem.datasource}
{problem.proxy &&
{problem.proxy}
} {problem.groups && } {problem.hosts && }
); } } interface ProblemItemProps { item: ZBXItem; showName?: boolean; } function ProblemItem(props: ProblemItemProps) { const { item, showName } = props; const itemName = utils.expandItemName(item.name, item.key_); return (
{showName && {item.name}: } {item.lastvalue}
); } interface ProblemItemsProps { items: ZBXItem[]; } class ProblemItems extends PureComponent { render() { const { items } = this.props; return (items.length > 1 ? items.map(item => ) : ); } } interface AcknowledgesListProps { acknowledges: ZBXAcknowledge[]; } function AcknowledgesList(props: AcknowledgesListProps) { const { acknowledges } = props; return (
{acknowledges.map(ack => {ack.time})}
{acknowledges.map(ack => {ack.user})}
{acknowledges.map(ack => {ack.message})}
); } interface ProblemGroupsProps { groups: ZBXGroup[]; className?: string; } class ProblemGroups extends PureComponent { render() { return this.props.groups.map(g => (
{g.name}
)); } } interface ProblemHostsProps { hosts: ZBXHost[]; className?: string; } class ProblemHosts extends PureComponent { render() { return this.props.hosts.map(h => (
{h.name}
)); } } interface ProblemStatusBarProps { problem: Trigger; className?: string; } function ProblemStatusBar(props: ProblemStatusBarProps) { const { problem, className } = props; const multiEvent = problem.type === '1'; const link = problem.url && problem.url !== ''; const maintenance = problem.maintenance; const manualClose = problem.manual_close === '1'; const error = problem.error && problem.error !== ''; const stateUnknown = problem.state === '1'; const closeByTag = problem.correlation_mode === '1'; const actions = problem.alerts && problem.alerts.length !== 0; const actionMessage = problem.alerts ? problem.alerts[0].message : ''; return (
); } interface ProblemStatusBarItemProps { icon: string; fired?: boolean; link?: string; tooltip?: string; } function ProblemStatusBarItem(props: ProblemStatusBarItemProps) { const { fired, icon, link, tooltip } = props; let item = (
); if (tooltip && fired) { item = ( {item} ); } return link ? {item} : item; } interface ProblemActionButtonProps { icon: string; tooltip?: string; className?: string; onClick?: (event?) => void; } class ProblemActionButton extends PureComponent { handleClick = (event) => { this.props.onClick(event); } render() { const { icon, tooltip, className } = this.props; let button = ( ); if (tooltip) { button = ( {button} ); } return button; } }