<BranchStatusContext.Provider
value={{
branchStatusByComponent: this.state.branchStatusByComponent,
- fetchBranchStatus: this.fetchBranchStatus,
+ fetchBranchStatus: (branchLike: BranchLike, projectKey: string) => {
+ this.fetchBranchStatus(branchLike, projectKey).catch(() => {
+ /* noop */
+ });
+ },
updateBranchStatus: this.updateBranchStatus,
}}
>
export default class IndexationNotificationHelper {
private static interval?: NodeJS.Timeout;
- static startPolling(onNewStatus: (status: IndexationStatus) => void) {
+ static async startPolling(onNewStatus: (status: IndexationStatus) => void) {
this.stopPolling();
- // eslint-disable-next-line promise/catch-or-return
- this.poll(onNewStatus).then((status) => {
- if (!status.isCompleted) {
- this.interval = setInterval(() => this.poll(onNewStatus), POLLING_INTERVAL_MS);
- }
- });
+ const status = await this.poll(onNewStatus);
+
+ if (!status.isCompleted) {
+ this.interval = setInterval(() => {
+ this.poll(onNewStatus).catch(() => {
+ /* noop */
+ });
+ }, POLLING_INTERVAL_MS);
+ }
}
static stopPolling() {
componentDidUpdate(prevProps: Props) {
if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) {
- this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => this.fetchData());
+ this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => {
+ this.fetchData().catch(() => {
+ /* noop */
+ });
+ });
}
}
onSelectedAlmInstanceChange = (instance: AlmSettingsInstance) => {
this.setState(
{ selectedAlmInstance: instance, searchResults: undefined, searchQuery: '' },
- () => this.fetchData()
+ () => {
+ this.fetchData().catch(() => {
+ /* noop */
+ });
+ }
);
};
componentDidUpdate(prevProps: Props) {
if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) {
- this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => this.fetchData());
+ this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => {
+ this.fetchData().catch(() => {
+ /* noop */
+ });
+ });
}
}
projectsPaging: { pageIndex: 1, pageSize: BITBUCKET_CLOUD_PROJECTS_PAGESIZE },
searchQuery,
},
- async () => {
- await this.fetchData();
- if (this.mounted) {
- this.setState({ searching: false });
- }
+ () => {
+ this.fetchData().then(
+ () => {
+ if (this.mounted) {
+ this.setState({ searching: false });
+ }
+ },
+ () => {
+ /* noop */
+ }
+ );
}
);
};
pageSize: state.projectsPaging.pageSize,
},
}),
- async () => {
- await this.fetchData(true);
- if (this.mounted) {
- this.setState({ loadingMore: false });
- }
+ () => {
+ this.fetchData(true).then(
+ () => {
+ if (this.mounted) {
+ this.setState({ loadingMore: false });
+ }
+ },
+ () => {
+ /* noop */
+ }
+ );
}
);
};
componentDidUpdate(prevProps: Props) {
if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) {
- this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () =>
- this.fetchInitialData()
- );
+ this.setState({ selectedAlmInstance: this.props.almInstances[0] }, () => {
+ this.fetchInitialData().catch(() => {
+ /* noop */
+ });
+ });
}
}
componentDidUpdate(prevProps: Props) {
if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) {
- this.setState({ selectedAlmInstance: this.getInitialSelectedAlmInstance() }, () =>
- this.initialize()
- );
+ this.setState({ selectedAlmInstance: this.getInitialSelectedAlmInstance() }, () => {
+ this.initialize().catch(() => {
+ /* noop */
+ });
+ });
}
}
onSelectedAlmInstanceChange = (instance: AlmSettingsInstance) => {
this.setState(
{ selectedAlmInstance: instance, searchQuery: '', organizations: [], repositories: [] },
- () => this.initialize()
+ () => {
+ this.initialize().catch(() => {
+ /* noop */
+ });
+ }
);
};
componentDidUpdate(prevProps: Props) {
const { almInstances } = this.props;
if (prevProps.almInstances.length === 0 && this.props.almInstances.length > 0) {
- this.setState({ selectedAlmInstance: almInstances[0] }, () => this.fetchInitialData());
+ this.setState({ selectedAlmInstance: almInstances[0] }, () => {
+ this.fetchInitialData().catch(() => {
+ /* noop */
+ });
+ });
}
}
};
handleSearch = (query: string) => {
- this.setState({ query }, this.requestHolders);
+ this.setState({ query }, () => {
+ this.requestHolders().catch(() => {
+ /* noop */
+ });
+ });
};
handleFilter = (filter: FilterOption) => {
- this.setState({ filter }, this.requestHolders);
+ this.setState({ filter }, () => {
+ this.requestHolders().catch(() => {
+ /* noop */
+ });
+ });
};
handleSelectPermission = (selectedPermission: string) => {
if (selectedPermission === this.state.selectedPermission) {
- this.setState({ selectedPermission: undefined }, this.requestHolders);
+ this.setState({ selectedPermission: undefined }, () => {
+ this.requestHolders().catch(() => {
+ /* noop */
+ });
+ });
} else {
- this.setState({ selectedPermission }, this.requestHolders);
+ this.setState({ selectedPermission }, () => {
+ this.requestHolders().catch(() => {
+ /* noop */
+ });
+ });
}
};
};
handleRangeChange = ({ value }: { value: number }) => {
- this.setState({ range: value }, () => this.fetchAnalyses());
+ this.setState({ range: value }, () => {
+ this.fetchAnalyses().catch(() => {
+ /* noop */
+ });
+ });
};
render() {
loading: true,
lastSearchParams: { ...prevState.lastSearchParams, ...searchParams },
}),
- () =>
+ () => {
this.props
.onSearch({
filter: this.getFilter(),
query: this.state.lastSearchParams.query,
})
.then(this.stopLoading)
- .catch(this.stopLoading)
+ .catch(this.stopLoading);
+ }
);
changeFilter = (filter: SelectListFilter) => this.search({ filter, page: 1 });
}
handleSubmit = (data: V, { setSubmitting }: FormikHelpers<V>) => {
- const result = this.props.onSubmit(data);
const stopSubmitting = () => {
if (this.mounted) {
setSubmitting(false);
}
};
- if (result) {
- result.then(stopSubmitting, stopSubmitting);
- } else {
- stopSubmitting();
- }
+ this.props.onSubmit(data).then(stopSubmitting, stopSubmitting);
};
render() {
it('should render and submit', async () => {
const render = jest.fn();
- const onSubmit = jest.fn();
+ const onSubmit = jest.fn().mockResolvedValue(null);
const setSubmitting = jest.fn();
const wrapper = shallow(
<ValidationForm initialValues={{ foo: 'bar' }} onSubmit={onSubmit} validate={jest.fn()}>
expect.objectContaining({ dirty: false, errors: {}, values: { foo: 'bar' } })
);
- wrapper.prop<Function>('onSubmit')({ foo: 'bar' }, { setSubmitting });
- expect(setSubmitting).toHaveBeenCalledWith(false);
-
onSubmit.mockResolvedValue(undefined).mockClear();
setSubmitting.mockClear();
wrapper.prop<Function>('onSubmit')({ foo: 'bar' }, { setSubmitting });