New attempts should default to same settings as previous attempts (vibe-kanban) (#103)

* Perfect! The implementation is complete and working. Let me create a quick summary of what was implemented:

## Summary

I've successfully implemented the feature to default new attempts to the same settings as previous attempts. Here's what was added:

### Key Changes

1. **Added automatic default value updates** - When taskAttempts change, the component now automatically updates the default branch and executor based on the most recent attempt.

2. **Enhanced create attempt mode** - When entering create attempt mode, the component now uses the latest attempt's settings as defaults instead of the current selected values.

3. **Branch availability check** - The implementation verifies that the previous attempt's branch still exists before defaulting to it.

4. **Executor availability check** - The implementation verifies that the previous attempt's executor still exists in the available executors before defaulting to it.

### How it works:

- When a user creates a new attempt, the form will automatically:
  - Use the **same branch** as the most recent attempt (if it still exists)
  - Use the **same executor** as the most recent attempt (if it still exists)
  - Fall back to current selected values if previous settings are not available
  - Allow users to override both settings before creating the attempt

The implementation ensures backward compatibility and graceful fallbacks when previous settings are no longer available, while providing the convenience of defaulting to the most recently used settings.

* Perfect! The formatting issues have been fixed. The `npm run format` command automatically reformatted the `TaskDetailsToolbar.tsx` file to match the project's Prettier configuration, and now all files pass the format check.
This commit is contained in:
Louis Knight-Webb
2025-07-08 17:43:00 +01:00
committed by GitHub
parent 4275e2dea7
commit 76d03564ad

View File

@@ -148,6 +148,33 @@ export function TaskDetailsToolbar({
setIsInCreateAttemptMode(taskAttempts.length === 0);
}, [taskAttempts.length]);
// Update default values from latest attempt when taskAttempts change
useEffect(() => {
if (taskAttempts.length > 0) {
const latestAttempt = taskAttempts.reduce((latest, current) =>
new Date(current.created_at) > new Date(latest.created_at)
? current
: latest
);
// Only update if branch still exists in available branches
if (
latestAttempt.base_branch &&
branches.some((b: GitBranch) => b.name === latestAttempt.base_branch)
) {
setCreateAttemptBranch(latestAttempt.base_branch);
}
// Only update executor if it's different from default and exists in available executors
if (
latestAttempt.executor &&
availableExecutors.some((e) => e.id === latestAttempt.executor)
) {
setCreateAttemptExecutor(latestAttempt.executor);
}
}
}, [taskAttempts, branches, availableExecutors]);
// Update PR base branch when selected attempt changes
useEffect(() => {
if (selectedAttempt?.base_branch) {
@@ -349,8 +376,39 @@ export function TaskDetailsToolbar({
// Handle entering create attempt mode
const handleEnterCreateAttemptMode = () => {
setIsInCreateAttemptMode(true);
setCreateAttemptBranch(selectedBranch);
setCreateAttemptExecutor(selectedExecutor);
// Use latest attempt's settings as defaults if available
if (taskAttempts.length > 0) {
const latestAttempt = taskAttempts.reduce((latest, current) =>
new Date(current.created_at) > new Date(latest.created_at)
? current
: latest
);
// Use latest attempt's branch if it still exists, otherwise use current selected branch
if (
latestAttempt.base_branch &&
branches.some((b: GitBranch) => b.name === latestAttempt.base_branch)
) {
setCreateAttemptBranch(latestAttempt.base_branch);
} else {
setCreateAttemptBranch(selectedBranch);
}
// Use latest attempt's executor if it exists, otherwise use current selected executor
if (
latestAttempt.executor &&
availableExecutors.some((e) => e.id === latestAttempt.executor)
) {
setCreateAttemptExecutor(latestAttempt.executor);
} else {
setCreateAttemptExecutor(selectedExecutor);
}
} else {
// Fallback to current selected values if no attempts exist
setCreateAttemptBranch(selectedBranch);
setCreateAttemptExecutor(selectedExecutor);
}
};
// Handle exiting create attempt mode