Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7646000

Browse files
jsjoeiobpmct
andauthored
feat: add open in coder docs, fix missing templates (#4124)
* docs: add open in coder This adds new documentation for the "Open in Coder" button that admins can use to get their developers up and running faster. * fix: display error if template not found Previously, we weren't handling a case where we tried to get a template that returned a 404 from the backend. Now we handle that case in our state machine and display the error message from the API on the frontend. * feat: support template query param in index This adds support to navigate directly to a template from the index by using the `?template=<name>` query param. * Revert "feat: support template query param in index" This reverts commit bad7ffb. We decided to use the `/template/path` route instead. * fixup!: docs: add open in coder * docs: add open in coder to dogfood readme * Update docs/admin/open-in-coder.md Co-authored-by: Ben Potter <[email protected]> * Update docs/admin/open-in-coder.md Co-authored-by: Ben Potter <[email protected]> * Update docs/admin/open-in-coder.md Co-authored-by: Ben Potter <[email protected]>
1 parent 7ad4276 commit 7646000

File tree

5 files changed

+68
-0
lines changed

5 files changed

+68
-0
lines changed

docs/admin/open-in-coder.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Open in Coder Button
2+
3+
Add a Markdown button to your project's `README.md` to get your developers up and running with Coder with a few clicks.
4+
5+
A basic example looks like this:
6+
7+
```markdown
8+
[![Open in Coder](https://cdn.coder.com/embed-button.svg)](https://<deployment-url>/templates/<template-name>)
9+
```
10+
11+
which renders like this:
12+
13+
![Open in Coder](https://cdn.coder.com/embed-button.svg)
14+
15+
You can customize this to take developers directly to your team's template. Read on to learn more.
16+
17+
### Customization
18+
19+
The underlying link for this button consists of the following pieces:
20+
- <deployment-url>: where your Coder deployment lives i.e. https://dev.coder.com
21+
- <template-name>: name of template i.e. coder
22+
23+
### template name
24+
25+
A template to redirect your developers to after they authenticate on your deployment.
26+
27+
Example: https://dev.coder.com/templates/coder

docs/manifest.json

+5
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@
188188
"title": "Enterprise",
189189
"description": "Learn how to enable Enterprise features.",
190190
"path": "./admin/enterprise.md"
191+
},
192+
{
193+
"title": "Open in Coder Button",
194+
"description": "Learn how to create an 'Open in Coder' button.",
195+
"path": "./admin/open-in-coder.md"
191196
}
192197
]
193198
},

dogfood/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# dogfood template
22

3+
[![Open in Coder](https://cdn.coder.com/embed-button.svg)](https://dev.coder.com/templates/coder)
4+
35
Ammar is this template's admin.
46

57
## Personalization

site/src/pages/TemplatePage/TemplatePage.tsx

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import { makeStyles } from "@material-ui/core/styles"
12
import { useMachine, useSelector } from "@xstate/react"
23
import { DeleteDialog } from "components/Dialogs/DeleteDialog/DeleteDialog"
4+
import { ErrorSummary } from "components/ErrorSummary/ErrorSummary"
5+
import { Margins } from "components/Margins/Margins"
36
import { FC, useContext } from "react"
47
import { Helmet } from "react-helmet-async"
58
import { Navigate, useParams } from "react-router-dom"
@@ -22,6 +25,7 @@ const useTemplateName = () => {
2225
}
2326

2427
export const TemplatePage: FC<React.PropsWithChildren<unknown>> = () => {
28+
const styles = useStyles()
2529
const organizationId = useOrganizationId()
2630
const templateName = useTemplateName()
2731
const [templateState, templateSend] = useMachine(templateMachine, {
@@ -38,6 +42,7 @@ export const TemplatePage: FC<React.PropsWithChildren<unknown>> = () => {
3842
templateVersions,
3943
deleteTemplateError,
4044
templateDAUs,
45+
getTemplateError,
4146
} = templateState.context
4247
const xServices = useContext(XServiceContext)
4348
const permissions = useSelector(xServices.authXService, selectPermissions)
@@ -48,6 +53,16 @@ export const TemplatePage: FC<React.PropsWithChildren<unknown>> = () => {
4853
templateSend("DELETE")
4954
}
5055

56+
if (templateState.matches("error") && Boolean(getTemplateError)) {
57+
return (
58+
<Margins>
59+
<div className={styles.errorBox}>
60+
<ErrorSummary error={getTemplateError} />
61+
</div>
62+
</Margins>
63+
)
64+
}
65+
5166
if (isLoading) {
5267
return <Loader />
5368
}
@@ -88,4 +103,10 @@ export const TemplatePage: FC<React.PropsWithChildren<unknown>> = () => {
88103
)
89104
}
90105

106+
const useStyles = makeStyles((theme) => ({
107+
errorBox: {
108+
padding: theme.spacing(3),
109+
},
110+
}))
111+
91112
export default TemplatePage

site/src/xServices/template/templateXService.ts

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface TemplateContext {
2525
templateVersions?: TemplateVersion[]
2626
templateDAUs: TemplateDAUsResponse
2727
deleteTemplateError?: Error | unknown
28+
getTemplateError?: Error | unknown
2829
}
2930

3031
type TemplateEvent = { type: "DELETE" } | { type: "CONFIRM_DELETE" } | { type: "CANCEL_DELETE" }
@@ -71,6 +72,12 @@ export const templateMachine =
7172
target: "initialInfo",
7273
},
7374
],
75+
onError: [
76+
{
77+
actions: "assignGetTemplateError",
78+
target: "error",
79+
},
80+
],
7481
},
7582
},
7683
initialInfo: {
@@ -211,6 +218,9 @@ export const templateMachine =
211218
deleted: {
212219
type: "final",
213220
},
221+
error: {
222+
type: "final",
223+
},
214224
},
215225
},
216226
{
@@ -257,6 +267,9 @@ export const templateMachine =
257267
assignActiveTemplateVersion: assign({
258268
activeTemplateVersion: (_, event) => event.data,
259269
}),
270+
assignGetTemplateError: assign({
271+
getTemplateError: (_, event) => event.data,
272+
}),
260273
assignTemplateResources: assign({
261274
templateResources: (_, event) => event.data,
262275
}),

0 commit comments

Comments
 (0)