}
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,
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)
+ });
+ }
});
};
organization: this.props.organization,
projectId: id
}).then(() => {
- this.setState(state => ({
- selectedProjects: [...state.selectedProjects, id]
- }));
+ if (this.mounted) {
+ this.setState(state => ({
+ selectedProjects: [...state.selectedProjects, id]
+ }));
+ }
});
};
projectId: id
}).then(
() => {
- this.setState(state => ({
- selectedProjects: without(state.selectedProjects, id)
- }));
+ if (this.mounted) {
+ this.setState(state => ({
+ selectedProjects: without(state.selectedProjects, id)
+ }));
+ }
},
() => {}
);