Skip to content

Commit

Permalink
[GH-819]:Create issue modal crashes when assignee is selected before …
Browse files Browse the repository at this point in the history
…switching projects (#879)

* [MI-2228]:Fixed Jira Issue 819 (Create issue modal crashes when assignee is selected before switching projects) (#8)

* iterim pr for qa

* updated changes that fixes crash

* this is a hotfix that fixes the crash

* fixes line issue

* updated logic to reset fields

* spacing

* updated types for datatypes

* fixed linting

* fixed linting issues

* [MI-2228]:Fixed jira issue 819

* [MI-2228]:Fixed review fixes

Co-authored-by: raju <[email protected]>
Co-authored-by: sibasankarnayak <[email protected]>

* remove filter function

* [MM-819]:remove states.field

* [MM-819]:Fixed lint errors

* [MM-819]:Fixed lint errors

---------

Co-authored-by: raju <[email protected]>
Co-authored-by: sibasankarnayak <[email protected]>
  • Loading branch information
3 people authored Feb 25, 2023
1 parent fabe48c commit ba4e351
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
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,
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};

0 comments on commit ba4e351

Please sign in to comment.