This is an automated email from the ASF dual-hosted git repository. beto pushed a commit to branch default-db-schema-dropdown in repository https://gitbox.apache.org/repos/asf/superset.git
commit 1910a5c6073b362e71e3874d710cb375f1afa0ff Author: Beto Dealmeida <[email protected]> AuthorDate: Thu Dec 18 18:15:44 2025 -0500 feat(frontend): extract default catalog/schema from API responses Update useCatalogs and useSchemas hooks to: - Parse the new `default` field from API responses - Expose `defaultCatalog` and `defaultSchema` from the hooks - Maintain backwards compatibility with the existing API The internal response types are updated to include both the list of options and the default value, while the external hook interface continues to return the options as `data` for compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]> --- superset-frontend/src/hooks/apiResources/catalogs.ts | 18 ++++++++++++++---- superset-frontend/src/hooks/apiResources/schemas.ts | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/superset-frontend/src/hooks/apiResources/catalogs.ts b/superset-frontend/src/hooks/apiResources/catalogs.ts index 26f56b1dd6..636b5d92ec 100644 --- a/superset-frontend/src/hooks/apiResources/catalogs.ts +++ b/superset-frontend/src/hooks/apiResources/catalogs.ts @@ -36,21 +36,29 @@ export type FetchCatalogsQueryParams = { type Params = Omit<FetchCatalogsQueryParams, 'forceRefresh'>; +// Internal type for transformed API response +type CatalogsApiResponse = { + catalogs: CatalogOption[]; + defaultCatalog: string | null; +}; + const catalogApi = api.injectEndpoints({ endpoints: builder => ({ - catalogs: builder.query<CatalogOption[], FetchCatalogsQueryParams>({ + catalogs: builder.query<CatalogsApiResponse, FetchCatalogsQueryParams>({ providesTags: [{ type: 'Catalogs', id: 'LIST' }], query: ({ dbId, forceRefresh }) => ({ endpoint: `/api/v1/database/${dbId}/catalogs/`, urlParams: { force: forceRefresh, }, - transformResponse: ({ json }: JsonResponse) => - json.result.sort().map((value: string) => ({ + transformResponse: ({ json }: JsonResponse) => ({ + catalogs: json.result.sort().map((value: string) => ({ value, label: value, title: value, })), + defaultCatalog: json.default ?? null, + }), }), serializeQueryArgs: ({ queryArgs: { dbId } }) => ({ dbId, @@ -89,7 +97,7 @@ export function useCatalogs(options: Params) { if (dbId && (!result.currentData || forceRefresh)) { trigger({ dbId, forceRefresh }).then(({ isSuccess, isError, data }) => { if (isSuccess) { - onSuccess?.(data || EMPTY_CATALOGS, forceRefresh); + onSuccess?.(data?.catalogs || EMPTY_CATALOGS, forceRefresh); } if (isError) { onError?.(result.error as ClientErrorObject); @@ -110,5 +118,7 @@ export function useCatalogs(options: Params) { return { ...result, refetch, + data: result.data?.catalogs, + defaultCatalog: result.data?.defaultCatalog ?? null, }; } diff --git a/superset-frontend/src/hooks/apiResources/schemas.ts b/superset-frontend/src/hooks/apiResources/schemas.ts index 4439b894cf..41a729c118 100644 --- a/superset-frontend/src/hooks/apiResources/schemas.ts +++ b/superset-frontend/src/hooks/apiResources/schemas.ts @@ -37,9 +37,15 @@ export type FetchSchemasQueryParams = { type Params = Omit<FetchSchemasQueryParams, 'forceRefresh'>; +// Internal type for transformed API response +type SchemasApiResponse = { + schemas: SchemaOption[]; + defaultSchema: string | null; +}; + const schemaApi = api.injectEndpoints({ endpoints: builder => ({ - schemas: builder.query<SchemaOption[], FetchSchemasQueryParams>({ + schemas: builder.query<SchemasApiResponse, FetchSchemasQueryParams>({ providesTags: [{ type: 'Schemas', id: 'LIST' }], query: ({ dbId, catalog, forceRefresh }) => ({ endpoint: `/api/v1/database/${dbId}/schemas/`, @@ -48,12 +54,14 @@ const schemaApi = api.injectEndpoints({ force: forceRefresh, ...(catalog !== undefined && { catalog }), }, - transformResponse: ({ json }: JsonResponse) => - json.result.sort().map((value: string) => ({ + transformResponse: ({ json }: JsonResponse) => ({ + schemas: json.result.sort().map((value: string) => ({ value, label: value, title: value, })), + defaultSchema: json.default ?? null, + }), }), serializeQueryArgs: ({ queryArgs: { dbId, catalog } }) => ({ dbId, @@ -98,7 +106,7 @@ export function useSchemas(options: Params) { trigger({ dbId, catalog, forceRefresh }).then( ({ isSuccess, isError, data }) => { if (isSuccess) { - onSuccess?.(data || EMPTY_SCHEMAS, forceRefresh); + onSuccess?.(data?.schemas || EMPTY_SCHEMAS, forceRefresh); } if (isError) { onError?.(result.error as ClientErrorObject); @@ -120,5 +128,7 @@ export function useSchemas(options: Params) { return { ...result, refetch, + data: result.currentData?.schemas, + defaultSchema: result.currentData?.defaultSchema ?? null, }; }
