Skip to content

Commit d7d4641

Browse files
authored
Merge pull request #1203 from Kiln-AI/KIL-506/task-warn
Only warn before leaving edit task if unsaved changes
2 parents 7e69056 + 6e0496c commit d7d4641

File tree

2 files changed

+55
-4
lines changed

2 files changed

+55
-4
lines changed

.config/wt/start.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ export VITE_API_PORT="$PORT"
2525
export KILN_WEB_URL="http://localhost:$KILN_FRONTEND_PORT"
2626

2727
export KILN_CODER_CMD="claude"
28+
# user_settings.sh is gitignored, so in worktrees we fall back to the main repo copy
29+
MAIN_REPO_ROOT="$(git -C "$REPO_ROOT" rev-parse --path-format=absolute --git-common-dir 2>/dev/null | sed 's|/\.git$||')"
2830
if [ -f "$REPO_ROOT/.config/wt/user_settings.sh" ]; then
2931
# shellcheck source=/dev/null
3032
source "$REPO_ROOT/.config/wt/user_settings.sh"
33+
elif [ -n "$MAIN_REPO_ROOT" ] && [ -f "$MAIN_REPO_ROOT/.config/wt/user_settings.sh" ]; then
34+
# shellcheck source=/dev/null
35+
source "$MAIN_REPO_ROOT/.config/wt/user_settings.sh"
3136
fi
3237

3338
export PATH="$REPO_ROOT/.config/wt/bin:$PATH"

app/web_ui/src/routes/(fullscreen)/setup/(setup)/create_task/edit_task.svelte

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,56 @@
4545
let error: KilnError | null = null
4646
let submitting = false
4747
export let saved: boolean = false
48-
// Warn before unload if there's any user input
48+
49+
// Track initial values to detect actual changes from the loaded state.
50+
// This prevents false "unsaved changes" warnings when opening an existing task.
51+
let initial_name: string
52+
let initial_description: string | null | undefined
53+
let initial_instruction: string
54+
let initial_thinking_instruction: string | null | undefined
55+
let initial_requirements: Array<{
56+
name: string | undefined
57+
instruction: string | undefined
58+
type: string | undefined
59+
priority: number | undefined
60+
}>
61+
62+
function reset_initial_values() {
63+
initial_name = task.name
64+
initial_description = task.description
65+
initial_instruction = task.instruction
66+
initial_thinking_instruction = task.thinking_instruction
67+
initial_requirements = task.requirements.map((r) => ({
68+
name: r.name,
69+
instruction: r.instruction,
70+
type: r.type,
71+
priority: r.priority,
72+
}))
73+
}
74+
reset_initial_values()
75+
76+
function requirements_changed(
77+
reqs: Task["requirements"],
78+
initial: typeof initial_requirements,
79+
): boolean {
80+
if (reqs.length !== initial.length) return true
81+
return reqs.some(
82+
(r, i) =>
83+
(r.name || "") !== (initial[i].name || "") ||
84+
(r.instruction || "") !== (initial[i].instruction || "") ||
85+
(r.type || "") !== (initial[i].type || "") ||
86+
r.priority !== initial[i].priority,
87+
)
88+
}
89+
90+
// Warn before unload only if there are actual changes from the initial state
4991
$: warn_before_unload =
50-
!saved &&
51-
([task.name, task.description, task.instruction].some((value) => !!value) ||
52-
task.requirements.some((req) => !!req.name || !!req.instruction))
92+
task.name !== initial_name ||
93+
(task.description || "") !== (initial_description || "") ||
94+
task.instruction !== initial_instruction ||
95+
(task.thinking_instruction || "") !==
96+
(initial_thinking_instruction || "") ||
97+
requirements_changed(task.requirements, initial_requirements)
5398
5499
// Allow explicitly setting project ID, or infer current project ID
55100
export let explicit_project_id: string | undefined = undefined
@@ -145,6 +190,7 @@
145190
current_task_rating_options: null,
146191
})
147192
saved = true
193+
reset_initial_values()
148194
149195
// reload the current task to make sure changes propagate throughout the UI
150196
// e.g. the rating options

0 commit comments

Comments
 (0)