-
Notifications
You must be signed in to change notification settings - Fork 17
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
refactor(docs-page): to TS; split up file #360
refactor(docs-page): to TS; split up file #360
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/hashicorp/react-components/6miKUkyNtmdtK3bYeA2sgwHiLvj3 |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥇
packages/docs-page/server/consts.ts
Outdated
export const ENABLE_VERSIONED_DOCS = process.env.ENABLE_VERSIONED_DOCS | ||
export const VERCEL_ENV = process.env.VERCEL_ENV |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'm not super crazy about re-assigning env vars in a separate file like this. I find it harder to grok for usage and it's just another layer of indirection.
That said, I'm not willing to die on this hill and if you feel this is a better structure I'm okay with that. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not tied to this! Happy to revert this change...
I'm more interested in lifting up environment variable usage into function args, so that the functions can be more pure. Didn't get to this part yet though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like
- import { ENABLE_VERSIONED_DOCS, VERCEL_ENV, DEFAULT_PARAM_ID } from './consts'
+ import { DEFAULT_PARAM_ID } from './consts'
Then in a function
- function generateStaticPaths(context) { ... }
+ const options = {
+ VERCEL_ENV: process.env.VERCEL_ENV,
+ ENABLE_VERSIONED_DOCS: process.env.ENABLE_VERSIONED_DOCS,
+ }
+
+ function generateStaticPaths(context, { VERCEL_ENV, ENABLE_VERSIONED_DOCS } = options) { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating this now... and removing the env vars from consts.ts
versions = versionMetadataList.map((e) => { | ||
const { isLatest, version, display } = e | ||
if (isLatest) { | ||
latestVersion = version | ||
} | ||
|
||
const displayValue = display ?? version | ||
|
||
return { | ||
name: isLatest ? 'latest' : version, | ||
label: isLatest ? `${displayValue} (latest)` : displayValue, | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like this could be a fair candidate to extract into a function that's easier to test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extracted into mapVersionList
Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
- refactor `generateStaticProps` logic
Looking good! Could you test this with a canary release in a site? That would be full validation that the refactor is good, apart from your tests 😄 |
📦 Canary Packages PublishedLatest commit: cd07f61 Published 1 packages@hashicorp/react-docs-page@14.2.4-canary-202183015355
|
Merging into #354 — will continue UAT there! |
* refactor(docs-page): to TS; split up file * test: add at least snapshot tests for all files * chore: fixtures * chore: update snapshots * chore: rename to moizeOpts * Update packages/docs-page/server/generate-static-props.ts Co-authored-by: Bryce Kalow <bkalow@hashicorp.com> * chore: extract `mapVersionList`; - refactor `generateStaticProps` logic * chore: `generateStaticProps` snapshot * chore: remove env vars from `consts.ts` Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
* refactor(docs-page): to TS; split up file * test: add at least snapshot tests for all files * chore: fixtures * chore: update snapshots * chore: rename to moizeOpts * Update packages/docs-page/server/generate-static-props.ts Co-authored-by: Bryce Kalow <bkalow@hashicorp.com> * chore: extract `mapVersionList`; - refactor `generateStaticProps` logic * chore: `generateStaticProps` snapshot * chore: remove env vars from `consts.ts` Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
* refactor(docs-page): to TS; split up file * test: add at least snapshot tests for all files * chore: fixtures * chore: update snapshots * chore: rename to moizeOpts * Update packages/docs-page/server/generate-static-props.ts Co-authored-by: Bryce Kalow <bkalow@hashicorp.com> * chore: extract `mapVersionList`; - refactor `generateStaticProps` logic * chore: `generateStaticProps` snapshot * chore: remove env vars from `consts.ts` Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
* feat(docs-page): server.js calls content api * chore: add logging to generateStaticPaths * feat: use display attribute if available * fix: only use display for option label * feat: always fetch remote content in production * fix: `moize` usage * refactor(docs-page/server): to TS; split up files (#360) * refactor(docs-page): to TS; split up file * chore: extract `mapVersionList`; - refactor `generateStaticProps` logic Co-authored-by: Bryce Kalow <bkalow@hashicorp.com>
asana
Description
docs-page/server.js
into isolated TypeScript files.moize
usageThis is meant to merge into: