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}} <div class="ui icon search input"> <i class="icon">{{svg "octicon-search" 16}}</i> @@ -5,7 +6,7 @@ </div> <div class="divider"></div> {{end}} -<div class="no-select item" hx-post="{{$.RepoLink}}/issues/milestone?issue_ids={{$.Issue.ID}}&htmx=true">{{ctx.Locale.Tr "repo.issues.new.clear_milestone"}}</div> +<div class="no-select item"{{if $useHTMX}} hx-post="{{$.RepoLink}}/issues/milestone?issue_ids={{$.Issue.ID}}&htmx=true"{{end}}>{{ctx.Locale.Tr "repo.issues.new.clear_milestone"}}</div> {{if and (not .OpenMilestones) (not .ClosedMilestones)}} <div class="disabled item"> {{ctx.Locale.Tr "repo.issues.new.no_items"}} @@ -17,7 +18,7 @@ {{ctx.Locale.Tr "repo.issues.new.open_milestone"}} </div> {{range .OpenMilestones}} - <a class="item" hx-post="{{$.RepoLink}}/issues/milestone?id={{.ID}}&issue_ids={{$.Issue.ID}}&htmx=true"> + <a class="item"{{if $useHTMX}} hx-post="{{$.RepoLink}}/issues/milestone?id={{.ID}}&issue_ids={{$.Issue.ID}}&htmx=true"{{else}} data-id="{{.ID}}" data-href="{{$.RepoLink}}/issues?milestone={{.ID}}"{{end}}> {{svg "octicon-milestone" 16 "tw-mr-1"}} {{.Name}} </a> @@ -29,7 +30,7 @@ {{ctx.Locale.Tr "repo.issues.new.closed_milestone"}} </div> {{range .ClosedMilestones}} - <a class="item" hx-post="{{$.RepoLink}}/issues/milestone?id={{.ID}}&issue_ids={{$.Issue.ID}}&htmx=true"> + <a class="item"{{if $useHTMX}} hx-post="{{$.RepoLink}}/issues/milestone?id={{.ID}}&issue_ids={{$.Issue.ID}}&htmx=true"{{else}} data-id="{{.ID}}" data-href="{{$.RepoLink}}/issues?milestone={{.ID}}"{{end}}> {{svg "octicon-milestone" 16 "tw-mr-1"}} {{.Name}} </a> 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}} </span> <div class="menu"> - {{template "repo/issue/milestone/select_menu" .}} + {{template "repo/issue/milestone/select_menu" dict "." . "NewIssuePage" 1}} </div> </div> <div class="ui select-milestone list"> diff --git a/tests/e2e/issue-sidebar.test.e2e.js b/tests/e2e/issue-sidebar.test.e2e.js index 3bda7bdd17..0311910a34 100644 --- a/tests/e2e/issue-sidebar.test.e2e.js +++ b/tests/e2e/issue-sidebar.test.e2e.js @@ -119,3 +119,25 @@ test('Issue: Milestone', async ({browser}, workerInfo) => { await expect(selectedMilestone).toContainText('No milestone'); await expect(page.locator('.timeline-item.event').last()).toContainText('user2 removed this from the milestone1 milestone'); }); + +test('New Issue: Milestone', async ({browser}, workerInfo) => { + test.skip(workerInfo.project.name === 'Mobile Safari', 'Unable to get tests working on Safari Mobile, see https://codeberg.org/forgejo/forgejo/pulls/3445#issuecomment-1789636'); + const page = await login({browser}, workerInfo); + + const response = await page.goto('/user2/repo1/issues/new'); + await expect(response?.status()).toBe(200); + + const selectedMilestone = page.locator('.issue-content-right .select-milestone.list'); + const milestoneDropdown = page.locator('.issue-content-right .select-milestone.dropdown'); + await expect(selectedMilestone).toContainText('No milestone'); + + // Add milestone. + await milestoneDropdown.click(); + await page.getByRole('option', {name: 'milestone1'}).click(); + await expect(selectedMilestone).toContainText('milestone1'); + + // Clear milestone. + await milestoneDropdown.click(); + await page.getByText('Clear milestone', {exact: true}).click(); + await expect(selectedMilestone).toContainText('No milestone'); +}); diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index d9aa881127..b25fc28dea 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -270,7 +270,9 @@ export function initRepoCommentForm() { } let icon = ''; - if (input_id === '#project_id') { + if (input_id === '#milestone_id') { + icon = svg('octicon-milestone', 18, 'tw-mr-2'); + } else if (input_id === '#project_id') { icon = svg('octicon-project', 18, 'tw-mr-2'); } else if (input_id === '#assignee_id') { icon = `<img class="ui avatar image tw-mr-2" alt="avatar" src=${$(this).data('avatar')}>`; @@ -311,6 +313,7 @@ export function initRepoCommentForm() { // Milestone, Assignee, Project selectItem('.select-project', '#project_id'); + selectItem('.select-milestone', '#milestone_id'); selectItem('.select-assignee', '#assignee_id'); }