diff --git a/apps/desktop/layer/renderer/src/modules/action/action-setting.tsx b/apps/desktop/layer/renderer/src/modules/action/action-setting.tsx index b36b80ae7..3472e5ce7 100644 --- a/apps/desktop/layer/renderer/src/modules/action/action-setting.tsx +++ b/apps/desktop/layer/renderer/src/modules/action/action-setting.tsx @@ -1,20 +1,25 @@ import { Button } from "@follow/components/ui/button/index.js" import { LoadingWithIcon } from "@follow/components/ui/loading/index.jsx" +import * as ScrollArea from "@follow/components/ui/scroll-area/ScrollArea.js" import { useActionRules, useIsActionDataDirty, usePrefetchActions, useUpdateActionsMutation, } from "@follow/store/action/hooks" +import type { ActionItem } from "@follow/store/action/store" import { actionActions } from "@follow/store/action/store" +import { nextFrame } from "@follow/utils" import { JsonObfuscatedCodec } from "@follow/utils/json-codec" +import { cn } from "@follow/utils/utils" import { useQueryClient } from "@tanstack/react-query" import { m } from "motion/react" -import { useEffect } from "react" +import { useCallback, useEffect, useState } from "react" import { useTranslation } from "react-i18next" import { unstable_usePrompt } from "react-router" import { toast } from "sonner" +import { MenuItemText, useShowContextMenu } from "~/atoms/context-menu" import { HeaderActionButton, HeaderActionGroup } from "~/components/ui/button/HeaderActionButton" import { DropdownMenu, @@ -23,9 +28,16 @@ import { DropdownMenuSeparator, DropdownMenuTrigger, } from "~/components/ui/dropdown-menu/dropdown-menu.js" +import { useDialog } from "~/components/ui/modal/stacked/hooks" +import { useContextMenu } from "~/hooks/common/useContextMenu" import { copyToClipboard, readFromClipboard } from "~/lib/clipboard" import { downloadJsonFile, selectJsonFile } from "~/lib/export" import { RuleCard } from "~/modules/action/rule-card" +import { + buildActionSummary, + buildConditionSummary, + getRuleDisplayName, +} from "~/modules/action/rule-summary" import { useSetSubViewRightView } from "../app-layout/subview/hooks" import { generateExportFilename } from "./utils" @@ -37,12 +49,12 @@ const EmptyActionPlaceholder = () => {
{/* Simple icon */} -
- +
+
-

+

{t("actions.action_card.empty.title")}

@@ -51,7 +63,7 @@ const EmptyActionPlaceholder = () => {

{ ease: "easeInOut", }} > -
+
{t("actions.action_card.empty.start")} - +
@@ -74,9 +86,22 @@ const EmptyActionPlaceholder = () => { export const ActionSetting = () => { const actions = useActionRules() + const { t } = useTranslation("settings") + const [selectedRuleIndex, setSelectedRuleIndex] = useState(0) const actionQuery = usePrefetchActions() + useEffect(() => { + if (actions.length === 0) { + setSelectedRuleIndex(0) + return + } + + if (selectedRuleIndex > actions.length - 1) { + setSelectedRuleIndex(actions.length - 1) + } + }, [actions.length, selectedRuleIndex]) + if (actionQuery.isPending) { return ( { const hasActions = actions.length > 0 + const handleCreateRule = () => { + const nextIndex = actions.length + actionActions.addRule((number) => t("actions.actionName", { number })) + setSelectedRuleIndex(nextIndex) + } + return ( -
- + <> + + {hasActions ? ( -
- {actions.map((_, actionIdx) => { - return - })} +
+
+ { + // Adjust selectedRuleIndex when a rule is deleted + if (deletedIndex === selectedRuleIndex) { + // If deleting the selected rule, select the previous one or 0 + setSelectedRuleIndex(Math.max(0, deletedIndex - 1)) + } else if (deletedIndex < selectedRuleIndex) { + // If deleting a rule before the selected one, shift the index down + setSelectedRuleIndex(selectedRuleIndex - 1) + } + }} + /> +
+ +
+
+
+ {actions.map((_, actionIdx) => ( + { + if (open) { + setSelectedRuleIndex(actionIdx) + } + }} + /> + ))} +
) : ( )} -
+ ) } -const ActionButtonGroup = () => { - const queryClient = useQueryClient() - const actionLength = useActionRules((actions) => actions.length) - const isDirty = useIsActionDataDirty() +const ShareImportSection = () => { const { t } = useTranslation("settings") - unstable_usePrompt({ - message: t("actions.navigate.prompt"), - when: ({ currentLocation, nextLocation }) => - isDirty && currentLocation.pathname !== nextLocation.pathname, - }) + const actionLength = useActionRules((actions) => actions.length) + const hasActions = actionLength > 0 - const mutation = useUpdateActionsMutation({ - onSuccess: () => { - // apply new action settings - queryClient.invalidateQueries({ - queryKey: ["entries"], - }) - toast(t("actions.saveSuccess")) - }, - onError: (error) => { - toast.error(error) - }, - }) - - const handleExport = () => { + const handleExport = useCallback(() => { try { const jsonData = actionActions.exportRules() const filename = generateExportFilename() @@ -138,9 +182,9 @@ const ActionButtonGroup = () => { } catch { toast.error("Failed to export action rules") } - } + }, []) - const handleImport = async () => { + const handleImport = useCallback(async () => { try { const jsonData = await selectJsonFile() const result = actionActions.importRules(jsonData) @@ -152,28 +196,26 @@ const ActionButtonGroup = () => { } } catch (error) { if (error instanceof Error && error.message === "No file selected") { - // User cancelled file selection, don't show error return } toast.error("Failed to import action rules") } - } + }, []) const foloPrefix = "folo:actions#" - const handleCopyToClipboard = async () => { + const handleCopyToClipboard = useCallback(async () => { try { const jsonData = actionActions.exportRules() const codecData = JsonObfuscatedCodec.encode(jsonData) - await copyToClipboard(`${foloPrefix}${codecData}`) toast.success("Action rules copied to clipboard") } catch (error) { toast.error("Failed to copy action rules to clipboard") console.error(error) } - } + }, [foloPrefix]) - const handleImportFromClipboard = async () => { + const handleImportFromClipboard = useCallback(async () => { try { const clipboardData = await readFromClipboard() if (!clipboardData.startsWith(foloPrefix)) { @@ -181,9 +223,7 @@ const ActionButtonGroup = () => { return } const codecData = clipboardData.slice(foloPrefix.length) - const jsonData = JsonObfuscatedCodec.decode(codecData) - const result = actionActions.importRules(jsonData) if (result.success) { @@ -199,19 +239,201 @@ const ActionButtonGroup = () => { } console.error(error) } + }, [foloPrefix]) + + return ( +
+ + + + + + + + {t("actions.action_card.summary.export")} + + + + {t("actions.action_card.summary.import_file")} + + + + + {t("actions.action_card.summary.copy")} + + + + {t("actions.action_card.summary.import_clipboard")} + + + +
+ ) +} + +const RuleList = ({ + selectedIndex, + onSelect, + onDelete, +}: { + selectedIndex: number + onSelect: (index: number) => void + onDelete: (index: number) => void +}) => { + const rules = useActionRules() + const { t } = useTranslation("settings") + const ruleCount = useActionRules((s) => s.length) + const mutation = useUpdateActionsMutation() + const { ask } = useDialog() + const showContextMenu = useShowContextMenu() + + const handleDeleteRule = useCallback( + (index: number) => { + if (ruleCount === 1) { + ask({ + title: t("actions.action_card.summary.delete_title"), + variant: "danger", + message: t("actions.action_card.summary.delete_message"), + onConfirm: () => { + actionActions.deleteRule(index) + onDelete(index) + nextFrame(() => { + mutation.mutate() + }) + }, + }) + } else { + actionActions.deleteRule(index) + onDelete(index) + } + }, + [ruleCount, ask, t, mutation, onDelete], + ) + + if (rules.length === 0) { + return null } + return ( +
+ +
+ {rules.map((rule, index) => ( + + ))} +
+
+
+ ) +} + +const RuleListItem = ({ + rule, + index, + isActive, + onSelect, + handleDelete, + showContextMenu, +}: { + rule: ActionItem + index: number + isActive: boolean + onSelect: (index: number) => void + handleDelete: (index: number) => void + showContextMenu: ReturnType +}) => { + const { t } = useTranslation("settings") + const displayName = getRuleDisplayName(rule, index, t) + const whenSummary = buildConditionSummary(rule, t) + const actionSummary = buildActionSummary(rule, t) + + const contextMenuProps = useContextMenu({ + onContextMenu: async (e) => { + e.preventDefault() + await showContextMenu( + [ + new MenuItemText({ + label: t("actions.action_card.summary.delete"), + icon: , + click: () => handleDelete(index), + }), + ], + e, + ) + }, + }) + + return ( + + ) +} + +const ActionButtonGroup = ({ onCreateRule }: { onCreateRule: () => void }) => { + const queryClient = useQueryClient() + const actionLength = useActionRules((actions) => actions.length) + const isDirty = useIsActionDataDirty() + const { t } = useTranslation("settings") + unstable_usePrompt({ + message: t("actions.navigate.prompt"), + when: ({ currentLocation, nextLocation }) => + isDirty && currentLocation.pathname !== nextLocation.pathname, + }) + + const mutation = useUpdateActionsMutation({ + onSuccess: () => { + queryClient.invalidateQueries({ + queryKey: ["entries"], + }) + toast(t("actions.saveSuccess")) + }, + onError: (error) => { + toast.error(error) + }, + }) + const hasActions = actionLength > 0 const setRightView = useSetSubViewRightView() useEffect(() => { setRightView( - actionActions.addRule((number) => t("actions.actionName", { number }))} - > + {t("actions.newRule")} @@ -231,70 +453,7 @@ const ActionButtonGroup = () => { return () => { setRightView(null) } - }, [setRightView, actionLength, hasActions, isDirty, mutation, t]) + }, [setRightView, actionLength, hasActions, isDirty, mutation, onCreateRule, t]) - return ( -
- {/* Left side - Simple status */} -
-

- {hasActions ? `${actionLength} Rules` : "No Rules"} -

-

- {hasActions ? "Active automation rules" : "Create your first automation rule"} -

-
- - {/* Right side - Action buttons */} -
- - - - - - - - Export to File - - - - Import from File - - - - - Copy to Clipboard - - - - Import from Clipboard - - - - - - - {hasActions && ( - - )} -
-
- ) + return null } diff --git a/apps/desktop/layer/renderer/src/modules/action/rule-card.tsx b/apps/desktop/layer/renderer/src/modules/action/rule-card.tsx index be04cdd06..760bf95b7 100644 --- a/apps/desktop/layer/renderer/src/modules/action/rule-card.tsx +++ b/apps/desktop/layer/renderer/src/modules/action/rule-card.tsx @@ -1,77 +1,181 @@ +import { Button } from "@follow/components/ui/button/index.js" import { Input } from "@follow/components/ui/input/index.js" +import * as ScrollArea from "@follow/components/ui/scroll-area/ScrollArea.js" import { Switch } from "@follow/components/ui/switch/index.jsx" import { useActionRule, useActionRules, useUpdateActionsMutation } from "@follow/store/action/hooks" import { actionActions } from "@follow/store/action/store" import { nextFrame } from "@follow/utils" +import { cn } from "@follow/utils/utils" +import { useEffect, useState } from "react" +import { useTranslation } from "react-i18next" import { useDialog } from "~/components/ui/modal/stacked/hooks" +import { buildActionSummary, buildConditionSummary, getRuleDisplayName } from "./rule-summary" import { ThenSection } from "./then-section" import { WhenSection } from "./when-section" -export const RuleCard = ({ index }: { index: number }) => { +type RuleCardProps = { + index: number + mode?: "detail" | "compact" + defaultOpen?: boolean + onOpenChange?: (open: boolean) => void +} + +export const RuleCard = ({ + index, + mode = "detail", + defaultOpen = false, + onOpenChange, +}: RuleCardProps) => { + if (mode === "compact") { + return + } + return ( -
- -
- - +
+
+
+ +
+ +
+
+
+ ) +} + +const RuleCardContent = ({ index }: { index: number }) => { + return ( +
+ + +
+ ) +} + +const CompactRuleCard = ({ + index, + defaultOpen, + onOpenChange, +}: { + index: number + defaultOpen: boolean + onOpenChange?: (open: boolean) => void +}) => { + const { t } = useTranslation("settings") + const rule = useActionRule(index) + const disabled = useActionRule(index, (a) => a.result.disabled) + const [open, setOpen] = useState(defaultOpen) + + useEffect(() => { + setOpen(defaultOpen) + }, [defaultOpen]) + + const toggle = () => { + setOpen((prev) => { + const next = !prev + onOpenChange?.(next) + return next + }) + } + + const displayName = getRuleDisplayName(rule, index, t) + const whenSummary = buildConditionSummary(rule, t) + const actionSummary = buildActionSummary(rule, t) + + return ( +
+ + {open ? ( +
+ + +
+ ) : null}
) } const RuleCardToolbar = ({ index }: { index: number }) => { + const { t } = useTranslation("settings") const name = useActionRule(index, (a) => a.name) const disabled = useActionRule(index, (a) => a.result.disabled) - const ruleCount = useActionRules((s) => s.length) const mutation = useUpdateActionsMutation() - const { ask } = useDialog() + + const handleDelete = () => { + if (ruleCount === 1) { + ask({ + title: t("actions.action_card.summary.delete_title"), + variant: "danger", + message: t("actions.action_card.summary.delete_message"), + onConfirm: () => { + actionActions.deleteRule(index) + nextFrame(() => { + mutation.mutate() + }) + }, + }) + } else { + actionActions.deleteRule(index) + } + } + return ( -
+
{ actionActions.patchRule(index, { name: e.target.value }) }} /> -
- - { - actionActions.patchRule(index, { - result: { disabled: !checked }, - }) - }} - /> -
- + +
) diff --git a/apps/desktop/layer/renderer/src/modules/action/rule-summary.ts b/apps/desktop/layer/renderer/src/modules/action/rule-summary.ts new file mode 100644 index 000000000..e6b6ef7bc --- /dev/null +++ b/apps/desktop/layer/renderer/src/modules/action/rule-summary.ts @@ -0,0 +1,95 @@ +import { filterFieldOptions, filterOperatorOptions } from "@follow/store/action/constant" +import type { ActionItem } from "@follow/store/action/store" +import type { TFunction } from "i18next" + +import { availableActionMap } from "./constants" + +const fieldLabelMap = new Map(filterFieldOptions.map((option) => [option.value, option.label])) +const operatorLabelMap = new Map( + filterOperatorOptions.map((option) => [option.value, option.label]), +) + +export const getRuleDisplayName = ( + rule: ActionItem | undefined, + index: number, + t: TFunction<"settings">, +) => { + const fallback = t("actions.actionName", { number: index + 1 }) + if (!rule) return fallback + const trimmedName = rule.name?.trim() + return trimmedName && trimmedName.length > 0 ? trimmedName : fallback +} + +export const buildConditionSummary = (rule: ActionItem | undefined, t: TFunction<"settings">) => { + if (!rule || rule.condition.length === 0) { + return t("actions.action_card.all") + } + + const andSeparator = ` ${t("actions.action_card.and")} ` + const orSeparator = ` ${t("actions.action_card.or")} ` + + const groups = rule.condition + .map((group) => { + const groupParts = group + .map((condition) => { + const fieldLabelKey = condition.field ? fieldLabelMap.get(condition.field) : undefined + const operatorLabelKey = condition.operator + ? operatorLabelMap.get(condition.operator) + : undefined + const fieldLabel = fieldLabelKey ? t(fieldLabelKey) : undefined + const operatorLabel = operatorLabelKey ? t(operatorLabelKey) : undefined + const { value } = condition + + const valueText = + typeof value === "number" + ? value.toString() + : typeof value === "string" && value.trim().length > 0 + ? value + : undefined + + const parts = [fieldLabel, operatorLabel, valueText].filter(Boolean) + return parts.join(" ") + }) + .filter((part) => part.length > 0) + + return groupParts.join(andSeparator) + }) + .filter((group) => group.length > 0) + + if (groups.length === 0) { + return t("actions.action_card.all") + } + + return groups.join(orSeparator) +} + +export const buildActionSummary = (rule: ActionItem | undefined, t: TFunction<"settings">) => { + if (!rule) { + return t("actions.action_card.summary.no_actions") + } + + if (rule.result?.disabled) { + return t("actions.action_card.summary.disabled") + } + + const labels = Object.values(availableActionMap) + .filter((action) => { + const value = rule.result?.[action.value as keyof typeof rule.result] + if (Array.isArray(value)) { + return value.length > 0 + } + + if (typeof value === "object" && value !== null) { + return Object.keys(value).length > 0 + } + + return Boolean(value) + }) + .map((action) => t(action.label)) + + if (labels.length === 0) { + return t("actions.action_card.summary.no_actions") + } + + return labels.join(" + ") +} diff --git a/apps/desktop/layer/renderer/src/modules/action/then-section.tsx b/apps/desktop/layer/renderer/src/modules/action/then-section.tsx index 5dd7fb9fb..af27d82ec 100644 --- a/apps/desktop/layer/renderer/src/modules/action/then-section.tsx +++ b/apps/desktop/layer/renderer/src/modules/action/then-section.tsx @@ -1,11 +1,12 @@ -import { ActionButton, Button } from "@follow/components/ui/button/index.js" -import { Divider } from "@follow/components/ui/divider/index.js" +import { Button } from "@follow/components/ui/button/index.js" import { Input } from "@follow/components/ui/input/index.js" import type { ActionAction } from "@follow/store/action/constant" import { useActionRule } from "@follow/store/action/hooks" import { actionActions } from "@follow/store/action/store" +import { cn } from "@follow/utils/utils" import type { ActionId } from "@follow-app/client-sdk" import { merge } from "es-toolkit/compat" +import type { ReactNode } from "react" import { Fragment, useMemo } from "react" import { useTranslation } from "react-i18next" @@ -19,7 +20,12 @@ import { import { useSettingModal } from "../settings/modal/useSettingModal" import { availableActionMap } from "./constants" -export const ThenSection = ({ index }: { index: number }) => { +type ThenSectionProps = { + index: number + variant?: "detail" | "compact" +} + +export const ThenSection = ({ index, variant: _variant = "detail" }: ThenSectionProps) => { const { t } = useTranslation("settings") const result = useActionRule(index, (a) => a.result) @@ -33,28 +39,26 @@ export const ThenSection = ({ index }: { index: number }) => { const extendedAvailableActionMap: Record< ActionId, ActionAction & { - config?: () => React.ReactNode + config?: () => ReactNode } > = merge(availableActionMap, { rewriteRules: { config: () => ( -
+
{!rewriteRules || rewriteRules.length === 0 ? ( -
- Add rewrite rules - -
+ ) : ( - <> +
{rewriteRules.map((rule, rewriteIdx) => { const change = (key: "from" | "to", value: string) => { actionActions.updateRewriteRule({ @@ -65,112 +69,116 @@ export const ThenSection = ({ index }: { index: number }) => { }) } return ( -
-
-
)}
), }, webhooks: { config: () => ( -
+
{!webhooks || webhooks.length === 0 ? ( -
- Add webhooks - -
+ ) : ( - <> +
{webhooks.map((webhook, webhookIdx) => { return ( -
+
{ + onChange={(event) => { actionActions.updateWebhook({ index, webhookIndex: webhookIdx, - value: e.target.value, + value: event.target.value, }) }} /> -
- + { actionActions.addWebhook(index) }} - > - - - + { actionActions.deleteWebhook(index, webhookIdx) }} - > - - + />
) })} - +
)}
), @@ -178,89 +186,204 @@ export const ThenSection = ({ index }: { index: number }) => { }) return Object.values(extendedAvailableActionMap) }, [disabled, index, rewriteRules, t, webhooks]) - const enabledActions = useMemo( - () => availableActions.filter((action) => !!result?.[action.value]), - [availableActions, result], - ) + + const enabledActions = useMemo(() => { + if (!result) return [] + + // Get the order of actions from the result object (insertion order) + const resultKeys = Object.keys(result).filter((key) => result[key as ActionId]) + + // Sort availableActions based on the order in result object + return resultKeys + .map((key) => availableActions.find((action) => action.value === key)) + .filter((action): action is NonNullable => !!action) + }, [availableActions, result]) const notEnabledActions = useMemo( () => availableActions.filter((action) => !result?.[action.value]), [availableActions, result], ) return ( -
-

{t("actions.action_card.then_do")}

-
- {enabledActions.map((action, i) => { - return ( - -
-
-
- - {t(action.label)} - {action.prefixElement &&
{action.prefixElement}
} -
-
- {action.settingsPath && ( - - )} - + + + {notEnabledActions.map((action) => { + return ( + { - actionActions.deleteRuleAction(index, action.value) + if (action.onEnable) { + action.onEnable(index) + } else { + actionActions.patchRule(index, { result: { [action.value]: true } }) + } }} > - - -
-
- {action.config &&
{action.config()}
} -
- {i !== enabledActions.length - 1 && } -
- ) - })} - - - - - - {notEnabledActions.map((action) => { +
+ + {t(action.label)} +
+ + ) + })} +
+
+
+ ) : ( + <> + {enabledActions.map((action, actionIndex) => { + const isLast = actionIndex === enabledActions.length - 1 return ( - { - if (action.onEnable) { - action.onEnable(index) - } else { - actionActions.patchRule(index, { result: { [action.value]: true } }) - } - }} - > -
- - {t(action.label)} + +
+ {/* Connection line and icon */} +
+
+ +
+ {!isLast && ( +
+ )} +
+ + {/* Action content */} +
+
+ {/* Label */} + + {t(action.label)} + + + {/* Spacer */} +
+ + {/* Value selector or prefix element */} + {action.prefixElement && ( +
{action.prefixElement}
+ )} + + {/* Settings button */} + {action.settingsPath && ( + + )} + + {/* Delete button */} + { + actionActions.deleteRuleAction(index, action.value) + }} + /> +
+ {action.config && ( +
{action.config()}
+ )} +
- + ) })} - - +
+
+
+ + + + + + {notEnabledActions.map((action) => { + return ( + { + if (action.onEnable) { + action.onEnable(index) + } else { + actionActions.patchRule(index, { result: { [action.value]: true } }) + } + }} + > +
+ + {t(action.label)} +
+
+ ) + })} +
+
+
+
+ + )}
-
+ + ) +} + +const IconButton = ({ + icon, + onClick, + ariaLabel, + disabled, + className, +}: { + icon: string + onClick: () => void + ariaLabel: string + disabled?: boolean + className?: string +}) => { + return ( + ) } diff --git a/apps/desktop/layer/renderer/src/modules/action/when-section.tsx b/apps/desktop/layer/renderer/src/modules/action/when-section.tsx index f754d32c3..c74897e38 100644 --- a/apps/desktop/layer/renderer/src/modules/action/when-section.tsx +++ b/apps/desktop/layer/renderer/src/modules/action/when-section.tsx @@ -1,6 +1,6 @@ import { Button } from "@follow/components/ui/button/index.js" import { Input } from "@follow/components/ui/input/index.js" -import { RadioGroup, RadioGroupItem } from "@follow/components/ui/radio-group/motion.js" +import { SegmentGroup, SegmentItem } from "@follow/components/ui/segment/index.js" import { Select, SelectContent, @@ -18,48 +18,50 @@ import { useTranslation } from "react-i18next" import { ViewSelectContent } from "~/modules/feed/view-select-content" -export const WhenSection = ({ index }: { index: number }) => { +type WhenSectionProps = { + index: number +} + +export const WhenSection = ({ index }: WhenSectionProps) => { const { t } = useTranslation("settings") const disabled = useActionRule(index, (a) => a.result.disabled) const condition = useActionRule(index, (a) => a.condition) + const mode = condition.length > 0 ? "filter" : "all" + + const handleModeChange = (value: "all" | "filter") => { + if (value === "all" && condition.length > 0) { + actionActions.toggleRuleFilter(index) + } + + if (value === "filter" && condition.length === 0) { + actionActions.toggleRuleFilter(index) + } + } + return ( -
-

{t("actions.action_card.when_feeds_match")}

-
- 0 ? "filter" : "all"} - onValueChange={(value) => { - actionActions.patchRule(index, { - condition: value === "all" ? [] : [[{}]], - }) - }} - className="flex gap-8" +
+
+ + {t("actions.action_card.when_feeds_match")} + + handleModeChange(value as "all" | "filter")} > - - - + + +
- {condition.length > 0 && ( -
+ {mode === "filter" && ( +
{condition.map((orConditions, orConditionIdx) => { return ( -
-
- {orConditions.map((condition, conditionIdx) => { +
+ {orConditions.map((item, conditionIdx) => { const actionConditionIndex = { ruleIndex: index, groupIndex: orConditionIdx, @@ -71,51 +73,52 @@ export const WhenSection = ({ index }: { index: number }) => { [key]: value, }) } + const type = - filterFieldOptions.find((option) => option.value === condition.field)?.type || + filterFieldOptions.find((option) => option.value === item.field)?.type || "text" + return ( -
-
-
-
+
+
change("field", value as ActionFeedField)} items={filterFieldOptions.map((option) => ({ ...option, label: t(option.label), }))} - triggerClassName="h-8" + triggerClassName="h-9 min-w-[160px] @[800px]:flex-1" /> change("operator", value)} /> change("value", value)} disabled={disabled} /> - +
{conditionIdx !== orConditions.length - 1 && ( -
- +
+ {t("actions.action_card.and")}
@@ -125,7 +128,8 @@ export const WhenSection = ({ index }: { index: number }) => { })}
{orConditionIdx !== condition.length - 1 && ( -
-
- +
+ {t("actions.action_card.or")}
@@ -151,6 +154,8 @@ export const WhenSection = ({ index }: { index: number }) => { })}
)} -
+
) } @@ -192,9 +197,9 @@ const OperationSelect = ({ placeholder="Select Operation" disabled={disabled} value={value} - onValueChange={(value) => onValueChange?.(value as ActionOperation)} + onValueChange={(nextValue) => onValueChange?.(nextValue as ActionOperation)} items={options} - triggerClassName="h-8" + triggerClassName="h-9 min-w-[150px]" /> ) } @@ -215,7 +220,7 @@ const ValueInput = ({ return ( onChange(value)} + onValueChange={(nextValue) => onChange(nextValue)} value={value as string | undefined} > @@ -247,8 +252,8 @@ const ValueInput = ({ disabled={disabled} type="number" value={value} - className="h-8" - onChange={(e) => onChange(e.target.value)} + className="h-9" + onChange={(event) => onChange(event.target.value)} /> ) } @@ -257,8 +262,8 @@ const ValueInput = ({ onChange(e.target.value)} + className="h-9" + onChange={(event) => onChange(event.target.value)} /> ) } @@ -266,7 +271,7 @@ const ValueInput = ({ } const CommonSelectTrigger = () => ( - + ) diff --git a/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/action/index.tsx b/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/action/index.tsx index 4f09b17a9..2bb82dc30 100644 --- a/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/action/index.tsx +++ b/apps/desktop/layer/renderer/src/pages/(main)/(layer)/(subview)/action/index.tsx @@ -10,9 +10,9 @@ export function Component() { useSubViewTitle("words.actions") return ( -
+
{/* Simple Header */} -
+

{t("words.actions")}

{/* Documentation Link */} @@ -28,7 +28,7 @@ export function Component() {
{/* Content */} -
+
diff --git a/locales/settings/en.json b/locales/settings/en.json index ce610ddf2..577cd811c 100644 --- a/locales/settings/en.json +++ b/locales/settings/en.json @@ -64,6 +64,23 @@ "actions.action_card.silence": "Silence", "actions.action_card.source_content": "View Source Content", "actions.action_card.star": "Star", + "actions.action_card.summary.action_count": "{{count}} actions enabled", + "actions.action_card.summary.active": "Active", + "actions.action_card.summary.copy": "Copy to Clipboard", + "actions.action_card.summary.delete": "Delete", + "actions.action_card.summary.delete_message": "Are you sure you want to delete this rule? This action cannot be undone.", + "actions.action_card.summary.delete_title": "Delete Rule", + "actions.action_card.summary.disabled": "Disabled", + "actions.action_card.summary.empty": "No rules yet", + "actions.action_card.summary.export": "Export to File", + "actions.action_card.summary.helper": "Automate your workflow with precise triggers and actions.", + "actions.action_card.summary.import": "Import", + "actions.action_card.summary.import_clipboard": "Import from Clipboard", + "actions.action_card.summary.import_file": "Import from File", + "actions.action_card.summary.no_actions": "No actions configured yet", + "actions.action_card.summary.rule_count": "{{count}} rules", + "actions.action_card.summary.share": "Share", + "actions.action_card.summary.toggle": "Toggle rule status", "actions.action_card.then_do": "Then Do…", "actions.action_card.to": "To", "actions.action_card.translate_into": "Translate", diff --git a/locales/settings/ja.json b/locales/settings/ja.json index 6bccda24d..d719063ef 100644 --- a/locales/settings/ja.json +++ b/locales/settings/ja.json @@ -64,6 +64,23 @@ "actions.action_card.silence": "サイレント", "actions.action_card.source_content": "ソースコンテンツを表示する", "actions.action_card.star": "スター", + "actions.action_card.summary.action_count": "有効なアクション {{count}} 件", + "actions.action_card.summary.active": "有効", + "actions.action_card.summary.copy": "クリップボードにコピー", + "actions.action_card.summary.delete": "削除", + "actions.action_card.summary.delete_message": "このルールを削除してもよろしいですか?この操作は元に戻せません。", + "actions.action_card.summary.delete_title": "ルールを削除", + "actions.action_card.summary.disabled": "無効", + "actions.action_card.summary.empty": "ルールはまだありません", + "actions.action_card.summary.export": "ファイルにエクスポート", + "actions.action_card.summary.helper": "条件とアクションを組み合わせてワークフローを自動化しましょう。", + "actions.action_card.summary.import": "インポート", + "actions.action_card.summary.import_clipboard": "クリップボードからインポート", + "actions.action_card.summary.import_file": "ファイルからインポート", + "actions.action_card.summary.no_actions": "アクションはまだ設定されていません", + "actions.action_card.summary.rule_count": "ルール {{count}} 件", + "actions.action_card.summary.share": "共有", + "actions.action_card.summary.toggle": "ルールの有効・無効を切り替える", "actions.action_card.then_do": "次に行う…", "actions.action_card.to": "へ", "actions.action_card.translate_into": "翻訳する", diff --git a/locales/settings/zh-CN.json b/locales/settings/zh-CN.json index 0f5b3114a..ac50c2a27 100644 --- a/locales/settings/zh-CN.json +++ b/locales/settings/zh-CN.json @@ -64,6 +64,23 @@ "actions.action_card.silence": "静音", "actions.action_card.source_content": "查看原始内容", "actions.action_card.star": "收藏", + "actions.action_card.summary.action_count": "已启用 {{count}} 个动作", + "actions.action_card.summary.active": "启用", + "actions.action_card.summary.copy": "复制到剪贴板", + "actions.action_card.summary.delete": "删除", + "actions.action_card.summary.delete_message": "确定要删除此规则吗?该操作无法撤销。", + "actions.action_card.summary.delete_title": "删除规则", + "actions.action_card.summary.disabled": "已禁用", + "actions.action_card.summary.empty": "暂时还没有规则", + "actions.action_card.summary.export": "导出到文件", + "actions.action_card.summary.helper": "用精准的触发条件和动作自动化你的工作流。", + "actions.action_card.summary.import": "导入", + "actions.action_card.summary.import_clipboard": "从剪贴板导入", + "actions.action_card.summary.import_file": "从文件导入", + "actions.action_card.summary.no_actions": "尚未配置任何动作", + "actions.action_card.summary.rule_count": "{{count}} 条规则", + "actions.action_card.summary.share": "分享", + "actions.action_card.summary.toggle": "切换规则状态", "actions.action_card.then_do": "执行动作", "actions.action_card.to": "到", "actions.action_card.translate_into": "翻译成", diff --git a/locales/settings/zh-TW.json b/locales/settings/zh-TW.json index 9467989c4..d820f7e99 100644 --- a/locales/settings/zh-TW.json +++ b/locales/settings/zh-TW.json @@ -61,6 +61,23 @@ "actions.action_card.silence": "靜音", "actions.action_card.source_content": "瀏覽原始内容", "actions.action_card.star": "收藏", + "actions.action_card.summary.action_count": "已啟用 {{count}} 個動作", + "actions.action_card.summary.active": "啟用中", + "actions.action_card.summary.copy": "複製到剪貼簿", + "actions.action_card.summary.delete": "刪除", + "actions.action_card.summary.delete_message": "確定要刪除此規則嗎?此操作無法復原。", + "actions.action_card.summary.delete_title": "刪除規則", + "actions.action_card.summary.disabled": "已停用", + "actions.action_card.summary.empty": "尚未建立任何規則", + "actions.action_card.summary.export": "匯出成檔案", + "actions.action_card.summary.helper": "透過精準的條件與動作,自動化你的工作流程。", + "actions.action_card.summary.import": "匯入", + "actions.action_card.summary.import_clipboard": "從剪貼簿匯入", + "actions.action_card.summary.import_file": "從檔案匯入", + "actions.action_card.summary.no_actions": "尚未設定任何動作", + "actions.action_card.summary.rule_count": "{{count}} 條規則", + "actions.action_card.summary.share": "分享", + "actions.action_card.summary.toggle": "切換規則狀態", "actions.action_card.then_do": "然後執行…", "actions.action_card.to": "到", "actions.action_card.translate_into": "翻譯成",