1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
<!-- eslint-disable vue/multi-word-component-names -->
<script>
import { GlButton, GlLoadingIcon } from '@gitlab/ui';
// eslint-disable-next-line no-restricted-imports
import { mapActions, mapGetters, mapState } from 'vuex';
import { __ } from '~/locale';
import {
WEBIDE_MARK_APP_START,
WEBIDE_MARK_FILE_FINISH,
WEBIDE_MARK_FILE_CLICKED,
WEBIDE_MEASURE_FILE_AFTER_INTERACTION,
WEBIDE_MEASURE_BEFORE_VUE,
} from '~/performance/constants';
import { performanceMarkAndMeasure } from '~/performance/utils';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { modalTypes } from '../constants';
import eventHub from '../eventhub';
import { measurePerformance } from '../utils';
import CannotPushCodeAlert from './cannot_push_code_alert.vue';
import IdeSidebar from './ide_side_bar.vue';
import RepoEditor from './repo_editor.vue';
eventHub.$on(WEBIDE_MEASURE_FILE_AFTER_INTERACTION, () =>
measurePerformance(
WEBIDE_MARK_FILE_FINISH,
WEBIDE_MEASURE_FILE_AFTER_INTERACTION,
WEBIDE_MARK_FILE_CLICKED,
),
);
export default {
components: {
IdeSidebar,
RepoEditor,
GlButton,
GlLoadingIcon,
ErrorMessage: () => import(/* webpackChunkName: 'ide_runtime' */ './error_message.vue'),
CommitEditorHeader: () =>
import(/* webpackChunkName: 'ide_runtime' */ './commit_sidebar/editor_header.vue'),
RepoTabs: () => import(/* webpackChunkName: 'ide_runtime' */ './repo_tabs.vue'),
IdeStatusBar: () => import(/* webpackChunkName: 'ide_runtime' */ './ide_status_bar.vue'),
FindFile: () =>
import(/* webpackChunkName: 'ide_runtime' */ '~/vue_shared/components/file_finder/index.vue'),
RightPane: () => import(/* webpackChunkName: 'ide_runtime' */ './panes/right.vue'),
NewModal: () => import(/* webpackChunkName: 'ide_runtime' */ './new_dropdown/modal.vue'),
CannotPushCodeAlert,
},
mixins: [glFeatureFlagsMixin()],
data() {
return {
loadDeferred: false,
skipBeforeUnload: false,
};
},
computed: {
...mapState([
'openFiles',
'viewer',
'fileFindVisible',
'emptyStateSvgPath',
'currentProjectId',
'errorMessage',
'loading',
]),
...mapGetters([
'canPushCodeStatus',
'activeFile',
'someUncommittedChanges',
'isCommitModeActive',
'allBlobs',
'emptyRepo',
'currentTree',
'hasCurrentProject',
'editorTheme',
'getUrlForPath',
]),
themeName() {
return window.gon?.user_color_scheme;
},
},
mounted() {
window.onbeforeunload = (e) => this.onBeforeUnload(e);
eventHub.$on('skip-beforeunload', this.handleSkipBeforeUnload);
if (this.themeName)
document.querySelector('.navbar-gitlab')?.classList.add(`theme-${this.themeName}`);
},
destroyed() {
eventHub.$off('skip-beforeunload', this.handleSkipBeforeUnload);
},
beforeCreate() {
performanceMarkAndMeasure({
mark: WEBIDE_MARK_APP_START,
measures: [
{
name: WEBIDE_MEASURE_BEFORE_VUE,
},
],
});
},
methods: {
...mapActions(['toggleFileFinder']),
onBeforeUnload(e = {}) {
if (this.skipBeforeUnload) {
this.skipBeforeUnload = false;
return undefined;
}
const returnValue = __('Are you sure you want to lose unsaved changes?');
if (!this.someUncommittedChanges) return undefined;
Object.assign(e, {
returnValue,
});
return returnValue;
},
handleSkipBeforeUnload() {
this.skipBeforeUnload = true;
},
openFile(file) {
this.$router.push(this.getUrlForPath(file.path));
},
createNewFile() {
this.$refs.newModal.open(modalTypes.blob);
},
loadDeferredComponents() {
this.loadDeferred = true;
},
},
};
</script>
<template>
<article
class="ide position-relative d-flex flex-column align-items-stretch"
:class="{ [`theme-${themeName}`]: themeName }"
>
<cannot-push-code-alert
v-if="!canPushCodeStatus.isAllowed"
:message="canPushCodeStatus.message"
:action="canPushCodeStatus.action"
/>
<error-message v-if="errorMessage" :message="errorMessage" />
<div class="ide-view flex-grow d-flex">
<template v-if="loadDeferred">
<find-file
:files="allBlobs"
:visible="fileFindVisible"
:loading="loading"
@toggle="toggleFileFinder"
@click="openFile"
/>
</template>
<ide-sidebar @tree-ready="loadDeferredComponents" />
<div class="multi-file-edit-pane">
<template v-if="activeFile">
<template v-if="loadDeferred">
<commit-editor-header v-if="isCommitModeActive" :active-file="activeFile" />
<repo-tabs v-else :active-file="activeFile" :files="openFiles" :viewer="viewer" />
</template>
<repo-editor :file="activeFile" class="multi-file-edit-pane-content" />
</template>
<template v-else>
<div class="ide-empty-state">
<div class="row js-empty-state">
<div class="col-12">
<div class="svg-content svg-250"><img :src="emptyStateSvgPath" /></div>
</div>
<div class="col-12">
<div class="text-content text-center">
<h4>
{{ __('Make and review changes in the browser with the Web IDE') }}
</h4>
<template v-if="emptyRepo">
<p>
{{
__(
"Create a new file as there are no files yet. Afterwards, you'll be able to commit your changes.",
)
}}
</p>
<gl-button
variant="confirm"
category="primary"
:title="__('New file')"
:aria-label="__('New file')"
@click="createNewFile()"
>
{{ __('New file') }}
</gl-button>
</template>
<gl-loading-icon v-else-if="!currentTree || currentTree.loading" size="lg" />
<p v-else>
{{
__(
"Select a file from the left sidebar to begin editing. Afterwards, you'll be able to commit your changes.",
)
}}
</p>
</div>
</div>
</div>
</div>
</template>
</div>
<template v-if="loadDeferred">
<right-pane v-if="currentProjectId" />
</template>
</div>
<template v-if="loadDeferred">
<ide-status-bar />
<new-modal ref="newModal" />
</template>
</article>
</template>
|