diff options
author | Phil Hughes <me@iamphill.com> | 2019-02-15 11:34:20 +0000 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-02-15 11:34:20 +0000 |
commit | ae8d167a7ea5bd7ff3d4a954b3af74921077cca5 (patch) | |
tree | 1ced9390512f7e1729d9fea88716f774c1c8a217 | |
parent | efd698e9159a7292f6c82cf98183f4821a78e84f (diff) | |
download | gitlab-ce-expand-diff-to-full-file.tar.gz |
Fully expand inline diff fileexpand-diff-to-full-file
[ci skip]
-rw-r--r-- | app/assets/javascripts/diffs/components/diff_file_header.vue | 2 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/actions.js | 19 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/store/mutations.js | 24 |
3 files changed, 37 insertions, 8 deletions
diff --git a/app/assets/javascripts/diffs/components/diff_file_header.vue b/app/assets/javascripts/diffs/components/diff_file_header.vue index 589cdf8e663..1d230c9a4cc 100644 --- a/app/assets/javascripts/diffs/components/diff_file_header.vue +++ b/app/assets/javascripts/diffs/components/diff_file_header.vue @@ -118,7 +118,7 @@ export default { return `\`${this.diffFile.file_path}\``; }, showExpandFullFileButton() { - return this.$options.expandFullDiffEnabled && this.diffFile.is_fully_expanded; + return (this.$options.expandFullDiffEnabled && this.diffFile.is_fully_expanded) || true; }, }, mounted() { diff --git a/app/assets/javascripts/diffs/store/actions.js b/app/assets/javascripts/diffs/store/actions.js index 55ee79484c4..c5b06369bcf 100644 --- a/app/assets/javascripts/diffs/store/actions.js +++ b/app/assets/javascripts/diffs/store/actions.js @@ -278,8 +278,23 @@ export const closeDiffFileCommentForm = ({ commit }, fileHash) => { commit(types.CLOSE_DIFF_FILE_COMMENT_FORM, fileHash); }; -export const toggleFullDiff = ({ commit }, filePath) => { - commit(types.TOGGLE_FULL_DIFF_FILE, { filePath, data: {} }); +export const toggleFullDiff = ({ commit, state }, filePath) => { + const file = state.diffFiles.find(f => f.file_path === filePath); + + return axios + .get(file.context_lines_path, { + params: { + full: true, + from_merge_request: true, + to: 0, + bottom: 0, + since: 0, + offset: 0, + }, + }) + .then(({ data }) => { + commit(types.TOGGLE_FULL_DIFF_FILE, { filePath, data }); + }); }; // prevent babel-plugin-rewire from generating an invalid default during karma tests diff --git a/app/assets/javascripts/diffs/store/mutations.js b/app/assets/javascripts/diffs/store/mutations.js index f3cfe0c428c..418c0b120ac 100644 --- a/app/assets/javascripts/diffs/store/mutations.js +++ b/app/assets/javascripts/diffs/store/mutations.js @@ -239,12 +239,26 @@ export default { state.tree = tree; }, [types.TOGGLE_FULL_DIFF_FILE](state, { filePath, data }) { - state.diffFiles = state.diffFiles.map(file => { - if (file.file_path === filePath) { - return { ...file, ...data, isShowingFullFile: !file.isShowingFullFile }; + const file = state.diffFiles.find(f => f.file_path === filePath); + + file.highlighted_diff_lines = file.highlighted_diff_lines.reduce((acc, line, i) => { + if (line.type === 'match') { + const before = file.highlighted_diff_lines[i - 1]; + const beforeIndex = before ? before.new_line : 0; + const after = file.highlighted_diff_lines[i + 1]; + const afterIndex = after ? after.new_line - 1 : data.length; + const lines = data.slice(beforeIndex, afterIndex).map((l, a) => ({ + ...l, + old_line: before.old_line + a + 1, + new_line: before.new_line + a + 1, + })); + + acc.push(...lines); + } else { + acc.push(line); } - return file; - }); + return acc; + }, []); }, }; |