Skip to content
Snippets Groups Projects
Unverified Commit e7fe50bf authored by Phil Hughes's avatar Phil Hughes
Browse files

rename files

not working for folders yet
parent 73473dfc
No related branches found
No related tags found
1 merge request!10495Merge Requests - Assignee
Loading
Loading
@@ -44,12 +44,19 @@ export default {
},
},
methods: {
...mapActions(['createTempEntry']),
createEntryInStore() {
this.createTempEntry({
name: this.name,
type: this.entryModal.type,
});
...mapActions(['createTempEntry', 'renameEntry']),
submitForm() {
if (this.entryModal.type === 'rename') {
this.renameEntry({
path: this.entryModal.entry.path,
name: this.entryName,
});
} else {
this.createTempEntry({
name: this.name,
type: this.entryModal.type,
});
}
},
focusInput() {
setTimeout(() => {
Loading
Loading
@@ -66,7 +73,7 @@ export default {
:header-title-text="modalTitle"
:footer-primary-button-text="buttonLabel"
footer-primary-button-variant="success"
@submit="createEntryInStore"
@submit="submitForm"
@open="focusInput"
>
<div
Loading
Loading
Loading
Loading
@@ -193,6 +193,11 @@ export const deleteEntry = ({ commit, dispatch, state }, path) => {
 
export const resetOpenFiles = ({ commit }) => commit(types.RESET_OPEN_FILES);
 
export const renameEntry = ({ dispatch, commit }, { path, name }) => {
commit(types.RENAME_ENTRY, { path, name });
dispatch('deleteEntry', path);
};
export * from './actions/tree';
export * from './actions/file';
export * from './actions/project';
Loading
Loading
Loading
Loading
@@ -77,3 +77,4 @@ export const SET_ERROR_MESSAGE = 'SET_ERROR_MESSAGE';
 
export const OPEN_NEW_ENTRY_MODAL = 'OPEN_NEW_ENTRY_MODAL';
export const DELETE_ENTRY = 'DELETE_ENTRY';
export const RENAME_ENTRY = 'RENAME_ENTRY';
Loading
Loading
@@ -131,11 +131,14 @@ export default {
},
[types.UPDATE_FILE_AFTER_COMMIT](state, { file, lastCommit }) {
const changedFile = state.changedFiles.find(f => f.path === file.path);
const { prevPath } = file;
 
Object.assign(state.entries[file.path], {
raw: file.content,
changed: !!changedFile,
staged: false,
prevPath: '',
moved: false,
lastCommit: Object.assign(state.entries[file.path].lastCommit, {
id: lastCommit.commit.id,
url: lastCommit.commit_path,
Loading
Loading
@@ -144,6 +147,18 @@ export default {
updatedAt: lastCommit.commit.authored_date,
}),
});
if (prevPath) {
// Update URLs after file has moved
const regex = new RegExp(`${prevPath}$`);
Object.assign(state.entries[file.path], {
rawPath: file.rawPath.replace(regex, file.name),
permalink: file.permalink.replace(regex, file.name),
commitsPath: file.commitsPath.replace(regex, file.name),
blamePath: file.blamePath.replace(regex, file.name),
});
}
},
[types.BURST_UNUSED_SEAL](state) {
Object.assign(state, {
Loading
Loading
@@ -186,6 +201,28 @@ export default {
state.changedFiles = state.changedFiles.concat(entry);
parent.tree = parent.tree.filter(f => f.path !== entry.path);
},
[types.RENAME_ENTRY](state, { path, name }) {
const oldEntry = state.entries[path];
const parent = oldEntry.parentPath
? state.entries[oldEntry.parentPath]
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
const nameRegex = new RegExp(`${oldEntry.name}$`);
const newPath = path.replace(nameRegex, name);
state.entries[newPath] = {
...oldEntry,
id: newPath,
key: `${name}-${oldEntry.type}-${oldEntry.id}`,
path: newPath,
name,
tempFile: true,
prevPath: path,
url: oldEntry.url.replace(nameRegex, name),
};
oldEntry.moved = true;
parent.tree = parent.tree.concat(state.entries[newPath]);
state.changedFiles = state.changedFiles.concat(state.entries[newPath]);
},
...projectMutations,
...mergeRequestMutation,
...fileMutations,
Loading
Loading
Loading
Loading
@@ -47,6 +47,8 @@ export const dataStructure = () => ({
lastOpenedAt: 0,
mrChange: null,
deleted: false,
prevPath: '',
moved: false,
});
 
export const decorateData = entity => {
Loading
Loading
@@ -107,7 +109,9 @@ export const setPageTitle = title => {
};
 
export const commitActionForFile = file => {
if (file.deleted) {
if (file.prevPath !== '') {
return 'move';
} else if (file.deleted) {
return 'delete';
} else if (file.tempFile) {
return 'create';
Loading
Loading
@@ -118,6 +122,8 @@ export const commitActionForFile = file => {
 
export const getCommitFiles = (stagedFiles, deleteTree = false) =>
stagedFiles.reduce((acc, file) => {
if (file.moved) return acc;
if ((file.deleted || deleteTree) && file.type === 'tree') {
return acc.concat(getCommitFiles(file.tree, true));
}
Loading
Loading
@@ -134,9 +140,10 @@ export const createCommitPayload = ({ branch, getters, newBranch, state, rootSta
actions: getCommitFiles(rootState.stagedFiles).map(f => ({
action: commitActionForFile(f),
file_path: f.path,
previous_path: f.prevPath === '' ? undefined : f.prevPath,
content: f.content,
encoding: f.base64 ? 'base64' : 'text',
last_commit_id: newBranch || f.deleted ? undefined : f.lastCommitSha,
last_commit_id: newBranch || f.deleted || f.prevPath ? undefined : f.lastCommitSha,
})),
start_branch: newBranch ? rootState.currentBranchId : undefined,
});
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment