diff --git a/src/components/profile/rules-editor-viewer.tsx b/src/components/profile/rules-editor-viewer.tsx index fe5cac2..c9c0248 100644 --- a/src/components/profile/rules-editor-viewer.tsx +++ b/src/components/profile/rules-editor-viewer.tsx @@ -127,6 +127,8 @@ export const RulesEditorViewer = (props: Props) => { const [proxyPolicy, setProxyPolicy] = useState("DIRECT"); const [proxyPolicyList, setProxyPolicyList] = useState([]); const [ruleList, setRuleList] = useState([]); + const [ruleSetList, setRuleSetList] = useState([]); + const [subRuleList, setSubRuleList] = useState([]); const [prependSeq, setPrependSeq] = useState([]); const [appendSeq, setAppendSeq] = useState([]); @@ -144,16 +146,26 @@ export const RulesEditorViewer = (props: Props) => { const fetchProfile = async () => { let data = await readProfileFile(profileUid); - let obj = yaml.load(data) as { "proxy-groups": []; proxies: []; rules: [] }; - if (!obj["proxy-groups"]) { - obj = { "proxy-groups": [], proxies: [], rules: [] }; - } + let groupsObj = yaml.load(data) as { "proxy-groups": [] }; + let rulesObj = yaml.load(data) as { rules: [] }; + let ruleSetObj = yaml.load(data) as { "rule-providers": [] }; + let subRuleObj = yaml.load(data) as { "sub-rules": [] }; setProxyPolicyList( BuiltinProxyPolicyList.concat( - obj["proxy-groups"].map((item: any) => item.name) + groupsObj["proxy-groups"] + ? groupsObj["proxy-groups"].map((item: any) => item.name) + : [] ) ); - setRuleList(obj.rules); + setRuleList(rulesObj.rules || []); + setRuleSetList( + ruleSetObj["rule-providers"] + ? Object.keys(ruleSetObj["rule-providers"]) + : [] + ); + setSubRuleList( + subRuleObj["sub-rules"] ? Object.keys(subRuleObj["sub-rules"]) : [] + ); }; useEffect(() => { @@ -203,15 +215,41 @@ export const RulesEditorViewer = (props: Props) => { - { - setRuleContent(e.target.value); - }} - /> + {ruleType === "RULE-SET" && ( + { + if (v) setRuleContent(v); + }} + renderInput={(params) => } + /> + )} + {ruleType === "SUB-RULE" && ( + { + if (v) setRuleContent(v); + }} + renderInput={(params) => } + /> + )} + {ruleType !== "RULE-SET" && ruleType !== "SUB-RULE" && ( + { + setRuleContent(e.target.value); + }} + /> + )}