-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickActionsMenu.tsx
More file actions
219 lines (202 loc) · 6.59 KB
/
Copy pathQuickActionsMenu.tsx
File metadata and controls
219 lines (202 loc) · 6.59 KB
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
218
219
import { useCallback, useEffect } from 'react';
import { useTranslation } from 'react-i18next';
import {
Clock,
Play,
StopCircle,
CheckCircle2,
Layers,
Trash2,
MoreHorizontal
} from 'lucide-react';
import { Button } from './ui/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger
} from './ui/dropdown-menu';
import { cn } from '../lib/utils';
import {
useQuickActionsStore,
getActionLabel,
canRepeatAction,
getTimeAgo,
type RecentAction
} from '../stores/quick-actions-store';
interface QuickActionsMenuProps {
/** Callback when an action is selected */
onActionSelect?: (action: RecentAction) => void;
/** Optional className for styling */
className?: string;
}
/**
* Get icon component for an action type
*/
function getActionIcon(type: RecentAction['type']) {
switch (type) {
case 'batch_qa':
return CheckCircle2;
case 'batch_status_update':
return Layers;
case 'create_task':
return Play;
case 'start_task':
return Play;
case 'stop_task':
return StopCircle;
default:
return MoreHorizontal;
}
}
/**
* Quick Actions Menu component
*
* Displays a dropdown menu with recent actions for quick access.
* Actions are persisted across sessions and can be repeated with one click.
*
* Features:
* - Shows recent actions with timestamps
* - One-click repeat for batch operations
* - Clear history option
* - Auto-loads from localStorage on mount
*/
export function QuickActionsMenu({ onActionSelect, className }: QuickActionsMenuProps) {
const { t } = useTranslation(['quickActions', 'common']);
const recentActions = useQuickActionsStore((state) => state.recentActions);
const clearRecentActions = useQuickActionsStore((state) => state.clearRecentActions);
const removeRecentAction = useQuickActionsStore((state) => state.removeRecentAction);
const loadRecentActions = useQuickActionsStore((state) => state.loadRecentActions);
// Load recent actions on mount
useEffect(() => {
loadRecentActions();
}, [loadRecentActions]);
// Handle action selection
const handleActionSelect = useCallback(
(action: RecentAction) => {
if (onActionSelect) {
onActionSelect(action);
}
},
[onActionSelect]
);
// Handle clear all
const handleClearAll = useCallback(() => {
clearRecentActions();
}, [clearRecentActions]);
// Handle remove individual action
const handleRemoveAction = useCallback(
(e: React.MouseEvent, actionId: string) => {
e.stopPropagation();
removeRecentAction(actionId);
},
[removeRecentAction]
);
const hasRecentActions = recentActions.length > 0;
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button
variant="ghost"
size="sm"
className={cn(
'relative',
hasRecentActions && 'text-accent-foreground',
className
)}
>
<Clock className="h-4 w-4 mr-2" />
<span>{t('quickActions:title')}</span>
{hasRecentActions && (
<span
className={cn(
'ml-2 flex h-5 w-5 items-center justify-center rounded-full',
'bg-primary text-primary-foreground text-xs',
'font-medium'
)}
>
{recentActions.length}
</span>
)}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-80">
<DropdownMenuLabel className="flex items-center gap-2">
<Clock className="h-4 w-4" />
<span>{t('quickActions:recentActions')}</span>
</DropdownMenuLabel>
<DropdownMenuSeparator />
{hasRecentActions ? (
<>
<DropdownMenuGroup>
{recentActions.map((action) => {
const IconComponent = getActionIcon(action.type);
const canRepeat = canRepeatAction(action);
const timeAgo = getTimeAgo(action.timestamp);
const label = getActionLabel(action);
return (
<DropdownMenuItem
key={action.id}
disabled={!canRepeat}
className={cn(
'group flex items-center gap-2 py-2',
canRepeat && 'cursor-pointer'
)}
onClick={() => canRepeat && handleActionSelect(action)}
>
<div
className={cn(
'flex h-8 w-8 shrink-0 items-center justify-center rounded-md',
'bg-muted text-muted-foreground',
canRepeat && 'group-hover:bg-accent group-hover:text-accent-foreground'
)}
>
<IconComponent className="h-4 w-4" />
</div>
<div className="flex flex-1 flex-col gap-0.5 overflow-hidden">
<span className="truncate text-sm font-medium">
{label}
</span>
<span className="truncate text-xs text-muted-foreground">
{timeAgo}
</span>
</div>
{canRepeat && (
<Button
variant="ghost"
size="sm"
className="h-6 w-6 p-0 opacity-0 group-hover:opacity-100"
onClick={(e) => handleRemoveAction(e, action.id)}
>
<Trash2 className="h-3 w-3 text-muted-foreground" />
</Button>
)}
</DropdownMenuItem>
);
})}
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem
className="cursor-pointer text-destructive focus:text-destructive"
onClick={handleClearAll}
>
<Trash2 className="h-4 w-4 mr-2" />
<span>{t('quickActions:clearHistory')}</span>
</DropdownMenuItem>
</>
) : (
<div className="py-8 text-center text-sm text-muted-foreground">
<Clock className="mx-auto h-8 w-8 mb-2 opacity-50" />
<p>{t('quickActions:noRecentActions')}</p>
<p className="mt-1 text-xs">
{t('quickActions:noRecentActionsHint')}
</p>
</div>
)}
</DropdownMenuContent>
</DropdownMenu>
);
}