Skip to content

Commit bedad23

Browse files
Expand/Collapse all changed files (#23639)
close #23628 Now in `...` dropdown, you can expand or collapse all diff files that have loaded. https://user-images.githubusercontent.com/33891828/227749688-2d406916-3347-49f6-93a5-4092a00e8809.mov Co-authored-by: silverwind <me@silverwind.io>
1 parent f2b98d8 commit bedad23

File tree

6 files changed

+45
-19
lines changed

6 files changed

+45
-19
lines changed

options/locale/locale_en-US.ini

+2
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,8 @@ pulls.compare_changes_desc = Select the branch to merge into and the branch to p
15721572
pulls.has_viewed_file = Viewed
15731573
pulls.has_changed_since_last_review = Changed since your last review
15741574
pulls.viewed_files_label = %[1]d / %[2]d files viewed
1575+
pulls.expand_files = Expand all files
1576+
pulls.collapse_files = Collapse all files
15751577
pulls.compare_base = merge into
15761578
pulls.compare_compare = pull from
15771579
pulls.switch_comparison_type = Switch comparison type

templates/repo/diff/options_dropdown.tmpl

+2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@
1212
<a class="item" href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}.patch" download="{{ShortSha .Commit.ID.String}}.patch">{{.locale.Tr "repo.diff.download_patch"}}</a>
1313
<a class="item" href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}.diff" download="{{ShortSha .Commit.ID.String}}.diff">{{.locale.Tr "repo.diff.download_diff"}}</a>
1414
{{end}}
15+
<a id="expand-files-btn" class="item">{{.locale.Tr "repo.pulls.expand_files"}}</a>
16+
<a id="collapse-files-btn"class="item">{{.locale.Tr "repo.pulls.collapse_files"}}</a>
1517
</div>
1618
</div>

web_src/css/review.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ a.blob-excerpt:hover {
256256
.changed-since-last-review {
257257
border: 1px var(--color-accent) solid;
258258
background-color: var(--color-small-accent);
259-
border-radius: 15px;
259+
border-radius: var(--border-radius);
260260
padding: 4px 8px;
261261
margin: -8px 0; /* just like other buttons in the diff box header */
262262
font-size: 0.857rem; /* just like .ui.tiny.button */

web_src/js/features/pull-view-file.js

+20
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const {csrfToken, pageData} = window.config;
44
const prReview = pageData.prReview || {};
55
const viewedStyleClass = 'viewed-file-checked-form';
66
const viewedCheckboxSelector = '.viewed-file-form'; // Selector under which all "Viewed" checkbox forms can be found
7+
const expandFilesBtnSelector = '#expand-files-btn';
8+
const collapseFilesBtnSelector = '#collapse-files-btn';
79

810

911
// Refreshes the summary of viewed files if present
@@ -69,3 +71,21 @@ export function initViewedCheckboxListenerFor() {
6971
});
7072
}
7173
}
74+
75+
export function initExpandAndCollapseFilesButton() {
76+
// expand btn
77+
document.querySelector(expandFilesBtnSelector)?.addEventListener('click', () => {
78+
for (const box of document.querySelectorAll('.file-content[data-folded="true"]')) {
79+
setFileFolding(box, box.querySelector('.fold-file'), false);
80+
}
81+
});
82+
// collapse btn, need to exclude the div of “show more”
83+
document.querySelector(collapseFilesBtnSelector)?.addEventListener('click', () => {
84+
for (const box of document.querySelectorAll('.file-content:not([data-folded="true"])')) {
85+
if (box.getAttribute('id') === 'diff-incomplete') continue;
86+
setFileFolding(box, box.querySelector('.fold-file'), true);
87+
}
88+
});
89+
}
90+
91+

web_src/js/features/repo-diff.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import $ from 'jquery';
22
import {initCompReactionSelector} from './comp/ReactionSelector.js';
33
import {initRepoIssueContentHistory} from './repo-issue-content.js';
4-
import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles} from './pull-view-file.js';
4+
import {initDiffFileTree} from './repo-diff-filetree.js';
55
import {validateTextareaNonEmpty} from './comp/ComboMarkdownEditor.js';
6+
import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles, initExpandAndCollapseFilesButton} from './pull-view-file.js';
67

78
const {csrfToken} = window.config;
89

9-
export function initRepoDiffReviewButton() {
10+
function initRepoDiffReviewButton() {
1011
const $reviewBox = $('#review-box');
1112
const $counter = $reviewBox.find('.review-comments-counter');
1213

@@ -25,7 +26,7 @@ export function initRepoDiffReviewButton() {
2526
});
2627
}
2728

28-
export function initRepoDiffFileViewToggle() {
29+
function initRepoDiffFileViewToggle() {
2930
$('.file-view-toggle').on('click', function () {
3031
const $this = $(this);
3132
$this.parent().children().removeClass('active');
@@ -37,7 +38,7 @@ export function initRepoDiffFileViewToggle() {
3738
});
3839
}
3940

40-
export function initRepoDiffConversationForm() {
41+
function initRepoDiffConversationForm() {
4142
$(document).on('submit', '.conversation-holder form', async (e) => {
4243
e.preventDefault();
4344

@@ -152,7 +153,7 @@ function loadMoreFiles(url, callback) {
152153
});
153154
}
154155

155-
export function initRepoDiffShowMore() {
156+
function initRepoDiffShowMore() {
156157
$(document).on('click', 'a#diff-show-more-files', (e) => {
157158
e.preventDefault();
158159

@@ -186,3 +187,15 @@ export function initRepoDiffShowMore() {
186187
});
187188
});
188189
}
190+
191+
export function initRepoDiffView() {
192+
const diffFileList = $('#diff-file-list');
193+
if (diffFileList.length === 0) return;
194+
initDiffFileTree();
195+
initRepoDiffShowMore();
196+
initRepoDiffReviewButton();
197+
initRepoDiffFileViewToggle();
198+
initRepoDiffConversationForm();
199+
initViewedCheckboxListenerFor();
200+
initExpandAndCollapseFilesButton();
201+
}

web_src/js/index.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,8 @@ import {initRepoIssueContentHistory} from './features/repo-issue-content.js';
2121
import {initStopwatch} from './features/stopwatch.js';
2222
import {initFindFileInRepo} from './features/repo-findfile.js';
2323
import {initCommentContent, initMarkupContent} from './markup/content.js';
24-
import {initDiffFileTree} from './features/repo-diff-filetree.js';
2524

2625
import {initUserAuthLinkAccountView, initUserAuthOauth2} from './features/user-auth.js';
27-
import {
28-
initRepoDiffConversationForm,
29-
initRepoDiffFileViewToggle,
30-
initRepoDiffReviewButton, initRepoDiffShowMore,
31-
} from './features/repo-diff.js';
3226
import {
3327
initRepoIssueDue,
3428
initRepoIssueReferenceRepositorySearch,
@@ -68,7 +62,7 @@ import {
6862
initRepoSettingsCollaboration,
6963
initRepoSettingSearchTeamBox,
7064
} from './features/repo-settings.js';
71-
import {initViewedCheckboxListenerFor} from './features/pull-view-file.js';
65+
import {initRepoDiffView} from './features/repo-diff.js';
7266
import {initOrgTeamSearchRepoBox, initOrgTeamSettings} from './features/org-team.js';
7367
import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.js';
7468
import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.js';
@@ -151,11 +145,6 @@ onDomReady(() => {
151145
initRepoCommentForm();
152146
initRepoEllipsisButton();
153147
initRepoCommitLastCommitLoader();
154-
initRepoDiffConversationForm();
155-
initRepoDiffFileViewToggle();
156-
initRepoDiffReviewButton();
157-
initRepoDiffShowMore();
158-
initDiffFileTree();
159148
initRepoEditor();
160149
initRepoGraphGit();
161150
initRepoIssueContentHistory();
@@ -190,5 +179,5 @@ onDomReady(() => {
190179
initUserAuthWebAuthn();
191180
initUserAuthWebAuthnRegister();
192181
initUserSettings();
193-
initViewedCheckboxListenerFor();
182+
initRepoDiffView();
194183
});

0 commit comments

Comments
 (0)