Commit ee456b97 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch '227351-impossible-to-permanently-close-jira-import-success-alert' into 'master'

Permanently close Jira import success alert

See merge request gitlab-org/gitlab!36571
parents f8f18e4c 27825805
...@@ -5,8 +5,9 @@ import { n__ } from '~/locale'; ...@@ -5,8 +5,9 @@ import { n__ } from '~/locale';
import getIssuesListDetailsQuery from '../queries/get_issues_list_details.query.graphql'; import getIssuesListDetailsQuery from '../queries/get_issues_list_details.query.graphql';
import { import {
calculateJiraImportLabel, calculateJiraImportLabel,
isFinished,
isInProgress, isInProgress,
setFinishedAlertHideMap,
shouldShowFinishedAlert,
} from '~/jira_import/utils/jira_import_utils'; } from '~/jira_import/utils/jira_import_utils';
export default { export default {
...@@ -35,8 +36,6 @@ export default { ...@@ -35,8 +36,6 @@ export default {
}, },
data() { data() {
return { return {
isFinishedAlertShowing: true,
isInProgressAlertShowing: true,
jiraImport: {}, jiraImport: {},
}; };
}, },
...@@ -48,15 +47,18 @@ export default { ...@@ -48,15 +47,18 @@ export default {
fullPath: this.projectPath, fullPath: this.projectPath,
}; };
}, },
update: ({ project }) => ({ update: ({ project }) => {
importedIssuesCount: last(project.jiraImports.nodes)?.importedIssuesCount, const label = calculateJiraImportLabel(
isInProgress: isInProgress(project.jiraImportStatus),
isFinished: isFinished(project.jiraImportStatus),
label: calculateJiraImportLabel(
project.jiraImports.nodes, project.jiraImports.nodes,
project.issues.nodes.flatMap(({ labels }) => labels.nodes), project.issues.nodes.flatMap(({ labels }) => labels.nodes),
), );
}), return {
importedIssuesCount: last(project.jiraImports.nodes)?.importedIssuesCount,
label,
shouldShowFinishedAlert: shouldShowFinishedAlert(label.title, project.jiraImportStatus),
shouldShowInProgressAlert: isInProgress(project.jiraImportStatus),
};
},
skip() { skip() {
return !this.isJiraConfigured || !this.canEdit; return !this.isJiraConfigured || !this.canEdit;
}, },
...@@ -73,19 +75,14 @@ export default { ...@@ -73,19 +75,14 @@ export default {
labelTarget() { labelTarget() {
return `${this.issuesPath}?label_name[]=${encodeURIComponent(this.jiraImport.label.title)}`; return `${this.issuesPath}?label_name[]=${encodeURIComponent(this.jiraImport.label.title)}`;
}, },
shouldShowFinishedAlert() {
return this.isFinishedAlertShowing && this.jiraImport.isFinished;
},
shouldShowInProgressAlert() {
return this.isInProgressAlertShowing && this.jiraImport.isInProgress;
},
}, },
methods: { methods: {
hideFinishedAlert() { hideFinishedAlert() {
this.isFinishedAlertShowing = false; setFinishedAlertHideMap(this.jiraImport.label.title);
this.jiraImport.shouldShowFinishedAlert = false;
}, },
hideInProgressAlert() { hideInProgressAlert() {
this.isInProgressAlertShowing = false; this.jiraImport.shouldShowInProgressAlert = false;
}, },
}, },
}; };
...@@ -93,10 +90,15 @@ export default { ...@@ -93,10 +90,15 @@ export default {
<template> <template>
<div class="issuable-list-root"> <div class="issuable-list-root">
<gl-alert v-if="shouldShowInProgressAlert" @dismiss="hideInProgressAlert"> <gl-alert v-if="jiraImport.shouldShowInProgressAlert" @dismiss="hideInProgressAlert">
{{ __('Import in progress. Refresh page to see newly added issues.') }} {{ __('Import in progress. Refresh page to see newly added issues.') }}
</gl-alert> </gl-alert>
<gl-alert v-if="shouldShowFinishedAlert" variant="success" @dismiss="hideFinishedAlert">
<gl-alert
v-if="jiraImport.shouldShowFinishedAlert"
variant="success"
@dismiss="hideFinishedAlert"
>
{{ finishedMessage }} {{ finishedMessage }}
<gl-label <gl-label
:background-color="jiraImport.label.color" :background-color="jiraImport.label.color"
......
...@@ -52,3 +52,5 @@ export const availableSortOptionsJira = [ ...@@ -52,3 +52,5 @@ export const availableSortOptionsJira = [
}, },
}, },
]; ];
export const JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY = 'jira-import-success-alert-hide-map';
import { last } from 'lodash'; import { last } from 'lodash';
import { JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY } from '~/issuables_list/constants';
export const IMPORT_STATE = { export const IMPORT_STATE = {
FAILED: 'failed', FAILED: 'failed',
...@@ -68,3 +69,36 @@ export const calculateJiraImportLabel = (jiraImports, labels) => { ...@@ -68,3 +69,36 @@ export const calculateJiraImportLabel = (jiraImports, labels) => {
title, title,
}; };
}; };
/**
* Calculates whether the Jira import success alert should be shown.
*
* @param {string} labelTitle - Jira import label, for checking localStorage
* @param {string} importStatus - Jira import status
* @returns {boolean} - A boolean indicating whether to show the success alert
*/
export const shouldShowFinishedAlert = (labelTitle, importStatus) => {
const finishedAlertHideMap =
JSON.parse(localStorage.getItem(JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY)) || {};
const shouldHide = finishedAlertHideMap[labelTitle];
return !shouldHide && isFinished(importStatus);
};
/**
* Updates the localStorage map to permanently hide the Jira import success alert
*
* @param {string} labelTitle - Jira import label, for checking localStorage
*/
export const setFinishedAlertHideMap = labelTitle => {
const finishedAlertHideMap =
JSON.parse(localStorage.getItem(JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY)) || {};
finishedAlertHideMap[labelTitle] = true;
localStorage.setItem(
JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY,
JSON.stringify(finishedAlertHideMap),
);
};
---
title: Permanently close Jira import success alert
merge_request: 36571
author:
type: fixed
...@@ -16,10 +16,8 @@ describe('IssuableListRootApp', () => { ...@@ -16,10 +16,8 @@ describe('IssuableListRootApp', () => {
const findAlertLabel = () => wrapper.find(GlAlert).find(GlLabel); const findAlertLabel = () => wrapper.find(GlAlert).find(GlLabel);
const mountComponent = ({ const mountComponent = ({
isFinishedAlertShowing = false, shouldShowFinishedAlert = false,
isInProgressAlertShowing = false, shouldShowInProgressAlert = false,
isInProgress = false,
isFinished = false,
} = {}) => } = {}) =>
shallowMount(IssuableListRootApp, { shallowMount(IssuableListRootApp, {
propsData: { propsData: {
...@@ -30,13 +28,11 @@ describe('IssuableListRootApp', () => { ...@@ -30,13 +28,11 @@ describe('IssuableListRootApp', () => {
}, },
data() { data() {
return { return {
isFinishedAlertShowing,
isInProgressAlertShowing,
jiraImport: { jiraImport: {
importedIssuesCount: 1, importedIssuesCount: 1,
isInProgress,
isFinished,
label, label,
shouldShowFinishedAlert,
shouldShowInProgressAlert,
}, },
}; };
}, },
...@@ -58,8 +54,7 @@ describe('IssuableListRootApp', () => { ...@@ -58,8 +54,7 @@ describe('IssuableListRootApp', () => {
describe('when Jira import is in progress', () => { describe('when Jira import is in progress', () => {
it('shows an alert that tells the user a Jira import is in progress', () => { it('shows an alert that tells the user a Jira import is in progress', () => {
wrapper = mountComponent({ wrapper = mountComponent({
isInProgressAlertShowing: true, shouldShowInProgressAlert: true,
isInProgress: true,
}); });
expect(findAlert().text()).toBe( expect(findAlert().text()).toBe(
...@@ -71,8 +66,7 @@ describe('IssuableListRootApp', () => { ...@@ -71,8 +66,7 @@ describe('IssuableListRootApp', () => {
describe('when Jira import has finished', () => { describe('when Jira import has finished', () => {
beforeEach(() => { beforeEach(() => {
wrapper = mountComponent({ wrapper = mountComponent({
isFinishedAlertShowing: true, shouldShowFinishedAlert: true,
isFinished: true,
}); });
}); });
...@@ -106,8 +100,7 @@ describe('IssuableListRootApp', () => { ...@@ -106,8 +100,7 @@ describe('IssuableListRootApp', () => {
describe('alert message', () => { describe('alert message', () => {
it('is hidden when dismissed', () => { it('is hidden when dismissed', () => {
wrapper = mountComponent({ wrapper = mountComponent({
isInProgressAlertShowing: true, shouldShowInProgressAlert: true,
isInProgress: true,
}); });
expect(wrapper.contains(GlAlert)).toBe(true); expect(wrapper.contains(GlAlert)).toBe(true);
......
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import { import {
calculateJiraImportLabel, calculateJiraImportLabel,
extractJiraProjectsOptions, extractJiraProjectsOptions,
IMPORT_STATE, IMPORT_STATE,
isFinished, isFinished,
isInProgress, isInProgress,
setFinishedAlertHideMap,
shouldShowFinishedAlert,
} from '~/jira_import/utils/jira_import_utils'; } from '~/jira_import/utils/jira_import_utils';
import { JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY } from '~/issuables_list/constants';
useLocalStorageSpy();
describe('isInProgress', () => { describe('isInProgress', () => {
it.each` it.each`
...@@ -89,3 +95,56 @@ describe('calculateJiraImportLabel', () => { ...@@ -89,3 +95,56 @@ describe('calculateJiraImportLabel', () => {
expect(label.color).toBe('#333'); expect(label.color).toBe('#333');
}); });
}); });
describe('shouldShowFinishedAlert', () => {
const labelTitle = 'jira-import::JCP-1';
afterEach(() => {
localStorage.clear();
});
it('checks localStorage value', () => {
jest.spyOn(localStorage, 'getItem').mockReturnValue(JSON.stringify({}));
shouldShowFinishedAlert(labelTitle, IMPORT_STATE.FINISHED);
expect(localStorage.getItem).toHaveBeenCalledWith(JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY);
});
it('returns true when an import has finished', () => {
jest.spyOn(localStorage, 'getItem').mockReturnValue(JSON.stringify({}));
expect(shouldShowFinishedAlert(labelTitle, IMPORT_STATE.FINISHED)).toBe(true);
});
it('returns false when an import has finished but the user chose to hide the alert', () => {
jest.spyOn(localStorage, 'getItem').mockReturnValue(JSON.stringify({ [labelTitle]: true }));
expect(shouldShowFinishedAlert(labelTitle, IMPORT_STATE.FINISHED)).toBe(false);
});
it('returns false when an import has not finished', () => {
jest.spyOn(localStorage, 'getItem').mockReturnValue(JSON.stringify({}));
expect(shouldShowFinishedAlert(labelTitle, IMPORT_STATE.SCHEDULED)).toBe(false);
});
});
describe('setFinishedAlertHideMap', () => {
const labelTitle = 'jira-import::ABC-1';
const newLabelTitle = 'jira-import::JCP-1';
it('sets item to localStorage correctly', () => {
jest.spyOn(localStorage, 'getItem').mockReturnValue(JSON.stringify({ [labelTitle]: true }));
setFinishedAlertHideMap(newLabelTitle);
expect(localStorage.setItem).toHaveBeenCalledWith(
JIRA_IMPORT_SUCCESS_ALERT_HIDE_MAP_KEY,
JSON.stringify({
[labelTitle]: true,
[newLabelTitle]: true,
}),
);
});
});
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