Commit 2c4aaa87 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '322842-convert-the-dependency-proxy-ui-from-haml-to-vue' into 'master'

Enable new dependency proxy vue app

See merge request gitlab-org/gitlab!70916
parents 2fac068e 897cc2bc
import setupToggleButtons from '~/toggle_buttons';
export default () => {
setupToggleButtons(document.querySelector('.js-dependency-proxy-toggle-area'));
};
...@@ -22,8 +22,9 @@ export default { ...@@ -22,8 +22,9 @@ export default {
}, },
inject: ['groupPath', 'dependencyProxyAvailable'], inject: ['groupPath', 'dependencyProxyAvailable'],
i18n: { i18n: {
proxyNotAvailableText: __('Dependency proxy feature is limited to public groups for now.'), proxyNotAvailableText: __('Dependency Proxy feature is limited to public groups for now.'),
proxyImagePrefix: __('Dependency proxy image prefix'), proxyDisabledText: __('Dependency Proxy disabled. To enable it, contact the group owner.'),
proxyImagePrefix: __('Dependency Proxy image prefix'),
copyImagePrefixText: __('Copy prefix'), copyImagePrefixText: __('Copy prefix'),
blobCountAndSize: __('Contains %{count} blobs of images (%{size})'), blobCountAndSize: __('Contains %{count} blobs of images (%{size})'),
}, },
...@@ -52,6 +53,9 @@ export default { ...@@ -52,6 +53,9 @@ export default {
}, },
]; ];
}, },
dependencyProxyEnabled() {
return this.group?.dependencyProxySetting?.enabled;
},
}, },
}; };
</script> </script>
...@@ -59,18 +63,23 @@ export default { ...@@ -59,18 +63,23 @@ export default {
<template> <template>
<div> <div>
<title-area :title="__('Dependency Proxy')" :info-messages="infoMessages" /> <title-area :title="__('Dependency Proxy')" :info-messages="infoMessages" />
<gl-alert v-if="!dependencyProxyAvailable" :dismissible="false"> <gl-alert
v-if="!dependencyProxyAvailable"
:dismissible="false"
data-testid="proxy-not-available"
>
{{ $options.i18n.proxyNotAvailableText }} {{ $options.i18n.proxyNotAvailableText }}
</gl-alert> </gl-alert>
<gl-skeleton-loader v-else-if="$apollo.queries.group.loading" /> <gl-skeleton-loader v-else-if="$apollo.queries.group.loading" />
<div v-else data-testid="main-area"> <div v-else-if="dependencyProxyEnabled" data-testid="main-area">
<gl-form-group :label="$options.i18n.proxyImagePrefix"> <gl-form-group :label="$options.i18n.proxyImagePrefix">
<gl-form-input-group <gl-form-input-group
readonly readonly
:value="group.dependencyProxyImagePrefix" :value="group.dependencyProxyImagePrefix"
class="gl-layout-w-limited" class="gl-layout-w-limited"
data-testid="proxy-url"
> >
<template #append> <template #append>
<clipboard-button <clipboard-button
...@@ -89,5 +98,8 @@ export default { ...@@ -89,5 +98,8 @@ export default {
</template> </template>
</gl-form-group> </gl-form-group>
</div> </div>
<gl-alert v-else :dismissible="false" data-testid="proxy-disabled">
{{ $options.i18n.proxyDisabledText }}
</gl-alert>
</div> </div>
</template> </template>
query getDependencyProxyDetails($fullPath: ID!) { query getDependencyProxyDetails($fullPath: ID!) {
group(fullPath: $fullPath) { group(fullPath: $fullPath) {
name
dependencyProxyBlobCount dependencyProxyBlobCount
dependencyProxyTotalSize dependencyProxyTotalSize
dependencyProxyImagePrefix dependencyProxyImagePrefix
dependencyProxyManifests { dependencyProxySetting {
nodes { enabled
digest
}
}
dependencyProxyBlobs {
nodes {
fileName
}
} }
} }
} }
import $ from 'jquery'; import { initDependencyProxyApp } from '~/packages_and_registries/dependency_proxy/';
import initDependencyProxy from '~/dependency_proxy';
initDependencyProxy(); initDependencyProxyApp();
const form = document.querySelector('form.edit_dependency_proxy_group_setting');
const toggleInput = $('input.js-project-feature-toggle-input');
if (form && toggleInput) {
toggleInput.on('trigger-change', () => {
form.submit();
});
}
- proxy_url = @group.dependency_proxy_image_prefix
%h5.prepend-top-20= _('Dependency proxy image prefix')
.row
.col-lg-8.col-md-12.input-group
= text_field_tag :url, "#{proxy_url}", class: 'js-dependency-proxy-url form-control', readonly: true
= clipboard_button(text: "#{proxy_url}", title: _("Copy %{proxy_url}") % { proxy_url: proxy_url })
.row
.col-12.help-block.gl-mt-3{ data: { qa_selector: 'dependency_proxy_count' } }
= _('Contains %{count} blobs of images (%{size})') % { count: @blobs_count, size: number_to_human_size(@blobs_total_size) }
- page_title _("Dependency Proxy") - page_title _("Dependency Proxy")
- dependency_proxy_available = Feature.enabled?(:dependency_proxy_for_private_groups, default_enabled: true) || @group.public?
.settings-header #js-dependency-proxy{ data: { group_path: @group.full_path,
%h4= _('Dependency proxy') dependency_proxy_available: dependency_proxy_available.to_s } }
%p
- link_start = '<a href="%{url}">'.html_safe % { url: help_page_path('user/packages/dependency_proxy/index') }
= _('Create a local proxy for storing frequently used upstream images. %{link_start}Learn more%{link_end} about dependency proxies.').html_safe % { link_start: link_start, link_end: '</a>'.html_safe }
- if Feature.enabled?(:dependency_proxy_for_private_groups, default_enabled: true) || @group.public?
- if @dependency_proxy.enabled
= render 'groups/dependency_proxies/url'
- else
.gl-alert.gl-alert-info
.gl-alert-container
= sprite_icon('information-o', size: 16, css_class: 'gl-icon gl-alert-icon gl-alert-icon-no-title')
.gl-alert-content
= _('Dependency proxy feature is limited to public groups for now.')
...@@ -9272,9 +9272,6 @@ msgstr "" ...@@ -9272,9 +9272,6 @@ msgstr ""
msgid "Copy %{protocol} clone URL" msgid "Copy %{protocol} clone URL"
msgstr "" msgstr ""
msgid "Copy %{proxy_url}"
msgstr ""
msgid "Copy %{type}" msgid "Copy %{type}"
msgstr "" msgstr ""
...@@ -9572,9 +9569,6 @@ msgstr "" ...@@ -9572,9 +9569,6 @@ msgstr ""
msgid "Create a Mattermost team for this group" msgid "Create a Mattermost team for this group"
msgstr "" msgstr ""
msgid "Create a local proxy for storing frequently used upstream images. %{link_start}Learn more%{link_end} about dependency proxies."
msgstr ""
msgid "Create a merge request" msgid "Create a merge request"
msgstr "" msgstr ""
...@@ -11204,16 +11198,16 @@ msgstr "" ...@@ -11204,16 +11198,16 @@ msgstr ""
msgid "Dependency Proxy" msgid "Dependency Proxy"
msgstr "" msgstr ""
msgid "Dependency Scanning" msgid "Dependency Proxy disabled. To enable it, contact the group owner."
msgstr "" msgstr ""
msgid "Dependency proxy" msgid "Dependency Proxy feature is limited to public groups for now."
msgstr "" msgstr ""
msgid "Dependency proxy feature is limited to public groups for now." msgid "Dependency Proxy image prefix"
msgstr "" msgstr ""
msgid "Dependency proxy image prefix" msgid "Dependency Scanning"
msgstr "" msgstr ""
msgid "DependencyProxy|Create a local proxy for storing frequently used upstream images. %{docLinkStart}Learn more%{docLinkEnd} about dependency proxies." msgid "DependencyProxy|Create a local proxy for storing frequently used upstream images. %{docLinkStart}Learn more%{docLinkEnd} about dependency proxies."
......
...@@ -4,7 +4,7 @@ module QA ...@@ -4,7 +4,7 @@ module QA
module Page module Page
module Group module Group
class DependencyProxy < QA::Page::Base class DependencyProxy < QA::Page::Base
view 'app/views/groups/dependency_proxies/_url.html.haml' do view 'app/assets/javascripts/packages_and_registries/dependency_proxy/app.vue' do
element :dependency_proxy_count element :dependency_proxy_count
end end
......
...@@ -23,7 +23,7 @@ RSpec.describe 'Group Dependency Proxy' do ...@@ -23,7 +23,7 @@ RSpec.describe 'Group Dependency Proxy' do
visit path visit path
expect(page).not_to have_css('.js-dependency-proxy-url') expect(page).not_to have_css('[data-testid="proxy-url"]')
end end
end end
...@@ -43,13 +43,13 @@ RSpec.describe 'Group Dependency Proxy' do ...@@ -43,13 +43,13 @@ RSpec.describe 'Group Dependency Proxy' do
it 'toggles defaults to enabled' do it 'toggles defaults to enabled' do
visit path visit path
expect(page).to have_css('.js-dependency-proxy-url') expect(page).to have_css('[data-testid="proxy-url"]')
end end
it 'shows the proxy URL' do it 'shows the proxy URL' do
visit path visit path
expect(find('.js-dependency-proxy-url').value).to have_content('/dependency_proxy/containers') expect(find('input[data-testid="proxy-url"]').value).to have_content('/dependency_proxy/containers')
end end
it 'hides the proxy URL when feature is disabled' do it 'hides the proxy URL when feature is disabled' do
...@@ -62,7 +62,7 @@ RSpec.describe 'Group Dependency Proxy' do ...@@ -62,7 +62,7 @@ RSpec.describe 'Group Dependency Proxy' do
visit path visit path
expect(page).not_to have_css('.js-dependency-proxy-url') expect(page).not_to have_css('input[data-testid="proxy-url"]')
end end
end end
...@@ -73,7 +73,7 @@ RSpec.describe 'Group Dependency Proxy' do ...@@ -73,7 +73,7 @@ RSpec.describe 'Group Dependency Proxy' do
end end
it 'does not show the feature toggle but shows the proxy URL' do it 'does not show the feature toggle but shows the proxy URL' do
expect(find('.js-dependency-proxy-url').value).to have_content('/dependency_proxy/containers') expect(find('input[data-testid="proxy-url"]').value).to have_content('/dependency_proxy/containers')
end end
end end
end end
...@@ -83,7 +83,7 @@ RSpec.describe 'Group Dependency Proxy' do ...@@ -83,7 +83,7 @@ RSpec.describe 'Group Dependency Proxy' do
sign_in(owner) sign_in(owner)
end end
context 'feature flag is disabled' do context 'feature flag is disabled', :js do
before do before do
stub_feature_flags(dependency_proxy_for_private_groups: false) stub_feature_flags(dependency_proxy_for_private_groups: false)
end end
...@@ -94,7 +94,7 @@ RSpec.describe 'Group Dependency Proxy' do ...@@ -94,7 +94,7 @@ RSpec.describe 'Group Dependency Proxy' do
it 'informs user that feature is only available for public groups' do it 'informs user that feature is only available for public groups' do
visit path visit path
expect(page).to have_content('Dependency proxy feature is limited to public groups for now.') expect(page).to have_content('Dependency Proxy feature is limited to public groups for now.')
end end
end end
end end
......
import { GlAlert, GlFormInputGroup, GlFormGroup, GlSkeletonLoader, GlSprintf } from '@gitlab/ui'; import { GlFormInputGroup, GlFormGroup, GlSkeletonLoader, GlSprintf } from '@gitlab/ui';
import { createLocalVue } from '@vue/test-utils'; import { createLocalVue } from '@vue/test-utils';
import VueApollo from 'vue-apollo'; import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
...@@ -45,7 +45,8 @@ describe('DependencyProxyApp', () => { ...@@ -45,7 +45,8 @@ describe('DependencyProxyApp', () => {
}); });
} }
const findProxyNotAvailableAlert = () => wrapper.findComponent(GlAlert); const findProxyNotAvailableAlert = () => wrapper.findByTestId('proxy-not-available');
const findProxyDisabledAlert = () => wrapper.findByTestId('proxy-disabled');
const findClipBoardButton = () => wrapper.findComponent(ClipboardButton); const findClipBoardButton = () => wrapper.findComponent(ClipboardButton);
const findFormGroup = () => wrapper.findComponent(GlFormGroup); const findFormGroup = () => wrapper.findComponent(GlFormGroup);
const findFormInputGroup = () => wrapper.findComponent(GlFormInputGroup); const findFormInputGroup = () => wrapper.findComponent(GlFormInputGroup);
...@@ -108,38 +109,64 @@ describe('DependencyProxyApp', () => { ...@@ -108,38 +109,64 @@ describe('DependencyProxyApp', () => {
}); });
describe('when the app is loaded', () => { describe('when the app is loaded', () => {
beforeEach(() => { describe('when the dependency proxy is enabled', () => {
createComponent(); beforeEach(() => {
return waitForPromises(); createComponent();
}); return waitForPromises();
});
it('does not render the info alert', () => { it('does not render the info alert', () => {
expect(findProxyNotAvailableAlert().exists()).toBe(false); expect(findProxyNotAvailableAlert().exists()).toBe(false);
}); });
it('renders the main area', () => { it('renders the main area', () => {
expect(findMainArea().exists()).toBe(true); expect(findMainArea().exists()).toBe(true);
}); });
it('renders a form group with a label', () => { it('renders a form group with a label', () => {
expect(findFormGroup().attributes('label')).toBe(DependencyProxyApp.i18n.proxyImagePrefix); expect(findFormGroup().attributes('label')).toBe(
}); DependencyProxyApp.i18n.proxyImagePrefix,
);
});
it('renders a form input group', () => { it('renders a form input group', () => {
expect(findFormInputGroup().exists()).toBe(true); expect(findFormInputGroup().exists()).toBe(true);
expect(findFormInputGroup().props('value')).toBe(proxyData().dependencyProxyImagePrefix); expect(findFormInputGroup().props('value')).toBe(proxyData().dependencyProxyImagePrefix);
}); });
it('form input group has a clipboard button', () => { it('form input group has a clipboard button', () => {
expect(findClipBoardButton().exists()).toBe(true); expect(findClipBoardButton().exists()).toBe(true);
expect(findClipBoardButton().props()).toMatchObject({ expect(findClipBoardButton().props()).toMatchObject({
text: proxyData().dependencyProxyImagePrefix, text: proxyData().dependencyProxyImagePrefix,
title: DependencyProxyApp.i18n.copyImagePrefixText, title: DependencyProxyApp.i18n.copyImagePrefixText,
});
});
it('from group has a description with proxy count', () => {
expect(findProxyCountText().text()).toBe('Contains 2 blobs of images (1024 Bytes)');
}); });
}); });
describe('when the dependency proxy is disabled', () => {
beforeEach(() => {
createComponent({
resolver: jest
.fn()
.mockResolvedValue(proxyDetailsQuery({ extendSettings: { enabled: false } })),
});
return waitForPromises();
});
it('from group has a description with proxy count', () => { it('does not show the main area', () => {
expect(findProxyCountText().text()).toBe('Contains 2 blobs of images (1024 Bytes)'); expect(findMainArea().exists()).toBe(false);
});
it('does not show the loader', () => {
expect(findSkeletonLoader().exists()).toBe(false);
});
it('shows a proxy disabled alert', () => {
expect(findProxyDisabledAlert().text()).toBe(DependencyProxyApp.i18n.proxyDisabledText);
});
}); });
}); });
}); });
......
export const proxyData = () => ({ export const proxyData = () => ({
name: 'Gitlab Org',
dependencyProxyBlobCount: 2, dependencyProxyBlobCount: 2,
dependencyProxyTotalSize: '1024 Bytes', dependencyProxyTotalSize: '1024 Bytes',
dependencyProxyImagePrefix: 'gdk.test:3000/groups/gitlab-org/dependency_proxy/containers', dependencyProxyImagePrefix: 'gdk.test:3000/private-group/dependency_proxy/containers',
dependencyProxyManifests: { nodes: [], __typename: 'DependencyProxyManifestConnection' }, dependencyProxySetting: { enabled: true, __typename: 'DependencyProxySetting' },
dependencyProxyBlobs: { nodes: [], __typename: 'DependencyProxyBlobConnection' },
}); });
export const proxyDetailsQuery = () => ({
export const proxySettings = (extend = {}) => ({ enabled: true, ...extend });
export const proxyDetailsQuery = ({ extendSettings = {} } = {}) => ({
data: { data: {
group: { group: {
...proxyData(), ...proxyData(),
__typename: 'Group', __typename: 'Group',
dependencyProxySetting: {
...proxySettings(extendSettings),
__typename: 'DependencyProxySetting',
},
}, },
}, },
}); });
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