Skip to content

Commit 43c1362

Browse files
authored
Deduplicate template code for label selection menu (#23431)
1 parent a04eeb2 commit 43c1362

File tree

3 files changed

+45
-87
lines changed

3 files changed

+45
-87
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<div class="ui {{if or (not .HasIssuesOrPullsWritePermission) .Repository.IsArchived}}disabled{{end}} floating jump select-label dropdown">
2+
<a class="text gt-df gt-ac muted">
3+
<strong>{{.locale.Tr "repo.issues.new.labels"}}</strong>
4+
{{if and .HasIssuesOrPullsWritePermission (not .Repository.IsArchived)}}
5+
{{svg "octicon-gear" 16 "gt-ml-2"}}
6+
{{end}}
7+
</a>
8+
<div class="filter menu" {{if .Issue}}data-action="update" data-issue-id="{{$.Issue.ID}}" data-update-url="{{$.RepoLink}}/issues/labels"{{else}}data-id="#label_ids"{{end}}>
9+
<div class="header" style="text-transform: none;font-size:16px;">{{.locale.Tr "repo.issues.new.add_labels_title"}}</div>
10+
{{if or .Labels .OrgLabels}}
11+
<div class="ui icon search input">
12+
<i class="icon gt-df gt-ac gt-jc">{{svg "octicon-search" 16}}</i>
13+
<input type="text" placeholder="{{.locale.Tr "repo.issues.filter_labels"}}">
14+
</div>
15+
{{end}}
16+
<a class="no-select item" href="#">{{.locale.Tr "repo.issues.new.clear_labels"}}</a>
17+
{{if or .Labels .OrgLabels}}
18+
{{$previousExclusiveScope := "_no_scope"}}
19+
{{range .Labels}}
20+
{{$exclusiveScope := .ExclusiveScope}}
21+
{{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
22+
<div class="ui divider"></div>
23+
{{end}}
24+
{{$previousExclusiveScope = $exclusiveScope}}
25+
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
26+
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}</a>
27+
{{end}}
28+
<div class="ui divider"></div>
29+
{{$previousExclusiveScope := "_no_scope"}}
30+
{{range .OrgLabels}}
31+
{{$exclusiveScope := .ExclusiveScope}}
32+
{{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
33+
<div class="ui divider"></div>
34+
{{end}}
35+
{{$previousExclusiveScope = $exclusiveScope}}
36+
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
37+
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}</a>
38+
{{end}}
39+
{{else}}
40+
<div class="header" style="text-transform: none;font-size:14px;">{{.locale.Tr "repo.issues.new.no_items"}}</div>
41+
{{end}}
42+
</div>
43+
</div>

templates/repo/issue/new_form.tmpl

+1-44
Original file line numberDiff line numberDiff line change
@@ -36,50 +36,7 @@
3636
{{template "repo/issue/branch_selector_field" .}}
3737

3838
<input id="label_ids" name="label_ids" type="hidden" value="{{.label_ids}}">
39-
<div class="ui {{if not .HasIssuesOrPullsWritePermission}}disabled{{end}} floating jump select-label dropdown">
40-
<span class="text">
41-
<strong>{{.locale.Tr "repo.issues.new.labels"}}</strong>
42-
{{if .HasIssuesOrPullsWritePermission}}
43-
{{svg "octicon-gear"}}
44-
{{end}}
45-
</span>
46-
<div class="filter menu" data-id="#label_ids">
47-
<div class="header" style="text-transform: none;font-size:16px;">{{.locale.Tr "repo.issues.new.add_labels_title"}}</div>
48-
{{if or .Labels .OrgLabels}}
49-
<div class="ui icon search input">
50-
<i class="icon gt-df gt-ac gt-jc">{{svg "octicon-search" 16}}</i>
51-
<input type="text" placeholder="{{.locale.Tr "repo.issues.filter_labels"}}">
52-
</div>
53-
{{end}}
54-
<div class="no-select item">{{.locale.Tr "repo.issues.new.clear_labels"}}</div>
55-
{{if or .Labels .OrgLabels}}
56-
{{$previousExclusiveScope := "_no_scope"}}
57-
{{range .Labels}}
58-
{{$exclusiveScope := .ExclusiveScope}}
59-
{{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
60-
<div class="ui divider"></div>
61-
{{end}}
62-
{{$previousExclusiveScope = $exclusiveScope}}
63-
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
64-
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}</a>
65-
{{end}}
66-
67-
<div class="ui divider"></div>
68-
{{$previousExclusiveScope := "_no_scope"}}
69-
{{range .OrgLabels}}
70-
{{$exclusiveScope := .ExclusiveScope}}
71-
{{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
72-
<div class="ui divider"></div>
73-
{{end}}
74-
{{$previousExclusiveScope = $exclusiveScope}}
75-
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
76-
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}</a>
77-
{{end}}
78-
{{else}}
79-
<div class="header" style="text-transform: none;font-size:14px;">{{.locale.Tr "repo.issues.new.no_items"}}</div>
80-
{{end}}
81-
</div>
82-
</div>
39+
{{template "repo/issue/labels/labels_selector_field" .}}
8340
{{template "repo/issue/labels/labels_sidebar" dict "root" $}}
8441

8542
<div class="ui divider"></div>

templates/repo/issue/view_content/sidebar.tmpl

+1-43
Original file line numberDiff line numberDiff line change
@@ -106,49 +106,7 @@
106106
<div class="ui divider"></div>
107107
{{end}}
108108

109-
<div class="ui {{if or (not .HasIssuesOrPullsWritePermission) .Repository.IsArchived}}disabled{{end}} floating jump select-label dropdown">
110-
<a class="text gt-df gt-ac muted">
111-
<strong>{{.locale.Tr "repo.issues.new.labels"}}</strong>
112-
{{if and .HasIssuesOrPullsWritePermission (not .Repository.IsArchived)}}
113-
{{svg "octicon-gear" 16 "gt-ml-2"}}
114-
{{end}}
115-
</a>
116-
<div class="filter menu" data-action="update" data-issue-id="{{$.Issue.ID}}" data-update-url="{{$.RepoLink}}/issues/labels">
117-
<div class="header" style="text-transform: none;font-size:16px;">{{.locale.Tr "repo.issues.new.add_labels_title"}}</div>
118-
{{if or .Labels .OrgLabels}}
119-
<div class="ui icon search input">
120-
<i class="icon gt-df gt-ac gt-jc">{{svg "octicon-search" 16}}</i>
121-
<input type="text" placeholder="{{.locale.Tr "repo.issues.filter_labels"}}">
122-
</div>
123-
{{end}}
124-
<a class="no-select item" href="#">{{.locale.Tr "repo.issues.new.clear_labels"}}</a>
125-
{{if or .Labels .OrgLabels}}
126-
{{$previousExclusiveScope := "_no_scope"}}
127-
{{range .Labels}}
128-
{{$exclusiveScope := .ExclusiveScope}}
129-
{{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
130-
<div class="ui divider"></div>
131-
{{end}}
132-
{{$previousExclusiveScope = $exclusiveScope}}
133-
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
134-
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}</a>
135-
{{end}}
136-
<div class="ui divider"></div>
137-
{{$previousExclusiveScope := "_no_scope"}}
138-
{{range .OrgLabels}}
139-
{{$exclusiveScope := .ExclusiveScope}}
140-
{{if and (ne $previousExclusiveScope "_no_scope") (ne $previousExclusiveScope $exclusiveScope)}}
141-
<div class="ui divider"></div>
142-
{{end}}
143-
{{$previousExclusiveScope = $exclusiveScope}}
144-
<a class="{{if .IsChecked}}checked{{end}} item" href="#" data-id="{{.ID}}" data-id-selector="#label_{{.ID}}" data-scope="{{$exclusiveScope}}"><span class="octicon-check {{if not .IsChecked}}invisible{{end}}">{{if $exclusiveScope}}{{svg "octicon-dot-fill"}}{{else}}{{svg "octicon-check"}}{{end}}</span>&nbsp;&nbsp;{{RenderLabel $.Context .}}
145-
{{if .Description}}<br><small class="desc">{{.Description | RenderEmoji $.Context}}</small>{{end}}</a>
146-
{{end}}
147-
{{else}}
148-
<div class="header" style="text-transform: none;font-size:14px;">{{.locale.Tr "repo.issues.new.no_items"}}</div>
149-
{{end}}
150-
</div>
151-
</div>
109+
{{template "repo/issue/labels/labels_selector_field" .}}
152110
{{template "repo/issue/labels/labels_sidebar" dict "root" $}}
153111

154112
<div class="ui divider"></div>

0 commit comments

Comments
 (0)