Skip to content

Commit 11692e6

Browse files
beeme1mrtoddbaert
andauthored
docs: add flag definition playground (#1084)
Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com> Signed-off-by: Todd Baert <todd.baert@dynatrace.com> Co-authored-by: Todd Baert <todd.baert@dynatrace.com>
1 parent a690d3b commit 11692e6

32 files changed

+7054
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ core-coverage.out
1212
go.work
1313
go.work.sum
1414
bin/
15+
node_modules/
1516

1617
# built documentation
1718
site

.markdownlint-cli2.yaml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ config:
1616

1717
ignores:
1818
- "**/CHANGELOG.md"
19+
- ".venv"
1920
- "node_modules"
21+
- "playground-app/node_modules"
2022
- "tmp"
21-
- "**/protos.md" # auto-generated
22-
- "schemas" # submodule
23-
- "spec" # submodule
24-
- "test-harness" # submodule
23+
- "**/protos.md" # auto-generated
24+
- "docs/playground" # auto-generated
25+
- "schemas" # submodule
26+
- "spec" # submodule
27+
- "test-harness" # submodule

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18

Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,22 @@ generate-proto-docs: pull-schemas-submodule
123123

124124
.PHONY: run-web-docs
125125
run-web-docs: generate-docs generate-proto-docs
126-
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material
126+
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs squidfunk/mkdocs-material
127+
128+
# Run the playground app in dev mode
129+
# See the readme in the playground-app folder for more details
130+
.PHONY: playground-dev
131+
playground-dev:
132+
cd playground-app && npm ci && npm run dev
133+
134+
# Build the playground app
135+
# See the readme in the playground-app folder for more details
136+
.PHONY: playground-build
137+
playground-build:
138+
cd playground-app && npm ci && npm run build
139+
140+
# Publish the playground app to the docs folder
141+
# See the readme in the playground-app folder for more details
142+
.PHONY: playground-publish
143+
playground-publish: playground-build
144+
cp playground-app/dist/assets/index-*.js docs/playground/playground.js

docs/assets/extra.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,17 @@
1717
--md-default-bg-color--light: hsla(240, 4%, 11%, 0.54);
1818
--md-default-bg-color--lighter: hsla(240, 4%, 11%, 0.26);
1919
--md-default-bg-color--lightest: hsla(240, 4%, 11%, 0.07);
20+
}
21+
button:disabled {
22+
opacity: 0.5;
23+
cursor: not-allowed !important;
24+
}
25+
26+
.output {
27+
transition: opacity .5s ease-in-out;
28+
opacity: 0;
29+
}
30+
31+
.output.visible {
32+
opacity: 1;
2033
}

docs/playground/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<!--
2+
The playground.js is automatically generated using the 'make playground-publish' command.
3+
For more information, please refer to the README.md in 'playground-app' folder.
4+
-->
5+
<script type="module" crossorigin src="./playground.js"></script>
6+
<div id="playground"></div>

docs/playground/playground.js

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

mkdocs.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ theme:
1818
primary: custom
1919
accent: custom
2020
toggle:
21-
icon: material/toggle-switch-off
21+
icon: material/toggle-switch-off
2222
name: Switch to light mode
2323
logo: assets/logo-white.svg
2424
favicon: assets/logo-white.svg
@@ -55,6 +55,7 @@ markdown_extensions:
5555
format: !!python/name:pymdownx.superfences.fence_code_format
5656
- tables
5757
- attr_list
58+
- md_in_html
5859
- pymdownx.emoji:
5960
# we are using an older emoji extension because the newest (suggested in docs) doesn't work with Python < 3.10
6061
emoji_index: !!python/name:materialx.emoji.twemoji
@@ -64,6 +65,7 @@ nav:
6465
- 'Introduction': 'index.md'
6566
- 'Quick start': 'quick-start.md'
6667
- 'Installation': 'installation.md'
68+
- 'Playground': 'playground/index.md'
6769
- 'Concepts':
6870
- 'Feature Flagging': 'concepts/feature-flagging.md'
6971
- 'Syncs': 'concepts/syncs.md'

playground-app/.eslintrc.cjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module.exports = {
2+
root: true,
3+
env: { browser: true, es2020: true },
4+
extends: [
5+
'eslint:recommended',
6+
'plugin:@typescript-eslint/recommended',
7+
'plugin:react-hooks/recommended',
8+
],
9+
ignorePatterns: ['dist', '.eslintrc.cjs'],
10+
parser: '@typescript-eslint/parser',
11+
plugins: ['react-refresh'],
12+
rules: {
13+
'react-refresh/only-export-components': [
14+
'warn',
15+
{ allowConstantExport: true },
16+
],
17+
},
18+
}

playground-app/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# flagd playground
2+
3+
The flagd playground is an application designed to test the behavior of flagd.
4+
It allows users to define flags and experiment with various inputs to understand how flagd responds.
5+
This tool is particularly useful for developers and testers who are working with flagd in their projects and need a simple and effective way to validate their flag definitions.
6+
7+
## Development
8+
9+
### Getting Started
10+
11+
To get started with the development of the flagd playground, you'll need to have Node.js installed on your machine.
12+
13+
1. Install [Node.js](https://nodejs.org/en/download/) version 18 or newer.
14+
1. From the root of the project, run `make playground-dev`.
15+
1. Open your browser and navigate to [http://localhost:5173/](http://localhost:5173/);
16+
17+
> [!NOTE]
18+
> This page is mostly unstyled because it inherits the styles from Mkdocs Material.
19+
20+
### Add a new scenario
21+
22+
A new scenario can be added to the playground by following these steps:
23+
24+
1. Add a new scenario file during the ``./src/scenarios`` directory.
25+
1. Export a constant that conforms to the `Scenario` type.
26+
1. Include the scenario in the scenarios objects at `./src/scenarios/index.ts`.
27+
28+
> [!NOTE]
29+
> Make sure to update the docs once you're ready. This does not happen automatically! Please see below for more information.
30+
31+
### Adding Playground to the Docs
32+
33+
Adding the playground app to the docs can be done by running the following command from the root of the project:
34+
35+
```bash
36+
make make playground-publish
37+
```
38+
39+
> [!NOTE]
40+
> This will build the app and copy the output to the docs.

playground-app/index.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
</head>
7+
8+
<body>
9+
<div id="playground"></div>
10+
<script type="module" src="/src/main.tsx"></script>
11+
</body>
12+
13+
</html>

0 commit comments

Comments
 (0)