-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathEditWorkflowModal.tsx
More file actions
229 lines (216 loc) · 8.83 KB
/
EditWorkflowModal.tsx
File metadata and controls
229 lines (216 loc) · 8.83 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
220
221
222
223
224
225
226
227
228
229
/**
* Modal dialog for editing an existing scheduled workflow.
* Focused on editable fields only — schedule, workflow kind, and custom prompt.
*/
import { useState } from 'react'
import { IconX, IconLoader2 } from '@tabler/icons-react'
import type { ReviewRepoConfig } from '../lib/workflowApi'
import {
WORKFLOW_KINDS, DAY_PRESETS, DAY_INDIVIDUAL, MODEL_OPTIONS, isBiweeklyDow,
buildCron, parseCron, describeCron, kindLabel,
} from '../lib/workflowHelpers'
import { CategoryBadge } from './WorkflowBadges'
import TimePicker from './TimePicker'
const btnClass = (selected: boolean) =>
`rounded-md border px-3 py-1.5 text-[13px] font-medium transition-colors ${
selected
? 'border-accent-6 bg-accent-9/40 text-accent-2'
: 'border-neutral-7 bg-neutral-10 text-neutral-3 hover:border-neutral-6 hover:text-neutral-2'
}`
interface Props {
repo: ReviewRepoConfig
schedules?: unknown[]
recentRuns?: unknown[]
onClose: () => void
onSave: (id: string, patch: Partial<ReviewRepoConfig>) => Promise<void>
}
export function EditWorkflowModal({ repo, onClose, onSave }: Props) {
const parsed = parseCron(repo.cronExpression)
const [form, setForm] = useState({
kind: repo.kind ?? 'coverage.daily',
cronHour: parsed.hour,
cronMinute: parsed.minute,
cronDow: parsed.dow,
customPrompt: repo.customPrompt ?? '',
model: repo.model ?? '',
})
const [saving, setSaving] = useState(false)
const [formError, setFormError] = useState<string | null>(null)
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setSaving(true)
setFormError(null)
try {
await onSave(repo.id, {
kind: form.kind,
cronExpression: buildCron(form.cronHour, form.cronDow, form.cronMinute),
customPrompt: form.customPrompt.trim() || undefined,
model: form.model || undefined,
})
onClose()
} catch (err) {
setFormError(err instanceof Error ? err.message : 'Failed to save workflow')
} finally {
setSaving(false)
}
}
const repoShortName = repo.repoPath.split('/').pop() || repo.name
const biweekly = isBiweeklyDow(form.cronDow)
const baseDow = biweekly ? form.cronDow.split('-').slice(1).join('-') : form.cronDow
const isDay = DAY_INDIVIDUAL.some(d => d.dow === baseDow)
return (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60" onClick={onClose}>
<div
className="w-[480px] max-h-[90vh] overflow-y-auto rounded-xl border border-neutral-7 bg-neutral-11 p-6 shadow-2xl"
onClick={e => e.stopPropagation()}
>
{/* Header */}
<div className="flex items-center justify-between mb-5">
<div>
<h2 className="text-[19px] font-semibold text-neutral-1">Edit Workflow</h2>
<div className="flex items-center gap-2 mt-1">
<span className="text-[13px] text-neutral-4">{repoShortName}</span>
<span className="text-neutral-7">·</span>
<span className="text-[13px] text-neutral-4">{kindLabel(repo.kind ?? '')}</span>
</div>
</div>
<button onClick={onClose} className="rounded p-1 text-neutral-4 hover:text-neutral-1 hover:bg-neutral-9">
<IconX size={16} stroke={2} />
</button>
</div>
<form onSubmit={handleSubmit} className="space-y-5">
{/* Workflow kind */}
<div>
<div className="flex items-center justify-between mb-2">
<label className="text-[13px] font-medium text-neutral-3">Workflow type</label>
<CategoryBadge kind={form.kind} />
</div>
<div className="grid grid-cols-2 gap-2">
{WORKFLOW_KINDS.map(k => (
<button
key={k.value}
type="button"
onClick={() => setForm(f => ({ ...f, kind: k.value }))}
className={`rounded-lg border px-3 py-2.5 text-left transition-colors ${
form.kind === k.value
? 'border-accent-6 bg-accent-9/30 ring-1 ring-accent-6/30'
: 'border-neutral-7 bg-neutral-10 hover:border-neutral-6'
}`}
>
<span className={`block text-[15px] font-medium ${
form.kind === k.value ? 'text-accent-2' : 'text-neutral-2'
}`}>
{k.label}
</span>
</button>
))}
</div>
</div>
{/* Schedule */}
<div>
<label className="block text-[13px] font-medium text-neutral-3 mb-2">Time</label>
<TimePicker
hour={form.cronHour}
minute={form.cronMinute}
onChange={(h, m) => setForm(f => ({ ...f, cronHour: h, cronMinute: m }))}
className="mb-3"
/>
<label className="block text-[13px] font-medium text-neutral-3 mb-2">Frequency</label>
<div className="flex flex-wrap gap-1.5 mb-2">
{DAY_PRESETS.map(p => (
<button
key={p.dow}
type="button"
onClick={() => setForm(f => ({ ...f, cronDow: p.dow }))}
className={btnClass(form.cronDow === p.dow)}
>
{p.label}
</button>
))}
</div>
<div className="flex gap-1.5">
{DAY_INDIVIDUAL.map(p => (
<button
key={p.dow}
type="button"
onClick={() => setForm(f => ({ ...f, cronDow: biweekly ? `biweekly-${p.dow}` : p.dow }))}
className={btnClass(baseDow === p.dow)}
>
{p.label}
</button>
))}
</div>
{isDay && (
<div className="flex gap-1.5 mt-2">
<button type="button" onClick={() => setForm(f => ({ ...f, cronDow: baseDow }))} className={btnClass(!biweekly)}>
Every week
</button>
<button type="button" onClick={() => setForm(f => ({ ...f, cronDow: `biweekly-${baseDow}` }))} className={btnClass(biweekly)}>
Every 2 weeks
</button>
</div>
)}
<div className="mt-2 text-[13px] text-neutral-5">
{describeCron(buildCron(form.cronHour, form.cronDow, form.cronMinute))}
</div>
</div>
{/* Model selection */}
<div>
<label className="block text-[13px] font-medium text-neutral-3 mb-2">Model</label>
<div className="flex gap-1.5">
{MODEL_OPTIONS.map(m => (
<button
key={m.value}
type="button"
onClick={() => setForm(f => ({ ...f, model: m.value }))}
className={btnClass(form.model === m.value)}
>
{m.label}
</button>
))}
</div>
</div>
{/* Custom prompt */}
<div>
<label className="block text-[13px] font-medium text-neutral-3 mb-1.5">
Focus areas <span className="text-neutral-5 font-normal">(optional)</span>
</label>
<textarea
value={form.customPrompt}
onChange={e => setForm(f => ({ ...f, customPrompt: e.target.value }))}
rows={3}
placeholder="e.g. Focus on the auth module and payment flows"
className="w-full rounded-md border border-neutral-7 bg-neutral-10 px-3 py-2 text-[15px] text-neutral-1 placeholder-neutral-5 focus:border-accent-6 focus:outline-none resize-none"
/>
</div>
{formError && (
<div className="rounded-md bg-error-10/50 px-3 py-2 text-[13px] text-error-4">{formError}</div>
)}
<div className="flex gap-2 pt-2 border-t border-neutral-8/50">
<button
type="button"
onClick={onClose}
className="flex-1 rounded-md border border-neutral-7 bg-neutral-10 py-2 text-[15px] text-neutral-3 hover:bg-neutral-9 hover:text-neutral-1 transition-colors"
>
Cancel
</button>
<button
type="submit"
disabled={saving}
className="flex-1 rounded-md bg-primary-8 py-2 text-[15px] font-medium text-neutral-1 hover:bg-primary-7 disabled:opacity-50 transition-colors flex items-center justify-center gap-1.5"
>
{saving ? (
<>
<IconLoader2 size={14} stroke={2} className="animate-spin" />
Saving…
</>
) : (
'Save Changes'
)}
</button>
</div>
</form>
</div>
</div>
)
}