Skip to content

chore(Coder plugin): Create guide for working with the Coder SDK #133

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 112 commits into from
Jun 17, 2024

Conversation

Parkreiner
Copy link
Member

@Parkreiner Parkreiner commented May 31, 2024

Closes #112

Changes made

  • Added guide

Things left to do

  • Add images/video to designated areas of the draft
  • Add link to the guide from the main README

Notes

  • Might be helpful to view the README in the actual repo view
  • I updated a couple of the other pending PRs as I was writing this out
    • There's a couple of things I'm realizing could be improved with the final design, but I'm going to make a note of them, and come back once we have more customer interest

Parkreiner added 30 commits May 24, 2024 14:58
@Parkreiner Parkreiner marked this pull request as ready for review June 11, 2024 16:37
@Parkreiner Parkreiner requested a review from Kira-Pilot June 11, 2024 16:37
@Parkreiner
Copy link
Member Author

@Kira-Pilot Updated the READMEs: there's two main files now:

There are a lot more files changed compared to before, but they're all basically file/property renames/reorganization to make things more clear

Can you let me know if the new READMEs feel a bit more scrutible?

1. If querying data, prefer `useCoderQuery`. It automatically wires up all auth logic to React Query (which includes pausing queries if the user is not authenticated). It also lets you access the Coder API via its query function. `useQuery` is also a good escape hatch if `useCoderQuery` doesn't meet your needs, but it requires more work to wire up correctly.
2. If mutating data, you will need to call `useMutation`, `useQueryClient`, and `useCoderApi` in tandem\*. The plugin exposes a `CODER_QUERY_KEY_PREFIX` constant that you can use to group all Coder queries together.

We highly recommend **not** fetching with `useState` + `useEffect`, or with `useAsync`. Both face performance issues when trying to share state. See [ui.dev](https://www.ui.dev/)'s wonderful [_The Story of React Query_ video](https://www.youtube.com/watch?v=OrliU0e09io) for more info on some of the problems they face.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason we have to include this disclaimer? Seems like general React knowledge, rather than Coder plugin specific knowledge.

Copy link
Member Author

@Parkreiner Parkreiner Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree in principle, but considering that part of the reason why I brought in RQ in the first place was to fight some of Backstage's design decisions, I'm not sure if infrastructure engineers who are trying to get their React UI working would be aware of the issues. Especially since it's going against Backstage's official recommendations

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense! Could we just move it after the meat of the examples then?

Copy link
Member Author

@Parkreiner Parkreiner Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I would expect a good chunk of plugin users not to be super seasoned with React. So I'm not sure if we want to get rid of the disclaimer, or if it'd be better to reword it

Comment on lines 23 to 25
- `useQuery` - Query and cache data
- `useMutation` - Perform mutations on an API resource
- `useQueryClient` - Coordinate queries and mutations
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like basic use cases for fetching don't need these RQ hooks but they're the first thing we talk about.
WDYT about moving your example code snippets up to the top here alongside your hook explanations so users can immediately see how they might use what you've built?

This could look something like:

### Available hooks
We've exposed a few hooks to get you started building your own Coder components: 

- `useCoderApi` - Exposes an object with all available Coder API methods. For the most part, there is no exposed state on this object; you can consider it a "function bucket".
- `useCoderAuth` - Provides methods and state values for interacting with your current Coder auth session from within Backstage.
- `useCoderQuery` - a convenience hook that simplifies wiring up `useQuery`, `useCoderApi`, and `useCoderAuth`.

// Query Example:


// Mutation Example:

Note that we use [React Query/TanStack Query v4](https://tanstack.com/query/v4/docs/framework/react/overview) in the above examples. When querying, RQ's `useQuery` hook is also a good escape hatch if `useCoderQuery` doesn't meet your needs, but it requires more work to wire up correctly. 
The plugin exposes a `CODER_QUERY_KEY_PREFIX` constant that you can use to group all Coder queries together; read more here(link to your query constant section).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I see what you mean. I went ahead and reorganized the hooks section, and added some bite-sized examples

</CoderProvider>;
```

### Grouping queries with the Coder query key prefix
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we move this up so its closer to the hook section

@Parkreiner
Copy link
Member Author

@Kira-Pilot Third time's the charm?

@@ -1,11 +1,18 @@
# Plugin API Reference – Coder for Backstage

For users who need more information about how to extend and modify the Coder plugin. For general setup, please see our main [README](../README.md).
The Coder plugin for Backstage does follow semantic versioning.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an important sentence, but should not necessarily be the first sentence of this doc. Can we change it to something that explains what the reader will learn from reading this doc? e.g.

Learn how to build custom Backstage functions and components that use the Coder API

Copy link
Member

@Kira-Pilot Kira-Pilot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I can see everything I need right up top and there's a great level of detail if I dig in.

@Parkreiner Parkreiner merged commit 80d6858 into main Jun 17, 2024
2 checks passed
@Parkreiner Parkreiner deleted the mes/vendored-sdk-readme branch June 17, 2024 19:50
@bioerrorlog bioerrorlog mentioned this pull request Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Coder plugin: Add documentation for helping users cache state from CoderClient API calls
4 participants