-
Notifications
You must be signed in to change notification settings - Fork 32
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
Website: Introduce Snippets for FE Package Managers #233
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1d0fe6d
feat(website): introduce CodeSnippets component to render tabbed code…
jackw 1213f5d
feat(website): introduce code snippet files
jackw 30b68d3
feat(website): introduce CodeSnippets to documentation, rename to mdx
jackw 253953b
chore(website): delete page from original docusaurus scaffolding
jackw 80b5847
chore(website): exclude snippets from creating docs page entries
jackw 147e453
chore(website): ts-ignore broken docusaurus types in CodeSnippets
jackw 6aabe93
docs(website): add additional snippets for install and grafana versio…
jackw 2a20252
docs(website): allow regex to match multiple occurances of []({{}}) i…
jackw 372d297
docs(codesnippets): commment explaining snippet namingconvention and …
jackw 30e300d
docs(synccommand): add component to hook into currently active packag…
jackw c37a5e7
docs(website): fix up remaining occurances of fe package manager comm…
jackw a3c518d
fix(website): use browseronly component so server will build
jackw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cd <orgName>-<pluginName>-<pluginType> | ||
npm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cd <orgName>-<pluginName>-<pluginType> | ||
pnpm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cd <orgName>-<pluginName>-<pluginType> | ||
yarn install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx @grafana/create-plugin@latest migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pnpm dlx @grafana/create-plugin@latest migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
yarn create @grafana/plugin migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx @grafana/create-plugin@latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pnpm dlx @grafana/create-plugin@latest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
yarn create @grafana/plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npx @grafana/create-plugin@latest update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pnpm dlx @grafana/create-plugin@latest update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
yarn create @grafana/plugin update |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GRAFANA_VERSION=8.5.5 npm run server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GRAFANA_VERSION=8.5.5 pnpm run server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GRAFANA_VERSION=8.5.5 yarn run server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
docusaurus/website/src/components/CodeSnippets/CodeSnippets.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import CodeBlock from '@theme/CodeBlock'; | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
|
||
/* | ||
CodeSnippets is a component that allows you to display code snippets from the docs/snippets folder. | ||
It takes in an array of paths to the snippets you want to display, and will display them in a tabbed | ||
interface. The paths should be relative to the docs/snippets folder, and should include the file extension. | ||
|
||
Snippets should be named in the following format: <name>.<value>.<language>.<extension> | ||
`value` is used for the tabs unique value and label. | ||
language is used for syntax highlighting. | ||
*/ | ||
|
||
function CodeSnippets({ paths, groupId, queryString }: { paths: string[]; groupId?: string; queryString?: string }) { | ||
const snippetPaths = paths.map((path) => path.trim()); | ||
const [snippets, setSnippets] = useState([]); | ||
|
||
useEffect(() => { | ||
async function fetchSnippets() { | ||
const fetchedSnippets = await Promise.all( | ||
snippetPaths.map(async (path) => { | ||
const [_, value, language] = path.split('.'); | ||
try { | ||
const code = (await import(`!!raw-loader!@site/../docs/snippets/${path}`)).default; | ||
|
||
return { | ||
language, | ||
value, | ||
label: value.toUpperCase(), | ||
code, | ||
}; | ||
} catch (error) { | ||
console.log(`CodeSnippets failed to load: docs/snippets/${path}`, error); | ||
return null; | ||
} | ||
}) | ||
); | ||
setSnippets(fetchedSnippets.filter((snippet) => snippet != null)); | ||
} | ||
|
||
fetchSnippets(); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
if (snippets.length === 0) { | ||
return null; | ||
} | ||
|
||
if (snippets.length === 1) { | ||
return <CodeBlock language={snippets[0].language}>{snippets[0].code}</CodeBlock>; | ||
} | ||
|
||
return ( | ||
// @ts-ignore - Tabs types appear to be broken. | ||
<Tabs groupId={groupId} queryString={queryString}> | ||
{snippets.map((snippet) => ( | ||
// @ts-ignore - TabItem types appear to be broken. | ||
<TabItem key={snippet.value} value={snippet.value} label={snippet.label}> | ||
<CodeBlock language={snippet.language}>{snippet.code}</CodeBlock> | ||
</TabItem> | ||
))} | ||
</Tabs> | ||
); | ||
} | ||
|
||
export default CodeSnippets; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 would probably add a block of comments above the component definition that explains how to use this component on the call-site, especially how the name of the file relates to the names of the tabs.