Skip to content

Commit c7218b4

Browse files
authored
docs: update frontend contribution docs (#10028)
* docs: update frontend contribution docs * fix: update docs formatting
1 parent 4ab5276 commit c7218b4

File tree

1 file changed

+59
-32
lines changed

1 file changed

+59
-32
lines changed

docs/contributing/frontend.md

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ important ones:
3636
fetching data
3737
- [XState](https://xstate.js.org/docs/) for handling complex state flows
3838
- [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
4040
- [Jest](https://jestjs.io/) for integration testing
4141
- [Storybook](https://storybook.js.org/) and
4242
[Chromatic](https://www.chromatic.com/) for visual testing
@@ -47,20 +47,19 @@ important ones:
4747
All the code related to the UI is inside the `site` folder and we defined a few
4848
conventions to help people to navigate through it.
4949

50-
- **e2e** - E2E tests
50+
- **e2e** - End-to-end (E2E) tests
5151
- **src** - Source code
5252
- **mocks** - [Manual mocks](https://jestjs.io/docs/manual-mocks) used by Jest
5353
- **@types** - Custom types for dependencies that don't have defined types
54+
(largely code that has no server-side equivalent)
5455
- **api** - API code as function calls and types
5556
- **components** - UI components
5657
- **hooks** - Hooks that can be used across the application
57-
- **i18n** - Translations
5858
- **pages** - Page components
5959
- **testHelpers** - Helper functions to help with integration tests
6060
- **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
6463

6564
## Routing
6665

@@ -88,10 +87,10 @@ to the view. We explain this decision a bit better in the next section.
8887
8988
### States
9089

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
9392
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.
9594

9695
## Fetching data
9796

@@ -107,8 +106,8 @@ states and transitions.
107106
108107
### Where to fetch data
109108

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
112111
props down to the views. This makes it easier to find where data is being loaded
113112
and easy to test using Storybook. So you will see components like `UsersPage`
114113
and `UsersPageView`.
@@ -118,9 +117,9 @@ and `UsersPageView`.
118117
We are using [axios](https://github.com/axios/axios) as our fetching library and
119118
writing the API functions in the `site/src/api/api.ts` files. We also have
120119
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:
124123

125124
```ts
126125
export const getAgentListeningPorts = async (
@@ -133,8 +132,8 @@ export const getAgentListeningPorts = async (
133132
};
134133
```
135134

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.
138137

139138
```ts
140139
export const updateWorkspaceVersion = async (
@@ -150,10 +149,11 @@ separated and use XState for that.
150149

151150
## Components
152151

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.
157157

158158
### Structure
159159

@@ -163,29 +163,56 @@ remain easy to navigate, healthy and maintainable for all contributors.
163163

164164
### Accessibility
165165

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+
```
169196

170197
### Should I create a new component?
171198

172199
As with most things in the world, it depends. If you are creating a new
173200
component to encapsulate some UI abstraction like `UsersTable` it is ok but you
174201
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.
177204

178205
## Testing
179206

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**.
182209

183-
### E2E (end-to-end)
210+
### End-to-End (E2E)
184211

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.
189216

190217
> ℹ️ For scenarios where you need to be authenticated, you can use
191218
> `test.use({ storageState: getStatePath("authState") })`.

0 commit comments

Comments
 (0)