Commit 5b41ac97 authored by Robert Hunt's avatar Robert Hunt

Merge branch 'load-diff-stats-async' into 'master'

Load diff stats for async diffs

See merge request gitlab-org/gitlab!84039
parents d74aea9c 08bfdf81
...@@ -27,8 +27,34 @@ initCommitBoxInfo(); ...@@ -27,8 +27,34 @@ initCommitBoxInfo();
initDeprecatedNotes(); initDeprecatedNotes();
const loadDiffStats = () => {
const diffStatsElements = document.querySelectorAll('#js-diff-stats');
if (diffStatsElements.length) {
diffStatsElements.forEach((diffStatsEl) => {
const { addedLines, removedLines, oldSize, newSize, viewerName } = diffStatsEl.dataset;
new Vue({
el: diffStatsEl,
render(createElement) {
return createElement(DiffStats, {
props: {
diffFile: {
old_size: oldSize,
new_size: newSize,
viewer: { name: viewerName },
},
addedLines: Number(addedLines),
removedLines: Number(removedLines),
},
});
},
});
});
}
};
const filesContainer = $('.js-diffs-batch'); const filesContainer = $('.js-diffs-batch');
const diffStatsElements = document.querySelectorAll('#js-diff-stats');
if (filesContainer.length) { if (filesContainer.length) {
const batchPath = filesContainer.data('diffFilesPath'); const batchPath = filesContainer.data('diffFilesPath');
...@@ -40,35 +66,14 @@ if (filesContainer.length) { ...@@ -40,35 +66,14 @@ if (filesContainer.length) {
syntaxHighlight(filesContainer); syntaxHighlight(filesContainer);
handleLocationHash(); handleLocationHash();
new Diff(); new Diff();
loadDiffStats();
}) })
.catch(() => { .catch(() => {
createFlash({ message: __('An error occurred while retrieving diff files') }); createFlash({ message: __('An error occurred while retrieving diff files') });
}); });
} else { } else {
new Diff(); new Diff();
} loadDiffStats();
if (diffStatsElements.length) {
diffStatsElements.forEach((diffStatsEl) => {
const { addedLines, removedLines, oldSize, newSize, viewerName } = diffStatsEl.dataset;
new Vue({
el: diffStatsEl,
render(createElement) {
return createElement(DiffStats, {
props: {
diffFile: {
old_size: oldSize,
new_size: newSize,
viewer: { name: viewerName },
},
addedLines: Number(addedLines),
removedLines: Number(removedLines),
},
});
},
});
});
} }
loadAwardsHandler(); loadAwardsHandler();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment