|
|
@@ -39,12 +39,18 @@ interface State { |
|
|
|
} |
|
|
|
|
|
|
|
export default class Projects extends React.PureComponent<Props, State> { |
|
|
|
mounted = false; |
|
|
|
state: State = { projects: [], selectedProjects: [] }; |
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
this.mounted = true; |
|
|
|
this.handleSearch('', Filter.Selected); |
|
|
|
} |
|
|
|
|
|
|
|
componentWillUnmount() { |
|
|
|
this.mounted = false; |
|
|
|
} |
|
|
|
|
|
|
|
handleSearch = (query: string, selected: string) => { |
|
|
|
return searchGates({ |
|
|
|
gateId: this.props.qualityGate.id, |
|
|
@@ -53,12 +59,14 @@ export default class Projects extends React.PureComponent<Props, State> { |
|
|
|
query: query !== '' ? query : undefined, |
|
|
|
selected |
|
|
|
}).then(data => { |
|
|
|
this.setState({ |
|
|
|
projects: data.results, |
|
|
|
selectedProjects: data.results |
|
|
|
.filter(project => project.selected) |
|
|
|
.map(project => project.id) |
|
|
|
}); |
|
|
|
if (this.mounted) { |
|
|
|
this.setState({ |
|
|
|
projects: data.results, |
|
|
|
selectedProjects: data.results |
|
|
|
.filter(project => project.selected) |
|
|
|
.map(project => project.id) |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
@@ -68,9 +76,11 @@ export default class Projects extends React.PureComponent<Props, State> { |
|
|
|
organization: this.props.organization, |
|
|
|
projectId: id |
|
|
|
}).then(() => { |
|
|
|
this.setState(state => ({ |
|
|
|
selectedProjects: [...state.selectedProjects, id] |
|
|
|
})); |
|
|
|
if (this.mounted) { |
|
|
|
this.setState(state => ({ |
|
|
|
selectedProjects: [...state.selectedProjects, id] |
|
|
|
})); |
|
|
|
} |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
@@ -81,9 +91,11 @@ export default class Projects extends React.PureComponent<Props, State> { |
|
|
|
projectId: id |
|
|
|
}).then( |
|
|
|
() => { |
|
|
|
this.setState(state => ({ |
|
|
|
selectedProjects: without(state.selectedProjects, id) |
|
|
|
})); |
|
|
|
if (this.mounted) { |
|
|
|
this.setState(state => ({ |
|
|
|
selectedProjects: without(state.selectedProjects, id) |
|
|
|
})); |
|
|
|
} |
|
|
|
}, |
|
|
|
() => {} |
|
|
|
); |