From 8a4382b7b3d0225d6d2f7286d66b972df92aa3b8 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 21 Feb 2023 00:28:12 +0800 Subject: [PATCH 1/6] improve --- templates/repo/issue/view_content/sidebar.tmpl | 2 +- web_src/js/features/aria.js | 3 ++- web_src/js/features/repo-legacy.js | 15 ++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/templates/repo/issue/view_content/sidebar.tmpl b/templates/repo/issue/view_content/sidebar.tmpl index 2b24825b5f7bd..d9c506243705f 100644 --- a/templates/repo/issue/view_content/sidebar.tmpl +++ b/templates/repo/issue/view_content/sidebar.tmpl @@ -121,7 +121,7 @@ {{end}} -
{{.locale.Tr "repo.issues.new.clear_labels"}}
+ {{.locale.Tr "repo.issues.new.clear_labels"}} {{if or .Labels .OrgLabels}} {{$previousExclusiveScope := "_no_scope"}} {{range .Labels}} diff --git a/web_src/js/features/aria.js b/web_src/js/features/aria.js index a5ac84e4464c5..373d667c5f73c 100644 --- a/web_src/js/features/aria.js +++ b/web_src/js/features/aria.js @@ -81,7 +81,8 @@ function attachOneDropdownAria($dropdown) { $dropdown.on('keydown', (e) => { // here it must use keydown event before dropdown's keyup handler, otherwise there is no Enter event in our keyup handler if (e.key === 'Enter') { - const $item = $dropdown.dropdown('get item', $dropdown.dropdown('get value')); + let $item = $dropdown.dropdown('get item', $dropdown.dropdown('get value')); + if (!$item) $item = $menu.find('> .item.selected'); // when dropdown filters items by input, there is no "value", so query the "selected" item // if the selected item is clickable, then trigger the click event. in the future there could be a special CSS class for it. if ($item && $item.is('a')) $item[0].click(); } diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index e1dc51432051b..9b72250b43cad 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -86,11 +86,12 @@ export function initRepoCommentForm() { let hasUpdateAction = $listMenu.data('action') === 'update'; const items = {}; - $(`.${selector}`).dropdown('setting', 'onHide', () => { - hasUpdateAction = $listMenu.data('action') === 'update'; // Update the var - if (hasUpdateAction) { - // TODO: Add batch functionality and make this 1 network request. - (async function() { + $(`.${selector}`).dropdown({ + 'action': 'nothing', // do not hide the menu if user presses Enter + async onHide() { + hasUpdateAction = $listMenu.data('action') === 'update'; // Update the var + if (hasUpdateAction) { + // TODO: Add batch functionality and make this 1 network request. for (const [elementId, item] of Object.entries(items)) { await updateIssuesMeta( item['update-url'], @@ -100,8 +101,8 @@ export function initRepoCommentForm() { ); } window.location.reload(); - })(); - } + } + }, }); $listMenu.find('.item:not(.no-select)').on('click', function (e) { From 649fa2d2ed7fffa696602d619d8be55b416aae99 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 21 Feb 2023 02:05:38 +0800 Subject: [PATCH 2/6] Update web_src/js/features/repo-legacy.js Co-authored-by: Brecht Van Lommel --- web_src/js/features/repo-legacy.js | 1 + 1 file changed, 1 insertion(+) diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 9b72250b43cad..77839ceb2edfd 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -88,6 +88,7 @@ export function initRepoCommentForm() { $(`.${selector}`).dropdown({ 'action': 'nothing', // do not hide the menu if user presses Enter + fullTextSearch: 'exact', async onHide() { hasUpdateAction = $listMenu.data('action') === 'update'; // Update the var if (hasUpdateAction) { From 8668a88f9295237c1b4b5ad7ad6215599f8e92a3 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Tue, 21 Feb 2023 13:33:10 +0800 Subject: [PATCH 3/6] fix comment actions and menus --- templates/repo/issue/view_content/add_reaction.tmpl | 2 +- templates/repo/issue/view_content/context_menu.tmpl | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/repo/issue/view_content/add_reaction.tmpl b/templates/repo/issue/view_content/add_reaction.tmpl index 9bd9022d28abf..bfa8a7e122349 100644 --- a/templates/repo/issue/view_content/add_reaction.tmpl +++ b/templates/repo/issue/view_content/add_reaction.tmpl @@ -7,7 +7,7 @@
{{.ctx.locale.Tr "repo.pick_reaction"}}
{{range $value := AllowedReactions}} -
{{ReactionToEmoji $value}}
+ {{ReactionToEmoji $value}} {{end}} diff --git a/templates/repo/issue/view_content/context_menu.tmpl b/templates/repo/issue/view_content/context_menu.tmpl index b96fd86af5d00..b4b9403b2af74 100644 --- a/templates/repo/issue/view_content/context_menu.tmpl +++ b/templates/repo/issue/view_content/context_menu.tmpl @@ -10,16 +10,16 @@ {{else}} {{$referenceUrl = Printf "%s/files#%s" .ctx.Issue.Link .item.HashTag}} {{end}} -
{{.ctx.locale.Tr "repo.issues.context.copy_link"}}
-
{{.ctx.locale.Tr "repo.issues.context.quote_reply"}}
+ {{.ctx.locale.Tr "repo.issues.context.copy_link"}} + {{.ctx.locale.Tr "repo.issues.context.quote_reply"}} {{if not .ctx.UnitIssuesGlobalDisabled}} -
{{.ctx.locale.Tr "repo.issues.context.reference_issue"}}
+ {{.ctx.locale.Tr "repo.issues.context.reference_issue"}} {{end}} {{if or .ctx.Permission.IsAdmin .IsCommentPoster .ctx.HasIssuesOrPullsWritePermission}}
-
{{.ctx.locale.Tr "repo.issues.context.edit"}}
+ {{.ctx.locale.Tr "repo.issues.context.edit"}} {{if .delete}} -
{{.ctx.locale.Tr "repo.issues.context.delete"}}
+ {{.ctx.locale.Tr "repo.issues.context.delete"}} {{end}} {{end}} From 1bd96d326eeccbfe3957dadd696920d446d08672 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 22 Feb 2023 13:49:39 +0800 Subject: [PATCH 4/6] do not reload window when there is no change --- web_src/js/features/repo-legacy.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index f2cab2c3d06ef..1d1215e5da2a6 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -93,7 +93,8 @@ export function initRepoCommentForm() { hasUpdateAction = $listMenu.data('action') === 'update'; // Update the var if (hasUpdateAction) { // TODO: Add batch functionality and make this 1 network request. - for (const [elementId, item] of Object.entries(items)) { + const itemEntries = Object.entries(items); + for (const [elementId, item] of itemEntries) { await updateIssuesMeta( item['update-url'], item.action, @@ -101,7 +102,9 @@ export function initRepoCommentForm() { elementId, ); } - window.location.reload(); + if (itemEntries.length) { + window.location.reload(); + } } }, }); From d263120e47b6787f8d763d9a603ad5352487ce79 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 22 Feb 2023 14:11:30 +0800 Subject: [PATCH 5/6] reloadConfirmDraftComment --- web_src/js/features/repo-legacy.js | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index 1d1215e5da2a6..e7c12cfd59d88 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -29,6 +29,24 @@ import {hideElem, showElem} from '../utils/dom.js'; const {csrfToken} = window.config; +// if there are draft comments (more than 20 chars), confirm before reloading, to avoid losing comments +function reloadConfirmDraftComment() { + const commentTextareas = [ + document.querySelector('.edit-content-zone:not(.gt-hidden) textarea'), + document.querySelector('.edit_area'), + ]; + for (const textarea of commentTextareas) { + if (textarea && textarea.value.trim().length > 20) { + textarea.parentElement.scrollIntoView(); + if (!window.confirm('Page will be reloaded, but there are draft comments. Continuing to reload will discard the comments. Continue?')) { + return; + } + break; + } + } + window.location.reload(); +} + export function initRepoCommentForm() { const $commentForm = $('.comment.form'); if ($commentForm.length === 0) { @@ -103,7 +121,7 @@ export function initRepoCommentForm() { ); } if (itemEntries.length) { - window.location.reload(); + reloadConfirmDraftComment(); } } }, @@ -201,7 +219,7 @@ export function initRepoCommentForm() { 'clear', $listMenu.data('issue-id'), '', - ).then(() => window.location.reload()); + ).then(reloadConfirmDraftComment); } $(this).parent().find('.item').each(function () { @@ -244,7 +262,7 @@ export function initRepoCommentForm() { '', $menu.data('issue-id'), $(this).data('id'), - ).then(() => window.location.reload()); + ).then(reloadConfirmDraftComment); } let icon = ''; @@ -277,7 +295,7 @@ export function initRepoCommentForm() { '', $menu.data('issue-id'), $(this).data('id'), - ).then(() => window.location.reload()); + ).then(reloadConfirmDraftComment); } $list.find('.selected').html(''); From afef2c4ea9fedca0d35db8ee1aa4c1f0a8b54419 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 23 Feb 2023 16:36:03 +0800 Subject: [PATCH 6/6] Update repo-legacy.js --- web_src/js/features/repo-legacy.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/web_src/js/features/repo-legacy.js b/web_src/js/features/repo-legacy.js index e7c12cfd59d88..a9229c0d1e6f5 100644 --- a/web_src/js/features/repo-legacy.js +++ b/web_src/js/features/repo-legacy.js @@ -36,6 +36,8 @@ function reloadConfirmDraftComment() { document.querySelector('.edit_area'), ]; for (const textarea of commentTextareas) { + // Most users won't feel too sad if they lose a comment with 10 or 20 chars, they can re-type these in seconds. + // But if they have typed more (like 50) chars and the comment is lost, they will be very unhappy. if (textarea && textarea.value.trim().length > 20) { textarea.parentElement.scrollIntoView(); if (!window.confirm('Page will be reloaded, but there are draft comments. Continuing to reload will discard the comments. Continue?')) {