Chore: move shared components to components/

This commit is contained in:
Alexander Zobnin
2020-05-19 12:26:04 +03:00
parent ca0f297ac7
commit 0c2197e4ad
13 changed files with 82 additions and 72 deletions

View File

@@ -0,0 +1,19 @@
import React, { FC } from 'react';
import { cx } from 'emotion';
interface Props {
icon: string;
customClass?: string;
}
export const FAIcon: FC<Props> = ({ icon, customClass }) => {
const wrapperClass = cx('fa-icon-container', customClass);
return (
<span className={wrapperClass}>
<i className={`fa fa-${icon}`}></i>
</span>
);
};
export default FAIcon;

View File

@@ -0,0 +1,22 @@
import React, { FC } from 'react';
import { cx } from 'emotion';
interface Props {
status: 'critical' | 'warning' | 'online' | 'ok' | 'problem';
className?: string;
}
export const GFHeartIcon: FC<Props> = ({ status, className }) => {
const iconClass = cx(
className,
'icon-gf',
{ "icon-gf-critical": status === 'critical' || status === 'problem' || status === 'warning'},
{ "icon-gf-online": status === 'online' || status === 'ok' },
);
return (
<i className={iconClass}></i>
);
};
export default GFHeartIcon;

View File

@@ -2,7 +2,7 @@ import React, { FC } from 'react';
import Popper from './Popper'; import Popper from './Popper';
import withPopper, { UsingPopperProps } from './withPopper'; import withPopper, { UsingPopperProps } from './withPopper';
const Tooltip: FC<UsingPopperProps> = ({ hidePopper, showPopper, className, children, ...restProps }) => { const TooltipWrapper: FC<UsingPopperProps> = ({ hidePopper, showPopper, className, children, ...restProps }) => {
return ( return (
<div className={`popper__manager ${className}`} onMouseEnter={showPopper} onMouseLeave={hidePopper}> <div className={`popper__manager ${className}`} onMouseEnter={showPopper} onMouseLeave={hidePopper}>
<Popper {...restProps}>{children}</Popper> <Popper {...restProps}>{children}</Popper>
@@ -10,4 +10,6 @@ const Tooltip: FC<UsingPopperProps> = ({ hidePopper, showPopper, className, chil
); );
}; };
export default withPopper(Tooltip); export const Tooltip = withPopper(TooltipWrapper);
export default Tooltip;

3
src/components/index.ts Normal file
View File

@@ -0,0 +1,3 @@
export { GFHeartIcon } from './GFHeartIcon/GFHeartIcon';
export { FAIcon } from './FAIcon/FAIcon';
export { Tooltip } from './Tooltip/Tooltip';

View File

@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
import classNames from 'classnames'; import classNames from 'classnames';
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, Input, VerticalGroup, Spinner } from '@grafana/ui'; import { Button, Input, VerticalGroup, Spinner } from '@grafana/ui';
import { FAIcon } from './FAIcon'; import { FAIcon } from '../../components';
import * as grafanaUi from '@grafana/ui'; import * as grafanaUi from '@grafana/ui';
const Checkbox: any = grafanaUi.Forms?.Checkbox || (grafanaUi as any).Checkbox; const Checkbox: any = grafanaUi.Forms?.Checkbox || (grafanaUi as any).Checkbox;

View File

@@ -1,33 +1,34 @@
import React, { CSSProperties } from 'react'; import React, { FC } from 'react';
import classNames from 'classnames'; import { cx, css } from 'emotion';
import { ZBXTrigger } from '../../types'; import { GFHeartIcon } from '../../../components';
import { ProblemDTO } from '../../../datasource-zabbix/types';
interface AlertIconProps { interface Props {
problem: ZBXTrigger; problem: ProblemDTO;
color: string; color: string;
blink?: boolean; blink?: boolean;
highlightBackground?: boolean; highlightBackground?: boolean;
} }
export default function AlertIcon(props: AlertIconProps) { export const AlertIcon: FC<Props> = ({ problem, color, blink, highlightBackground }) => {
const { problem, color, blink, highlightBackground } = props; const severity = Number(problem.severity);
const priority = Number(problem.priority); const status = problem.value === '1' && severity >= 2 ? 'critical' : 'online';
let iconClass = '';
if (problem.value === '1' && priority >= 2) {
iconClass = 'icon-gf-critical';
} else {
iconClass = 'icon-gf-online';
}
const className = classNames('icon-gf', iconClass, { 'zabbix-trigger--blinked': blink }); const iconClass = cx(
const style: CSSProperties = {}; 'icon-gf',
if (!highlightBackground) { blink && 'zabbix-trigger--blinked',
style.color = color; );
}
const wrapperClass = cx(
'alert-rule-item__icon',
!highlightBackground && css`color: ${color}`
);
return ( return (
<div className="alert-rule-item__icon" style={style}> <div className={wrapperClass}>
<i className={className}></i> <GFHeartIcon status={status} className={iconClass} />
</div> </div>
); );
} };
export default AlertIcon;

View File

@@ -1,16 +0,0 @@
import React from 'react';
interface FAIconProps {
icon: string;
customClass?: string;
}
export const FAIcon: React.FC<FAIconProps> = (props: FAIconProps) => {
return (
<span className={`fa-icon-container ${props.customClass || ''}`}>
<i className={`fa fa-${props.icon}`}></i>
</span>
);
};
export default FAIcon;

View File

@@ -1,18 +0,0 @@
import React from 'react';
import classNames from 'classnames';
interface GFHeartIconProps {
status: 'critical' | 'warning' | 'online' | 'ok' | 'problem';
className?: string;
}
export default function GFHeartIcon(props: GFHeartIconProps) {
const status = props.status;
const className = classNames("icon-gf", props.className,
{ "icon-gf-critical": status === 'critical' || status === 'problem' || status === 'warning'},
{ "icon-gf-online": status === 'online' || status === 'ok' },
);
return (
<i className={className}></i>
);
}

View File

@@ -2,7 +2,7 @@ import React from 'react';
import { css } from 'emotion'; import { css } from 'emotion';
import { RTCell } from '../../types'; import { RTCell } from '../../types';
import { ProblemDTO } from '../../../datasource-zabbix/types'; import { ProblemDTO } from '../../../datasource-zabbix/types';
import { FAIcon } from '../FAIcon'; import { FAIcon } from '../../../components';
import { useTheme, stylesFactory } from '@grafana/ui'; import { useTheme, stylesFactory } from '@grafana/ui';
import { GrafanaTheme } from '@grafana/data'; import { GrafanaTheme } from '@grafana/data';

View File

@@ -3,14 +3,13 @@ import moment from 'moment';
import * as utils from '../../../datasource-zabbix/utils'; import * as utils from '../../../datasource-zabbix/utils';
import { MODE_ITEMID, MODE_METRICS } from '../../../datasource-zabbix/constants'; import { MODE_ITEMID, MODE_METRICS } from '../../../datasource-zabbix/constants';
import { ProblemDTO, ZBXHost, ZBXGroup, ZBXEvent, ZBXTag, ZBXAlert } from '../../../datasource-zabbix/types'; import { ProblemDTO, ZBXHost, ZBXGroup, ZBXEvent, ZBXTag, ZBXAlert } from '../../../datasource-zabbix/types';
import { ZBXItem, ZBXAcknowledge, GFTimeRange, RTRow } from '../../types'; import { ZBXItem, GFTimeRange, RTRow } from '../../types';
import { AckModal, AckProblemData } from '../AckModal'; import { AckModal, AckProblemData } from '../AckModal';
import EventTag from '../EventTag'; import EventTag from '../EventTag';
import Tooltip from '../../../components/Tooltip/Tooltip';
import ProblemStatusBar from './ProblemStatusBar'; import ProblemStatusBar from './ProblemStatusBar';
import AcknowledgesList from './AcknowledgesList'; import AcknowledgesList from './AcknowledgesList';
import ProblemTimeline from './ProblemTimeline'; import ProblemTimeline from './ProblemTimeline';
import FAIcon from '../FAIcon'; import { FAIcon, Tooltip } from '../../../components';
import { renderUrl } from '../../utils'; import { renderUrl } from '../../utils';
import { getLocationSrv } from '@grafana/runtime'; import { getLocationSrv } from '@grafana/runtime';

View File

@@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import FAIcon from '../FAIcon'; import FAIcon from '../../../components/FAIcon/FAIcon';
import Tooltip from '../../../components/Tooltip/Tooltip'; import Tooltip from '../../../components/Tooltip/Tooltip';
import { ZBXTrigger, ZBXAlert } from '../../types'; import { ZBXTrigger, ZBXAlert } from '../../types';

View File

@@ -3,15 +3,13 @@ import ReactTable from 'react-table-6';
import classNames from 'classnames'; import classNames from 'classnames';
import _ from 'lodash'; import _ from 'lodash';
import moment from 'moment'; import moment from 'moment';
import * as utils from '../../../datasource-zabbix/utils';
import { isNewProblem } from '../../utils'; import { isNewProblem } from '../../utils';
import EventTag from '../EventTag'; import EventTag from '../EventTag';
import ProblemDetails from './ProblemDetails'; import ProblemDetails from './ProblemDetails';
import { AckProblemData } from '../AckModal'; import { AckProblemData } from '../AckModal';
import GFHeartIcon from '../GFHeartIcon'; import { GFHeartIcon, FAIcon } from '../../../components';
import { ProblemsPanelOptions, GFTimeRange, RTCell, TriggerSeverity, RTResized } from '../../types'; import { ProblemsPanelOptions, GFTimeRange, RTCell, TriggerSeverity, RTResized } from '../../types';
import { ProblemDTO, ZBXEvent, ZBXTag, ZBXAlert } from '../../../datasource-zabbix/types'; import { ProblemDTO, ZBXEvent, ZBXTag, ZBXAlert } from '../../../datasource-zabbix/types';
import { FAIcon } from '../FAIcon';
import { AckCell } from './AckCell'; import { AckCell } from './AckCell';
export interface ProblemListProps { export interface ProblemListProps {
@@ -121,12 +119,12 @@ export default class ProblemList extends PureComponent<ProblemListProps, Problem
Cell: props => <TagCell {...props} onTagClick={this.handleTagClick} /> Cell: props => <TagCell {...props} onTagClick={this.handleTagClick} />
}, },
{ {
Header: 'Age', className: 'problem-age', width: 100, show: options.ageField, accessor: 'lastchangeUnix', Header: 'Age', className: 'problem-age', width: 100, show: options.ageField, accessor: 'timestamp',
id: 'age', id: 'age',
Cell: AgeCell, Cell: AgeCell,
}, },
{ {
Header: 'Time', className: 'last-change', width: 150, accessor: 'lastchangeUnix', Header: 'Time', className: 'last-change', width: 150, accessor: 'timestamp',
id: 'lastchange', id: 'lastchange',
Cell: props => LastChangeCell(props, options.customLastChangeFormat && options.lastChangeFormat), Cell: props => LastChangeCell(props, options.customLastChangeFormat && options.lastChangeFormat),
}, },

View File

@@ -2,12 +2,12 @@ import _ from 'lodash';
import moment from 'moment'; import moment from 'moment';
import { DataQuery } from '@grafana/data'; import { DataQuery } from '@grafana/data';
import * as utils from '../datasource-zabbix/utils'; import * as utils from '../datasource-zabbix/utils';
import { ZBXTrigger } from './types'; import { ProblemDTO } from 'datasource-zabbix/types';
export function isNewProblem(problem: ZBXTrigger, highlightNewerThan: string): boolean { export function isNewProblem(problem: ProblemDTO, highlightNewerThan: string): boolean {
try { try {
const highlightIntervalMs = utils.parseInterval(highlightNewerThan); const highlightIntervalMs = utils.parseInterval(highlightNewerThan);
const durationSec = (Date.now() - problem.lastchangeUnix * 1000); const durationSec = (Date.now() - problem.timestamp * 1000);
return durationSec < highlightIntervalMs; return durationSec < highlightIntervalMs;
} catch (e) { } catch (e) {
return false; return false;