Add shard to scheduled query form (#1142)

* Adds shard input to Configure Pack Query Form

* Adds shard to API client

* Adds shard attribute to scheduled queries list
This commit is contained in:
Mike Stone 2017-02-01 15:48:08 -05:00 committed by GitHub
parent a000751bfe
commit f263fbcba2
11 changed files with 29 additions and 5 deletions

View File

@ -9,7 +9,7 @@ import InputField from 'components/forms/fields/InputField';
import validate from 'components/forms/ConfigurePackQueryForm/validate';
const baseClass = 'configure-pack-query-form';
const fieldNames = ['query_id', 'interval', 'logging_type', 'platform', 'version'];
const fieldNames = ['query_id', 'interval', 'logging_type', 'platform', 'shard', 'version'];
const platformOptions = [
{ label: 'All', value: 'all' },
{ label: 'Windows', value: 'windows' },
@ -90,6 +90,13 @@ class ConfigurePackQueryForm extends Component {
label="Logging"
wrapperClassName={`${baseClass}__form-field ${baseClass}__form-field--logging`}
/>
<InputField
{...fields.shard}
inputWrapperClass={`${baseClass}__form-field ${baseClass}__form-field--shard`}
placeholder="- - -"
label="Shard"
type="number"
/>
<div className={`${baseClass}__btn-wrapper`}>
<Button className={`${baseClass}__cancel-btn`} onClick={onCancel} variant="inverse">
Cancel

View File

@ -21,6 +21,7 @@ describe('ConfigurePackQueryForm - component', () => {
itBehavesLikeAFormDropdownElement(form, 'logging_type');
itBehavesLikeAFormDropdownElement(form, 'platform');
itBehavesLikeAFormDropdownElement(form, 'version');
itBehavesLikeAFormInputElement(form, 'shard');
});
});
@ -38,6 +39,7 @@ describe('ConfigurePackQueryForm - component', () => {
itBehavesLikeAFormDropdownElement(form, 'logging_type');
itBehavesLikeAFormDropdownElement(form, 'platform');
itBehavesLikeAFormDropdownElement(form, 'version');
itBehavesLikeAFormInputElement(form, 'shard', 'InputField', 12);
form.find('form').simulate('submit');
@ -47,6 +49,7 @@ describe('ConfigurePackQueryForm - component', () => {
platform: 'all',
query_id: 1,
version: '',
shard: 12,
});
});
});

View File

@ -21,6 +21,12 @@ const validate = (formData) => {
errors.logging_type = 'A Logging Type must be selected';
}
if (formData.shard) {
if (formData.shard < 0 || formData.shard > 100) {
errors.shard = 'Shard must be between 0 and 100';
}
}
const valid = !size(errors);
return { valid, errors };

View File

@ -105,6 +105,7 @@ class ScheduledQueriesList extends Component {
<th>Interval [s]</th>
<th>Platform</th>
<th><Icon name="osquery" /> Ver.</th>
<th>Shard</th>
<th>Logging</th>
</tr>
</thead>

View File

@ -56,7 +56,7 @@ class ScheduledQueriesListItem extends Component {
render () {
const { checked, disabled, scheduledQuery } = this.props;
const { onCheck, renderPlatformIcon } = this;
const { id, name, interval, version } = scheduledQuery;
const { id, name, interval, shard, version } = scheduledQuery;
const { loggingTypeString } = this;
return (
@ -73,6 +73,7 @@ class ScheduledQueriesListItem extends Component {
<td>{interval}</td>
<td>{renderPlatformIcon()}</td>
<td>{version ? `${version}+` : 'Any'}</td>
<td>{shard}</td>
<td><Icon name={loggingTypeString()} /></td>
</tr>
);

View File

@ -13,6 +13,7 @@ describe('ScheduledQueriesListItem - component', () => {
const component = mount(<ScheduledQueriesListItem checked={false} onSelect={noop} scheduledQuery={scheduledQueryStub} />);
expect(component.text()).toInclude(scheduledQueryStub.name);
expect(component.text()).toInclude(scheduledQueryStub.interval);
expect(component.text()).toInclude(scheduledQueryStub.shard);
expect(component.find('PlatformIcon').length).toEqual(1);
});

View File

@ -90,7 +90,8 @@
}
&:nth-child(4),
&:nth-child(5) {
&:nth-child(5),
&:nth-child(6) {
font-size: 14px;
font-weight: $normal;
line-height: 2.71;
@ -103,7 +104,7 @@
}
}
&:nth-child(6) {
&:nth-child(7) {
text-align: center;
font-size: 18px;
color: $text-ultradark;

View File

@ -188,7 +188,7 @@ class Kolide extends Base {
.then((response) => { return response.query; });
}
createScheduledQuery = ({ interval, logging_type: loggingType, pack_id: packID, platform, query_id: queryID, version }) => {
createScheduledQuery = ({ interval, logging_type: loggingType, pack_id: packID, platform, query_id: queryID, shard, version }) => {
const removed = loggingType === 'differential';
const snapshot = loggingType === 'snapshot';
@ -199,6 +199,7 @@ class Kolide extends Base {
query_id: Number(queryID),
removed,
snapshot,
shard: Number(shard),
version,
};

View File

@ -400,6 +400,7 @@ describe('Kolide - API client', () => {
pack_id: 1,
platform: 'darwin',
query_id: 2,
shard: 12,
};
const request = validCreateScheduledQueryRequest(bearerToken, formData);

View File

@ -63,6 +63,7 @@ export const validCreateScheduledQueryRequest = (bearerToken, formData) => {
query_id: Number(formData.query_id),
removed: true,
snapshot: false,
shard: Number(formData.shard),
};
return nock('http://localhost:8080', {

View File

@ -157,6 +157,7 @@ export const scheduledQueryStub = {
query: 'SELECT * FROM users',
query_id: 5,
removed: false,
shard: 12,
snapshot: true,
};