Files
supabase/apps/studio/stores/RootStore.ts
T
Joshen LimandAlaister Young da792ba0ba Chore/show rr UI only if project is enabled (#19642)
* Only show RR UI if project is enabled

* Only show RR UI if project has read replicas enabled, shift DatabaseSelector state to valtio, add Database Selector to API URl

* Update usage of Project interface from types to Project from project-details-query

* Fix ts errors

* Another one

* Another one...

* God one more

* Fingers crossed

* jesus

* Add deprecate mark on ProjectBase

* Resolve conflicts

* Rename ProjectState from valtio to DatabaseSelectorState

* Rename file

* fix imports

* tiny code changes

* Fixes

---------

Co-authored-by: Alaister Young <a@alaisteryoung.com>
2023-12-20 16:49:53 +07:00

56 lines
1.4 KiB
TypeScript

import { configure } from 'mobx'
import { Project } from 'data/projects/project-detail-query'
import UiStore, { IUiStore } from './UiStore'
import MetaStore, { IMetaStore } from './pgmeta/MetaStore'
import VaultStore, { IVaultStore } from './project/VaultStore'
// Temporary disable mobx warnings
// TODO: need to remove this after refactoring old stores.
configure({
enforceActions: 'never',
})
export interface IRootStore {
ui: IUiStore
meta: IMetaStore
vault: IVaultStore
selectedProjectRef?: string
setProject: (project: Project) => void
}
export class RootStore implements IRootStore {
ui: IUiStore
meta: IMetaStore
vault: IVaultStore
selectedProjectRef: string | undefined
constructor() {
this.ui = new UiStore(this)
this.meta = new MetaStore(this, { projectRef: '', connectionString: '' })
this.vault = new VaultStore(this)
}
/**
* Set selected project reference
*
* This method will also trigger project detail loading when it's not available
*/
setProject(project: Project) {
if (this.selectedProjectRef === project.ref) return
// reset ui projectRef in case of switching projects
// this will show the loading screen instead of showing the previous project
this.ui.setProjectRef(undefined)
this.meta.setProjectDetails(project)
// ui set must come last
this.ui.setProjectRef(project.ref)
this.selectedProjectRef = project.ref
}
}