BranchSelector() — supabase Function Reference
Architecture documentation for the BranchSelector() function in ProjectConfigVariables.tsx from the supabase codebase.
Entity Profile
Dependency Diagram
graph TD a18b0675_01e4_91fb_4b0f_69aed0bf085e["BranchSelector()"] 2fa31a08_7861_3ec6_44c7_7e8a65e06a99["isProjectPaused()"] a18b0675_01e4_91fb_4b0f_69aed0bf085e -->|calls| 2fa31a08_7861_3ec6_44c7_7e8a65e06a99 1a0fb889_5497_6f22_9a47_15fa9d3151a9["useBranchesQuery()"] a18b0675_01e4_91fb_4b0f_69aed0bf085e -->|calls| 1a0fb889_5497_6f22_9a47_15fa9d3151a9 198dc860_88ff_83be_86c6_c192e2e930b4["toBranchValue()"] a18b0675_01e4_91fb_4b0f_69aed0bf085e -->|calls| 198dc860_88ff_83be_86c6_c192e2e930b4 49a28a62_f6e4_17bb_f52c_25d99b997a0f["retrieve()"] a18b0675_01e4_91fb_4b0f_69aed0bf085e -->|calls| 49a28a62_f6e4_17bb_f52c_25d99b997a0f 965ae01b_f498_32bb_fc8b_be1fabbe301c["fromBranchValue()"] a18b0675_01e4_91fb_4b0f_69aed0bf085e -->|calls| 965ae01b_f498_32bb_fc8b_be1fabbe301c style a18b0675_01e4_91fb_4b0f_69aed0bf085e fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
apps/docs/components/ProjectConfigVariables/ProjectConfigVariables.tsx lines 216–298
function BranchSelector() {
const userLoading = useIsUserLoading()
const isLoggedIn = useIsLoggedIn()
const { selectedProject, selectedBranch, setSelectedBranch } = useSnapshot(projectsStore)
const [branchSearch, setBranchSearch] = useState('')
const projectPaused = isProjectPaused(selectedProject)
const hasBranches = selectedProject?.is_branch_enabled ?? false
const { data, isPending, isError } = useBranchesQuery(
{ projectRef: selectedProject?.ref },
{ enabled: isLoggedIn && !projectPaused && hasBranches }
)
const stateSummary: BranchesDataState = userLoading
? 'userLoading'
: !isLoggedIn
? 'loggedOut'
: !hasBranches || projectPaused
? 'loggedIn.noBranches'
: isPending
? 'loggedIn.branches.dataPending'
: isError
? 'loggedIn.branches.dataError'
: data.length === 0
? 'loggedIn.branches.dataSuccess.noData'
: 'loggedIn.branches.dataSuccess.hasData'
const formattedData: ComboBoxOption[] =
stateSummary !== 'loggedIn.branches.dataSuccess.hasData'
? []
: data!.map((branch) => ({
id: branch.id,
displayName: branch.name,
value: toBranchValue(branch),
}))
useEffect(() => {
if (stateSummary === 'loggedIn.branches.dataSuccess.hasData' && !selectedBranch) {
const storedMaybeBranchId = retrieve('local', LOCAL_STORAGE_KEYS.SAVED_BRANCH)
let storedBranch: Branch | undefined
if (storedMaybeBranchId) {
storedBranch = data!.find((branch) => branch.id === storedMaybeBranchId)
}
if (storedBranch) {
setSelectedBranch(storedBranch)
} else {
const productionBranch = data!.find(
(branch) => branch.project_ref === branch.parent_project_ref
)
setSelectedBranch(productionBranch ?? data![0])
}
}
}, [data, selectedBranch, setSelectedBranch, stateSummary])
return hasBranches ? (
<ComboBox
name="branch"
isLoading={stateSummary === 'userLoading' || stateSummary === 'loggedIn.branches.dataPending'}
disabled={
stateSummary === 'loggedOut' ||
stateSummary === 'loggedIn.noBranches' ||
stateSummary === 'loggedIn.branches.dataError' ||
stateSummary === 'loggedIn.branches.dataSuccess.noData'
}
options={formattedData}
selectedDisplayName={selectedBranch?.name}
selectedOption={selectedBranch ? toBranchValue(selectedBranch) : undefined}
search={branchSearch}
setSearch={setBranchSearch}
onSelectOption={(option) => {
const [branchId] = fromBranchValue(option)
if (branchId) {
const branch = data?.find((branch) => branch.id === branchId)
if (branch) setSelectedBranch(branch)
}
}}
/>
) : null
}
Domain
Subdomains
Source
Frequently Asked Questions
What does BranchSelector() do?
BranchSelector() is a function in the supabase codebase.
What does BranchSelector() call?
BranchSelector() calls 5 function(s): fromBranchValue, isProjectPaused, retrieve, toBranchValue, useBranchesQuery.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free