Skip to content

Commit

Permalink
[GH-993]: Added types for the subtask parameter in getIssueType function
Browse files Browse the repository at this point in the history
  • Loading branch information
Kshitij-Katiyar committed Jul 4, 2024
1 parent 7e860cf commit e9b6b4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ export default class EditChannelSubscription extends PureComponent<Props, State>
render(): JSX.Element {
const style = getModalStyles(this.props.theme);

const issueTypes = getIssueTypes(this.state.jiraIssueMetadata, this.state.filters.projects[0], true);
const issueTypes = getIssueTypes(this.state.jiraIssueMetadata, this.state.filters.projects[0], {includeSubtasks: true});
const issueOptions = issueTypes.map((it) => ({label: it.name, value: it.id}));

const customFields = getCustomFieldValuesForEvents(this.state.jiraIssueMetadata, this.state.filters.projects);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class CreateIssueForm extends React.PureComponent<Props, State> {
id: fieldValues.issue_type,
};
} else {
const issueTypes = getIssueTypes(this.state.jiraIssueMetadata, projectKey, false);
const issueTypes = getIssueTypes(this.state.jiraIssueMetadata, projectKey, {includeSubtasks: false});
const issueType = issueTypes.length ? issueTypes[0].id : '';
fields.issuetype = {
id: issueType,
Expand Down Expand Up @@ -267,7 +267,7 @@ export default class CreateIssueForm extends React.PureComponent<Props, State> {
};

renderForm = () => {
const issueTypes = getIssueTypes(this.state.jiraIssueMetadata, this.state.projectKey, false);
const issueTypes = getIssueTypes(this.state.jiraIssueMetadata, this.state.projectKey, {includeSubtasks: false});
const issueOptions = issueTypes.map((it) => ({label: it.name, value: it.id}));

return (
Expand Down
12 changes: 8 additions & 4 deletions webapp/src/utils/jira_issue_metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type FieldWithInfo = JiraField & {
issueTypeMeta: IssueTypeIdentifier;
}

type GetIssueTypesOptions = {
includeSubtasks: boolean;
}

export const FIELD_KEY_STATUS = 'status';

// This is a replacement for the Array.flat() function which will be polyfilled by Babel
Expand Down Expand Up @@ -55,7 +59,7 @@ export function getProjectValues(metadata: ProjectMetadata | null): ReactSelectO
return metadata.projects;
}

export function getIssueTypes(metadata: IssueMetadata | null, projectKey: string | null, includeSubtasks: boolean): IssueType[] {
export function getIssueTypes(metadata: IssueMetadata | null, projectKey: string | null, options: GetIssueTypesOptions): IssueType[] {
if (!metadata || !metadata.projects) {
return [];
}
Expand All @@ -65,7 +69,7 @@ export function getIssueTypes(metadata: IssueMetadata | null, projectKey: string
return [];
}

if (!includeSubtasks) {
if (!options.includeSubtasks) {
project.issuetypes = project.issuetypes.filter((i) => !i.subtask);
}

Expand Down Expand Up @@ -100,7 +104,7 @@ export function getFields(metadata: IssueMetadata | null, projectKey: string | n
return {};
}

const issueType = getIssueTypes(metadata, projectKey, true).find((it) => it.id === issueTypeId);
const issueType = getIssueTypes(metadata, projectKey, {includeSubtasks: false}).find((it) => it.id === issueTypeId);
if (issueType) {
return issueType.fields;
}
Expand Down Expand Up @@ -131,7 +135,7 @@ export function getCustomFieldsForProjects(metadata: IssueMetadata | null, proje
return [];
}

const issueTypes = flatten(projectKeys.map((key) => getIssueTypes(metadata, key, true))) as IssueType[];
const issueTypes = flatten(projectKeys.map((key) => getIssueTypes(metadata, key, {includeSubtasks: true}))) as IssueType[];

const customFieldHash: {[key: string]: FieldWithInfo} = {};
const fields = flatten(issueTypes.map((issueType) =>
Expand Down

0 comments on commit e9b6b4c

Please sign in to comment.