Initiate editor for any file without content
Important to get file data for any file that has no content set yet: we need this information in order to build a previe for changed/staged files if they were not yet opened in the editor
This commit is contained in:
parent
4c954a5c9e
commit
ff1a4a4241
5 changed files with 81 additions and 14 deletions
|
@ -144,7 +144,9 @@ export default {
|
||||||
'triggerFilesChange',
|
'triggerFilesChange',
|
||||||
]),
|
]),
|
||||||
initEditor() {
|
initEditor() {
|
||||||
if (this.shouldHideEditor) return;
|
if (this.shouldHideEditor && (this.file.content || this.file.raw)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.editor.clearEditor();
|
this.editor.clearEditor();
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as types from '../mutation_types';
|
import * as types from '../mutation_types';
|
||||||
import { sortTree } from '../utils';
|
import { sortTree } from '../utils';
|
||||||
import { diffModes } from '../../constants';
|
import { diffModes } from '../../constants';
|
||||||
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
[types.SET_FILE_ACTIVE](state, { path, active }) {
|
[types.SET_FILE_ACTIVE](state, { path, active }) {
|
||||||
|
@ -35,19 +36,18 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[types.SET_FILE_DATA](state, { data, file }) {
|
[types.SET_FILE_DATA](state, { data, file }) {
|
||||||
Object.assign(state.entries[file.path], {
|
const stateEntry = state.entries[file.path];
|
||||||
id: data.id,
|
const stagedFile = state.stagedFiles.find(f => f.path === file.path);
|
||||||
blamePath: data.blame_path,
|
const openFile = state.openFiles.find(f => f.path === file.path);
|
||||||
commitsPath: data.commits_path,
|
const changedFile = state.changedFiles.find(f => f.path === file.path);
|
||||||
permalink: data.permalink,
|
|
||||||
rawPath: data.raw_path,
|
[stateEntry, stagedFile, openFile, changedFile].forEach(f => {
|
||||||
binary: data.binary,
|
if (f) {
|
||||||
renderError: data.render_error,
|
Object.assign(f, convertObjectPropsToCamelCase(data, { dropKeys: ['raw', 'baseRaw'] }), {
|
||||||
raw: (state.entries[file.path] && state.entries[file.path].raw) || null,
|
raw: (stateEntry && stateEntry.raw) || null,
|
||||||
baseRaw: null,
|
baseRaw: null,
|
||||||
html: data.html,
|
});
|
||||||
size: data.size,
|
}
|
||||||
lastCommitSha: data.last_commit_sha,
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[types.SET_FILE_RAW_DATA](state, { file, raw }) {
|
[types.SET_FILE_RAW_DATA](state, { file, raw }) {
|
||||||
|
|
5
changelogs/unreleased/60856-deleting-binary-file.yml
Normal file
5
changelogs/unreleased/60856-deleting-binary-file.yml
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Removing an image should not output binary data
|
||||||
|
merge_request: 30314
|
||||||
|
author:
|
||||||
|
type: fixed
|
|
@ -30,6 +30,7 @@ describe('RepoEditor', () => {
|
||||||
Vue.set(vm.$store.state.entries, f.path, f);
|
Vue.set(vm.$store.state.entries, f.path, f);
|
||||||
|
|
||||||
spyOn(vm, 'getFileData').and.returnValue(Promise.resolve());
|
spyOn(vm, 'getFileData').and.returnValue(Promise.resolve());
|
||||||
|
spyOn(vm, 'getRawFileData').and.returnValue(Promise.resolve());
|
||||||
|
|
||||||
vm.$mount();
|
vm.$mount();
|
||||||
|
|
||||||
|
@ -407,6 +408,44 @@ describe('RepoEditor', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('initEditor', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
spyOn(vm.editor, 'createInstance');
|
||||||
|
spyOnProperty(vm, 'shouldHideEditor').and.returnValue(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('is being initialised for files without content even if shouldHideEditor is `true`', done => {
|
||||||
|
vm.file.content = '';
|
||||||
|
vm.file.raw = '';
|
||||||
|
|
||||||
|
vm.initEditor();
|
||||||
|
vm.$nextTick()
|
||||||
|
.then(() => {
|
||||||
|
expect(vm.getFileData).toHaveBeenCalled();
|
||||||
|
expect(vm.getRawFileData).toHaveBeenCalled();
|
||||||
|
})
|
||||||
|
.then(done)
|
||||||
|
.catch(done.fail);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not initialize editor for files already with content', done => {
|
||||||
|
expect(vm.getFileData.calls.count()).toEqual(1);
|
||||||
|
expect(vm.getRawFileData.calls.count()).toEqual(1);
|
||||||
|
|
||||||
|
vm.file.content = 'foo';
|
||||||
|
|
||||||
|
vm.initEditor();
|
||||||
|
vm.$nextTick()
|
||||||
|
.then(() => {
|
||||||
|
expect(vm.getFileData.calls.count()).toEqual(1);
|
||||||
|
expect(vm.getRawFileData.calls.count()).toEqual(1);
|
||||||
|
expect(vm.editor.createInstance).not.toHaveBeenCalled();
|
||||||
|
})
|
||||||
|
.then(done)
|
||||||
|
.catch(done.fail);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('calls removePendingTab when old file is pending', done => {
|
it('calls removePendingTab when old file is pending', done => {
|
||||||
spyOnProperty(vm, 'shouldHideEditor').and.returnValue(true);
|
spyOnProperty(vm, 'shouldHideEditor').and.returnValue(true);
|
||||||
spyOn(vm, 'removePendingTab');
|
spyOn(vm, 'removePendingTab');
|
||||||
|
@ -416,6 +455,7 @@ describe('RepoEditor', () => {
|
||||||
vm.$nextTick()
|
vm.$nextTick()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
vm.file = file('testing');
|
vm.file = file('testing');
|
||||||
|
vm.file.content = 'foo'; // need to prevent full cycle of initEditor
|
||||||
|
|
||||||
return vm.$nextTick();
|
return vm.$nextTick();
|
||||||
})
|
})
|
||||||
|
|
|
@ -83,6 +83,26 @@ describe('IDE store file mutations', () => {
|
||||||
expect(localFile.raw).toBeNull();
|
expect(localFile.raw).toBeNull();
|
||||||
expect(localFile.baseRaw).toBeNull();
|
expect(localFile.baseRaw).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('sets extra file data to all arrays concerned', () => {
|
||||||
|
localState.stagedFiles = [localFile];
|
||||||
|
localState.changedFiles = [localFile];
|
||||||
|
localState.openFiles = [localFile];
|
||||||
|
|
||||||
|
const rawPath = 'foo/bar/blah.md';
|
||||||
|
|
||||||
|
mutations.SET_FILE_DATA(localState, {
|
||||||
|
data: {
|
||||||
|
raw_path: rawPath,
|
||||||
|
},
|
||||||
|
file: localFile,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(localState.stagedFiles[0].rawPath).toEqual(rawPath);
|
||||||
|
expect(localState.changedFiles[0].rawPath).toEqual(rawPath);
|
||||||
|
expect(localState.openFiles[0].rawPath).toEqual(rawPath);
|
||||||
|
expect(localFile.rawPath).toEqual(rawPath);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('SET_FILE_RAW_DATA', () => {
|
describe('SET_FILE_RAW_DATA', () => {
|
||||||
|
|
Loading…
Reference in a new issue