chore: select rule-set name

This commit is contained in:
MystiPanda 2024-06-30 22:46:11 +08:00
parent 7d5d604ea6
commit 5e20e9ae1c

View File

@ -127,6 +127,8 @@ export const RulesEditorViewer = (props: Props) => {
const [proxyPolicy, setProxyPolicy] = useState("DIRECT"); const [proxyPolicy, setProxyPolicy] = useState("DIRECT");
const [proxyPolicyList, setProxyPolicyList] = useState<string[]>([]); const [proxyPolicyList, setProxyPolicyList] = useState<string[]>([]);
const [ruleList, setRuleList] = useState<string[]>([]); const [ruleList, setRuleList] = useState<string[]>([]);
const [ruleSetList, setRuleSetList] = useState<string[]>([]);
const [subRuleList, setSubRuleList] = useState<string[]>([]);
const [prependSeq, setPrependSeq] = useState<string[]>([]); const [prependSeq, setPrependSeq] = useState<string[]>([]);
const [appendSeq, setAppendSeq] = useState<string[]>([]); const [appendSeq, setAppendSeq] = useState<string[]>([]);
@ -144,16 +146,26 @@ export const RulesEditorViewer = (props: Props) => {
const fetchProfile = async () => { const fetchProfile = async () => {
let data = await readProfileFile(profileUid); let data = await readProfileFile(profileUid);
let obj = yaml.load(data) as { "proxy-groups": []; proxies: []; rules: [] }; let groupsObj = yaml.load(data) as { "proxy-groups": [] };
if (!obj["proxy-groups"]) { let rulesObj = yaml.load(data) as { rules: [] };
obj = { "proxy-groups": [], proxies: [], rules: [] }; let ruleSetObj = yaml.load(data) as { "rule-providers": [] };
} let subRuleObj = yaml.load(data) as { "sub-rules": [] };
setProxyPolicyList( setProxyPolicyList(
BuiltinProxyPolicyList.concat( 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(() => { useEffect(() => {
@ -203,15 +215,41 @@ export const RulesEditorViewer = (props: Props) => {
</Item> </Item>
<Item> <Item>
<ListItemText primary={t("Rule Content")} /> <ListItemText primary={t("Rule Content")} />
<TextField {ruleType === "RULE-SET" && (
size="small" <Autocomplete
sx={{ minWidth: "240px" }} size="small"
value={ruleContent} sx={{ minWidth: "240px" }}
placeholder={ExampleMap[ruleType]} value={ruleContent}
onChange={(e) => { options={ruleSetList}
setRuleContent(e.target.value); onChange={(_, v) => {
}} if (v) setRuleContent(v);
/> }}
renderInput={(params) => <TextField {...params} />}
/>
)}
{ruleType === "SUB-RULE" && (
<Autocomplete
size="small"
sx={{ minWidth: "240px" }}
value={ruleContent}
options={subRuleList}
onChange={(_, v) => {
if (v) setRuleContent(v);
}}
renderInput={(params) => <TextField {...params} />}
/>
)}
{ruleType !== "RULE-SET" && ruleType !== "SUB-RULE" && (
<TextField
size="small"
sx={{ minWidth: "240px" }}
value={ruleContent}
placeholder={ExampleMap[ruleType]}
onChange={(e) => {
setRuleContent(e.target.value);
}}
/>
)}
</Item> </Item>
<Item> <Item>
<ListItemText primary={t("Proxy Policy")} /> <ListItemText primary={t("Proxy Policy")} />