import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Archive, Download, List, PlusCircle, Star, Tag, Trash2, } from "lucide-react"; import { useTranslation } from "react-i18next"; import type { RuleEngineAction } from "@karakeep/shared/types/rules"; import { BookmarkListSelector } from "../lists/BookmarkListSelector"; import { TagAutocomplete } from "../tags/TagAutocomplete"; interface ActionBuilderProps { value: RuleEngineAction[]; onChange: (actions: RuleEngineAction[]) => void; } export function ActionBuilder({ value, onChange }: ActionBuilderProps) { const { t } = useTranslation(); const handleAddAction = () => { onChange([...value, { type: "addTag", tagId: "" }]); }; const handleRemoveAction = (index: number) => { const newActions = [...value]; newActions.splice(index, 1); onChange(newActions); }; const handleActionTypeChange = ( index: number, type: RuleEngineAction["type"], ) => { const newActions = [...value]; switch (type) { case "addTag": newActions[index] = { type: "addTag", tagId: "" }; break; case "removeTag": newActions[index] = { type: "removeTag", tagId: "" }; break; case "addToList": newActions[index] = { type: "addToList", listId: "" }; break; case "removeFromList": newActions[index] = { type: "removeFromList", listId: "" }; break; case "downloadFullPageArchive": newActions[index] = { type: "downloadFullPageArchive" }; break; case "favouriteBookmark": newActions[index] = { type: "favouriteBookmark" }; break; case "archiveBookmark": newActions[index] = { type: "archiveBookmark" }; break; default: { const _exhaustiveCheck: never = type; return null; } } onChange(newActions); }; const handleActionFieldChange = ( index: number, selectVal: RuleEngineAction, ) => { const newActions = [...value]; newActions[index] = selectVal; onChange(newActions); }; const renderActionIcon = (type: string) => { switch (type) { case "addTag": case "removeTag": return ; case "addToList": case "removeFromList": return ; case "downloadFullPageArchive": return ; case "favouriteBookmark": return ; case "archiveBookmark": return ; default: return null; } }; return (
{value.length === 0 ? (

No actions added yet

) : ( value.map((action, index) => (
{renderActionIcon(action.type)} {(action.type === "addTag" || action.type === "removeTag") && ( handleActionFieldChange(index, { type: action.type, tagId: t, }) } /> )} {(action.type === "addToList" || action.type === "removeFromList") && ( handleActionFieldChange(index, { type: action.type, listId: e, }) } /> )}
)) )}
); }