123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- import {Component} from 'react';
- import {loadSdkUpdates} from 'sentry/actionCreators/sdkUpdates';
- import {Client} from 'sentry/api';
- import SdkUpdatesStore from 'sentry/stores/sdkUpdatesStore';
- import {Organization, ProjectSdkUpdates} from 'sentry/types';
- import withApi from './withApi';
- import withOrganization from './withOrganization';
- type InjectedProps = {
-
- sdkUpdates?: ProjectSdkUpdates[] | null;
- };
- type Props = {
- api: Client;
- organization: Organization;
-
- projectIds?: string[];
- };
- type State = {
- sdkUpdates: ProjectSdkUpdates[] | null;
- };
- function withSdkUpdates<P extends InjectedProps>(
- WrappedComponent: React.ComponentType<P>
- ) {
- class WithProjectSdkSuggestions extends Component<
- Omit<P, keyof InjectedProps> & Props,
- State
- > {
- state: State = {sdkUpdates: []};
- componentDidMount() {
- const orgSlug = this.props.organization.slug;
- const updates = SdkUpdatesStore.getUpdates(orgSlug);
-
- if (updates !== undefined) {
- this.onSdkUpdatesUpdate();
- return;
- }
- loadSdkUpdates(this.props.api, orgSlug);
- }
- componentWillUnmount() {
- this.unsubscribe();
- }
- unsubscribe = SdkUpdatesStore.listen(() => this.onSdkUpdatesUpdate(), undefined);
- onSdkUpdatesUpdate() {
- const sdkUpdates = SdkUpdatesStore.getUpdates(this.props.organization.slug) ?? null;
- this.setState({sdkUpdates});
- }
- render() {
-
-
-
- return (
- <WrappedComponent
- {...(this.props as unknown as P)}
- sdkUpdates={this.state.sdkUpdates}
- />
- );
- }
- }
- return withOrganization(withApi(WithProjectSdkSuggestions));
- }
- export default withSdkUpdates;
|