Commit b03b414c authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'tr-show-new-alerts' into 'master'

Highlight row when alert is new

See merge request gitlab-org/gitlab!35708
parents f6a5eae4 47d7099e
...@@ -44,6 +44,8 @@ const initialPaginationState = { ...@@ -44,6 +44,8 @@ const initialPaginationState = {
lastPageSize: null, lastPageSize: null,
}; };
const TWELVE_HOURS_IN_MS = 12 * 60 * 60 * 1000;
export default { export default {
i18n: { i18n: {
noAlertsMsg: s__( noAlertsMsg: s__(
...@@ -149,9 +151,20 @@ export default { ...@@ -149,9 +151,20 @@ export default {
update(data) { update(data) {
const { alertManagementAlerts: { nodes: list = [], pageInfo = {} } = {} } = const { alertManagementAlerts: { nodes: list = [], pageInfo = {} } = {} } =
data.project || {}; data.project || {};
const now = new Date();
const listWithData = list.map(alert => {
const then = new Date(alert.startedAt);
const diff = now - then;
return {
...alert,
isNew: diff < TWELVE_HOURS_IN_MS,
};
});
return { return {
list, list: listWithData,
pageInfo, pageInfo,
}; };
}, },
...@@ -207,9 +220,6 @@ export default { ...@@ -207,9 +220,6 @@ export default {
hasAlerts() { hasAlerts() {
return this.alerts?.list?.length; return this.alerts?.list?.length;
}, },
tbodyTrClass() {
return !this.loading && this.hasAlerts ? bodyTrClass : '';
},
showPaginationControls() { showPaginationControls() {
return Boolean(this.prevPage || this.nextPage); return Boolean(this.prevPage || this.nextPage);
}, },
...@@ -290,6 +300,12 @@ export default { ...@@ -290,6 +300,12 @@ export default {
resetPagination() { resetPagination() {
this.pagination = initialPaginationState; this.pagination = initialPaginationState;
}, },
tbodyTrClass(item) {
return {
[bodyTrClass]: !this.loading && this.hasAlerts,
'new-alert': item?.isNew,
};
},
handleAlertError(errorMessage) { handleAlertError(errorMessage) {
this.errored = true; this.errored = true;
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
......
.alert-management-list { .alert-management-list {
.new-alert {
background-color: $issues-today-bg;
}
// these styles need to be deleted once GlTable component looks in GitLab same as in @gitlab/ui // these styles need to be deleted once GlTable component looks in GitLab same as in @gitlab/ui
table { table {
color: $gray-700; color: $gray-700;
......
---
title: Show when alert is new in the Alerts list
merge_request: 35708
author:
type: added
...@@ -349,6 +349,40 @@ describe('AlertManagementTable', () => { ...@@ -349,6 +349,40 @@ describe('AlertManagementTable', () => {
}); });
expect(findDateFields().exists()).toBe(false); expect(findDateFields().exists()).toBe(false);
}); });
describe('New Alert indicator', () => {
const oldAlert = mockAlerts[0];
const newAlert = { ...oldAlert, isNew: true };
it('should highlight the row when alert is new', () => {
mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: [newAlert] }, alertsCount, errored: false },
loading: false,
});
expect(
findAlerts()
.at(0)
.classes(),
).toContain('new-alert');
});
it('should not highlight the row when alert is not new', () => {
mountComponent({
props: { alertManagementEnabled: true, userCanEnableAlertManagement: true },
data: { alerts: { list: [oldAlert] }, alertsCount, errored: false },
loading: false,
});
expect(
findAlerts()
.at(0)
.classes(),
).not.toContain('new-alert');
});
});
}); });
}); });
......
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