Commit 9235a1d4 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Update empty state behaviour for incidents list

parent 58e6326a
......@@ -208,6 +208,31 @@ export default {
isEmpty() {
return !this.incidents.list?.length;
},
showList() {
return !this.isEmpty || this.errored || this.loading;
},
activeClosedTabHasNoIncidents() {
const { all, closed } = this.incidentsCount || {};
const isClosedTabActive = this.statusFilter === this.$options.statusTabs[1].filters;
return isClosedTabActive && all && !closed;
},
emptyStateData() {
const {
emptyState: { title, emptyClosedTabTitle, description },
createIncidentBtnLabel,
} = this.$options.i18n;
if (this.activeClosedTabHasNoIncidents) {
return { title: emptyClosedTabTitle };
}
return {
title,
description,
btnLink: this.newIncidentPath,
btnText: createIncidentBtnLabel,
};
},
},
methods: {
onInputChange: debounce(function debounceSearch(input) {
......@@ -279,7 +304,7 @@ export default {
</gl-tabs>
<gl-button
v-if="!isEmpty"
v-if="!isEmpty || activeClosedTabHasNoIncidents"
class="gl-my-3 gl-mr-5 create-incident-button"
data-testid="createIncidentBtn"
data-qa-selector="create_incident_button"
......@@ -307,6 +332,7 @@ export default {
{{ s__('IncidentManagement|Incidents') }}
</h4>
<gl-table
v-if="showList"
:items="incidents.list || []"
:fields="availableFields"
:show-empty="true"
......@@ -379,21 +405,20 @@ export default {
<gl-loading-icon size="lg" color="dark" class="mt-3" />
</template>
<template #empty>
<gl-empty-state
v-if="!errored"
:title="$options.i18n.emptyState.title"
:svg-path="emptyListSvgPath"
:description="$options.i18n.emptyState.description"
:primary-button-link="newIncidentPath"
:primary-button-text="$options.i18n.createIncidentBtnLabel"
/>
<span v-else>
<template v-if="errored" #empty>
{{ $options.i18n.noIncidents }}
</span>
</template>
</gl-table>
<gl-empty-state
v-else
:title="emptyStateData.title"
:svg-path="emptyListSvgPath"
:description="emptyStateData.description"
:primary-button-link="emptyStateData.btnLink"
:primary-button-text="emptyStateData.btnText"
/>
<gl-pagination
v-if="showPaginationControls"
:value="pagination.currentPage"
......
......@@ -9,6 +9,7 @@ export const I18N = {
searchPlaceholder: __('Search results…'),
emptyState: {
title: s__('IncidentManagement|Display your incidents in a dedicated view'),
emptyClosedTabTitle: s__('IncidentManagement|There are no closed incidents'),
description: s__(
'IncidentManagement|All alerts promoted to incidents will automatically be displayed within the list. You can also create a new incident using the button below.',
),
......
---
title: Update empty state behavior for incidents list
merge_request: 40872
author:
type: other
......@@ -13112,6 +13112,9 @@ msgstr ""
msgid "IncidentManagement|Published to status page"
msgstr ""
msgid "IncidentManagement|There are no closed incidents"
msgstr ""
msgid "IncidentManagement|There was an error displaying the incidents."
msgstr ""
......
......@@ -78,6 +78,7 @@ describe('Incidents List', () => {
stubs: {
GlButton: true,
GlAvatar: true,
GlEmptyState: true,
},
});
}
......@@ -96,12 +97,30 @@ describe('Incidents List', () => {
expect(findLoader().exists()).toBe(true);
});
it('shows empty state', () => {
describe('empty state', () => {
const {
emptyState: { title, emptyClosedTabTitle, description },
} = I18N;
it.each`
statusFilter | all | closed | expectedTitle | expectedDescription
${'all'} | ${2} | ${1} | ${title} | ${description}
${'open'} | ${2} | ${0} | ${title} | ${description}
${'closed'} | ${0} | ${0} | ${title} | ${description}
${'closed'} | ${2} | ${0} | ${emptyClosedTabTitle} | ${undefined}
`(
`when active tab is $statusFilter and there are $all incidents in total and $closed closed incidents, the empty state
has title: $expectedTitle and description: $expectedDescription`,
({ statusFilter, all, closed, expectedTitle, expectedDescription }) => {
mountComponent({
data: { incidents: { list: [] }, incidentsCount: {} },
data: { incidents: { list: [] }, incidentsCount: { all, closed }, statusFilter },
loading: false,
});
expect(findEmptyState().exists()).toBe(true);
expect(findEmptyState().attributes('title')).toBe(expectedTitle);
expect(findEmptyState().attributes('description')).toBe(expectedDescription);
},
);
});
it('shows error state', () => {
......@@ -188,6 +207,14 @@ describe('Incidents List', () => {
expect(findCreateIncidentBtn().attributes('loading')).toBe('true');
});
});
it("doesn't show the button when list is empty", () => {
mountComponent({
data: { incidents: { list: [] }, incidentsCount: {} },
loading: false,
});
expect(findCreateIncidentBtn().exists()).toBe(false);
});
});
describe('Pagination', () => {
......@@ -313,7 +340,7 @@ describe('Incidents List', () => {
describe('Status Filter Tabs', () => {
beforeEach(() => {
mountComponent({
data: { incidents: mockIncidents, incidentsCount },
data: { incidents: { list: mockIncidents }, incidentsCount },
loading: false,
stubs: {
GlTab: true,
......@@ -345,7 +372,7 @@ describe('Incidents List', () => {
describe('sorting the incident list by column', () => {
beforeEach(() => {
mountComponent({
data: { incidents: mockIncidents, incidentsCount },
data: { incidents: { list: mockIncidents }, incidentsCount },
loading: 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