Commit e74e6fcb authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'axios-get-single-file-diff' into 'master'

Replace $.get in single file diff with axios

See merge request gitlab-org/gitlab-ce!16696
parents 5f1a09e2 dfc62605
/* 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')
......
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