Commit 4cf8a898 authored by Andrew Fontaine's avatar Andrew Fontaine

Display File-Based Alerts on the WebIDE

Provides a way to display alerts attached to files within the WebIDE.

The first alert shows guidance to users who are editing their CI
configuration about environments, if we are reasonably certain they
don't know about environments.

We need to request the parsed CI configuration while the user edits it,
and accomplish this by watching the content. This watcher is
conditionally created and destroyed when the config file is active.
parent 78375ddc
<script>
import { GlAlert } from '@gitlab/ui';
import { getAlert } from '../lib/alerts';
export default {
components: {
GlAlert,
},
props: {
alertKey: {
type: Symbol,
required: true,
},
},
computed: {
alert() {
return getAlert(this.alertKey);
},
},
};
</script>
<template>
<gl-alert v-bind="alert.props" @dismiss="alert.dismiss($store)">
<component :is="alert.message" />
</gl-alert>
</template>
<script>
import { debounce } from 'lodash';
import { mapState, mapGetters, mapActions } from 'vuex';
import {
EDITOR_TYPE_DIFF,
......@@ -34,11 +35,13 @@ import mapRulesToMonaco from '../lib/editorconfig/rules_mapper';
import { getFileEditorOrDefault } from '../stores/modules/editor/utils';
import { extractMarkdownImagesFromEntries } from '../stores/utils';
import { getPathParent, readFileAsDataURL, registerSchema, isTextFile } from '../utils';
import FileAlert from './file_alert.vue';
import FileTemplatesBar from './file_templates/bar.vue';
export default {
name: 'RepoEditor',
components: {
FileAlert,
ContentViewer,
DiffViewer,
FileTemplatesBar,
......@@ -57,6 +60,7 @@ export default {
globalEditor: null,
modelManager: new ModelManager(),
isEditorLoading: true,
unwatchCiYaml: null,
};
},
computed: {
......@@ -74,6 +78,7 @@ export default {
'currentProjectId',
]),
...mapGetters([
'getAlert',
'currentMergeRequest',
'getStagedFile',
'isEditModeActive',
......@@ -82,6 +87,9 @@ export default {
'getJsonSchemaForPath',
]),
...mapGetters('fileTemplates', ['showFileTemplatesBar']),
alertKey() {
return this.getAlert(this.file);
},
fileEditor() {
return getFileEditorOrDefault(this.fileEditors, this.file.path);
},
......@@ -136,6 +144,16 @@ export default {
},
},
watch: {
'file.name': {
handler() {
this.stopWatchingCiYaml();
if (this.file.name === '.gitlab-ci.yml') {
this.startWatchingCiYaml();
}
},
immediate: true,
},
file(newVal, oldVal) {
if (oldVal.pending) {
this.removePendingTab(oldVal);
......@@ -216,6 +234,7 @@ export default {
'removePendingTab',
'triggerFilesChange',
'addTempImage',
'detectGitlabCiFileAlerts',
]),
...mapActions('editor', ['updateFileEditor']),
initEditor() {
......@@ -422,6 +441,18 @@ export default {
this.updateFileEditor({ path: this.file.path, data });
},
startWatchingCiYaml() {
this.unwatchCiYaml = this.$watch(
'file.content',
debounce(this.detectGitlabCiFileAlerts, 500),
);
},
stopWatchingCiYaml() {
if (this.unwatchCiYaml) {
this.unwatchCiYaml();
this.unwatchCiYaml = null;
}
},
},
viewerTypes,
FILE_VIEW_MODE_EDITOR,
......@@ -439,9 +470,8 @@ export default {
role="button"
data-testid="edit-tab"
@click.prevent="updateEditor({ viewMode: $options.FILE_VIEW_MODE_EDITOR })"
>{{ __('Edit') }}</a
>
{{ __('Edit') }}
</a>
</li>
<li v-if="previewMode" :class="previewTabCSS">
<a
......@@ -454,7 +484,8 @@ export default {
</li>
</ul>
</div>
<file-templates-bar v-if="showFileTemplatesBar(file.name)" />
<file-alert v-if="alertKey" :alert-key="alertKey" />
<file-templates-bar v-else-if="showFileTemplatesBar(file.name)" />
<div
v-show="showEditor"
ref="editor"
......
......@@ -510,6 +510,7 @@ describe('RepoEditor', () => {
},
});
await vm.$nextTick();
await vm.$nextTick();
expect(vm.initEditor).toHaveBeenCalled();
});
......
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