Skip to content

Commit 6287c73

Browse files
authored
feat(gatsby-admin): plugin view (#26195)
* feat(gatsby-admin): plugin view * Add readme field to plugin provider * Fetch npm data for plugin on plugin details page * Render view on GitHub and readme * Handle new plugins and install flow from plugin screen * Redirect to /plugins/{name} on plugin search and fix homepage loading state * Rework loading states on plugin pages * Cleanup, add GitHub icon * Render metadata * Render markdown but ugly * Delete duplicate headers * Make markdown readable * Use interface components to render text and headings in markdown * Render code snippets kinda nicely * Clean up inline code * Add first syntax highlighting to readme code blocks * Remove unused imports * Add readmes to pluign provider test snapshots * Share Algolia API keys * Extract homepagePath into own variable
1 parent f47e4c1 commit 6287c73

16 files changed

+4923
-364
lines changed
+27-15
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
module.exports = {
2-
plugins: [{
3-
resolve: "gatsby-plugin-react-helmet"
4-
}, {
5-
resolve: "gatsby-plugin-webfonts",
6-
options: {
7-
fonts: {
8-
google: [{
9-
family: `Inter`,
10-
variants: [`400`, `600`, `800`]
11-
}]
12-
}
13-
}
14-
}],
15-
pathPrefix: `/___admin`
16-
};
2+
plugins: [
3+
{
4+
resolve: "gatsby-plugin-react-helmet",
5+
options: {},
6+
},
7+
{
8+
resolve: "gatsby-plugin-webfonts",
9+
options: {
10+
fonts: {
11+
google: [
12+
{
13+
family: `Inter`,
14+
variants: [`400`, `600`, `800`],
15+
},
16+
],
17+
},
18+
},
19+
},
20+
{
21+
resolve: "gatsby-plugin-create-client-paths",
22+
options: {
23+
prefixes: ["/plugins/*"],
24+
},
25+
},
26+
],
27+
pathPrefix: `/___admin`,
28+
}

packages/gatsby-admin/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
"lodash-es": "^4.17.15",
2828
"ncp": "^2.0.0",
2929
"nodemon": "^2.0.4",
30+
"prism-react-renderer": "^1.1.1",
3031
"react": "^16.12.0",
3132
"react-dom": "^16.12.0",
3233
"react-helmet": "^6.1.0",
3334
"react-icons": "^3.10.0",
3435
"react-instantsearch-dom": "^5.7.0",
36+
"react-markdown": "^4.3.1",
3537
"remove-markdown": "^0.3.0",
3638
"rimraf": "^3.0.2",
3739
"strict-ui": "^0.2.0-0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* @jsx jsx */
2+
import { jsx } from "strict-ui"
3+
import {
4+
InstantSearch,
5+
Configure,
6+
RefinementList,
7+
ToggleRefinement,
8+
} from "react-instantsearch-dom"
9+
import algoliaConfig from "../utils/algolia-config"
10+
11+
export default function InstantSearchProvider({
12+
children,
13+
searchState,
14+
}: {
15+
children: React.ReactNode
16+
searchState?: string
17+
}): JSX.Element {
18+
return (
19+
<InstantSearch
20+
apiKey={algoliaConfig.API_KEY}
21+
appId={algoliaConfig.APPLICATION_ID}
22+
indexName="npm-search"
23+
searchState={searchState}
24+
>
25+
<div style={{ display: `none` }}>
26+
<Configure analyticsTags={[`gatsby-plugins`]} />
27+
<RefinementList
28+
attribute="keywords"
29+
transformItems={(items: Array<any>): Array<any> =>
30+
items.map(({ count, ...item }) => {
31+
return {
32+
...item,
33+
count: count || 0,
34+
}
35+
})
36+
}
37+
defaultRefinement={[`gatsby-component`, `gatsby-plugin`]}
38+
/>
39+
<ToggleRefinement
40+
attribute="deprecated"
41+
value={false}
42+
label="No deprecated plugins"
43+
defaultRefinement={true}
44+
/>
45+
</div>
46+
{children}
47+
</InstantSearch>
48+
)
49+
}

packages/gatsby-admin/src/components/manage-plugin-modal.tsx

-152
This file was deleted.

packages/gatsby-admin/src/components/navbar.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useQuery } from "urql"
55
import { FeedbackForm } from "feedback-fish"
66
import externalLinkIcon from "../external-link.svg"
77
import graphqlIcon from "../graphql.svg"
8+
import { Link } from "gatsby"
89

910
function SendFeedbackButton(props): JSX.Element {
1011
return (
@@ -14,6 +15,8 @@ function SendFeedbackButton(props): JSX.Element {
1415
)
1516
}
1617

18+
const homepagePath = process.env.NODE_ENV === `development` ? `/` : `/___admin`
19+
1720
function Navbar(): JSX.Element {
1821
const [{ data }] = useQuery({
1922
query: `
@@ -35,7 +38,14 @@ function Navbar(): JSX.Element {
3538
paddingY: 5,
3639
}}
3740
>
38-
<Flex gap={5} alignItems="baseline">
41+
<Flex
42+
as={Link}
43+
// @ts-ignore
44+
to={homepagePath}
45+
gap={5}
46+
alignItems="baseline"
47+
sx={{ textDecoration: `none` }}
48+
>
3949
<Text sx={{ textTransform: `uppercase`, fontSize: 0 }}>
4050
Gatsby Admin
4151
</Text>
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
/* @jsx jsx */
22
import { jsx } from "strict-ui"
3-
import { Spinner } from "theme-ui"
4-
import {
5-
InstantSearch,
6-
Configure,
7-
RefinementList,
8-
ToggleRefinement,
9-
connectAutoComplete,
10-
} from "react-instantsearch-dom"
3+
import { connectAutoComplete } from "react-instantsearch-dom"
114
import {
125
Combobox,
136
ComboboxInput,
147
ComboboxPopover,
158
ComboboxList,
169
ComboboxOption,
1710
} from "gatsby-interface"
18-
import { useMutation } from "urql"
11+
import InstantSearchProvider from "./instantsearch-provider"
12+
import { navigate } from "gatsby-link"
1913

2014
const SearchCombobox: React.FC<{
2115
onSelect: (value: string) => void
@@ -42,65 +36,16 @@ const SearchCombobox: React.FC<{
4236
))
4337

4438
// the search bar holds the Search component in the InstantSearch widget
45-
const PluginSearchInput: React.FC<{}> = () => {
46-
const [{ fetching }, installGatbyPlugin] = useMutation(`
47-
mutation installGatsbyPlugin($name: String!) {
48-
createNpmPackage(npmPackage: {
49-
name: $name,
50-
dependencyType: "production"
51-
}) {
52-
id
53-
name
54-
}
55-
createGatsbyPlugin(gatsbyPlugin: {
56-
name: $name
57-
}) {
58-
id
59-
name
60-
}
61-
}
62-
`)
63-
64-
return (
65-
<div>
66-
<InstantSearch
67-
apiKey="ae43b69014c017e05950a1cd4273f404"
68-
appId="OFCNCOG2CU"
69-
indexName="npm-search"
70-
>
71-
<div style={{ display: `none` }}>
72-
<Configure analyticsTags={[`gatsby-plugins`]} />
73-
<RefinementList
74-
attribute="keywords"
75-
transformItems={(items: Array<any>): Array<any> =>
76-
items.map(({ count, ...item }) => {
77-
return {
78-
...item,
79-
count: count || 0,
80-
}
81-
})
82-
}
83-
defaultRefinement={[`gatsby-component`, `gatsby-plugin`]}
84-
/>
85-
<ToggleRefinement
86-
attribute="deprecated"
87-
value={false}
88-
label="No deprecated plugins"
89-
defaultRefinement={true}
90-
/>
91-
</div>
92-
{fetching ? (
93-
<Spinner />
94-
) : (
95-
<SearchCombobox
96-
onSelect={(value): void => {
97-
installGatbyPlugin({ name: value })
98-
}}
99-
/>
100-
)}
101-
</InstantSearch>
102-
</div>
103-
)
104-
}
39+
const PluginSearchInput: React.FC<{}> = () => (
40+
<div>
41+
<InstantSearchProvider>
42+
<SearchCombobox
43+
onSelect={(name): void => {
44+
navigate(`/plugins/${name}`)
45+
}}
46+
/>
47+
</InstantSearchProvider>
48+
</div>
49+
)
10550

10651
export default PluginSearchInput

0 commit comments

Comments
 (0)