Commit c62a5ad2 authored by Andrew Fontaine's avatar Andrew Fontaine Committed by David O'Regan

Add button to toggle deployment details

This button will toggle the display of additional details, such as the
user who triggered the deployment, the job, and the git ref.
parent fdbca440
<script> <script>
import { GlBadge, GlIcon, GlTooltipDirective as GlTooltip } from '@gitlab/ui'; import { GlBadge, GlButton, GlCollapse, GlIcon, GlTooltipDirective as GlTooltip } from '@gitlab/ui';
import { GlBreakpointInstance } from '@gitlab/ui/dist/utils';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
...@@ -10,6 +11,8 @@ export default { ...@@ -10,6 +11,8 @@ export default {
ClipboardButton, ClipboardButton,
DeploymentStatusBadge, DeploymentStatusBadge,
GlBadge, GlBadge,
GlButton,
GlCollapse,
GlIcon, GlIcon,
TimeAgoTooltip, TimeAgoTooltip,
}, },
...@@ -27,6 +30,9 @@ export default { ...@@ -27,6 +30,9 @@ export default {
required: false, required: false,
}, },
}, },
data() {
return { visible: false };
},
computed: { computed: {
status() { status() {
return this.deployment?.status; return this.deployment?.status;
...@@ -40,43 +46,103 @@ export default { ...@@ -40,43 +46,103 @@ export default {
createdAt() { createdAt() {
return this.deployment?.createdAt; return this.deployment?.createdAt;
}, },
isMobile() {
return !GlBreakpointInstance.isDesktop();
},
detailsButton() {
return this.visible
? { text: this.$options.i18n.hideDetails, icon: 'expand-up' }
: { text: this.$options.i18n.showDetails, icon: 'expand-down' };
},
detailsButtonClasses() {
return this.isMobile ? 'gl-sr-only' : '';
},
},
methods: {
toggleCollapse() {
this.visible = !this.visible;
},
}, },
i18n: { i18n: {
latestBadge: s__('Deployment|Latest Deployed'), latestBadge: s__('Deployment|Latest Deployed'),
deploymentId: s__('Deployment|Deployment ID'), deploymentId: s__('Deployment|Deployment ID'),
copyButton: __('Copy commit SHA'), copyButton: __('Copy commit SHA'),
commitSha: __('Commit SHA'), commitSha: __('Commit SHA'),
showDetails: __('Show details'),
hideDetails: __('Hide details'),
}, },
headerClasses: [
'gl-display-flex',
'gl-align-items-flex-start',
'gl-md-align-items-center',
'gl-justify-content-space-between',
'gl-pr-6',
],
headerDetailsClasses: [
'gl-display-flex',
'gl-flex-direction-column',
'gl-md-flex-direction-row',
'gl-align-items-flex-start',
'gl-md-align-items-center',
'gl-font-sm',
'gl-text-gray-700',
],
deploymentStatusClasses: [
'gl-display-flex',
'gl-gap-x-3',
'gl-mr-0',
'gl-md-mr-5',
'gl-mb-3',
'gl-md-mb-0',
],
}; };
</script> </script>
<template> <template>
<div class="gl-display-flex gl-align-items-center gl-gap-x-3 gl-font-sm gl-text-gray-700"> <div>
<deployment-status-badge v-if="status" :status="status" /> <div :class="$options.headerClasses">
<gl-badge v-if="latest" variant="info">{{ $options.i18n.latestBadge }}</gl-badge> <div :class="$options.headerDetailsClasses">
<div <div :class="$options.deploymentStatusClasses">
v-if="iid" <deployment-status-badge v-if="status" :status="status" />
v-gl-tooltip <gl-badge v-if="latest" variant="info">{{ $options.i18n.latestBadge }}</gl-badge>
:title="$options.i18n.deploymentId" </div>
:aria-label="$options.i18n.deploymentId" <div class="gl-display-flex gl-align-items-center gl-gap-x-5">
> <div
<gl-icon ref="deployment-iid-icon" name="deployments" /> #{{ iid }} v-if="iid"
</div> v-gl-tooltip
<div :title="$options.i18n.deploymentId"
v-if="shortSha" :aria-label="$options.i18n.deploymentId"
data-testid="deployment-commit-sha" >
class="gl-font-monospace gl-display-flex gl-align-items-center" <gl-icon ref="deployment-iid-icon" name="deployments" /> #{{ iid }}
> </div>
<gl-icon ref="deployment-commit-icon" name="commit" class="gl-mr-2" /> <div
<span v-gl-tooltip :title="$options.i18n.commitSha">{{ shortSha }}</span> v-if="shortSha"
<clipboard-button data-testid="deployment-commit-sha"
:text="shortSha" class="gl-font-monospace gl-display-flex gl-align-items-center"
>
<gl-icon ref="deployment-commit-icon" name="commit" class="gl-mr-2" />
<span v-gl-tooltip :title="$options.i18n.commitSha">{{ shortSha }}</span>
<clipboard-button
:text="shortSha"
category="tertiary"
:title="$options.i18n.copyButton"
size="small"
/>
</div>
<time-ago-tooltip v-if="createdAt" :time="createdAt">
<template #default="{ timeAgo }"> <gl-icon name="calendar" /> {{ timeAgo }} </template>
</time-ago-tooltip>
</div>
</div>
<gl-button
ref="details-toggle"
category="tertiary" category="tertiary"
:title="$options.i18n.copyButton" :icon="detailsButton.icon"
size="small" :button-text-classes="detailsButtonClasses"
/> @click="toggleCollapse"
<time-ago-tooltip v-if="createdAt" :time="createdAt" class="gl-ml-5!"> >
<template #default="{ timeAgo }"> <gl-icon name="calendar" /> {{ timeAgo }} </template> {{ detailsButton.text }}
</time-ago-tooltip> </gl-button>
</div> </div>
<gl-collapse :visible="visible" />
</div> </div>
</template> </template>
import { GlCollapse } from '@gitlab/ui';
import { mountExtended } from 'helpers/vue_test_utils_helper'; import { mountExtended } from 'helpers/vue_test_utils_helper';
import { __, s__ } from '~/locale';
import { formatDate } from '~/lib/utils/datetime_utility';
import { useFakeDate } from 'helpers/fake_date'; import { useFakeDate } from 'helpers/fake_date';
import { stubTransition } from 'helpers/stub_transition';
import { formatDate } from '~/lib/utils/datetime_utility';
import { __, s__ } from '~/locale';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import Deployment from '~/environments/components/deployment.vue'; import Deployment from '~/environments/components/deployment.vue';
import DeploymentStatusBadge from '~/environments/components/deployment_status_badge.vue'; import DeploymentStatusBadge from '~/environments/components/deployment_status_badge.vue';
...@@ -19,6 +21,7 @@ describe('~/environments/components/deployment.vue', () => { ...@@ -19,6 +21,7 @@ describe('~/environments/components/deployment.vue', () => {
deployment, deployment,
...propsData, ...propsData,
}, },
stubs: { transition: stubTransition() },
}); });
afterEach(() => { afterEach(() => {
...@@ -148,4 +151,29 @@ describe('~/environments/components/deployment.vue', () => { ...@@ -148,4 +151,29 @@ describe('~/environments/components/deployment.vue', () => {
}); });
}); });
}); });
describe('collapse', () => {
let collapse;
let button;
beforeEach(() => {
wrapper = createWrapper();
collapse = wrapper.findComponent(GlCollapse);
button = wrapper.findComponent({ ref: 'details-toggle' });
});
it('is collapsed by default', () => {
expect(collapse.attributes('visible')).toBeUndefined();
expect(button.props('icon')).toBe('expand-down');
expect(button.text()).toBe(__('Show details'));
});
it('opens on click', async () => {
await button.trigger('click');
expect(button.text()).toBe(__('Hide details'));
expect(button.props('icon')).toBe('expand-up');
expect(collapse.attributes('visible')).toBe('visible');
});
});
}); });
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