Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Migrate over HistoryTableTestSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
khelif96 committed Oct 31, 2023
1 parent 05b8d24 commit 8c87fd9
Showing 1 changed file with 7 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import { useState } from "react";
import styled from "@emotion/styled";
import IconButton from "@leafygreen-ui/icon-button";
import { palette } from "@leafygreen-ui/palette";
import Icon from "components/Icon";
import IconTooltip from "components/IconTooltip";
import TextInput from "components/TextInputWithGlyph";
import TextInput from "components/TextInputWithValidation";
import { useUpsertQueryParams } from "hooks";
import { TestStatus } from "types/history";
import { validators } from "utils";

const { validateRegexp } = validators;
const { yellow } = palette;

interface HistoryTableTestSearchProps {
onSubmit?: () => void;
Expand All @@ -19,19 +13,11 @@ interface HistoryTableTestSearchProps {
export const HistoryTableTestSearch: React.FC<HistoryTableTestSearchProps> = ({
onSubmit = () => {},
}) => {
const [input, setInput] = useState("");
const isValid = validateRegexp(input);
const handleSubmit = useUpsertQueryParams();

const handleOnChange = (value: string) => {
setInput(value);
};
const handleOnSubmit = () => {
if (isValid) {
onSubmit();
handleSubmit({ category: TestStatus.Failed, value: input });
setInput("");
}
const handleOnSubmit = (input: string) => {
onSubmit();
handleSubmit({ category: TestStatus.Failed, value: input });
};

return (
Expand All @@ -40,30 +26,10 @@ export const HistoryTableTestSearch: React.FC<HistoryTableTestSearchProps> = ({
type="search"
label="Filter by Failed Tests"
aria-label="history-table-test-search-input"
value={input}
placeholder="Search test name regex"
onChange={(e) => handleOnChange(e.target.value)}
onKeyPress={(e: React.KeyboardEvent<HTMLInputElement>) =>
e.key === "Enter" && handleOnSubmit()
}
icon={
isValid ? (
<IconButton
onClick={handleOnSubmit}
aria-label="Select plus button"
>
<Icon glyph="Plus" data-cy="tuple-select-button" />
</IconButton>
) : (
<IconTooltip
glyph="Warning"
data-cy="tuple-select-warning"
fill={yellow.base}
>
Invalid Regular Expression
</IconTooltip>
)
}
validatorErrorMessage="Invalid Regular Expression"
onSubmit={handleOnSubmit}
validator={validateRegexp}
/>
</ContentWrapper>
);
Expand Down

0 comments on commit 8c87fd9

Please sign in to comment.