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 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions options/locale/locale_en-US.ini
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
6 changes: 6 additions & 0 deletions templates/repo/diff/box.tmpl
Expand Up @@ -30,6 +30,12 @@
<label for="viewed-files-summary" id="viewed-files-summary-label" class="gt-mr-3 gt-f1" data-text-changed-template="{{.locale.Tr "repo.pulls.viewed_files_label"}}">
{{.locale.Tr "repo.pulls.viewed_files_label" .Diff.NumViewedFiles .Diff.NumFiles}}
</label>
<button id="expand-files-btn" class="ui button tiny tooltip basic" data-content="{{.locale.Tr "repo.pulls.expand_files"}}">
{{svg "octicon-fold-down"}}
</button>
<button id="collapse-files-btn" class="ui button tiny tooltip basic" data-content="{{.locale.Tr "repo.pulls.collapse_files"}}">
{{svg "octicon-fold-up"}}
</button>
{{end}}
{{template "repo/diff/whitespace_dropdown" .}}
{{template "repo/diff/options_dropdown" .}}
Expand Down
19 changes: 19 additions & 0 deletions web_src/js/features/pull-view-file.js
Expand Up @@ -4,6 +4,8 @@ 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 +71,20 @@ export function initViewedCheckboxListenerFor() {
});
}
}

export function initExpandFilesButton() {
sillyguodong marked this conversation as resolved.
Show resolved Hide resolved
document.querySelector(expandFilesBtnSelector)?.addEventListener('click', () => {
for (const box of document.querySelectorAll('.file-content[data-folded="true"]')) {
setFileFolding(box, box.querySelector('.fold-file'), false);
}
});
}

export function initCollapseFilesButton() {
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
4 changes: 3 additions & 1 deletion web_src/js/index.js
Expand Up @@ -72,7 +72,7 @@ import {
initRepoSettingsCollaboration,
initRepoSettingSearchTeamBox,
} from './features/repo-settings.js';
import {initViewedCheckboxListenerFor} from './features/pull-view-file.js';
import {initViewedCheckboxListenerFor, initExpandFilesButton, initCollapseFilesButton} from './features/pull-view-file.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 @@ -201,4 +201,6 @@ $(document).ready(() => {
initUserAuthWebAuthnRegister();
initUserSettings();
initViewedCheckboxListenerFor();
initExpandFilesButton();
initCollapseFilesButton();
});