@@ -36,7 +36,7 @@ important ones:
36
36
fetching data
37
37
- [ XState] ( https://xstate.js.org/docs/ ) for handling complex state flows
38
38
- [ axios] ( https://github.com/axios/axios ) as fetching lib
39
- - [ Playwright] ( https://playwright.dev/ ) for E2E testing
39
+ - [ Playwright] ( https://playwright.dev/ ) for end-to-end ( E2E) testing
40
40
- [ Jest] ( https://jestjs.io/ ) for integration testing
41
41
- [ Storybook] ( https://storybook.js.org/ ) and
42
42
[ Chromatic] ( https://www.chromatic.com/ ) for visual testing
@@ -47,20 +47,19 @@ important ones:
47
47
All the code related to the UI is inside the ` site ` folder and we defined a few
48
48
conventions to help people to navigate through it.
49
49
50
- - ** e2e** - E2E tests
50
+ - ** e2e** - End-to-end ( E2E) tests
51
51
- ** src** - Source code
52
52
- ** mocks** - [ Manual mocks] ( https://jestjs.io/docs/manual-mocks ) used by Jest
53
53
- ** @types ** - Custom types for dependencies that don't have defined types
54
+ (largely code that has no server-side equivalent)
54
55
- ** api** - API code as function calls and types
55
56
- ** components** - UI components
56
57
- ** hooks** - Hooks that can be used across the application
57
- - ** i18n** - Translations
58
58
- ** pages** - Page components
59
59
- ** testHelpers** - Helper functions to help with integration tests
60
60
- ** util** - Helper functions that can be used across the application
61
- - ** xServices** - XState machines used to fetch data and handle complex
62
- scenarios
63
- - ** static** - UI static assets like images, fonts, icons, etc
61
+ - ** xServices** - XState machines used to handle complex state representations
62
+ - ** static** - Static UI assets like images, fonts, icons, etc
64
63
65
64
## Routing
66
65
@@ -88,10 +87,10 @@ to the view. We explain this decision a bit better in the next section.
88
87
89
88
### States
90
89
91
- A page usually has at least three states: ** loading** , ** ready** or ** success** ,
92
- and ** error** so remember to always handle these scenarios while you are coding
90
+ A page usually has at least three states: ** loading** , ** ready** / ** success** ,
91
+ and ** error** , so always remember to handle these scenarios while you are coding
93
92
a page. We also encourage you to add visual testing for these three states using
94
- the ` *.stories.ts ` file.
93
+ a ` *.stories.ts ` file.
95
94
96
95
## Fetching data
97
96
@@ -107,8 +106,8 @@ states and transitions.
107
106
108
107
### Where to fetch data
109
108
110
- Finding the right place to fetch data in React apps is the one million dollar
111
- question but we decided to make it only in the page components and pass the
109
+ Finding the right place to fetch data in React apps is the million- dollar
110
+ question, but we decided to make it only in the page components and pass the
112
111
props down to the views. This makes it easier to find where data is being loaded
113
112
and easy to test using Storybook. So you will see components like ` UsersPage `
114
113
and ` UsersPageView ` .
@@ -118,9 +117,9 @@ and `UsersPageView`.
118
117
We are using [ axios] ( https://github.com/axios/axios ) as our fetching library and
119
118
writing the API functions in the ` site/src/api/api.ts ` files. We also have
120
119
auto-generated types from our Go server on ` site/src/api/typesGenerated.ts ` .
121
- Usually, every endpoint has its own ` Request ` and ` Response ` types but
122
- sometimes you need to pass extra parameters to make the call like the example
123
- below:
120
+ Usually, every endpoint has its own ` Request ` and ` Response ` types, but
121
+ sometimes you need to pass extra parameters to make the call, like in the
122
+ example below:
124
123
125
124
``` ts
126
125
export const getAgentListeningPorts = async (
@@ -133,8 +132,8 @@ export const getAgentListeningPorts = async (
133
132
};
134
133
```
135
134
136
- Sometimes, a FE operation can have multiple API calls so it is ok to wrap it as
137
- a single function.
135
+ Sometimes, a frontend operation can have multiple API calls, so it is okay to
136
+ wrap it as a single function.
138
137
139
138
``` ts
140
139
export const updateWorkspaceVersion = async (
@@ -150,10 +149,11 @@ separated and use XState for that.
150
149
151
150
## Components
152
151
153
- We are using [ Material V4] ( https://v4.mui.com/ ) in our UI and we don't have any
154
- short-term plans to update or even replace it. It still provides good value for
155
- us and changing it would cost too much work which is not valuable right now but
156
- of course, it can change in the future.
152
+ The codebase is currently using MUI v5. Please see the
153
+ [ official documentation] ( https://mui.com/material-ui/getting-started/ ) . In
154
+ general, favor building a custom component via MUI instead of plain React/HTML,
155
+ as MUI's suite of components is thoroughly battle-tested and accessible right
156
+ out of the box.
157
157
158
158
### Structure
159
159
@@ -163,29 +163,56 @@ remain easy to navigate, healthy and maintainable for all contributors.
163
163
164
164
### Accessibility
165
165
166
- We strive to keep our UI accessible. When using colors, avoid adding new
167
- elements with low color contrast. Always use labels on inputs, not just
168
- placeholders. These are important for screen-readers.
166
+ We strive to keep our UI accessible.
167
+
168
+ In general, colors should come from the app theme, but if there is a need to add
169
+ a custom color, please ensure that the foreground and background have a minimum
170
+ contrast ratio of 4.5:1 to meet WCAG level AA compliance. WebAIM has
171
+ [ a great tool for checking your colors directly] ( https://webaim.org/resources/contrastchecker/ ) ,
172
+ but tools like
173
+ [ Dequeue's axe DevTools] ( https://chrome.google.com/webstore/detail/axe-devtools-web-accessib/lhdoppojpmngadmnindnejefpokejbdd )
174
+ can also do automated checks in certain situations.
175
+
176
+ When using any kind of input element, always make sure that there is a label
177
+ associated with that element (the label can be made invisible for aesthetic
178
+ reasons, but it should always be in the HTML markup). Labels are important for
179
+ screen-readers; a placeholder text value is not enough for all users.
180
+
181
+ When possible, make sure that all image/graphic elements have accompanying text
182
+ that describes the image. ` <img /> ` elements should have an ` alt ` text value. In
183
+ other situations, it might make sense to place invisible, descriptive text
184
+ inside the component itself using MUI's ` visuallyHidden ` utility function.
185
+
186
+ ``` tsx
187
+ import { visuallyHidden } from " @mui/utils" ;
188
+
189
+ <Button >
190
+ <GearIcon />
191
+ <Box component = " span" sx = { visuallyHidden } >
192
+ Settings
193
+ </Box >
194
+ </Button >;
195
+ ```
169
196
170
197
### Should I create a new component?
171
198
172
199
As with most things in the world, it depends. If you are creating a new
173
200
component to encapsulate some UI abstraction like ` UsersTable ` it is ok but you
174
201
should always try to use the base components that are provided by the library or
175
- from the codebase so I recommend you to always do a quick search before creating
176
- a custom primitive component like dialogs, popovers, buttons, etc.
202
+ from the codebase. It's recommended that you always do a quick search before
203
+ creating a custom primitive component like dialogs, popovers, buttons, etc.
177
204
178
205
## Testing
179
206
180
- We use three types of testing in our app: ** E2E** , ** Integration** and ** Visual
181
- Testing** .
207
+ We use three types of testing in our app: ** End-to-end ( E2E) ** , ** Integration**
208
+ and ** Visual Testing** .
182
209
183
- ### E2E (end -to-end )
210
+ ### End -to-End (E2E )
184
211
185
- Are useful to test complete flows like "Create a user", "Import template", etc.
186
- For this one, we use [ Playwright] ( https://playwright.dev/ ) . If you only need to
187
- test if the page is being rendered correctly, you should probably consider using
188
- the ** Visual Testing** approach.
212
+ These are useful for testing complete flows like "Create a user", "Import
213
+ template", etc. We use [ Playwright] ( https://playwright.dev/ ) . If you only need
214
+ to test if the page is being rendered correctly, you should consider using the
215
+ ** Visual Testing** approach.
189
216
190
217
> ℹ️ For scenarios where you need to be authenticated, you can use
191
218
> ` test.use({ storageState: getStatePath("authState") }) ` .
0 commit comments