-
Notifications
You must be signed in to change notification settings - Fork 121
chore: migrate site to Next.js #3011
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
Changes from all commits
abf8946
414ab89
e21023b
4a4a5c2
ff66060
354c4f7
1a93cf0
df444ce
61c7aff
1dfcd62
a321c5f
5a56f9f
6c7b5f0
a783114
dbecf12
048e165
d7b70ea
e2c1e1e
7d91988
e401578
3783763
a6048df
695e920
a41e714
83945a1
ddfa72c
d15eae5
b77a07e
f87fea3
f58c5db
3fb0dbc
0096437
d9499d3
0c05f3d
3c3cd8d
4c9acab
f8fcaa3
8779dfc
7c3c383
9b1c22d
06346d2
0a74f82
758b723
51cbf3c
acd4b68
8fbe995
97204b6
a44eb97
edb3eb9
e638bf1
c2d1bd1
af72556
427f909
105c48e
bf07dd6
38dde8f
3a9809e
df7ac59
6029dec
c330beb
e66678f
df963ad
8285f70
c5bc23b
da3e389
34501d5
9ee20f1
0070f8e
fec2f1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,30 +9,50 @@ | |
|
|
||
| The overview tables and component/pattern headers all use an Airtable integration to gather the data displayed in each. | ||
|
|
||
| The Airtable connection is done through the `gatsby-source-airtable` plugin. This uses an api key and pulls all of the Airtable information into a graphql schema. We then use this to populate the component or pattern statuses. Here is an example of the component overview page graphql query: | ||
| The Airtable connection is done through the `Airtable JS client`. It uses an api key and allows us to query the Airtable information. We then use this to populate the component or pattern statuses. Here is an example of the query used to fetch all features: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: love these docs! |
||
|
|
||
| ```js | ||
| allAirtable( | ||
| sort: {fields: [data___Feature]} | ||
| filter: {data: {status: {ne: null}, Component_Category: {eq: "component"}}} | ||
| ) { | ||
| edges { | ||
| node { | ||
| data { | ||
| Feature | ||
| Documentation | ||
| Figma | ||
| Design_committee_review | ||
| Engineer_committee_review | ||
| Code | ||
| status | ||
| } | ||
| } | ||
| } | ||
| } | ||
| const airtable = new Airtable({apiKey: process.env.AIRTABLE_APIKEY}); | ||
| const base = airtable.base(process.env.AIRTABLE_BASEID); | ||
|
|
||
| export const systemTable = base('System'); | ||
|
|
||
| const features = await systemTable | ||
| .select({ | ||
| filterByFormula: 'status', | ||
| sort: [{field: 'Feature'}], | ||
| fields: [ | ||
| 'Component Category', | ||
| 'Feature', | ||
| 'Documentation', | ||
| 'Figma', | ||
| 'Design committee review', | ||
| 'Engineer committee review', | ||
| 'Code', | ||
| 'status', | ||
| 'Product suitability', | ||
| ], | ||
| }) | ||
| .all(); | ||
| const items = features.map(({fields}) => fields); | ||
| ``` | ||
|
|
||
| In the query, we’re filtering all of the Airtable data by status and Component_Category. Then getting the Feature, Documentation, Figma, etc table data. | ||
| The data is then written to a JSON file and made available via the `utils/api` helper functions. The overview pages can then access this data using Next's `getStaticProps` and pass the information to other components: | ||
|
|
||
| ```js | ||
| import {getAllComponents} from '../../utils/api'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: this approach is much more intuitive imo |
||
|
|
||
| export const getStaticProps = async () => { | ||
| const components = await getAllComponents(['component', 'layout']); | ||
| return { | ||
| props: { | ||
| componentList: components, | ||
| }, | ||
| }; | ||
| }; | ||
| ``` | ||
|
|
||
| In the query, we’re filtering all of the Airtable data by status. Then getting the Feature, Documentation, Figma, etc table data. | ||
|
|
||
| In the `component-overview-table` component, we either display the data, pass the data to a conditional, or pass the data to another component like `AssetStatus` or `PeerReviewStatus`. | ||
|
|
||
|
|
@@ -42,29 +62,26 @@ _This can cause some issues with Cypress tests failing if you’re working on a | |
|
|
||
| ## Component and pattern headers | ||
|
|
||
| The component and pattern headers also get their data from Airtable. In the components, the graphql data is passed to the `PackageStatusLegend` component, where a series of conditionals displays either a `SuccessIcon` or `pending`. The `status` and `Product_suitability` data are used directly in the component or pattern header components. | ||
| The component and pattern headers also get their data from Airtable. In the components, the data is passed to the `PackageStatusLegend` component, where a series of conditionals displays either a `SuccessIcon` or `pending`. The `status` and `Product suitability` data are used directly in the component or pattern header components. | ||
|
|
||
| Here is an example of the graphql query: | ||
| Here is an example: | ||
|
|
||
| ```js | ||
| allAirtable(filter: {data: {Feature: {eq: "Delete"}}}) { | ||
| edges { | ||
| node { | ||
| data { | ||
| Documentation | ||
| Figma | ||
| Design_committee_review | ||
| Engineer_committee_review | ||
| Code | ||
| status | ||
| Product_suitability | ||
| } | ||
| } | ||
| } | ||
| } | ||
| import {getFeature} from '../../../utils/api'; | ||
|
|
||
| export const getStaticProps = async () => { | ||
| const feature = await getFeature('Delete'); | ||
| return { | ||
| props: { | ||
| data: { | ||
| ...feature, | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
| ``` | ||
|
|
||
| This query filters all of the Airtable data by Feature name. The feature needs to match exactly what is in Airtable for the data to correctly be fetched. So in this case, if you filtered by “delete”, no data would be fetched, but “Delete” works because the feature in Aritable is “Delete”. | ||
| This util filters all of the Airtable data by Feature name. The feature needs to match exactly what is in Airtable for the data to correctly be fetched. So in this case, if you filtered by “delete”, no data would be fetched, but “Delete” works because the feature in Aritable is “Delete”. | ||
|
|
||
| ## Future state | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,21 @@ | ||
| # Images | ||
|
|
||
| Images in Gatsby can be unnecessarily complicated, so we should try and keep it as simple as possible by following these guidelines. | ||
|
|
||
| ## In MDX pages | ||
|
|
||
| In MDX favor Markdown syntax for including images. Let Gatsby do the rest. | ||
|
|
||
| ```mdx | ||
|  | ||
| ``` | ||
|
|
||
| If you can't use Markdown because you are displaying your image inside a component, first **do not** compose your component in the MDX file. Create a component `tsx` file and import it. Inside you component file, use the [Gatsby Static Image](https://www.gatsbyjs.com/docs/how-to/images-and-media/using-gatsby-plugin-image/#static-images) component. | ||
| Use Next's [next/image](https://nextjs.org/docs/api-reference/next/image) component to render statically imported images: | ||
|
|
||
| ```tsx | ||
| import {StaticImage} from 'gatsby-plugin-image'; | ||
| import Image from 'next/future/image'; | ||
| import AwaitingData from '../../assets/images/patterns/empty-awaiting-data.png'; | ||
|
|
||
| export const AwaitingDataImage: React.FC = () => { | ||
| return ( | ||
| <StaticImage | ||
| src="../../assets/images/patterns/empty-awaiting-data.png" | ||
| alt="" | ||
| width={150} | ||
| placeholder="blurred" | ||
| layout="fixed" | ||
| /> | ||
| ); | ||
| return <Image src={AwaitingData} alt="" width={150} placeholder="blur" />; | ||
| }; | ||
| ``` | ||
|
|
||
| ## Non-MDX pages | ||
|
|
||
| Favor using the [Gatsby Static Image](https://www.gatsbyjs.com/docs/how-to/images-and-media/using-gatsby-plugin-image/#static-images) component. | ||
| Next does not apply styles/wrappers to images, so to ensure non-gif images are centered and styled correctly in MDX pages import and use the custom `ResponsiveImage` component which wraps `next/image`: | ||
|
|
||
| ```tsx | ||
| import {StaticImage} from 'gatsby-plugin-image'; | ||
| import {ResponsiveImage} from '../../components/ResponsiveImage'; | ||
| import AwaitingData from '../../assets/images/patterns/empty-awaiting-data.png'; | ||
|
|
||
| export const AwaitingDataImage: React.FC = () => { | ||
| return ( | ||
| <StaticImage | ||
| src="../../assets/images/patterns/empty-awaiting-data.png" | ||
| alt="" | ||
| width={150} | ||
| placeholder="blurred" | ||
| layout="fixed" | ||
| /> | ||
| ); | ||
| }; | ||
| <ResponsiveImage src={AwaitingData} />; | ||
| ``` | ||
|
|
||
| ## Dynamic Images (GraphQL) | ||
|
|
||
| It is incredibly rare that you should need [Dynamic images](https://www.gatsbyjs.com/docs/how-to/images-and-media/using-gatsby-plugin-image/#dynamic-images). We aren't doing anything fancy right now, **avoid them at all costs**. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # MDX | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: nice addition |
||
|
|
||
| MDX is implemented by the [@next/mdx](https://nextjs.org/docs/advanced-features/using-mdx) package. To ensure your page renders correctly, supply the needed navigation data to `getStaticProps` and export the layout component as the default export: | ||
|
|
||
| ```tsx | ||
| import DefaultLayout from '../../../layouts/DefaultLayout'; | ||
| import {getNavigationData} from '../../../utils/api'; // import this last to avoid issues with the MDXProvider | ||
|
|
||
| export default DefaultLayout; | ||
|
|
||
| export const getStaticProps = async () => { | ||
| const navigationData = await getNavigationData(); | ||
| return { | ||
| props: { | ||
| navigationData, | ||
| }, | ||
| }; | ||
| }; | ||
| ``` | ||
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.
question: why this change?
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.
Have a lib directory in the docs package now for holding things like google analytics (to match practices from the next official examples).