import React, { Component, PropTypes } from 'react'; import radium from 'radium'; import componentStyles from './styles'; import Button from '../../../buttons/Button'; import Dropdown from '../../fields/Dropdown'; import InputField from '../../fields/InputField'; import validatePresence from '../../validators/validate_presence'; const RUN_TYPES = { RUN: 'RUN', RUN_AND_SAVE: 'RUN_AND_SAVE', SAVE: 'SAVE', }; class SaveQueryForm extends Component { static propTypes = { onSubmit: PropTypes.func, saveQuery: PropTypes.bool, }; constructor (props) { super(props); this.state = { errors: { name: null, description: null, duration: null, platforms: null, hosts: null, hostsPercentage: null, scanInterval: null, }, formData: { name: null, description: null, duration: 'short', platforms: 'all', hosts: 'all', hostsPercentage: null, scanInterval: 0, }, showMoreOptions: false, }; } componentWillMount () { global.window.addEventListener('keydown', this.handleKeydown); } componentWillUnmount () { global.window.removeEventListener('keydown', this.handleKeydown); } onFieldChange = (fieldName) => { return ({ target }) => { const { errors, formData } = this.state; this.setState({ errors: { ...errors, [fieldName]: null, }, formData: { ...formData, [fieldName]: target.value, }, }); }; } onFormSubmit = (runType) => { return (evt) => { if (evt) { evt.preventDefault(); } const { formData } = this.state; const { onSubmit } = this.props; const { validate } = this; if (validate(runType)) return onSubmit({ formData, runType }); return false; }; } handleKeydown = (evt) => { const { metaKey, code } = evt; const { onFormSubmit } = this; const { RUN_AND_SAVE, RUN } = RUN_TYPES; const { saveQuery } = this.props; const runType = saveQuery ? RUN_AND_SAVE : RUN; if (metaKey && code === 'Enter') { return onFormSubmit(runType)(); } return false; }; validate = (runType) => { const { errors, formData: { name }, } = this.state; const { RUN } = RUN_TYPES; if (runType === RUN) return true; if (!validatePresence(name)) { this.setState({ errors: { ...errors, name: 'Query Name field must be completed', }, }); return false; } return true; } toggleShowMoreOptions = () => { const { showMoreOptions } = this.state; this.setState({ showMoreOptions: !showMoreOptions, }); return false; }; renderMoreOptionsCtaSection = () => { const { moreOptionsIconStyles, moreOptionsCtaSectionStyles, moreOptionsTextStyles } = componentStyles; const { showMoreOptions } = this.state; const { toggleShowMoreOptions } = this; if (showMoreOptions) { return (
Fewer Options
); } return (
More Options
); } renderMoreOptionsFormFields = () => { const { errors, formData: { hosts }, showMoreOptions, } = this.state; const { dropdownInputStyles, formSectionStyles, helpTextStyles, labelStyles, queryDescriptionInputStyles, queryHostsPercentageStyles, queryNameInputStyles, } = componentStyles; const { onFieldChange } = this; if (!showMoreOptions) return false; return (
If your query is really complex and/or it is not clear why you wrote this query, you should write a description so others can reuse this query for the correct reason.
Individual hosts are not always online. A longer duration will return more complete results. You can view results of any in-progress query at any time.
Specifying a platform allows you to restrict the query from running on a certain platform (even on hosts specifically targeted that do not match).
Run Query On All Hosts
Run Query On % Of All Hosts
Specifying a platform allows you to restrict the query from running on a certain platform (even on hosts specifically targeted that do not match).
You can use queries you write in "scans". The interval can be used to control how frequently the query runs when it is running continuously.
); }; renderRunQuery = () => { const { buttonStyles, runQuerySectionStyles, runQueryTipStyles, } = componentStyles; const { onFormSubmit } = this; const { RUN } = RUN_TYPES; return (
⌘ + Enter