diff --git a/apps/renderer/src/modules/settings/action-card.tsx b/apps/renderer/src/modules/settings/action-card.tsx index 7c8b526ec..829f0ed34 100644 --- a/apps/renderer/src/modules/settings/action-card.tsx +++ b/apps/renderer/src/modules/settings/action-card.tsx @@ -1,4 +1,4 @@ -import { useMemo } from "react" +import { useMemo, useState } from "react" import { useTranslation } from "react-i18next" import { Button } from "~/components/ui/button" @@ -160,7 +160,6 @@ const OperationTableCell = ({ const SettingCollapsible = ({ title, onOpenChange, - open, children, }: { title: string @@ -168,9 +167,16 @@ const SettingCollapsible = ({ open?: boolean onOpenChange?: (open: boolean) => void }) => { + const [open, setOpen] = useState(false) + + const toggleOpen = () => { + setOpen((pre) => !pre) + onOpenChange && onOpenChange(!open) + } + if (typeof open === "boolean" && typeof onOpenChange === "function") { return ( - +
{children}
) @@ -452,170 +458,166 @@ export function ActionCard({ { - if (open) { + if ( + open && + (!data.result.rewriteRules || data.result.rewriteRules?.length === 0) + ) { data.result.rewriteRules = [ { from: "", to: "", }, ] - } else { - delete data.result.rewriteRules } onChange(data) }} > {data.result.rewriteRules && data.result.rewriteRules.length > 0 && ( - <> - - - - - {t("actions.action_card.from")} - {t("actions.action_card.to")} - - - - {data.result.rewriteRules.map((rule, rewriteIdx) => { - const change = (key: string, value: string) => { - data.result.rewriteRules![rewriteIdx][key] = value - onChange(data) - } - return ( - - { - if (data.result.rewriteRules?.length === 1) { - delete data.result.rewriteRules - } else { - data.result.rewriteRules?.splice(rewriteIdx, 1) - } - onChange(data) - }} +
+ + + + {t("actions.action_card.from")} + {t("actions.action_card.to")} + + + + {data.result.rewriteRules.map((rule, rewriteIdx) => { + const change = (key: string, value: string) => { + data.result.rewriteRules![rewriteIdx][key] = value + onChange(data) + } + return ( + + { + if (data.result.rewriteRules?.length === 1) { + delete data.result.rewriteRules + } else { + data.result.rewriteRules?.splice(rewriteIdx, 1) + } + onChange(data) + }} + /> + + change("from", e.target.value)} /> - - change("from", e.target.value)} - /> - - - change("to", e.target.value)} - /> - - - ) - })} - -
- { - data.result.rewriteRules!.push({ - from: "", - to: "", - }) - onChange(data) - }} - /> - + + + change("to", e.target.value)} + /> + + + ) + })} + + )} + { + if (!data.result.rewriteRules) { + data.result.rewriteRules = [] + } + data.result.rewriteRules!.push({ + from: "", + to: "", + }) + onChange(data) + }} + />
{ - if (open) { + if (open && (!data.result.blockRules || data.result.blockRules?.length === 0)) { data.result.blockRules = [{}] - } else { - delete data.result.blockRules } onChange(data) }} > {data.result.blockRules && data.result.blockRules.length > 0 && ( - <> - - - - {data.result.blockRules.map((rule, index) => { - const change = (key: string, value: string | number) => { - data.result.blockRules![index][key] = value - onChange(data) - } - const type = - EntryOptions.find((option) => option.value === rule.field)?.type || - "text" - return ( - - { - if (data.result.blockRules?.length === 1) { - delete data.result.blockRules - } else { - data.result.blockRules?.splice(index, 1) - } - onChange(data) - }} - /> - - - - + + + {data.result.blockRules.map((rule, index) => { + const change = (key: string, value: string | number) => { + data.result.blockRules![index][key] = value + onChange(data) + } + const type = + EntryOptions.find((option) => option.value === rule.field)?.type || + "text" + return ( + + { + if (data.result.blockRules?.length === 1) { + delete data.result.blockRules + } else { + data.result.blockRules?.splice(index, 1) + } + onChange(data) + }} + /> + + + + change("operator", value)} + /> + + change("operator", value)} + value={rule.value} + className="h-8" + onChange={(e) => change("value", e.target.value)} /> - - change("value", e.target.value)} - /> - - - ) - })} - -
- { - data.result.blockRules!.push({}) - onChange(data) - }} - /> - + + + ) + })} + + )} + { + if (!data.result.blockRules) { + data.result.blockRules = [] + } + data.result.blockRules!.push({}) + onChange(data) + }} + />
{ - if (open) { + if (open && (!data.result.webhooks || data.result.webhooks?.length === 0)) { data.result.webhooks = [""] - } else { - delete data.result.webhooks } onChange(data) }} @@ -647,14 +649,17 @@ export function ActionCard({ ) })} - { - data.result.webhooks!.push("") - onChange(data) - }} - /> )} + { + if (!data.result.webhooks) { + data.result.webhooks = [] + } + data.result.webhooks!.push("") + onChange(data) + }} + />