fleet/frontend/components/forms/fields/SearchField/SearchField.tsx
Gabriel Hernandez 37985e3df6
feat activity audit fancy search activities (#35825)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #29727

**new filters:**

<img width="720" height="931" alt="image"
src="https://github.com/user-attachments/assets/bba33904-24ae-4c12-b2ed-49152588e636"
/>

**new type filter**

<img width="411" height="433" alt="image"
src="https://github.com/user-attachments/assets/14b060df-f01b-48ce-8dff-ca01e5fad6d6"
/>

> NOTE: i will be doing a follow up PR for keyboard navigation

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.
- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually

---------

Co-authored-by: Magnus Jensen <magnus@fleetdm.com>
2025-12-01 16:48:43 +00:00

68 lines
1.6 KiB
TypeScript

import React, { useState } from "react";
import { useDebouncedCallback } from "use-debounce";
import { IconNames } from "components/icons";
import TooltipWrapper from "components/TooltipWrapper";
// @ts-ignore
import InputFieldWithIcon from "../InputFieldWithIcon";
const baseClass = "search-field";
export interface ISearchFieldProps {
placeholder: string;
defaultValue?: string;
onChange: (value: string) => void;
onClick?: (e: React.MouseEvent) => void;
clearButton?: boolean;
icon?: IconNames;
tooltip?: React.ReactNode;
}
const SearchField = ({
placeholder,
defaultValue = "",
onChange,
clearButton,
onClick,
icon = "search",
tooltip,
}: ISearchFieldProps): JSX.Element => {
const [searchQueryInput, setSearchQueryInput] = useState(defaultValue);
const debouncedOnChange = useDebouncedCallback((newValue: string) => {
onChange(newValue);
}, 500);
const onInputChange = (newValue: string): void => {
setSearchQueryInput(newValue);
debouncedOnChange(newValue);
};
return (
<>
<TooltipWrapper
disableTooltip={!tooltip}
tipContent={tooltip}
position="top"
showArrow
underline={false}
tooltipClass={`${baseClass}__tooltip-text`}
className={`${baseClass}__tooltip-container`}
>
<InputFieldWithIcon
name={icon}
placeholder={placeholder}
value={searchQueryInput}
onChange={onInputChange}
onClick={onClick}
clearButton={clearButton}
iconPosition="start"
iconSvg={icon}
/>
</TooltipWrapper>
</>
);
};
export default SearchField;