Commit 5730873b authored by Simon Knox's avatar Simon Knox

Merge branch 'fc-add-pipeline-editor-as-default-split-button-for-ci-configs' into 'master'

Make split btn default to pipeline editor for root CI configs

See merge request gitlab-org/gitlab!80829
parents 68748303 70631c33
...@@ -8,6 +8,7 @@ import ConfirmForkModal from '~/vue_shared/components/confirm_fork_modal.vue'; ...@@ -8,6 +8,7 @@ import ConfirmForkModal from '~/vue_shared/components/confirm_fork_modal.vue';
const KEY_EDIT = 'edit'; const KEY_EDIT = 'edit';
const KEY_WEB_IDE = 'webide'; const KEY_WEB_IDE = 'webide';
const KEY_GITPOD = 'gitpod'; const KEY_GITPOD = 'gitpod';
const KEY_PIPELINE_EDITOR = 'pipeline_editor';
export default { export default {
components: { components: {
...@@ -64,6 +65,11 @@ export default { ...@@ -64,6 +65,11 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
showPipelineEditorButton: {
type: Boolean,
required: false,
default: false,
},
userPreferencesGitpodPath: { userPreferencesGitpodPath: {
type: String, type: String,
required: false, required: false,
...@@ -79,6 +85,11 @@ export default { ...@@ -79,6 +85,11 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
pipelineEditorUrl: {
type: String,
required: false,
default: '',
},
webIdeUrl: { webIdeUrl: {
type: String, type: String,
required: false, required: false,
...@@ -117,14 +128,19 @@ export default { ...@@ -117,14 +128,19 @@ export default {
}, },
data() { data() {
return { return {
selection: KEY_WEB_IDE, selection: this.showPipelineEditorButton ? KEY_PIPELINE_EDITOR : KEY_WEB_IDE,
showEnableGitpodModal: false, showEnableGitpodModal: false,
showForkModal: false, showForkModal: false,
}; };
}, },
computed: { computed: {
actions() { actions() {
return [this.webIdeAction, this.editAction, this.gitpodAction].filter((action) => action); return [
this.pipelineEditorAction,
this.webIdeAction,
this.editAction,
this.gitpodAction,
].filter((action) => action);
}, },
editAction() { editAction() {
if (!this.showEditButton) { if (!this.showEditButton) {
...@@ -209,6 +225,24 @@ export default { ...@@ -209,6 +225,24 @@ export default {
this.showGitpodButton && this.userPreferencesGitpodPath && this.userProfileEnableGitpodPath this.showGitpodButton && this.userPreferencesGitpodPath && this.userProfileEnableGitpodPath
); );
}, },
pipelineEditorAction() {
if (!this.showPipelineEditorButton) {
return null;
}
const secondaryText = __('Edit, lint, and visualize your pipeline.');
return {
key: KEY_PIPELINE_EDITOR,
text: __('Edit in pipeline editor'),
secondaryText,
tooltip: secondaryText,
attrs: {
'data-qa-selector': 'pipeline_editor_button',
},
href: this.pipelineEditorUrl,
};
},
gitpodAction() { gitpodAction() {
if (!this.computedShowGitpodButton) { if (!this.computedShowGitpodButton) {
return null; return null;
......
...@@ -203,9 +203,11 @@ module TreeHelper ...@@ -203,9 +203,11 @@ module TreeHelper
show_edit_button: show_edit_button?(options), show_edit_button: show_edit_button?(options),
show_web_ide_button: show_web_ide_button?, show_web_ide_button: show_web_ide_button?,
show_gitpod_button: show_gitpod_button?, show_gitpod_button: show_gitpod_button?,
show_pipeline_editor_button: show_pipeline_editor_button?(@project, @path),
web_ide_url: web_ide_url, web_ide_url: web_ide_url,
edit_url: edit_url(options), edit_url: edit_url(options),
pipeline_editor_url: project_ci_pipeline_editor_path(@project, branch_name: @ref),
gitpod_url: gitpod_url, gitpod_url: gitpod_url,
user_preferences_gitpod_path: profile_preferences_path(anchor: 'user_gitpod_enabled'), user_preferences_gitpod_path: profile_preferences_path(anchor: 'user_gitpod_enabled'),
......
...@@ -29,6 +29,10 @@ module WebIdeButtonHelper ...@@ -29,6 +29,10 @@ module WebIdeButtonHelper
show_web_ide_button? && Gitlab::CurrentSettings.gitpod_enabled show_web_ide_button? && Gitlab::CurrentSettings.gitpod_enabled
end end
def show_pipeline_editor_button?(project, path)
can_view_pipeline_editor?(project) && path == project.ci_config_path_or_default
end
def can_push_code? def can_push_code?
current_user&.can?(:push_code, @project) current_user&.can?(:push_code, @project)
end end
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
.file-actions.gl-display-flex.gl-align-items-center.gl-flex-wrap.gl-md-justify-content-end< .file-actions.gl-display-flex.gl-align-items-center.gl-flex-wrap.gl-md-justify-content-end<
= render 'projects/blob/viewer_switcher', blob: blob unless blame = render 'projects/blob/viewer_switcher', blob: blob unless blame
= render 'shared/web_ide_button', blob: blob = render 'shared/web_ide_button', blob: blob
- if can_view_pipeline_editor?(@project) && @path == @project.ci_config_path_or_default - if show_pipeline_editor_button?(@project, @path)
= link_to "Pipeline Editor", project_ci_pipeline_editor_path(@project, branch_name: @ref), class: "btn gl-button btn-confirm-secondary gl-ml-3" = link_to "Pipeline Editor", project_ci_pipeline_editor_path(@project, branch_name: @ref), class: "btn gl-button btn-confirm-secondary gl-ml-3"
.btn-group{ role: "group", class: ("gl-ml-3" if current_user) }> .btn-group{ role: "group", class: ("gl-ml-3" if current_user) }>
= render_if_exists 'projects/blob/header_file_locks_link' = render_if_exists 'projects/blob/header_file_locks_link'
......
...@@ -13214,6 +13214,9 @@ msgstr "" ...@@ -13214,6 +13214,9 @@ msgstr ""
msgid "Edit in Web IDE" msgid "Edit in Web IDE"
msgstr "" msgstr ""
msgid "Edit in pipeline editor"
msgstr ""
msgid "Edit in single-file editor" msgid "Edit in single-file editor"
msgstr "" msgstr ""
...@@ -13256,6 +13259,9 @@ msgstr "" ...@@ -13256,6 +13259,9 @@ msgstr ""
msgid "Edit your most recent comment in a thread (from an empty textarea)" msgid "Edit your most recent comment in a thread (from an empty textarea)"
msgstr "" msgstr ""
msgid "Edit, lint, and visualize your pipeline."
msgstr ""
msgid "Edited" msgid "Edited"
msgstr "" msgstr ""
......
...@@ -12,6 +12,7 @@ import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_help ...@@ -12,6 +12,7 @@ import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_help
const TEST_EDIT_URL = '/gitlab-test/test/-/edit/main/'; const TEST_EDIT_URL = '/gitlab-test/test/-/edit/main/';
const TEST_WEB_IDE_URL = '/-/ide/project/gitlab-test/test/edit/main/-/'; const TEST_WEB_IDE_URL = '/-/ide/project/gitlab-test/test/edit/main/-/';
const TEST_GITPOD_URL = 'https://gitpod.test/'; const TEST_GITPOD_URL = 'https://gitpod.test/';
const TEST_PIPELINE_EDITOR_URL = '/-/ci/editor?branch_name="main"';
const TEST_USER_PREFERENCES_GITPOD_PATH = '/-/profile/preferences#user_gitpod_enabled'; const TEST_USER_PREFERENCES_GITPOD_PATH = '/-/profile/preferences#user_gitpod_enabled';
const TEST_USER_PROFILE_ENABLE_GITPOD_PATH = '/-/profile?user%5Bgitpod_enabled%5D=true'; const TEST_USER_PROFILE_ENABLE_GITPOD_PATH = '/-/profile?user%5Bgitpod_enabled%5D=true';
const forkPath = '/some/fork/path'; const forkPath = '/some/fork/path';
...@@ -66,6 +67,16 @@ const ACTION_GITPOD_ENABLE = { ...@@ -66,6 +67,16 @@ const ACTION_GITPOD_ENABLE = {
href: undefined, href: undefined,
handle: expect.any(Function), handle: expect.any(Function),
}; };
const ACTION_PIPELINE_EDITOR = {
href: TEST_PIPELINE_EDITOR_URL,
key: 'pipeline_editor',
secondaryText: 'Edit, lint, and visualize your pipeline.',
tooltip: 'Edit, lint, and visualize your pipeline.',
text: 'Edit in pipeline editor',
attrs: {
'data-qa-selector': 'pipeline_editor_button',
},
};
describe('Web IDE link component', () => { describe('Web IDE link component', () => {
let wrapper; let wrapper;
...@@ -76,6 +87,7 @@ describe('Web IDE link component', () => { ...@@ -76,6 +87,7 @@ describe('Web IDE link component', () => {
editUrl: TEST_EDIT_URL, editUrl: TEST_EDIT_URL,
webIdeUrl: TEST_WEB_IDE_URL, webIdeUrl: TEST_WEB_IDE_URL,
gitpodUrl: TEST_GITPOD_URL, gitpodUrl: TEST_GITPOD_URL,
pipelineEditorUrl: TEST_PIPELINE_EDITOR_URL,
forkPath, forkPath,
...props, ...props,
}, },
...@@ -106,6 +118,10 @@ describe('Web IDE link component', () => { ...@@ -106,6 +118,10 @@ describe('Web IDE link component', () => {
props: {}, props: {},
expectedActions: [ACTION_WEB_IDE, ACTION_EDIT], expectedActions: [ACTION_WEB_IDE, ACTION_EDIT],
}, },
{
props: { showPipelineEditorButton: true },
expectedActions: [ACTION_PIPELINE_EDITOR, ACTION_WEB_IDE, ACTION_EDIT],
},
{ {
props: { webIdeText: 'Test Web IDE' }, props: { webIdeText: 'Test Web IDE' },
expectedActions: [{ ...ACTION_WEB_IDE_EDIT_FORK, text: 'Test Web IDE' }, ACTION_EDIT], expectedActions: [{ ...ACTION_WEB_IDE_EDIT_FORK, text: 'Test Web IDE' }, ACTION_EDIT],
...@@ -193,12 +209,34 @@ describe('Web IDE link component', () => { ...@@ -193,12 +209,34 @@ describe('Web IDE link component', () => {
expect(findActionsButton().props('actions')).toEqual(expectedActions); expect(findActionsButton().props('actions')).toEqual(expectedActions);
}); });
describe('when pipeline editor action is available', () => {
beforeEach(() => {
createComponent({
showEditButton: false,
showWebIdeButton: true,
showGitpodButton: true,
showPipelineEditorButton: true,
userPreferencesGitpodPath: TEST_USER_PREFERENCES_GITPOD_PATH,
userProfileEnableGitpodPath: TEST_USER_PROFILE_ENABLE_GITPOD_PATH,
gitpodEnabled: true,
});
});
it('selected Pipeline Editor by default', () => {
expect(findActionsButton().props()).toMatchObject({
actions: [ACTION_PIPELINE_EDITOR, ACTION_WEB_IDE, ACTION_GITPOD],
selectedKey: ACTION_PIPELINE_EDITOR.key,
});
});
});
describe('with multiple actions', () => { describe('with multiple actions', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
showEditButton: false, showEditButton: false,
showWebIdeButton: true, showWebIdeButton: true,
showGitpodButton: true, showGitpodButton: true,
showPipelineEditorButton: false,
userPreferencesGitpodPath: TEST_USER_PREFERENCES_GITPOD_PATH, userPreferencesGitpodPath: TEST_USER_PREFERENCES_GITPOD_PATH,
userProfileEnableGitpodPath: TEST_USER_PROFILE_ENABLE_GITPOD_PATH, userProfileEnableGitpodPath: TEST_USER_PROFILE_ENABLE_GITPOD_PATH,
gitpodEnabled: true, gitpodEnabled: true,
...@@ -240,6 +278,7 @@ describe('Web IDE link component', () => { ...@@ -240,6 +278,7 @@ describe('Web IDE link component', () => {
props: { props: {
showWebIdeButton: true, showWebIdeButton: true,
showEditButton: false, showEditButton: false,
showPipelineEditorButton: false,
forkPath, forkPath,
forkModalId: 'edit-modal', forkModalId: 'edit-modal',
}, },
...@@ -249,6 +288,7 @@ describe('Web IDE link component', () => { ...@@ -249,6 +288,7 @@ describe('Web IDE link component', () => {
props: { props: {
showWebIdeButton: false, showWebIdeButton: false,
showEditButton: true, showEditButton: true,
showPipelineEditorButton: false,
forkPath, forkPath,
forkModalId: 'webide-modal', forkModalId: 'webide-modal',
}, },
......
...@@ -116,9 +116,11 @@ RSpec.describe TreeHelper do ...@@ -116,9 +116,11 @@ RSpec.describe TreeHelper do
show_edit_button: false, show_edit_button: false,
show_web_ide_button: true, show_web_ide_button: true,
show_gitpod_button: false, show_gitpod_button: false,
show_pipeline_editor_button: false,
edit_url: '', edit_url: '',
web_ide_url: "/-/ide/project/#{project.full_path}/edit/#{sha}", web_ide_url: "/-/ide/project/#{project.full_path}/edit/#{sha}",
pipeline_editor_url: "/#{project.full_path}/-/ci/editor?branch_name=#{@ref}",
gitpod_url: '', gitpod_url: '',
user_preferences_gitpod_path: user_preferences_gitpod_path, user_preferences_gitpod_path: user_preferences_gitpod_path,
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe WebIdeButtonHelper do
describe '#show_pipeline_editor_button?' do
subject(:result) { helper.show_pipeline_editor_button?(project, path) }
let_it_be(:project) { build(:project) }
context 'when can view pipeline editor' do
before do
allow(helper).to receive(:can_view_pipeline_editor?).and_return(true)
end
context 'when path is ci config path' do
let(:path) { project.ci_config_path_or_default }
it 'returns true' do
expect(result).to eq(true)
end
end
context 'when path is not config path' do
let(:path) { '/' }
it 'returns false' do
expect(result).to eq(false)
end
end
end
context 'when can not view pipeline editor' do
before do
allow(helper).to receive(:can_view_pipeline_editor?).and_return(false)
end
let(:path) { project.ci_config_path_or_default }
it 'returns false' do
expect(result).to eq(false)
end
end
end
end
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