diff --git a/web/src/components/inputs/index.ts b/web/src/components/inputs/index.ts index 2feb2e0..49cf304 100644 --- a/web/src/components/inputs/index.ts +++ b/web/src/components/inputs/index.ts @@ -1,5 +1,5 @@ export { ErrorField, CheckboxField } from "./common"; -export { TextField, NumberField, PasswordField } from "./input"; +export { TextField, NumberField, PasswordField, RegexField } from "./input"; export { NumberFieldWide, PasswordFieldWide, SwitchGroupWide, SwitchGroupWideRed, TextFieldWide } from "./input_wide"; export { RadioFieldsetWide } from "./radio"; export { MultiSelect, Select, SelectWide, DownloadClientSelect, IndexerMultiSelect } from "./select"; diff --git a/web/src/components/inputs/input.tsx b/web/src/components/inputs/input.tsx index bf3490b..d52021c 100644 --- a/web/src/components/inputs/input.tsx +++ b/web/src/components/inputs/input.tsx @@ -1,21 +1,21 @@ import { Field, FieldProps } from "formik"; import { classNames } from "../../utils"; -import { EyeIcon, EyeSlashIcon } from "@heroicons/react/24/solid"; +import { EyeIcon, EyeSlashIcon, CheckCircleIcon, XCircleIcon } from "@heroicons/react/24/solid"; import { useToggle } from "../../hooks/hooks"; import { CustomTooltip } from "../tooltips/CustomTooltip"; type COL_WIDTHS = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; interface TextFieldProps { - name: string; - defaultValue?: string; - label?: string; - placeholder?: string; - columns?: COL_WIDTHS; - autoComplete?: string; - hidden?: boolean; - disabled?: boolean; - tooltip?: JSX.Element; + name: string; + defaultValue?: string; + label?: string; + placeholder?: string; + columns?: COL_WIDTHS; + autoComplete?: string; + hidden?: boolean; + disabled?: boolean; + tooltip?: JSX.Element; } export const TextField = ({ @@ -75,6 +75,113 @@ export const TextField = ({ ); +interface RegexFieldProps { + name: string; + defaultValue?: string; + label?: string; + placeholder?: string; + columns?: COL_WIDTHS; + autoComplete?: string; + useRegex?: boolean; + hidden?: boolean; + disabled?: boolean; + tooltip?: JSX.Element; +} + +export const RegexField = ({ + name, + defaultValue, + label, + placeholder, + columns, + autoComplete, + useRegex, + hidden, + tooltip, + disabled +}: RegexFieldProps) => { + const golangRegex = /^((\\\*|\\\?|\\[^\s\\])+|\(\?i\))(\|((\\\*|\\\?|\\[^\s\\])+|\(\?i\)))*$/; + + const validRegex = (pattern: string) => { + try { + new RegExp(golangRegex.source + pattern); + return true; + } catch (e) { + return false; + } + }; + + const validateRegexp = (val: string) => { + let error = ""; + + if (!validRegex(val)) { + error = "Invalid regex"; + } + + return error; + }; + + return ( +
This field has full regex support (Golang flavour).
https://autobrr.com/filters#advancedRemember to tick Use Regex below if using more than *
and ?
.
This field has full regex support (Golang flavour).
https://autobrr.com/filters#advancedRemember to tick Use Regex below if using more than *
and ?
.
This field has full regex support (Golang flavour).
https://autobrr.com/filters#advancedRemember to tick Use Regex below if using more than *
and ?
.
This field has full regex support (Golang flavour).
https://autobrr.com/filters#advancedRemember to tick Use Regex below if using more than *
and ?
.
Comma separated list of release groups to match.
https://autobrr.com/filters#advanced} />Comma separated list of release groups to ignore (takes priority over Match releases).
https://autobrr.com/filters#advanced} /> @@ -531,8 +532,9 @@ export function Advanced({ values }: AdvancedProps) {