From 1e54e211ca25eee308f0773213d26855330f2e94 Mon Sep 17 00:00:00 2001 From: Sai Nane Date: Wed, 4 Sep 2024 03:07:23 +0000 Subject: [PATCH] Fix milestone assignment in New Issue Avoids the use of HTMX on milestone assignment within a New Issue form. The New Issue form doesn't have an issue ID to send to a milestone change URL, which the backend expects in order to construct a proper reply. The frontend template was also not built to use the new HTMX response. This resulted in a backend error and a large warning whenever anyone tried to set a milestone from within the New Issue form (new pull requests were also affected), rather than from a View Issue page. This introduces a new parameter into the `issue/milestone/select_menu` template, "NewIssuePage". When unset, the template produces the same results as before. Selection uses `hx-post` to notify the server immediately, using the updated htmx fragment from the reply. When set to a truthy value, the old style of form is used. Selection uses `data-id` and `data-href` to update the selected milestone locally, via `selectItem` in `repo-legacy.js`, recreating the selected element and updating the hidden form value. Fixes #5176. --- templates/repo/issue/milestone/select_menu.tmpl | 7 ++++--- templates/repo/issue/new_form.tmpl | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/templates/repo/issue/milestone/select_menu.tmpl b/templates/repo/issue/milestone/select_menu.tmpl index eae2f3baa9..570acc2eee 100644 --- a/templates/repo/issue/milestone/select_menu.tmpl +++ b/templates/repo/issue/milestone/select_menu.tmpl @@ -1,3 +1,4 @@ +{{$useHTMX := not .NewIssuePage}} {{if or .OpenMilestones .ClosedMilestones}}
{{end}} -
{{ctx.Locale.Tr "repo.issues.new.clear_milestone"}}
+
{{ctx.Locale.Tr "repo.issues.new.clear_milestone"}}
{{if and (not .OpenMilestones) (not .ClosedMilestones)}}
{{ctx.Locale.Tr "repo.issues.new.no_items"}} @@ -17,7 +18,7 @@ {{ctx.Locale.Tr "repo.issues.new.open_milestone"}}
{{range .OpenMilestones}} - + {{svg "octicon-milestone" 16 "tw-mr-1"}} {{.Name}} @@ -29,7 +30,7 @@ {{ctx.Locale.Tr "repo.issues.new.closed_milestone"}} {{range .ClosedMilestones}} - + {{svg "octicon-milestone" 16 "tw-mr-1"}} {{.Name}} diff --git a/templates/repo/issue/new_form.tmpl b/templates/repo/issue/new_form.tmpl index 465cb44f6f..fe10c1f9b9 100644 --- a/templates/repo/issue/new_form.tmpl +++ b/templates/repo/issue/new_form.tmpl @@ -64,7 +64,7 @@ {{end}}