Commit 37a65459 authored by Nathan Friend's avatar Nathan Friend Committed by Natalia Tepluhina

Move group-level release stats into tab

parent 05c87a33
...@@ -182,3 +182,10 @@ ...@@ -182,3 +182,10 @@
.gl-mb-n3 { .gl-mb-n3 {
margin-bottom: -$gl-spacing-scale-3; margin-bottom: -$gl-spacing-scale-3;
} }
// Will be moved to @gitlab/ui in https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1408
$gl-line-height-42: px-to-rem(42px);
.gl-line-height-42 {
line-height: $gl-line-height-42;
}
<script> <script>
import { GlTabs, GlTab } from '@gitlab/ui';
import { mergeUrlParams, updateHistory, getParameterValues } from '~/lib/utils/url_utility';
import { TABS } from '../constants';
import ReleaseStatsCard from './release_stats_card.vue'; import ReleaseStatsCard from './release_stats_card.vue';
export default { export default {
name: 'CiCdAnalyticsApp', name: 'CiCdAnalyticsApp',
components: { components: {
ReleaseStatsCard, ReleaseStatsCard,
GlTabs,
GlTab,
},
data() {
return {
selectedTabIndex: 0,
};
},
created() {
this.selectTab();
window.addEventListener('popstate', this.selectTab);
},
methods: {
selectTab() {
const [tabQueryParam] = getParameterValues('tab');
const tabIndex = TABS.indexOf(tabQueryParam);
this.selectedTabIndex = tabIndex >= 0 ? tabIndex : 0;
},
onTabChange(newIndex) {
if (newIndex !== this.selectedTabIndex) {
this.selectedTabIndex = newIndex;
const path = mergeUrlParams({ tab: TABS[newIndex] }, window.location.pathname);
updateHistory({ url: path, title: window.title });
}
},
}, },
}; };
</script> </script>
<template> <template>
<div> <div>
<gl-tabs :value="selectedTabIndex" @input="onTabChange">
<gl-tab :title="s__('CICDAnalytics|Release statistics')">
<release-stats-card class="gl-mt-5" /> <release-stats-card class="gl-mt-5" />
</gl-tab>
</gl-tabs>
</div> </div>
</template> </template>
...@@ -115,7 +115,7 @@ export default { ...@@ -115,7 +115,7 @@ export default {
<rect x="50" y="94" rx="3" ry="3" width="300" height="31" /> <rect x="50" y="94" rx="3" ry="3" width="300" height="31" />
</gl-skeleton-loader> </gl-skeleton-loader>
<template v-else> <template v-else>
<span class="gl-font-size-h-display">{{ stat.stat }}</span> <span class="gl-font-size-h-display gl-line-height-42">{{ stat.stat }}</span>
{{ stat.title }} {{ stat.title }}
</template> </template>
</div> </div>
......
export const STAT_ERROR_PLACEHOLDER = '-'; export const STAT_ERROR_PLACEHOLDER = '-';
export const TABS = ['release-statistics'];
---
title: Move group-level release statistics into tab
merge_request: 60749
author:
type: changed
import { GlTabs, GlTab } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import CiCdAnalyticsApp from 'ee/analytics/group_ci_cd_analytics/components/app.vue'; import CiCdAnalyticsApp from 'ee/analytics/group_ci_cd_analytics/components/app.vue';
import ReleaseStatsCard from 'ee/analytics/group_ci_cd_analytics/components/release_stats_card.vue'; import ReleaseStatsCard from 'ee/analytics/group_ci_cd_analytics/components/release_stats_card.vue';
import setWindowLocation from 'helpers/set_window_location_helper';
import { TEST_HOST } from 'helpers/test_constants';
import { getParameterValues } from '~/lib/utils/url_utility';
jest.mock('~/lib/utils/url_utility');
describe('ee/analytics/group_ci_cd_analytics/components/app.vue', () => { describe('ee/analytics/group_ci_cd_analytics/components/app.vue', () => {
let wrapper; let wrapper;
beforeEach(() => {
getParameterValues.mockReturnValue([]);
});
const createComponent = () => { const createComponent = () => {
wrapper = shallowMount(CiCdAnalyticsApp); wrapper = shallowMount(CiCdAnalyticsApp);
}; };
it('renders the release stats card', () => { const findGlTabs = () => wrapper.findComponent(GlTabs);
const findAllGlTabs = () => wrapper.findAllComponents(GlTab);
const findGlTabAtIndex = (index) => findAllGlTabs().at(index);
describe('tabs', () => {
beforeEach(() => {
createComponent(); createComponent();
expect(wrapper.find(ReleaseStatsCard).exists()).toBe(true); });
it('renders tabs in the correct order', () => {
expect(findGlTabs().exists()).toBe(true);
expect(findGlTabAtIndex(0).attributes('title')).toBe('Release statistics');
});
});
describe('release statistics', () => {
beforeEach(() => {
createComponent();
});
it('renders the release statistics component inside the first tab', () => {
expect(findGlTabAtIndex(0).find(ReleaseStatsCard).exists()).toBe(true);
});
});
describe('when provided with a query param', () => {
it.each`
tab | index
${'release-statistics'} | ${'0'}
${'fake'} | ${'0'}
${''} | ${'0'}
`('shows the correct tab for URL parameter "$tab"', ({ tab, index }) => {
setWindowLocation(`${TEST_HOST}/groups/gitlab-org/gitlab/-/analytics/ci_cd?tab=${tab}`);
getParameterValues.mockImplementation((name) => {
expect(name).toBe('tab');
return tab ? [tab] : [];
});
createComponent();
expect(findGlTabs().attributes('value')).toBe(index);
});
}); });
}); });
...@@ -5597,6 +5597,9 @@ msgid_plural "CICDAnalytics|Releases" ...@@ -5597,6 +5597,9 @@ msgid_plural "CICDAnalytics|Releases"
msgstr[0] "" msgstr[0] ""
msgstr[1] "" msgstr[1] ""
msgid "CICDAnalytics|Release statistics"
msgstr ""
msgid "CICDAnalytics|Releases" msgid "CICDAnalytics|Releases"
msgstr "" msgstr ""
......
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