2019-01-07 01:25:33 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
2016-10-19 20:22:18 +00:00
|
|
|
|
2016-11-28 19:20:15 +00:00
|
|
|
import osqueryTableInterface from 'interfaces/osquery_table';
|
|
|
|
|
import { osqueryTableNames } from 'utilities/osquery_tables';
|
|
|
|
|
import Dropdown from 'components/forms/fields/Dropdown';
|
2016-12-22 19:26:18 +00:00
|
|
|
import Icon from 'components/icons/Icon';
|
|
|
|
|
import PlatformIcon from 'components/icons/PlatformIcon';
|
2016-11-28 19:20:15 +00:00
|
|
|
import SecondarySidePanelContainer from '../SecondarySidePanelContainer';
|
2016-12-16 16:07:35 +00:00
|
|
|
|
2020-07-07 16:47:50 +00:00
|
|
|
import displayTypeForDataType from './helpers';
|
2016-10-11 15:32:39 +00:00
|
|
|
|
2016-11-03 19:40:54 +00:00
|
|
|
const baseClass = 'query-side-panel';
|
2016-10-11 15:32:39 +00:00
|
|
|
|
|
|
|
|
class QuerySidePanel extends Component {
|
|
|
|
|
static propTypes = {
|
|
|
|
|
onOsqueryTableSelect: PropTypes.func,
|
|
|
|
|
onTextEditorInputChange: PropTypes.func,
|
2016-10-21 23:13:41 +00:00
|
|
|
selectedOsqueryTable: osqueryTableInterface,
|
2016-10-11 15:32:39 +00:00
|
|
|
};
|
|
|
|
|
|
2016-12-22 19:26:18 +00:00
|
|
|
onSelectTable = (value) => {
|
2016-10-11 15:32:39 +00:00
|
|
|
const { onOsqueryTableSelect } = this.props;
|
|
|
|
|
|
2016-11-09 14:26:15 +00:00
|
|
|
onOsqueryTableSelect(value);
|
2016-10-11 15:32:39 +00:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onSuggestedQueryClick = (query) => {
|
|
|
|
|
return (evt) => {
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|
|
|
|
|
|
const { onTextEditorInputChange } = this.props;
|
|
|
|
|
|
|
|
|
|
return onTextEditorInputChange(query);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
renderColumns = () => {
|
|
|
|
|
const { selectedOsqueryTable } = this.props;
|
2017-02-23 19:18:23 +00:00
|
|
|
const columns = selectedOsqueryTable.columns;
|
2016-12-16 16:07:35 +00:00
|
|
|
const columnBaseClass = 'query-column-list';
|
2016-10-11 15:32:39 +00:00
|
|
|
|
2016-10-21 23:13:41 +00:00
|
|
|
return columns.map((column) => {
|
2016-10-11 15:32:39 +00:00
|
|
|
return (
|
2016-12-16 16:07:35 +00:00
|
|
|
<li key={column.name} className={`${columnBaseClass}__item`}>
|
|
|
|
|
<span className={`${columnBaseClass}__name`}>{column.name}</span>
|
|
|
|
|
<div className={`${columnBaseClass}__description`}>
|
|
|
|
|
<span className={`${columnBaseClass}__type`}>{displayTypeForDataType(column.type)}</span>
|
|
|
|
|
<Icon name="help-solid" className={`${columnBaseClass}__help`} title={column.description} />
|
2016-10-11 15:32:39 +00:00
|
|
|
</div>
|
2016-12-16 16:07:35 +00:00
|
|
|
</li>
|
2016-10-11 15:32:39 +00:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderTableSelect = () => {
|
|
|
|
|
const { onSelectTable } = this;
|
|
|
|
|
const { selectedOsqueryTable } = this.props;
|
|
|
|
|
|
2016-11-09 14:26:15 +00:00
|
|
|
const tableNames = osqueryTableNames.map((name) => {
|
|
|
|
|
return { label: name, value: name };
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-11 15:32:39 +00:00
|
|
|
return (
|
2016-11-09 14:26:15 +00:00
|
|
|
<Dropdown
|
|
|
|
|
options={tableNames}
|
|
|
|
|
value={selectedOsqueryTable.name}
|
2016-12-16 15:54:49 +00:00
|
|
|
onChange={onSelectTable}
|
2016-11-09 14:26:15 +00:00
|
|
|
placeholder="Choose Table..."
|
|
|
|
|
/>
|
2016-10-11 15:32:39 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
|
const {
|
|
|
|
|
renderColumns,
|
|
|
|
|
renderTableSelect,
|
|
|
|
|
} = this;
|
2020-07-07 16:47:50 +00:00
|
|
|
const { selectedOsqueryTable: { description, platforms } } = this.props;
|
2016-10-11 15:32:39 +00:00
|
|
|
|
|
|
|
|
return (
|
2016-11-03 19:40:54 +00:00
|
|
|
<SecondarySidePanelContainer className={baseClass}>
|
2016-12-16 16:07:35 +00:00
|
|
|
<div className={`${baseClass}__choose-table`}>
|
2020-12-07 23:08:59 +00:00
|
|
|
<h2 className={`${baseClass}__header`}>Documentation</h2>
|
2016-12-16 16:07:35 +00:00
|
|
|
{renderTableSelect()}
|
|
|
|
|
<p className={`${baseClass}__description`}>{description}</p>
|
2016-10-11 15:32:39 +00:00
|
|
|
</div>
|
2016-12-16 16:07:35 +00:00
|
|
|
|
|
|
|
|
<div className={`${baseClass}__os-availability`}>
|
|
|
|
|
<h2 className={`${baseClass}__header`}>OS Availability</h2>
|
|
|
|
|
<ul className={`${baseClass}__platforms`}>
|
2020-07-07 16:47:50 +00:00
|
|
|
{platforms.map((platform) => {
|
|
|
|
|
if (platform === 'all') {
|
|
|
|
|
return <li key={platform}><Icon name="hosts" /> {platform}</li>;
|
2016-12-22 19:26:18 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-07 16:47:50 +00:00
|
|
|
return <li key={platform}><PlatformIcon name={platform} title={platform} /> {platform}</li>;
|
2016-12-16 16:07:35 +00:00
|
|
|
})}
|
|
|
|
|
</ul>
|
2016-10-11 15:32:39 +00:00
|
|
|
</div>
|
2016-12-16 16:07:35 +00:00
|
|
|
|
|
|
|
|
<div className={`${baseClass}__columns`}>
|
|
|
|
|
<h2 className={`${baseClass}__header`}>Columns</h2>
|
|
|
|
|
<ul className={`${baseClass}__column-list`}>
|
|
|
|
|
{renderColumns()}
|
|
|
|
|
</ul>
|
2016-10-11 15:32:39 +00:00
|
|
|
</div>
|
2016-10-20 12:43:25 +00:00
|
|
|
</SecondarySidePanelContainer>
|
2016-10-11 15:32:39 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-03 19:40:54 +00:00
|
|
|
export default QuerySidePanel;
|