fleet/frontend/components/forms/fields/SelectTargetsDropdown/SelectTargetsInput/SelectTargetsInput.jsx
gillespi314 09cd3622da
Fixes to new pack page (#857)
- Fix "Query pack title" and "Description" input fields so they fill the full width of their container
-  Replace "New Pack" with "New pack" in the page header (sentence casing)
-  Input titles should have the font weight set to $bold
-  Remove the folder icon from the title
-  Remove bold sections from paragraphs including the "(interval = 3600s)," "targets," "individual hosts," and "labels."
-  Change bullet and link colors to $fleet-core-vibrant-blue
-  Replace differential and snapshot kolidecons with png images included in the Figma page.
2021-05-25 17:03:03 -04:00

82 lines
2 KiB
JavaScript

import React, { Component } from "react";
import PropTypes from "prop-types";
import { difference } from "lodash";
import Select from "react-select";
import "react-select/dist/react-select.css";
import debounce from "utilities/debounce";
import targetInterface from "interfaces/target";
class SelectTargetsInput extends Component {
static propTypes = {
className: PropTypes.string,
disabled: PropTypes.bool,
isLoading: PropTypes.bool,
menuRenderer: PropTypes.func,
onClose: PropTypes.func,
onOpen: PropTypes.func,
onFocus: PropTypes.func,
onTargetSelect: PropTypes.func,
onTargetSelectInputChange: PropTypes.func,
selectedTargets: PropTypes.arrayOf(targetInterface),
targets: PropTypes.arrayOf(targetInterface),
};
filterOptions = (options) => {
const { selectedTargets } = this.props;
return difference(options, selectedTargets);
};
handleInputChange = debounce(
(query) => {
const { onTargetSelectInputChange } = this.props;
onTargetSelectInputChange(query);
},
{ leading: false, trailing: true }
);
render() {
const {
className,
disabled,
isLoading,
menuRenderer,
onClose,
onOpen,
onFocus,
onTargetSelect,
selectedTargets,
targets,
} = this.props;
const { handleInputChange } = this;
return (
<Select
className={`${className} target-select`}
disabled={disabled}
isLoading={isLoading}
filterOptions={this.filterOptions}
labelKey="display_text"
menuRenderer={menuRenderer}
multi
name="targets"
options={targets}
onChange={onTargetSelect}
onClose={onClose}
onOpen={onOpen}
onFocus={onFocus}
onInputChange={handleInputChange}
placeholder="Label name, host name, IP address, etc."
resetValue={[]}
scrollMenuIntoView={false}
tabSelectsValue={false}
value={selectedTargets}
valueKey="id"
/>
);
}
}
export default SelectTargetsInput;