diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-19 18:08:04 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-19 18:08:04 +0300 |
commit | f2151c65d5826f0609a716e185893787b6375ae3 (patch) | |
tree | aeac6ff3ac12329ddf137b80fb69064eecf7dd36 /app/assets/javascripts/jira_import | |
parent | 553a22402b0c176b0486cac0009af085122c00f3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/jira_import')
-rw-r--r-- | app/assets/javascripts/jira_import/components/jira_import_app.vue | 2 | ||||
-rw-r--r-- | app/assets/javascripts/jira_import/utils.js | 49 |
2 files changed, 50 insertions, 1 deletions
diff --git a/app/assets/javascripts/jira_import/components/jira_import_app.vue b/app/assets/javascripts/jira_import/components/jira_import_app.vue index b6c50b89382..d1570f52c8c 100644 --- a/app/assets/javascripts/jira_import/components/jira_import_app.vue +++ b/app/assets/javascripts/jira_import/components/jira_import_app.vue @@ -1,6 +1,6 @@ <script> import { GlAlert, GlLoadingIcon, GlSprintf } from '@gitlab/ui'; -import last from 'lodash/last'; +import { last } from 'lodash'; import { __ } from '~/locale'; import getJiraImportDetailsQuery from '../queries/get_jira_import_details.query.graphql'; import initiateJiraImportMutation from '../queries/initiate_jira_import.mutation.graphql'; diff --git a/app/assets/javascripts/jira_import/utils.js b/app/assets/javascripts/jira_import/utils.js index 504cf19e44e..aa10dfc8099 100644 --- a/app/assets/javascripts/jira_import/utils.js +++ b/app/assets/javascripts/jira_import/utils.js @@ -1,3 +1,5 @@ +import { last } from 'lodash'; + export const IMPORT_STATE = { FAILED: 'failed', FINISHED: 'finished', @@ -8,3 +10,50 @@ export const IMPORT_STATE = { export const isInProgress = state => state === IMPORT_STATE.SCHEDULED || state === IMPORT_STATE.STARTED; + +export const isFinished = state => state === IMPORT_STATE.FINISHED; + +/** + * Calculates the label title for the most recent Jira import. + * + * @param {Object[]} jiraImports - List of Jira imports + * @param {string} jiraImports[].jiraProjectKey - Jira project key + * @returns {string} - A label title + */ +const calculateJiraImportLabelTitle = jiraImports => { + const mostRecentJiraProjectKey = last(jiraImports)?.jiraProjectKey; + const jiraProjectImportCount = jiraImports.filter( + jiraImport => jiraImport.jiraProjectKey === mostRecentJiraProjectKey, + ).length; + return `jira-import::${mostRecentJiraProjectKey}-${jiraProjectImportCount}`; +}; + +/** + * Finds the label color from a list of labels. + * + * @param {string} labelTitle - Label title + * @param {Object[]} labels - List of labels + * @param {string} labels[].title - Label title + * @param {string} labels[].color - Label color + * @returns {string} - The label color associated with the given labelTitle + */ +const calculateJiraImportLabelColor = (labelTitle, labels) => + labels.find(label => label.title === labelTitle)?.color; + +/** + * Calculates the label for the most recent Jira import. + * + * @param {Object[]} jiraImports - List of Jira imports + * @param {string} jiraImports[].jiraProjectKey - Jira project key + * @param {Object[]} labels - List of labels + * @param {string} labels[].title - Label title + * @param {string} labels[].color - Label color + * @returns {{color: string, title: string}} - A label object containing a label color and title + */ +export const calculateJiraImportLabel = (jiraImports, labels) => { + const title = calculateJiraImportLabelTitle(jiraImports); + return { + color: calculateJiraImportLabelColor(title, labels), + title, + }; +}; |