Skip to content

Commit 01c6491

Browse files
axelbocmarcus-oscarsson
authored andcommitted
Update and improve front-end documentation
1 parent 592ee20 commit 01c6491

File tree

3 files changed

+66
-9
lines changed

3 files changed

+66
-9
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ a library called [SocketIO](https://socket.io/) is further used to provide
5151
a bidirectional communication channel between backend and client.
5252
The backend exposes a REST API to the client.
5353

54-
The client is implemented in ECMAScript6 and HTML5.
55-
React, Boostrap, and FabricJS are the main libraries used for the UI development.
54+
The UI is implemented in HTML, CSS and JavaScript, mainly with the React, Redux, Boostrap, and FabricJS libraries.
5655

5756
## Information for developers
5857

docs/source/dev/environment.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ _The output should look something like the following:_
159159

160160
#### 9.2. Running the front-end development server
161161

162-
The front end development server, webpack development server,
163-
listens for changes on the filesystem and builds (re-builds) the UI when a change is made.
162+
The front end development server, listens for changes on the filesystem and builds (re-builds) the UI when a change is made.
164163
This makes it very easy and fast to see how a change affects the UI and makes debugging much easier.
165164
The development server listens on port **5173**
166165

docs/source/dev/front-end.md

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,76 @@
11
# Front-end architecture
22

3-
## Environment variables
3+
## Tooling
44

5-
Environment variables are defined in file `ui/.env`. To override them, create your own local environment file as explained in the [Vite documentation](https://vitejs.dev/guide/env-and-mode.html#env-files) – e.g. `ui/.env.local` or `ui/.env.production.local`.
5+
The front-end package manager is [pnpm](https://pnpm.io/):
66

7-
The following environment variables are available:
7+
- `pnpm install` - install the dependencies, updating the lockfile as needed (except when the `CI` env var is defined)
8+
- `pnpm add [--save-dev] <pkg-name>` - [add a dependency](https://pnpm.io/cli/add)
9+
- `pnpm why <pkg-name>` - show why a package is present in `node_modules`
10+
- `pnpm up -L <pkg-name>` - update a package to the latest version
11+
- `pnpm outdated` - list outdated dependencies
12+
- `pnpm [run] <script> [--<arg>]` - run a script defined in `package.json`
13+
- `pnpm dlx <pkg-name>` - fetch a package from the registry and run its default
14+
command binary (equivalent to `npx <pkg-name>`)
815

9-
- `VITE_REDUX_LOGGER_ENABLED`: whether to log Redux actions to the browser console (disabled by default); useful if you're unable to install the [Redux devtools](https://github.com/reduxjs/redux-devtools/tree/main/extension#installation) browser extension.
16+
> You can run all `pnpm` commands above from the root of the repository with `pnpm --prefix ui <cmd>`.
17+
18+
[Vite](https://vitejs.dev/) is used to build the project for production:
19+
20+
- `pnpm start` - start the development server at http://localhost:5173
21+
- `pnpm build` - build the front-end for production into the `ui/build` folder
22+
- `pnpm preview` - serve the production build at http://localhost:5173
23+
24+
The codebase is formatted with Prettier, linted with ESLint and tested with Cypress:
25+
26+
- `pnpm prettier` - check formatting
27+
- `pnpm format` - fix formatting
28+
- `pnpm eslint` - check for linting errors
29+
- `pnpm fix` - fix linting errors
30+
- `pnpm cypress` - open Cypress testing UI
31+
- `pnpm e2e` - run Cypress E2E tests
32+
33+
### Editor integration
34+
35+
Most editors support fixing and formatting files automatically on save. The configuration for VSCode is provided out of the box, so all you need to do is install the recommended extensions.
36+
37+
## React & Bootstrap
38+
39+
The MXCuBE UI is developed in [React](https://react.dev/) with the [Bootstrap](https://getbootstrap.com/) UI toolkit (more specifically its React integration, [React Bootstrap](https://react-bootstrap.github.io/)).
40+
41+
While you'll still see a lot of class-based components in the codebase, please strive to use [function components](https://react.dev/learn#components) instead when implementing new features or refactoring existing code.
42+
43+
## State management
44+
45+
[Redux](https://redux.js.org/) is used to manage the app's global state and [React Redux](https://react-redux.js.org/) to subscribe React components to changes in the store.
46+
47+
The [Redux Style Guide](https://redux.js.org/style-guide/) contains some good advice on managing state with Redux. In particular:
48+
49+
- Be sure to not store state in Redux if it doesn't need to be globally available to all components. Prefer local React state (i.e. `useState`) and URL state instead, and prefer managing/retrieving state higher up the component hierarchy if it needs to be passed down to multiple components.
50+
- Do not store duplicated state, or state that can be computed from other state. Prefer creating your own custom React hooks instead (with `useSelector` + computation).
51+
52+
Additionally, please strive to connect to the Redux store using the React Redux [hooks API](https://react-redux.js.org/api/hooks) rather than the old `connect` API. Note that this may require converting class-based components to function components.
53+
54+
To debug state management issues, you can either install the [Redux devtools extension](https://github.com/reduxjs/redux-devtools/tree/main/extension#installation) or turn on [Redux logger](https://github.com/LogRocket/redux-logger) with the corresponding [environment variable](#environment-variables).
1055

1156
## Fetching layer
1257

1358
- For each back-end API called by the front-end, there is a file under `src/api/` named after that API (e.g. `beamline.js`, `login.js` ...)
1459
- For each endpoint, there is a function in the API's front-end file dedicated to making HTTP requests to that endpoint (e.g. `fetchLoginInfo`, `sendRunBeamlineAction` ...)
1560
- Functions that retrieve resources are named `fetch<Something>`.
1661
- Functions that perform actions are named `send<DoSomething>`.
17-
- Library [wretch](https://github.com/elbywan/wretch) is used for making HTTP requests; it is a thin wrapper around the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API>).
62+
- The [wretch](https://github.com/elbywan/wretch) library is used to make HTTP requests; it is a thin wrapper around the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API>).
63+
64+
## Styling
65+
66+
A significant amount of styling is provided by [Bootstrap](https://getbootstrap.com/). If you need to override these styles or write custom styles from scratch for a component, please use [CSS Modules](https://github.com/css-modules/css-modules).
67+
68+
Global styles should be avoided at all cost as they can conflict with one another and with Bootstrap's styles. They are also more difficult to maintain in the long run.
69+
70+
## Environment variables
71+
72+
Environment variables are defined in file `ui/.env`. To override them, create your own local environment file as explained in the [Vite documentation](https://vitejs.dev/guide/env-and-mode.html#env-files) – e.g. `ui/.env.local` or `ui/.env.production.local`.
73+
74+
The following environment variables are available:
75+
76+
- `VITE_REDUX_LOGGER_ENABLED`: whether to log Redux actions to the browser console (disabled by default); useful if you're unable to install the [Redux devtools](https://github.com/reduxjs/redux-devtools/tree/main/extension#installation) browser extension.

0 commit comments

Comments
 (0)