-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Use mutations in Gatsby Admin #23337
Changes from 3 commits
3def3a7
2f353f1
3dcff0c
5cd1d61
fae27a8
85cf630
5975874
0fe8008
c29c6ee
0dcc20a
e095119
d69b217
d8fdee6
c8d86ae
c681ccd
a9d1e94
b333083
ab48677
92fee49
da93096
5f1e42d
3c123c7
8cfe41b
442b7e5
435baa7
c45b0ba
ea7160d
4a4d5fa
4f045c6
b9a28f7
b349a04
8a0f9c4
da535a8
67730fd
8ee74c1
ca3f76e
372c843
59992b7
6a079fb
8b180da
ac8db6a
3beca2e
82c05aa
12eaaa0
18de9f8
9c01fb2
c8da75e
ef8346f
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 |
---|---|---|
@@ -1,5 +1,72 @@ | ||
import React from "react" | ||
import { useQuery } from "urql" | ||
import { useQuery, useMutation } from "urql" | ||
|
||
const InstallInput = () => { | ||
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 => { | ||
evt.preventDefault() | ||
installGatbyPlugin({ | ||
name: value, | ||
}) | ||
}} | ||
> | ||
<label> | ||
Install: | ||
<input | ||
value={value} | ||
onChange={evt => setValue(evt.target.value)} | ||
type="text" | ||
placeholder="gatsby-plugin-cool" | ||
/> | ||
</label> | ||
</form> | ||
) | ||
} | ||
|
||
const DestroyButton = ({ name }) => { | ||
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. You'll need to use an interface to type the props here. Make it |
||
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 onClick={() => deleteGatsbyPlugin({ name })}>X</button> | ||
} | ||
|
||
export default (): React.ReactElement => { | ||
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. If you give this a name and export that as default afterwards it should show up properly in devtools. As above, typing it as React.FC will give correct return and props values |
||
const [{ data, fetching, error }] = useQuery({ | ||
|
@@ -33,17 +100,22 @@ export default (): React.ReactElement => { | |
{data.allGatsbyPlugin.nodes | ||
.filter(plugin => plugin.name.indexOf(`gatsby-plugin`) === 0) | ||
.map(plugin => ( | ||
<li key={plugin.id}>{plugin.name}</li> | ||
<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}</summary> | ||
<summary> | ||
{plugin.name} <DestroyButton name={plugin.name} /> | ||
</summary> | ||
<ul> | ||
{plugin.shadowedFiles.map(file => ( | ||
<li key={file} style={{ opacity: 0.6 }}> | ||
|
@@ -58,6 +130,8 @@ export default (): React.ReactElement => { | |
</li> | ||
))} | ||
</ul> | ||
|
||
<InstallInput /> | ||
</> | ||
) | ||
} |
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.
The linter is complaining about missing return values, which is why it's failing tests. Type them as
React.FC
and you'll get that for free