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>
This commit is contained in:
yp05327 2023-11-02 23:49:02 +09:00 committed by GitHub
parent 0ba4ecc3bd
commit dcb648ee71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 138 additions and 86 deletions

View file

@ -1786,6 +1786,8 @@ pulls.status_checks_failure = Some checks failed
pulls.status_checks_error = Some checks reported errors pulls.status_checks_error = Some checks reported errors
pulls.status_checks_requested = Required pulls.status_checks_requested = Required
pulls.status_checks_details = Details pulls.status_checks_details = Details
pulls.status_checks_hide_all = Hide all checks
pulls.status_checks_show_all = Show all checks
pulls.update_branch = Update branch by merge pulls.update_branch = Update branch by merge
pulls.update_branch_rebase = Update branch by rebase pulls.update_branch_rebase = Update branch by rebase
pulls.update_branch_success = Branch update was successful pulls.update_branch_success = Branch update was successful

View file

@ -19,7 +19,7 @@
{{end}} {{end}}
<div class="ui top attached header clearing segment gt-relative commit-header {{$class}}"> <div class="ui top attached header clearing segment gt-relative commit-header {{$class}}">
<div class="gt-df gt-mb-4 gt-fw"> <div class="gt-df gt-mb-4 gt-fw">
<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> <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>
{{if not $.PageIsWiki}} {{if not $.PageIsWiki}}
<div> <div>
<a class="ui primary tiny button" href="{{.SourcePath}}"> <a class="ui primary tiny button" href="{{.SourcePath}}">

View file

@ -8,15 +8,7 @@
{{template "repo/commit_status" .Status}} {{template "repo/commit_status" .Status}}
</span> </span>
{{end}} {{end}}
<div class="tippy-target ui relaxed list divided"> <div class="tippy-target">
{{range .Statuses}} {{template "repo/pulls/status" (dict "CommitStatuses" .Statuses "CommitStatus" .Status)}}
<div class="ui item singular-status gt-df">
{{template "repo/commit_status" .}}
<span class="ui gt-ml-3 gt-f1">{{.Context}} <span class="text grey">{{.Description}}</span></span>
{{if .TargetURL}}
<a class="gt-ml-3" href="{{.TargetURL}}" target="_blank" rel="noopener noreferrer">{{ctx.Locale.Tr "repo.pulls.status_checks_details"}}</a>
{{end}}
</div>
{{end}}
</div> </div>
{{end}} {{end}}

View file

@ -66,7 +66,7 @@
{{if IsMultilineCommitMessage .Message}} {{if IsMultilineCommitMessage .Message}}
<button class="ui button js-toggle-commit-body ellipsis-button" aria-expanded="false">...</button> <button class="ui button js-toggle-commit-body ellipsis-button" aria-expanded="false">...</button>
{{end}} {{end}}
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $}} {{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
{{if IsMultilineCommitMessage .Message}} {{if IsMultilineCommitMessage .Message}}
<pre class="commit-body gt-hidden">{{RenderCommitBody $.Context .Message $commitRepoLink ($.Repository.ComposeMetas ctx)}}</pre> <pre class="commit-body gt-hidden">{{RenderCommitBody $.Context .Message $commitRepoLink ($.Repository.ComposeMetas ctx)}}</pre>
{{end}} {{end}}

View file

@ -14,7 +14,7 @@
{{$commitLink:= printf "%s/commit/%s" $.comment.Issue.PullRequest.BaseRepo.Link (PathEscape .ID.String)}} {{$commitLink:= printf "%s/commit/%s" $.comment.Issue.PullRequest.BaseRepo.Link (PathEscape .ID.String)}}
<span class="shabox gt-df gt-ac gt-float-right"> <span class="shabox gt-df gt-ac gt-float-right">
{{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses "root" $.root}} {{template "repo/commit_statuses" dict "Status" .Status "Statuses" .Statuses}}
{{$class := "ui sha label"}} {{$class := "ui sha label"}}
{{if .Signature}} {{if .Signature}}
{{$class = (print $class " isSigned")}} {{$class = (print $class " isSigned")}}

View file

@ -20,7 +20,14 @@
{{- else if .Issue.PullRequest.CanAutoMerge}}green {{- else if .Issue.PullRequest.CanAutoMerge}}green
{{- else}}red{{end}}">{{svg "octicon-git-merge" 40}}</div> {{- else}}red{{end}}">{{svg "octicon-git-merge" 40}}</div>
<div class="content"> <div class="content">
{{template "repo/pulls/status" .}} <div class="ui attached segment fitted">
{{template "repo/pulls/status" (dict
"CommitStatus" .LatestCommitStatus
"CommitStatuses" .LatestCommitStatuses
"ShowHideChecks" true
"is_context_required" .is_context_required
)}}
</div>
{{$showGeneralMergeForm := false}} {{$showGeneralMergeForm := false}}
<div class="ui attached merge-section segment {{if not $.LatestCommitStatus}}no-header{{end}} flex-items-block"> <div class="ui attached merge-section segment {{if not $.LatestCommitStatus}}no-header{{end}} flex-items-block">
{{if .Issue.PullRequest.HasMerged}} {{if .Issue.PullRequest.HasMerged}}

View file

@ -1,27 +1,43 @@
{{if $.LatestCommitStatus}} {{/*
{{if not $.Issue.PullRequest.HasMerged}} Template Attributes:
<div class="ui top attached header"> * CommitStatus: summary of all commit status state
{{if eq .LatestCommitStatus.State "pending"}} * CommitStatuses: all commit status elements
* ShowHideChecks: whether use a button to show/hide the checks
* is_context_required: Used in pull request commit status check table
*/}}
{{if .CommitStatus}}
<div class="commit-status-panel">
<div class="ui top attached header commit-status-header">
{{if eq .CommitStatus.State "pending"}}
{{ctx.Locale.Tr "repo.pulls.status_checking"}} {{ctx.Locale.Tr "repo.pulls.status_checking"}}
{{else if eq .LatestCommitStatus.State "success"}} {{else if eq .CommitStatus.State "success"}}
{{ctx.Locale.Tr "repo.pulls.status_checks_success"}} {{ctx.Locale.Tr "repo.pulls.status_checks_success"}}
{{else if eq .LatestCommitStatus.State "warning"}} {{else if eq .CommitStatus.State "warning"}}
{{ctx.Locale.Tr "repo.pulls.status_checks_warning"}} {{ctx.Locale.Tr "repo.pulls.status_checks_warning"}}
{{else if eq .LatestCommitStatus.State "failure"}} {{else if eq .CommitStatus.State "failure"}}
{{ctx.Locale.Tr "repo.pulls.status_checks_failure"}} {{ctx.Locale.Tr "repo.pulls.status_checks_failure"}}
{{else if eq .LatestCommitStatus.State "error"}} {{else if eq .CommitStatus.State "error"}}
{{ctx.Locale.Tr "repo.pulls.status_checks_error"}} {{ctx.Locale.Tr "repo.pulls.status_checks_error"}}
{{else}} {{else}}
{{ctx.Locale.Tr "repo.pulls.status_checking"}} {{ctx.Locale.Tr "repo.pulls.status_checking"}}
{{end}} {{end}}
{{if .ShowHideChecks}}
<div class="ui right">
<button class="commit-status-hide-checks btn interact-fg"
data-show-all="{{ctx.Locale.Tr "repo.pulls.status_checks_show_all"}}"
data-hide-all="{{ctx.Locale.Tr "repo.pulls.status_checks_hide_all"}}">
{{ctx.Locale.Tr "repo.pulls.status_checks_hide_all"}}</button>
</div> </div>
{{end}} {{end}}
</div>
{{range $.LatestCommitStatuses}} <div class="commit-status-list">
<div class="ui attached segment pr-status"> {{range .CommitStatuses}}
<div class="commit-status-item">
{{template "repo/commit_status" .}} {{template "repo/commit_status" .}}
<div class="status-context"> <div class="status-context gt-ellipsis">{{.Context}} <span class="text light-2">{{.Description}}</span></div>
<span>{{.Context}} <span class="text grey">{{.Description}}</span></span>
<div class="ui status-details"> <div class="ui status-details">
{{if $.is_context_required}} {{if $.is_context_required}}
{{if (call $.is_context_required .Context)}}<div class="ui label">{{ctx.Locale.Tr "repo.pulls.status_checks_requested"}}</div>{{end}} {{if (call $.is_context_required .Context)}}<div class="ui label">{{ctx.Locale.Tr "repo.pulls.status_checks_requested"}}</div>{{end}}
@ -29,6 +45,7 @@
<span>{{if .TargetURL}}<a href="{{.TargetURL}}">{{ctx.Locale.Tr "repo.pulls.status_checks_details"}}</a>{{end}}</span> <span>{{if .TargetURL}}<a href="{{.TargetURL}}">{{ctx.Locale.Tr "repo.pulls.status_checks_details"}}</a>{{end}}</span>
</div> </div>
</div> </div>
</div>
{{end}} {{end}}
</div>
</div>
{{end}} {{end}}

View file

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

View file

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

View file

@ -6,7 +6,7 @@
} }
[data-tippy-root] { [data-tippy-root] {
max-width: calc(100vw - 10px); max-width: calc(100vw - 32px);
} }
.tippy-box { .tippy-box {
@ -18,37 +18,59 @@
font-size: 1rem; font-size: 1rem;
} }
.tippy-content {
position: relative;
padding: 1rem; /* if you need different padding, use different data-theme */
z-index: 1;
}
/* tooltip theme for text tooltips */
.tippy-box[data-theme="tooltip"] { .tippy-box[data-theme="tooltip"] {
background-color: var(--color-tooltip-bg); background-color: var(--color-tooltip-bg);
color: var(--color-tooltip-text); color: var(--color-tooltip-text);
border: none; border: none;
} }
.tippy-box[data-theme="tooltip"] .tippy-content {
padding: 0.5rem 1rem;
}
.tippy-box[data-theme="tooltip"] .tippy-svg-arrow-inner,
.tippy-box[data-theme="tooltip"] .tippy-svg-arrow-outer {
fill: var(--color-tooltip-bg);
}
/* menu theme for .ui.menu */
.tippy-box[data-theme="menu"] { .tippy-box[data-theme="menu"] {
background-color: var(--color-menu); background-color: var(--color-menu);
color: var(--color-text); color: var(--color-text);
} }
.tippy-box[data-theme="form-fetch-error"] {
border-color: var(--color-error-border);
background-color: var(--color-error-bg);
color: var(--color-error-text);
}
.tippy-content {
position: relative;
padding: 1rem;
z-index: 1;
}
.tippy-box[data-theme="tooltip"] .tippy-content {
padding: 0.5rem 1rem;
}
.tippy-box[data-theme="menu"] .tippy-content { .tippy-box[data-theme="menu"] .tippy-content {
padding: 0; padding: 0;
} }
.tippy-box[data-theme="menu"] .tippy-svg-arrow-inner {
fill: var(--color-menu);
}
/* box-with-header theme to look like .ui.attached.segment. can contain .ui.attached.header */
.tippy-box[data-theme="box-with-header"] .tippy-content {
background: var(--color-box-body);
padding: 0;
}
.tippy-box[data-theme="box-with-header"][data-placement^="top"] .tippy-svg-arrow-inner {
fill: var(--color-box-body);
}
.tippy-box[data-theme="box-with-header"][data-placement^="bottom"] .tippy-svg-arrow-inner {
fill: var(--color-box-header);
}
.tippy-box[data-placement^="top"] > .tippy-svg-arrow { .tippy-box[data-placement^="top"] > .tippy-svg-arrow {
bottom: 0; bottom: 0;
} }
@ -107,12 +129,3 @@
.tippy-svg-arrow-inner { .tippy-svg-arrow-inner {
fill: var(--color-body); fill: var(--color-body);
} }
.tippy-box[data-theme="tooltip"] .tippy-svg-arrow-inner,
.tippy-box[data-theme="tooltip"] .tippy-svg-arrow-outer {
fill: var(--color-tooltip-bg);
}
.tippy-box[data-theme="menu"] .tippy-svg-arrow-inner {
fill: var(--color-menu);
}

View file

@ -3074,43 +3074,49 @@ tbody.commit-list {
} }
} }
.pr-status { .commit-status-header {
padding: 0 !important; /* To clear fomantic's padding on .ui.segment elements */ border: none !important; /* reset the default ".ui.attached.header" styles, to use the outer border */
display: flex; margin: 0 !important;
align-items: center;
} }
.pr-status .commit-status { .commit-status-list {
margin: 1em; max-height: 195px; /* fit exactly 4 items */
overflow-x: hidden;
transition: max-height .2s;
}
.commit-status-item {
padding: 14px 10px !important;
display: flex;
gap: 8px;
align-items: center;
border-top: 1px solid var(--color-secondary);
}
.commit-status-item .commit-status {
flex-shrink: 0; flex-shrink: 0;
} }
.pr-status .status-context { .commit-status-item .status-context {
display: flex; color: var(--color-text);
justify-content: space-between; flex: 1;
width: 100%;
} }
.pr-status .status-context > span { .commit-status-item .status-details {
padding: 1em 0;
}
.pr-status .status-details {
display: flex; display: flex;
padding-right: 0.5em;
align-items: center; align-items: center;
justify-content: flex-end; justify-content: flex-end;
} }
@media (max-width: 767.98px) { @media (max-width: 767.98px) {
.pr-status .status-details { .commit-status-item .status-details {
flex-direction: column; flex-direction: column;
align-items: flex-end; align-items: flex-end;
justify-content: center; justify-content: center;
} }
} }
.pr-status .status-details > span { .commit-status-item .status-details > span {
padding-right: 0.5em; /* To match the alignment with the "required" label */ padding-right: 0.5em; /* To match the alignment with the "required" label */
} }

View file

@ -66,6 +66,7 @@ export function initCommitStatuses() {
placement: top ? 'top-start' : 'bottom-start', placement: top ? 'top-start' : 'bottom-start',
interactive: true, interactive: true,
role: 'dialog', role: 'dialog',
theme: 'box-with-header',
}); });
}); });
} }

View file

@ -0,0 +1,12 @@
export function initRepoPullRequestCommitStatus() {
for (const btn of document.querySelectorAll('.commit-status-hide-checks')) {
const panel = btn.closest('.commit-status-panel');
const list = panel.querySelector('.commit-status-list');
btn.addEventListener('click', () => {
list.style.maxHeight = list.style.maxHeight ? '' : '0px'; // toggle
list.style.overflow = 'hidden'; // hide scrollbar when hiding
btn.textContent = btn.getAttribute(list.style.maxHeight ? 'data-show-all' : 'data-hide-all');
});
list.addEventListener('animationend', () => list.style.overflow = '');
}
}

View file

@ -20,6 +20,7 @@ import {initCommentContent, initMarkupContent} from '../markup/content.js';
import {initCompReactionSelector} from './comp/ReactionSelector.js'; import {initCompReactionSelector} from './comp/ReactionSelector.js';
import {initRepoSettingBranches} from './repo-settings.js'; import {initRepoSettingBranches} from './repo-settings.js';
import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.js'; import {initRepoPullRequestMergeForm} from './repo-issue-pr-form.js';
import {initRepoPullRequestCommitStatus} from './repo-issue-pr-status.js';
import {hideElem, showElem} from '../utils/dom.js'; import {hideElem, showElem} from '../utils/dom.js';
import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js'; import {getComboMarkdownEditor, initComboMarkdownEditor} from './comp/ComboMarkdownEditor.js';
import {attachRefIssueContextPopup} from './contextpopup.js'; import {attachRefIssueContextPopup} from './contextpopup.js';
@ -546,6 +547,7 @@ export function initRepository() {
initCompReactionSelector($(document)); initCompReactionSelector($(document));
initRepoPullRequestMergeForm(); initRepoPullRequestMergeForm();
initRepoPullRequestCommitStatus();
} }
// Pull request // Pull request

View file

@ -34,7 +34,7 @@ export function createTippy(target, opts = {}) {
}, },
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>`, 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>`,
role: 'menu', // HTML role attribute, only tooltips should use "tooltip" role: 'menu', // HTML role attribute, only tooltips should use "tooltip"
theme: other.role || 'menu', // CSS theme, we support either "tooltip" or "menu" theme: other.role || 'menu', // CSS theme, either "tooltip", "menu" or "box-with-header"
plugins: [followCursor], plugins: [followCursor],
...other, ...other,
}); });