diff --git a/src/lib/learn-client/api/collection/fetch-product-collections.ts b/src/lib/learn-client/api/collection/fetch-product-collections.ts index 278cc70e6c..ca18b1ae62 100644 --- a/src/lib/learn-client/api/collection/fetch-product-collections.ts +++ b/src/lib/learn-client/api/collection/fetch-product-collections.ts @@ -8,6 +8,7 @@ import { uuid, ProductOption, AllCollectionsProductOptions, + ThemeOption, } from 'lib/learn-client/types' import { get, toError } from '../../index' @@ -27,18 +28,29 @@ export const PRODUCT_COLLECTION_API_ROUTE = ( * includes filtering for theme */ export async function fetchAllCollectionsByProduct( - product: AllCollectionsProductOptions + product: AllCollectionsProductOptions, + /** + * All `ProductOption` values except `sentinel` can be used as "theme" options. + * Theme is mainly used to add a product logo to various UI elements, and + * since Sentinel doesn't have a logo, it's not a valid theme option. + * + * Note: an alternative here might be to implement a `theme` option for + * Sentinel, and for now, set it to render a HashiCorp logo. This might + * be a more future-proof approach. This would require updates to `learn-api`: + * https://github.com/hashicorp/learn-api/blob/main/src/models/collection.ts#L17 + */ + theme?: Exclude | ThemeOption ): Promise { const baseUrl = PRODUCT_COLLECTION_API_ROUTE(product.slug) let route = baseUrl if (product.sidebarSort) { - const params = new URLSearchParams([ - ['topLevelCategorySort', 'true'], - ['theme', product.slug], - ]) - - route = baseUrl + `?${params.toString()}` + const params = [] + params.push(['topLevelCategorySort', 'true']) + if (theme) { + params.push(['theme', theme]) + } + route = baseUrl + `?${new URLSearchParams(params).toString()}` } const getProductCollectionsRes = await get(route) diff --git a/src/lib/learn-client/api/collection/index.ts b/src/lib/learn-client/api/collection/index.ts index 54e88c382a..8a84776df6 100644 --- a/src/lib/learn-client/api/collection/index.ts +++ b/src/lib/learn-client/api/collection/index.ts @@ -80,8 +80,19 @@ export async function getAllCollections( // check if the product option is valid, i.e. not 'cloud' or 'hashicorp' if (options?.product && themeIsProduct(options.product.slug)) { - const allCollections = await fetchAllCollectionsByProduct(options.product) - + /** + * Sentinel cannot use "theme", as the `learn-api` doesn't support a + * `sentinel` theme value. We expect authors to use `theme: hashicorp` + * on Sentinel collections. We could provide "hashicorp" here instead + * of `null`, but that might result in unexpected filtering out if + * authors use a different `theme` for any Sentinel collection. + */ + const theme = + options.product.slug === 'sentinel' ? null : options.product.slug + const allCollections = await fetchAllCollectionsByProduct( + options.product, + theme + ) collections = [...allCollections] } else { const limit = options?.limit?.toString()