Commit 377afd65 authored by Phil Hughes's avatar Phil Hughes

Enable renaming files & folders in the Web IDE

Closes #44845
parent 2ca8219a
...@@ -109,6 +109,15 @@ export default { ...@@ -109,6 +109,15 @@ export default {
</li> </li>
<li class="divider"></li> <li class="divider"></li>
</template> </template>
<li>
<item-button
:label="__('Rename')"
class="d-flex"
icon="pencil"
icon-classes="mr-2"
@click="createNewItem('rename')"
/>
</li>
<li> <li>
<item-button <item-button
:label="__('Delete')" :label="__('Delete')"
......
...@@ -13,24 +13,30 @@ export default { ...@@ -13,24 +13,30 @@ export default {
}; };
}, },
computed: { computed: {
...mapState(['newEntryModal']), ...mapState(['entryModal']),
entryName: { entryName: {
get() { get() {
return this.name || (this.newEntryModal.path !== '' ? `${this.newEntryModal.path}/` : ''); if (this.entryModal.type === 'rename') return this.name || this.entryModal.entry.name;
return this.name || (this.entryModal.path !== '' ? `${this.entryModal.path}/` : '');
}, },
set(val) { set(val) {
this.name = val; this.name = val;
}, },
}, },
modalTitle() { modalTitle() {
if (this.newEntryModal.type === 'tree') { if (this.entryModal.type === 'rename') return __('Rename');
if (this.entryModal.type === 'tree') {
return __('Create new directory'); return __('Create new directory');
} }
return __('Create new file'); return __('Create new file');
}, },
buttonLabel() { buttonLabel() {
if (this.newEntryModal.type === 'tree') { if (this.entryModal.type === 'rename') return __('Update');
if (this.entryModal.type === 'tree') {
return __('Create directory'); return __('Create directory');
} }
...@@ -42,7 +48,7 @@ export default { ...@@ -42,7 +48,7 @@ export default {
createEntryInStore() { createEntryInStore() {
this.createTempEntry({ this.createTempEntry({
name: this.name, name: this.name,
type: this.newEntryModal.type, type: this.entryModal.type,
}); });
}, },
focusInput() { focusInput() {
......
...@@ -134,8 +134,7 @@ export default { ...@@ -134,8 +134,7 @@ export default {
.replace(/[/]$/g, ''); .replace(/[/]$/g, '');
// - strip ending "/" // - strip ending "/"
const filePath = this.file.path const filePath = this.file.path.replace(/[/]$/g, '');
.replace(/[/]$/g, '');
return filePath === routePath; return filePath === routePath;
}, },
...@@ -208,7 +207,6 @@ export default { ...@@ -208,7 +207,6 @@ export default {
</span> </span>
<new-dropdown <new-dropdown
:type="file.type" :type="file.type"
:branch="file.branchId"
:path="file.path" :path="file.path"
:mouse-over="mouseOver" :mouse-over="mouseOver"
class="float-right prepend-left-8" class="float-right prepend-left-8"
......
...@@ -169,7 +169,11 @@ export default { ...@@ -169,7 +169,11 @@ export default {
}, },
[types.OPEN_NEW_ENTRY_MODAL](state, { type, path }) { [types.OPEN_NEW_ENTRY_MODAL](state, { type, path }) {
Object.assign(state, { Object.assign(state, {
newEntryModal: { type, path }, entryModal: {
type,
path,
entry: { ...state.entries[path] },
},
}); });
}, },
[types.DELETE_ENTRY](state, path) { [types.DELETE_ENTRY](state, path) {
......
...@@ -26,8 +26,9 @@ export default () => ({ ...@@ -26,8 +26,9 @@ export default () => ({
rightPane: null, rightPane: null,
links: {}, links: {},
errorMessage: null, errorMessage: null,
newEntryModal: { entryModal: {
type: '', type: '',
path: '', path: '',
entry: {},
}, },
}); });
---
title: Enable renaming files and folders in Web IDE
merge_request:
author:
type: added
...@@ -15,7 +15,7 @@ describe('new file modal component', () => { ...@@ -15,7 +15,7 @@ describe('new file modal component', () => {
describe(type, () => { describe(type, () => {
beforeEach(() => { beforeEach(() => {
const store = createStore(); const store = createStore();
store.state.newEntryModal = { store.state.entryModal = {
type, type,
path: '', path: '',
}; };
...@@ -55,4 +55,36 @@ describe('new file modal component', () => { ...@@ -55,4 +55,36 @@ describe('new file modal component', () => {
}); });
}); });
}); });
describe('rename entry', () => {
beforeEach(() => {
const store = createStore();
store.state.entryModal = {
type: 'rename',
path: '',
entry: {
name: 'test',
},
};
vm = createComponentWithStore(Component, store).$mount();
});
it('renders title and button for renaming', () => {
expect(vm.$el.querySelector('.modal-title').textContent.trim()).toBe('Rename');
expect(vm.$el.querySelector('.btn-success').textContent.trim()).toBe('Update');
});
describe('entryName', () => {
it('returns entries name', () => {
expect(vm.entryName).toBe('test');
});
it('updated name', () => {
vm.name = 'index.js';
expect(vm.entryName).toBe('index.js');
});
});
});
}); });
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