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

@@ -307,6 +307,9 @@ export default class NewTeamCollectionAdapter {
collection: TeamCollection,
parentCollectionID: string | null
) {
// Check if we have it already in the entity tree, if so, we don't need it again
if (this.entityIDs.has(`collection-${collection.id}`)) return
const tree = this.collections$.value
if (!parentCollectionID) {

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)
}

View File

@@ -15,6 +15,8 @@ export default class TeamListAdapter {
private timeoutHandle: ReturnType<typeof setTimeout> | null
private isDispose: boolean
public isInitialized: boolean
constructor(deferInit = false) {
this.error$ = new BehaviorSubject<GQLError<string> | null>(null)
this.loading$ = new BehaviorSubject<boolean>(false)
@@ -22,6 +24,8 @@ export default class TeamListAdapter {
this.timeoutHandle = null
this.isDispose = false
this.isInitialized = false
if (!deferInit) this.initialize()
}
@@ -29,6 +33,8 @@ export default class TeamListAdapter {
if (this.timeoutHandle) throw new Error(`Adapter already initialized`)
if (this.isDispose) throw new Error(`Adapter has been disposed`)
this.isInitialized = true
const func = async () => {
await this.fetchList()
@@ -44,6 +50,7 @@ export default class TeamListAdapter {
this.isDispose = true
clearTimeout(this.timeoutHandle as any)
this.timeoutHandle = null
this.isInitialized = false
}
async fetchList() {