feat: global workspace selector (#2922)

Co-authored-by: Liyas Thomas <liyascthomas@gmail.com>
This commit is contained in:
Nivedin
2023-02-24 23:20:02 +05:30
committed by GitHub
parent 4ca6e9ec3a
commit 7e686a8882
35 changed files with 1130 additions and 808 deletions

View File

@@ -11,11 +11,19 @@ import {
} from "../backend/graphql"
import { TeamEnvironment } from "./TeamEnvironment"
type EntityType = "environment"
type EntityID = `${EntityType}-${string}`
export default class TeamEnvironmentAdapter {
error$: BehaviorSubject<GQLError<string> | null>
loading$: BehaviorSubject<boolean>
teamEnvironmentList$: BehaviorSubject<TeamEnvironment[]>
/**
* Stores the entity (environments) ids of all the loaded entities.
* Used for preventing duplication of data which definitely is not possible (duplication due to network problems etc.)
*/
private entityIDs: Set<EntityID>
private isDispose: boolean
private teamEnvironmentCreated$: Subscription | null
@@ -32,6 +40,8 @@ export default class TeamEnvironmentAdapter {
this.teamEnvironmentList$ = new BehaviorSubject<TeamEnvironment[]>([])
this.isDispose = true
this.entityIDs = new Set()
this.teamEnvironmentCreated$ = null
this.teamEnvironmentDeleted$ = null
this.teamEnvironmentUpdated$ = null
@@ -56,6 +66,8 @@ export default class TeamEnvironmentAdapter {
this.teamEnvironmentList$.next([])
this.loading$.next(false)
this.entityIDs.clear()
this.unsubscribeSubscriptions()
if (this.teamID) this.initialize()
@@ -112,16 +124,25 @@ export default class TeamEnvironmentAdapter {
)
}
// Add all the environments to the entity ids list
results.forEach((env) => this.entityIDs.add(`environment-${env.id}`))
this.teamEnvironmentList$.next(results)
this.loading$.next(false)
}
private createNewTeamEnvironment(newEnvironment: TeamEnvironment) {
// Check if we have it already in the entity tree, if so, we don't need it again
if (this.entityIDs.has(`environment-${newEnvironment.id}`)) return
const teamEnvironments = this.teamEnvironmentList$.value
teamEnvironments.push(newEnvironment)
// Add to entity ids set
this.entityIDs.add(`environment-${newEnvironment.id}`)
this.teamEnvironmentList$.next(teamEnvironments)
}
@@ -129,7 +150,7 @@ export default class TeamEnvironmentAdapter {
const teamEnvironments = this.teamEnvironmentList$.value.filter(
({ id }) => id !== envId
)
this.entityIDs.delete(`environment-${envId}`)
this.teamEnvironmentList$.next(teamEnvironments)
}