mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
- Add new PNG files for the new icons in the left side navigation and the right side labels on the Hosts page. - Rename the old `<Icon />` component to `<KolideIcon />` and create a new `<Icon />` component. The ultimate goal is to get rid of the `<KolideIcon />` and `<PlatformIcon />` components and use the encompassing `<Icon />` component for all icons. The full transition will be made when we have icon assets to replace all the kolide icons and platform icons. Currently, we don't. - Rename the `icon_name_for_label.js` utility to `icon_name.js` because the utility now includes `iconNameForLabel()` and `iconNameForPlatform()` functions. - Fixes issue #127.
76 lines
2 KiB
JavaScript
76 lines
2 KiB
JavaScript
import React, { Component } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import classnames from 'classnames';
|
|
|
|
import KolideIcon from 'components/icons/KolideIcon';
|
|
import targetInterface from 'interfaces/target';
|
|
import TargetIcon from './TargetIcon';
|
|
|
|
const baseClass = 'target-option';
|
|
|
|
class TargetOption extends Component {
|
|
static propTypes = {
|
|
onMoreInfoClick: PropTypes.func,
|
|
onSelect: PropTypes.func,
|
|
target: targetInterface.isRequired,
|
|
};
|
|
|
|
handleSelect = (evt) => {
|
|
const { onSelect, target } = this.props;
|
|
|
|
return onSelect(target, evt);
|
|
}
|
|
|
|
renderTargetDetail = () => {
|
|
const { target } = this.props;
|
|
const {
|
|
count,
|
|
primary_ip: hostIpAddress,
|
|
target_type: targetType,
|
|
} = target;
|
|
|
|
if (targetType === 'hosts') {
|
|
if (!hostIpAddress) {
|
|
return false;
|
|
}
|
|
|
|
return (
|
|
<span>
|
|
<span className={`${baseClass}__ip`}>{hostIpAddress}</span>
|
|
</span>
|
|
);
|
|
}
|
|
|
|
return <span className={`${baseClass}__count`}>{count} hosts</span>;
|
|
}
|
|
|
|
render () {
|
|
const { onMoreInfoClick, target } = this.props;
|
|
const { display_text: displayText, target_type: targetType } = target;
|
|
const {
|
|
handleSelect,
|
|
renderTargetDetail,
|
|
} = this;
|
|
const wrapperClassName = classnames(`${baseClass}__wrapper`, {
|
|
'is-label': targetType === 'labels',
|
|
'is-host': targetType === 'hosts',
|
|
});
|
|
|
|
return (
|
|
<div className={wrapperClassName}>
|
|
<button className={`button button--unstyled ${baseClass}__target-content`} onClick={onMoreInfoClick(target)}>
|
|
<div>
|
|
<TargetIcon target={target} />
|
|
<span className={`${baseClass}__label-label`}>{displayText}</span>
|
|
</div>
|
|
{renderTargetDetail()}
|
|
</button>
|
|
<button className={`button button--unstyled ${baseClass}__add-btn`} onClick={handleSelect}>
|
|
<KolideIcon name="add-button" />
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default TargetOption;
|