-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForm.vue
More file actions
210 lines (189 loc) · 6.63 KB
/
Copy pathForm.vue
File metadata and controls
210 lines (189 loc) · 6.63 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
<script setup lang="ts">
import type { FormError, FormSubmitEvent } from '#ui/types'
// --- Basic job submission form ---
const jobState = reactive({
agentId: '',
runtime: '',
priority: 'normal',
maxRetries: 3,
dryRun: false,
})
const runtimeOptions = [
{ label: 'Local (dev)', value: 'local' },
{ label: 'Cloud (prod)', value: 'cloud' },
{ label: 'Edge (beta)', value: 'edge' },
]
const priorityOptions = [
{ label: 'Low', value: 'low' },
{ label: 'Normal', value: 'normal' },
{ label: 'High', value: 'high' },
{ label: 'Critical', value: 'critical' },
]
function validateJob(state: typeof jobState): FormError[] {
const errors: FormError[] = []
if (!state.agentId) errors.push({ name: 'agentId', message: 'Agent ID is required' })
if (!state.runtime) errors.push({ name: 'runtime', message: 'Select a runtime target' })
if (state.maxRetries < 0 || state.maxRetries > 10)
errors.push({ name: 'maxRetries', message: 'Must be between 0 and 10' })
return errors
}
const toast = useToast()
async function onJobSubmit(event: FormSubmitEvent<typeof jobState>) {
toast.add({
title: 'Job queued',
description: `Agent "${event.data.agentId}" dispatched to ${event.data.runtime} runtime.`,
color: 'success',
icon: 'i-material-symbols-check-circle-outline',
})
}
// --- Disabled form state ---
const disabledState = reactive({ agentId: 'agent-7f3a', runtime: 'cloud' })
// --- Validation states demo ---
const validationState = reactive({ sessionId: '', leaseTimeout: '' })
function validateSession(state: typeof validationState): FormError[] {
const errors: FormError[] = []
if (!state.sessionId) errors.push({ name: 'sessionId', message: 'Session ID is required' })
if (!state.leaseTimeout) errors.push({ name: 'leaseTimeout', message: 'Lease timeout is required' })
return errors
}
</script>
<template>
<div class="flex flex-col gap-8">
<!-- Job Dispatch Form -->
<GallerySection title="Job dispatch form">
<UForm
:state="jobState"
:validate="validateJob"
class="w-full max-w-lg space-y-4"
@submit="onJobSubmit"
>
<UFormField name="agentId" label="Agent ID" required hint="Must be a registered agent">
<UInput
v-model="jobState.agentId"
placeholder="agent-7f3a1b"
icon="i-material-symbols-smart-toy-outline"
class="w-full"
/>
</UFormField>
<UFormField name="runtime" label="Runtime target" required description="Where the job will execute">
<USelect
v-model="jobState.runtime"
:items="runtimeOptions"
value-key="value"
placeholder="Select runtime…"
class="w-full"
/>
</UFormField>
<UFormField name="priority" label="Priority">
<USelect
v-model="jobState.priority"
:items="priorityOptions"
value-key="value"
class="w-full"
/>
</UFormField>
<UFormField name="maxRetries" label="Max retries" help="Retries on transient failures (0–10)">
<UInputNumber
v-model="jobState.maxRetries"
:min="0"
:max="10"
class="w-full"
/>
</UFormField>
<UFormField name="dryRun" label="Dry run" description="Validate the job without executing it">
<USwitch v-model="jobState.dryRun" label="Enabled" />
</UFormField>
<div class="flex gap-3 pt-2">
<UButton type="submit" icon="i-material-symbols-rocket-launch-outline">
Dispatch job
</UButton>
<UButton type="reset" variant="ghost" color="neutral">
Reset
</UButton>
</div>
</UForm>
</GallerySection>
<!-- Inline validation -->
<GallerySection title="Validation states">
<UForm
:state="validationState"
:validate="validateSession"
:validate-on="['blur', 'change']"
class="w-full max-w-lg space-y-4"
@submit="() => {}"
>
<UFormField name="sessionId" label="Session ID" required>
<UInput
v-model="validationState.sessionId"
placeholder="sess-0000"
icon="i-material-symbols-key-outline"
class="w-full"
/>
</UFormField>
<UFormField
name="leaseTimeout"
label="Lease timeout"
required
description="Duration before the session lease expires"
>
<UInput
v-model="validationState.leaseTimeout"
placeholder="30s"
icon="i-material-symbols-timer-outline"
class="w-full"
/>
</UFormField>
<div class="flex gap-3 pt-2">
<UButton type="submit" color="secondary" icon="i-material-symbols-lock-clock-outline">
Claim session
</UButton>
</div>
</UForm>
</GallerySection>
<!-- Disabled form -->
<GallerySection title="Disabled state">
<UForm :state="disabledState" disabled class="w-full max-w-lg space-y-4" @submit="() => {}">
<UFormField name="agentId" label="Agent ID">
<UInput v-model="disabledState.agentId" class="w-full" />
</UFormField>
<UFormField name="runtime" label="Runtime">
<UInput v-model="disabledState.runtime" class="w-full" />
</UFormField>
<UButton type="submit" icon="i-material-symbols-block">
Submit (disabled)
</UButton>
</UForm>
</GallerySection>
<!-- FormField orientations -->
<GallerySection title="Field orientations">
<div class="w-full max-w-lg space-y-4">
<UFormField
name="trace-id"
label="Trace ID"
description="Unique identifier for this trace span"
orientation="vertical"
hint="vertical"
>
<UInput placeholder="trace-abc123" icon="i-material-symbols-timeline" class="w-full" />
</UFormField>
<UFormField
name="event-source"
label="Event source"
description="Origin of the runtime event"
orientation="horizontal"
hint="horizontal"
>
<UInput placeholder="runtime.scheduler" class="w-full" />
</UFormField>
</div>
</GallerySection>
<!-- FormField sizes -->
<GallerySection title="Field sizes">
<div class="w-full max-w-lg space-y-4">
<UFormField v-for="s in ['sm', 'md', 'lg'] as const" :key="s" :size="s" :label="`Size ${s}`" :name="`size-${s}`">
<UInput :placeholder="`agent-id (${s})`" :size="s" class="w-full" />
</UFormField>
</div>
</GallerySection>
</div>
</template>