Commit 3e2d0e1a authored by Phil Hughes's avatar Phil Hughes

fixed opening/changing/closing files

[ci skip]
parent f6240a82
...@@ -31,13 +31,13 @@ ...@@ -31,13 +31,13 @@
}, },
}, },
computed: { computed: {
...mapState([
'changedFiles',
'openFiles',
]),
...mapGetters([ ...mapGetters([
'activeFile', 'activeFile',
]), ]),
...mapGetters({
openFiles: 'openFilesMap',
changedFiles: 'changedFilesMap',
}),
}, },
mounted() { mounted() {
const returnValue = 'Are you sure you want to lose unsaved changes?'; const returnValue = 'Are you sure you want to lose unsaved changes?';
......
<script> <script>
import { mapState, mapGetters, mapActions } from 'vuex'; import { mapState } from 'vuex';
import icon from '~/vue_shared/components/icon.vue'; import icon from '~/vue_shared/components/icon.vue';
import panelResizer from '~/vue_shared/components/panel_resizer.vue'; import panelResizer from '~/vue_shared/components/panel_resizer.vue';
import repoCommitSection from './repo_commit_section.vue'; import repoCommitSection from './repo_commit_section.vue';
...@@ -24,11 +24,9 @@ ...@@ -24,11 +24,9 @@
}, },
computed: { computed: {
...mapState([ ...mapState([
'changedFiles',
'rightPanelCollapsed', 'rightPanelCollapsed',
]), ]),
...mapGetters({
changedFiles: 'changedFilesMap',
}),
currentIcon() { currentIcon() {
return this.rightPanelCollapsed ? 'angle-double-left' : 'angle-double-right'; return this.rightPanelCollapsed ? 'angle-double-left' : 'angle-double-right';
}, },
......
<script> <script>
import { mapState, mapActions } from 'vuex'; import { mapState } from 'vuex';
import icon from '~/vue_shared/components/icon.vue'; import icon from '~/vue_shared/components/icon.vue';
import panelResizer from '~/vue_shared/components/panel_resizer.vue'; import panelResizer from '~/vue_shared/components/panel_resizer.vue';
import skeletonLoadingContainer from '~/vue_shared/components/skeleton_loading_container.vue'; import skeletonLoadingContainer from '~/vue_shared/components/skeleton_loading_container.vue';
......
...@@ -36,10 +36,8 @@ export default { ...@@ -36,10 +36,8 @@ export default {
'currentBranchId', 'currentBranchId',
'rightPanelCollapsed', 'rightPanelCollapsed',
'lastCommitMsg', 'lastCommitMsg',
'changedFiles',
]), ]),
...mapGetters({
changedFiles: 'changedFilesMap',
}),
...mapState('commit', [ ...mapState('commit', [
'commitMessage', 'commitMessage',
'submitCommitLoading', 'submitCommitLoading',
......
<script> <script>
import { mapState } from 'vuex';
import timeAgoMixin from '~/vue_shared/mixins/timeago'; import timeAgoMixin from '~/vue_shared/mixins/timeago';
import skeletonLoadingContainer from '~/vue_shared/components/skeleton_loading_container.vue'; import skeletonLoadingContainer from '~/vue_shared/components/skeleton_loading_container.vue';
import fileIcon from '~/vue_shared/components/file_icon.vue'; import fileIcon from '~/vue_shared/components/file_icon.vue';
...@@ -130,11 +128,12 @@ ...@@ -130,11 +128,12 @@
</template> </template>
</div> </div>
</div> </div>
<repo-file <template v-if="file.opened">
v-if="file.opened" <repo-file
v-for="childFile in file.tree" v-for="childFile in file.tree"
:key="childFile.key" :key="childFile.key"
:file="childFile" :file="childFile"
/> />
</template>
</div> </div>
</template> </template>
<script> <script>
import { mapGetters } from 'vuex';
export default { export default {
props: { props: {
file: { file: {
......
<script> <script>
import { mapGetters } from 'vuex';
import RepoTab from './repo_tab.vue'; import RepoTab from './repo_tab.vue';
export default { export default {
components: { components: {
'repo-tab': RepoTab, RepoTab,
}, },
props: { props: {
files: { files: {
...@@ -12,11 +11,6 @@ ...@@ -12,11 +11,6 @@
required: true, required: true,
}, },
}, },
computed: {
...mapGetters([
'openFilesMap',
]),
},
}; };
</script> </script>
......
...@@ -82,11 +82,11 @@ export const changeFileContent = ({ state, commit }, { path, content }) => { ...@@ -82,11 +82,11 @@ export const changeFileContent = ({ state, commit }, { path, content }) => {
const file = state.entries[path]; const file = state.entries[path];
commit(types.UPDATE_FILE_CONTENT, { path, content }); commit(types.UPDATE_FILE_CONTENT, { path, content });
const indexOfChangedFile = state.changedFiles.indexOf(path); const indexOfChangedFile = state.changedFiles.findIndex(f => f.path === path);
if (!file.changed && indexOfChangedFile === -1) { if (file.changed && indexOfChangedFile === -1) {
commit(types.ADD_FILE_TO_CHANGED, path); commit(types.ADD_FILE_TO_CHANGED, path);
} else if (file.changed && indexOfChangedFile !== -1) { } else if (!file.changed && indexOfChangedFile !== -1) {
commit(types.REMOVE_FILE_FROM_CHANGED, path); commit(types.REMOVE_FILE_FROM_CHANGED, path);
} }
}; };
......
export const openFilesMap = state => state.openFiles.map(path => state.entries[path]); export const activeFile = state => state.openFiles.find(file => file.active) || null;
export const changedFilesMap = state => state.changedFiles.map(path => state.entries[path]);
export const activeFile = state => openFilesMap(state).find(file => file.active) || null;
export const canEditFile = (state) => { export const canEditFile = (state) => {
const currentActiveFile = activeFile(state); const currentActiveFile = activeFile(state);
...@@ -10,9 +7,9 @@ export const canEditFile = (state) => { ...@@ -10,9 +7,9 @@ export const canEditFile = (state) => {
(currentActiveFile && !currentActiveFile.renderError && !currentActiveFile.binary); (currentActiveFile && !currentActiveFile.renderError && !currentActiveFile.binary);
}; };
export const addedFiles = state => changedFilesMap(state).filter(f => f.tempFile); export const addedFiles = state => state.changedFiles.filter(f => f.tempFile);
export const modifiedFiles = state => changedFilesMap(state).filter(f => !f.tempFile); export const modifiedFiles = state => state.changedFiles.filter(f => !f.tempFile);
export const treeList = (state) => { export const treeList = (state) => {
const tree = state.trees[`${state.currentProjectId}/master`]; const tree = state.trees[`${state.currentProjectId}/master`];
......
export const SET_INITIAL_DATA = 'SET_INITIAL_DATA'; export const SET_INITIAL_DATA = 'SET_INITIAL_DATA';
export const TOGGLE_LOADING = 'TOGGLE_LOADING'; export const TOGGLE_LOADING = 'TOGGLE_LOADING';
export const SET_PARENT_TREE_URL = 'SET_PARENT_TREE_URL';
export const SET_LAST_COMMIT_DATA = 'SET_LAST_COMMIT_DATA'; export const SET_LAST_COMMIT_DATA = 'SET_LAST_COMMIT_DATA';
export const SET_LAST_COMMIT_MSG = 'SET_LAST_COMMIT_MSG'; export const SET_LAST_COMMIT_MSG = 'SET_LAST_COMMIT_MSG';
export const SET_LEFT_PANEL_COLLAPSED = 'SET_LEFT_PANEL_COLLAPSED'; export const SET_LEFT_PANEL_COLLAPSED = 'SET_LEFT_PANEL_COLLAPSED';
......
...@@ -10,14 +10,8 @@ export default { ...@@ -10,14 +10,8 @@ export default {
}, },
[types.TOGGLE_LOADING](state, { entry, forceValue = undefined }) { [types.TOGGLE_LOADING](state, { entry, forceValue = undefined }) {
if (entry.path) { if (entry.path) {
Object.assign(state, { Object.assign(state.entries[entry.path], {
entries: { loading: forceValue !== undefined ? forceValue : !state.entries[entry.path].loading,
...state.entries,
[entry.path]: {
...state.entries[entry.path],
loading: forceValue !== undefined ? forceValue : !state.entries[entry.path].loading,
},
},
}); });
} else { } else {
Object.assign(entry, { Object.assign(entry, {
...@@ -41,7 +35,6 @@ export default { ...@@ -41,7 +35,6 @@ export default {
}); });
}, },
[types.SET_LAST_COMMIT_DATA](state, { entry, lastCommit }) { [types.SET_LAST_COMMIT_DATA](state, { entry, lastCommit }) {
console.log(entry);
Object.assign(entry.lastCommit, { Object.assign(entry.lastCommit, {
id: lastCommit.commit.id, id: lastCommit.commit.id,
url: lastCommit.commit_path, url: lastCommit.commit_path,
......
...@@ -12,9 +12,11 @@ export default { ...@@ -12,9 +12,11 @@ export default {
}); });
if (state.entries[path].opened) { if (state.entries[path].opened) {
state.openFiles.push(path); state.openFiles.push(state.entries[path]);
} else { } else {
state.openFiles.splice(state.openFiles.indexOf(path), 1); Object.assign(state, {
openFiles: state.openFiles.filter(f => f.path !== path),
});
} }
}, },
[types.SET_FILE_DATA](state, { data, file }) { [types.SET_FILE_DATA](state, { data, file }) {
...@@ -67,10 +69,14 @@ export default { ...@@ -67,10 +69,14 @@ export default {
parent.tree.push(file); parent.tree.push(file);
}, },
[types.ADD_FILE_TO_CHANGED](state, path) { [types.ADD_FILE_TO_CHANGED](state, path) {
state.changedFiles.push(path); Object.assign(state, {
changedFiles: state.changedFiles.concat(state.entries[path]),
});
}, },
[types.REMOVE_FILE_FROM_CHANGED](state, path) { [types.REMOVE_FILE_FROM_CHANGED](state, path) {
state.changedFiles.splice(state.changedFiles.indexOf(path), 1); Object.assign(state, {
changedFiles: state.changedFiles.filter(f => f.path !== path),
});
}, },
[types.TOGGLE_FILE_CHANGED](state, { file, changed }) { [types.TOGGLE_FILE_CHANGED](state, { file, changed }) {
Object.assign(state.entries[file.path], { Object.assign(state.entries[file.path], {
......
...@@ -21,11 +21,6 @@ export default { ...@@ -21,11 +21,6 @@ export default {
tree: data, tree: data,
}); });
}, },
[types.SET_PARENT_TREE_URL](state, url) {
Object.assign(state, {
parentTreeUrl: url,
});
},
[types.SET_LAST_COMMIT_URL](state, { tree = state, url }) { [types.SET_LAST_COMMIT_URL](state, { tree = state, url }) {
Object.assign(tree, { Object.assign(tree, {
lastCommitPath: url, lastCommitPath: url,
......
...@@ -47,14 +47,6 @@ describe('Multi-file store tree mutations', () => { ...@@ -47,14 +47,6 @@ describe('Multi-file store tree mutations', () => {
}); });
}); });
describe('SET_PARENT_TREE_URL', () => {
it('sets the parent tree url', () => {
mutations.SET_PARENT_TREE_URL(localState, 'test');
expect(localState.parentTreeUrl).toBe('test');
});
});
describe('CREATE_TMP_TREE', () => { describe('CREATE_TMP_TREE', () => {
it('adds tree into parent tree', () => { it('adds tree into parent tree', () => {
const tmpEntry = file('tmpTree'); const tmpEntry = file('tmpTree');
......
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