Commit b75d5a1f authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch 'tr-filter-internal-strings' into 'master'

Remove internal fields from alert details table

See merge request gitlab-org/gitlab!43076
parents 3cfc8a73 d6573b85
...@@ -45,13 +45,6 @@ export default { ...@@ -45,13 +45,6 @@ export default {
loading() { loading() {
return this.$apollo.queries.alert.loading; return this.$apollo.queries.alert.loading;
}, },
alertTableFields() {
if (this.alert) {
const { detailsUrl, __typename, ...restDetails } = this.alert;
return restDetails;
}
return null;
},
}, },
}; };
</script> </script>
...@@ -64,7 +57,7 @@ export default { ...@@ -64,7 +57,7 @@ export default {
<description-component v-bind="$attrs" /> <description-component v-bind="$attrs" />
</gl-tab> </gl-tab>
<gl-tab v-if="alert" class="alert-management-details" :title="s__('Incident|Alert details')"> <gl-tab v-if="alert" class="alert-management-details" :title="s__('Incident|Alert details')">
<alert-details-table :alert="alertTableFields" :loading="loading" /> <alert-details-table :alert="alert" :loading="loading" />
</gl-tab> </gl-tab>
</gl-tabs> </gl-tabs>
</div> </div>
......
...@@ -9,6 +9,22 @@ import { ...@@ -9,6 +9,22 @@ import {
const thClass = 'gl-bg-transparent! gl-border-1! gl-border-b-solid! gl-border-gray-200!'; const thClass = 'gl-bg-transparent! gl-border-1! gl-border-b-solid! gl-border-gray-200!';
const tdClass = 'gl-border-gray-100! gl-p-5!'; const tdClass = 'gl-border-gray-100! gl-p-5!';
const allowedFields = [
'iid',
'title',
'severity',
'status',
'startedAt',
'eventCount',
'monitoringTool',
'service',
'description',
'endedAt',
'details',
];
const filterAllowedFields = ([fieldName]) => allowedFields.includes(fieldName);
const arrayToObject = ([fieldName, value]) => ({ fieldName, value });
export default { export default {
components: { components: {
...@@ -46,10 +62,9 @@ export default { ...@@ -46,10 +62,9 @@ export default {
if (!this.alert) { if (!this.alert) {
return []; return [];
} }
return Object.entries(this.alert).map(([fieldName, value]) => ({ return Object.entries(this.alert)
fieldName, .filter(filterAllowedFields)
value, .map(arrayToObject);
}));
}, },
}, },
}; };
......
---
title: Remove internal fields from alert details table
merge_request: 43076
author:
type: changed
...@@ -79,7 +79,7 @@ describe('Incident Tabs component', () => { ...@@ -79,7 +79,7 @@ describe('Incident Tabs component', () => {
it('renders the alert details table with the correct props', () => { it('renders the alert details table with the correct props', () => {
const alert = { iid: mockAlert.iid }; const alert = { iid: mockAlert.iid };
expect(findAlertDetailsComponent().props('alert')).toEqual(alert); expect(findAlertDetailsComponent().props('alert')).toMatchObject(alert);
expect(findAlertDetailsComponent().props('loading')).toBe(true); expect(findAlertDetailsComponent().props('loading')).toBe(true);
}); });
......
...@@ -14,6 +14,7 @@ const mockAlert = { ...@@ -14,6 +14,7 @@ const mockAlert = {
assignees: { nodes: [] }, assignees: { nodes: [] },
notes: { nodes: [] }, notes: { nodes: [] },
todos: { nodes: [] }, todos: { nodes: [] },
__typename: 'AlertManagementAlert',
}; };
describe('AlertDetails', () => { describe('AlertDetails', () => {
...@@ -35,6 +36,8 @@ describe('AlertDetails', () => { ...@@ -35,6 +36,8 @@ describe('AlertDetails', () => {
}); });
const findTableComponent = () => wrapper.find(GlTable); const findTableComponent = () => wrapper.find(GlTable);
const findTableKeys = () => findTableComponent().findAll('tbody td:first-child');
const findTableField = (fields, fieldName) => fields.filter(row => row.text() === fieldName);
describe('Alert details', () => { describe('Alert details', () => {
describe('empty state', () => { describe('empty state', () => {
...@@ -69,6 +72,24 @@ describe('AlertDetails', () => { ...@@ -69,6 +72,24 @@ describe('AlertDetails', () => {
it('renders a cell based on alert data', () => { it('renders a cell based on alert data', () => {
expect(findTableComponent().text()).toContain('SyntaxError: Invalid or unexpected token'); expect(findTableComponent().text()).toContain('SyntaxError: Invalid or unexpected token');
}); });
it('should show allowed alert fields', () => {
const fields = findTableKeys();
expect(findTableField(fields, 'Iid').exists()).toBe(true);
expect(findTableField(fields, 'Title').exists()).toBe(true);
expect(findTableField(fields, 'Severity').exists()).toBe(true);
expect(findTableField(fields, 'Status').exists()).toBe(true);
});
it('should not show disallowed alert fields', () => {
const fields = findTableKeys();
expect(findTableField(fields, 'Typename').exists()).toBe(false);
expect(findTableField(fields, 'Todos').exists()).toBe(false);
expect(findTableField(fields, 'Notes').exists()).toBe(false);
expect(findTableField(fields, 'Assignees').exists()).toBe(false);
});
}); });
}); });
}); });
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