-
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.
feat(gatsby): serve Admin from develop parent process (#23734)
* Server static admin app from parent process * Start Recipes GraphQL server when running develop and fetch fresh port in admin * Setup gatsby-inteface and strict-ui * Build gatsby admin navbar * Proper headings on the dash * Style rest of dashboard * Add return type to createUrqlClient * Update gatsby admin running instructions * Add instructions to replace ___loader with window.___loader * Remove unused components * Bump strict-ui and test local site dev * Add GATSBY_EXPERIMENTAL_ENABLE_ADMIN feature flag * Resolve type issue by pinning version of csstype to 2.6.10 * Fix package.json for gatsby-admin package * Update packages/gatsby-admin/README.md Co-authored-by: Lennart <lekoarts@gmail.com> * Remove built-in plugin * Add some more technical docs * Fix prettier Co-authored-by: Lennart <lekoarts@gmail.com>
- Loading branch information
Showing
16 changed files
with
1,002 additions
and
115 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import React from 'react'; | ||
import Providers from './src/components/providers' | ||
import Layout from './src/components/layout' | ||
|
||
export const wrapPageElement = ({ element,props }) =>( | ||
<Providers {...props}>{element}</Providers> | ||
<Layout {...props}>{element}</Layout> | ||
) |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
plugins: [`gatsby-plugin-typescript`] | ||
plugins: [], | ||
pathPrefix: `/___admin` | ||
} |
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 @@ | ||
// NOOP |
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,15 @@ | ||
/** @jsx jsx */ | ||
import { jsx, Flex } from "strict-ui" | ||
import Providers from "./providers" | ||
import Navbar from "./navbar" | ||
|
||
const Layout: React.FC<{}> = ({ children }) => ( | ||
<Providers> | ||
<Flex gap={0} flexDirection="column"> | ||
<Navbar /> | ||
{children} | ||
</Flex> | ||
</Providers> | ||
) | ||
|
||
export default Layout |
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,58 @@ | ||
/** @jsx jsx */ | ||
import { jsx, Flex } from "strict-ui" | ||
import { Text, BaseAnchor } from "gatsby-interface" | ||
import { useQuery } from "urql" | ||
|
||
const Navbar: React.FC<{}> = () => { | ||
const [{ data }] = useQuery({ | ||
query: ` | ||
{ | ||
npmPackageJson(id: "name") { | ||
value | ||
} | ||
} | ||
`, | ||
}) | ||
|
||
return ( | ||
<Flex | ||
justifyContent="space-between" | ||
alignItems="center" | ||
sx={{ | ||
backgroundColor: `grey.90`, | ||
borderBottom: `default`, | ||
paddingX: 6, | ||
paddingY: 5, | ||
}} | ||
> | ||
<Flex gap={5} alignItems="center"> | ||
<Text sx={{ color: `white` }}>Gatsby Admin</Text> | ||
{data && data.npmPackageJson && ( | ||
<div | ||
sx={{ | ||
width: `1px`, | ||
height: `16px`, | ||
backgroundColor: `grey.40`, | ||
}} | ||
/> | ||
)} | ||
{data && data.npmPackageJson && ( | ||
<Text sx={{ color: `teal.50` }}> | ||
{data.npmPackageJson.value.replace(/^"|"$/g, ``)} | ||
</Text> | ||
)} | ||
</Flex> | ||
<Flex alignItems="center"> | ||
<BaseAnchor | ||
href={`/`} | ||
target="_blank" | ||
sx={{ color: `whiteFade.60`, textDecoration: `none` }} | ||
> | ||
Visit site | ||
</BaseAnchor> | ||
</Flex> | ||
</Flex> | ||
) | ||
} | ||
|
||
export default Navbar |
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 |
---|---|---|
@@ -1,7 +1,63 @@ | ||
import React from "react" | ||
import { Provider } from "urql" | ||
import client from "../urql-client" | ||
import { Provider, Client } from "urql" | ||
import { ThemeProvider, getTheme } from "gatsby-interface" | ||
import { ThemeProvider as StrictUIProvider } from "strict-ui" | ||
import { createUrqlClient } from "../urql-client" | ||
|
||
export default ({ children }): React.ReactElement => ( | ||
<Provider value={client}>{children}</Provider> | ||
const baseTheme = getTheme() | ||
|
||
const theme = { | ||
...baseTheme, | ||
colors: { | ||
...baseTheme.colors, | ||
background: baseTheme.colors.grey[90], | ||
}, | ||
fontWeights: { | ||
...baseTheme.fontWeights, | ||
"500": 500, | ||
}, | ||
borders: { | ||
default: `1px solid ${baseTheme.colors.whiteFade[20]}`, | ||
}, | ||
sizes: { | ||
// NOTE(@mxstbr): Hacks around issues with strict-ui that I have to fix upstream eventually | ||
"1px": `1px`, | ||
"100%": `100%`, | ||
"16px": `16px`, | ||
initial: `initial`, | ||
}, | ||
} | ||
|
||
const GraphQLProvider: React.FC<{}> = ({ children }) => { | ||
const [status, setStatus] = React.useState(`loading`) | ||
const [client, setClient] = React.useState<Client | null>(null) | ||
|
||
React.useEffect(() => { | ||
setStatus(`loading`) | ||
fetch(`/___services`) | ||
.then(res => res.json()) | ||
.then(json => { | ||
setStatus(`idle`) | ||
if (json.recipesgraphqlserver) { | ||
setClient(createUrqlClient({ port: json.recipesgraphqlserver.port })) | ||
} | ||
}) | ||
}, []) | ||
|
||
if (status === `loading`) return <p>Loading...</p> | ||
|
||
if (client === null) | ||
return <p>It looks like no develop process is running.</p> | ||
|
||
return <Provider value={client}>{children}</Provider> | ||
} | ||
|
||
const Providers: React.FC<{}> = ({ children }) => ( | ||
<StrictUIProvider theme={theme}> | ||
<ThemeProvider theme={theme}> | ||
<GraphQLProvider>{children}</GraphQLProvider> | ||
</ThemeProvider> | ||
</StrictUIProvider> | ||
) | ||
|
||
export default Providers |
Oops, something went wrong.