From e9b6b4ccc3354e709c8763dcfb6ed47a38d1696e Mon Sep 17 00:00:00 2001 From: kshitij katiyar Date: Thu, 4 Jul 2024 17:50:09 +0530 Subject: [PATCH] [GH-993]: Added types for the subtask parameter in getIssueType function --- .../edit_channel_subscription.tsx | 2 +- .../modals/create_issue/create_issue_form.tsx | 4 ++-- webapp/src/utils/jira_issue_metadata.tsx | 12 ++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/webapp/src/components/modals/channel_subscriptions/edit_channel_subscription.tsx b/webapp/src/components/modals/channel_subscriptions/edit_channel_subscription.tsx index 4e089a93c..1edc90f60 100644 --- a/webapp/src/components/modals/channel_subscriptions/edit_channel_subscription.tsx +++ b/webapp/src/components/modals/channel_subscriptions/edit_channel_subscription.tsx @@ -349,7 +349,7 @@ export default class EditChannelSubscription extends PureComponent 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); diff --git a/webapp/src/components/modals/create_issue/create_issue_form.tsx b/webapp/src/components/modals/create_issue/create_issue_form.tsx index 38491c468..bcc4ac996 100644 --- a/webapp/src/components/modals/create_issue/create_issue_form.tsx +++ b/webapp/src/components/modals/create_issue/create_issue_form.tsx @@ -153,7 +153,7 @@ export default class CreateIssueForm extends React.PureComponent { 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, @@ -267,7 +267,7 @@ export default class CreateIssueForm extends React.PureComponent { }; 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 ( diff --git a/webapp/src/utils/jira_issue_metadata.tsx b/webapp/src/utils/jira_issue_metadata.tsx index af10c66a2..afe2833c8 100644 --- a/webapp/src/utils/jira_issue_metadata.tsx +++ b/webapp/src/utils/jira_issue_metadata.tsx @@ -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 @@ -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 []; } @@ -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); } @@ -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; } @@ -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) =>