import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { noop } from 'lodash'; import Button from 'components/buttons/Button'; import Dropdown from 'components/forms/fields/Dropdown'; import Form from 'components/forms/Form'; import formFieldInterface from 'interfaces/form_field'; import helpers from 'components/forms/queries/QueryForm/helpers'; import InputField from 'components/forms/fields/InputField'; import KolideAce from 'components/KolideAce'; import validate from 'components/forms/LabelForm/validate'; const baseClass = 'label-form'; class LabelForm extends Component { static propTypes = { baseError: PropTypes.string, fields: PropTypes.shape({ description: formFieldInterface.isRequired, name: formFieldInterface.isRequired, platform: formFieldInterface.isRequired, query: formFieldInterface.isRequired, }).isRequired, formData: PropTypes.shape({ type: PropTypes.string, label_type: PropTypes.string, label_membership_type: PropTypes.string, }), handleSubmit: PropTypes.func.isRequired, isEdit: PropTypes.bool, onCancel: PropTypes.func.isRequired, onOsqueryTableSelect: PropTypes.func, }; static defaultProps = { isEdit: false, }; onLoad = (editor) => { editor.setOptions({ enableLinking: true, }); editor.on('linkClick', (data) => { const { type, value } = data.token; const { onOsqueryTableSelect } = this.props; if (type === 'osquery-token') { return onOsqueryTableSelect(value); } return false; }); } render () { const { baseError, fields, handleSubmit, isEdit, onCancel, formData } = this.props; const { onLoad } = this; const isBuiltin = formData && (formData.label_type === 'builtin' || formData.type === 'status'); const isManual = formData && formData.label_membership_type === 'manual'; const headerText = isEdit ? 'Edit label' : 'New label'; const saveBtnText = isEdit ? 'Update label' : 'Save label'; const aceHintText = isEdit ? 'Label queries are immutable. To change the query, delete this label and create a new one.' : ''; if (isBuiltin) { return (

Built in labels cannot be edited

); } return (

{headerText}

{!isManual && ( )} {baseError &&
{baseError}
} {!isManual && (
)}
); } } export default Form(LabelForm, { fields: ['description', 'name', 'platform', 'query'], validate, });