Replace $.get in single file diff with axios
This commit is contained in:
parent
5f1a09e21a
commit
dfc626059b
2 changed files with 15 additions and 18 deletions
|
@ -1,5 +1,8 @@
|
|||
/* eslint-disable func-names, prefer-arrow-callback, space-before-function-paren, no-var, prefer-rest-params, wrap-iife, one-var, one-var-declaration-per-line, consistent-return, no-param-reassign, max-len */
|
||||
|
||||
import { __ } from './locale';
|
||||
import axios from './lib/utils/axios_utils';
|
||||
import createFlash from './flash';
|
||||
import FilesCommentButton from './files_comment_button';
|
||||
import imageDiffHelper from './image_diff/helpers/index';
|
||||
import syntaxHighlight from './syntax_highlight';
|
||||
|
@ -60,30 +63,31 @@ export default class SingleFileDiff {
|
|||
getContentHTML(cb) {
|
||||
this.collapsedContent.hide();
|
||||
this.loadingContent.show();
|
||||
$.get(this.diffForPath, (function(_this) {
|
||||
return function(data) {
|
||||
_this.loadingContent.hide();
|
||||
|
||||
axios.get(this.diffForPath)
|
||||
.then(({ data }) => {
|
||||
this.loadingContent.hide();
|
||||
if (data.html) {
|
||||
_this.content = $(data.html);
|
||||
syntaxHighlight(_this.content);
|
||||
this.content = $(data.html);
|
||||
syntaxHighlight(this.content);
|
||||
} else {
|
||||
_this.hasError = true;
|
||||
_this.content = $(ERROR_HTML);
|
||||
this.hasError = true;
|
||||
this.content = $(ERROR_HTML);
|
||||
}
|
||||
_this.collapsedContent.after(_this.content);
|
||||
this.collapsedContent.after(this.content);
|
||||
|
||||
if (typeof gl.diffNotesCompileComponents !== 'undefined') {
|
||||
gl.diffNotesCompileComponents();
|
||||
}
|
||||
|
||||
const $file = $(_this.file);
|
||||
const $file = $(this.file);
|
||||
FilesCommentButton.init($file);
|
||||
|
||||
const canCreateNote = $file.closest('.files').is('[data-can-create-note]');
|
||||
imageDiffHelper.initImageDiff($file[0], canCreateNote);
|
||||
|
||||
if (cb) cb();
|
||||
};
|
||||
})(this));
|
||||
})
|
||||
.catch(createFlash(__('An error occurred while retrieving diff')));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,13 +112,6 @@ feature 'Expand and collapse diffs', :js do
|
|||
wait_for_requests
|
||||
end
|
||||
|
||||
it 'makes a request to get the content' do
|
||||
ajax_uris = evaluate_script('ajaxUris')
|
||||
|
||||
expect(ajax_uris).not_to be_empty
|
||||
expect(ajax_uris.first).to include('large_diff.md')
|
||||
end
|
||||
|
||||
it 'shows the diff content' do
|
||||
expect(large_diff).to have_selector('.code')
|
||||
expect(large_diff).not_to have_selector('.nothing-here-block')
|
||||
|
|
Loading…
Reference in a new issue