Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | /** * BatchActionBar - Batch Operations Action Bar * * Provides batch action buttons for selected automation items. * Supports batch execute, approve, reject, and schedule. * * @module components/Automation/BatchActionBar */ import { useState, useCallback } from 'react'; import { Play, Check, X, Clock, XCircle, MoreHorizontal, Trash2, Copy, } from 'lucide-react'; // === Component Props === interface BatchActionBarProps { selectedCount: number; totalCount?: number; // Optional - for "select all X items" display onSelectAll: () => void; onDeselectAll: () => void; onBatchExecute: () => Promise<void>; onBatchApprove?: () => Promise<void>; onBatchReject?: () => Promise<void>; onBatchSchedule?: () => void; onBatchDelete?: () => Promise<void>; onBatchDuplicate?: () => Promise<void>; } // === Main Component === export function BatchActionBar({ selectedCount, totalCount: _totalCount, // Used for future "select all X items" display onSelectAll, onDeselectAll, onBatchExecute, onBatchApprove, onBatchReject, onBatchSchedule, onBatchDelete, onBatchDuplicate, }: BatchActionBarProps) { const [isExecuting, setIsExecuting] = useState(false); const [showMoreMenu, setShowMoreMenu] = useState(false); // Handle batch execute const handleExecute = useCallback(async () => { setIsExecuting(true); try { await onBatchExecute(); } finally { setIsExecuting(false); } }, [onBatchExecute]); // Handle batch approve const handleApprove = useCallback(async () => { if (onBatchApprove) { setIsExecuting(true); try { await onBatchApprove(); } finally { setIsExecuting(false); } } }, [onBatchApprove]); // Handle batch reject const handleReject = useCallback(async () => { if (onBatchReject) { setIsExecuting(true); try { await onBatchReject(); } finally { setIsExecuting(false); } } }, [onBatchReject]); return ( <div className="sticky bottom-0 left-0 right-0 bg-orange-50 dark:bg-orange-900/20 border-t border-orange-200 dark:border-orange-800 px-4 py-3"> <div className="flex items-center justify-between gap-4"> {/* Selection Info */} <div className="flex items-center gap-3"> <span className="text-sm text-orange-700 dark:text-orange-300"> 已选择 <span className="font-medium">{selectedCount}</span> 项 </span> <div className="flex items-center gap-1"> <button onClick={onSelectAll} className="text-xs text-orange-600 dark:text-orange-400 hover:underline" > 全选 </button> <span className="text-orange-400 dark:text-orange-600">|</span> <button onClick={onDeselectAll} className="text-xs text-orange-600 dark:text-orange-400 hover:underline" > 取消选择 </button> </div> </div> {/* Action Buttons */} <div className="flex items-center gap-2"> {/* Execute */} <button onClick={handleExecute} disabled={isExecuting} className="inline-flex items-center gap-1.5 px-3 py-1.5 text-sm bg-orange-500 text-white rounded-md hover:bg-orange-600 disabled:opacity-50 disabled:cursor-not-allowed" > <Play className="w-3.5 h-3.5" /> 批量执行 </button> {/* Approve (if handler provided) */} {onBatchApprove && ( <button onClick={handleApprove} disabled={isExecuting} className="inline-flex items-center gap-1.5 px-3 py-1.5 text-sm bg-green-500 text-white rounded-md hover:bg-green-600 disabled:opacity-50 disabled:cursor-not-allowed" > <Check className="w-3.5 h-3.5" /> 批量审批 </button> )} {/* Reject (if handler provided) */} {onBatchReject && ( <button onClick={handleReject} disabled={isExecuting} className="inline-flex items-center gap-1.5 px-3 py-1.5 text-sm bg-red-500 text-white rounded-md hover:bg-red-600 disabled:opacity-50 disabled:cursor-not-allowed" > <X className="w-3.5 h-3.5" /> 批量拒绝 </button> )} {/* Schedule */} {onBatchSchedule && ( <button onClick={onBatchSchedule} disabled={isExecuting} className="inline-flex items-center gap-1.5 px-3 py-1.5 text-sm border border-orange-300 dark:border-orange-700 text-orange-600 dark:text-orange-400 rounded-md hover:bg-orange-100 dark:hover:bg-orange-900/30 disabled:opacity-50 disabled:cursor-not-allowed" > <Clock className="w-3.5 h-3.5" /> 批量调度 </button> )} {/* More Actions */} {(onBatchDelete || onBatchDuplicate) && ( <div className="relative"> <button onClick={() => setShowMoreMenu(!showMoreMenu)} className="p-1.5 text-orange-600 dark:text-orange-400 hover:bg-orange-100 dark:hover:bg-orange-900/30 rounded-md" > <MoreHorizontal className="w-4 h-4" /> </button> {showMoreMenu && ( <div className="absolute bottom-full right-0 mb-1 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg py-1 min-w-[150px] z-10"> {onBatchDuplicate && ( <button onClick={() => { onBatchDuplicate(); setShowMoreMenu(false); }} className="w-full flex items-center gap-2 px-3 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700" > <Copy className="w-4 h-4" /> 复制 </button> )} {onBatchDelete && ( <button onClick={() => { onBatchDelete(); setShowMoreMenu(false); }} className="w-full flex items-center gap-2 px-3 py-2 text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20" > <Trash2 className="w-4 h-4" /> 删除 </button> )} </div> )} </div> )} {/* Close */} <button onClick={onDeselectAll} className="p-1.5 text-orange-600 dark:text-orange-400 hover:bg-orange-100 dark:hover:bg-orange-900/30 rounded-md" title="取消选择" > <XCircle className="w-4 h-4" /> </button> </div> </div> </div> ); } export default BatchActionBar; |