2016-10-17 18:55:03 +00:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
2016-11-17 17:12:41 +00:00
|
|
|
import AceEditor from 'react-ace';
|
2016-10-17 18:55:03 +00:00
|
|
|
import { connect } from 'react-redux';
|
2017-01-19 21:29:49 +00:00
|
|
|
import { filter, orderBy, sortBy } from 'lodash';
|
|
|
|
import moment from 'moment';
|
2016-12-05 15:21:03 +00:00
|
|
|
import { push } from 'react-router-redux';
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
import entityGetter from 'redux/utilities/entityGetter';
|
2017-01-16 20:59:01 +00:00
|
|
|
import { getStatusLabelCounts, setDisplay } from 'redux/nodes/components/ManageHostsPage/actions';
|
2017-01-17 21:44:00 +00:00
|
|
|
import helpers from 'pages/hosts/ManageHostsPage/helpers';
|
2016-11-17 17:12:41 +00:00
|
|
|
import hostActions from 'redux/nodes/entities/hosts/actions';
|
|
|
|
import labelActions from 'redux/nodes/entities/labels/actions';
|
|
|
|
import labelInterface from 'interfaces/label';
|
|
|
|
import HostDetails from 'components/hosts/HostDetails';
|
|
|
|
import hostInterface from 'interfaces/host';
|
|
|
|
import HostSidePanel from 'components/side_panels/HostSidePanel';
|
2016-11-21 16:26:58 +00:00
|
|
|
import HostsTable from 'components/hosts/HostsTable';
|
2017-01-19 23:12:37 +00:00
|
|
|
import LonelyHost from 'components/hosts/LonelyHost';
|
2016-12-22 19:26:18 +00:00
|
|
|
import Icon from 'components/icons/Icon';
|
2017-01-17 18:55:19 +00:00
|
|
|
import PlatformIcon from 'components/icons/PlatformIcon';
|
2016-11-17 17:12:41 +00:00
|
|
|
import osqueryTableInterface from 'interfaces/osquery_table';
|
2016-12-12 16:48:50 +00:00
|
|
|
import paths from 'router/paths';
|
2017-01-06 00:01:17 +00:00
|
|
|
import QueryForm from 'components/forms/queries/QueryForm';
|
2016-11-17 17:12:41 +00:00
|
|
|
import QuerySidePanel from 'components/side_panels/QuerySidePanel';
|
2016-11-21 16:26:58 +00:00
|
|
|
import Rocker from 'components/buttons/Rocker';
|
2017-01-19 17:57:59 +00:00
|
|
|
import Button from 'components/buttons/Button';
|
|
|
|
import Modal from 'components/modals/Modal';
|
2016-11-17 17:12:41 +00:00
|
|
|
import { selectOsqueryTable } from 'redux/nodes/components/QueryPages/actions';
|
2017-01-19 17:57:59 +00:00
|
|
|
import { renderFlash } from 'redux/nodes/notifications/actions';
|
2017-01-16 20:59:01 +00:00
|
|
|
import statusLabelsInterface from 'interfaces/status_labels';
|
2016-12-15 14:44:45 +00:00
|
|
|
import iconClassForLabel from 'utilities/icon_class_for_label';
|
2017-01-17 18:55:19 +00:00
|
|
|
import platformIconClass from 'utilities/platform_icon_class';
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2016-12-05 15:21:03 +00:00
|
|
|
const NEW_LABEL_HASH = '#new_label';
|
2016-12-15 14:44:45 +00:00
|
|
|
const baseClass = 'manage-hosts';
|
2016-12-05 15:21:03 +00:00
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
export class ManageHostsPage extends Component {
|
2016-10-17 18:55:03 +00:00
|
|
|
static propTypes = {
|
|
|
|
dispatch: PropTypes.func,
|
2016-11-21 16:26:58 +00:00
|
|
|
display: PropTypes.oneOf(['Grid', 'List']),
|
2016-10-21 23:13:41 +00:00
|
|
|
hosts: PropTypes.arrayOf(hostInterface),
|
2016-12-05 15:21:03 +00:00
|
|
|
isAddLabel: PropTypes.bool,
|
2017-01-06 00:01:17 +00:00
|
|
|
labelErrors: PropTypes.shape({
|
|
|
|
base: PropTypes.string,
|
|
|
|
}),
|
2016-11-17 17:12:41 +00:00
|
|
|
labels: PropTypes.arrayOf(labelInterface),
|
|
|
|
selectedLabel: labelInterface,
|
|
|
|
selectedOsqueryTable: osqueryTableInterface,
|
2017-01-16 20:59:01 +00:00
|
|
|
statusLabels: statusLabelsInterface,
|
2016-10-17 18:55:03 +00:00
|
|
|
};
|
|
|
|
|
2016-11-21 16:26:58 +00:00
|
|
|
static defaultProps = {
|
|
|
|
display: 'Grid',
|
|
|
|
};
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
labelQueryText: '',
|
2017-01-19 17:57:59 +00:00
|
|
|
showDeleteModal: false,
|
2016-11-17 17:12:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-10-17 18:55:03 +00:00
|
|
|
componentWillMount () {
|
2017-01-16 20:59:01 +00:00
|
|
|
const { dispatch } = this.props;
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2017-01-16 20:59:01 +00:00
|
|
|
dispatch(hostActions.loadAll());
|
|
|
|
dispatch(labelActions.loadAll());
|
|
|
|
dispatch(getStatusLabelCounts);
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
onCancelAddLabel = () => {
|
2016-12-05 15:21:03 +00:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
dispatch(push('/hosts/manage'));
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
onAddLabelClick = (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
2016-12-05 15:21:03 +00:00
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
dispatch(push(`/hosts/manage${NEW_LABEL_HASH}`));
|
2016-11-17 17:12:41 +00:00
|
|
|
|
2016-10-17 18:55:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
onHostDetailActionClick = (type) => {
|
|
|
|
return (host) => {
|
|
|
|
return (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
console.log(type, host);
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
onLabelClick = (selectedLabel) => {
|
|
|
|
return (evt) => {
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
const { dispatch } = this.props;
|
2016-12-12 16:48:50 +00:00
|
|
|
const { MANAGE_HOSTS } = paths;
|
|
|
|
const { slug } = selectedLabel;
|
|
|
|
const nextLocation = slug === 'all-hosts' ? MANAGE_HOSTS : `${MANAGE_HOSTS}/${slug}`;
|
2016-11-17 17:12:41 +00:00
|
|
|
|
2016-12-12 16:48:50 +00:00
|
|
|
dispatch(push(nextLocation));
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onOsqueryTableSelect = (tableName) => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
dispatch(selectOsqueryTable(tableName));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
onSaveAddLabel = (formData) => {
|
|
|
|
const { dispatch } = this.props;
|
|
|
|
|
|
|
|
return dispatch(labelActions.create(formData))
|
|
|
|
.then(() => {
|
2016-12-05 15:21:03 +00:00
|
|
|
dispatch(push('/hosts/manage'));
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-16 15:54:49 +00:00
|
|
|
onToggleDisplay = (val) => {
|
|
|
|
const { dispatch } = this.props;
|
2016-11-21 16:26:58 +00:00
|
|
|
|
2016-12-16 15:54:49 +00:00
|
|
|
dispatch(setDisplay(val));
|
2016-11-21 16:26:58 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-19 17:57:59 +00:00
|
|
|
onDeleteLabel = () => {
|
|
|
|
const { toggleModal } = this;
|
|
|
|
const { dispatch, selectedLabel } = this.props;
|
|
|
|
const { MANAGE_HOSTS } = paths;
|
|
|
|
|
|
|
|
return dispatch(labelActions.destroy(selectedLabel))
|
|
|
|
.then(() => {
|
|
|
|
toggleModal();
|
|
|
|
dispatch(push(MANAGE_HOSTS));
|
|
|
|
dispatch(renderFlash('success', 'Label successfully deleted'));
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleModal = () => {
|
|
|
|
const { showDeleteModal } = this.state;
|
|
|
|
|
|
|
|
this.setState({ showDeleteModal: !showDeleteModal });
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-16 22:55:31 +00:00
|
|
|
filterHosts = () => {
|
2017-01-17 21:44:00 +00:00
|
|
|
const { hosts, selectedLabel } = this.props;
|
2017-01-16 22:55:31 +00:00
|
|
|
|
2017-01-17 21:44:00 +00:00
|
|
|
return helpers.filterHosts(hosts, selectedLabel);
|
2017-01-16 22:55:31 +00:00
|
|
|
}
|
|
|
|
|
2017-01-13 01:18:23 +00:00
|
|
|
sortHosts = (hosts) => {
|
|
|
|
const alphaHosts = sortBy(hosts, (h) => { return h.hostname; });
|
|
|
|
const orderedHosts = orderBy(alphaHosts, 'status', 'desc');
|
|
|
|
|
|
|
|
return orderedHosts;
|
|
|
|
}
|
|
|
|
|
2017-01-19 17:57:59 +00:00
|
|
|
renderModal = () => {
|
|
|
|
const { showDeleteModal } = this.state;
|
|
|
|
const { toggleModal, onDeleteLabel } = this;
|
|
|
|
|
|
|
|
if (!showDeleteModal) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
title="Delete Label"
|
|
|
|
onExit={toggleModal}
|
|
|
|
className={`${baseClass}__modal`}
|
|
|
|
>
|
|
|
|
<p>Are you sure you wish to delete this label?</p>
|
|
|
|
<div>
|
|
|
|
<Button onClick={toggleModal} variant="inverse">Cancel</Button>
|
|
|
|
<Button onClick={onDeleteLabel} variant="alert">Delete</Button>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderDeleteButton = () => {
|
|
|
|
const { toggleModal } = this;
|
|
|
|
const { selectedLabel: { type } } = this.props;
|
|
|
|
|
|
|
|
if (type !== 'custom') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={`${baseClass}__delete-label`}>
|
|
|
|
<Button onClick={toggleModal} variant="alert">Delete</Button>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-17 18:55:19 +00:00
|
|
|
renderIcon = () => {
|
|
|
|
const { selectedLabel } = this.props;
|
|
|
|
|
|
|
|
if (platformIconClass(selectedLabel.display_text)) {
|
|
|
|
return <PlatformIcon name={platformIconClass(selectedLabel.display_text)} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
return <Icon name={iconClassForLabel(selectedLabel)} />;
|
|
|
|
}
|
|
|
|
|
2017-01-11 19:08:27 +00:00
|
|
|
renderQuery = () => {
|
|
|
|
const { selectedLabel } = this.props;
|
|
|
|
const { label_type: labelType, query } = selectedLabel;
|
|
|
|
|
|
|
|
if (!query || labelType === 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AceEditor
|
|
|
|
editorProps={{ $blockScrolling: Infinity }}
|
|
|
|
mode="kolide"
|
|
|
|
minLines={1}
|
|
|
|
maxLines={20}
|
|
|
|
name="label-header"
|
|
|
|
readOnly
|
|
|
|
setOptions={{ wrap: true }}
|
|
|
|
showGutter={false}
|
|
|
|
showPrintMargin={false}
|
|
|
|
theme="kolide"
|
|
|
|
value={query}
|
|
|
|
width="100%"
|
|
|
|
fontSize={14}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
renderHeader = () => {
|
2017-01-19 17:57:59 +00:00
|
|
|
const { renderIcon, renderQuery, renderDeleteButton } = this;
|
2017-01-17 21:44:00 +00:00
|
|
|
const { display, isAddLabel, selectedLabel, statusLabels } = this.props;
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
if (!selectedLabel || isAddLabel) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-19 21:29:49 +00:00
|
|
|
const { count, description, display_text: displayText, statusLabelKey, type } = selectedLabel;
|
2016-11-21 16:26:58 +00:00
|
|
|
const { onToggleDisplay } = this;
|
|
|
|
const buttonOptions = {
|
2016-12-16 15:54:49 +00:00
|
|
|
rightIcon: 'grid-select',
|
|
|
|
rightText: 'Grid',
|
|
|
|
leftIcon: 'list-select',
|
|
|
|
leftText: 'List',
|
2016-11-21 16:26:58 +00:00
|
|
|
};
|
2016-11-17 17:12:41 +00:00
|
|
|
|
2017-01-19 21:29:49 +00:00
|
|
|
const hostCount = type === 'status' ? statusLabels[`${statusLabelKey}`] : count;
|
2017-01-17 21:44:00 +00:00
|
|
|
const hostsTotalDisplay = hostCount === 1 ? '1 Host Total' : `${hostCount} Hosts Total`;
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
return (
|
2016-12-15 14:44:45 +00:00
|
|
|
<div className={`${baseClass}__header`}>
|
2017-01-19 17:57:59 +00:00
|
|
|
{renderDeleteButton()}
|
|
|
|
|
2016-12-15 14:44:45 +00:00
|
|
|
<h1 className={`${baseClass}__title`}>
|
2017-01-17 18:55:19 +00:00
|
|
|
{renderIcon()}
|
2016-12-15 14:44:45 +00:00
|
|
|
<span>{displayText}</span>
|
|
|
|
</h1>
|
|
|
|
|
2017-01-11 19:08:27 +00:00
|
|
|
{ renderQuery() }
|
2016-12-15 14:44:45 +00:00
|
|
|
|
2017-01-11 19:08:27 +00:00
|
|
|
{description &&
|
|
|
|
<div className={`${baseClass}__description`}>
|
|
|
|
<h2>Description</h2>
|
|
|
|
<p>{description}</p>
|
|
|
|
</div>
|
|
|
|
}
|
2016-12-15 14:44:45 +00:00
|
|
|
|
|
|
|
<div className={`${baseClass}__topper`}>
|
2017-01-17 21:44:00 +00:00
|
|
|
<p className={`${baseClass}__host-count`}>{hostsTotalDisplay}</p>
|
2016-11-21 16:26:58 +00:00
|
|
|
<Rocker
|
2016-12-16 15:54:49 +00:00
|
|
|
onChange={onToggleDisplay}
|
2016-11-21 16:26:58 +00:00
|
|
|
options={buttonOptions}
|
|
|
|
value={display}
|
|
|
|
/>
|
|
|
|
</div>
|
2016-11-17 17:12:41 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-19 21:14:44 +00:00
|
|
|
renderNoHosts = () => {
|
2017-01-19 21:45:03 +00:00
|
|
|
const { selectedLabel } = this.props;
|
|
|
|
const { type } = selectedLabel || '';
|
|
|
|
const isCustom = type === 'custom';
|
|
|
|
|
2017-01-19 21:14:44 +00:00
|
|
|
return (
|
|
|
|
<div className={`${baseClass}__no-hosts`}>
|
|
|
|
<h1>No matching hosts found.</h1>
|
|
|
|
<h2>Where are the missing hosts?</h2>
|
|
|
|
<ul>
|
2017-01-19 21:45:03 +00:00
|
|
|
{isCustom && <li>Check your SQL query above to confirm there are no mistakes.</li>}
|
2017-01-19 21:14:44 +00:00
|
|
|
<li>Check to confirm that your hosts are online.</li>
|
|
|
|
<li>Confirm that your expected hosts have osqueryd installed and configured.</li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<div className={`${baseClass}__no-hosts-contact`}>
|
|
|
|
<p>Still having trouble? Want to talk to a human?</p>
|
|
|
|
<p>Contact Kolide Support:</p>
|
|
|
|
<p><a href="mailto:support@kolide.co">support@kolide.co</a></p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:26:58 +00:00
|
|
|
renderHosts = () => {
|
2017-01-19 23:12:37 +00:00
|
|
|
const { display, isAddLabel, selectedLabel } = this.props;
|
2017-01-19 21:14:44 +00:00
|
|
|
const { onHostDetailActionClick, filterHosts, sortHosts, renderNoHosts } = this;
|
2016-11-21 16:26:58 +00:00
|
|
|
|
|
|
|
if (isAddLabel) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-16 22:55:31 +00:00
|
|
|
const filteredHosts = filterHosts();
|
|
|
|
const sortedHosts = sortHosts(filteredHosts);
|
2017-01-13 01:18:23 +00:00
|
|
|
|
2017-01-19 21:14:44 +00:00
|
|
|
if (sortedHosts.length === 0) {
|
2017-01-19 23:12:37 +00:00
|
|
|
if (selectedLabel && selectedLabel.type === 'all') {
|
|
|
|
return <LonelyHost />;
|
|
|
|
}
|
|
|
|
|
2017-01-19 21:14:44 +00:00
|
|
|
return renderNoHosts();
|
|
|
|
}
|
|
|
|
|
2016-11-21 16:26:58 +00:00
|
|
|
if (display === 'Grid') {
|
2017-01-13 01:18:23 +00:00
|
|
|
return sortedHosts.map((host) => {
|
2016-11-21 16:26:58 +00:00
|
|
|
return (
|
|
|
|
<HostDetails
|
|
|
|
host={host}
|
|
|
|
key={`host-${host.id}-details`}
|
|
|
|
onDisableClick={onHostDetailActionClick('disable')}
|
|
|
|
onQueryClick={onHostDetailActionClick('query')}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-01-13 01:18:23 +00:00
|
|
|
return <HostsTable hosts={sortedHosts} />;
|
2016-11-21 16:26:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
renderForm = () => {
|
2017-01-06 00:01:17 +00:00
|
|
|
const { isAddLabel, labelErrors } = this.props;
|
2016-11-17 17:12:41 +00:00
|
|
|
const {
|
|
|
|
onCancelAddLabel,
|
2017-01-06 00:01:17 +00:00
|
|
|
onOsqueryTableSelect,
|
2016-11-17 17:12:41 +00:00
|
|
|
onSaveAddLabel,
|
|
|
|
} = this;
|
2017-01-06 00:01:17 +00:00
|
|
|
const queryStub = { description: '', name: '', query: '' };
|
2016-11-17 17:12:41 +00:00
|
|
|
|
|
|
|
if (isAddLabel) {
|
|
|
|
return (
|
2017-01-10 19:20:36 +00:00
|
|
|
<div className="body-wrap">
|
|
|
|
<QueryForm
|
|
|
|
key="query-composer"
|
|
|
|
onCancel={onCancelAddLabel}
|
|
|
|
onOsqueryTableSelect={onOsqueryTableSelect}
|
|
|
|
handleSubmit={onSaveAddLabel}
|
|
|
|
queryType="label"
|
|
|
|
query={queryStub}
|
|
|
|
serverErrors={labelErrors}
|
|
|
|
/>
|
|
|
|
</div>
|
2016-11-17 17:12:41 +00:00
|
|
|
);
|
|
|
|
}
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2016-11-21 16:26:58 +00:00
|
|
|
return false;
|
2016-10-17 18:55:03 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
renderSidePanel = () => {
|
|
|
|
let SidePanel;
|
|
|
|
const {
|
2016-12-05 15:21:03 +00:00
|
|
|
isAddLabel,
|
2016-11-17 17:12:41 +00:00
|
|
|
labels,
|
|
|
|
selectedLabel,
|
|
|
|
selectedOsqueryTable,
|
2017-01-16 20:59:01 +00:00
|
|
|
statusLabels,
|
2016-11-17 17:12:41 +00:00
|
|
|
} = this.props;
|
|
|
|
const { onAddLabelClick, onLabelClick, onOsqueryTableSelect } = this;
|
|
|
|
|
|
|
|
if (isAddLabel) {
|
|
|
|
SidePanel = (
|
|
|
|
<QuerySidePanel
|
|
|
|
key="query-side-panel"
|
|
|
|
onOsqueryTableSelect={onOsqueryTableSelect}
|
|
|
|
selectedOsqueryTable={selectedOsqueryTable}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
SidePanel = (
|
|
|
|
<HostSidePanel
|
|
|
|
key="hosts-side-panel"
|
|
|
|
labels={labels}
|
|
|
|
onAddLabelClick={onAddLabelClick}
|
|
|
|
onLabelClick={onLabelClick}
|
|
|
|
selectedLabel={selectedLabel}
|
2017-01-16 20:59:01 +00:00
|
|
|
statusLabels={statusLabels}
|
2016-11-17 17:12:41 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-06 15:36:51 +00:00
|
|
|
return SidePanel;
|
2016-11-17 17:12:41 +00:00
|
|
|
}
|
|
|
|
|
2016-10-17 18:55:03 +00:00
|
|
|
render () {
|
2017-01-19 17:57:59 +00:00
|
|
|
const { renderForm, renderHeader, renderHosts, renderSidePanel, renderModal } = this;
|
2016-12-21 18:39:40 +00:00
|
|
|
const { display, isAddLabel } = this.props;
|
2016-10-17 18:55:03 +00:00
|
|
|
|
|
|
|
return (
|
2016-12-15 14:44:45 +00:00
|
|
|
<div className="has-sidebar">
|
2016-12-21 18:39:40 +00:00
|
|
|
{renderForm()}
|
|
|
|
{!isAddLabel &&
|
|
|
|
<div className={`${baseClass} body-wrap`}>
|
|
|
|
{renderHeader()}
|
|
|
|
<div className={`${baseClass}__list ${baseClass}__list--${display.toLowerCase()}`}>
|
|
|
|
{renderHosts()}
|
|
|
|
</div>
|
2016-12-15 14:44:45 +00:00
|
|
|
</div>
|
2016-12-21 18:39:40 +00:00
|
|
|
}
|
2016-12-15 14:44:45 +00:00
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
{renderSidePanel()}
|
2017-01-19 17:57:59 +00:00
|
|
|
{renderModal()}
|
2016-10-17 18:55:03 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-12 16:48:50 +00:00
|
|
|
const mapStateToProps = (state, { location, params }) => {
|
|
|
|
const activeLabelSlug = params.active_label || 'all-hosts';
|
2017-01-16 20:59:01 +00:00
|
|
|
const { display, status_labels: statusLabels } = state.components.ManageHostsPage;
|
2016-10-17 18:55:03 +00:00
|
|
|
const { entities: hosts } = entityGetter(state).get('hosts');
|
2016-12-12 16:48:50 +00:00
|
|
|
const labelEntities = entityGetter(state).get('labels');
|
|
|
|
const { entities: labels } = labelEntities;
|
2016-12-05 15:21:03 +00:00
|
|
|
const isAddLabel = location.hash === NEW_LABEL_HASH;
|
2016-12-12 16:48:50 +00:00
|
|
|
const selectedLabel = labelEntities.findBy(
|
|
|
|
{ slug: activeLabelSlug },
|
|
|
|
{ ignoreCase: true },
|
|
|
|
);
|
2016-11-17 17:12:41 +00:00
|
|
|
const { selectedOsqueryTable } = state.components.QueryPages;
|
2017-01-06 00:01:17 +00:00
|
|
|
const labelErrors = state.entities.labels.errors;
|
2016-10-17 18:55:03 +00:00
|
|
|
|
2017-01-19 21:29:49 +00:00
|
|
|
// TODO: remove this once the API is updated to return new_count
|
|
|
|
statusLabels.new_count = filter(hosts, (h) => {
|
|
|
|
return moment().diff(h.created_at, 'hours') <= 24;
|
|
|
|
}).length;
|
|
|
|
|
2016-11-17 17:12:41 +00:00
|
|
|
return {
|
2016-11-21 16:26:58 +00:00
|
|
|
display,
|
2016-11-17 17:12:41 +00:00
|
|
|
hosts,
|
2016-12-05 15:21:03 +00:00
|
|
|
isAddLabel,
|
2017-01-06 00:01:17 +00:00
|
|
|
labelErrors,
|
2016-11-17 17:12:41 +00:00
|
|
|
labels,
|
|
|
|
selectedLabel,
|
|
|
|
selectedOsqueryTable,
|
2017-01-16 20:59:01 +00:00
|
|
|
statusLabels,
|
2016-11-17 17:12:41 +00:00
|
|
|
};
|
2016-10-17 18:55:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(ManageHostsPage);
|