Skip to content

Commit 797e373

Browse files
committed
extract feature toggles to its own file + document usage in README
1 parent cbf8999 commit 797e373

File tree

4 files changed

+69
-6
lines changed

4 files changed

+69
-6
lines changed

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,65 @@
33
[![CircleCI](https://circleci.com/gh/saljuama/codebar-pairing-tool.svg?style=svg)](https://circleci.com/gh/saljuama/codebar-pairing-tool)
44

55
See it in action: https://saljuama.github.io/codebar-pairing-tool
6+
7+
## Development
8+
9+
### Running the application locally
10+
11+
```bash
12+
$ yarn start
13+
```
14+
15+
### Running the tests
16+
17+
#### Unit tests
18+
19+
```bash
20+
$ yarn test
21+
```
22+
23+
#### Functional tests
24+
25+
This requires that the application is running locally
26+
27+
```bash
28+
$ yarn test:e2e
29+
```
30+
31+
### Working with Feature Toggles
32+
33+
If we wanted to create a new toggle named `myToggle` with a default value of `false`, we would:
34+
35+
#### Adding a new toggle
36+
Add the name, and the default value in the `src/config/featureToggles.js` file.
37+
```javascript
38+
export const featureToggles = {
39+
myToggle: false
40+
}
41+
```
42+
43+
It is recommended to create new toggles with a default value of `false` so new features developed under them are not
44+
available to the users right away until the features are ready for it
45+
46+
#### Accessing the value of a feature toggle
47+
```javascript
48+
import {useSelector} from 'react-redux'
49+
import {featureEnabled} from '..path-to-config-folder../config/togglesSlice'
50+
51+
const AnyComponent = () => {
52+
const myToggleValue = useSelector(featureEnabled('myToggle')) // false
53+
// rest of the component
54+
}
55+
```
56+
57+
#### Overriding a toggle value
58+
With the querystring parameters:
59+
* Local: after `yarn start` we can visit `http://localhost:3000?myToggle=true`
60+
* In GH pages: visit `https://saljuama.github.io/codebar-pairing-tool?myToggle=true`
61+
62+
#### Releasing and cleaning up
63+
To release a feature, or a change, hidden under a feature toggle, just go to the `src/config/featureToggles.js` file and
64+
change the value to `true`.
65+
66+
Once is verified that the feature is stable, and we will not need to turn the toggle off, we can start cleaning up the
67+
source code to remove the toggle usages and remove the toggle from the `src/config/featureToggles.js` file itself.

src/config/featureToggles.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const featureToggles = {
2+
csvFileDropzoneWithDnd: false
3+
}

src/config/store.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {configureStore} from '@reduxjs/toolkit'
2-
import {togglesReducer, initialState as toggles} from './togglesSlice'
2+
import {togglesReducer} from './togglesSlice'
33
import {configurationReducer, initialState as configuration} from '../app/configuration/configurationSlice'
44
import {attendeesReducer, initialState as attendees} from '../app/pairingTool/attendees/attendeesSlice'
55
import {pairingsReducer, initialState as pairings} from '../app/pairingTool/pairings/pairingsSlice'
6+
import {featureToggles as toggles} from './featureToggles'
67

78
export const storeInitialState = {
89
toggles,

src/config/togglesSlice.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import {createSlice} from '@reduxjs/toolkit'
2-
3-
export const initialState = {
4-
csvFileDropzoneWithDnd: false
5-
}
2+
import {featureToggles} from './featureToggles'
63

74
const togglesSlice = createSlice({
85
name: 'toggles',
9-
initialState,
6+
initialState: featureToggles,
107
reducers: {
118
overrideToggle: (state, action) => {
129
if (action.payload.toggle in state)

0 commit comments

Comments
 (0)