Skip to content

Commit dcb648e

Browse files
yp05327delvhsilverwindwxiaoguang
authored
Add Hide/Show all checks button to commit status check (#26284)
Step one for a GitHub like commit status check ui: ![image](https://github.com/go-gitea/gitea/assets/18380374/22953b88-1f91-4d19-bc57-ad92d33fa11f) ![image](https://github.com/go-gitea/gitea/assets/18380374/78572a49-c9b0-472b-86a8-8293197e807b) ![image](https://github.com/go-gitea/gitea/assets/18380374/bc5c8d1c-2ab5-4b03-b8c6-20c34b86d856) Step two: ![image](https://github.com/go-gitea/gitea/assets/18380374/938b359e-8823-4192-b82d-55fa40b986fd) ![image](https://github.com/go-gitea/gitea/assets/18380374/2de5bb8f-40f5-462a-8d6d-bac13a32bc2a) The design now will list all commit status checks which takes too much space. This is a pre-improve for #26247 --------- Co-authored-by: delvh <dev.lh@web.de> Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
1 parent 0ba4ecc commit dcb648e

15 files changed

+132
-80
lines changed

options/locale/locale_en-US.ini

+2
Original file line numberDiff line numberDiff line change
@@ -1786,6 +1786,8 @@ pulls.status_checks_failure = Some checks failed
17861786
pulls.status_checks_error = Some checks reported errors
17871787
pulls.status_checks_requested = Required
17881788
pulls.status_checks_details = Details
1789+
pulls.status_checks_hide_all = Hide all checks
1790+
pulls.status_checks_show_all = Show all checks
17891791
pulls.update_branch = Update branch by merge
17901792
pulls.update_branch_rebase = Update branch by rebase
17911793
pulls.update_branch_success = Branch update was successful

templates/repo/commit_page.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
{{end}}
2020
<div class="ui top attached header clearing segment gt-relative commit-header {{$class}}">
2121
<div class="gt-df gt-mb-4 gt-fw">
22-
<h3 class="gt-mb-0 gt-f1"><span class="commit-summary" title="{{.Commit.Summary}}">{{RenderCommitMessage $.Context .Commit.Message $.RepoLink ($.Repository.ComposeMetas ctx)}}</span>{{template "repo/commit_statuses" dict "Status" .CommitStatus "Statuses" .CommitStatuses "root" $}}</h3>
22+
<h3 class="gt-mb-0 gt-f1"><span class="commit-summary" title="{{.Commit.Summary}}">{{RenderCommitMessage $.Context .Commit.Message $.RepoLink ($.Repository.ComposeMetas ctx)}}</span>{{template "repo/commit_statuses" dict "Status" .CommitStatus "Statuses" .CommitStatuses}}</h3>
2323
{{if not $.PageIsWiki}}
2424
<div>
2525
<a class="ui primary tiny button" href="{{.SourcePath}}">

templates/repo/commit_statuses.tmpl

+2-10
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@
88
{{template "repo/commit_status" .Status}}
99
</span>
1010
{{end}}
11-
<div class="tippy-target ui relaxed list divided">
12-
{{range .Statuses}}
13-
<div class="ui item singular-status gt-df">
14-
{{template "repo/commit_status" .}}
15-
<span class="ui gt-ml-3 gt-f1">{{.Context}} <span class="text grey">{{.Description}}</span></span>
16-
{{if .TargetURL}}
17-
<a class="gt-ml-3" href="{{.TargetURL}}" target="_blank" rel="noopener noreferrer">{{ctx.Locale.Tr "repo.pulls.status_checks_details"}}</a>
18-
{{end}}
19-
</div>
20-
{{end}}
11+
<div class="tippy-target">
12+
{{template "repo/pulls/status" (dict "CommitStatuses" .Statuses "CommitStatus" .Status)}}
2113
</div>
2214
{{end}}

templates/repo/commits_list.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
{{if IsMultilineCommitMessage .Message}}
6767
<button class="ui button js-toggle-commit-body ellipsis-button" aria-expanded="false">...</button>
6868
{{end}}
69-
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $}}
69+
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
7070
{{if IsMultilineCommitMessage .Message}}
7171
<pre class="commit-body gt-hidden">{{RenderCommitBody $.Context .Message $commitRepoLink ($.Repository.ComposeMetas ctx)}}</pre>
7272
{{end}}

templates/repo/commits_list_small.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{{$commitLink:= printf "%s/commit/%s" $.comment.Issue.PullRequest.BaseRepo.Link (PathEscape .ID.String)}}
1515

1616
<span class="shabox gt-df gt-ac gt-float-right">
17-
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $.root}}
17+
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
1818
{{$class := "ui sha label"}}
1919
{{if .Signature}}
2020
{{$class = (print $class " isSigned")}}

templates/repo/issue/view_content/pull.tmpl

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020
{{- else if .Issue.PullRequest.CanAutoMerge}}green
2121
{{- else}}red{{end}}">{{svg "octicon-git-merge" 40}}</div>
2222
<div class="content">
23-
{{template "repo/pulls/status" .}}
23+
<div class="ui attached segment fitted">
24+
{{template "repo/pulls/status" (dict
25+
"CommitStatus" .LatestCommitStatus
26+
"CommitStatuses" .LatestCommitStatuses
27+
"ShowHideChecks" true
28+
"is_context_required" .is_context_required
29+
)}}
30+
</div>
2431
{{$showGeneralMergeForm := false}}
2532
<div class="ui attached merge-section segment {{if not $.LatestCommitStatus}}no-header{{end}} flex-items-block">
2633
{{if .Issue.PullRequest.HasMerged}}

templates/repo/pulls/status.tmpl

+42-25
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
1-
{{if $.LatestCommitStatus}}
2-
{{if not $.Issue.PullRequest.HasMerged}}
3-
<div class="ui top attached header">
4-
{{if eq .LatestCommitStatus.State "pending"}}
5-
{{ctx.Locale.Tr "repo.pulls.status_checking"}}
6-
{{else if eq .LatestCommitStatus.State "success"}}
7-
{{ctx.Locale.Tr "repo.pulls.status_checks_success"}}
8-
{{else if eq .LatestCommitStatus.State "warning"}}
9-
{{ctx.Locale.Tr "repo.pulls.status_checks_warning"}}
10-
{{else if eq .LatestCommitStatus.State "failure"}}
11-
{{ctx.Locale.Tr "repo.pulls.status_checks_failure"}}
12-
{{else if eq .LatestCommitStatus.State "error"}}
13-
{{ctx.Locale.Tr "repo.pulls.status_checks_error"}}
14-
{{else}}
15-
{{ctx.Locale.Tr "repo.pulls.status_checking"}}
16-
{{end}}
17-
</div>
18-
{{end}}
1+
{{/*
2+
Template Attributes:
3+
* CommitStatus: summary of all commit status state
4+
* CommitStatuses: all commit status elements
5+
* ShowHideChecks: whether use a button to show/hide the checks
6+
* is_context_required: Used in pull request commit status check table
7+
*/}}
8+
9+
{{if .CommitStatus}}
10+
<div class="commit-status-panel">
11+
<div class="ui top attached header commit-status-header">
12+
{{if eq .CommitStatus.State "pending"}}
13+
{{ctx.Locale.Tr "repo.pulls.status_checking"}}
14+
{{else if eq .CommitStatus.State "success"}}
15+
{{ctx.Locale.Tr "repo.pulls.status_checks_success"}}
16+
{{else if eq .CommitStatus.State "warning"}}
17+
{{ctx.Locale.Tr "repo.pulls.status_checks_warning"}}
18+
{{else if eq .CommitStatus.State "failure"}}
19+
{{ctx.Locale.Tr "repo.pulls.status_checks_failure"}}
20+
{{else if eq .CommitStatus.State "error"}}
21+
{{ctx.Locale.Tr "repo.pulls.status_checks_error"}}
22+
{{else}}
23+
{{ctx.Locale.Tr "repo.pulls.status_checking"}}
24+
{{end}}
1925

20-
{{range $.LatestCommitStatuses}}
21-
<div class="ui attached segment pr-status">
22-
{{template "repo/commit_status" .}}
23-
<div class="status-context">
24-
<span>{{.Context}} <span class="text grey">{{.Description}}</span></span>
26+
{{if .ShowHideChecks}}
27+
<div class="ui right">
28+
<button class="commit-status-hide-checks btn interact-fg"
29+
data-show-all="{{ctx.Locale.Tr "repo.pulls.status_checks_show_all"}}"
30+
data-hide-all="{{ctx.Locale.Tr "repo.pulls.status_checks_hide_all"}}">
31+
{{ctx.Locale.Tr "repo.pulls.status_checks_hide_all"}}</button>
32+
</div>
33+
{{end}}
34+
</div>
35+
36+
<div class="commit-status-list">
37+
{{range .CommitStatuses}}
38+
<div class="commit-status-item">
39+
{{template "repo/commit_status" .}}
40+
<div class="status-context gt-ellipsis">{{.Context}} <span class="text light-2">{{.Description}}</span></div>
2541
<div class="ui status-details">
2642
{{if $.is_context_required}}
2743
{{if (call $.is_context_required .Context)}}<div class="ui label">{{ctx.Locale.Tr "repo.pulls.status_checks_requested"}}</div>{{end}}
2844
{{end}}
2945
<span>{{if .TargetURL}}<a href="{{.TargetURL}}">{{ctx.Locale.Tr "repo.pulls.status_checks_details"}}</a>{{end}}</span>
3046
</div>
3147
</div>
32-
</div>
33-
{{end}}
48+
{{end}}
49+
</div>
50+
</div>
3451
{{end}}

templates/repo/view_list.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
{{template "repo/shabox_badge" dict "root" $ "verification" .LatestCommitVerification}}
2525
{{end}}
2626
</a>
27-
{{template "repo/commit_statuses" dict "Status" .LatestCommitStatus "Statuses" .LatestCommitStatuses "root" $}}
27+
{{template "repo/commit_statuses" dict "Status" .LatestCommitStatus "Statuses" .LatestCommitStatuses}}
2828
{{$commitLink:= printf "%s/commit/%s" .RepoLink (PathEscape .LatestCommit.ID.String)}}
2929
<span class="grey commit-summary" title="{{.LatestCommit.Summary}}"><span class="message-wrapper">{{RenderCommitMessageLinkSubject $.Context .LatestCommit.Message $.RepoLink $commitLink ($.Repository.ComposeMetas ctx)}}</span>
3030
{{if IsMultilineCommitMessage .LatestCommit.Message}}

templates/shared/issuelist.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<a class="gt-no-underline issue-title" href="{{if .Link}}{{.Link}}{{else}}{{$.Link}}/{{.Index}}{{end}}">{{RenderEmoji $.Context .Title | RenderCodeBlock}}</a>
1717
{{if .IsPull}}
1818
{{if (index $.CommitStatuses .PullRequest.ID)}}
19-
{{template "repo/commit_statuses" dict "Status" (index $.CommitLastStatus .PullRequest.ID) "Statuses" (index $.CommitStatuses .PullRequest.ID) "root" $}}
19+
{{template "repo/commit_statuses" dict "Status" (index $.CommitLastStatus .PullRequest.ID) "Statuses" (index $.CommitStatuses .PullRequest.ID)}}
2020
{{end}}
2121
{{end}}
2222
<span class="labels-list gt-ml-2">

web_src/css/modules/tippy.css

+35-22
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
}
77

88
[data-tippy-root] {
9-
max-width: calc(100vw - 10px);
9+
max-width: calc(100vw - 32px);
1010
}
1111

1212
.tippy-box {
@@ -18,37 +18,59 @@
1818
font-size: 1rem;
1919
}
2020

21+
.tippy-content {
22+
position: relative;
23+
padding: 1rem; /* if you need different padding, use different data-theme */
24+
z-index: 1;
25+
}
26+
27+
/* tooltip theme for text tooltips */
28+
2129
.tippy-box[data-theme="tooltip"] {
2230
background-color: var(--color-tooltip-bg);
2331
color: var(--color-tooltip-text);
2432
border: none;
2533
}
2634

35+
.tippy-box[data-theme="tooltip"] .tippy-content {
36+
padding: 0.5rem 1rem;
37+
}
38+
39+
.tippy-box[data-theme="tooltip"] .tippy-svg-arrow-inner,
40+
.tippy-box[data-theme="tooltip"] .tippy-svg-arrow-outer {
41+
fill: var(--color-tooltip-bg);
42+
}
43+
44+
/* menu theme for .ui.menu */
45+
2746
.tippy-box[data-theme="menu"] {
2847
background-color: var(--color-menu);
2948
color: var(--color-text);
3049
}
3150

32-
.tippy-box[data-theme="form-fetch-error"] {
33-
border-color: var(--color-error-border);
34-
background-color: var(--color-error-bg);
35-
color: var(--color-error-text);
51+
.tippy-box[data-theme="menu"] .tippy-content {
52+
padding: 0;
3653
}
3754

38-
.tippy-content {
39-
position: relative;
40-
padding: 1rem;
41-
z-index: 1;
55+
.tippy-box[data-theme="menu"] .tippy-svg-arrow-inner {
56+
fill: var(--color-menu);
4257
}
4358

44-
.tippy-box[data-theme="tooltip"] .tippy-content {
45-
padding: 0.5rem 1rem;
46-
}
59+
/* box-with-header theme to look like .ui.attached.segment. can contain .ui.attached.header */
4760

48-
.tippy-box[data-theme="menu"] .tippy-content {
61+
.tippy-box[data-theme="box-with-header"] .tippy-content {
62+
background: var(--color-box-body);
4963
padding: 0;
5064
}
5165

66+
.tippy-box[data-theme="box-with-header"][data-placement^="top"] .tippy-svg-arrow-inner {
67+
fill: var(--color-box-body);
68+
}
69+
70+
.tippy-box[data-theme="box-with-header"][data-placement^="bottom"] .tippy-svg-arrow-inner {
71+
fill: var(--color-box-header);
72+
}
73+
5274
.tippy-box[data-placement^="top"] > .tippy-svg-arrow {
5375
bottom: 0;
5476
}
@@ -107,12 +129,3 @@
107129
.tippy-svg-arrow-inner {
108130
fill: var(--color-body);
109131
}
110-
111-
.tippy-box[data-theme="tooltip"] .tippy-svg-arrow-inner,
112-
.tippy-box[data-theme="tooltip"] .tippy-svg-arrow-outer {
113-
fill: var(--color-tooltip-bg);
114-
}
115-
116-
.tippy-box[data-theme="menu"] .tippy-svg-arrow-inner {
117-
fill: var(--color-menu);
118-
}

web_src/css/repo.css

+22-16
Original file line numberDiff line numberDiff line change
@@ -3074,43 +3074,49 @@ tbody.commit-list {
30743074
}
30753075
}
30763076

3077-
.pr-status {
3078-
padding: 0 !important; /* To clear fomantic's padding on .ui.segment elements */
3079-
display: flex;
3080-
align-items: center;
3077+
.commit-status-header {
3078+
border: none !important; /* reset the default ".ui.attached.header" styles, to use the outer border */
3079+
margin: 0 !important;
30813080
}
30823081

3083-
.pr-status .commit-status {
3084-
margin: 1em;
3085-
flex-shrink: 0;
3082+
.commit-status-list {
3083+
max-height: 195px; /* fit exactly 4 items */
3084+
overflow-x: hidden;
3085+
transition: max-height .2s;
30863086
}
30873087

3088-
.pr-status .status-context {
3088+
.commit-status-item {
3089+
padding: 14px 10px !important;
30893090
display: flex;
3090-
justify-content: space-between;
3091-
width: 100%;
3091+
gap: 8px;
3092+
align-items: center;
3093+
border-top: 1px solid var(--color-secondary);
3094+
}
3095+
3096+
.commit-status-item .commit-status {
3097+
flex-shrink: 0;
30923098
}
30933099

3094-
.pr-status .status-context > span {
3095-
padding: 1em 0;
3100+
.commit-status-item .status-context {
3101+
color: var(--color-text);
3102+
flex: 1;
30963103
}
30973104

3098-
.pr-status .status-details {
3105+
.commit-status-item .status-details {
30993106
display: flex;
3100-
padding-right: 0.5em;
31013107
align-items: center;
31023108
justify-content: flex-end;
31033109
}
31043110

31053111
@media (max-width: 767.98px) {
3106-
.pr-status .status-details {
3112+
.commit-status-item .status-details {
31073113
flex-direction: column;
31083114
align-items: flex-end;
31093115
justify-content: center;
31103116
}
31113117
}
31123118

3113-
.pr-status .status-details > span {
3119+
.commit-status-item .status-details > span {
31143120
padding-right: 0.5em; /* To match the alignment with the "required" label */
31153121
}
31163122

web_src/js/features/repo-commit.js

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export function initCommitStatuses() {
6666
placement: top ? 'top-start' : 'bottom-start',
6767
interactive: true,
6868
role: 'dialog',
69+
theme: 'box-with-header',
6970
});
7071
});
7172
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function initRepoPullRequestCommitStatus() {
2+
for (const btn of document.querySelectorAll('.commit-status-hide-checks')) {
3+
const panel = btn.closest('.commit-status-panel');
4+
const list = panel.querySelector('.commit-status-list');
5+
btn.addEventListener('click', () => {
6+
list.style.maxHeight = list.style.maxHeight ? '' : '0px'; // toggle
7+
list.style.overflow = 'hidden'; // hide scrollbar when hiding
8+
btn.textContent = btn.getAttribute(list.style.maxHeight ? 'data-show-all' : 'data-hide-all');
9+
});
10+
list.addEventListener('animationend', () => list.style.overflow = '');
11+
}
12+
}

web_src/js/features/repo-legacy.js

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {initCommentContent, initMarkupContent} from '../markup/content.js';
2020
import {initCompReactionSelector} from './comp/ReactionSelector.js';
2121
import {initRepoSettingBranches} from './repo-settings.js';
2222
import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.js';
23+
import {initRepoPullRequestCommitStatus} from './repo-issue-pr-status.js';
2324
import {hideElem, showElem} from '../utils/dom.js';
2425
import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';
2526
import {attachRefIssueContextPopup} from './contextpopup.js';
@@ -546,6 +547,7 @@ export function initRepository() {
546547
initCompReactionSelector($(document));
547548

548549
initRepoPullRequestMergeForm();
550+
initRepoPullRequestCommitStatus();
549551
}
550552

551553
// Pull request

web_src/js/modules/tippy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function createTippy(target, opts = {}) {
3434
},
3535
arrow: `<svg width="16" height="7"><path d="m0 7 8-7 8 7Z" class="tippy-svg-arrow-outer"/><path d="m0 8 8-7 8 7Z" class="tippy-svg-arrow-inner"/></svg>`,
3636
role: 'menu', // HTML role attribute, only tooltips should use "tooltip"
37-
theme: other.role || 'menu', // CSS theme, we support either "tooltip" or "menu"
37+
theme: other.role || 'menu', // CSS theme, either "tooltip", "menu" or "box-with-header"
3838
plugins: [followCursor],
3939
...other,
4040
});

0 commit comments

Comments
 (0)