Commit 64a32d6c authored by Chris Toynbee's avatar Chris Toynbee Committed by Paul Slaughter

Encapsulate file view modes with constants

parent 43626526
...@@ -4,7 +4,12 @@ import { viewerInformationForPath } from '~/vue_shared/components/content_viewer ...@@ -4,7 +4,12 @@ import { viewerInformationForPath } from '~/vue_shared/components/content_viewer
import flash from '~/flash'; import flash from '~/flash';
import ContentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue'; import ContentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue';
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue'; import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
import { activityBarViews, viewerTypes } from '../constants'; import {
activityBarViews,
viewerTypes,
FILE_VIEW_MODE_EDITOR,
FILE_VIEW_MODE_PREVIEW,
} from '../constants';
import Editor from '../lib/editor'; import Editor from '../lib/editor';
import ExternalLink from './external_link.vue'; import ExternalLink from './external_link.vue';
import FileTemplatesBar from './file_templates/bar.vue'; import FileTemplatesBar from './file_templates/bar.vue';
...@@ -49,10 +54,10 @@ export default { ...@@ -49,10 +54,10 @@ export default {
return this.shouldHideEditor && this.file.mrChange && this.viewer === viewerTypes.mr; return this.shouldHideEditor && this.file.mrChange && this.viewer === viewerTypes.mr;
}, },
isEditorViewMode() { isEditorViewMode() {
return this.file.viewMode === 'editor'; return this.file.viewMode === FILE_VIEW_MODE_EDITOR;
}, },
isPreviewViewMode() { isPreviewViewMode() {
return this.file.viewMode === 'preview'; return this.file.viewMode === FILE_VIEW_MODE_PREVIEW;
}, },
editTabCSS() { editTabCSS() {
return { return {
...@@ -85,7 +90,7 @@ export default { ...@@ -85,7 +90,7 @@ export default {
if (this.currentActivityView !== activityBarViews.edit) { if (this.currentActivityView !== activityBarViews.edit) {
this.setFileViewMode({ this.setFileViewMode({
file: this.file, file: this.file,
viewMode: 'editor', viewMode: FILE_VIEW_MODE_EDITOR,
}); });
} }
} }
...@@ -94,7 +99,7 @@ export default { ...@@ -94,7 +99,7 @@ export default {
if (this.currentActivityView !== activityBarViews.edit) { if (this.currentActivityView !== activityBarViews.edit) {
this.setFileViewMode({ this.setFileViewMode({
file: this.file, file: this.file,
viewMode: 'editor', viewMode: FILE_VIEW_MODE_EDITOR,
}); });
} }
}, },
...@@ -244,6 +249,8 @@ export default { ...@@ -244,6 +249,8 @@ export default {
}, },
}, },
viewerTypes, viewerTypes,
FILE_VIEW_MODE_EDITOR,
FILE_VIEW_MODE_PREVIEW,
}; };
</script> </script>
...@@ -255,7 +262,7 @@ export default { ...@@ -255,7 +262,7 @@ export default {
<a <a
href="javascript:void(0);" href="javascript:void(0);"
role="button" role="button"
@click.prevent="setFileViewMode({ file, viewMode: 'editor' })" @click.prevent="setFileViewMode({ file, viewMode: $options.FILE_VIEW_MODE_EDITOR })"
> >
<template v-if="viewer === $options.viewerTypes.edit">{{ __('Edit') }}</template> <template v-if="viewer === $options.viewerTypes.edit">{{ __('Edit') }}</template>
<template v-else>{{ __('Review') }}</template> <template v-else>{{ __('Review') }}</template>
...@@ -265,7 +272,7 @@ export default { ...@@ -265,7 +272,7 @@ export default {
<a <a
href="javascript:void(0);" href="javascript:void(0);"
role="button" role="button"
@click.prevent="setFileViewMode({ file, viewMode: 'preview' })" @click.prevent="setFileViewMode({ file, viewMode: $options.FILE_VIEW_MODE_PREVIEW })"
>{{ file.previewMode.previewTitle }}</a >{{ file.previewMode.previewTitle }}</a
> >
</li> </li>
......
...@@ -4,6 +4,10 @@ export const MAX_WINDOW_HEIGHT_COMPACT = 750; ...@@ -4,6 +4,10 @@ export const MAX_WINDOW_HEIGHT_COMPACT = 750;
export const MAX_TITLE_LENGTH = 50; export const MAX_TITLE_LENGTH = 50;
export const MAX_BODY_LENGTH = 72; export const MAX_BODY_LENGTH = 72;
// File view modes
export const FILE_VIEW_MODE_EDITOR = 'editor';
export const FILE_VIEW_MODE_PREVIEW = 'preview';
export const activityBarViews = { export const activityBarViews = {
edit: 'ide-tree', edit: 'ide-tree',
commit: 'commit-section', commit: 'commit-section',
......
import { commitActionTypes } from '../constants'; import { commitActionTypes, FILE_VIEW_MODE_EDITOR } from '../constants';
export const dataStructure = () => ({ export const dataStructure = () => ({
id: '', id: '',
...@@ -43,7 +43,7 @@ export const dataStructure = () => ({ ...@@ -43,7 +43,7 @@ export const dataStructure = () => ({
editorColumn: 1, editorColumn: 1,
fileLanguage: '', fileLanguage: '',
eol: '', eol: '',
viewMode: 'editor', viewMode: FILE_VIEW_MODE_EDITOR,
previewMode: null, previewMode: null,
size: 0, size: 0,
parentPath: null, parentPath: null,
......
...@@ -5,7 +5,7 @@ import axios from '~/lib/utils/axios_utils'; ...@@ -5,7 +5,7 @@ import axios from '~/lib/utils/axios_utils';
import store from '~/ide/stores'; import store from '~/ide/stores';
import repoEditor from '~/ide/components/repo_editor.vue'; import repoEditor from '~/ide/components/repo_editor.vue';
import Editor from '~/ide/lib/editor'; import Editor from '~/ide/lib/editor';
import { activityBarViews } from '~/ide/constants'; import { activityBarViews, FILE_VIEW_MODE_EDITOR, FILE_VIEW_MODE_PREVIEW } from '~/ide/constants';
import { createComponentWithStore } from '../../helpers/vue_mount_component_helper'; import { createComponentWithStore } from '../../helpers/vue_mount_component_helper';
import setTimeoutPromise from '../../helpers/set_timeout_promise_helper'; import setTimeoutPromise from '../../helpers/set_timeout_promise_helper';
import { file, resetStore } from '../helpers'; import { file, resetStore } from '../helpers';
...@@ -16,7 +16,7 @@ describe('RepoEditor', () => { ...@@ -16,7 +16,7 @@ describe('RepoEditor', () => {
beforeEach(done => { beforeEach(done => {
const f = { const f = {
...file(), ...file(),
viewMode: 'editor', viewMode: FILE_VIEW_MODE_EDITOR,
}; };
const RepoEditor = Vue.extend(repoEditor); const RepoEditor = Vue.extend(repoEditor);
...@@ -370,7 +370,7 @@ describe('RepoEditor', () => { ...@@ -370,7 +370,7 @@ describe('RepoEditor', () => {
describe('when files view mode is preview', () => { describe('when files view mode is preview', () => {
beforeEach(done => { beforeEach(done => {
spyOn(vm.editor, 'updateDimensions'); spyOn(vm.editor, 'updateDimensions');
vm.file.viewMode = 'preview'; vm.file.viewMode = FILE_VIEW_MODE_PREVIEW;
vm.$nextTick(done); vm.$nextTick(done);
}); });
...@@ -392,7 +392,7 @@ describe('RepoEditor', () => { ...@@ -392,7 +392,7 @@ describe('RepoEditor', () => {
describe('when file view mode changes to editor', () => { describe('when file view mode changes to editor', () => {
beforeEach(done => { beforeEach(done => {
vm.file.viewMode = 'editor'; vm.file.viewMode = FILE_VIEW_MODE_EDITOR;
// one tick to trigger watch // one tick to trigger watch
vm.$nextTick() vm.$nextTick()
......
import mutations from '~/ide/stores/mutations/file'; import mutations from '~/ide/stores/mutations/file';
import state from '~/ide/stores/state'; import state from '~/ide/stores/state';
import { FILE_VIEW_MODE_PREVIEW } from '~/ide/constants';
import { file } from '../../helpers'; import { file } from '../../helpers';
describe('IDE store file mutations', () => { describe('IDE store file mutations', () => {
...@@ -425,10 +426,10 @@ describe('IDE store file mutations', () => { ...@@ -425,10 +426,10 @@ describe('IDE store file mutations', () => {
it('updates file view mode', () => { it('updates file view mode', () => {
mutations.SET_FILE_VIEWMODE(localState, { mutations.SET_FILE_VIEWMODE(localState, {
file: localFile, file: localFile,
viewMode: 'preview', viewMode: FILE_VIEW_MODE_PREVIEW,
}); });
expect(localFile.viewMode).toBe('preview'); expect(localFile.viewMode).toBe(FILE_VIEW_MODE_PREVIEW);
}); });
}); });
......
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