TasksView.vue
Vue · 407 рядків
1<script setup>
2import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
3import { api } from '../api.js'
4
5const emit = defineEmits(['notify'])
6const scope = ref('active')
7const query = ref('')
8const type = ref('')
9const sort = ref('updatedAt')
10const direction = ref('desc')
11const tasks = ref([])
12const types = ref([])
13const counts = ref({ active: 0, completed: 0 })
14const total = ref(0)
15const loading = ref(true)
16let searchTimer = null
17let requestSequence = 0
18
19async function load() {
20 const requestId = ++requestSequence
21 loading.value = true
22 try {
23 const result = await api.tasks({
24 scope: scope.value,
25 query: query.value.trim(),
26 type: type.value,
27 sort: sort.value,
28 direction: direction.value
29 })
30 if (requestId !== requestSequence) return
31 tasks.value = result.tasks
32 types.value = result.types
33 counts.value = result.counts
34 total.value = result.total
35 } catch (error) {
36 if (requestId === requestSequence) emit('notify', error.message)
37 } finally {
38 if (requestId === requestSequence) loading.value = false
39 }
40}
41
42function selectScope(value) {
43 if (scope.value === value) return
44 scope.value = value
45}
46
47function sortBy(field) {
48 if (sort.value === field) {
49 direction.value = direction.value === 'asc' ? 'desc' : 'asc'
50 } else {
51 sort.value = field
52 direction.value = field === 'updatedAt' ? 'desc' : 'asc'
53 }
54 load()
55}
56
57function sortMark(field) {
58 if (sort.value !== field) return ''
59 return direction.value === 'asc' ? ' ↑' : ' ↓'
60}
61
62function formatDate(value) {
63 if (!value) return '—'
64 return new Intl.DateTimeFormat(undefined, {
65 dateStyle: 'medium',
66 timeStyle: 'short'
67 }).format(new Date(value))
68}
69
70function scheduleSearch() {
71 clearTimeout(searchTimer)
72 searchTimer = setTimeout(load, 200)
73}
74
75watch([scope, type], load)
76watch(query, scheduleSearch)
77onMounted(load)
78onBeforeUnmount(() => clearTimeout(searchTimer))
79</script>
80
81<template>
82 <section class="tasks-view">
83 <div class="tasks-heading">
84 <div>
85 <span class="eyebrow">OPERATIONS</span>
86 <h1>Tasks</h1>
87 <p>Find and monitor active or completed warehouse tasks.</p>
88 </div>
89 <button @click="load" :disabled="loading">Refresh</button>
90 </div>
91
92 <nav class="task-scope-tabs" aria-label="Task status">
93 <button
94 :class="{ active: scope === 'active' }"
95 @click="selectScope('active')"
96 >
97 Active <span>{{ counts.active }}</span>
98 </button>
99 <button
100 :class="{ active: scope === 'completed' }"
101 @click="selectScope('completed')"
102 >
103 Completed <span>{{ counts.completed }}</span>
104 </button>
105 </nav>
106
107 <div class="task-filters">
108 <label class="task-search">
109 <span>Search by code</span>
110 <input
111 v-model="query"
112 type="search"
113 placeholder="Entity, order or task ID…"
114 >
115 </label>
116 <label>
117 <span>Task type</span>
118 <select v-model="type">
119 <option value="">All types</option>
120 <option v-for="item in types" :key="item" :value="item">
121 {{ item }}
122 </option>
123 </select>
124 </label>
125 <small>{{ total }} task{{ total === 1 ? '' : 's' }}</small>
126 </div>
127
128 <div class="tasks-table-wrap">
129 <table class="tasks-table">
130 <thead>
131 <tr>
132 <th>
133 <button @click="sortBy('entityId')">
134 Code{{ sortMark('entityId') }}
135 </button>
136 </th>
137 <th>
138 <button @click="sortBy('type')">
139 Type{{ sortMark('type') }}
140 </button>
141 </th>
142 <th>
143 <button @click="sortBy('title')">
144 Task{{ sortMark('title') }}
145 </button>
146 </th>
147 <th>
148 <button @click="sortBy('state')">
149 State{{ sortMark('state') }}
150 </button>
151 </th>
152 <th>
153 <button @click="sortBy('status')">
154 Status{{ sortMark('status') }}
155 </button>
156 </th>
157 <th>
158 <button @click="sortBy('orderId')">
159 Order{{ sortMark('orderId') }}
160 </button>
161 </th>
162 <th>
163 <button @click="sortBy('updatedAt')">
164 Updated{{ sortMark('updatedAt') }}
165 </button>
166 </th>
167 </tr>
168 </thead>
169 <tbody>
170 <tr v-for="task in tasks" :key="task.id">
171 <td>
172 <strong>{{ task.entityId || '—' }}</strong>
173 <small>#{{ task.id.slice(0, 8) }}</small>
174 </td>
175 <td><code>{{ task.type || '—' }}</code></td>
176 <td>
177 <strong>{{ task.title || 'Untitled task' }}</strong>
178 <small>{{ task.description || task.handlerWorkflowId || '—' }}</small>
179 </td>
180 <td>{{ task.state || '—' }}</td>
181 <td>
182 <span :class="['task-status', task.status]">
183 {{ task.status }}
184 </span>
185 </td>
186 <td>{{ task.orderId || '—' }}</td>
187 <td>{{ formatDate(task.updatedAt || task.createdAt) }}</td>
188 </tr>
189 </tbody>
190 </table>
191
192 <div v-if="loading" class="tasks-state">Loading tasks…</div>
193 <div v-else-if="!tasks.length" class="tasks-state">
194 No {{ scope }} tasks match the current filters.
195 </div>
196 </div>
197 </section>
198</template>
199
200<style scoped>
201.tasks-view {
202 grid-column: 1 / 4;
203 min-width: 0;
204 overflow: auto;
205 padding: 38px max(30px, 7vw);
206 background: #080d15;
207}
208
209.tasks-heading {
210 display: flex;
211 align-items: flex-start;
212 justify-content: space-between;
213 padding: 0;
214 background: transparent;
215 border: 0;
216}
217
218.tasks-heading h1 {
219 margin: 6px 0;
220 font-size: 28px;
221}
222
223.tasks-heading p {
224 margin: 0;
225 color: #64748b;
226}
227
228.task-scope-tabs {
229 display: flex;
230 gap: 8px;
231 margin: 28px 0 18px;
232 border-bottom: 1px solid #1e293b;
233}
234
235.task-scope-tabs button {
236 border: 0;
237 border-bottom: 2px solid transparent;
238 border-radius: 0;
239 background: transparent;
240 padding: 11px 4px;
241 color: #64748b;
242}
243
244.task-scope-tabs button + button {
245 margin-left: 18px;
246}
247
248.task-scope-tabs button.active {
249 color: #f8fafc;
250 border-bottom-color: #38bdf8;
251}
252
253.task-scope-tabs span {
254 margin-left: 6px;
255 border-radius: 999px;
256 background: #172033;
257 padding: 2px 7px;
258 color: #94a3b8;
259 font-size: 10px;
260}
261
262.task-filters {
263 display: grid;
264 grid-template-columns: minmax(260px, 1fr) 220px auto;
265 gap: 12px;
266 align-items: end;
267 margin-bottom: 16px;
268}
269
270.task-filters label {
271 color: #94a3b8;
272 font-size: 10px;
273}
274
275.task-filters input,
276.task-filters select {
277 display: block;
278 width: 100%;
279 margin-top: 7px;
280 border: 1px solid #26344c;
281 border-radius: 7px;
282 background: #0b111c;
283 padding: 10px 11px;
284 color: #e2e8f0;
285 font: 12px Inter, sans-serif;
286}
287
288.task-filters small {
289 padding: 11px 0;
290 color: #64748b;
291 white-space: nowrap;
292}
293
294.tasks-table-wrap {
295 position: relative;
296 min-height: 260px;
297 overflow: auto;
298 border: 1px solid #26344c;
299 border-radius: 10px;
300 background: #0b111c;
301}
302
303.tasks-table {
304 width: 100%;
305 min-width: 980px;
306 border-collapse: collapse;
307 text-align: left;
308}
309
310.tasks-table th {
311 position: sticky;
312 top: 0;
313 z-index: 1;
314 border-bottom: 1px solid #26344c;
315 background: #0d1522;
316}
317
318.tasks-table th button {
319 width: 100%;
320 border: 0;
321 border-radius: 0;
322 background: transparent;
323 padding: 12px 14px;
324 text-align: left;
325 color: #64748b;
326 font-size: 9px;
327 letter-spacing: .08em;
328 text-transform: uppercase;
329}
330
331.tasks-table td {
332 border-bottom: 1px solid #172033;
333 padding: 13px 14px;
334 color: #cbd5e1;
335 vertical-align: middle;
336}
337
338.tasks-table tr:last-child td {
339 border-bottom: 0;
340}
341
342.tasks-table tbody tr:hover {
343 background: #101b2a;
344}
345
346.tasks-table td strong,
347.tasks-table td small {
348 display: block;
349}
350
351.tasks-table td small {
352 max-width: 260px;
353 margin-top: 4px;
354 overflow: hidden;
355 color: #64748b;
356 font-size: 9px;
357 text-overflow: ellipsis;
358 white-space: nowrap;
359}
360
361.tasks-table code {
362 color: #7dd3fc;
363 font: 10px 'JetBrains Mono', monospace;
364}
365
366.task-status {
367 display: inline-block;
368 border-radius: 999px;
369 background: #334155;
370 padding: 4px 8px;
371 color: #cbd5e1;
372 font-size: 9px;
373 text-transform: uppercase;
374}
375
376.task-status.open {
377 background: #0c4a6e;
378 color: #7dd3fc;
379}
380
381.task-status.in_progress {
382 background: #713f12;
383 color: #fde047;
384}
385
386.task-status.completed {
387 background: #14532d;
388 color: #86efac;
389}
390
391.tasks-state {
392 padding: 60px 20px;
393 color: #64748b;
394 text-align: center;
395}
396
397@media (max-width: 850px) {
398 .task-filters {
399 grid-template-columns: 1fr;
400 }
401
402 .task-filters small {
403 padding: 0;
404 }
405}
406</style>
407