Files
supabase/apps/studio/hooks/misc/useIsWarehouseEnabled.ts
Coenen BenjaminandCharis Lam 11289328e5 add support for warehouse connection string (#49914)
Add support for connection string for warehouse. 
This PR gives the ability to enable warehouse on a project and also get
the connection string to connect to.

> This project is only available in staging for now and gated behind a
feature flag

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
  - Added a Warehouse connection option to the Connect dialog.
- Select schemas and tables to replicate, with setup progress, error
recovery, and retry support.
- View copyable Warehouse connection details, credentials guidance,
command-line instructions, and DuckLake setup scripts.
  - Warehouse availability is controlled by feature configuration.

- **Tests**
- Added coverage for Warehouse table selection, setup script generation,
URL parsing, and connection configuration utilities.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
2026-09-07 11:24:42 +02:00

43 lines
1.6 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { getStringArrayFlag, useParams } from 'common'
import { useIsFeatureEnabled } from './useIsFeatureEnabled'
import { useSelectedOrganizationQuery } from './useSelectedOrganization'
import { IS_PLATFORM } from '@/lib/constants'
/**
* ConfigCat flag holding a comma-separated allow-list of org slugs (or the `'none'` sentinel for an
* empty list), targeted per-project via `targetingKey`.
*/
const WAREHOUSE_CONFIGCAT_FLAG_KEY = 'warehouse'
const WAREHOUSE_ALLOW_ALL_SENTINEL = 'all'
/**
* Returns whether the Warehouse tab should be shown in the Connect dialog.
*
* The API gates every `/platform/warehouse/{ref}/*` call against the same ConfigCat `warehouse`
* flag, so this mirrors that check client-side and tab visibility matches what the API allows.
*/
export function useIsWarehouseEnabled(): boolean {
const { ref: projectRef } = useParams()
const { projectConnectionShowWarehouse: isFeatureFlagEnabled } = useIsFeatureEnabled([
'project_connection:show_warehouse',
])
const { data: organization } = useSelectedOrganizationQuery({ enabled: IS_PLATFORM })
const { data: allowedOrgSlugs, isSuccess } = useQuery({
queryKey: ['warehouse-configcat-flag', projectRef],
queryFn: () => getStringArrayFlag(WAREHOUSE_CONFIGCAT_FLAG_KEY, projectRef!),
enabled: IS_PLATFORM && isFeatureFlagEnabled && !!projectRef,
staleTime: 5 * 60 * 1000,
})
if (!IS_PLATFORM || !isFeatureFlagEnabled) return false
if (!isSuccess || !organization?.slug) return false
return (
allowedOrgSlugs.includes(WAREHOUSE_ALLOW_ALL_SENTINEL) ||
allowedOrgSlugs.includes(organization.slug)
)
}