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

[GH-819]:Create issue modal crashes when assignee is selected before switching projects #879

Merged
merged 7 commits into from
Feb 25, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import BackendSelector, {Props as BackendSelectorProps} from '../backend_selecto

type Props = BackendSelectorProps & {
projectKey: string;
searchUsers: (params: {project: string; q: string}) => Promise<{data: JiraUser[]; error?: Error}>;
searchUsers: (params: {project: string; q: string}) => Promise<{data: {label: string; value: JiraUser[]}; error?: Error}>;
};

export default class JiraUserSelector extends React.PureComponent<Props> {
Expand Down
37 changes: 7 additions & 30 deletions webapp/src/components/modals/create_issue/create_issue_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,14 @@ export default class CreateIssueForm extends React.PureComponent<Props, State> {

if (error) {
state.error = error.message;
} else {
const fields = this.filterInvalidFields(this.state.projectKey, this.state.issueType, this.state.fields);
state.fields = fields;
}

this.setState(state);
});

let fields = {
...this.state.fields,
const fields = {
summary: this.state.fields.summary,
description: this.state.fields.description,
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved
project: {key: projectKey},
} as CreateIssueFields;

Expand All @@ -146,7 +144,6 @@ export default class CreateIssueForm extends React.PureComponent<Props, State> {
id: issueType,
};

fields = this.filterInvalidFields(projectKey, issueType, fields);
this.setState({
projectKey,
issueType,
Expand All @@ -159,12 +156,13 @@ export default class CreateIssueForm extends React.PureComponent<Props, State> {
}

handleIssueTypeChange = (_: string, issueType: string) => {
let fields = {
...this.state.fields,
const fields = {
summary: this.state.fields.summary,
description: this.state.fields.description,
project: {key: this.state.projectKey},
issuetype: {id: issueType},
} as CreateIssueFields;

fields = this.filterInvalidFields(this.state.projectKey, issueType, fields);
this.setState({
issueType,
fields,
Expand Down Expand Up @@ -210,27 +208,6 @@ export default class CreateIssueForm extends React.PureComponent<Props, State> {
return fieldsNotCovered;
}

filterInvalidFields = (projectKey: string | null, issueType: string | null, fields: CreateIssueFields) => {
if (!projectKey || !issueType || !this.state.jiraIssueMetadata) {
return fields;
}

const available = getFields(this.state.jiraIssueMetadata, projectKey, issueType);

if (Object.keys(available).length === 0) {
return fields;
}

const result = {} as CreateIssueFields;
for (const key of Object.keys(fields)) {
if (available[key] || key === 'project' || key === 'issuetype') {
result[key] = fields[key];
}
}

return result;
}

handleSubmit = (e?: React.FormEvent) => {
if (e && e.preventDefault) {
e.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions webapp/src/types/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ export type AllProjectMetadata = {

export type CreateIssueFields = {
description: string;
summary?: string;
project: {key: string};
issuetype: {id: string};
} & {[key: string]: JiraField};