Commit d2d82cf0 authored by Dave Pisek's avatar Dave Pisek

Generic vulnerability: Remove grid column margins

* Makes use of css-grids to switch the first column to being
  the same width as it's content
* Removes grid-row component
parent 97bbe800
<script>
export default {
props: {
label: {
type: String,
required: true,
},
},
};
</script>
<template>
<div
class="generic-report-row gl-display-grid gl-px-3 gl-py-5 gl-border-b-1 gl-border-b-solid gl-border-gray-100"
>
<strong>{{ label }}</strong>
<div data-testid="reportContent">
<slot></slot>
</div>
</div>
</template>
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
import { GlCollapse, GlIcon } from '@gitlab/ui'; import { GlCollapse, GlIcon } from '@gitlab/ui';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import ReportItem from './report_item.vue'; import ReportItem from './report_item.vue';
import ReportRow from './report_row.vue';
import { filterTypesAndLimitListDepth } from './types/utils'; import { filterTypesAndLimitListDepth } from './types/utils';
const NESTED_LISTS_MAX_DEPTH = 4; const NESTED_LISTS_MAX_DEPTH = 4;
...@@ -15,7 +14,6 @@ export default { ...@@ -15,7 +14,6 @@ export default {
GlCollapse, GlCollapse,
GlIcon, GlIcon,
ReportItem, ReportItem,
ReportRow,
}, },
props: { props: {
details: { details: {
...@@ -57,11 +55,14 @@ export default { ...@@ -57,11 +55,14 @@ export default {
</h3> </h3>
</header> </header>
<gl-collapse :visible="showSection"> <gl-collapse :visible="showSection">
<div data-testid="reports"> <div class="generic-report-container" data-testid="reports">
<template v-for="[label, item] in detailsEntries"> <template v-for="[label, item] in detailsEntries">
<report-row :key="label" :label="item.name" :data-testid="`report-row-${label}`"> <div :key="label" class="generic-report-row" :data-testid="`report-row-${label}`">
<report-item :item="item" /> <strong class="generic-report-column">{{ item.name }}</strong>
</report-row> <div class="generic-report-column" data-testid="reportContent">
<report-item :item="item" :data-testid="`report-item-${label}`" />
</div>
</div>
</template> </template>
</div> </div>
</gl-collapse> </gl-collapse>
......
...@@ -120,15 +120,32 @@ $selection-summary-with-error-height: 118px; ...@@ -120,15 +120,32 @@ $selection-summary-with-error-height: 118px;
} }
} }
.generic-report-container {
@include gl-display-grid;
grid-template-columns: max-content auto;
}
.generic-report-row { .generic-report-row {
grid-template-columns: minmax(150px, 1fr) 3fr; display: contents;
grid-column-gap: $gl-spacing-scale-5;
&:last-child { &:last-child .generic-report-column {
@include gl-border-b-0; @include gl-border-b-0;
} }
} }
.generic-report-column {
@include gl-px-3;
@include gl-py-5;
@include gl-border-b-1;
@include gl-border-b-solid;
@include gl-border-gray-100;
&:first-child {
max-width: 15rem;
}
}
.generic-report-list { .generic-report-list {
li { li {
@include gl-ml-0; @include gl-ml-0;
...@@ -140,4 +157,3 @@ $selection-summary-with-error-height: 118px; ...@@ -140,4 +157,3 @@ $selection-summary-with-error-height: 118px;
list-style-type: disc; list-style-type: disc;
} }
} }
---
title: 'Generic vulnerability reports: Remove extra margin between report columns'
merge_request: 58720
author:
type: other
import { shallowMount } from '@vue/test-utils';
import ReportRow from 'ee/vulnerabilities/components/generic_report/report_row.vue';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
describe('ee/vulnerabilities/components/generic_report/report_row.vue', () => {
let wrapper;
const createWrapper = ({ ...options } = {}) =>
extendedWrapper(
shallowMount(ReportRow, {
propsData: {
label: 'Foo',
},
...options,
}),
);
it('renders the default slot', () => {
const slotContent = 'foo bar';
wrapper = createWrapper({ slots: { default: slotContent } });
expect(wrapper.findByTestId('reportContent').text()).toBe(slotContent);
});
});
import { within, fireEvent } from '@testing-library/dom'; import { within, fireEvent } from '@testing-library/dom';
import { mount } from '@vue/test-utils'; import { mount } from '@vue/test-utils';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import ReportItem from 'ee/vulnerabilities/components/generic_report/report_item.vue';
import ReportRow from 'ee/vulnerabilities/components/generic_report/report_row.vue';
import ReportSection from 'ee/vulnerabilities/components/generic_report/report_section.vue'; import ReportSection from 'ee/vulnerabilities/components/generic_report/report_section.vue';
import { REPORT_TYPE_URL } from 'ee/vulnerabilities/components/generic_report/types/constants'; import { REPORT_TYPE_URL } from 'ee/vulnerabilities/components/generic_report/types/constants';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
...@@ -47,9 +45,9 @@ describe('ee/vulnerabilities/components/generic_report/report_section.vue', () = ...@@ -47,9 +45,9 @@ describe('ee/vulnerabilities/components/generic_report/report_section.vue', () =
name: /evidence/i, name: /evidence/i,
}); });
const findReportsSection = () => wrapper.findByTestId('reports'); const findReportsSection = () => wrapper.findByTestId('reports');
const findAllReportRows = () => wrapper.findAllComponents(ReportRow); const findAllReportRows = () => wrapper.findAll('[data-testid*="report-row"');
const findReportRowByLabel = (label) => wrapper.findByTestId(`report-row-${label}`); const findReportRowByLabel = (label) => wrapper.findByTestId(`report-row-${label}`);
const findItemWithinRow = (row) => row.findComponent(ReportItem); const findReportItemByLabel = (label) => wrapper.findByTestId(`report-item-${label}`);
const supportedReportTypesLabels = Object.keys(TEST_DATA.supportedTypes); const supportedReportTypesLabels = Object.keys(TEST_DATA.supportedTypes);
describe('with supported report types', () => { describe('with supported report types', () => {
...@@ -77,20 +75,21 @@ describe('ee/vulnerabilities/components/generic_report/report_section.vue', () = ...@@ -77,20 +75,21 @@ describe('ee/vulnerabilities/components/generic_report/report_section.vue', () =
expect(findAllReportRows()).toHaveLength(supportedReportTypesLabels.length); expect(findAllReportRows()).toHaveLength(supportedReportTypesLabels.length);
}); });
it.each(supportedReportTypesLabels)('passes the correct props to report row: %s', (label) => { it.each(supportedReportTypesLabels)(
expect(findReportRowByLabel(label).props()).toMatchObject({ 'renders the correct label for report row: %s',
label: TEST_DATA.supportedTypes[label].name, (label) => {
}); expect(within(findReportRowByLabel(label).element).getByText(label)).toBeInstanceOf(
}); HTMLElement,
);
},
);
}); });
describe('report items', () => { describe('report items', () => {
it.each(supportedReportTypesLabels)( it.each(supportedReportTypesLabels)(
'passes the correct props to item for row: %s', 'passes the correct props to item for row: %s',
(label) => { (label) => {
const row = findReportRowByLabel(label); expect(findReportItemByLabel(label).props()).toMatchObject({
expect(findItemWithinRow(row).props()).toMatchObject({
item: TEST_DATA.supportedTypes[label], item: TEST_DATA.supportedTypes[label],
}); });
}, },
......
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