fix: fix add custom step error

This commit is contained in:
Tiger Ren 2026-02-01 19:46:47 +08:00
parent d05edeba5a
commit 8f6cad6365
1 changed files with 4 additions and 4 deletions

View File

@ -60,7 +60,7 @@ export function AddCustomStepDialog({
const [name, setName] = useState(''); const [name, setName] = useState('');
const [type, setType] = useState<'bash' | 'sql' | 'text'>('bash'); const [type, setType] = useState<'bash' | 'sql' | 'text'>('bash');
const [content, setContent] = useState(''); const [content, setContent] = useState('');
const [insertAfterId, setInsertAfterId] = useState<string>(''); const [insertAfterId, setInsertAfterId] = useState<string>('__start__');
const [addToTemplate, setAddToTemplate] = useState(false); const [addToTemplate, setAddToTemplate] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false);
@ -76,7 +76,7 @@ export function AddCustomStepDialog({
// Calculate orderIndex based on insert position // Calculate orderIndex based on insert position
let orderIndex = existingSteps.length; let orderIndex = existingSteps.length;
if (insertAfterId) { if (insertAfterId && insertAfterId !== '__start__') {
const afterStep = existingSteps.find(s => s.id.toString() === insertAfterId); const afterStep = existingSteps.find(s => s.id.toString() === insertAfterId);
if (afterStep) { if (afterStep) {
// Use decimal to insert between (e.g., if after step with index 1, use 1.5) // Use decimal to insert between (e.g., if after step with index 1, use 1.5)
@ -87,7 +87,7 @@ export function AddCustomStepDialog({
orderIndex = afterStep.orderIndex + 1; orderIndex = afterStep.orderIndex + 1;
} }
} }
} else if (existingSteps.length > 0) { } else if (insertAfterId === '__start__' && existingSteps.length > 0) {
// Insert at beginning - use negative decimal or 0.5 before first // Insert at beginning - use negative decimal or 0.5 before first
const firstStep = existingSteps[0]; const firstStep = existingSteps[0];
orderIndex = firstStep.orderIndex / 2; orderIndex = firstStep.orderIndex / 2;
@ -170,7 +170,7 @@ export function AddCustomStepDialog({
<SelectValue placeholder="At the beginning" /> <SelectValue placeholder="At the beginning" />
</SelectTrigger> </SelectTrigger>
<SelectContent> <SelectContent>
<SelectItem value="">At the beginning</SelectItem> <SelectItem value="__start__">At the beginning</SelectItem>
{existingSteps.map((step) => ( {existingSteps.map((step) => (
<SelectItem key={step.id} value={step.id.toString()}> <SelectItem key={step.id} value={step.id.toString()}>
After: {step.name} After: {step.name}