Skip to content

Commit c0da363

Browse files
zeripathjolheiserlunny
authored
Restore function to "Show more" buttons (#22399)
There was a serious regression in #21012 which broke the Show More button on the diff page, and the show more button was also broken on the file tree too. This PR fixes this by resetting the pageData.diffFiles as the vue watched value and reattachs a function to the show more button outside of the file tree view. Fix #22380 Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: John Olheiser <[email protected]> Co-authored-by: Lunny Xiao <[email protected]>
1 parent 99cf0d3 commit c0da363

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

templates/repo/diff/box.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
{{$.locale.Tr "repo.diff.file_suppressed_line_too_long"}}
144144
{{else}}
145145
{{$.locale.Tr "repo.diff.file_suppressed"}}
146-
<a class="ui basic tiny button diff-show-more-button" data-href="{{$.Link}}?file-only=true&files={{$file.Name}}&files={{$file.OldName}}">{{$.locale.Tr "repo.diff.load"}}</a>
146+
<a class="ui basic tiny button diff-load-button" data-href="{{$.Link}}?file-only=true&files={{$file.Name}}&files={{$file.OldName}}">{{$.locale.Tr "repo.diff.load"}}</a>
147147
{{end}}
148148
{{else}}
149149
{{$.locale.Tr "repo.diff.bin_not_shown"}}

web_src/js/components/DiffFileTree.vue

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<DiffFileTreeItem v-for="item in fileTree" :key="item.name" :item="item" />
99
</div>
1010
<div v-if="isIncomplete" id="diff-too-many-files-stats" class="pt-2">
11-
<span>{{ tooManyFilesMessage }}</span><a :class="['ui', 'basic', 'tiny', 'button', isLoadingNewData === true ? 'disabled' : '']" id="diff-show-more-files-stats" @click.stop="loadMoreData">{{ showMoreMessage }}</a>
11+
<span class="mr-2">{{ tooManyFilesMessage }}</span><a :class="['ui', 'basic', 'tiny', 'button', isLoadingNewData === true ? 'disabled' : '']" id="diff-show-more-files-stats" @click.stop="loadMoreData">{{ showMoreMessage }}</a>
1212
</div>
1313
</div>
1414
</template>
@@ -94,6 +94,9 @@ export default {
9494
mounted() {
9595
// ensure correct buttons when we are mounted to the dom
9696
this.adjustToggleButton(this.fileTreeIsVisible);
97+
// replace the pageData.diffFileInfo.files with our watched data so we get updates
98+
pageData.diffFileInfo.files = this.files;
99+
97100
document.querySelector('.diff-toggle-file-tree-button').addEventListener('click', this.toggleVisibility);
98101
},
99102
unmounted() {

web_src/js/features/repo-diff.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,47 @@ function onShowMoreFiles() {
119119

120120
export function doLoadMoreFiles(link, diffEnd, callback) {
121121
const url = `${link}?skip-to=${diffEnd}&file-only=true`;
122+
loadMoreFiles(url, callback);
123+
}
124+
125+
function loadMoreFiles(url, callback) {
126+
const $target = $('a#diff-show-more-files');
127+
if ($target.hasClass('disabled')) {
128+
callback();
129+
return;
130+
}
131+
$target.addClass('disabled');
122132
$.ajax({
123133
type: 'GET',
124134
url,
125135
}).done((resp) => {
126136
if (!resp) {
137+
$target.removeClass('disabled');
127138
callback(resp);
128139
return;
129140
}
141+
$('#diff-incomplete').replaceWith($(resp).find('#diff-file-boxes').children());
130142
// By simply rerunning the script we add the new data to our existing
131143
// pagedata object. this triggers vue and the filetree and filelist will
132144
// render the new elements.
133145
$('body').append($(resp).find('script#diff-data-script'));
146+
onShowMoreFiles();
134147
callback(resp);
135148
}).fail(() => {
149+
$target.removeClass('disabled');
136150
callback();
137151
});
138152
}
139153

140154
export function initRepoDiffShowMore() {
141-
$(document).on('click', 'a.diff-show-more-button', (e) => {
155+
$(document).on('click', 'a#diff-show-more-files', (e) => {
156+
e.preventDefault();
157+
158+
const $target = $(e.target);
159+
loadMoreFiles($target.data('href'), () => {});
160+
});
161+
162+
$(document).on('click', 'a.diff-load-button', (e) => {
142163
e.preventDefault();
143164
const $target = $(e.target);
144165

web_src/less/_repository.less

+3
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,9 @@
16671667
background-color: var(--color-teal);
16681668
}
16691669
}
1670+
.button {
1671+
padding: 8px 12px;
1672+
}
16701673
}
16711674

16721675
.diff-box .header:not(.resolved-placeholder) {

0 commit comments

Comments
 (0)