Commit 0b9b0e64 authored by Sam Beckham's avatar Sam Beckham Committed by Miguel Rincon

When a non-default branch is selected, the merged YAML result is

potentially incorrect. This issue is being addressed elsewhere, but this
solution hides the tab when editing on the non-default branch.

It's a temporary solution that should be reverted as soon as the merged
YAML functionality works correctly across multiple branches.
parent 16c21707
<script> <script>
import { GlIcon } from '@gitlab/ui'; import { GlAlert, GlLink, GlSprintf, GlIcon } from '@gitlab/ui';
import { uniqueId } from 'lodash'; import { uniqueId } from 'lodash';
import { helpPagePath } from '~/helpers/help_page_helper';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import SourceEditor from '~/vue_shared/components/source_editor.vue'; import SourceEditor from '~/vue_shared/components/source_editor.vue';
import getCurrentBranch from '../../graphql/queries/client/current_branch.graphql';
export default { export default {
i18n: { i18n: {
viewOnlyMessage: s__('Pipelines|Merged YAML is view only'), viewOnlyMessage: s__('Pipelines|Merged YAML is view only'),
unavailableDefaultTitle: s__('Pipelines|Merged YAML unavailable'),
unavailableDefaultText: s__(
'Pipelines|The merged YAML view is only available for the default branch. %{linkStart}Learn more.%{linkEnd}',
),
}, },
components: { components: {
SourceEditor, SourceEditor,
GlAlert,
GlIcon, GlIcon,
GlLink,
GlSprintf,
}, },
inject: ['ciConfigPath'], inject: ['ciConfigPath', 'defaultBranch'],
props: { props: {
ciConfigData: { ciConfigData: {
type: Object, type: Object,
...@@ -24,6 +33,15 @@ export default { ...@@ -24,6 +33,15 @@ export default {
failureType: null, failureType: null,
}; };
}, },
// This is not the best practice, don't copy me (@samdbeckham)
// This is a temporary workaround to unblock a release.
// See this comment for more information on this approach
// https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65972#note_626095648
apollo: {
currentBranch: {
query: getCurrentBranch,
},
},
computed: { computed: {
fileGlobalId() { fileGlobalId() {
return `${this.ciConfigPath}-${uniqueId()}`; return `${this.ciConfigPath}-${uniqueId()}`;
...@@ -31,24 +49,44 @@ export default { ...@@ -31,24 +49,44 @@ export default {
mergedYaml() { mergedYaml() {
return this.ciConfigData.mergedYaml; return this.ciConfigData.mergedYaml;
}, },
isOnDefaultBranch() {
return this.currentBranch === this.defaultBranch;
},
expandedConfigHelpPath() {
return helpPagePath('ci/pipeline_editor/index', { anchor: 'view-expanded-configuration' });
},
}, },
}; };
</script> </script>
<template> <template>
<div> <div>
<div class="gl-display-flex gl-align-items-center"> <div v-if="isOnDefaultBranch">
<gl-icon :size="16" name="lock" class="gl-text-gray-500 gl-mr-3" /> <div class="gl-display-flex gl-align-items-center">
{{ $options.i18n.viewOnlyMessage }} <gl-icon :size="16" name="lock" class="gl-text-gray-500 gl-mr-3" />
</div> {{ $options.i18n.viewOnlyMessage }}
<div class="gl-mt-3 gl-border-solid gl-border-gray-100 gl-border-1"> </div>
<source-editor <div class="gl-mt-3 gl-border-solid gl-border-gray-100 gl-border-1">
ref="editor" <source-editor
:value="mergedYaml" ref="editor"
:file-name="ciConfigPath" :value="mergedYaml"
:file-global-id="fileGlobalId" :file-name="ciConfigPath"
:editor-options="{ readOnly: true }" :file-global-id="fileGlobalId"
v-on="$listeners" :editor-options="{ readOnly: true }"
/> v-on="$listeners"
/>
</div>
</div> </div>
<gl-alert
v-else
variant="info"
:dismissible="false"
:title="$options.i18n.unavailableDefaultTitle"
>
<gl-sprintf :message="$options.i18n.unavailableDefaultText">
<template #link="{ content }">
<gl-link :href="expandedConfigHelpPath" target="_blank">{{ content }}</gl-link>
</template>
</gl-sprintf>
</gl-alert>
</div> </div>
</template> </template>
...@@ -85,6 +85,9 @@ where: ...@@ -85,6 +85,9 @@ where:
[extended configuration merged into the job](../yaml/index.md#merge-details). [extended configuration merged into the job](../yaml/index.md#merge-details).
- YAML anchors are [replaced with the linked configuration](../yaml/index.md#anchors). - YAML anchors are [replaced with the linked configuration](../yaml/index.md#anchors).
NOTE:
You can only see the expanded view when editing the [default branch](../../user/project/repository/branches/default.md).
## Commit changes to CI configuration ## Commit changes to CI configuration
The commit form appears at the bottom of each tab in the editor so you can commit The commit form appears at the bottom of each tab in the editor so you can commit
......
...@@ -24221,6 +24221,9 @@ msgstr "" ...@@ -24221,6 +24221,9 @@ msgstr ""
msgid "Pipelines|Merged YAML is view only" msgid "Pipelines|Merged YAML is view only"
msgstr "" msgstr ""
msgid "Pipelines|Merged YAML unavailable"
msgstr ""
msgid "Pipelines|More Information" msgid "Pipelines|More Information"
msgstr "" msgstr ""
...@@ -24257,6 +24260,9 @@ msgstr "" ...@@ -24257,6 +24260,9 @@ msgstr ""
msgid "Pipelines|The GitLab CI configuration could not be updated." msgid "Pipelines|The GitLab CI configuration could not be updated."
msgstr "" msgstr ""
msgid "Pipelines|The merged YAML view is only available for the default branch. %{linkStart}Learn more.%{linkEnd}"
msgstr ""
msgid "Pipelines|There are currently no finished pipelines." msgid "Pipelines|There are currently no finished pipelines."
msgstr "" msgstr ""
......
import { GlIcon } from '@gitlab/ui'; import { GlIcon, GlAlert } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { EDITOR_READY_EVENT } from '~/editor/constants'; import { EDITOR_READY_EVENT } from '~/editor/constants';
import CiConfigMergedPreview from '~/pipeline_editor/components/editor/ci_config_merged_preview.vue'; import CiConfigMergedPreview from '~/pipeline_editor/components/editor/ci_config_merged_preview.vue';
import { mockLintResponse, mockCiConfigPath } from '../../mock_data'; import { mockLintResponse, mockCiConfigPath } from '../../mock_data';
const DEFAULT_BRANCH = 'main';
describe('Text editor component', () => { describe('Text editor component', () => {
let wrapper; let wrapper;
...@@ -16,7 +18,7 @@ describe('Text editor component', () => { ...@@ -16,7 +18,7 @@ describe('Text editor component', () => {
}, },
}; };
const createComponent = ({ props = {} } = {}) => { const createComponent = ({ props = {}, currentBranch = DEFAULT_BRANCH } = {}) => {
wrapper = shallowMount(CiConfigMergedPreview, { wrapper = shallowMount(CiConfigMergedPreview, {
propsData: { propsData: {
ciConfigData: mockLintResponse, ciConfigData: mockLintResponse,
...@@ -24,20 +26,45 @@ describe('Text editor component', () => { ...@@ -24,20 +26,45 @@ describe('Text editor component', () => {
}, },
provide: { provide: {
ciConfigPath: mockCiConfigPath, ciConfigPath: mockCiConfigPath,
defaultBranch: DEFAULT_BRANCH,
}, },
stubs: { stubs: {
SourceEditor: MockSourceEditor, SourceEditor: MockSourceEditor,
}, },
data() {
return {
currentBranch,
};
},
}); });
}; };
const findIcon = () => wrapper.findComponent(GlIcon); const findIcon = () => wrapper.findComponent(GlIcon);
const findAlert = () => wrapper.findComponent(GlAlert);
const findEditor = () => wrapper.findComponent(MockSourceEditor); const findEditor = () => wrapper.findComponent(MockSourceEditor);
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
// This is testing a temporary feature.
// It may be slightly hacky code that doesn't follow best practice.
// See the related MR for more information.
// https://gitlab.com/gitlab-org/gitlab/-/merge_requests/65972#note_626095644
describe('on a non-default branch', () => {
beforeEach(() => {
createComponent({ currentBranch: 'feature' });
});
it('does not load the editor', () => {
expect(findEditor().exists()).toBe(false);
});
it('renders an informational alert', () => {
expect(findAlert().exists()).toBe(true);
});
});
describe('when status is valid', () => { describe('when status is valid', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
......
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