Browse Source

ref(ui) Remove a few more contextTypes references (#25902)

Remove a few more, slowly approaching 0 legacy context usage.
Mark Story 3 years ago
parent
commit
476439d016

+ 11 - 13
static/app/views/organizationIntegrations/integrationRepos.tsx

@@ -1,7 +1,6 @@
 import * as React from 'react';
 import styled from '@emotion/styled';
 import debounce from 'lodash/debounce';
-import PropTypes from 'prop-types';
 
 import {addRepository, migrateRepository} from 'app/actionCreators/integrations';
 import RepositoryActions from 'app/actions/repositoryActions';
@@ -17,11 +16,13 @@ import {IconCommit, IconFlag} from 'app/icons';
 import {t} from 'app/locale';
 import overflowEllipsis from 'app/styles/overflowEllipsis';
 import space from 'app/styles/space';
-import {Integration, Repository} from 'app/types';
+import {Integration, Organization, Repository} from 'app/types';
+import withOrganization from 'app/utils/withOrganization';
 import EmptyMessage from 'app/views/settings/components/emptyMessage';
 
 type Props = AsyncComponent['props'] & {
   integration: Integration;
+  organization: Organization;
 };
 
 type State = AsyncComponent['state'] & {
@@ -34,12 +35,7 @@ type State = AsyncComponent['state'] & {
   };
 };
 
-export default class IntegrationRepos extends AsyncComponent<Props, State> {
-  static contextTypes = {
-    organization: PropTypes.object.isRequired,
-    router: PropTypes.object,
-  };
-
+class IntegrationRepos extends AsyncComponent<Props, State> {
   getDefaultState(): State {
     return {
       ...super.getDefaultState(),
@@ -51,7 +47,7 @@ export default class IntegrationRepos extends AsyncComponent<Props, State> {
   }
 
   getEndpoints(): ReturnType<AsyncComponent['getEndpoints']> {
-    const orgId = this.context.organization.slug;
+    const orgId = this.props.organization.slug;
     return [
       ['itemList', `/organizations/${orgId}/repos/`, {query: {status: ''}}],
       [
@@ -84,7 +80,7 @@ export default class IntegrationRepos extends AsyncComponent<Props, State> {
   );
 
   searchRepositoriesRequest = (searchQuery: string) => {
-    const orgId = this.context.organization.slug;
+    const orgId = this.props.organization.slug;
     const query = {search: searchQuery};
     const endpoint = `/organizations/${orgId}/integrations/${this.props.integration.id}/repos/`;
     return this.api.request(endpoint, {
@@ -107,7 +103,7 @@ export default class IntegrationRepos extends AsyncComponent<Props, State> {
   addRepo(selection: {searchKey: string; value: string; label: JSX.Element}) {
     const {integration} = this.props;
     const {itemList} = this.state;
-    const orgId = this.context.organization.slug;
+    const orgId = this.props.organization.slug;
 
     this.setState({adding: true});
 
@@ -134,7 +130,7 @@ export default class IntegrationRepos extends AsyncComponent<Props, State> {
   }
 
   renderDropdown() {
-    const access = new Set(this.context.organization.access);
+    const access = new Set(this.props.organization.access);
     if (!access.has('org:integrations')) {
       return (
         <DropdownButton
@@ -209,7 +205,7 @@ export default class IntegrationRepos extends AsyncComponent<Props, State> {
 
   renderBody() {
     const {itemListPageLinks} = this.state;
-    const orgId = this.context.organization.slug;
+    const orgId = this.props.organization.slug;
     const itemList = this.getIntegrationRepos() || [];
     const header = (
       <PanelHeader disablePadding hasButtons>
@@ -256,6 +252,8 @@ export default class IntegrationRepos extends AsyncComponent<Props, State> {
   }
 }
 
+export default withOrganization(IntegrationRepos);
+
 const HeaderText = styled('div')`
   padding-left: ${space(2)};
   flex: 1;

+ 8 - 9
static/app/views/settings/components/settingsProjectProvider.tsx

@@ -1,7 +1,11 @@
 import {cloneElement, Component, isValidElement} from 'react';
 
-import SentryTypes from 'app/sentryTypes';
 import {Project} from 'app/types';
+import withProject from 'app/utils/withProject';
+
+type Props = {
+  project: Project;
+};
 
 /**
  * Simple Component that takes project from context and passes it as props to children
@@ -10,14 +14,9 @@ import {Project} from 'app/types';
  *
  * This is made because some components (e.g. ProjectPluginDetail) takes project as prop
  */
-class SettingsProjectProvider extends Component {
-  static contextTypes = {
-    project: SentryTypes.Project,
-  };
-
+class SettingsProjectProvider extends Component<Props> {
   render() {
-    const {children} = this.props;
-    const {project}: {project: Project} = this.context;
+    const {children, project} = this.props;
 
     if (isValidElement(children)) {
       return cloneElement(children, {
@@ -30,4 +29,4 @@ class SettingsProjectProvider extends Component {
   }
 }
 
-export default SettingsProjectProvider;
+export default withProject(SettingsProjectProvider);