Browse Source

ref(js): Remove teams list from Organization type (#28692)

Evan Purkhiser 3 years ago
parent
commit
8a32d5d57e

+ 11 - 27
static/app/stores/organizationStore.tsx

@@ -2,9 +2,8 @@ import Reflux from 'reflux';
 
 
 import OrganizationActions from 'app/actions/organizationActions';
 import OrganizationActions from 'app/actions/organizationActions';
 import ProjectActions from 'app/actions/projectActions';
 import ProjectActions from 'app/actions/projectActions';
-import TeamActions from 'app/actions/teamActions';
 import {ORGANIZATION_FETCH_ERROR_TYPES} from 'app/constants';
 import {ORGANIZATION_FETCH_ERROR_TYPES} from 'app/constants';
-import {Organization, Project, Team} from 'app/types';
+import {Organization, Project} from 'app/types';
 import RequestError from 'app/utils/requestError/requestError';
 import RequestError from 'app/utils/requestError/requestError';
 
 
 type UpdateOptions = {
 type UpdateOptions = {
@@ -24,9 +23,8 @@ type OrganizationStoreInterface = {
   reset: () => void;
   reset: () => void;
   onUpdate: (org: Organization, options: UpdateOptions) => void;
   onUpdate: (org: Organization, options: UpdateOptions) => void;
   onFetchOrgError: (err: RequestError) => void;
   onFetchOrgError: (err: RequestError) => void;
-  onProjectOrTeamChange: () => void;
+  onProjectsChange: () => void;
   onLoadProjects: (projects: Project[]) => void;
   onLoadProjects: (projects: Project[]) => void;
-  onLoadTeams: (teams: Team[]) => void;
   get: () => State;
   get: () => State;
 };
 };
 
 
@@ -37,20 +35,15 @@ const storeConfig: Reflux.StoreDefinition & OrganizationStoreInterface = {
     this.listenTo(OrganizationActions.fetchOrg, this.reset);
     this.listenTo(OrganizationActions.fetchOrg, this.reset);
     this.listenTo(OrganizationActions.fetchOrgError, this.onFetchOrgError);
     this.listenTo(OrganizationActions.fetchOrgError, this.onFetchOrgError);
 
 
-    // fill in teams and projects if they are loaded
+    // fill in projects if they are loaded
     this.listenTo(ProjectActions.loadProjects, this.onLoadProjects);
     this.listenTo(ProjectActions.loadProjects, this.onLoadProjects);
-    this.listenTo(TeamActions.loadTeams, this.onLoadTeams);
-
-    // mark the store as dirty if projects or teams change
-    this.listenTo(ProjectActions.createSuccess, this.onProjectOrTeamChange);
-    this.listenTo(ProjectActions.updateSuccess, this.onProjectOrTeamChange);
-    this.listenTo(ProjectActions.changeSlug, this.onProjectOrTeamChange);
-    this.listenTo(ProjectActions.addTeamSuccess, this.onProjectOrTeamChange);
-    this.listenTo(ProjectActions.removeTeamSuccess, this.onProjectOrTeamChange);
-
-    this.listenTo(TeamActions.updateSuccess, this.onProjectOrTeamChange);
-    this.listenTo(TeamActions.removeTeamSuccess, this.onProjectOrTeamChange);
-    this.listenTo(TeamActions.createTeamSuccess, this.onProjectOrTeamChange);
+
+    // mark the store as dirty if projects change
+    this.listenTo(ProjectActions.createSuccess, this.onProjectsChange);
+    this.listenTo(ProjectActions.updateSuccess, this.onProjectsChange);
+    this.listenTo(ProjectActions.changeSlug, this.onProjectsChange);
+    this.listenTo(ProjectActions.addTeamSuccess, this.onProjectsChange);
+    this.listenTo(ProjectActions.removeTeamSuccess, this.onProjectsChange);
   },
   },
 
 
   reset() {
   reset() {
@@ -90,7 +83,7 @@ const storeConfig: Reflux.StoreDefinition & OrganizationStoreInterface = {
     this.trigger(this.get());
     this.trigger(this.get());
   },
   },
 
 
-  onProjectOrTeamChange() {
+  onProjectsChange() {
     // mark the store as dirty so the next fetch will trigger an org details refetch
     // mark the store as dirty so the next fetch will trigger an org details refetch
     this.dirty = true;
     this.dirty = true;
   },
   },
@@ -104,15 +97,6 @@ const storeConfig: Reflux.StoreDefinition & OrganizationStoreInterface = {
     }
     }
   },
   },
 
 
-  onLoadTeams(teams: Team[]) {
-    if (this.organization) {
-      // sort teams to mimic how they are received from backend
-      teams.sort((a, b) => a.slug.localeCompare(b.slug));
-      this.organization = {...this.organization, teams};
-      this.trigger(this.get());
-    }
-  },
-
   get() {
   get() {
     return {
     return {
       organization: this.organization,
       organization: this.organization,

+ 0 - 1
static/app/types/index.tsx

@@ -239,7 +239,6 @@ export type LightWeightOrganization = OrganizationSummary & {
  */
  */
 export type Organization = LightWeightOrganization & {
 export type Organization = LightWeightOrganization & {
   projects: Project[];
   projects: Project[];
-  teams: Team[];
 };
 };
 
 
 /**
 /**

+ 1 - 1
static/app/utils/withOrganization.tsx

@@ -36,7 +36,7 @@ export function isLightweightOrganization(
   organization: Organization | LightWeightOrganization
   organization: Organization | LightWeightOrganization
 ): organization is LightWeightOrganization {
 ): organization is LightWeightOrganization {
   const castedOrg = organization as Organization;
   const castedOrg = organization as Organization;
-  return !(castedOrg.projects && castedOrg.teams);
+  return !castedOrg.projects;
 }
 }
 
 
 export default withOrganization;
 export default withOrganization;

+ 2 - 7
static/app/views/organizationContext.tsx

@@ -156,7 +156,7 @@ class OrganizationContextContainer extends React.Component<Props, State> {
       !dirty &&
       !dirty &&
       organization &&
       organization &&
       !OrganizationContextContainer.isOrgChanging(props) &&
       !OrganizationContextContainer.isOrgChanging(props) &&
-      (!detailed || (detailed && organization.projects && organization.teams))
+      (!detailed || (detailed && organization.projects))
     );
     );
   }
   }
 
 
@@ -231,12 +231,7 @@ class OrganizationContextContainer extends React.Component<Props, State> {
     // the whole organization object to come in or just the teams and projects.
     // the whole organization object to come in or just the teams and projects.
     const {loading, error, organization} = this.state;
     const {loading, error, organization} = this.state;
     const {detailed} = this.props;
     const {detailed} = this.props;
-    return (
-      loading ||
-      (!error &&
-        detailed &&
-        (!organization || !organization.projects || !organization.teams))
-    );
+    return loading || (!error && detailed && (!organization || !organization.projects));
   }
   }
 
 
   fetchData(isInitialFetch = false) {
   fetchData(isInitialFetch = false) {

+ 3 - 3
static/app/views/projectInstall/createProject.tsx

@@ -59,11 +59,11 @@ type State = {
 };
 };
 
 
 class CreateProject extends React.Component<Props, State> {
 class CreateProject extends React.Component<Props, State> {
-  constructor(props, context) {
+  constructor(props: Props, context) {
     super(props, context);
     super(props, context);
 
 
-    const {query} = props.location;
-    const {teams} = props.organization;
+    const {teams, location} = props;
+    const {query} = location;
     const accessTeams = teams.filter((team: Team) => team.hasAccess);
     const accessTeams = teams.filter((team: Team) => team.hasAccess);
 
 
     const team = query.team || (accessTeams.length && accessTeams[0].slug);
     const team = query.team || (accessTeams.length && accessTeams[0].slug);

+ 0 - 1
tests/js/spec/actionCreators/organization.spec.jsx

@@ -99,7 +99,6 @@ describe('OrganizationActionCreator', function () {
 
 
     expect(OrganizationStore.organization).toEqual({
     expect(OrganizationStore.organization).toEqual({
       ...lightOrg,
       ...lightOrg,
-      teams: detailedOrg.teams,
       projects: detailedOrg.projects,
       projects: detailedOrg.projects,
     });
     });
   });
   });

+ 0 - 11
tests/js/spec/components/organizations/projectSelector.spec.jsx

@@ -3,30 +3,21 @@ import {mountWithTheme} from 'sentry-test/enzyme';
 import ProjectSelector from 'app/components/organizations/projectSelector';
 import ProjectSelector from 'app/components/organizations/projectSelector';
 
 
 describe('ProjectSelector', function () {
 describe('ProjectSelector', function () {
-  const testTeam = TestStubs.Team({
-    id: 'test-team',
-    slug: 'test-team',
-    isMember: true,
-  });
-
   const testProject = TestStubs.Project({
   const testProject = TestStubs.Project({
     id: 'test-project',
     id: 'test-project',
     slug: 'test-project',
     slug: 'test-project',
     isBookmarked: true,
     isBookmarked: true,
     isMember: true,
     isMember: true,
-    teams: [testTeam],
   });
   });
   const anotherProject = TestStubs.Project({
   const anotherProject = TestStubs.Project({
     id: 'another-project',
     id: 'another-project',
     slug: 'another-project',
     slug: 'another-project',
     isMember: true,
     isMember: true,
-    teams: [testTeam],
   });
   });
 
 
   const mockOrg = TestStubs.Organization({
   const mockOrg = TestStubs.Organization({
     id: 'org',
     id: 'org',
     slug: 'org',
     slug: 'org',
-    teams: [testTeam],
     projects: [testProject, anotherProject],
     projects: [testProject, anotherProject],
     features: ['new-teams'],
     features: ['new-teams'],
     access: [],
     access: [],
@@ -57,7 +48,6 @@ describe('ProjectSelector', function () {
         organization={{
         organization={{
           id: 'org',
           id: 'org',
           slug: 'org-slug',
           slug: 'org-slug',
-          teams: [],
           projects: [],
           projects: [],
           access: [],
           access: [],
         }}
         }}
@@ -79,7 +69,6 @@ describe('ProjectSelector', function () {
         organization={{
         organization={{
           id: 'org',
           id: 'org',
           slug: 'org-slug',
           slug: 'org-slug',
-          teams: [],
           projects: [],
           projects: [],
           access: ['project:write'],
           access: ['project:write'],
         }}
         }}

+ 0 - 18
tests/js/spec/stores/organizationStore.spec.jsx

@@ -1,7 +1,6 @@
 import {updateOrganization} from 'app/actionCreators/organizations';
 import {updateOrganization} from 'app/actionCreators/organizations';
 import OrganizationActions from 'app/actions/organizationActions';
 import OrganizationActions from 'app/actions/organizationActions';
 import ProjectActions from 'app/actions/projectActions';
 import ProjectActions from 'app/actions/projectActions';
-import TeamActions from 'app/actions/teamActions';
 import OrganizationStore from 'app/stores/organizationStore';
 import OrganizationStore from 'app/stores/organizationStore';
 
 
 describe('OrganizationStore', function () {
 describe('OrganizationStore', function () {
@@ -71,23 +70,6 @@ describe('OrganizationStore', function () {
     });
     });
   });
   });
 
 
-  it('loads in sorted teams', async function () {
-    const organization = TestStubs.Organization();
-    OrganizationActions.update(organization);
-    // wait for action to get dispatched to store
-    await tick();
-
-    const teamA = TestStubs.Team({slug: 'a'});
-    const teamB = TestStubs.Team({slug: 'b'});
-    const teams = [teamB, teamA];
-    TeamActions.loadTeams(teams);
-    // wait for action to get dispatched to store
-    await tick();
-
-    // verify existence and sorted order of loaded teams
-    expect(OrganizationStore.get().organization.teams).toEqual([teamA, teamB]);
-  });
-
   it('loads in sorted projects', async function () {
   it('loads in sorted projects', async function () {
     const organization = TestStubs.Organization();
     const organization = TestStubs.Organization();
     OrganizationActions.update(organization);
     OrganizationActions.update(organization);

+ 0 - 1
tests/js/spec/utils/withTeamsForUser.spec.jsx

@@ -8,7 +8,6 @@ describe('withUserTeams HoC', function () {
   const api = new MockApiClient();
   const api = new MockApiClient();
   const organization = TestStubs.Organization();
   const organization = TestStubs.Organization();
   delete organization.projects;
   delete organization.projects;
-  delete organization.teams;
 
 
   beforeEach(function () {
   beforeEach(function () {
     MockApiClient.clearMockResponses();
     MockApiClient.clearMockResponses();

+ 15 - 55
tests/js/spec/views/projectInstall/createProject.spec.jsx

@@ -6,11 +6,14 @@ import {CreateProject} from 'app/views/projectInstall/createProject';
 jest.mock('app/actionCreators/modal');
 jest.mock('app/actionCreators/modal');
 
 
 describe('CreateProject', function () {
 describe('CreateProject', function () {
+  const teamNoAccess = {slug: 'test', id: '1', name: 'test', hasAccess: false};
+  const teamWithAccess = {...teamNoAccess, hasAccess: true};
+
   const baseProps = {
   const baseProps = {
     api: new MockApiClient(),
     api: new MockApiClient(),
     location: {query: {}},
     location: {query: {}},
     organization: TestStubs.Organization(),
     organization: TestStubs.Organization(),
-    teams: [],
+    teams: [teamNoAccess],
     params: {
     params: {
       projectId: '',
       projectId: '',
       orgId: 'testOrg',
       orgId: 'testOrg',
@@ -24,15 +27,7 @@ describe('CreateProject', function () {
 
 
     const wrapper = mountWithTheme(
     const wrapper = mountWithTheme(
       <CreateProject {...props} />,
       <CreateProject {...props} />,
-      TestStubs.routerContext([
-        {
-          organization: {
-            id: '1',
-            slug: 'testOrg',
-            teams: [{slug: 'test', id: '1', name: 'test', hasAccess: false}],
-          },
-        },
-      ])
+      TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}])
     );
     );
 
 
     expect(wrapper).toSnapshot();
     expect(wrapper).toSnapshot();
@@ -45,15 +40,7 @@ describe('CreateProject', function () {
 
 
     const wrapper = mountWithTheme(
     const wrapper = mountWithTheme(
       <CreateProject {...props} />,
       <CreateProject {...props} />,
-      TestStubs.routerContext([
-        {
-          organization: {
-            id: '1',
-            slug: 'testOrg',
-            teams: [{slug: 'test', id: '1', name: 'test', hasAccess: false}],
-          },
-        },
-      ])
+      TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}])
     );
     );
 
 
     wrapper.find('TeamSelectInput Button').simulate('click');
     wrapper.find('TeamSelectInput Button').simulate('click');
@@ -66,16 +53,9 @@ describe('CreateProject', function () {
     };
     };
 
 
     const wrapper = mountWithTheme(
     const wrapper = mountWithTheme(
-      <CreateProject {...props} />,
+      <CreateProject {...props} teams={[teamWithAccess]} />,
       TestStubs.routerContext([
       TestStubs.routerContext([
-        {
-          organization: {
-            id: '1',
-            slug: 'testOrg',
-            teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
-          },
-          location: {query: {}},
-        },
+        {organization: {id: '1', slug: 'testOrg'}, location: {query: {}}},
       ])
       ])
     );
     );
 
 
@@ -104,16 +84,8 @@ describe('CreateProject', function () {
     };
     };
 
 
     const wrapper = mountWithTheme(
     const wrapper = mountWithTheme(
-      <CreateProject {...props} />,
-      TestStubs.routerContext([
-        {
-          organization: {
-            id: '1',
-            slug: 'testOrg',
-            teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
-          },
-        },
-      ])
+      <CreateProject {...props} teams={[teamWithAccess]} />,
+      TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}])
     );
     );
 
 
     expect(wrapper.find('ProjectNameInput input').props().value).toBe('Rails');
     expect(wrapper.find('ProjectNameInput input').props().value).toBe('Rails');
@@ -128,16 +100,8 @@ describe('CreateProject', function () {
     };
     };
 
 
     const wrapper = mountWithTheme(
     const wrapper = mountWithTheme(
-      <CreateProject {...props} />,
-      TestStubs.routerContext([
-        {
-          organization: {
-            id: '1',
-            slug: 'testOrg',
-            teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
-          },
-        },
-      ])
+      <CreateProject {...props} teams={[teamWithAccess]} />,
+      TestStubs.routerContext([{organization: {id: '1', slug: 'testOrg'}}])
     );
     );
 
 
     expect(wrapper.find('PlatformPicker').state('category')).toBe('mobile');
     expect(wrapper.find('PlatformPicker').state('category')).toBe('mobile');
@@ -149,14 +113,10 @@ describe('CreateProject', function () {
     };
     };
 
 
     const wrapper = mountWithTheme(
     const wrapper = mountWithTheme(
-      <CreateProject {...props} />,
+      <CreateProject {...props} teams={[teamWithAccess]} />,
       TestStubs.routerContext([
       TestStubs.routerContext([
         {
         {
-          organization: {
-            id: '1',
-            slug: 'testOrg',
-            teams: [{slug: 'test', id: '1', name: 'test', hasAccess: true}],
-          },
+          organization: {id: '1', slug: 'testOrg'},
           location: {query: {platform: 'XrubyROOLs'}},
           location: {query: {platform: 'XrubyROOLs'}},
         },
         },
       ])
       ])
@@ -173,7 +133,7 @@ describe('CreateProject', function () {
       props = {
       props = {
         ...baseProps,
         ...baseProps,
       };
       };
-      props.organization.teams = [{slug: 'test', id: '1', name: 'test', hasAccess: true}];
+      props.teams = [teamWithAccess];
       MockApiClient.addMockResponse({
       MockApiClient.addMockResponse({
         url: `/projects/${props.organization.slug}/rule-conditions/`,
         url: `/projects/${props.organization.slug}/rule-conditions/`,
         body: TestStubs.MOCK_RESP_VERBOSE,
         body: TestStubs.MOCK_RESP_VERBOSE,