Commit d335be8a authored by Angelo Gulina's avatar Angelo Gulina Committed by Savas Vedova

Subscription Details: fix table styles and skeleton

parent 512a4bfc
...@@ -26,10 +26,6 @@ export default { ...@@ -26,10 +26,6 @@ export default {
}, },
computed: { computed: {
details() { details() {
if (!Object.keys(this.subscription).length) {
return [];
}
return this.detailsFields.map((detail) => ({ return this.detailsFields.map((detail) => ({
canCopy: detail === 'id', canCopy: detail === 'id',
label: detailsLabels[detail], label: detailsLabels[detail],
......
<script> <script>
import { GlSkeletonLoader } from '@gitlab/ui'; import { GlSkeletonLoader, GlTable } from '@gitlab/ui';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import { copySubscriptionIdButtonText } from '../constants'; import { copySubscriptionIdButtonText } from '../constants';
const placeholderHeightFactor = 32;
const placeholderWidth = 180;
const DEFAULT_TH_CLASSES = 'gl-display-none';
const DEFAULT_TD_CLASSES = 'gl-border-none! gl-h-7 gl-line-height-normal! gl-p-0!';
export default { export default {
i18n: { i18n: {
copySubscriptionIdButtonText, copySubscriptionIdButtonText,
}, },
fields: [
{
key: 'label',
label: '',
thClass: DEFAULT_TH_CLASSES,
tdClass: `${DEFAULT_TD_CLASSES} gl-w-13`,
},
{
key: 'value',
label: '',
thClass: DEFAULT_TH_CLASSES,
tdClass: DEFAULT_TD_CLASSES,
},
],
name: 'SubscriptionDetailsTable', name: 'SubscriptionDetailsTable',
components: { components: {
ClipboardButton, ClipboardButton,
GlSkeletonLoader, GlSkeletonLoader,
GlTable,
}, },
props: { props: {
details: { details: {
...@@ -18,36 +38,65 @@ export default { ...@@ -18,36 +38,65 @@ export default {
required: true, required: true,
}, },
}, },
computed: {
hasContent() {
return this.details.some(({ value }) => Boolean(value));
},
placeholderContainerHeight() {
return this.details.length * placeholderHeightFactor;
},
placeholderContainerWidth() {
return placeholderWidth;
},
placeHolderHeight() {
return placeholderHeightFactor / 2;
},
},
methods: { methods: {
isNotLast(index) { isLastRow(index) {
return index < this.details.length - 1; return index === this.details.length - 1;
},
placeHolderPosition(index) {
return (index - 1) * placeholderHeightFactor;
}, },
}, },
}; };
</script> </script>
<template> <template>
<div v-if="!details.length"> <gl-table v-if="hasContent" :fields="$options.fields" :items="details" class="gl-m-0!">
<gl-skeleton-loader :lines="1" /> <template #cell(label)="{ item }">
<gl-skeleton-loader :lines="1" /> <p class="gl-font-weight-bold" data-testid="details-label">{{ item.label }}:</p>
</div> </template>
<ul v-else class="gl-list-style-none gl-m-0 gl-p-0">
<li <template #cell(value)="{ item }">
v-for="(detail, index) in details" <p class="gl-relative" data-testid="details-content">
:key="detail.label" {{ item.value }}
:class="{ 'gl-mb-3': isNotLast(index) }" <clipboard-button
class="gl-display-flex" v-if="item.canCopy"
> :text="item.value"
<p class="gl-font-weight-bold gl-m-0" data-testid="details-label">{{ detail.label }}:</p> :title="$options.i18n.copySubscriptionIdButtonText"
<p class="gl-m-0 gl-ml-4" data-testid="details-content">{{ detail.value }}</p> category="tertiary"
<clipboard-button class="gl-absolute gl-mt-n2 gl-ml-2"
v-if="detail.canCopy" size="small"
:text="detail.value" />
:title="$options.i18n.copySubscriptionIdButtonText" </p>
category="tertiary" </template>
class="gl-ml-2" </gl-table>
size="small" <div
v-else
:style="{ height: `${placeholderContainerHeight}px`, width: `${placeholderContainerWidth}px` }"
class="gl-pt-2"
>
<gl-skeleton-loader :height="placeholderContainerHeight" :width="placeholderContainerWidth">
<rect
v-for="index in details.length"
:key="index"
:height="placeHolderHeight"
:width="placeholderContainerWidth"
:y="placeHolderPosition(index)"
rx="8"
/> />
</li> </gl-skeleton-loader>
</ul> </div>
</template> </template>
...@@ -67,14 +67,6 @@ describe('Subscription Details Card', () => { ...@@ -67,14 +67,6 @@ describe('Subscription Details Card', () => {
}); });
}); });
describe('with empty subscription', () => {
it('passes an empty array to the table component', () => {
createComponent({ subscription: {} });
expect(findSubscriptionDetailsTable().props('details')).toEqual([]);
});
});
describe('with no title', () => { describe('with no title', () => {
it('does not display a title', () => { it('does not display a title', () => {
createComponent(); createComponent();
......
import { GlSkeletonLoader } from '@gitlab/ui'; import { GlSkeletonLoader } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import SubscriptionDetailsTable from 'ee/pages/admin/cloud_licenses/components/subscription_details_table.vue'; import SubscriptionDetailsTable from 'ee/pages/admin/cloud_licenses/components/subscription_details_table.vue';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
...@@ -22,11 +22,10 @@ describe('Subscription Details Table', () => { ...@@ -22,11 +22,10 @@ describe('Subscription Details Table', () => {
const findContentCells = () => wrapper.findAllByTestId('details-content'); const findContentCells = () => wrapper.findAllByTestId('details-content');
const findLabelCells = () => wrapper.findAllByTestId('details-label'); const findLabelCells = () => wrapper.findAllByTestId('details-label');
const findLastRow = () => wrapper.findAll('li').wrappers.slice(-1).pop();
const findClipboardButton = () => wrapper.findComponent(ClipboardButton); const findClipboardButton = () => wrapper.findComponent(ClipboardButton);
const createComponent = (details = licenseDetails) => { const createComponent = (details = licenseDetails) => {
wrapper = extendedWrapper(shallowMount(SubscriptionDetailsTable, { propsData: { details } })); wrapper = extendedWrapper(mount(SubscriptionDetailsTable, { propsData: { details } }));
}; };
afterEach(() => { afterEach(() => {
...@@ -52,10 +51,6 @@ describe('Subscription Details Table', () => { ...@@ -52,10 +51,6 @@ describe('Subscription Details Table', () => {
expect(findLabelCells().wrappers.every(hasFontWeightBold)).toBe(true); expect(findLabelCells().wrappers.every(hasFontWeightBold)).toBe(true);
}); });
it('does not add space to the last row', () => {
expect(findLastRow().classes('gl-mb-3')).toBe(false);
});
it('does not show a clipboard button', () => { it('does not show a clipboard button', () => {
expect(findClipboardButton().exists()).toBe(false); expect(findClipboardButton().exists()).toBe(false);
}); });
......
...@@ -5,6 +5,9 @@ export const license = { ...@@ -5,6 +5,9 @@ export const license = {
lastSync: 'just now - actual date', lastSync: 'just now - actual date',
startsAt: '22 February', startsAt: '22 February',
renews: 'in 11 months', renews: 'in 11 months',
name: 'Jane Doe',
email: 'user@acmecorp.com',
company: 'ACME Corp',
}, },
}; };
......
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