@svadmin/ui 0.33.0 → 0.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,150 @@
1
+ <script lang="ts">
2
+ import { useTaskList, getTaskProvider } from '@svadmin/core';
3
+ import { t } from '@svadmin/core/i18n';
4
+ import type { TaskProvider, TaskRecord } from '@svadmin/core';
5
+ import { Loader2 } from '@lucide/svelte';
6
+ import * as Card from './ui/card/index.js';
7
+ import * as Table from './ui/table/index.js';
8
+ import { Button } from './ui/button/index.js';
9
+ import TaskStatusBadge from './TaskStatusBadge.svelte';
10
+ import TaskProgressBar from './TaskProgressBar.svelte';
11
+ import RetryTaskButton from './RetryTaskButton.svelte';
12
+ import CancelTaskButton from './CancelTaskButton.svelte';
13
+
14
+ let {
15
+ tasks,
16
+ taskProvider = getTaskProvider({ optional: true }) as TaskProvider<TaskRecord> | undefined,
17
+ params,
18
+ dlq = false,
19
+ title,
20
+ emptyText,
21
+ showActions = true,
22
+ showProgress = true,
23
+ useProviderData = !tasks,
24
+ queryOptions,
25
+ onSelect,
26
+ } = $props<{
27
+ tasks?: TaskRecord[];
28
+ taskProvider?: TaskProvider<TaskRecord>;
29
+ params?: Record<string, unknown>;
30
+ dlq?: boolean;
31
+ title?: string;
32
+ emptyText?: string;
33
+ showActions?: boolean;
34
+ showProgress?: boolean;
35
+ useProviderData?: boolean;
36
+ queryOptions?: {
37
+ enabled?: boolean;
38
+ staleTime?: number;
39
+ gcTime?: number;
40
+ refetchOnWindowFocus?: boolean;
41
+ refetchInterval?: number | false;
42
+ refetchIntervalInBackground?: boolean;
43
+ };
44
+ onSelect?: (task: TaskRecord) => void;
45
+ }>();
46
+
47
+ const query = useTaskList({
48
+ get params() {
49
+ return params;
50
+ },
51
+ get dlq() {
52
+ return dlq;
53
+ },
54
+ get taskProvider() {
55
+ return taskProvider;
56
+ },
57
+ get queryOptions() {
58
+ return { enabled: useProviderData && !!taskProvider, ...queryOptions };
59
+ },
60
+ });
61
+
62
+ const resolvedTasks = $derived(tasks ?? query.data?.data ?? []);
63
+ const resolvedTitle = $derived(title ?? (dlq ? t('task.dlqTitle') : t('task.listTitle')));
64
+ const resolvedEmptyText = $derived(emptyText ?? (dlq ? t('task.noDlq') : t('task.noTasks')));
65
+
66
+ function formatDate(value: unknown) {
67
+ if (!value) return '—';
68
+ return new Date(value as string | Date).toLocaleString();
69
+ }
70
+ </script>
71
+
72
+ <Card.Root class="border-border/40 shadow-sm">
73
+ <Card.Header class="pb-3">
74
+ <Card.Title class="text-base">{resolvedTitle}</Card.Title>
75
+ <Card.Description>
76
+ {#if useProviderData && taskProvider}
77
+ {t('task.count', { count: (query.data?.total ?? resolvedTasks.length) || 0 })}
78
+ {:else}
79
+ {t('task.count', { count: resolvedTasks.length })}
80
+ {/if}
81
+ </Card.Description>
82
+ </Card.Header>
83
+ <Card.Content class="pt-0">
84
+ {#if useProviderData && taskProvider && query.isLoading}
85
+ <div class="flex h-40 items-center justify-center text-muted-foreground">
86
+ <Loader2 class="mr-2 h-4 w-4 animate-spin" />
87
+ {t('task.loadingList')}
88
+ </div>
89
+ {:else}
90
+ <div class="overflow-auto">
91
+ <Table.Root>
92
+ <Table.Header>
93
+ <Table.Row>
94
+ <Table.Head>{t('task.taskColumn')}</Table.Head>
95
+ <Table.Head>{t('task.statusColumn')}</Table.Head>
96
+ <Table.Head>{t('task.updatedColumn')}</Table.Head>
97
+ {#if showActions}
98
+ <Table.Head class="text-right">{t('task.actionsColumn')}</Table.Head>
99
+ {/if}
100
+ </Table.Row>
101
+ </Table.Header>
102
+ <Table.Body>
103
+ {#each resolvedTasks as task}
104
+ <Table.Row class="cursor-pointer hover:bg-muted/40" onclick={() => onSelect?.(task)}>
105
+ <Table.Cell class="min-w-[240px]">
106
+ <div class="space-y-1">
107
+ <div class="font-medium text-foreground">{String(task.title ?? task.name ?? task.id)}</div>
108
+ {#if task.message}
109
+ <div class="text-xs text-muted-foreground">{String(task.message)}</div>
110
+ {/if}
111
+ {#if showProgress && typeof task.progress === 'number' && String(task.status).toLowerCase() === 'running'}
112
+ <TaskProgressBar value={Number(task.progress)} />
113
+ {/if}
114
+ </div>
115
+ </Table.Cell>
116
+ <Table.Cell>
117
+ <TaskStatusBadge status={String(task.status ?? 'pending')} />
118
+ </Table.Cell>
119
+ <Table.Cell class="text-xs text-muted-foreground">
120
+ {formatDate(task.updatedAt ?? task.createdAt)}
121
+ </Table.Cell>
122
+ {#if showActions}
123
+ <Table.Cell class="text-right">
124
+ <div class="flex justify-end gap-2">
125
+ {#if taskProvider?.retry && ['failed', 'error'].includes(String(task.status).toLowerCase())}
126
+ <RetryTaskButton taskId={task.id} {taskProvider} />
127
+ {/if}
128
+ {#if taskProvider?.cancel && ['pending', 'queued', 'running', 'processing'].includes(String(task.status).toLowerCase())}
129
+ <CancelTaskButton taskId={task.id} {taskProvider} />
130
+ {/if}
131
+ <Button variant="ghost" size="sm" onclick={(e) => { e.stopPropagation(); onSelect?.(task); }}>
132
+ {t('task.detailsAction')}
133
+ </Button>
134
+ </div>
135
+ </Table.Cell>
136
+ {/if}
137
+ </Table.Row>
138
+ {:else}
139
+ <Table.Row>
140
+ <Table.Cell colspan={showActions ? 4 : 3} class="h-24 text-center text-muted-foreground">
141
+ {resolvedEmptyText}
142
+ </Table.Cell>
143
+ </Table.Row>
144
+ {/each}
145
+ </Table.Body>
146
+ </Table.Root>
147
+ </div>
148
+ {/if}
149
+ </Card.Content>
150
+ </Card.Root>
@@ -0,0 +1,24 @@
1
+ import type { TaskProvider, TaskRecord } from '@svadmin/core';
2
+ type $$ComponentProps = {
3
+ tasks?: TaskRecord[];
4
+ taskProvider?: TaskProvider<TaskRecord>;
5
+ params?: Record<string, unknown>;
6
+ dlq?: boolean;
7
+ title?: string;
8
+ emptyText?: string;
9
+ showActions?: boolean;
10
+ showProgress?: boolean;
11
+ useProviderData?: boolean;
12
+ queryOptions?: {
13
+ enabled?: boolean;
14
+ staleTime?: number;
15
+ gcTime?: number;
16
+ refetchOnWindowFocus?: boolean;
17
+ refetchInterval?: number | false;
18
+ refetchIntervalInBackground?: boolean;
19
+ };
20
+ onSelect?: (task: TaskRecord) => void;
21
+ };
22
+ declare const TaskList: import("svelte").Component<$$ComponentProps, {}, "">;
23
+ type TaskList = ReturnType<typeof TaskList>;
24
+ export default TaskList;
@@ -0,0 +1,25 @@
1
+ <script lang="ts">
2
+ import { Progress } from './ui/progress/index.js';
3
+
4
+ let {
5
+ value = 0,
6
+ label = 'Progress',
7
+ showLabel = true,
8
+ } = $props<{
9
+ value?: number;
10
+ label?: string;
11
+ showLabel?: boolean;
12
+ }>();
13
+
14
+ const safeValue = $derived(Math.max(0, Math.min(100, Number(value ?? 0))));
15
+ </script>
16
+
17
+ <div class="space-y-1.5">
18
+ {#if showLabel}
19
+ <div class="flex items-center justify-between text-[11px] text-muted-foreground">
20
+ <span>{label}</span>
21
+ <span class="font-mono">{safeValue}%</span>
22
+ </div>
23
+ {/if}
24
+ <Progress value={safeValue} max={100} class="h-1.5" />
25
+ </div>
@@ -0,0 +1,8 @@
1
+ type $$ComponentProps = {
2
+ value?: number;
3
+ label?: string;
4
+ showLabel?: boolean;
5
+ };
6
+ declare const TaskProgressBar: import("svelte").Component<$$ComponentProps, {}, "">;
7
+ type TaskProgressBar = ReturnType<typeof TaskProgressBar>;
8
+ export default TaskProgressBar;