You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: clean up and consolidate config values in codebase (#29)
* fix: fix hover behavior for last list item
* fix: shrink default max height for container
* fix: ensure divider bar appears when there is overflow
* refactor: add workspaceCreationLink prop to context provider
* refactor: split Placeholder into separate component
* chore: finish cta button
* fix: make sure button only appears when loading is finished
* docs: remove bad comment
* chore: add explicit return type to useCoderAppConfig for clarity
* refactor: consolidate and decouple type definitions
* refactor: move dynamic entity config logic
* refactor: update references for workspaces config
* refactor: centralize creationUrl logic
* refactor: rename useCoderEntityConfig to useCoderWorkspacesConfig
* refactor: rename old useCoderWorkspaces to useCoderWorkspacesQuery
* fix: update typo in test case
* fix: update test logic to account for creationUrl
* fix: update query logic to account for always-defined workspacesConfig
* docs: fix typo in comment
* refactor: clean up how mock data is defined
* fix: make logic for showing reminder more airtight
* refactor: split DataReminder into separate file
* refactor: simplify API for useCoderWorkspacesQuery
* fix: make sure data reminder only shows when appropriate
* fix: delete stale DataReminder file
* docs: update type definitions
* docs: update hook/type docs to reflect new APIs
* docs: fix typo
* chore: try removing react-use dependency to make CI happy
[Type definition for `CoderEntityConfig`](./types.md#coderentityconfig)
27
+
[Type definition for `CoderWorkspacesConfig`](./types.md#coderWorkspacesconfig)
22
28
23
29
### Example usage
24
30
25
31
```tsx
26
32
function YourComponent() {
27
-
const config =useCoderEntityConfig();
33
+
const config =useCoderWorkspacesConfig();
28
34
return <p>Your repo URL is {config.repoUrl}</p>;
29
35
}
30
36
@@ -52,50 +58,46 @@ const serviceEntityPage = (
52
58
### Throws
53
59
54
60
- Will throw an error if called outside a React component
55
-
- Will throw an error if called outside an `EntityLayout` (or any other Backstage component that exposes `Entity` data via React Context)
61
+
- Will throw if the value of the `readEntityData` property input changes across re-renders
56
62
57
63
### Notes
58
64
59
-
- The type definition for `CoderEntityConfig`[can be found here](./types.md#coderentityconfig). That section also includes info on the heuristic used for compiling the data
65
+
- The type definition for `CoderWorkspacesConfig`[can be found here](./types.md#coderworkspacesconfig). That section also includes info on the heuristic used for compiling the data
66
+
- The value of `readEntityData` determines the "mode" that the workspace operates in. If the value is `false`/`undefined`, the component will act as a general list of workspaces that isn't aware of Backstage APIs. If the value is `true`, the hook will also read Backstage data during the compilation step.
60
67
- The hook tries to ensure that the returned value maintains a stable memory reference as much as possible, if you ever need to use that value in other React hooks that use dependency arrays (e.g., `useEffect`, `useCallback`)
61
68
62
-
## `useCoderWorkspaces`
69
+
## `useCoderWorkspacesQuery`
63
70
64
71
This hook gives you access to all workspaces that match a given query string. If
65
-
[`repoConfig`](#usecoderentityconfig) is defined via `options`, the workspaces returned will be filtered down further to only those that match the the repo.
72
+
[`workspacesConfig`](#usecoderworkspacesconfig) is defined via `options`, and that config has a defined `repoUrl`, the workspaces returned will be filtered down further to only those that match the the repo.
1. The user is not currently authenticated (We recommend wrapping your component inside [`CoderAuthWrapper`](./components.md#coderauthwrapper) to make these checks easier)
129
131
2. If `repoConfig` is passed in via `options`: when the value of `coderQuery` is an empty string
130
-
-`CoderEntityConfig` is the return type of [`useCoderEntityConfig`](#usecoderentityconfig)
132
+
- The `workspacesConfig` property is the return type of [`useCoderWorkspacesConfig`](#usecoderworkspacesconfig)
133
+
- The only way to get automatically-filtered results is by (1) passing in a workspaces config value, and (2) ensuring that config has a `repoUrl` property of type string (it can sometimes be `undefined`, depending on built-in Backstage APIs).
131
134
132
135
## `useWorkspacesCardContext`
133
136
@@ -140,8 +143,8 @@ type WorkspacesCardContext = Readonly<{
@@ -57,22 +57,23 @@ See example for [`CoderProvider`](./components.md#coderprovider)
57
57
-`templateName` refers to the name of the Coder template that you wish to use as default for creating workspaces
58
58
- If `mode` is not specified, the plugin will default to a value of `manual`
59
59
-`repoUrlParamKeys` is defined as a non-empty array – there must be at least one element inside it.
60
-
- For more info on how this type is used within the plugin, see [`CoderEntityConfig`](./types.md#coderentityconfig) and [`useCoderEntityConfig`](./hooks.md#usecoderentityconfig)
60
+
- For more info on how this type is used within the plugin, see [`CoderWorkspacesConfig`](./types.md#coderworkspacesconfig) and [`useCoderWorkspacesConfig`](./hooks.md#usecoderworkspacesconfig)
61
61
62
-
## `CoderEntityConfig`
62
+
## `CoderWorkspacesConfig`
63
63
64
-
Represents the result of compiling Coder plugin configuration data. All data will be compiled from the following sources:
64
+
Represents the result of compiling Coder plugin configuration data. The main source for this type is [`useCoderWorkspacesConfig`](./hooks.md#usecoderworkspacesconfig). All data will be compiled from the following sources:
65
65
66
-
1. The [`CoderAppConfig`](#coderappconfig) passed to [`CoderProvider`](./components.md#coderprovider)
66
+
1. The [`CoderAppConfig`](#coderappconfig) passed to [`CoderProvider`](./components.md#coderprovider). This acts as the "baseline" set of values.
67
67
2. The entity-specific fields for a given repo's `catalog-info.yaml` file
68
68
3. The entity's location metadata (corresponding to the repo)
3. Go through all properties parsed from `catalog-info.yaml` and inject those. If the properties are already defined, overwrite them
147
153
4. Grab the repo URL from the entity's location fields.
148
154
5. For each key in `CoderAppConfig`'s `workspaces.repoUrlParamKeys` property, take that key, and inject it as a key-value pair, using the URL as the value. If the key already exists, always override it with the URL
155
+
6. Use the Coder access URL and the properties defined during the previous steps to create the URL for creating new workspaces, and then inject that.
0 commit comments