8000 docs: add API documentation for Coder plugin by Parkreiner · Pull Request #15 · coder/backstage-plugins · GitHub
[go: up one dir, main page]

Skip to content

docs: add API documentation for Coder plugin #15

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

Merged
merged 36 commits into from
Mar 11, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7153251
docs: finish drafts for hooks/types README files
Parkreiner Mar 4, 2024
6d67225
wip: add stub for components README
Parkreiner Mar 4, 2024
be54ee6
fix: remove typo in main docs
Parkreiner Mar 4, 2024
cb0d816
wip: add stub for component docs
Parkreiner Mar 4, 2024
d0fa96c
wip: add outline for component documentation
Parkreiner Mar 4, 2024
aead300
docs: add documentation for CoderAuthWrapper and CoderErrorBoundary
Parkreiner Mar 5, 2024
d37ae30
docs: finish up section for CoderProvider
Parkreiner Mar 5, 2024
5fed31e
fix: update typo in library name
Parkreiner Mar 5, 2024
89fde98
docs: finish section for CoderAppConfig
Parkreiner Mar 5, 2024
06963f7
fix: export useWorkspacesCardContext
Parkreiner Mar 5, 2024
a2e2e4b
docs: finish section for useWorkspacesCardContext
Parkreiner Mar 5, 2024
c89d7ad
wip: add stubs for CoderWorkspacesCard
Parkreiner Mar 5, 2024
e4d5e0a
fix: update link in main directory README
Parkreiner Mar 5, 2024
3f8c852
docs: add more info to component docs
Parkreiner Mar 6, 2024
4a31ac6
fix: ensure link configs are combined properly
Parkreiner Mar 6, 2024
93bb583
docs: finish docs for CreateWorkspacesLink
Parkreiner Mar 6, 2024
833ad2d
docs: finish section for ExtraActionsButton
Parkreiner Mar 6, 2024
cbca5fb
docs: finish section for HeaderRow
Parkreiner Mar 6, 2024
21f06eb
docs: finish Root
Parkreiner Mar 6, 2024
f3a8dae
docs: finish section for SearchBox
Parkreiner Mar 6, 2024
88bd95d
docs: finish rough draft of API docs
Parkreiner Mar 7, 2024
cfe2c4d
Merge branch 'main' into mes/coder-api-docs
Parkreiner Mar 7, 2024
605b2b9
fix: fill in missing section for CoderProvider
Parkreiner Mar 7, 2024
d5a46af
chore: move API docs up one level
Parkreiner Mar 7, 2024
abfcf0f
docs: fill in link for TODO comment
Parkreiner Mar 7, 2024
799132c
fix: reword docs message for clarity
Parkreiner Mar 7, 2024
8085717
Update plugins/backstage-plugin-coder/docs/README.md
Parkreiner Mar 7, 2024
54c65c2
fix: update version for Coder plugin
Parkreiner Mar 7, 2024
4511773
Merge branch 'mes/coder-api-docs' of github.com:coder/backstage-plugi…
Parkreiner Mar 7, 2024
dd56f00
docs: add info about useCoderEntityConfig
Parkreiner Mar 7, 2024
a899bad
fix: make sure all exported components have unique name values
Parkreiner Mar 8, 2024
af5e67a
fix: make sure all values are properly exported at top-level plugin root
Parkreiner Mar 8, 2024
6d67468
Merge branch 'main' into mes/coder-api-docs
Parkreiner Mar 8, 2024
3a09f9c
fix: remove forwardRef from exported sub-components
Parkreiner Mar 8, 2024
f99a1a4
fix: remove forwardRef from Root
Parkreiner Mar 8, 2024
63a71e8
Merge branch 'main' into mes/coder-api-docs
Parkreiner Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add documentation for CoderAuthWrapper and CoderErrorBoundary
  • Loading branch information
Parkreiner committed Mar 5, 2024
commit aead3007c20467776164df1b30f17b475d38ef84
96 changes: 96 additions & 0 deletions plugins/backstage-plugin-coder/docs/api-reference/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,104 @@ This is the main documentation page for the Coder plugin's React components.

## `CoderAuthWrapper`

This component is designed to simplify authentication checks for other components that need to be authenticated with Coder. Place any child component inside the wrapper. If the user is authenticated, they will see the children. Otherwise, they will see a form for authenticating themselves.

### Type signature

```tsx
type WrapperProps = Readonly<
PropsWithChildren<{
type: 'card';
}>
>;

declare function CoderAuthWrapper(props: WrapperProps): JSX.Element;
```

### Sample usage

```tsx
function YourComponent() {
// This query requires authentication
const query = useCoderWorkspaces('owner:lil-brudder');
return <p>{query.isLoading ? 'Loading' : 'Not loading'}</p>;
}

<CoderProvider appConfig={yourAppConfig}>
<CoderAuthWrapper>
<YourComponent />
</CoderAuthWrapper>
</CoderProvider>;
```

### Throws

- Throws a render error if this component mounts outside of `CoderProvider`

### Notes

- The wrapper will also stop displaying the child component(s) if the auth token expires, or if the token cannot be safely verified. If that happens, the component will also display some form controls for troubleshooting.
- `CoderAuthWrapper` only supports the `card` type for now, but more types will be added as we add more UI components to the library

## `CoderErrorBoundary`

Provides an error boundary for catching render errors thrown by Coder's custom hooks (e.g., parsing logic).

### Type signature

```tsx
type CoderErrorBoundaryProps = {
children?: ReactNode;
fallbackUi?: ReactNode;
};

declare function CoderErrorBoundary(
props: CoderErrorBoundaryProps,
): JSX.Element;
```

### Sample usage

```tsx
function YourComponent() {
// Pretend that there is an issue with this hook, and that it will always
// throw an error
const config = useCoderEntityConfig();
return <p>Will never reach this code</p>;
}

<CoderErrorBoundary>
<YourComponent />
</CoderErrorBoundary>;
```

### Throws

- Does not throw
- (Need to verify this - our own code for this component doesn't throw any errors, but it does rely on Backstage's `useApi` hook. Unfortunately, TypeScript type signatures can't communicate whether they throw errors, and the documentation has no info. Will need to go through the source code)

### Notes

- All other Coder components are exported with this component wrapped around them. Unless you are making extension use of the plugin's custom hooks, it is not expected that you will need this component.
- If `fallbackUi` is not specified, `CoderErrorBoundary` will default to a simple error message
- Although Backstage automatically places error boundaries around each exported component, `CoderErrorBoundary` is designed to handle and process specific kinds of errors from the Coder plugins.

## `CoderProvider`

### Type signature

### Sample usage

### Throws

### Notes

## `CoderWorkspacesCard`

### Type signature

### Sample usage

### Throws

### Notes
0