From 606817ae06c94b1c8457fb0d668ed6371f24fc89 Mon Sep 17 00:00:00 2001 From: dongchengjie <37543964+dongchengjie@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:32:49 +0800 Subject: [PATCH] chore: add rule list search-box --- src/components/base/base-search-box.tsx | 13 ++++-- src/components/profile/rule-item.tsx | 10 +++-- .../profile/rules-editor-viewer.tsx | 45 ++++++++++++------- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/components/base/base-search-box.tsx b/src/components/base/base-search-box.tsx index 3a154586..771002ea 100644 --- a/src/components/base/base-search-box.tsx +++ b/src/components/base/base-search-box.tsx @@ -9,6 +9,9 @@ import useRegularExpressionIcon from "@/assets/image/component/use_regular_expre type SearchProps = { placeholder?: string; + matchCase?: boolean; + matchWholeWord?: boolean; + useRegularExpression?: boolean; onSearch: ( match: (content: string) => boolean, state: { @@ -23,9 +26,13 @@ type SearchProps = { export const BaseSearchBox = styled((props: SearchProps) => { const { t } = useTranslation(); const inputRef = useRef(null); - const [matchCase, setMatchCase] = useState(true); - const [matchWholeWord, setMatchWholeWord] = useState(false); - const [useRegularExpression, setUseRegularExpression] = useState(false); + const [matchCase, setMatchCase] = useState(props.matchCase ?? true); + const [matchWholeWord, setMatchWholeWord] = useState( + props.matchWholeWord ?? false + ); + const [useRegularExpression, setUseRegularExpression] = useState( + props.useRegularExpression ?? false + ); const [errorMessage, setErrorMessage] = useState(""); const iconStyle = { diff --git a/src/components/profile/rule-item.tsx b/src/components/profile/rule-item.tsx index 2b30f42c..7093a3e8 100644 --- a/src/components/profile/rule-item.tsx +++ b/src/components/profile/rule-item.tsx @@ -46,10 +46,14 @@ export const RuleItem = (props: Props) => { primary={ <> {rule.length === 3 ? rule[1] : "-"} diff --git a/src/components/profile/rules-editor-viewer.tsx b/src/components/profile/rules-editor-viewer.tsx index 902eec9b..6b9d39d0 100644 --- a/src/components/profile/rules-editor-viewer.tsx +++ b/src/components/profile/rules-editor-viewer.tsx @@ -34,6 +34,7 @@ import { readProfileFile, saveProfileFile } from "@/services/cmds"; import { Notice, Switch } from "@/components/base"; import getSystem from "@/utils/get-system"; import { RuleItem } from "@/components/profile/rule-item"; +import { BaseSearchBox } from "../base/base-search-box"; interface Props { profileUid: string; @@ -230,6 +231,7 @@ export const RulesEditorViewer = (props: Props) => { const { t } = useTranslation(); const [prevData, setPrevData] = useState(""); + const [match, setMatch] = useState(() => (_: string) => true); const [ruleType, setRuleType] = useState<(typeof rules)[number]>(rules[0]); const [ruleContent, setRuleContent] = useState(""); @@ -476,9 +478,16 @@ export const RulesEditorViewer = (props: Props) => { width: "50%", height: "100%", overflowY: "auto", - marginLeft: "10px", + overflowX: "hidden", + padding: "0 10px", }} > +
+ setMatch(() => match)} + /> +
{prependSeq.length > 0 && ( { )} - {ruleList.map((item, index) => { - return ( - { - if (deleteSeq.includes(item)) { - setDeleteSeq(deleteSeq.filter((v) => v !== item)); - } else { - setDeleteSeq([...deleteSeq, item]); - } - }} - /> - ); - })} + {ruleList + .filter((item) => match(item)) + .map((item, index) => { + return ( + { + if (deleteSeq.includes(item)) { + setDeleteSeq(deleteSeq.filter((v) => v !== item)); + } else { + setDeleteSeq([...deleteSeq, item]); + } + }} + /> + ); + })} {appendSeq.length > 0 && (