-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby-admin): Setup Gatsby Admin site (#23291)
Co-Authored-By: LB <laurie@gatsbyjs.com> Co-Authored-By: Brent Jackson <jxnblk@gmail.com>
- Loading branch information
1 parent
ddf68db
commit 385dfae
Showing
14 changed files
with
643 additions
and
16 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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,18 @@ | ||
# Gatsby Admin | ||
|
||
A visual interface to configure your Gatsby site. | ||
|
||
We have not packaged this nicely yet, so it is not installable. | ||
|
||
## How to develop it | ||
|
||
However, you can do some manual set up in order to work with it locally. Follow these steps: | ||
|
||
1. Navigate to the monorepo and open the `packages/gatsby-admin` directory. | ||
2. In that directory, run `yarn develop`. | ||
> If you see eslint errors you'll need to temporarily replace all references to `___loader` with `window.___loader` inside of `gatsby-link/index.js`. | ||
3. In a new tab, navigate to a Gatsby site of your choice (or create one) that runs the latest version of Gatsby (recipes are a requirement). | ||
4. From the `packages/gatsby-recipes/src` directory in the monorepo copy the `create-types.js` and `graphql.js` files. Use these files to replace those currently in your site's `node_modules/gatsby-recipes/src` directory. | ||
5. Run `node ./node_modules/gatsby-recipes/src/graphql.js` to start the Recipes GraphQL server for that site. | ||
|
||
You should now be able to visit `localhost:8000` to see Gatsby Admin for that site! |
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,6 @@ | ||
import React from 'react'; | ||
import Providers from './src/components/providers' | ||
|
||
export const wrapPageElement = ({ element,props }) =>( | ||
<Providers {...props}>{element}</Providers> | ||
) |
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,3 @@ | ||
module.exports = { | ||
plugins: [`gatsby-plugin-typescript`] | ||
} |
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,23 @@ | ||
{ | ||
"name": "gatsby-admin", | ||
"version": "0.0.0", | ||
"main": "index.js", | ||
"author": "Max Stoiber", | ||
"license": "MIT", | ||
"private": true, | ||
"dependencies": { | ||
"@typescript-eslint/parser": "^2.28.0", | ||
"@typescript-eslint/eslint-plugin": "^2.28.0", | ||
"gatsby": "^2.20.25", | ||
"gatsby-source-graphql": "^2.4.2", | ||
"gatsby-plugin-typescript": "^2.3.3", | ||
"react": "^16.12.0", | ||
"react-dom": "^16.12.0", | ||
"subscriptions-transport-ws": "^0.9.16", | ||
"typescript": "^3.8.3", | ||
"urql": "^1.9.5" | ||
}, | ||
"scripts": { | ||
"develop": "gatsby develop" | ||
} | ||
} |
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,7 @@ | ||
import React from "react" | ||
import { Provider } from "urql" | ||
import client from "../urql-client" | ||
|
||
export default ({ children }): React.ReactElement => ( | ||
<Provider value={client}>{children}</Provider> | ||
) |
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,148 @@ | ||
import React from "react" | ||
import { useQuery, useMutation } from "urql" | ||
|
||
const InstallInput: React.FC<{}> = () => { | ||
const [value, setValue] = React.useState(``) | ||
|
||
const [, installGatbyPlugin] = useMutation(` | ||
mutation installGatsbyPlugin($name: String!) { | ||
createNpmPackage(npmPackage: { | ||
name: $name, | ||
dependencyType: "production" | ||
}) { | ||
id | ||
name | ||
} | ||
createGatsbyPlugin(gatsbyPlugin: { | ||
name: $name | ||
}) { | ||
id | ||
name | ||
} | ||
} | ||
`) | ||
|
||
return ( | ||
<form | ||
onSubmit={(evt): void => { | ||
evt.preventDefault() | ||
installGatbyPlugin({ | ||
name: value, | ||
}) | ||
}} | ||
> | ||
<label> | ||
Install: | ||
<input | ||
value={value} | ||
onChange={(evt): void => setValue(evt.target.value)} | ||
type="text" | ||
placeholder="gatsby-plugin-cool" | ||
/> | ||
</label> | ||
</form> | ||
) | ||
} | ||
|
||
const DestroyButton: React.FC<{ name: string }> = ({ name }) => { | ||
const [, deleteGatsbyPlugin] = useMutation(` | ||
mutation destroyGatsbyPlugin($name: String!) { | ||
destroyNpmPackage(npmPackage: { | ||
name: $name, | ||
id: $name, | ||
dependencyType: "production" | ||
}) { | ||
id | ||
name | ||
} | ||
destroyGatsbyPlugin(gatsbyPlugin: { | ||
name: $name, | ||
id: $name | ||
}) { | ||
id | ||
name | ||
} | ||
} | ||
`) | ||
|
||
return ( | ||
<button | ||
aria-label={`Delete ${name}`} | ||
onClick={(): void => { | ||
deleteGatsbyPlugin({ name }) | ||
}} | ||
> | ||
X | ||
</button> | ||
) | ||
} | ||
|
||
const Index: React.FC<{}> = () => { | ||
const [{ data, fetching, error }] = useQuery({ | ||
query: ` | ||
{ | ||
allGatsbyPlugin { | ||
nodes { | ||
name | ||
id | ||
shadowedFiles | ||
shadowableFiles | ||
} | ||
} | ||
npmPackageJson(id: "name") { | ||
name | ||
value | ||
} | ||
} | ||
`, | ||
}) | ||
|
||
if (fetching) return <p>Loading...</p> | ||
|
||
if (error) return <p>Oops something went wrong.</p> | ||
|
||
return ( | ||
<> | ||
<h1>{data.npmPackageJson.value.replace(/^"|"$/g, ``)}</h1> | ||
<h2>Plugins</h2> | ||
<ul> | ||
{data.allGatsbyPlugin.nodes | ||
.filter(plugin => plugin.name.indexOf(`gatsby-plugin`) === 0) | ||
.map(plugin => ( | ||
<li key={plugin.id}> | ||
{plugin.name} <DestroyButton name={plugin.name} /> | ||
</li> | ||
))} | ||
</ul> | ||
<InstallInput /> | ||
<h2>Themes</h2> | ||
<ul> | ||
{data.allGatsbyPlugin.nodes | ||
.filter(plugin => plugin.name.indexOf(`gatsby-theme`) === 0) | ||
.map(plugin => ( | ||
<li key={plugin.id}> | ||
<details> | ||
<summary> | ||
{plugin.name} <DestroyButton name={plugin.name} /> | ||
</summary> | ||
<ul> | ||
{plugin.shadowedFiles.map(file => ( | ||
<li key={file} style={{ opacity: 0.6 }}> | ||
{file} (shadowed) | ||
</li> | ||
))} | ||
{plugin.shadowableFiles.map(file => ( | ||
<li key={file}>{file}</li> | ||
))} | ||
</ul> | ||
</details> | ||
</li> | ||
))} | ||
</ul> | ||
|
||
<InstallInput /> | ||
</> | ||
) | ||
} | ||
|
||
export default Index |
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,24 @@ | ||
const { createClient, defaultExchanges, subscriptionExchange } = require(`urql`) | ||
const { SubscriptionClient } = require(`subscriptions-transport-ws`) | ||
|
||
const subscriptionClient = new SubscriptionClient( | ||
`ws://localhost:4000/graphql`, | ||
{ | ||
reconnect: true, | ||
} | ||
) | ||
|
||
const client = createClient({ | ||
fetch, | ||
url: `http://localhost:4000/graphql`, | ||
exchanges: [ | ||
...defaultExchanges, | ||
subscriptionExchange({ | ||
forwardSubscription(operation) { | ||
return subscriptionClient.request(operation) | ||
}, | ||
}), | ||
], | ||
}) | ||
|
||
export default client |
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,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"strict": true | ||
} |
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
Oops, something went wrong.