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 */ /* 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 FilesCommentButton from './files_comment_button';
import imageDiffHelper from './image_diff/helpers/index'; import imageDiffHelper from './image_diff/helpers/index';
import syntaxHighlight from './syntax_highlight'; import syntaxHighlight from './syntax_highlight';
...@@ -60,30 +63,31 @@ export default class SingleFileDiff { ...@@ -60,30 +63,31 @@ export default class SingleFileDiff {
getContentHTML(cb) { getContentHTML(cb) {
this.collapsedContent.hide(); this.collapsedContent.hide();
this.loadingContent.show(); this.loadingContent.show();
$.get(this.diffForPath, (function(_this) {
return function(data) { axios.get(this.diffForPath)
_this.loadingContent.hide(); .then(({ data }) => {
this.loadingContent.hide();
if (data.html) { if (data.html) {
_this.content = $(data.html); this.content = $(data.html);
syntaxHighlight(_this.content); syntaxHighlight(this.content);
} else { } else {
_this.hasError = true; this.hasError = true;
_this.content = $(ERROR_HTML); this.content = $(ERROR_HTML);
} }
_this.collapsedContent.after(_this.content); this.collapsedContent.after(this.content);
if (typeof gl.diffNotesCompileComponents !== 'undefined') { if (typeof gl.diffNotesCompileComponents !== 'undefined') {
gl.diffNotesCompileComponents(); gl.diffNotesCompileComponents();
} }
const $file = $(_this.file); const $file = $(this.file);
FilesCommentButton.init($file); FilesCommentButton.init($file);
const canCreateNote = $file.closest('.files').is('[data-can-create-note]'); const canCreateNote = $file.closest('.files').is('[data-can-create-note]');
imageDiffHelper.initImageDiff($file[0], canCreateNote); imageDiffHelper.initImageDiff($file[0], canCreateNote);
if (cb) cb(); if (cb) cb();
}; })
})(this)); .catch(createFlash(__('An error occurred while retrieving diff')));
} }
} }
...@@ -112,13 +112,6 @@ feature 'Expand and collapse diffs', :js do ...@@ -112,13 +112,6 @@ feature 'Expand and collapse diffs', :js do
wait_for_requests wait_for_requests
end 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 it 'shows the diff content' do
expect(large_diff).to have_selector('.code') expect(large_diff).to have_selector('.code')
expect(large_diff).not_to have_selector('.nothing-here-block') 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