Repository navigation
feat(tutorials): copy-pastable CopyBlock and CodeGroup for tutorial pages - #210
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
|
🏭 Tracked by CCF Factory — view |
There was a problem hiding this comment.
ccf-review: APPROVE
Re-review at 5d98cf0: both round-1 findings are fixed, verified, and their threads resolved; no new findings in the delta.
- CORE-TEST-001 (untested tab logic): the decisions now live in
codeGroupTabs.mjsas three plain-ESM helpers (initialTab,clampTab,nextTab), tested incodeGroupTabs.test.mjs(wrap-around both ends, Home/End, unhandled key,defaultTabmatching nothing and empty items, the clamp), registered inpackage.json'stestscript.yarn test: 57/57 pass locally at this head. - Tailwind shadow:
shadow-[shadow:var(--ifm-global-shadow-lw)]compiles to a realbox-shadowdeclaration in the built CSS (confirmed inbuild/assets/css/styles.*.css), so the group renders the shadowcustom.cssdrops from the inner block.
Checks at this head: CI build success; local yarn build, yarn typecheck, yarn spellcheck clean. i18n: single en locale, no translation tree, no hardcoded UI strings (copy-button labels go through Docusaurus translate). versioning: instances.yaml parses, every *_versions.json is one version per minor line, and the diff touches no versioned files. style: no .md/.mdx page in the diff, so no STYLE.md skeleton applies. The title prop and clean-btn hook on @theme/CodeBlock were verified against the pinned Docusaurus 3.9.2 sources.
5d98cf0 to
31d2176
Compare
There was a problem hiding this comment.
ccf-review: REQUEST_CHANGES
3 Must-fix.
Stack (base-chain): #210 → #211 → #212
Checks
- build: the PR's
buildcheck is SUCCESS on the head reviewed; at the stack headyarn install,yarn test(62 pass),yarn typecheck,yarn spellcheck(0 issues) andyarn buildalso pass locally, and tests/typecheck/spellcheck pass at this PR's head too. - i18n:
i18n.localesis['en']only and noi18n/tree exists, so the only locale is the one built; nothing half-translated; DOCS-TRANS-001 not applicable. - versioning:
instances.yamlis untouched by the stack (and validates during the build); no*_versions.jsonor*_versioned_docsfile changes, so no released line is touched and no minor line is duplicated. - style: docs-style checklist run against STYLE.md on the changed pages.
- source verification (DOCS-ACC-001): every setting, CLI command/flag, config field and path the diff adds was checked against the source repo it documents (instances.yaml) with
gh api ...?ref=<branch>; no docs page or memory was trusted.
|
No need to include a ccf-skills PR. |
There was a problem hiding this comment.
ccf-review: REQUEST_CHANGES
3 Must-fix open, 1 Nit (reported, not posted). No new threads: this is round 2 at the same head (31d2176, no new commits since round 1), and the three Must-fix threads opened in round 1 are still unresolved.
Stack (base-chain): #210 → #211 → #212
Still open from round 1 (Must-fix, DOCS-ACC-001)
The head has not moved, so none of these is fixed: src/components/tutorials/snippetText.test.mjs still contains all three fixtures. Re-verified in round 2 against the source the fixtures imitate — compliance-framework/api at its default branch, with gh api …?ref=main, not against another docs page.
src/components/tutorials/snippetText.test.mjs:8(8aa330b06681) —ccf evidence list.cmd/root.gonames the binaryapiand adds run, authz, oscal, users, seed, migrate, bootstrap, dashboards, digest, riskdigest: there is noccfbinary, noevidencecommand, and no such command anywhere in the org's CLI. Still stands.src/components/tutorials/snippetText.test.mjs:18(013955ce9f4a) —plugins:as a list of{name, namespace}.pkg/agentconfig/types.godeclaresConfig.Plugins map[string]*Plugin, keyed by the plugin identifier, whose fields are enabled, protocol_version, schedule, source, policies, config, labels, policy_data, policy_behavior: noname, nonamespace, no list form. A tutorial author copying this fixture documents a config the agent does not read. Still stands.src/components/tutorials/snippetText.test.mjs:31(69a1348577b0) —ccf catalog apply c.yaml --dry-run. Nocatalog applycommand exists and--dry-runappears on no catalog command; the site's ownapi/cli-reference.mddocumentsapi digest test --dry-runas the only--dry-run. Still stands.
Fix, as said in round 1: either use commands and a config shape the documented source has (api dashboards export f.json; plugins: as a map keyed by plugin identifier with source:), or keep the fixtures plainly about the docs repo — yarn build, compliance.yaml, the way the showcase page does. These are node --test fixtures for the dedent helper, so the assertions stay identical either way; what matters is that this file is the first thing a tutorial author reads when they want to know what a CopyBlock snippet looks like, and it teaches a CLI and a config the product does not have.
Checks and verification (round 2)
Re-run at this head in the review workspace: yarn test 57 pass / 0 fail, yarn typecheck and yarn spellcheck clean; the PR's build check is SUCCESS at this head. instances.yaml, *_versioned_docs/ and *_versions.json are untouched (versioning); i18n.locales is ['en'] alone, nothing half-translated (i18n); the new page text and CSS follow STYLE.md (style).
What the components claim held up: CopyBlock really is Docusaurus's own CodeBlock with a title row, and the copy button it promises is in the client bundle (build/assets/js/6556.*.js carries "Copy code to clipboard"), so .ccf-copy-block button.clean-btn reaches a real element after hydration rather than a hoped-for one; initialTab/clampTab/nextTab are genuinely tested for the wrap-around, the unmatched defaultTab and the hot-reload clamp; snippetText's dedent is tested for tabs, shared indentation and inner blank lines. The language values the JSDoc suggests (sh, yaml, json) match STYLE.md's own convention — the fact that the site cannot highlight sh is the site's Prism gap, reported once on #212, not a fault here.
One Nit, reported rather than posted: src/components/tutorials/CodeGroup.tsx:93 gives its role="tabpanel" no tabIndex, so unlike Tabs.tsx:119 its panel cannot be reached with Tab and the copy button inside it is mouse-only (83b40402b0be).
Once the three fixtures are changed, this is good to merge: the components themselves are sound, and both PRs above it are already approved.
Review (DOCS-ACC-001): the fixtures taught 'ccf evidence list',
'ccf catalog apply --dry-run' and a plugins list with name/namespace.
The documented CLI is the 'api' binary (api dashboards export,
api digest test --dry-run) and agentconfig.Config keys plugins by
identifier (plugins: { k8s: { enabled: ... } }). Fixtures now use
those real forms.
There was a problem hiding this comment.
ccf-review: APPROVE
1 Nit (reported, not posted). The three Must-fix threads from the review that requested changes are fixed at this head (9d1ce79) and resolved.
Stack (base-chain): #210 → #211 → #212
Re-review at 9d1ce79
One new commit since the review that requested changes: 9d1ce79 test(tutorials): keep snippet fixtures to real CLI commands and config, touching only src/components/tutorials/snippetText.test.mjs. It replaces the three Must-fix fixtures. All three were re-verified independently against the source they imitate — compliance-framework/api at its default branch with gh api …?ref=main, not against another docs page or the fix commit's own words: api dashboards export f.json is real (cmd/root.go:20 names the root command api and cmd/root.go:147 adds dashboards.RootCmd; cmd/dashboards/export.go:19 defines export); api digest test --dry-run is real (cmd/digest.go:41, digestTestCmd.Flags().BoolVar(&dryRun, "dry-run", …)); plugins: { k8s: { enabled: true } } matches pkg/agentconfig/types.go:50 (Config.Plugins map[string]*Plugin) and types.go:102 (Plugin.Enabled). The threads are resolved. No new product claim elsewhere in the diff: the remaining fixture strings (kubectl get pods, name: k8s, version: 1, port: 8080) are plain dedent material.
Checks and verification
build: the PR'sbuildcheck is SUCCESS at this head (Spellcheck too); locallyyarn testis 57 pass / 0 fail — the new fixtures pass the dedent cases unchanged, whose assertions are identical to before — andyarn typecheckis clean.versioning: the diff touches noinstances.yaml,*_versioned_docs/or*_versions.json; released lines stay untouched.i18n:i18n.localesis['en']alone and there is noi18n/directory, so nothing is half-translated (DOCS-TRANS-001 not engaged).style: no page text in this PR; the new comments and CSS follow the conventions of the files they sit in (docs-style checklist has nothing to bite on).- One Nit, reported rather than posted:
src/components/tutorials/CodeGroup.tsx:93gives itsrole="tabpanel"notabIndex, so unlikeTabs.tsx:118its panel cannot be reached with Tab and the copy button inside it is mouse-only (48475cace8dd).
With the three Must-fix findings fixed and re-verified against the source, and nothing blocking left, this is good to merge.
Closes #206 — part 2 of 4 of #204, stacked on #205.
What this adds
Two components for the tutorial pages, both usable in a
.mdxpage with no per-page import:<CopyBlock>(src/components/tutorials/CopyBlock.tsx) — one copy-pastable snippet: commands, config or file contents. It is Docusaurus's own@theme/CodeBlockunderneath, so it keeps the site's prism github/dracula highlighting and Docusaurus's built-in copy button (which copiesmetadata.code, so the clipboard gets exactly what is on screen). On top of that: atitlerow (the file the snippet goes in, or what running the command does) and a copy button that stays visible instead of fading in only on hover. Give itcode="..."or an indented text child:snippetTextdrops the blank lines the MDX literal adds and the indentation every line shares, so the reader copies what they read.<CodeGroup>(src/components/tutorials/CodeGroup.tsx) — the files of one step as tabs (items={[{title, code, language}]}, optionaldefaultTab). The selected file renders as aCopyBlock, so every file keeps its own copy button. The tabs are atablistwith roving focus and Arrow / Home / End navigation.Registering them for MDX: not
markdown.mdxPageImportsThe issue suggested
markdown.mdxPageImports. That option does not exist: Docusaurus 3.9.2'smarkdownconfig isformat,parseFrontMatter,mermaid,emoji,preprocessor,mdx1Compat,remarkRehypeOptions,anchors,hooks(@docusaurus/types/src/markdown.d.tsand the Joi schema in@docusaurus/core/lib/server/configValidation.js), and it is absent from docusaurusmaintoo. The supported way to put components on every page's MDX scope is wrapping@theme/MDXComponents, sosrc/theme/MDXComponents/index.tsxdoes exactly that and keeps the theme's own mappings (code,a,ul,admonition…). The repo already uses@theme-originalwrappers (src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx), anddocusaurus.config.tsis therefore untouched. Docusaurus has one MDX component scope, so the two tags are available on every instance's pages.Styling
Tailwind utilities on the components, with the site's Infima variables for colour (
bg-[var(--ifm-background-surface-color)],border-[var(--ifm-color-emphasis-300)],text-[var(--ifm-font-color-secondary)], …), so both themes come from the variables the site already flips at[data-theme='dark']; the code area is the prism github/dracula pair fromthemeConfig.prism. Two rules insrc/css/custom.cssreach into the theme's code block: keep the copy button visible, and let the group's chrome replace the inner block's own border, radius, shadow and margin. No new dependencies, andthemeConfig.prismis unchanged.Verification
yarn test(49 tests, including 8 new ones forsnippetText),yarn typecheck,yarn spellcheckandyarn buildpass.yarn serveof the build, on a scratch.mdxpage (not committed): both components render with no import; each block's copy button puts the exact text on the clipboard (navigator.clipboard.readText()compared with the expected snippet, forcodeand for an indented text child);CodeGroupswitches between its files through the tabs and each file copies its own text, also afterArrowRight; light mode shows the github code background (#f6f8fa) and dark mode the dracula one (#282a36) through the site's own colour toggle; no console or page errors. Screenshots of that page are in the run's artifacts rather than committed: the components have no page of their own until Showcase the tutorial components and document how to write tutorials #208 adds the showcase.Decisions
@theme/CodeBlockrather than a secondprism-react-rendererinstance: one code-block implementation site-wide, on-demand prism languages, and the copy text is the theme's ownmetadata.code.CopyBlock.tsx, not the issue'sCodeBlock.tsx: the file is named after the tag authors write, andCodeBlockis Docusaurus's component.snippetTextlives insnippetText.mjs(plain ESM with JSDoc, likescripts/*.mjs, whichdocusaurus.config.tsalready imports) soyarn testcan cover it;package.json'stestscript lists the new test file. No dependency or lockfile change.CodeGrouprenders only the selected file, so a group shows one copy button, and the panel has no title row because the tab already names the file.Open questions for reviewers
themeConfig.prism.additionalLanguages: ['bash'](perhaps alsodocker,hcl)?prism-react-rendererships no shell grammar, solanguage="sh"snippets render as plain text — as the site's 34 existingsh,shellandbashfences do today. It changes how every code block on the site renders, so it is left out here.Scope
The general unversioned site plus the shared components — no tutorial content, no other components. #207 adds the rest of the MDX component set and #208 the showcase and authoring guide, so nothing here duplicates them. No released version line is touched.
Files:
src/components/tutorials/CopyBlock.tsx,CodeGroup.tsx,snippetText.mjs,snippetText.test.mjs,src/theme/MDXComponents/index.tsx,src/css/custom.css,package.json(test script only).