({ script, userConfig, values })
| 29 | userConfig: UserConfig; |
| 30 | values: { [key: string]: any }; |
| 31 | }> = ({ script, userConfig, values }) => { |
| 32 | const formRefs = useRef<{ [key: string]: FormInstance }>({}); |
| 33 | const [visible, setVisible] = React.useState(true); |
| 34 | const [tab, setTab] = React.useState(""); |
| 35 | useEffect(() => { |
| 36 | setTab(userConfig["#options"]?.sort[0] || Object.keys(userConfig)[0]); |
| 37 | setVisible(true); |
| 38 | }, [script, userConfig]); |
| 39 | |
| 40 | // 过滤掉 #options |
| 41 | const filteredConfig = useMemo(() => { |
| 42 | return (userConfig["#options"]?.sort || Object.keys(userConfig)).reduce((acc, key) => { |
| 43 | if (key === "#options") { |
| 44 | return acc; |
| 45 | } |
| 46 | acc[key] = userConfig[key] as ConfigGroup; |
| 47 | return acc; |
| 48 | }, {} as UserConfigWithoutOptions); |
| 49 | }, [userConfig]); |
| 50 | |
| 51 | const { t } = useTranslation(); |
| 52 | |
| 53 | return ( |
| 54 | <Modal |
| 55 | visible={visible} |
| 56 | className={"modal-config"} |
| 57 | title={`${script.name} ${t("config")}`} // 替换为键值对应的英文文本 |
| 58 | okText={<Popover content={t("save_only_current_group")}>{t("save")}</Popover>} |
| 59 | cancelText={t("close")} // 替换为键值对应的英文文本 |
| 60 | onOk={() => { |
| 61 | if (formRefs.current[tab]) { |
| 62 | const saveValues = formRefs.current[tab].getFieldsValue(); |
| 63 | // 更新value |
| 64 | const valueClient = new ValueClient(message); |
| 65 | const uuid = script.uuid; |
| 66 | const keyValuePairs = [] as TKeyValuePair[]; |
| 67 | for (const key of Object.keys(saveValues)) { |
| 68 | for (const valueKey of Object.keys(saveValues[key])) { |
| 69 | if (saveValues[key][valueKey] === undefined) { |
| 70 | continue; |
| 71 | } |
| 72 | keyValuePairs.push([`${key}.${valueKey}`, encodeRValue(saveValues[key][valueKey])]); |
| 73 | } |
| 74 | } |
| 75 | valueClient.setScriptValues({ |
| 76 | uuid: uuid, |
| 77 | keyValuePairs: keyValuePairs, |
| 78 | isReplace: false, |
| 79 | ts: Date.now(), |
| 80 | }); |
| 81 | Message.success(t("save_success")!); // 替换为键值对应的英文文本 |
| 82 | setVisible(false); |
| 83 | } |
| 84 | }} |
| 85 | onCancel={() => { |
| 86 | setVisible(false); |
| 87 | }} |
| 88 | > |
nothing calls this directly
no test coverage detected