Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-1121]: Fix epic selector not displaying options if field is renamed in Jira #1134

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import React from 'react';

import {isEpicIssueType, isEpicNameField} from 'utils/jira_issue_metadata';
import {isEpicNameField} from 'utils/jira_issue_metadata';
import {IssueMetadata, JiraIssue, ReactSelectOption} from 'types/model';

import BackendSelector, {Props as BackendSelectorProps} from '../backend_selector';
Expand Down Expand Up @@ -43,18 +43,26 @@ export default class JiraEpicSelector extends React.PureComponent<Props> {
};

searchIssues = async (userInput: string): Promise<ReactSelectOption[]> => {
const epicIssueType = this.props.issueMetadata.projects[0].issuetypes.find(isEpicIssueType);
if (!epicIssueType) {
return [];
let epicNameTypeId: string | undefined;
let epicNameTypeName: string | undefined;

for (const project of this.props.issueMetadata.projects) {
for (const issueType of project.issuetypes) {
epicNameTypeId = Object.keys(issueType.fields).find((key) => isEpicNameField(issueType.fields[key]));
if (epicNameTypeId) {
epicNameTypeName = issueType.fields[epicNameTypeId].name;
break;
}
}
if (epicNameTypeId) {
break;
}
Comment on lines +57 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will always be false. I think we can remove this

}

const epicNameTypeId = Object.keys(epicIssueType.fields).find((key) => isEpicNameField(epicIssueType.fields[key]));
if (!epicNameTypeId) {
if (!epicNameTypeId || !epicNameTypeName) {
return [];
}

const epicNameTypeName = epicIssueType.fields[epicNameTypeId].name;

let searchStr = '';
if (userInput) {
const cleanedInput = userInput.trim().replace(/"/g, '\\"');
Expand All @@ -65,18 +73,29 @@ export default class JiraEpicSelector extends React.PureComponent<Props> {
};

fetchEpicsFromJql = async (jqlSearch: string, userInput: string): Promise<ReactSelectOption[]> => {
const epicIssueType = this.props.issueMetadata.projects[0].issuetypes.find(isEpicIssueType);
if (!epicIssueType) {
return [];
let epicIssueTypeId: string | undefined;
let epicNameTypeId: string | undefined;
let projectKey: string | undefined;

for (const project of this.props.issueMetadata.projects) {
for (const issueType of project.issuetypes) {
epicNameTypeId = Object.keys(issueType.fields).find((key) => isEpicNameField(issueType.fields[key]));
if (epicNameTypeId) {
epicIssueTypeId = issueType.id;
projectKey = project.key;
break;
}
}
Comment on lines +80 to +88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can create a util for this

if (epicNameTypeId) {
break;
}
Comment on lines +89 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never true, can be removed

}

const epicNameTypeId = Object.keys(epicIssueType.fields).find((key) => isEpicNameField(epicIssueType.fields[key]));
if (!epicNameTypeId) {
if (!epicNameTypeId || !projectKey || !epicIssueTypeId) {
return [];
}

const projectKey = this.props.issueMetadata.projects[0].key;
const fullJql = `project=${projectKey} and issuetype=${epicIssueType.id} ${jqlSearch} ${searchDefaults}`;
const fullJql = `project=${projectKey} and issuetype=${epicIssueTypeId} ${jqlSearch} ${searchDefaults}`;

const params = {
jql: fullJql,
Expand Down
Loading