Commit d426ce3e authored by Miguel Rincon's avatar Miguel Rincon

Merge branch '273781-policy-type-column' into 'master'

Add policy type column

See merge request gitlab-org/gitlab!65075
parents 0f642b99 ca912bf6
...@@ -30,6 +30,12 @@ const createPolicyFetchError = ({ gqlError, networkError }) => { ...@@ -30,6 +30,12 @@ const createPolicyFetchError = ({ gqlError, networkError }) => {
}); });
}; };
const getPoliciesWithType = (policies, policyType) =>
policies.map((policy) => ({
...policy,
policyType,
}));
export default { export default {
components: { components: {
GlTable, GlTable,
...@@ -110,7 +116,10 @@ export default { ...@@ -110,7 +116,10 @@ export default {
return setUrlFragment(this.documentationPath, 'container-network-policy'); return setUrlFragment(this.documentationPath, 'container-network-policy');
}, },
policies() { policies() {
return [...this.networkPolicies, ...this.scanExecutionPolicies]; return [
...getPoliciesWithType(this.networkPolicies, s__('SecurityPolicies|Network')),
...getPoliciesWithType(this.scanExecutionPolicies, s__('SecurityPolicies|Scan execution')),
];
}, },
isLoadingPolicies() { isLoadingPolicies() {
return ( return (
...@@ -156,9 +165,15 @@ export default { ...@@ -156,9 +165,15 @@ export default {
label: s__('NetworkPolicies|Name'), label: s__('NetworkPolicies|Name'),
thClass: 'gl-w-half', thClass: 'gl-w-half',
}, },
{
key: 'policyType',
label: s__('SecurityPolicies|Policy type'),
sortable: true,
},
{ {
key: 'updatedAt', key: 'updatedAt',
label: s__('NetworkPolicies|Last modified'), label: s__('NetworkPolicies|Last modified'),
sortable: true,
}, },
]; ];
// Adds column 'namespace' only while 'all environments' option is selected // Adds column 'namespace' only while 'all environments' option is selected
...@@ -239,6 +254,9 @@ export default { ...@@ -239,6 +254,9 @@ export default {
:busy="isLoadingPolicies" :busy="isLoadingPolicies"
:items="policies" :items="policies"
:fields="fields" :fields="fields"
sort-icon-left
sort-by="updatedAt"
sort-desc
head-variant="white" head-variant="white"
stacked="md" stacked="md"
thead-class="gl-text-gray-900 border-bottom" thead-class="gl-text-gray-900 border-bottom"
......
...@@ -146,18 +146,27 @@ describe('PolicyList component', () => { ...@@ -146,18 +146,27 @@ describe('PolicyList component', () => {
rows = wrapper.findAll('tr'); rows = wrapper.findAll('tr');
}); });
it.each` describe.each`
rowIndex | expectedPolicyName rowIndex | expectedPolicyName | expectedPolicyType
${1} | ${mockNetworkPoliciesResponse[0].name} ${1} | ${mockScanExecutionPoliciesResponse[0].name} | ${'Scan execution'}
${2} | ${'drop-outbound'} ${2} | ${mockNetworkPoliciesResponse[0].name} | ${'Network'}
${3} | ${'allow-inbound-http'} ${3} | ${'drop-outbound'} | ${'Network'}
${4} | ${mockScanExecutionPoliciesResponse[0].name} ${4} | ${'allow-inbound-http'} | ${'Network'}
`( `('policy in row #$rowIndex', ({ rowIndex, expectedPolicyName, expectedPolicyType }) => {
'renders "$expectedPolicyName" policy in row #$rowIndex', let row;
({ expectedPolicyName, rowIndex }) => {
expect(rows.at(rowIndex).text()).toContain(expectedPolicyName); beforeEach(() => {
}, row = rows.at(rowIndex);
); });
it(`renders ${expectedPolicyName} in the name cell`, () => {
expect(row.findAll('td').at(1).text()).toBe(expectedPolicyName);
});
it(`renders ${expectedPolicyType} in the policy type cell`, () => {
expect(row.findAll('td').at(2).text()).toBe(expectedPolicyType);
});
});
}); });
describe('status column', () => { describe('status column', () => {
...@@ -166,7 +175,7 @@ describe('PolicyList component', () => { ...@@ -166,7 +175,7 @@ describe('PolicyList component', () => {
}); });
it('renders a checkmark icon for enabled policies', () => { it('renders a checkmark icon for enabled policies', () => {
const icon = findPolicyStatusCells().at(0).find('svg'); const icon = findPolicyStatusCells().at(1).find('svg');
expect(icon.exists()).toBe(true); expect(icon.exists()).toBe(true);
expect(icon.props('name')).toBe('check-circle-filled'); expect(icon.props('name')).toBe('check-circle-filled');
...@@ -174,7 +183,7 @@ describe('PolicyList component', () => { ...@@ -174,7 +183,7 @@ describe('PolicyList component', () => {
}); });
it('renders a "Disabled" label for screen readers for disabled policies', () => { it('renders a "Disabled" label for screen readers for disabled policies', () => {
const span = findPolicyStatusCells().at(1).find('span'); const span = findPolicyStatusCells().at(2).find('span');
expect(span.exists()).toBe(true); expect(span.exists()).toBe(true);
expect(span.attributes('class')).toBe('gl-sr-only'); expect(span.attributes('class')).toBe('gl-sr-only');
...@@ -190,7 +199,7 @@ describe('PolicyList component', () => { ...@@ -190,7 +199,7 @@ describe('PolicyList component', () => {
it('renders namespace column', () => { it('renders namespace column', () => {
const namespaceHeader = findPoliciesTable().findAll('[role="columnheader"]').at(2); const namespaceHeader = findPoliciesTable().findAll('[role="columnheader"]').at(2);
expect(namespaceHeader.text()).toBe('Namespace'); expect(namespaceHeader.text()).toContain('Namespace');
}); });
}); });
......
...@@ -28838,6 +28838,12 @@ msgstr "" ...@@ -28838,6 +28838,12 @@ msgstr ""
msgid "SecurityPolicies|Latest scan" msgid "SecurityPolicies|Latest scan"
msgstr "" msgstr ""
msgid "SecurityPolicies|Network"
msgstr ""
msgid "SecurityPolicies|Policy type"
msgstr ""
msgid "SecurityPolicies|Scan execution" msgid "SecurityPolicies|Scan execution"
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