Skip to content

[WIP] enable Sentinel tutorials without requiring them #2569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
cf6c99f
fix lint errors
im2nguyen Jul 9, 2024
836f251
Apply suggestions from code review (Leah)
im2nguyen Sep 9, 2024
ba911c2
support sentinel and hcp for neutral icon tiles
zchsh Sep 11, 2024
903686d
make collection fetch theme optional for sentinel
zchsh Sep 11, 2024
2c882ce
add sentinel badge option to avoid render err
zchsh Sep 11, 2024
6d71314
fix issue with missing sentinel collection pages
zchsh Sep 11, 2024
f0052e1
Merge branch 'main' into create-sentinel-tutorial
heatlikeheatwave Sep 24, 2024
ad9538c
support sentinel and hcp for neutral icon tiles
zchsh Sep 11, 2024
1121c85
make collection fetch theme optional for sentinel
zchsh Sep 11, 2024
3d0c12d
add sentinel badge option to avoid render err
zchsh Sep 11, 2024
434136d
fix issue with missing sentinel collection pages
zchsh Sep 11, 2024
108301b
revert changes to sentinel.json product data
zchsh Sep 13, 2024
f02fae4
revert nav item changes
zchsh Sep 13, 2024
cad3b7d
Add comment on removing activeProductSlugs
zchsh Sep 13, 2024
d8ebadf
re-order productSlugsToNames with sentinel last
zchsh Sep 13, 2024
91b83e5
remove test for order of a constant array
zchsh Sep 13, 2024
c579c5b
remove activeProductSlugs, use productSlugs
zchsh Sep 13, 2024
1d4f1f3
expand comment on refactoring productSlugs
zchsh Sep 13, 2024
dec8b8e
finish up comments on productSlugs
zchsh Sep 13, 2024
ea93b50
fix issue where tutorials page content is assumed
zchsh Sep 13, 2024
ebb177c
add comment on theme query option
zchsh Sep 13, 2024
e0bf0d3
fix 404 issue on /sentinel/tutorials
zchsh Sep 13, 2024
bb9eff2
Fix 404 error for Sentinel tutorials
heatlikeheatwave Sep 24, 2024
26810dd
Merge branch 'zs.add-sentinel-tutorials' of ssh://github.com/hashicor…
im2nguyen Sep 25, 2024
8b5da8f
Merge branch 'main' into zs.add-sentinel-tutorials
im2nguyen Sep 25, 2024
3018c64
working locally
im2nguyen Sep 25, 2024
89e67e5
fix build error, remove waf from branded card
im2nguyen Sep 25, 2024
fc287fb
create temp docs landing page
im2nguyen Sep 25, 2024
4bb6ba4
Merge branch 'create-sentinel-tutorial' into zs.add-sentinel-tutorials
heatlikeheatwave Sep 25, 2024
d4cb7cf
Update sentinel.json so test passes
heatlikeheatwave Sep 25, 2024
cc35424
Remove extra whitespace in product nav items page
heatlikeheatwave Sep 25, 2024
0eb5652
Fix build errors
heatlikeheatwave Sep 25, 2024
8310832
Add 'intro' back to basePaths
heatlikeheatwave Sep 25, 2024
e6aa910
Added intro to rootDocsPath
heatlikeheatwave Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/warm-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from 'lib/learn-client/api/collection'
import { splitProductFromFilename } from 'views/tutorial-view/utils'
import config from '../config/base.json'
import { activeProductSlugs } from 'lib/products'
import { productSlugs } from 'lib/products'
import { ProductSlug } from 'types/products'

const DEV_PORTAL_URL = config.dev_dot.canonical_base_url
Expand All @@ -27,7 +27,7 @@ const fetch = createFetch(null, { timeout: 900 * 1000 })
async function warmDeveloperDocsCache() {
const url = new URL('/api/revalidate', DEV_PORTAL_URL)

for (const productSlug of activeProductSlugs) {
for (const productSlug of productSlugs) {
const body = JSON.stringify({ product: productSlug })

try {
Expand Down Expand Up @@ -93,7 +93,7 @@ async function getTutorialUrlsToCache(product: ProductSlug): Promise<string[]> {
try {
const tutorialUrls = (
await Promise.all(
activeProductSlugs.map((product: ProductSlug) =>
productSlugs.map((product: ProductSlug) =>
getTutorialUrlsToCache(product)
)
)
Expand Down
5 changes: 4 additions & 1 deletion src/components/branded-card/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import patternVault from './img/vault.png'
import patternWaypoint from './img/waypoint.png'
import s from './branded-card.module.css'

const PATTERN_IMG_MAP: Record<ProductSlug, StaticImageData> = {
const PATTERN_IMG_MAP: Record<
Exclude<ProductSlug, 'well-architected-framework'>,
StaticImageData
> = {
boundary: patternBoundary,
consul: patternConsul,
nomad: patternNomad,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const generateBasicSuggestedPages = (productSlug: ProductSlug) => {
* link to the Tutorials Library.
*/
const EXTRA_PAGES: Record<
Exclude<ProductSlug, 'sentinel'>,
Exclude<ProductSlug, 'sentinel' | 'well-architected-framework'>,
SuggestedPageProps[]
> = {
boundary: [
Expand Down
4 changes: 3 additions & 1 deletion src/components/icon-tile/icon-tile.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@
/**
* Colors
*/
.color-neutral {
.color-neutral,
.color-sentinel,
.color-hcp {
--icon-color: var(--token-color-foreground-faint);
--border-color: var(--token-color-border-primary);
--background: var(--token-color-surface-faint);
Expand Down
7 changes: 2 additions & 5 deletions src/components/icon-tile/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@

import { ProductSlug } from 'types/products'

export type ProductBrandColor =
| 'neutral'
| 'neutral-dark'
| Exclude<ProductSlug, 'sentinel' | 'hcp'>
export type ProductBrandColor = 'neutral' | 'neutral-dark' | ProductSlug

export interface IconTileProps {
/** Pass a single child, which should be a Flight icon. For 'small' and 'medium' size, pass the 16px icon size; for other sizes pass the 24px icon size. Note that non-"color" icons will be colored using the "brandColor". */
children: React.ReactNode
/** Note: the "extra-large" option is not documented in the design system. It's being used for the IconTileLogo component, as used on the /{product} view pages. */
size?: 'small' | 'medium' | 'large' | 'extra-large'
/** Optional product slug to use for brand color theming. If not provided, defaults to "neutral". Note that "sentinel" and "hcp" are not supported. */
/** Optional product slug to use for brand color theming. If not provided, defaults to "neutral". Note that "sentinel" and "hcp" currently map to "neutral". */
brandColor?: ProductBrandColor
className?: string
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,18 @@ export function getNavItems(currentProduct: ProductData): NavItem[] {

/**
* Tutorials
*
* Note: we exclude Sentinel, as it does not have tutorials yet.
* Once Sentinel tutorials are published, we can remove this exclusion.
* PR to publish Sentinel tutorials:
* https://github.com/hashicorp/tutorials/pull/2169
*/
items.push({
label: 'Tutorials',
url: `/${currentProduct.slug}/tutorials`,
})
if (currentProduct.slug !== 'sentinel') {
items.push({
label: 'Tutorials',
url: `/${currentProduct.slug}/tutorials`,
})
}

/**
* Documentation categories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ export const generateProductLandingSidebarMenuItems = (
}

// Add a "Tutorials" link for all products
menuItems.push({
title: 'Tutorials',
fullPath: `/${product.slug}/tutorials`,
})
if (product.slug !== 'sentinel') {
menuItems.push({
title: 'Tutorials',
fullPath: `/${product.slug}/tutorials`,
})
}

// Add "Documentation" item links for all products
menuItems.push(...docsItems)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ const DEFAULT_COMMUNITY_FORUM_LINK = 'https://discuss.hashicorp.com/'
const DEFAULT_GITHUB_LINK = 'https://github.com/hashicorp'
const DEFAULT_SUPPORT_LINK = 'https://www.hashicorp.com/customer-success'

const COMMUNITY_LINKS_BY_PRODUCT: { [key in ProductSlug]: string } = {
const COMMUNITY_LINKS_BY_PRODUCT: {
[key in Exclude<ProductSlug, 'well-architected-framework'>]: string
} = {
boundary: 'https://discuss.hashicorp.com/c/boundary/50',
consul: 'https://discuss.hashicorp.com/c/consul/29',
hcp: 'https://discuss.hashicorp.com/c/hcp/54',
Expand All @@ -43,7 +45,10 @@ const COMMUNITY_LINKS_BY_PRODUCT: { [key in ProductSlug]: string } = {
}

const GITHUB_LINKS_BY_PRODUCT_SLUG: {
[key in Exclude<ProductSlug, 'waypoint'>]: string
[key in Exclude<
ProductSlug,
'waypoint' | 'well-architected-framework'
>]: string
} = {
boundary: 'https://github.com/hashicorp/boundary',
consul: 'https://github.com/hashicorp/consul',
Expand Down
2 changes: 1 addition & 1 deletion src/components/try-hcp-callout/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function hasHcpCalloutContent(s: string): s is ProductSlugWithContent {
}

export const tryHcpCalloutContent: Record<
ProductSlugWithContent,
Exclude<ProductSlugWithContent, 'well-architected-framework'>,
HcpCalloutContent
> = {
terraform: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const PRODUCT_ICON_MAP: Record<ProductOption, JSX.Element> = {
vault: <ProductIcon productSlug="vault" />,
vagrant: <ProductIcon productSlug="vagrant" />,
waypoint: <ProductIcon productSlug="waypoint" />,
sentinel: <ProductIcon productSlug="hcp" />,
}
/**
* Map all card badge options to icons
Expand Down
48 changes: 48 additions & 0 deletions src/content/sentinel/docs-landing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"pageSubtitle": "Sentinel is a policy as code tool that lets you control what users of HashiCorp products are allowed to do. It enforces policies proactively, preventing end users from deploying changes that are not allowed.",
"marketingContentBlocks": [
{
"type": "card-grid",
"title": "Fundamentals",
"cards": [
{
"title": "Policy as Code",
"description": "Understand how policy-as-code can help your organization",
"url": "/sentinel/docs/concepts/policy-as-code"
},
{
"title": "Write Sentinel policy",
"description": "Learn the fundamentals to writing Sentinel policies",
"url": "/sentinel/docs/writing"
},
{
"description": "Test Sentinel policy",
"title": "Learn how to test your Sentinel policies",
"url": "/sentinel/docs/writing/testing"
}
]
},
{
"type": "card-grid",
"title": "Integrations",
"description": "Sentinel integrates with HashiCorp products.",
"cards": [
{
"title": "Terraform",
"description": "Enforce infrastructure compliance policies with Terraform",
"url": "/sentinel/docs/terraform"
},
{
"title": "Vault",
"description": "Implement advanced access control policies within Vault",
"url": "/sentinel/docs/terraform"
},
{
"title": "Consul",
"description": "Create service mesh governance rules within Consul",
"url": "/sentinel/docs/terraform"
}
]
}
]
}
8 changes: 7 additions & 1 deletion src/data/sentinel.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,19 @@
"type": "inbound"
}
],
"basePaths": ["docs", "install"],
"basePaths": ["docs", "intro", "downloads"],
"rootDocsPaths": [
{
"basePathForLoader": "sentinel",
"iconName": "docs",
"name": "Docs",
"path": "docs"
},
{
"basePathForLoader": "sentinel/intro",
"iconName": "docs",
"name": "Intro",
"path": "intro"
}
]
}
23 changes: 0 additions & 23 deletions src/lib/__tests__/products.test.ts

This file was deleted.

26 changes: 19 additions & 7 deletions src/lib/learn-client/api/collection/fetch-product-collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
uuid,
ProductOption,
AllCollectionsProductOptions,
ThemeOption,
} from 'lib/learn-client/types'
import { get, toError } from '../../index'

Expand All @@ -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<ProductOption, 'sentinel'> | ThemeOption
): Promise<Collection[]> {
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)
Expand Down
15 changes: 13 additions & 2 deletions src/lib/learn-client/api/collection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading
Loading