Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand/Collapse all changed files #23639

Merged
merged 17 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,8 @@ pulls.compare_changes_desc = Select the branch to merge into and the branch to p
pulls.has_viewed_file = Viewed
pulls.has_changed_since_last_review = Changed since your last review
pulls.viewed_files_label = %[1]d / %[2]d files viewed
pulls.expand_files = Expand all files
pulls.collapse_files = Collapse all files
pulls.compare_base = merge into
pulls.compare_compare = pull from
pulls.switch_comparison_type = Switch comparison type
Expand Down
4 changes: 4 additions & 0 deletions templates/repo/diff/options_dropdown.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
<a class="item" href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}.patch" download="{{ShortSha .Commit.ID.String}}.patch">{{.locale.Tr "repo.diff.download_patch"}}</a>
<a class="item" href="{{$.RepoLink}}/commit/{{PathEscape .Commit.ID.String}}.diff" download="{{ShortSha .Commit.ID.String}}.diff">{{.locale.Tr "repo.diff.download_diff"}}</a>
{{end}}
{{if and .PageIsPullFiles $.SignedUserID (not .IsArchived)}}
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
<a id="expand-files-btn" class="item">{{.locale.Tr "repo.pulls.expand_files"}}</a>
<a id="collapse-files-btn"class="item">{{.locale.Tr "repo.pulls.collapse_files"}}</a>
{{end}}
</div>
</div>
21 changes: 21 additions & 0 deletions web_src/js/features/pull-view-file.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {setFileFolding} from './file-fold.js';


silverwind marked this conversation as resolved.
Show resolved Hide resolved
const {csrfToken, pageData} = window.config;
const prReview = pageData.prReview || {};
const viewedStyleClass = 'viewed-file-checked-form';
const viewedCheckboxSelector = '.viewed-file-form'; // Selector under which all "Viewed" checkbox forms can be found
const expandFilesBtnSelector = '#expand-files-btn';
const collapseFilesBtnSelector = '#collapse-files-btn';


// Refreshes the summary of viewed files if present
Expand Down Expand Up @@ -69,3 +72,21 @@ export function initViewedCheckboxListenerFor() {
});
}
}

export function initExpandAndCollapseFilesButton() {
// expand btn
document.querySelector(expandFilesBtnSelector)?.addEventListener('click', () => {
for (const box of document.querySelectorAll('.file-content[data-folded="true"]')) {
setFileFolding(box, box.querySelector('.fold-file'), false);
}
});
// collapse btn, need to exclude the div of “show more”
document.querySelector(collapseFilesBtnSelector)?.addEventListener('click', () => {
for (const box of document.querySelectorAll('.file-content:not([data-folded="true"])')) {
if (box.getAttribute('id') === 'diff-incomplete') continue;
setFileFolding(box, box.querySelector('.fold-file'), true);
}
});
}
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved


23 changes: 18 additions & 5 deletions web_src/js/features/repo-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import $ from 'jquery';
import {initCompReactionSelector} from './comp/ReactionSelector.js';
import {initRepoIssueContentHistory} from './repo-issue-content.js';
import {validateTextareaNonEmpty} from './comp/EasyMDE.js';
import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles} from './pull-view-file.js';
import {initDiffFileTree} from './repo-diff-filetree.js';
import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles, initExpandAndCollapseFilesButton} from './pull-view-file.js';

const {csrfToken} = window.config;

export function initRepoDiffReviewButton() {
function initRepoDiffReviewButton() {
const $reviewBox = $('#review-box');
const $counter = $reviewBox.find('.review-comments-counter');

Expand All @@ -25,7 +26,7 @@ export function initRepoDiffReviewButton() {
});
}

export function initRepoDiffFileViewToggle() {
function initRepoDiffFileViewToggle() {
$('.file-view-toggle').on('click', function () {
const $this = $(this);
$this.parent().children().removeClass('active');
Expand All @@ -37,7 +38,7 @@ export function initRepoDiffFileViewToggle() {
});
}

export function initRepoDiffConversationForm() {
function initRepoDiffConversationForm() {
$(document).on('submit', '.conversation-holder form', async (e) => {
e.preventDefault();

Expand Down Expand Up @@ -152,7 +153,7 @@ function loadMoreFiles(url, callback) {
});
}

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

Expand Down Expand Up @@ -186,3 +187,15 @@ export function initRepoDiffShowMore() {
});
});
}

export function initRepoDiffView() {
const diffFileList = $('#diff-file-list');
if (diffFileList.length === 0) return;
initDiffFileTree();
initRepoDiffShowMore();
initRepoDiffReviewButton();
initRepoDiffFileViewToggle();
initRepoDiffConversationForm();
initViewedCheckboxListenerFor();
initExpandAndCollapseFilesButton();
}
15 changes: 2 additions & 13 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@ import {initRepoIssueContentHistory} from './features/repo-issue-content.js';
import {initStopwatch} from './features/stopwatch.js';
import {initFindFileInRepo} from './features/repo-findfile.js';
import {initCommentContent, initMarkupContent} from './markup/content.js';
import {initDiffFileTree} from './features/repo-diff-filetree.js';

import {initUserAuthLinkAccountView, initUserAuthOauth2} from './features/user-auth.js';
import {
initRepoDiffConversationForm,
initRepoDiffFileViewToggle,
initRepoDiffReviewButton, initRepoDiffShowMore,
} from './features/repo-diff.js';
import {
initRepoIssueDue,
initRepoIssueList,
Expand Down Expand Up @@ -71,7 +65,7 @@ import {
initRepoSettingsCollaboration,
initRepoSettingSearchTeamBox,
} from './features/repo-settings.js';
import {initViewedCheckboxListenerFor} from './features/pull-view-file.js';
import {initRepoDiffView} from './features/repo-diff.js';
import {initOrgTeamSearchRepoBox, initOrgTeamSettings} from './features/org-team.js';
import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/user-auth-webauthn.js';
import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.js';
Expand Down Expand Up @@ -156,11 +150,6 @@ $(document).ready(() => {
initRepoCommentForm();
initRepoEllipsisButton();
initRepoCommitLastCommitLoader();
initRepoDiffConversationForm();
initRepoDiffFileViewToggle();
initRepoDiffReviewButton();
initRepoDiffShowMore();
initDiffFileTree();
initRepoEditor();
initRepoGraphGit();
initRepoIssueContentHistory();
Expand Down Expand Up @@ -194,5 +183,5 @@ $(document).ready(() => {
initUserAuthWebAuthn();
initUserAuthWebAuthnRegister();
initUserSettings();
initViewedCheckboxListenerFor();
initRepoDiffView();
});