Merge pull request 'Fix milestone assignment in new issue' (#5180) from esainane/forgejo:five-hundred-more into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5180
Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
Otto 2024-09-17 16:50:42 +00:00
commit a0c11f58dd
4 changed files with 31 additions and 5 deletions

View file

@ -1,3 +1,4 @@
{{$useHTMX := not .NewIssuePage}}
{{if or .OpenMilestones .ClosedMilestones}} {{if or .OpenMilestones .ClosedMilestones}}
<div class="ui icon search input"> <div class="ui icon search input">
<i class="icon">{{svg "octicon-search" 16}}</i> <i class="icon">{{svg "octicon-search" 16}}</i>
@ -5,7 +6,7 @@
</div> </div>
<div class="divider"></div> <div class="divider"></div>
{{end}} {{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)}} {{if and (not .OpenMilestones) (not .ClosedMilestones)}}
<div class="disabled item"> <div class="disabled item">
{{ctx.Locale.Tr "repo.issues.new.no_items"}} {{ctx.Locale.Tr "repo.issues.new.no_items"}}
@ -17,7 +18,7 @@
{{ctx.Locale.Tr "repo.issues.new.open_milestone"}} {{ctx.Locale.Tr "repo.issues.new.open_milestone"}}
</div> </div>
{{range .OpenMilestones}} {{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"}} {{svg "octicon-milestone" 16 "tw-mr-1"}}
{{.Name}} {{.Name}}
</a> </a>
@ -29,7 +30,7 @@
{{ctx.Locale.Tr "repo.issues.new.closed_milestone"}} {{ctx.Locale.Tr "repo.issues.new.closed_milestone"}}
</div> </div>
{{range .ClosedMilestones}} {{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"}} {{svg "octicon-milestone" 16 "tw-mr-1"}}
{{.Name}} {{.Name}}
</a> </a>

View file

@ -64,7 +64,7 @@
{{end}} {{end}}
</span> </span>
<div class="menu"> <div class="menu">
{{template "repo/issue/milestone/select_menu" .}} {{template "repo/issue/milestone/select_menu" dict "." . "NewIssuePage" 1}}
</div> </div>
</div> </div>
<div class="ui select-milestone list"> <div class="ui select-milestone list">

View file

@ -119,3 +119,25 @@ test('Issue: Milestone', async ({browser}, workerInfo) => {
await expect(selectedMilestone).toContainText('No milestone'); await expect(selectedMilestone).toContainText('No milestone');
await expect(page.locator('.timeline-item.event').last()).toContainText('user2 removed this from the milestone1 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');
});

View file

@ -270,7 +270,9 @@ export function initRepoCommentForm() {
} }
let icon = ''; 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'); icon = svg('octicon-project', 18, 'tw-mr-2');
} else if (input_id === '#assignee_id') { } else if (input_id === '#assignee_id') {
icon = `<img class="ui avatar image tw-mr-2" alt="avatar" src=${$(this).data('avatar')}>`; 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 // Milestone, Assignee, Project
selectItem('.select-project', '#project_id'); selectItem('.select-project', '#project_id');
selectItem('.select-milestone', '#milestone_id');
selectItem('.select-assignee', '#assignee_id'); selectItem('.select-assignee', '#assignee_id');
} }