Commit a3c0ad65 authored by Paul Slaughter's avatar Paul Slaughter Committed by Sean McGivern

Fix "Edit fork in Web IDE" behavior

- This was accidentally removed when things were
[refactored for Gitpod][1]

[1]: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/37985
parent d1d63b17
......@@ -113,9 +113,10 @@ export default function setupVueRepositoryList() {
const webIdeLinkEl = document.getElementById('js-tree-web-ide-link');
if (webIdeLinkEl) {
const { ideBasePath, ...options } = convertObjectPropsToCamelCase(
JSON.parse(webIdeLinkEl.dataset.options),
);
const {
webIdeUrlData: { path: ideBasePath, isFork: webIdeIsFork },
...options
} = convertObjectPropsToCamelCase(JSON.parse(webIdeLinkEl.dataset.options), { deep: true });
// eslint-disable-next-line no-new
new Vue({
......@@ -127,6 +128,7 @@ export default function setupVueRepositoryList() {
webIdeUrl: webIDEUrl(
joinPaths('/', ideBasePath, 'edit', ref, '-', this.$route.params.path || '', '/'),
),
webIdeIsFork,
...options,
},
});
......
......@@ -15,7 +15,13 @@ export default {
props: {
webIdeUrl: {
type: String,
required: true,
required: false,
default: '',
},
webIdeIsFork: {
type: Boolean,
required: false,
default: false,
},
needsToFork: {
type: Boolean,
......@@ -61,9 +67,11 @@ export default {
? { href: '#modal-confirm-fork', handle: () => this.showModal('#modal-confirm-fork') }
: { href: this.webIdeUrl };
const text = this.webIdeIsFork ? __('Edit fork in Web IDE') : __('Web IDE');
return {
key: KEY_WEB_IDE,
text: __('Web IDE'),
text,
secondaryText: __('Quickly and easily edit multiple files in your project.'),
tooltip: '',
attrs: {
......
......@@ -199,14 +199,14 @@ module TreeHelper
}
end
def ide_base_path(project)
def web_ide_url_data(project)
can_push_code = current_user&.can?(:push_code, project)
fork_path = current_user&.fork_of(project)&.full_path
if can_push_code
project.full_path
if fork_path && !can_push_code
{ path: fork_path, is_fork: true }
else
fork_path || project.full_path
{ path: project.full_path, is_fork: false }
end
end
......@@ -216,7 +216,7 @@ module TreeHelper
show_web_ide_button = (can_collaborate || current_user&.already_forked?(project) || can_create_mr_from_fork)
{
ide_base_path: ide_base_path(project),
web_ide_url_data: web_ide_url_data(project),
needs_to_fork: !can_collaborate && !current_user&.already_forked?(project),
show_web_ide_button: show_web_ide_button,
show_gitpod_button: show_web_ide_button && Gitlab::Gitpod.feature_and_settings_enabled?(project),
......
......@@ -9233,6 +9233,9 @@ msgstr ""
msgid "Edit files in the editor and commit changes here"
msgstr ""
msgid "Edit fork in Web IDE"
msgstr ""
msgid "Edit group: %{group_name}"
msgstr ""
......
......@@ -60,6 +60,7 @@ describe('Web IDE link component', () => {
it.each`
props | expectedActions
${{}} | ${[ACTION_WEB_IDE]}
${{ webIdeIsFork: true }} | ${[{ ...ACTION_WEB_IDE, text: 'Edit fork in Web IDE' }]}
${{ needsToFork: true }} | ${[ACTION_WEB_IDE_FORK]}
${{ showWebIdeButton: false, showGitpodButton: true, gitpodEnabled: true }} | ${[ACTION_GITPOD]}
${{ showWebIdeButton: false, showGitpodButton: true, gitpodEnabled: false }} | ${[ACTION_GITPOD_ENABLE]}
......
......@@ -178,7 +178,7 @@ RSpec.describe TreeHelper do
it 'returns a list of attributes related to the project' do
expect(subject).to include(
ide_base_path: project.full_path,
web_ide_url_data: { path: project.full_path, is_fork: false },
needs_to_fork: false,
show_web_ide_button: true,
show_gitpod_button: false,
......@@ -200,9 +200,9 @@ RSpec.describe TreeHelper do
allow(helper).to receive(:current_user).and_return(user)
end
it 'includes ide_base_path: forked_project.full_path' do
it 'includes web_ide_url_data: forked_project.full_path' do
expect(subject).to include(
ide_base_path: forked_project.full_path
web_ide_url_data: { path: forked_project.full_path, is_fork: true }
)
end
end
......@@ -216,9 +216,9 @@ RSpec.describe TreeHelper do
allow(helper).to receive(:current_user).and_return(user)
end
it 'includes ide_base_path: project.full_path' do
it 'includes web_ide_url_data: project.full_path' do
expect(subject).to include(
ide_base_path: project.full_path
web_ide_url_data: { path: project.full_path, is_fork: false }
)
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