Skip to content

Commit 592ee20

Browse files
axelbocmarcus-oscarsson
authored andcommitted
Allow enabling redux-logger via env var
1 parent 0b27870 commit 592ee20

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

docs/source/dev/front-end.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Front-end architecture
22

3+
## Environment variables
4+
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`.
6+
7+
The following environment variables are available:
8+
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.
10+
311
## Fetching layer
412

513
- 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` ...)

ui/.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#####
2+
# UI ENVIRONMENT VARIABLEs
3+
# Copy and configure the variables below in your own `.env.local` or `.env.[mode].local` file
4+
# https://vitejs.dev/guide/env-and-mode.html#env-files
5+
#####
6+
7+
# Redux logger ('true' to enable)
8+
VITE_REDUX_LOGGER_ENABLED=

ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"react-zoom-pan-pinch": "3.3.0",
5353
"redux": "4.1.2",
5454
"redux-form": "^8.3.8",
55+
"redux-logger": "3.0.6",
5556
"redux-thunk": "^2.4.1",
5657
"slick-carousel": "^1.8.1",
5758
"socket.io-client": "^4.6.1",

ui/pnpm-lock.yaml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/src/store.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
import { createStore, applyMiddleware } from 'redux';
2+
import { createLogger } from 'redux-logger';
23
import thunk from 'redux-thunk';
34
import rootReducer from './reducers';
45
import { composeWithDevTools } from '@redux-devtools/extension';
56

7+
const middleware = [
8+
thunk,
9+
...(import.meta.env.VITE_REDUX_LOGGER_ENABLED === 'true'
10+
? [createLogger()]
11+
: []),
12+
];
13+
614
export const store = createStore(
715
rootReducer,
8-
composeWithDevTools(applyMiddleware(thunk)),
16+
composeWithDevTools(applyMiddleware(...middleware)),
917
);
1018

1119
// Enable Hot Module Replacement for reducers

0 commit comments

Comments
 (0)