diff --git a/static/app/stores/projectsStore.tsx b/static/app/stores/projectsStore.tsx index ec2ae63028032f..db3cfb838c5da7 100644 --- a/static/app/stores/projectsStore.tsx +++ b/static/app/stores/projectsStore.tsx @@ -4,6 +4,8 @@ import ProjectActions from 'app/actions/projectActions'; import TeamActions from 'app/actions/teamActions'; import {Project, Team} from 'app/types'; +import {CommonStoreInterface} from './types'; + type State = { projects: Project[]; loading: boolean; @@ -19,7 +21,7 @@ type Internals = { loading: boolean; }; -type ProjectsStoreInterface = { +type ProjectsStoreInterface = CommonStoreInterface & { init(): void; reset(): void; loadInitialData(projects: Project[]): void; @@ -31,10 +33,10 @@ type ProjectsStoreInterface = { onRemoveTeam(teamSlug: string, projectSlug: string): void; onAddTeam(team: Team, projectSlug: string): void; removeTeamFromProject(teamSlug: string, project: Project): void; + isLoading(): boolean; getWithTeam(teamSlug: string): Project[]; getAll(): Project[]; getBySlugs(slug: string[]): Project[]; - getState(slugs?: string[]): State; getById(id?: string): Project | undefined; getBySlug(slug?: string): Project | undefined; }; @@ -193,6 +195,10 @@ const storeConfig: Reflux.StoreDefinition & Internals & ProjectsStoreInterface = return this.getAll().filter(({teams}) => teams.find(({slug}) => slug === teamSlug)); }, + isLoading() { + return this.loading; + }, + getAll() { return Object.values(this.itemsById).sort((a: Project, b: Project) => { if (a.slug > b.slug) { @@ -217,9 +223,9 @@ const storeConfig: Reflux.StoreDefinition & Internals & ProjectsStoreInterface = return this.getAll().filter(project => slugs.includes(project.slug)); }, - getState(slugs?: string[]): State { + getState() { return { - projects: slugs ? this.getBySlugs(slugs) : this.getAll(), + projects: this.getAll(), loading: this.loading, }; }, diff --git a/static/app/utils/withProjects.tsx b/static/app/utils/withProjects.tsx index 06d78a043c12b6..299eccb6edc8c7 100644 --- a/static/app/utils/withProjects.tsx +++ b/static/app/utils/withProjects.tsx @@ -26,14 +26,21 @@ function withProjects

( > { static displayName = `withProjects(${getDisplayName(WrappedComponent)})`; - state: State = ProjectsStore.getState(); + state: State = { + projects: ProjectsStore.getAll(), + loading: ProjectsStore.isLoading(), + }; componentWillUnmount() { this.unsubscribe(); } unsubscribe = ProjectsStore.listen( - () => this.setState(ProjectsStore.getState()), + () => + this.setState({ + projects: ProjectsStore.getAll(), + loading: ProjectsStore.isLoading(), + }), undefined ); diff --git a/static/app/utils/withProjectsSpecified.tsx b/static/app/utils/withProjectsSpecified.tsx index 091f83ae94e56e..d4db8401344746 100644 --- a/static/app/utils/withProjectsSpecified.tsx +++ b/static/app/utils/withProjectsSpecified.tsx @@ -31,10 +31,16 @@ function withProjectsSpecified

( > { static displayName = `withProjectsSpecified(${getDisplayName(WrappedComponent)})`; - state = ProjectsStore.getState(this.props.specificProjectSlugs); + state: State = { + projects: ProjectsStore.getBySlugs(this.props.specificProjectSlugs ?? []), + loading: ProjectsStore.isLoading(), + }; static getDerivedStateFromProps(nextProps: Readonly): State { - return ProjectsStore.getState(nextProps.specificProjectSlugs); + return { + projects: ProjectsStore.getBySlugs(nextProps.specificProjectSlugs ?? []), + loading: ProjectsStore.isLoading(), + }; } componentWillUnmount() { @@ -42,7 +48,10 @@ function withProjectsSpecified

( } unsubscribe = ProjectsStore.listen(() => { - const storeState = ProjectsStore.getState(this.props.specificProjectSlugs); + const storeState: State = { + projects: ProjectsStore.getBySlugs(this.props.specificProjectSlugs ?? []), + loading: ProjectsStore.isLoading(), + }; if (!isEqual(this.state, storeState)) { this.setState(storeState);