Commit 75bba85e authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch...

Merge branch '230719-tabs-vue-migrate-app-assets-javascripts-environments-components-environments_app-vue-to' into 'master'

Migrate custom Tabs to GlTabs

See merge request gitlab-org/gitlab!42236
parents e183d34d 0d47c86e
...@@ -49,7 +49,7 @@ export default { ...@@ -49,7 +49,7 @@ export default {
variant="info" variant="info"
category="secondary" category="secondary"
type="button" type="button"
class="js-enable-review-app-button" class="gl-w-full js-enable-review-app-button"
> >
{{ s__('Environments|Enable review app') }} {{ s__('Environments|Enable review app') }}
</gl-button> </gl-button>
......
<script> <script>
import { GlDeprecatedButton } from '@gitlab/ui'; import { GlBadge, GlButton, GlTab, GlTabs } from '@gitlab/ui';
import { deprecatedCreateFlash as Flash } from '~/flash'; import { deprecatedCreateFlash as Flash } from '~/flash';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import emptyState from './empty_state.vue'; import emptyState from './empty_state.vue';
...@@ -16,7 +16,10 @@ export default { ...@@ -16,7 +16,10 @@ export default {
ConfirmRollbackModal, ConfirmRollbackModal,
emptyState, emptyState,
EnableReviewAppButton, EnableReviewAppButton,
GlDeprecatedButton, GlBadge,
GlButton,
GlTab,
GlTabs,
StopEnvironmentModal, StopEnvironmentModal,
DeleteEnvironmentModal, DeleteEnvironmentModal,
}, },
...@@ -124,43 +127,87 @@ export default { ...@@ -124,43 +127,87 @@ export default {
}; };
</script> </script>
<template> <template>
<div> <div class="environments-section">
<stop-environment-modal :environment="environmentInStopModal" /> <stop-environment-modal :environment="environmentInStopModal" />
<delete-environment-modal :environment="environmentInDeleteModal" /> <delete-environment-modal :environment="environmentInDeleteModal" />
<confirm-rollback-modal :environment="environmentInRollbackModal" /> <confirm-rollback-modal :environment="environmentInRollbackModal" />
<div class="top-area"> <div class="gl-w-full">
<tabs :tabs="tabs" scope="environments" @onChangeTab="onChangeTab" /> <div
class="
<div class="nav-controls"> gl-display-flex
<enable-review-app-button v-if="state.reviewAppDetails.can_setup_review_app" class="mr-2" /> gl-flex-direction-column
<gl-deprecated-button gl-mt-3
gl-display-md-none!"
>
<enable-review-app-button
v-if="state.reviewAppDetails.can_setup_review_app"
class="gl-mb-3 gl-flex-fill-1"
/>
<gl-button
v-if="canCreateEnvironment && !isLoading" v-if="canCreateEnvironment && !isLoading"
:href="newEnvironmentPath" :href="newEnvironmentPath"
category="primary" category="primary"
variant="success" variant="success"
> >
{{ s__('Environments|New environment') }} {{ s__('Environments|New environment') }}
</gl-deprecated-button> </gl-button>
</div> </div>
<gl-tabs content-class="gl-display-none">
<gl-tab
v-for="(tab, idx) in tabs"
:key="idx"
:title-item-class="`js-environments-tab-${tab.scope}`"
@click="onChangeTab(tab.scope)"
>
<template #title>
<span>{{ tab.name }}</span>
<gl-badge size="sm" class="gl-tab-counter-badge">{{ tab.count }}</gl-badge>
</template>
</gl-tab>
<template #tabs-end>
<div
class="
gl-display-none
gl-display-md-flex
gl-lg-align-items-center
gl-lg-flex-direction-row
gl-lg-flex-fill-1
gl-lg-justify-content-end
gl-lg-mt-0"
>
<enable-review-app-button
v-if="state.reviewAppDetails.can_setup_review_app"
class="gl-mb-3 gl-lg-mr-3 gl-lg-mb-0"
/>
<gl-button
v-if="canCreateEnvironment && !isLoading"
:href="newEnvironmentPath"
category="primary"
variant="success"
>
{{ s__('Environments|New environment') }}
</gl-button>
</div>
</template>
</gl-tabs>
<container
:is-loading="isLoading"
:environments="state.environments"
:pagination="state.paginationInformation"
:can-read-environment="canReadEnvironment"
:canary-deployment-feature-id="canaryDeploymentFeatureId"
:show-canary-deployment-callout="showCanaryDeploymentCallout"
:user-callouts-path="userCalloutsPath"
:lock-promotion-svg-path="lockPromotionSvgPath"
:help-canary-deployments-path="helpCanaryDeploymentsPath"
:deploy-boards-help-path="deployBoardsHelpPath"
@onChangePage="onChangePage"
>
<template v-if="!isLoading && state.environments.length === 0" #emptyState>
<empty-state :help-path="helpPagePath" />
</template>
</container>
</div> </div>
<container
:is-loading="isLoading"
:environments="state.environments"
:pagination="state.paginationInformation"
:can-read-environment="canReadEnvironment"
:canary-deployment-feature-id="canaryDeploymentFeatureId"
:show-canary-deployment-callout="showCanaryDeploymentCallout"
:user-callouts-path="userCalloutsPath"
:lock-promotion-svg-path="lockPromotionSvgPath"
:help-canary-deployments-path="helpCanaryDeploymentsPath"
:deploy-boards-help-path="deployBoardsHelpPath"
@onChangePage="onChangePage"
>
<template v-if="!isLoading && state.environments.length === 0" #emptyState>
<empty-state :help-path="helpPagePath" />
</template>
</container>
</div> </div>
</template> </template>
...@@ -10,6 +10,10 @@ import { validateParams } from '~/pipelines/utils'; ...@@ -10,6 +10,10 @@ import { validateParams } from '~/pipelines/utils';
export default { export default {
methods: { methods: {
onChangeTab(scope) { onChangeTab(scope) {
if (this.scope === scope) {
return;
}
let params = { let params = {
scope, scope,
page: '1', page: '1',
......
---
title: Migrate custom Tabs to GlTabs
merge_request: 42236
author:
type: changed
...@@ -372,7 +372,7 @@ RSpec.describe 'Environments page', :js do ...@@ -372,7 +372,7 @@ RSpec.describe 'Environments page', :js do
let(:role) { :developer } let(:role) { :developer }
it 'developer creates a new environment with a valid name' do it 'developer creates a new environment with a valid name' do
within(".top-area") { click_link 'New environment' } within(".environments-section") { click_link 'New environment' }
fill_in('Name', with: 'production') fill_in('Name', with: 'production')
click_on 'Save' click_on 'Save'
...@@ -380,7 +380,7 @@ RSpec.describe 'Environments page', :js do ...@@ -380,7 +380,7 @@ RSpec.describe 'Environments page', :js do
end end
it 'developer creates a new environmetn with invalid name' do it 'developer creates a new environmetn with invalid name' do
within(".top-area") { click_link 'New environment' } within(".environments-section") { click_link 'New environment' }
fill_in('Name', with: 'name,with,commas') fill_in('Name', with: 'name,with,commas')
click_on 'Save' click_on 'Save'
......
...@@ -40,6 +40,9 @@ describe('Environment', () => { ...@@ -40,6 +40,9 @@ describe('Environment', () => {
return axios.waitForAll(); return axios.waitForAll();
}; };
const findEnvironmentsTabAvailable = () => wrapper.find('.js-environments-tab-available > a');
const findEnvironmentsTabStopped = () => wrapper.find('.js-environments-tab-stopped > a');
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
}); });
...@@ -108,9 +111,16 @@ describe('Environment', () => { ...@@ -108,9 +111,16 @@ describe('Environment', () => {
it('should make an API request when using tabs', () => { it('should make an API request when using tabs', () => {
jest.spyOn(wrapper.vm, 'updateContent').mockImplementation(() => {}); jest.spyOn(wrapper.vm, 'updateContent').mockImplementation(() => {});
wrapper.find('.js-environments-tab-stopped').trigger('click'); findEnvironmentsTabStopped().trigger('click');
expect(wrapper.vm.updateContent).toHaveBeenCalledWith({ scope: 'stopped', page: '1' }); expect(wrapper.vm.updateContent).toHaveBeenCalledWith({ scope: 'stopped', page: '1' });
}); });
it('should not make the same API request when clicking on the current scope tab', () => {
// component starts at available
jest.spyOn(wrapper.vm, 'updateContent').mockImplementation(() => {});
findEnvironmentsTabAvailable().trigger('click');
expect(wrapper.vm.updateContent).toHaveBeenCalledTimes(0);
});
}); });
}); });
}); });
......
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