Skip to content

Commit ac9241b

Browse files
committed
fine tune and improve comments
1 parent 0169fd3 commit ac9241b

File tree

4 files changed

+18
-25
lines changed

4 files changed

+18
-25
lines changed

routers/web/repo/issue.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ type issueSidebarLabelsData struct {
881881
SelectedLabelIDs string
882882
}
883883

884-
func findSelectedIDs[KeyType, ItemType comparable](
884+
func makeSelectedStringIDs[KeyType, ItemType comparable](
885885
allLabels []*issues_model.Label, candidateKey func(candidate *issues_model.Label) KeyType,
886886
selectedItems []ItemType, selectedKey func(selected ItemType) KeyType,
887887
) string {
@@ -902,29 +902,23 @@ func findSelectedIDs[KeyType, ItemType comparable](
902902
}
903903

904904
func (d *issueSidebarLabelsData) SetSelectedLabels(labels []*issues_model.Label) {
905-
d.SelectedLabelIDs = findSelectedIDs(
906-
d.AllLabels,
907-
func(label *issues_model.Label) int64 { return label.ID },
908-
labels,
909-
func(label *issues_model.Label) int64 { return label.ID },
905+
d.SelectedLabelIDs = makeSelectedStringIDs(
906+
d.AllLabels, func(label *issues_model.Label) int64 { return label.ID },
907+
labels, func(label *issues_model.Label) int64 { return label.ID },
910908
)
911909
}
912910

913911
func (d *issueSidebarLabelsData) SetSelectedLabelNames(labelNames []string) {
914-
d.SelectedLabelIDs = findSelectedIDs(
915-
d.AllLabels,
916-
func(label *issues_model.Label) string { return strings.ToLower(label.Name) },
917-
labelNames,
918-
strings.ToLower,
912+
d.SelectedLabelIDs = makeSelectedStringIDs(
913+
d.AllLabels, func(label *issues_model.Label) string { return strings.ToLower(label.Name) },
914+
labelNames, strings.ToLower,
919915
)
920916
}
921917

922918
func (d *issueSidebarLabelsData) SetSelectedLabelIDs(labelIDs []int64) {
923-
d.SelectedLabelIDs = findSelectedIDs(
924-
d.AllLabels,
925-
func(label *issues_model.Label) int64 { return label.ID },
926-
labelIDs,
927-
func(labelID int64) int64 { return labelID },
919+
d.SelectedLabelIDs = makeSelectedStringIDs(
920+
d.AllLabels, func(label *issues_model.Label) int64 { return label.ID },
921+
labelIDs, func(labelID int64) int64 { return labelID },
928922
)
929923
}
930924

routers/web/repo/issue_label.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func InitializeLabels(ctx *context.Context) {
5353
ctx.Redirect(ctx.Repo.RepoLink + "/labels")
5454
}
5555

56-
// RetrieveLabelsForList find all the labels of a repository and organization
56+
// RetrieveLabelsForList find all the labels of a repository and organization, it is only used by "/labels" page to list all labels
5757
func RetrieveLabelsForList(ctx *context.Context) {
5858
labels, err := issues_model.GetLabelsByRepoID(ctx, ctx.Repo.Repository.ID, ctx.FormString("sort"), db.ListOptions{})
5959
if err != nil {

templates/repo/issue/new_form.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<div class="issue-content-right ui segment">
5050
{{template "repo/issue/branch_selector_field" $}}
5151
{{if .PageIsComparePull}}
52-
{{template "repo/issue/sidebar/reviewer_list" dict "IssueSidebarReviewersData" $.IssueSidebarReviewersData}}
52+
{{template "repo/issue/sidebar/reviewer_list" $.IssueSidebarReviewersData}}
5353
<div class="divider"></div>
5454
{{end}}
5555

web_src/js/features/repo-issue-sidebar-combolist.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function initIssueSidebarComboList(container: HTMLElement) {
3131
const elDropdown = container.querySelector<HTMLElement>(':scope > .ui.dropdown');
3232
const elList = container.querySelector<HTMLElement>(':scope > .ui.list');
3333
const elComboValue = container.querySelector<HTMLInputElement>(':scope > .combo-value');
34-
const initialValues = collectCheckedValues(elDropdown);
34+
let initialValues = collectCheckedValues(elDropdown);
3535

3636
elDropdown.addEventListener('click', (e) => {
3737
const elItem = (e.target as HTMLElement).closest('.item');
@@ -78,7 +78,7 @@ export function initIssueSidebarComboList(container: HTMLElement) {
7878
if (changed) issueSidebarReloadConfirmDraftComment();
7979
};
8080

81-
const syncList = (changedValues) => {
81+
const syncUiList = (changedValues) => {
8282
const elEmptyTip = elList.querySelector('.item.empty-list');
8383
queryElemChildren(elList, '.item:not(.empty-list)', (el) => el.remove());
8484
for (const value of changedValues) {
@@ -95,12 +95,11 @@ export function initIssueSidebarComboList(container: HTMLElement) {
9595
action: 'nothing', // do not hide the menu if user presses Enter
9696
fullTextSearch: 'exact',
9797
async onHide() {
98+
// TODO: support "Esc" to cancel the selection. Use partial page loading to avoid losing inputs.
9899
const changedValues = collectCheckedValues(elDropdown);
99-
if (updateUrl) {
100-
await updateToBackend(changedValues); // send requests to backend and reload the page
101-
} else {
102-
syncList(changedValues); // only update the list in the sidebar
103-
}
100+
syncUiList(changedValues);
101+
if (updateUrl) await updateToBackend(changedValues);
102+
initialValues = changedValues;
104103
},
105104
});
106105
}

0 commit comments

Comments
 (0)