Compare commits

..
Author SHA1 Message Date
Thomas Nordquist 679e319912 Add bad examples 2019-10-10 10:42:09 +02:00
355 changed files with 12269 additions and 61533 deletions
+7 -42
View File
@@ -1,27 +1,19 @@
{
"import": [
"@cspell/dict-typescript/cspell-ext.json"
],
"ignoreRegExpList": [
"import(?:(?:(?:[ \\n\\t]+([^ *\\n\\t\\{\\},]+)[ \\n\\t]*(?:,|[ \\n\\t]+))?([ \\n\\t]*\\{(?:[ \\n\\t]*[^ \\n\\t\"'\\{\\}]+[ \\n\\t]*,?)+\\})?[ \\n\\t]*)|[ \n\\n\\t]*\\*[ \\n\\t]*as[ \\n\\t]+([^ \\n\\t\\{\\}]+)[ \\n\\t]+)from[ \\n\\t]*(?:['\"])([^'\"\\n]+)(['\"])\n",
"^import\\s+(['\"]).*\\1$"
],
"language": "en",
"words": [
"Bbreak",
"nodered",
"goog",
"thomasnordquist",
"nowrap",
"subheader",
"basepath",
"webdriverio",
"repo",
"hexagonalize",
"pixelize",
"Transistions",
"squashfs",
"squashfs",
"provisionprofile",
"Nsis",
"webdriverio",
"Appx",
"Hashable",
"clickaway",
@@ -31,6 +23,8 @@
"Monokai",
"plottable",
"snackbar",
"webdriverio",
"prismjs",
"Nordquist",
"debounced",
"mosquitto",
@@ -49,35 +43,6 @@
"DEVTOOLS",
"mixins",
"Explorerdmg",
"heapsnapshot",
"noconflict",
"sparkplugb",
"protojson",
"typesafe",
"visx",
"socketio",
"uuidv",
"hsts",
"frameguard",
"sameorigin",
"mqtts",
"infobars",
"KHTML",
"networkidle",
"testuser",
"wronguser",
"viewports",
"topicname",
"labelledby",
"dontAddToRecent",
"eclipseprojects",
"tasmota",
"Tasmota",
"automations",
"homeassistant",
"cmnd",
"parseable",
"sonoff",
"tele"
"heapsnapshot"
]
}
}
-64
View File
@@ -1,64 +0,0 @@
{
"name": "MQTT Explorer Development",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspace/MQTT-Explorer",
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-vscode.vscode-typescript-next",
"ms-azuretools.vscode-docker",
"eamodio.gitlens"
],
"settings": {
"editor.formatOnSave": true,
"typescript.tsdk": "node_modules/typescript/lib",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
}
}
},
"forwardPorts": [3000, 8080, 1883, 5900, 6080],
"portsAttributes": {
"3000": {
"label": "MQTT Explorer Server",
"onAutoForward": "notify"
},
"8080": {
"label": "Webpack Dev Server",
"onAutoForward": "notify"
},
"1883": {
"label": "MQTT Broker",
"onAutoForward": "ignore"
},
"5900": {
"label": "VNC Server",
"onAutoForward": "ignore"
},
"6080": {
"label": "noVNC Web Client",
"onAutoForward": "notify"
}
},
"postCreateCommand": "yarn install",
"postStartCommand": "sudo apt-get update && sudo apt-get install -y mosquitto xvfb x11vnc ffmpeg tmux python3 python3-pip && sudo pip3 install --break-system-packages websockify",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"installOhMyZsh": true,
"upgradePackages": true
}
},
"remoteUser": "node"
}
-23
View File
@@ -1,23 +0,0 @@
version: '3.8'
services:
app:
image: mcr.microsoft.com/devcontainers/javascript-node:24
volumes:
- ..:/workspaces/MQTT-Explorer:cached
command: sleep infinity
network_mode: service:mosquitto
environment:
- MQTT_EXPLORER_USERNAME=dev
- MQTT_EXPLORER_PASSWORD=dev123
mosquitto:
image: eclipse-mosquitto:2
ports:
- '1883:1883'
- '3000:3000'
- '8080:8080'
- '5900:5900'
- '6080:6080'
volumes:
- ./mosquitto.conf:/mosquitto/config/mosquitto.conf:ro
-4
View File
@@ -1,4 +0,0 @@
# Mosquitto configuration for development
listener 1883
allow_anonymous true
persistence false
-64
View File
@@ -1,64 +0,0 @@
# Git
.git
.gitignore
.github
# Dependencies
node_modules
app/node_modules
backend/node_modules
# Build artifacts
build
dist
app/dist
# Testing
coverage
.nyc_output
test-screenshot-*.png
ui-test.mp4
ui-test.gif
# Development
.vscode
.devcontainer
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# OS
.DS_Store
Thumbs.db
# IDE
*.swp
*.swo
*~
.idea
# Documentation
*.md
!Readme.md
LICENSE.md
# CI/CD files
.releaserc
appveyor.yml
# Misc
res
scripts
docker
icon.xcf
greenkeeper.json
prettier.config.js
.prettierignore
.eslintrc.json
.cspell.json
tslint.json
mcp.json
# Data directory (will be created in container)
data
-18
View File
@@ -1,18 +0,0 @@
# Example .env file for LLM tests
# Copy this to .env.llm-tests and fill in your API key
# Option 1: OpenAI (recommended for development)
export OPENAI_API_KEY=sk-your-openai-api-key-here
# Option 2: Google Gemini
# export GEMINI_API_KEY=your-gemini-api-key-here
# Option 3: Generic LLM API (specify provider)
# export LLM_API_KEY=your-api-key-here
# export LLM_PROVIDER=openai # or 'gemini'
# Enable LLM tests (required)
export RUN_LLM_TESTS=true
# Optional: Token limit for neighboring topics (default: 500)
# export LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT=500
-8
View File
@@ -1,8 +0,0 @@
node_modules
build
dist
app/build
*.js
!scripts/*.js
!*.config.js
!*.config.mjs
+14 -315
View File
@@ -1,318 +1,17 @@
{
"root": true,
"env": {
"browser": true,
"commonjs": true,
"es6": true,
"node": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
"env": {
"browser": true,
"commonjs": true,
"es6": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
}
},
"extends": [
"airbnb-base",
"plugin:@typescript-eslint/recommended",
"plugin:import/typescript"
],
"plugins": [
"@typescript-eslint",
"import"
],
"settings": {
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
},
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
},
"rules": {
"@typescript-eslint/semi": ["error", "never"],
"semi": "off",
"max-len": "warn",
"@typescript-eslint/explicit-member-accessibility": "warn",
"no-else-return": "warn",
"indent": "off",
"@typescript-eslint/indent": "warn",
"import/prefer-default-export": "warn",
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/comma-dangle": "warn",
"comma-dangle": "off",
"arrow-parens": "warn",
"import/no-extraneous-dependencies": ["warn", {
"devDependencies": ["**/*.spec.ts", "**/*.spec.tsx", "**/__tests__/**", "scripts/**", "src/spec/**"],
"optionalDependencies": true,
"peerDependencies": false
}],
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-unused-expressions": ["warn", {
"allowShortCircuit": true,
"allowTernary": true
}],
"object-shorthand": "warn",
"prefer-template": "warn",
"no-plusplus": "warn",
"class-methods-use-this": "warn",
"consistent-return": "warn",
"@typescript-eslint/lines-between-class-members": "warn",
"import/extensions": "warn",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "warn",
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": "warn",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
"import/no-cycle": "warn",
"import/no-relative-packages": "warn",
"operator-linebreak": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"prefer-destructuring": "warn",
"arrow-body-style": "warn",
"import/order": "warn",
"object-curly-newline": "warn",
"import/no-named-default": "warn",
"no-console": "warn",
"func-names": "warn",
"no-await-in-loop": "warn",
"no-restricted-syntax": "warn",
"no-continue": "warn",
"no-promise-executor-return": "warn",
"no-eval": "error",
"@typescript-eslint/default-param-last": "warn",
"radix": "warn",
"no-param-reassign": "warn",
"no-underscore-dangle": "warn",
"no-restricted-globals": "warn",
"@typescript-eslint/no-useless-constructor": "warn",
"@typescript-eslint/ban-types": "warn",
"global-require": "warn",
"@typescript-eslint/no-var-requires": "warn",
"eqeqeq": ["warn", "always", {"null": "ignore"}],
"no-var": "warn",
"prefer-const": "warn",
"no-unused-expressions": "off",
"curly": "warn",
"no-duplicate-imports": "warn",
"react-hooks/rules-of-hooks": "warn",
"@typescript-eslint/prefer-as-const": "warn",
"prefer-arrow-callback": "warn",
"react/jsx-boolean-value": "warn",
"react/jsx-one-expression-per-line": "warn",
"react/function-component-definition": "warn",
"react/no-unescaped-entities": "warn",
"no-trailing-spaces": "warn",
"padded-blocks": "warn",
"brace-style": "off",
"@typescript-eslint/brace-style": "warn",
"object-curly-spacing": "warn",
"space-before-function-paren": "off",
"@typescript-eslint/space-before-function-paren": "warn",
"keyword-spacing": "warn",
"space-infix-ops": "off",
"@typescript-eslint/space-infix-ops": "warn",
"comma-spacing": "off",
"@typescript-eslint/comma-spacing": "warn",
"quotes": "off",
"@typescript-eslint/quotes": "warn",
"linebreak-style": "warn"
},
"overrides": [
{
"files": ["src/**/*.ts", "scripts/**/*.ts", "events/**/*.ts"],
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"airbnb-base",
"airbnb-typescript/base"
],
"rules": {
"@typescript-eslint/semi": ["error", "never"],
"semi": "off",
"max-len": "warn",
"@typescript-eslint/indent": "warn",
"@typescript-eslint/no-throw-literal": "warn",
"arrow-parens": "warn",
"@typescript-eslint/comma-dangle": "warn",
"arrow-body-style": "warn",
"@typescript-eslint/no-use-before-define": "warn",
"object-curly-newline": "warn",
"no-trailing-spaces": "warn",
"operator-linebreak": "warn",
"no-await-in-loop": "warn",
"import/prefer-default-export": "warn",
"no-promise-executor-return": "warn",
"import/no-cycle": "warn",
"no-restricted-globals": "warn",
"import/no-extraneous-dependencies": ["warn", {
"devDependencies": ["**/*.spec.ts", "**/*.spec.tsx", "**/__tests__/**", "scripts/**", "src/spec/**"],
"optionalDependencies": true,
"peerDependencies": false
}],
"prefer-template": "warn",
"prefer-arrow-callback": "warn",
"import/no-relative-packages": "warn",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }]
}
},
{
"files": ["app/**/*.ts", "app/**/*.tsx"],
"parserOptions": {
"project": "./app/tsconfig.json"
},
"extends": [
"airbnb-base",
"airbnb-typescript/base"
],
"rules": {
"@typescript-eslint/semi": ["error", "never"],
"semi": "off",
"max-len": "warn",
"@typescript-eslint/indent": "warn",
"@typescript-eslint/no-throw-literal": "warn",
"arrow-parens": "warn",
"@typescript-eslint/comma-dangle": "warn",
"arrow-body-style": "warn",
"@typescript-eslint/no-use-before-define": "warn",
"object-curly-newline": "warn",
"no-trailing-spaces": "warn",
"operator-linebreak": "warn",
"no-await-in-loop": "warn",
"import/prefer-default-export": "warn",
"no-promise-executor-return": "warn",
"import/no-cycle": "warn",
"no-restricted-globals": "warn",
"import/no-extraneous-dependencies": ["warn", {
"devDependencies": ["**/*.spec.ts", "**/*.spec.tsx", "**/__tests__/**", "scripts/**", "src/spec/**"],
"optionalDependencies": true,
"peerDependencies": false
}],
"prefer-template": "warn",
"prefer-arrow-callback": "warn",
"import/no-relative-packages": "warn",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }]
}
},
{
"files": ["app/**/*.tsx"],
"parserOptions": {
"project": "./app/tsconfig.json"
},
"extends": [
"airbnb",
"airbnb-typescript",
"plugin:react/recommended",
"plugin:react-hooks/recommended"
],
"plugins": [
"react",
"react-hooks",
"jsx-a11y"
],
"settings": {
"react": {
"version": "detect"
}
},
"rules": {
"@typescript-eslint/semi": ["error", "never"],
"semi": "off",
"max-len": "off",
"@typescript-eslint/indent": "off",
"@typescript-eslint/no-throw-literal": "warn",
"react/jsx-filename-extension": ["error", { "extensions": [".tsx"] }],
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"react/jsx-props-no-spreading": "warn",
"jsx-a11y/click-events-have-key-events": "warn",
"jsx-a11y/no-static-element-interactions": "warn",
"react/destructuring-assignment": "warn",
"react/no-access-state-in-setstate": "warn",
"react/sort-comp": "warn",
"react/no-unused-state": "warn",
"react/state-in-constructor": "warn",
"react/static-property-placement": "warn",
"react/no-array-index-key": "warn",
"react/display-name": "warn",
"react-compiler/react-compiler": "off",
"react/require-default-props": "warn",
"react/jsx-no-bind": "warn",
"arrow-parens": "warn",
"@typescript-eslint/comma-dangle": "warn",
"arrow-body-style": "warn",
"@typescript-eslint/no-use-before-define": "warn",
"object-curly-newline": "warn",
"no-trailing-spaces": "warn",
"operator-linebreak": "warn",
"no-await-in-loop": "warn",
"import/prefer-default-export": "warn",
"no-promise-executor-return": "warn",
"import/no-cycle": "warn",
"no-restricted-globals": "warn",
"import/no-extraneous-dependencies": ["warn", {
"devDependencies": ["**/*.spec.ts", "**/*.spec.tsx", "**/__tests__/**", "scripts/**", "src/spec/**"],
"optionalDependencies": true,
"peerDependencies": false
}],
"prefer-template": "warn",
"prefer-arrow-callback": "warn",
"import/no-relative-packages": "warn",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }],
"react/jsx-boolean-value": "warn",
"react/jsx-one-expression-per-line": "warn"
}
},
{
"files": ["backend/**/*.ts"],
"parserOptions": {
"project": "./backend/tsconfig.json"
},
"extends": [
"airbnb-base",
"airbnb-typescript/base"
],
"rules": {
"@typescript-eslint/semi": ["error", "never"],
"semi": "off",
"max-len": "warn",
"@typescript-eslint/indent": "warn",
"@typescript-eslint/no-throw-literal": "warn",
"arrow-parens": "warn",
"@typescript-eslint/comma-dangle": "warn",
"arrow-body-style": "warn",
"@typescript-eslint/no-use-before-define": "warn",
"object-curly-newline": "warn",
"no-trailing-spaces": "warn",
"operator-linebreak": "warn",
"no-await-in-loop": "warn",
"import/prefer-default-export": "warn",
"no-promise-executor-return": "warn",
"import/no-cycle": "warn",
"no-restricted-globals": "warn",
"import/no-extraneous-dependencies": ["warn", {
"devDependencies": ["**/*.spec.ts", "**/*.spec.tsx", "**/__tests__/**", "scripts/**", "src/spec/**"],
"optionalDependencies": true,
"peerDependencies": false
}],
"prefer-template": "warn",
"prefer-arrow-callback": "warn",
"import/no-relative-packages": "warn",
"@typescript-eslint/no-unused-vars": ["warn", { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" }]
}
},
{
"files": ["*.spec.ts", "*.spec.tsx", "**/__tests__/**"],
"rules": {
"@typescript-eslint/no-unused-expressions": "off",
"import/no-extraneous-dependencies": "off"
}
}
]
}
-3
View File
@@ -1,3 +0,0 @@
package.ts @thomasnordquist
.github @thomasnordquist
scripts @thomasnordquist
-261
View File
@@ -1,261 +0,0 @@
# copilot-instructions.md - Agent Long-Term Memory
## META-INSTRUCTIONS (IMMUTABLE)
1. **Long-term memory**: If you learn something during a session that would save time in future sessions, add it to `.github/copilot-instructions.md`
2. **Paper knowledge must go**: If something is no longer true, update or remove it immediately
3. **Evaluate after every session**: Consider whether the instructions need updates based on what you learned
4. **Concise and useful**: All information must be actionable, current, and concise
## Code Formatting and Linting
**Before committing code, always run:**
- `yarn lint:prettier:fix` - Format all TypeScript files with Prettier
- `yarn lint:fix` - Fix ESLint and Prettier issues
**Check code quality:**
- `yarn lint` - Check Prettier, ESLint, and spell checking
- `yarn lint:prettier` - Check Prettier formatting only
- `yarn lint:eslint` - Check ESLint only
## Test Commands
**Unit tests:**
- `yarn test` - All unit tests (app + backend)
- `yarn test:app` - Frontend tests only
- `yarn test:backend` - Backend tests only
**LLM integration tests:**
- Requires API key (OpenAI or Gemini)
- **Setup**: Run `./scripts/setup-llm-env.sh` to create `.env.llm-tests` from injected secrets
- **Usage**: `source .env.llm-tests && ./scripts/run-llm-tests.sh`
- **Note**: The `.env.llm-tests` file must be sourced to get the LLM access token before running tests
- Tests make real API calls and cost ~$0.01-$0.05 per run
- See `app/src/services/spec/README.md` for details
**Integration tests:**
- `yarn test:ui` - Browser tests (requires `yarn build` first)
- `yarn test:demo-video` - UI recording (requires Xvfb, mosquitto, tmux, ffmpeg)
- `yarn test:mcp` - Model Context Protocol tests
- `yarn test:all` - All tests (unit + demo-video)
- `./scripts/runBrowserTests.sh` - Browser mode UI tests (requires mosquitto service)
- `./scripts/uiTests.sh` - Demo video tests with Electron (requires Xvfb, mosquitto)
**CI jobs:** `test`, `ui-tests`, `demo-video`, `test-browser`, `browser-ui-tests`
**Important:**
- Browser UI tests require MQTT broker. In CI, GitHub Actions health checks ensure the mosquitto service is ready before tests run.
- Demo video tests use the same test scenarios as browser tests - if browser tests pass, demo video tests should pass too (they use identical selectors in `src/spec/scenarios/`)
## Debugging Demo Video / UI Tests
When demo video tests fail in CI but you need to debug locally:
**Prerequisites:**
```bash
# Install required packages
sudo apt-get install xvfb mosquitto tmux ffmpeg
# Ensure mosquitto is stopped (script will start its own instance)
sudo systemctl stop mosquitto
```
**Steps to debug:**
1. Build the project: `yarn build`
2. Run the demo video tests: `ELECTRON_DISABLE_SANDBOX=1 ./scripts/uiTests.sh`
3. If tests fail, check the error messages for:
- Missing `data-test` or `data-test-type` attributes
- Elements not visible (hidden, outside viewport, or covered by overlays)
- Click interception (tooltips, dialogs blocking clicks)
- XPath selector issues (check the data-test value format)
**Common issues:**
- **"locator not visible"**: Element exists but is hidden or outside viewport
- **"locator.click intercepted"**: Another element (tooltip, dialog) is covering the click target
- **Empty `data-test` attribute**: For simple numeric values, ensure you're using the topic name, not `props.literal.path` (which is empty for non-JSON values)
- **"Process failed to launch"**: Electron can't start - ensure DISPLAY is set and Xvfb is running
**Environment-specific notes:**
- Demo video tests use Electron with Xvfb (virtual display)
- Browser tests use Chromium without Electron (easier to debug locally)
- CI environment has proper Electron setup - if local tests are flaky, trust CI results
- Both test types use the same scenario files in `src/spec/scenarios/`
**Material-UI Tooltip considerations:**
- Tooltips wrap their children and create overlay divs
- Test attributes (`data-test-type`, `data-test`) must be on the inner clickable element that's passed as a child to the Tooltip
- Mouse event handlers (onMouseEnter, onMouseLeave, ref) go on outer wrapper
- onClick handler and test attributes go on the span inside the Tooltip
- The clickable child inside the Tooltip is what Playwright should target
**Example:**
```tsx
// ❌ WRONG - attributes on outer wrapper, Tooltip wraps and hides them
<Tooltip title="...">
<span onClick={...} data-test-type="Button" data-test="example">
<Icon />
</span>
</Tooltip>
// ✅ CORRECT - attributes on the actual clickable child inside Tooltip
<span ref={ref} onMouseEnter={...} onMouseLeave={...}>
<Tooltip title="...">
<span onClick={...} data-test-type="Button" data-test="example">
<Icon />
</span>
</Tooltip>
</span>
```
**data-test value format:**
- ShowChart: Use last segment of topic path (e.g., "heater" for "kitchen/coffee_maker/heater")
- ChartSettings: Use full topic + dotPath (e.g., "kitchen/coffee_maker/heater-" with trailing dash when dotPath is empty)
- Test XPaths use `contains(@data-test, "substring")` so partial matches work
## Running Browser Tests Locally
**Prerequisites:**
```bash
# Install mosquitto (if not already installed)
sudo apt-get install mosquitto
# Start mosquitto service
sudo systemctl start mosquitto
sudo systemctl status mosquitto
```
**Run browser tests:**
```bash
# Build server and run tests
yarn build:server
./scripts/runBrowserTests.sh
```
The script automatically:
- Starts a local mosquitto broker
- Builds the TypeScript code
- Starts the browser mode server on port 3000
- Runs Playwright tests in browser mode
- Cleans up processes on exit
**Test environment variables:**
- `MQTT_EXPLORER_USERNAME` - Browser auth username (default: test)
- `MQTT_EXPLORER_PASSWORD` - Browser auth password (default: test123)
- `PORT` - Server port (default: 3000)
- `TESTS_MQTT_BROKER_HOST` - MQTT broker host (default: 127.0.0.1)
- `TESTS_MQTT_BROKER_PORT` - MQTT broker port (default: 1883)
- `USE_MOBILE_VIEWPORT` - Enable mobile viewport (default: false)
**Common test failures after UI changes:**
- Update test selectors in `src/spec/ui-tests.spec.ts` if UI structure changes
- Use `data-testid` attributes for stable test selectors
- Avoid using role + name selectors for dynamic content (use direct testid selectors instead)
## Browser Mode
**Prerequisites:** Node.js ≥24, Yarn, Mosquitto broker (for testing)
**Development (hot reload):**
```bash
export MQTT_EXPLORER_USERNAME=admin MQTT_EXPLORER_PASSWORD=yourpass
yarn dev:server
# Backend: http://localhost:3000, Frontend: http://localhost:8080 (use this one)
```
**Production:**
```bash
yarn build:server
export MQTT_EXPLORER_USERNAME=admin MQTT_EXPLORER_PASSWORD=yourpass
yarn start:server # http://localhost:3000
```
**Build artifacts:** `dist/src/server.js`, `app/build/*.js`, `app/build/index.html`
## Debugging Browser Mode
**DevTools checks:**
- Console: JavaScript errors, CSP errors (security headers), WebSocket issues
- Network: Static asset loading, WebSocket status, API auth
**Common issues:**
- **Blank page/CSP errors:** Add `'unsafe-eval'` to `scriptSrc` in `src/server.ts` helmet config
- **Auth loop:** WebSocket auth failing - check Network → WS → Messages and server logs
- **Theme errors:** Verify both ThemeProvider and LegacyThemeProvider in `app/src/index.tsx`
**Expected warnings (non-fatal):**
- React 18 + Material-UI v5 type warnings
- IpcRendererEventBus errors (no Electron IPC in browser mode)
- MUI locale, componentWillReceiveProps, ACE editor warnings
**WebSocket debugging:**
```bash
node dist/src/server.js 2>&1 | tee server.log
# Check DevTools → Network → WS → Messages for handshake
# CORS: check ALLOWED_ORIGINS env var
```
**Security notes:**
- `unsafe-eval` in CSP required for webpack (security tradeoff)
- Never hardcode credentials (use env vars)
- Production: use HTTPS with reverse proxy
- Rate limit: 5 auth attempts/15min/IP
- File upload limit: 16MB
**Key files:**
- `src/server.ts` - Express server, security middleware
- `app/webpack.browser.config.mjs` - Browser webpack config
- `app/src/browserEventBus.ts` - Socket.io client
- `app/src/components/BrowserAuthWrapper.tsx` - Auth dialog
- `app/src/index.tsx` - React entry, theme providers
## Styling Conventions
When modifying or creating UI components, follow the styling patterns documented in <a>STYLING.md</a>.
**Key points for AI agents:**
- Use Material-UI (MUI) v7 components with `withStyles` HOC for styling
- Access theme colors via `theme.palette.*`, spacing via `theme.spacing()`, typography via `theme.typography.*`
- Support both light and dark modes with theme-conditional styling
- Import Material-UI colors: `import { blueGrey, amber, green, red } from '@mui/material/colors'`
## Mobile Testing Workflow
**Prerequisites for mobile testing:**
```bash
# Install Playwright browsers
npx playwright install --with-deps chromium
# Configure mosquitto to allow anonymous connections (for local testing)
echo "listener 1883
allow_anonymous true" | sudo tee /etc/mosquitto/conf.d/allow-anonymous.conf
sudo systemctl restart mosquitto
```
**Interactive testing with mobile viewport:**
```bash
# Set up environment
export MQTT_EXPLORER_SKIP_AUTH=true
export MQTT_AUTO_CONNECT_HOST=127.0.0.1
# Build and start server
yarn build:server
node dist/src/server.js
# In another terminal, run Playwright test with mobile viewport
# Create test script with viewport: { width: 412, height: 914 }
# Always INSPECT the rendered output, don't rely on assumptions
```
**Key lesson**: Mobile tree visibility issues often stem from:
1. CSS flex/absolute positioning conflicts
2. Missing Redux state updates (connection not propagated to frontend)
3. MQTT broker authentication (mosquitto requires `allow_anonymous true` for testing)
4. Timing issues (frontend subscribing to events after backend emits them)
**Server-side auto-connect** (for testing):
```bash
export MQTT_AUTO_CONNECT_HOST=127.0.0.1
export MQTT_AUTO_CONNECT_PORT=1883 # optional
export MQTT_AUTO_CONNECT_PROTOCOL=mqtt # optional
```
-33
View File
@@ -1,33 +0,0 @@
on:
push:
branches:
- master
- release
- beta
paths:
- Dockerfile
- .github
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
create-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/thomasnordquist/mqtt-explorer-ui-tests:latest
-61
View File
@@ -1,61 +0,0 @@
name: 'Copilot Setup Steps'
# Automatically run the setup steps when they are changed to allow for easy validation, and
# allow manual testing through the repository's "Actions" tab
on:
workflow_dispatch:
push:
paths:
- .github/workflows/copilot-setup-steps.yml
pull_request:
paths:
- .github/workflows/copilot-setup-steps.yml
jobs:
copilot-setup-steps:
runs-on: ubuntu-latest
env:
TESTS_MQTT_BROKER_HOST: localhost
TESTS_MQTT_BROKER_PORT: 1883
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Persist Secrets to Agent Environment
run: |
echo "export OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" > .env.llm-tests
echo "export RUN_LLM_TESTS=true" >> .env.llm-tests
chmod 600 .env.llm-tests
echo "✅ Created .env.llm-tests file"
ls -la .env.llm-tests
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y xvfb mosquitto
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- name: Cache yarn dependencies
uses: actions/cache@v4
id: yarn-cache
with:
path: |
${{ steps.yarn-cache-dir-path.outputs.dir }}
node_modules
app/node_modules
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn
-231
View File
@@ -1,231 +0,0 @@
name: Docker Browser Build
on:
push:
branches:
- master
- release
- beta
paths:
- 'Dockerfile.browser'
- 'src/server.ts'
- 'src/AuthManager.ts'
- 'app/**'
- 'backend/**'
- 'package.json'
- 'yarn.lock'
- '.github/workflows/docker-browser.yml'
- 'tsconfig.json'
- 'events/**'
schedule:
# Run every two weeks (1st and 15th of each month) at 2:00 AM UTC
- cron: '0 2 1,15 * *'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build-and-test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
env:
TESTS_MQTT_BROKER_HOST: localhost
TESTS_MQTT_BROKER_PORT: 1883
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install and Start Mosquitto
run: |
sudo apt-get update
sudo apt-get install -y mosquitto mosquitto-clients
# Create a minimal configuration file for testing
sudo tee /etc/mosquitto/conf.d/test.conf > /dev/null <<EOF
listener 1883
allow_anonymous true
persistence false
EOF
# Start mosquitto in detached mode
sudo mosquitto -c /etc/mosquitto/mosquitto.conf -d
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}
- name: Build Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.browser
platforms: linux/amd64
push: false
load: true
tags: mqtt-explorer:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test Docker image - Basic startup
run: |
# Start container with test credentials
docker run -d \
--name mqtt-explorer-test \
-p 3000:3000 \
-e MQTT_EXPLORER_USERNAME=test \
-e MQTT_EXPLORER_PASSWORD=test123 \
-e PORT=3000 \
mqtt-explorer:test
# Wait for server to be ready (max 60 seconds)
echo "Waiting for server to start..."
for i in {1..60}; do
if curl -f http://localhost:3000 > /dev/null 2>&1; then
echo "Server started successfully after $i seconds"
break
fi
if [ $i -eq 60 ]; then
echo "Server failed to start within 60 seconds"
docker logs mqtt-explorer-test
exit 1
fi
sleep 1
done
- name: Test Docker image - Health check
run: |
# Wait for health check to pass
echo "Waiting for health check to pass..."
for i in {1..30}; do
health=$(docker inspect --format='{{.State.Health.Status}}' mqtt-explorer-test)
if [ "$health" = "healthy" ]; then
echo "Container is healthy"
break
fi
if [ $i -eq 30 ]; then
echo "Health check failed"
docker logs mqtt-explorer-test
exit 1
fi
sleep 2
done
- name: Test Docker image - Verify response
run: |
# Test that the server responds with HTML
response=$(curl -s http://localhost:3000)
if echo "$response" | grep -q "MQTT Explorer"; then
echo "Server is serving the application correctly"
else
echo "Server response does not contain expected content"
echo "Response: $response"
exit 1
fi
- name: Test Docker image - Verify data persistence
run: |
# Check that data directory was created
docker exec mqtt-explorer-test sh -c '[ -d /app/data ] && echo "Data directory exists"'
- name: Clean up test container
if: always()
run: |
docker stop mqtt-explorer-test || true
docker rm mqtt-explorer-test || true
- name: Check Docker image size
run: |
echo "### Docker Image Size" >> $GITHUB_STEP_SUMMARY
docker images mqtt-explorer:test --format "table {{.Repository}}\t{{.Tag}}\t{{.Size}}" >> $GITHUB_STEP_SUMMARY
# Get size in bytes for detailed reporting
SIZE_BYTES=$(docker inspect mqtt-explorer:test --format='{{.Size}}')
SIZE_MB=$((SIZE_BYTES / 1024 / 1024))
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image size**: ${SIZE_MB} MB (${SIZE_BYTES} bytes)" >> $GITHUB_STEP_SUMMARY
echo "Image size: ${SIZE_MB} MB"
- name: Setup Node.js for browser tests
uses: actions/setup-node@v4
with:
node-version: '24'
cache: 'yarn'
- name: Install dependencies for browser tests
run: yarn install --frozen-lockfile
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium
- name: Start Docker container for browser tests
run: |
docker run -d \
--name mqtt-explorer-browser-test \
--network host \
-e MQTT_EXPLORER_USERNAME=test \
-e MQTT_EXPLORER_PASSWORD=test123 \
-e PORT=3000 \
mqtt-explorer:test
# Wait for server to be ready
echo "Waiting for Docker container to be ready..."
timeout 60 bash -c 'until curl -f http://localhost:3000; do sleep 1; done'
echo "Docker container is ready"
- name: Run browser test suite
run: |
yarn test:browser
env:
MQTT_EXPLORER_USERNAME: test
MQTT_EXPLORER_PASSWORD: test123
BROWSER_MODE_URL: http://localhost:3000
- name: Clean up browser test container
if: always()
run: |
docker logs mqtt-explorer-browser-test || true
docker stop mqtt-explorer-browser-test || true
docker rm mqtt-explorer-browser-test || true
- name: Build and push Docker image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.browser
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ghcr.io/${{ github.repository }}
subject-digest: ${{ steps.build.outputs.digest }}
push-to-registry: true
-38
View File
@@ -1,38 +0,0 @@
name: Lint
on:
pull_request_target:
branches: [master, beta, release]
push:
branches: [master, beta, release]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
cache: 'yarn'
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Run Prettier
run: yarn lint:prettier
- name: Run ESLint
run: yarn lint:eslint
continue-on-error: true # Allow failures for now due to existing issues
- name: Run Spellcheck
run: yarn lint:spellcheck
-56
View File
@@ -1,56 +0,0 @@
name: Build
on:
push:
branches:
- release
- beta
concurrency:
group: ${{ github.ref }}
cancel-in-progress: false
jobs:
build:
strategy:
matrix:
build:
- os: ubuntu-latest
task: linux
- os: windows-latest
task: win
- os: macos-latest
task: mac
runs-on: ${{ matrix.build.os }}
steps:
- if: matrix.build.os == 'ubuntu-latest'
run: sudo snap install snapcraft --classic
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24
- run: npm install -g yarn
- run: yarn
- id: create_token # get ReleaseBot access token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.RELEASE_BOT_APP_ID }}
private-key: ${{ secrets.RELEASE_BOT_PRIVATE_KEY }}
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
id: semantic # Need an `id` for output variables
env:
GITHUB_TOKEN: ${{ steps.create_token.outputs.token }}
- run: yarn build
if: steps.semantic.outputs.new_release_published == 'true'
- run: yarn prepare-release
if: steps.semantic.outputs.new_release_published == 'true'
- run: yarn package ${{ matrix.build.task }}
if: steps.semantic.outputs.new_release_published == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SNAPCRAFT_STORE_CREDENTIALS: ${{ secrets.SNAPCRAFT_STORE_CREDENTIALS }}
APPLE_ID: ${{ secrets.APPLE_ID }}
APPLE_APP_SPECIFIC_PASSWORD: ${{ secrets.APPLE_APP_SPECIFIC_PASSWORD }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
-319
View File
@@ -1,319 +0,0 @@
on:
pull_request_target: # Use pull_request_target
branches: [master, beta, release]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
test:
runs-on: ubuntu-latest
container:
image: ghcr.io/thomasnordquist/mqtt-explorer-ui-tests:latest
volumes:
- ./:/app
options: --user root
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Packages
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Test
run: yarn test
browser-ui-tests:
runs-on: ubuntu-latest
container:
image: ghcr.io/thomasnordquist/mqtt-explorer-ui-tests:latest
volumes:
- ./:/app
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Packages
run: yarn install --frozen-lockfile
- name: Build Browser Mode
run: yarn build:server
- name: Run Browser UI Tests
timeout-minutes: 10
run: ./scripts/runBrowserTests.sh
- name: Upload Test Screenshots
if: always()
uses: actions/upload-artifact@v4
with:
name: browser-test-screenshots
path: |
test-screenshot-*.png
retention-days: 30
demo-video:
runs-on: ubuntu-latest
container:
image: ghcr.io/thomasnordquist/mqtt-explorer-ui-tests:latest
volumes:
- ./:/app
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Packages
run: yarn install --frozen-lockfile
- name: Build
run: yarn build
- name: Generate Demo Video
run: yarn ui-test
- name: Post-processing
run: ./scripts/prepareVideo.sh
- name: Generate unique base path
id: basepath
run: |
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
BASEPATH="pr-${{ github.event.pull_request.number }}-${TIMESTAMP}"
echo "basepath=${BASEPATH}" >> $GITHUB_OUTPUT
- name: Install AWS CLI v2
run: |
apt-get update && apt-get install -y unzip
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
./aws/install
rm -rf aws awscliv2.zip
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ vars.AWS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: 'eu-central-1'
- name: Upload full video to S3
env:
AWS_BUCKET: ${{ vars.AWS_BUCKET }}
BASEPATH: ${{ steps.basepath.outputs.basepath }}
run: |
# Upload GIF
aws s3api put-object \
--bucket ${AWS_BUCKET} \
--key artifacts/${BASEPATH}/ui-test.gif \
--body ./ui-test.gif \
--content-type image/gif
# Upload MP4
aws s3api put-object \
--bucket ${AWS_BUCKET} \
--key artifacts/${BASEPATH}/ui-test.mp4 \
--body ./ui-test.mp4 \
--content-type video/mp4
- name: Upload video segments to S3
env:
AWS_BUCKET: ${{ vars.AWS_BUCKET }}
BASEPATH: ${{ steps.basepath.outputs.basepath }}
shell: bash
run: |
# Upload all GIF segment files if they exist
shopt -s nullglob # Make glob return empty list if no matches
for segment in segment-*.gif; do
echo "Uploading $segment..."
aws s3api put-object \
--bucket ${AWS_BUCKET} \
--key artifacts/${BASEPATH}/${segment} \
--body ./${segment} \
--content-type image/gif
done
shopt -u nullglob # Restore default behavior
- name: Generate file URLs
id: fileurl
env:
AWS_BUCKET: ${{ vars.AWS_BUCKET }}
BASEPATH: ${{ steps.basepath.outputs.basepath }}
run: |
BASE_URL="https://${AWS_BUCKET}.s3.eu-central-1.amazonaws.com/artifacts/${BASEPATH}"
echo "base-url=${BASE_URL}" >> $GITHUB_OUTPUT
echo "Uploaded to: ${BASE_URL}"
- name: Generate markdown summary
id: markdown
env:
BASE_URL: ${{ steps.fileurl.outputs.base-url }}
run: |
MARKDOWN=$(node ./scripts/generateMarkdownSummary.js "${BASE_URL}")
echo "markdown<<EOF" >> $GITHUB_OUTPUT
echo "$MARKDOWN" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Add to workflow summary
env:
MARKDOWN: ${{ steps.markdown.outputs.markdown }}
run: |
echo "$MARKDOWN" >> $GITHUB_STEP_SUMMARY
- name: Post video to PR
uses: actions/github-script@v7
env:
MARKDOWN: ${{ steps.markdown.outputs.markdown }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const markdown = process.env.MARKDOWN;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: markdown
});
demo-video-mobile:
runs-on: ubuntu-latest
container:
image: ghcr.io/thomasnordquist/mqtt-explorer-ui-tests:latest
volumes:
- ./:/app
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install Packages
run: yarn install --frozen-lockfile
- name: Build Browser Mode
run: yarn build:server
- name: Generate Mobile Demo Video
id: generate_video
continue-on-error: true
run: ./scripts/uiTestsMobile.sh
- name: Post-processing
if: always()
continue-on-error: true
run: ./scripts/prepareVideoMobile.sh
- name: Generate unique base path
id: basepath
run: |
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
BASEPATH="pr-${{ github.event.pull_request.number }}-mobile-${TIMESTAMP}"
echo "basepath=${BASEPATH}" >> $GITHUB_OUTPUT
- name: Install AWS CLI v2
run: |
apt-get update && apt-get install -y unzip
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip -q awscliv2.zip
./aws/install
rm -rf aws awscliv2.zip
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ vars.AWS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: 'eu-central-1'
- name: Upload full mobile video to S3
if: always()
continue-on-error: true
env:
AWS_BUCKET: ${{ vars.AWS_BUCKET }}
BASEPATH: ${{ steps.basepath.outputs.basepath }}
run: |
# Upload GIF if it exists
if [ -f ./ui-test-mobile.gif ]; then
aws s3api put-object \
--bucket ${AWS_BUCKET} \
--key artifacts/${BASEPATH}/ui-test-mobile.gif \
--body ./ui-test-mobile.gif \
--content-type image/gif
fi
# Upload MP4 if it exists
if [ -f ./ui-test-mobile.mp4 ]; then
aws s3api put-object \
--bucket ${AWS_BUCKET} \
--key artifacts/${BASEPATH}/ui-test-mobile.mp4 \
--body ./ui-test-mobile.mp4 \
--content-type video/mp4
fi
- name: Upload mobile video segments to S3
if: always()
continue-on-error: true
env:
AWS_BUCKET: ${{ vars.AWS_BUCKET }}
BASEPATH: ${{ steps.basepath.outputs.basepath }}
shell: bash
run: |
# Upload all mobile GIF segment files if they exist
shopt -s nullglob # Make glob return empty list if no matches
for segment in segment-mobile-*.gif; do
echo "Uploading $segment..."
aws s3api put-object \
--bucket ${AWS_BUCKET} \
--key artifacts/${BASEPATH}/${segment} \
--body ./${segment} \
--content-type image/gif
done
shopt -u nullglob # Restore default behavior
- name: Generate file URLs
if: always()
id: fileurl
env:
AWS_BUCKET: ${{ vars.AWS_BUCKET }}
BASEPATH: ${{ steps.basepath.outputs.basepath }}
run: |
BASE_URL="https://${AWS_BUCKET}.s3.eu-central-1.amazonaws.com/artifacts/${BASEPATH}"
echo "base-url=${BASE_URL}" >> $GITHUB_OUTPUT
echo "Uploaded to: ${BASE_URL}"
- name: Generate markdown summary
if: always()
id: markdown
env:
BASE_URL: ${{ steps.fileurl.outputs.base-url }}
TEST_STATUS: ${{ steps.generate_video.outcome }}
run: |
MARKDOWN=$(node ./scripts/generateMarkdownSummaryMobile.js "${BASE_URL}" "${TEST_STATUS}")
echo "markdown<<EOF" >> $GITHUB_OUTPUT
echo "$MARKDOWN" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Add to workflow summary
if: always()
env:
MARKDOWN: ${{ steps.markdown.outputs.markdown }}
run: |
echo "$MARKDOWN" >> $GITHUB_STEP_SUMMARY
- name: Post mobile video to PR
if: always()
uses: actions/github-script@v7
env:
MARKDOWN: ${{ steps.markdown.outputs.markdown }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const markdown = process.env.MARKDOWN;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: markdown
});
test-browser:
runs-on: ubuntu-latest
env:
TESTS_MQTT_BROKER_HOST: localhost
TESTS_MQTT_BROKER_PORT: 1883
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install -y mosquitto mosquitto-clients
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Install Playwright Browsers
run: npx playwright install --with-deps chromium
- name: Build Browser Mode
run: yarn build:server
- name: Test App
run: yarn test:app
- name: Test Backend
run: yarn test:backend
- name: Run Browser UI Tests
run: ./scripts/runBrowserTests.sh
-21
View File
@@ -1,21 +0,0 @@
name: Update Website
on: [release, workflow_dispatch]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
update-website:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: gh-pages
- uses: actions/setup-node@v4
with:
node-version: '24'
- run: npm install
- run: npm run readme
- uses: stefanzweifel/git-auto-commit-action@v5
-64
View File
@@ -9,67 +9,3 @@ test.png
.awcache
.scannerwork
screen*.png
# MCP introspection artifacts
mqtt-explorer-mcp-screenshot.png
screenshot-mcp-*.png
test-mcp-introspection.js
/data
test-screenshot-*.png
test-expand-*.png
browser-debug-screenshot.png
app/.webpack-cache
# Temporary files
/tmp
# Environment files with secrets
.env
.env.*
!.env.example
# Demo video artifacts
scenes.json
scenes-mobile.json
segment-*.mp4
segment-*.gif
ui-test.mp4
ui-test.gif
ui-test-mobile.mp4
ui-test-mobile.gif
app.mp4
app2.mp4
app-mobile.mp4
app2-mobile.mp4
app720.gif
qrawvideorgb24.yuv
qrawvideorgb24-mobile.yuv
intro.png
intro-mobile.png
palette.png
palette-mobile.png
ffmpeg_info
ffmpeg_info_mobile# Mobile test artifacts
qrawvideorgb24-mobile.yuv
*.yuv
segment-mobile-*.gif
mobile-demo.mp4
mobile-demo.gif
final-mobile-tree.png
mobile-tree-debug.png
mobile-render-debug.png
tree-state-check.png
server*.log
# Test scripts
test-mobile-tree.js
check-*.js
debug-*.js
inspect-*.js
final-*.js
publish-test*.js
verify-mobile-tree.js
interactive-mobile-test.js
long-wait-test.js
-30
View File
@@ -1,30 +0,0 @@
{
"branches": [
"release",
{
"name": "beta",
"prerelease": true
}
],
repositoryUrl: "git@github.com:thomasnordquist/MQTT-Explorer.git",
"plugins": [
"@semantic-release/commit-analyzer",
"semantic-release-export-data",
"@semantic-release/changelog",
[
"@semantic-release/npm",
{
"npmPublish": false
}
],
[
"@semantic-release/git",
{
"assets": [
"package.json",
"yarn.lock"
]
}
]
]
}
+40
View File
@@ -0,0 +1,40 @@
language: node_js
services:
- xvfb
cache:
directories:
- node_modules
- $HOME/.cache/electron
- $HOME/.cache/electron-builder
- $HOME/.npm/_prebuilds
node_js:
- "10"
os:
- linux
- osx
osx_image: xcode10.2
dist: xenial
services:
- docker
install:
- yarn install
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update && sudo apt-get -y install snap squashfs-tools && sudo snap install snapcraft --classic; fi;
script:
- yarn run build
- yarn lint
- yarn test
- export TRAVIS_BUILD_NUMBER="" # Override travis build number since it is uses for tagging the binary version https://github.com/electron-userland/electron-builder/issues/3730
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run -e GH_TOKEN=$GH_TOKEN -e GIT_TAG=$TRAVIS_TAG --rm -v `pwd`:/app thomasnordquist/ui-test-recording-env sh -c "cd app && docker/testMounted.sh"; fi
- if [[ "$TRAVIS_TAG" != "" ]]; then yarn run prepare-release; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]] && [[ "$TRAVIS_TAG" != "" ]]; then yarn run package linux; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]] && [[ "$TRAVIS_TAG" != "" ]]; then yarn run package -- mac; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]] && [[ "$TRAVIS_TAG" != "" ]]; then unset CSC_LINK; yarn run package -- win; fi
-307
View File
@@ -1,307 +0,0 @@
# Browser Mode Documentation
MQTT Explorer now supports running as a web application served by a Node.js server, in addition to the existing Electron desktop app.
## Running in Browser Mode
### Quick Start
1. Build the application for browser mode:
```bash
yarn build:server
```
2. Start the server:
```bash
yarn start:server
```
3. Open your browser and navigate to `http://localhost:3000`
4. You'll be prompted to log in with credentials that were generated on server startup.
### Development Mode
To run in development mode with hot reload:
```bash
yarn dev:server
```
This starts both the webpack dev server and the backend server.
## Authentication
### Environment Variables
You can set custom authentication credentials using environment variables:
```bash
export MQTT_EXPLORER_USERNAME=admin
export MQTT_EXPLORER_PASSWORD=secretpassword
yarn start:server
```
### Generated Credentials
If no environment variables are set, the server will generate credentials on first startup and save them to `data/credentials.json`. The generated credentials will be printed to the console:
```
============================================================
Generated new credentials:
Username: user-abc123
Password: 123e4567-e89b-12d3-a456-426614174000
============================================================
Please save these credentials. They will be persisted to:
/path/to/data/credentials.json
============================================================
```
## Features
### Certificate Upload
In browser mode, certificate files are uploaded directly through the browser using the HTML5 File API. The certificates are:
- Read client-side as base64
- Stored in the connection configuration
- Used when establishing MQTT connections
### Data Storage
In browser mode, all data is stored on the server:
- Credentials: `data/credentials.json`
- Uploaded certificates: `data/certificates/`
- File uploads: `data/uploads/`
### Port Configuration
The default port is 3000. You can change it using the `PORT` environment variable:
```bash
PORT=8080 yarn start:server
```
## Architecture
### Client-Server Communication
- **Electron Mode**: Uses Electron IPC for communication between renderer and main process
- **Browser Mode**: Uses Socket.io WebSockets for real-time communication between browser and server
The application automatically detects the environment and uses the appropriate transport layer.
### Event Bus Abstraction
Both Electron IPC and Socket.io implement the same `EventBusInterface`, allowing the application code to work seamlessly in both modes without modification.
## Differences from Electron Mode
### Browser Mode Limitations
1. **File System Access**: Limited to server-side operations
2. **Native Dialogs**: File selection uses browser file input instead of native dialogs
3. **Auto-Updates**: Not available in browser mode
4. **Tray Icon**: Not available in browser mode
### Browser Mode Advantages
1. **No Installation**: Access from any browser
2. **Cross-Platform**: Works on any device with a modern browser
3. **Remote Access**: Can be deployed on a server for remote access
4. **Multi-User**: Can support authentication for multiple users
## Security Considerations
### Production Deployment
**CRITICAL**: The following security measures must be implemented for production deployments:
#### 1. HTTPS/TLS Encryption
Always use HTTPS in production to protect credentials and MQTT data in transit:
```bash
# Use a reverse proxy like nginx or Apache with TLS
# Example nginx configuration:
server {
listen 443 ssl http2;
server_name mqtt-explorer.example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
```
#### 2. Environment Variables for Credentials
**NEVER** use generated credentials in production. Always set secure credentials via environment variables:
```bash
export MQTT_EXPLORER_USERNAME=your_secure_username
export MQTT_EXPLORER_PASSWORD=your_strong_password_min_12_chars
export NODE_ENV=production
yarn start:server
```
#### 3. CORS Configuration
Configure allowed origins instead of using the wildcard (`*`):
```bash
# Single origin
export ALLOWED_ORIGINS=https://mqtt-explorer.example.com
# Multiple origins (comma-separated)
export ALLOWED_ORIGINS=https://app1.example.com,https://app2.example.com
yarn start:server
```
In production with `NODE_ENV=production`, wildcard CORS is automatically disabled for security.
#### 4. Network Security
- Deploy behind a firewall or VPN
- Use IP whitelisting if possible
- Implement network-level rate limiting
- Monitor for suspicious connection patterns
#### 5. File Upload Security
The server implements several protections against malicious file uploads:
- Maximum file size: 16MB (configurable via `MAX_FILE_SIZE` constant)
- Path traversal protection via filename sanitization
- Files stored in isolated directories
- Real path validation to prevent directory escapes
#### 6. Authentication Security
The server implements multiple layers of authentication security:
- **Password Hashing**: bcrypt with 10 rounds
- **Timing Attack Protection**: Constant-time string comparison for usernames
- **Rate Limiting**: Maximum 5 failed attempts per IP per 15 minutes
- **Session Tracking**: Failed attempts are tracked per client IP
- **No Credential Logging**: In production mode, credentials are not logged
#### 7. HTTP Security Headers
The server uses helmet.js to set security headers:
- Content Security Policy (CSP)
- HTTP Strict Transport Security (HSTS) in production
- X-Content-Type-Options: nosniff
- X-Frame-Options: DENY
- X-XSS-Protection
### Security Best Practices
1. **Rotate Credentials Regularly**: Change authentication credentials periodically
2. **Monitor Logs**: Watch for authentication failures and unusual patterns
3. **Keep Dependencies Updated**: Run `yarn audit` regularly
4. **Limit Network Exposure**: Don't expose the server directly to the internet
5. **Use Strong Passwords**: Minimum 12 characters with mixed case, numbers, and symbols
6. **Enable Logging**: Monitor access logs and error logs
7. **Regular Backups**: Back up configuration and certificate data
8. **Principle of Least Privilege**: Run the server with minimal required permissions
### Vulnerability Reporting
If you discover a security vulnerability, please report it via:
- GitHub Security Advisories
- Email to the maintainer
- Do NOT create public issues for security vulnerabilities
### Security Audit Log
- **2024-12**: Initial security review and hardening
- Added helmet.js for HTTP security headers
- Implemented rate limiting for authentication
- Added path traversal protection
- Implemented constant-time comparison for credentials
- Added input validation and size limits
- Removed credential logging in production
- Added configurable CORS origins
- Created comprehensive security test suite
## Security Considerations (Legacy)
1. **HTTPS**: For production, always use HTTPS to encrypt credentials and MQTT data
2. **Authentication**: Keep credentials secure and rotate them regularly
3. **Network**: Ensure the server is on a trusted network or behind a firewall
4. **Environment Variables**: Use environment variables for production credentials, not the generated ones
## Deployment
For production deployment:
1. Build the application:
```bash
yarn build:server
```
2. Set environment variables:
```bash
export MQTT_EXPLORER_USERNAME=your_username
export MQTT_EXPLORER_PASSWORD=your_secure_password
export PORT=3000
```
3. Start the server:
```bash
yarn start:server
```
4. Use a reverse proxy (nginx, Apache) to add HTTPS and additional security features
## Troubleshooting
### Debugging
Enable detailed Socket.IO connection and lifecycle debugging:
```bash
DEBUG=mqtt-explorer:socketio* yarn start:server
```
Available debug namespaces:
- `mqtt-explorer:socketio` - General Socket.IO events and metrics
- `mqtt-explorer:socketio:connect` - Client connection events
- `mqtt-explorer:socketio:disconnect` - Client disconnection and cleanup
- `mqtt-explorer:socketio:subscriptions` - Subscription lifecycle tracking
- `mqtt-explorer:socketio:connections` - MQTT connection ownership
This will log:
- Client connect/disconnect events
- Subscription counts per socket
- MQTT connection ownership tracking
- Memory leak detection metrics (subscriptions, handlers, connections)
Example output:
```
mqtt-explorer:socketio:connect Client connected: abc123de
mqtt-explorer:socketio [connect] clients=1 subscriptions=8 mqttConns=0 | socket[abc123de]: subs=8 conns=0
mqtt-explorer:socketio:connections Connection my-mqtt owned by socket abc123de (total: 1)
mqtt-explorer:socketio:disconnect Client disconnected: abc123de
mqtt-explorer:socketio:subscriptions Removed 8 subscriptions for socket abc123de
mqtt-explorer:socketio [disconnect] clients=0 subscriptions=0 mqttConns=0 | socket[abc123de]: subs=0 conns=0
```
### Authentication Fails
1. Check the console output for the generated credentials
2. Clear browser session storage: `sessionStorage.clear()` in browser console
3. Restart the server to regenerate credentials
### Connection Issues
1. Check that the server is running: `http://localhost:3000`
2. Check browser console for Socket.io connection errors
3. Verify firewall rules allow the port
### Certificate Upload Issues
In browser mode, certificates are handled differently:
- Use the file upload button to select certificate files
- Files are read and encoded client-side
- Large certificate files (>16KB) will be rejected
-329
View File
@@ -1,329 +0,0 @@
# CI/CD Pipeline Documentation
## Overview
MQTT Explorer uses GitHub Actions for continuous integration and testing. The pipeline tests both Electron (desktop) and browser modes.
## Workflows
### Test Workflow (`.github/workflows/tests.yml`)
This workflow runs on pull requests to `master`, `beta`, and `release` branches.
### Docker Browser Build Workflow (`.github/workflows/docker-browser.yml`)
This workflow builds and publishes a Docker image for the browser mode.
**Triggers**:
- Push to `master`, `beta`, or `release` branches (when relevant files change)
- Schedule: Runs every two weeks (1st and 15th of each month at 2:00 AM UTC)
- Manual trigger via workflow_dispatch
**Platforms**:
- linux/amd64 (x86-64)
- linux/arm64 (Raspberry Pi 3/4/5, Apple Silicon)
- linux/arm/v7 (Raspberry Pi 2/3)
**Image Registry**: GitHub Container Registry (ghcr.io/thomasnordquist/mqtt-explorer)
**Tags**:
- `latest` - Latest build from master branch
- `master` - Latest build from master
- `beta` - Latest build from beta branch
- `release` - Latest build from release branch
- `<branch>-<sha>` - Specific commit builds
**Steps**:
1. Build Docker image with multi-stage build
2. Test basic startup with test credentials
3. Test health check
4. Verify HTTP response
5. Test data directory creation
6. Check Docker image size
7. Setup Node.js 24 for browser tests
8. Install dependencies for browser tests
9. Install Playwright browsers (`npx playwright install --with-deps chromium`)
10. Start container for browser tests
11. Run browser test suite with Playwright
12. Push image to GitHub Container Registry
13. Generate build attestation for supply chain security
**Image Features**:
- Multi-stage build for minimal size
- Alpine Linux base with Node.js 24 (~200MB final image)
- Multi-platform support (amd64, arm64, arm/v7)
- Non-root user (UID 1001)
- Health check endpoint
- Proper signal handling with dumb-init
- Persistent data volume at `/app/data`
### Test Workflow (`.github/workflows/tests.yml`)
This workflow runs on pull requests to `master`, `beta`, and `release` branches.
#### Jobs
##### 1. `test` - Electron Mode Tests
Tests the traditional Electron desktop application:
- **Environment**: Custom Docker container (`ghcr.io/thomasnordquist/mqtt-explorer-ui-tests:latest`)
- Based on Node.js 24
- Includes Xvfb for headless display
- Includes FFmpeg for video recording
- Includes Mosquitto MQTT broker
- **Playwright browsers pre-installed** with system dependencies
- **Steps**:
1. Install dependencies with frozen lockfile
2. Build the Electron application
3. Run unit tests (app + backend)
4. Run UI tests with video recording
5. Upload test video to S3 with 90-day expiration tag
6. Post demo video to PR as comment
7. Display test results in GitHub summary
**Artifacts**:
- UI test video (GIF format) uploaded to S3 using AWS CLI
- Video is tagged with `expiration=90days` for automatic lifecycle deletion
- Video is posted to the PR thread as an embedded image
- Videos expire after 90 days via S3 lifecycle policy
##### 2. `test-browser` - Browser Mode Tests
Tests the new browser/server mode:
- **Environment**: Ubuntu latest with Node.js 24
- **MQTT Broker**: Mosquitto v2 on port 1883
- Started detached with `-d` flag
- Anonymous connections allowed
- No persistence
- **Steps**:
1. Install and start Mosquitto in detached mode
2. Setup Node.js 24
3. Install dependencies
4. Install Playwright browsers (`npx playwright install --with-deps chromium`)
5. Build browser mode (`yarn build:server`)
6. Run unit tests (app + backend)
7. Start server in background with test credentials
8. Wait for server to be ready
9. Run browser smoke tests
10. Clean up server process
**Environment Variables**:
- `MQTT_EXPLORER_USERNAME=test`
- `MQTT_EXPLORER_PASSWORD=test123`
- `PORT=3000`
## Test Commands
The following npm scripts are used in CI/CD:
```bash
# Unit tests
yarn test # Run all tests (app + backend)
yarn test:app # Frontend tests only
yarn test:backend # Backend tests only
# Build
yarn build # Build Electron mode
yarn build:server # Build browser mode
# UI Tests (Electron only)
yarn ui-test # Run UI tests with video recording
```
## Adding New Tests
### For Electron Mode
Add tests to the `test` job. UI tests should be added to the test suite that `yarn ui-test` runs.
### For Browser Mode
Browser-specific tests should:
1. Use the pre-configured Mosquitto service
2. Connect to `mqtt://mosquitto:1883`
3. Test server endpoints at `http://localhost:3000`
Example:
```yaml
- name: Browser Integration Test
run: |
# Test MQTT connection through server
curl -X POST http://localhost:3000/api/test
```
## Local Testing
### Docker Browser Mode
```bash
# Build the image locally (for your platform)
docker build -f Dockerfile.browser -t mqtt-explorer:local .
# Build for specific platform (e.g., Raspberry Pi)
docker buildx build --platform linux/arm64 -f Dockerfile.browser -t mqtt-explorer:local-arm64 .
# Run the container
docker run -d \
-p 3000:3000 \
-e MQTT_EXPLORER_USERNAME=test \
-e MQTT_EXPLORER_PASSWORD=test123 \
mqtt-explorer:local
# Test the server
curl http://localhost:3000
# Check logs
docker logs <container-id>
# Stop and remove
docker stop <container-id>
docker rm <container-id>
```
See [DOCKER.md](DOCKER.md) for complete documentation.
### Electron Mode
```bash
yarn build
yarn test
yarn ui-test
```
### Browser Mode
```bash
# Start Mosquitto in Docker
docker run -d -p 1883:1883 eclipse-mosquitto:2
# Build and test
yarn build:server
yarn test
# Start server
MQTT_EXPLORER_USERNAME=test MQTT_EXPLORER_PASSWORD=test123 yarn start:server
# Run manual tests
curl http://localhost:3000
```
## GitHub Codespaces / Devcontainer
The repository includes a devcontainer configuration that automatically sets up:
- Node.js 20
- MQTT broker (Mosquitto)
- All development dependencies
- Port forwarding for development
See [.devcontainer/README.md](.devcontainer/README.md) for details.
## S3 Configuration for Demo Videos
### Required S3 Lifecycle Policy
Demo videos uploaded from PRs are tagged with `expiration=90days` and require an S3 lifecycle policy to automatically delete them after 90 days.
**Important**: The `video.mp4` file in the gh-pages branch is NOT tagged and will NOT expire.
#### Setting up the Lifecycle Policy
1. Create a file named `s3-lifecycle-pr-videos.json`:
```json
{
"Rules": [
{
"ID": "ExpirePRDemoVideosAfter90Days",
"Status": "Enabled",
"Filter": {
"Tag": {
"Key": "expiration",
"Value": "90days"
}
},
"Expiration": {
"Days": 90
}
}
]
}
```
2. Apply the policy to your S3 bucket:
```bash
aws s3api put-bucket-lifecycle-configuration \
--bucket YOUR_BUCKET_NAME \
--lifecycle-configuration file://s3-lifecycle-pr-videos.json
```
3. Verify the policy:
```bash
aws s3api get-bucket-lifecycle-configuration --bucket YOUR_BUCKET_NAME
```
#### How It Works
- **PR demo videos**: Uploaded with filename pattern `pr-{number}-{timestamp}.gif` and tagged with:
- `expiration=90days` - Used by lifecycle policy for automatic deletion
- `Source=github-actions` - Identifies source of upload
- `Type=pr-demo-video` - Categorizes the object type
- **S3 lifecycle rule**: Automatically deletes objects tagged with `expiration=90days` after 90 days
- **Upload mechanism**: AWS CLI v2 is installed directly, authentication is configured via `aws-actions/configure-aws-credentials@v4` GitHub Action, then `aws s3api put-object` is used with object tagging support
- **gh-pages video**: `video.mp4` in gh-pages branch is served from GitHub Pages, not S3, so it persists indefinitely
#### Required AWS Credentials
The workflow requires the following secrets/variables:
- `vars.AWS_KEY_ID` - AWS access key ID (requires `s3:PutObject` and `s3:PutObjectTagging` permissions)
- `secrets.AWS_SECRET_ACCESS_KEY` - AWS secret access key
- `vars.AWS_BUCKET` - S3 bucket name
- AWS region: `eu-central-1` (hardcoded in workflow)
The S3 bucket must have:
- **Bucket policy for public read access**: Since ACLs are disabled (BucketOwnerEnforced), a bucket policy must grant public read access to uploaded objects
- Object tagging enabled
- Lifecycle policy configured as described above
**Example S3 Bucket Policy for Public Read Access**:
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/*"
}
]
}
```
The workflow uses AWS CLI v2 installed directly and `aws-actions/configure-aws-credentials@v4` action for secure credential management.
## Troubleshooting
### Browser Tests Failing
1. **Server won't start**: Check if port 3000 is already in use
2. **MQTT connection fails**: Ensure Mosquitto service is healthy
3. **Timeout errors**: Increase timeout in "Wait for Server" step
### Electron Tests Failing
1. **UI tests timeout**: Check if the Docker container has display access
2. **Build fails**: Verify all dependencies are in yarn.lock
## Future Improvements
- [x] Add Playwright browser installation to workflows (browser tests can now use Playwright)
- [ ] Add E2E browser tests with Playwright
- [ ] Test WebSocket connections in browser mode
- [ ] Add performance benchmarks
- [ ] Test with different MQTT broker versions
- [ ] Add security scanning for browser mode
-334
View File
@@ -1,334 +0,0 @@
# Debug Output Examples
This document shows examples of the enhanced debug output added to MQTT Explorer's AI Assistant.
## Frontend Debug View
Click the bug icon (🐛) in the AI Assistant header to toggle the debug view.
### Example Debug Output
```json
{
"systemMessage": {
"role": "system",
"content": "You are an expert AI assistant specializing in MQTT (Message Queuing Telemetry Transport) protocol and home/industrial automation systems.\n\n**Your Core Expertise:**\n- MQTT protocol: topics, QoS levels, retained messages, wildcards, last will and testament\n- IoT and smart home ecosystems: devices, sensors, actuators, and controllers\n- Home automation platforms: Home Assistant, openHAB, Node-RED, MQTT brokers, zigbee2mqtt, tasmota\n- Common MQTT topic patterns and naming conventions (e.g., zigbee2mqtt, tasmota, homie)\n- Data formats: JSON payloads, binary data, sensor readings, state messages\n- Time-series data analysis and pattern recognition\n- Troubleshooting connectivity, message delivery, and data quality issues\n\n**Your Communication Style:**\n- Keep your TEXT response CONCISE and practical (2-3 sentences maximum for the explanation)\n- Use clear technical language appropriate for users familiar with MQTT\n- When analyzing data, identify patterns, anomalies, or potential issues quickly\n- Suggest practical next steps or automations when relevant\n- Reference common MQTT ecosystems and standards when applicable\n- NOTE: Proposals and question suggestions are OUTSIDE the sentence limit - always include them when relevant\n...",
"note": "This is the system prompt that provides context to the LLM"
},
"messages": [
{
"index": 0,
"role": "user",
"content": "What does this topic do?",
"fullContent": "Context:\nTopic: home/livingroom/light\nValue: {\"state\":\"ON\",\"brightness\":255}\nRetained: true\n\nRelated Topics (3):\n home/livingroom/thermostat: 21.5\n home/livingroom/motion: false\n home/livingroom/light/set: \n\nMessages: 42\nSubtopics: 3\n\nUser Question: What does this topic do?",
"timestamp": "2026-01-30T13:20:15.123Z",
"proposals": 0,
"questionProposals": 0,
"apiDebug": {
"provider": "openai",
"model": "gpt-5-mini",
"timing": {
"duration_ms": 1234,
"timestamp": "2026-01-30T13:20:15.123Z"
},
"request": {
"url": "https://api.openai.com/v1/chat/completions",
"body": {
"model": "gpt-5-mini",
"messages": [
{
"role": "system",
"content": "You are an expert AI assistant..."
},
{
"role": "user",
"content": "Context:\nTopic: home/livingroom/light\n..."
}
],
"max_completion_tokens": 500
}
},
"response": {
"id": "chatcmpl-AbCdEfGh123456",
"model": "gpt-5-mini",
"created": 1738247815,
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "This topic represents a smart light in your living room..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 156,
"completion_tokens": 98,
"total_tokens": 254
},
"system_fingerprint": "fp_abc123def456"
}
}
},
{
"index": 1,
"role": "assistant",
"content": "This topic represents a smart light in your living room...",
"fullContent": "This topic represents a smart light in your living room. It's currently ON at full brightness (255). The topic follows a typical Home Assistant or MQTT smart home pattern.\n\n```proposal\n{\n \"topic\": \"home/livingroom/light/set\",\n \"payload\": \"OFF\",\n \"qos\": 0,\n \"description\": \"Turn off the living room light\"\n}\n```",
"timestamp": "2026-01-30T13:20:16.357Z",
"proposals": 1,
"questionProposals": 2
}
],
"summary": {
"totalMessages": 2,
"messagesWithDebugInfo": 1,
"lastApiCall": "2026-01-30T13:20:15.123Z"
}
}
```
## Server Console Output
### Example Request Log
```
================================================================================
LLM REQUEST (OpenAI)
================================================================================
Provider: openai
Model: gpt-5-mini
Messages Count: 2
Full Request Body:
{
model: 'gpt-5-mini',
messages: [
{
role: 'system',
content: 'You are an expert AI assistant specializing in MQTT (Message Queuing Telemetry Transport) protocol and home/industrial automation systems.\n' +
'\n' +
'**Your Core Expertise:**\n' +
'- MQTT protocol: topics, QoS levels, retained messages, wildcards, last will and testament\n' +
'- IoT and smart home ecosystems: devices, sensors, actuators, and controllers\n' +
'- Home automation platforms: Home Assistant, openHAB, Node-RED, MQTT brokers, zigbee2mqtt, tasmota\n' +
'- Common MQTT topic patterns and naming conventions (e.g., zigbee2mqtt, tasmota, homie)\n' +
'- Data formats: JSON payloads, binary data, sensor readings, state messages\n' +
'- Time-series data analysis and pattern recognition\n' +
'- Troubleshooting connectivity, message delivery, and data quality issues\n' +
'\n' +
'**Your Communication Style:**\n' +
'- Keep your TEXT response CONCISE and practical (2-3 sentences maximum for the explanation)\n' +
'- Use clear technical language appropriate for users familiar with MQTT\n' +
'- When analyzing data, identify patterns, anomalies, or potential issues quickly\n' +
'- Suggest practical next steps or automations when relevant\n' +
'- Reference common MQTT ecosystems and standards when applicable\n' +
'- NOTE: Proposals and question suggestions are OUTSIDE the sentence limit - always include them when relevant\n' +
'...'
},
{
role: 'user',
content: 'Context:\n' +
'Topic: home/livingroom/light\n' +
'Value: {"state":"ON","brightness":255}\n' +
'Retained: true\n' +
'\n' +
'Related Topics (3):\n' +
' home/livingroom/thermostat: 21.5\n' +
' home/livingroom/motion: false\n' +
' home/livingroom/light/set: \n' +
'\n' +
'Messages: 42\n' +
'Subtopics: 3\n' +
'\n' +
'User Question: What does this topic do?'
}
],
max_completion_tokens: 500
}
System Message:
{
role: 'system',
content: 'You are an expert AI assistant specializing in MQTT (Message Queuing Telemetry Transport) protocol and home/industrial automation systems.\n' +
'\n' +
'**Your Core Expertise:**\n' +
'- MQTT protocol: topics, QoS levels, retained messages, wildcards, last will and testament\n' +
'...'
}
================================================================================
```
### Example Response Log
```
================================================================================
LLM RESPONSE (OpenAI)
================================================================================
Duration: 1234 ms
Full Response:
{
id: 'chatcmpl-AbCdEfGh123456',
object: 'chat.completion',
created: 1738247815,
model: 'gpt-5-mini',
choices: [
{
index: 0,
message: {
role: 'assistant',
content: 'This topic represents a smart light in your living room. It\'s currently ON at full brightness (255). The topic follows a typical Home Assistant or MQTT smart home pattern.\n' +
'\n' +
'```proposal\n' +
'{\n' +
' "topic": "home/livingroom/light/set",\n' +
' "payload": "OFF",\n' +
' "qos": 0,\n' +
' "description": "Turn off the living room light"\n' +
'}\n' +
'```\n' +
'\n' +
'```question-proposal\n' +
'{\n' +
' "question": "What other devices are in the living room?",\n' +
' "category": "analysis"\n' +
'}\n' +
'```\n' +
'\n' +
'```question-proposal\n' +
'{\n' +
' "question": "How can I dim the light to 50%?",\n' +
' "category": "control"\n' +
'}\n' +
'```'
},
logprobs: null,
finish_reason: 'stop'
}
],
usage: {
prompt_tokens: 156,
completion_tokens: 98,
total_tokens: 254
},
system_fingerprint: 'fp_abc123def456'
}
================================================================================
================================================================================
LLM RPC HANDLER - Returning response
================================================================================
Response length: 456
Has debugInfo: true
================================================================================
```
### Example Error Log
If an error occurs:
```
================================================================================
LLM RPC ERROR
================================================================================
Error message: Invalid API key configuration
Error stack: Error: Invalid API key configuration
at /home/runner/work/MQTT-Explorer/MQTT-Explorer/dist/src/server.js:642:15
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Full error: Error: Invalid API key configuration
at /home/runner/work/MQTT-Explorer/MQTT-Explorer/dist/src/server.js:642:15 {
status: 401,
type: 'invalid_request_error',
code: 'invalid_api_key'
}
================================================================================
```
## Browser Console Output
### Normal Flow
```javascript
LLM Service: Received result from backend: {
response: "This topic represents a smart light...",
debugInfo: {
provider: "openai",
model: "gpt-5-mini",
timing: { duration_ms: 1234, timestamp: "2026-01-30T13:20:15.123Z" },
request: { url: "...", body: {...} },
response: { id: "chatcmpl-...", usage: {...} }
}
}
LLM Service: Has response: true
LLM Service: Has debugInfo: true
LLM Service: Assistant message length: 456
LLM Service: Debug info: { provider: "openai", model: "gpt-5-mini", ... }
```
### Error Flow
```javascript
LLM Service: Received result from backend: undefined
LLM Service: Has response: false
LLM Service: Has debugInfo: false
LLM Service: Invalid result from backend: undefined
AI Assistant error: Error: No response from AI assistant
at LLMService.sendMessage (llmService.ts:440)
Error details: { message: "No response from AI assistant" }
```
## Key Features
### No Truncation
Notice how the system message and all content is shown in full, without any "..." truncation:
- **Before:** Objects were truncated at depth 2, arrays at 10 items
- **After:** Complete objects shown with `depth: null`, full arrays with `maxArrayLength: null`
### Color Coding
In the terminal, the output is color-coded:
- Strings: Green
- Numbers: Yellow
- Booleans: Yellow
- Null/Undefined: Gray
- Object keys: Cyan
### Visual Separators
Clear visual boundaries between sections:
- `===` lines separate major sections
- Consistent formatting makes scanning easier
- Duration and timing info highlighted
### Complete Context
Every debug output includes:
- **What**: The operation being performed
- **When**: Timestamp and duration
- **How**: Complete request parameters
- **Result**: Complete response data
- **Why** (if error): Full error with stack trace
## Usage Tips
1. **Finding Issues**: Look for the last successful log before error
2. **Performance**: Check `duration_ms` for slow requests
3. **Token Usage**: Monitor `usage.total_tokens` to track costs
4. **Content Issues**: Check `fullContent` to see what was actually sent
5. **System Prompt**: Review `systemMessage` to verify LLM instructions
## Production Considerations
While these logs are comprehensive, in production you may want to:
1. **Add log levels**: Use DEBUG level for detailed logs
2. **Reduce verbosity**: Only log errors in production
3. **Sampling**: Log only 1% of requests for monitoring
4. **Remove colors**: Disable ANSI colors for log aggregation tools
5. **PII filtering**: Redact sensitive data from logs
Current implementation is optimized for development and debugging.
-285
View File
@@ -1,285 +0,0 @@
# MQTT Explorer - Docker Browser Mode
Docker image for running MQTT Explorer in browser mode.
## Try It Now
[![Try in PWD](https://raw.githubusercontent.com/play-with-docker/stacks/master/assets/images/button.png)](https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/thomasnordquist/MQTT-Explorer/master/docker-compose.yml)
Click the badge above to instantly try MQTT Explorer in your browser using Play with Docker (requires free Docker Hub account).
## Quick Start
### Using Pre-built Image
Pull and run the latest image from GitHub Container Registry:
```bash
docker pull ghcr.io/thomasnordquist/mqtt-explorer:latest
docker run -d \
-p 3000:3000 \
-e MQTT_EXPLORER_USERNAME=admin \
-e MQTT_EXPLORER_PASSWORD=your_secure_password \
-v mqtt-explorer-data:/app/data \
--name mqtt-explorer \
ghcr.io/thomasnordquist/mqtt-explorer:latest
```
Access the application at `http://localhost:3000`
### Using Docker Compose
Create a `docker-compose.yml` file:
```yaml
version: '3.8'
services:
mqtt-explorer:
image: ghcr.io/thomasnordquist/mqtt-explorer:latest
ports:
- "3000:3000"
environment:
- MQTT_EXPLORER_USERNAME=admin
- MQTT_EXPLORER_PASSWORD=your_secure_password
- PORT=3000
volumes:
- mqtt-explorer-data:/app/data
restart: unless-stopped
volumes:
mqtt-explorer-data:
```
Then run:
```bash
docker-compose up -d
```
## Environment Variables
| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `MQTT_EXPLORER_USERNAME` | No | Generated | Username for authentication |
| `MQTT_EXPLORER_PASSWORD` | No | Generated | Password for authentication |
| `MQTT_EXPLORER_SKIP_AUTH` | No | `false` | Set to `true` to disable authentication (use only behind a secure proxy!) |
| `PORT` | No | `3000` | Port the server listens on |
| `ALLOWED_ORIGINS` | No | `*` | Comma-separated list of allowed CORS origins |
| `NODE_ENV` | No | - | Set to `production` for production deployments |
| `UPGRADE_INSECURE_REQUESTS` | No | `false` | Set to `true` to enable CSP upgrade-insecure-requests directive. **Only use when deployed behind an HTTPS reverse proxy (nginx, Traefik, etc.) with valid SSL certificates.** This upgrades all HTTP requests to HTTPS and will break direct HTTP access. |
| `X_FRAME_OPTIONS` | No | `false` | Set to `true` to enable X-Frame-Options: SAMEORIGIN header to prevent clickjacking. **Disables iframe embedding when enabled.** |
### AI Assistant / LLM Configuration
| Variable | Required | Default | Description |
|----------|----------|---------|-------------|
| `LLM_PROVIDER` | No | `openai` | AI provider to use (`openai` or `gemini`) |
| `OPENAI_API_KEY` | No | - | OpenAI API key for AI Assistant (provider-specific) |
| `GEMINI_API_KEY` | No | - | Google Gemini API key for AI Assistant (provider-specific) |
| `LLM_API_KEY` | No | - | Generic API key for AI Assistant (works with either provider) |
| `LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT` | No | `500` | Token limit for neighboring topics context in AI queries (increased for better device relationship detection) |
**Architecture**: The backend proxies all LLM API requests via WebSocket RPC. API keys are **never** sent to the frontend - only an availability flag is transmitted. The frontend calls the backend via WebSocket RPC (`llm/chat` event), and the backend makes requests to OpenAI/Gemini on behalf of the client.
**Security**:
- ✅ API keys remain server-side only
- ✅ Keys never embedded in client bundles
- ✅ Keys never transmitted to frontend
- ✅ Backend controls all LLM access
- ✅ Communication via secure WebSocket RPC
**Note**: If no LLM environment variables are set, the AI Assistant feature will be completely hidden from users.
**Example with AI Assistant**:
```bash
docker run -d \
-p 3000:3000 \
-e MQTT_EXPLORER_USERNAME=admin \
-e MQTT_EXPLORER_PASSWORD=secret \
-e LLM_PROVIDER=openai \
-e OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxx \
-e LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT=500 \
ghcr.io/thomasnordquist/mqtt-explorer:latest
```
### Authentication Modes
**Standard Mode (Default):**
- Requires username and password for access
- Credentials can be set via environment variables or auto-generated
- Auto-generated credentials are logged on first startup and saved to `/app/data/credentials.json`
**Skip Authentication Mode (Use with caution!):**
```bash
docker run -d -p 3000:3000 \
-e MQTT_EXPLORER_SKIP_AUTH=true \
ghcr.io/thomasnordquist/mqtt-explorer:latest
```
⚠️ **WARNING**: When `MQTT_EXPLORER_SKIP_AUTH=true`, the application is **completely open** without any authentication. This should **only be used** when MQTT Explorer is deployed behind a secure authentication proxy (e.g., OAuth2 Proxy, Authelia, Nginx with auth_request) or in a trusted private network.
**Recommended use case**: Integration with enterprise SSO systems where authentication is handled by a reverse proxy.
**Note**: If credentials are not provided and auth is not skipped, they will be auto-generated and stored in `/app/data/credentials.json`. Check the container logs to see the generated credentials:
```bash
docker logs mqtt-explorer
```
## Data Persistence
The container stores data in `/app/data`, including:
- User credentials (`credentials.json`)
- Connection settings (`settings.json`)
- Uploaded certificates (`certificates/`)
- File uploads (`uploads/`)
Mount a volume to persist data across container restarts:
```bash
docker run -v mqtt-explorer-data:/app/data ...
```
## Building from Source
Build the Docker image locally:
```bash
docker build -f Dockerfile.browser -t mqtt-explorer:local .
```
Run the locally built image:
```bash
docker run -d \
-p 3000:3000 \
-e MQTT_EXPLORER_USERNAME=admin \
-e MQTT_EXPLORER_PASSWORD=secret \
mqtt-explorer:local
```
## Health Check
The container includes a health check that runs every 30 seconds. Check the health status:
```bash
docker inspect --format='{{.State.Health.Status}}' mqtt-explorer
```
## Security Best Practices
1. **Use HTTPS in Production**: Put the container behind a reverse proxy (nginx, Traefik) with HTTPS
2. **Set Strong Credentials**: Always set custom credentials via environment variables
3. **Network Isolation**: Run in a private network when possible
4. **Update Regularly**: Pull the latest image regularly for security updates
### Example with Nginx Reverse Proxy
```nginx
server {
listen 443 ssl http2;
server_name mqtt-explorer.example.com;
ssl_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
```
## Troubleshooting
### Container won't start
Check the logs:
```bash
docker logs mqtt-explorer
```
### Can't access the application
1. Verify the container is running: `docker ps`
2. Check the port mapping: `docker port mqtt-explorer`
3. Test connectivity: `curl http://localhost:3000`
### Authentication issues
1. Check generated credentials in logs: `docker logs mqtt-explorer`
2. Verify environment variables: `docker inspect mqtt-explorer`
3. Reset credentials by removing the data volume and restarting
### Permission issues
The container runs as a non-root user (UID 1001). If mounting host directories, ensure they're writable:
```bash
chown -R 1001:1001 /path/to/host/data
docker run -v /path/to/host/data:/app/data ...
```
## Available Tags
- `latest` - Latest stable version from the master branch
- `master` - Latest build from master branch
- `beta` - Latest beta version
- `release` - Latest release version
- `master-<sha>` - Specific commit from master
- `beta-<sha>` - Specific commit from beta
- `release-<sha>` - Specific commit from release
## Supported Platforms
The Docker image is built for multiple architectures:
- `linux/amd64` - x86-64 (standard PCs, servers)
- `linux/arm64` - ARM 64-bit (Raspberry Pi 3/4/5, Apple Silicon)
- `linux/arm/v7` - ARM 32-bit (Raspberry Pi 2/3)
## One-Click Deployment Options
### Play with Docker (Free)
Try MQTT Explorer instantly in your browser without installing anything:
[![Try in PWD](https://raw.githubusercontent.com/play-with-docker/stacks/master/assets/images/button.png)](https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/thomasnordquist/MQTT-Explorer/master/docker-compose.yml)
- **No installation required** - Runs entirely in your browser
- **Free to use** - Requires only a Docker Hub account
- **Perfect for demos** - Great for testing and demonstrations
- **4-hour sessions** - Sessions automatically expire after 4 hours
### Cloud Platforms
Deploy MQTT Explorer to various cloud platforms with one click:
#### DigitalOcean App Platform
[![Deploy to DO](https://www.deploytodo.com/do-btn-blue.svg)](https://cloud.digitalocean.com/apps/new?repo=https://github.com/thomasnordquist/MQTT-Explorer/tree/master&refcode=docker)
- Automatically detects Docker configuration
- Managed platform with auto-scaling
- Starting at $5/month
#### Koyeb
[![Deploy to Koyeb](https://www.koyeb.com/static/images/deploy/button.svg)](https://app.koyeb.com/deploy?type=docker&name=mqtt-explorer&image=ghcr.io/thomasnordquist/mqtt-explorer:latest&ports=3000;http;/)
- Deploy directly from Docker image
- Global edge network
- Free tier available
**Note:** Remember to set the environment variables `MQTT_EXPLORER_USERNAME` and `MQTT_EXPLORER_PASSWORD` when deploying to cloud platforms.
## License
See the main [LICENSE.md](LICENSE.md) file.
-69
View File
@@ -1,69 +0,0 @@
# Multi-stage build for MQTT Explorer Browser Mode
# Stage 1: Build and prepare production dependencies
FROM node:22-alpine AS builder
WORKDIR /build
# Copy all source files and dependencies
COPY package.json yarn.lock ./
COPY tsconfig.json ./
COPY src ./src
COPY backend ./backend
COPY events ./events
COPY app ./app
# Install ALL dependencies (needed for build)
RUN yarn install --frozen-lockfile --network-timeout 100000
# Build the application (compiles TypeScript and webpack bundles)
RUN yarn build:server
# Remove dev dependencies, keeping only production dependencies
RUN yarn install --production --frozen-lockfile --network-timeout 100000 && \
yarn cache clean && \
rm -rf /tmp/*
# Stage 2: Production
FROM node:22-alpine
# Install dumb-init in a single layer
RUN apk add --no-cache dumb-init
# Create app user in a single layer
RUN addgroup -g 1001 -S mqttexplorer && \
adduser -u 1001 -S mqttexplorer -G mqttexplorer
WORKDIR /app
# Copy ONLY the compiled dist folder (contains compiled TypeScript)
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/dist ./dist
# Copy ONLY the built frontend app
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/app/build ./app/build
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/app/index.html ./app/
# Copy runtime node_modules (production dependencies only)
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/node_modules ./node_modules
# Copy package.json for version info (needed by server)
COPY --from=builder --chown=mqttexplorer:mqttexplorer /build/package.json ./
# Create data directory for persistent storage
RUN mkdir -p /app/data && \
chown -R mqttexplorer:mqttexplorer /app/data
# Switch to non-root user
USER mqttexplorer
# Expose port
EXPOSE 3000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD node -e "const http = require('http'); const req = http.get('http://localhost:3000', (r) => process.exit(r.statusCode === 200 ? 0 : 1)); req.on('error', () => process.exit(1));"
# Use dumb-init to handle signals properly
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
# Start the server
CMD ["node", "dist/src/server.js"]
-200
View File
@@ -1,200 +0,0 @@
# Environment Variables for LLM Integration
This document provides examples of how to configure the AI Assistant using environment variables for server deployments.
## Basic Configuration
```bash
# Set up OpenAI as the provider
export LLM_PROVIDER=openai
export OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxx
# Or use Gemini
export LLM_PROVIDER=gemini
export GEMINI_API_KEY=AIzaxxxxxxxxxxxxxxxxxxxx
# Or use the generic LLM_API_KEY (works with either provider)
export LLM_PROVIDER=openai
export LLM_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxx
```
## Advanced Configuration
```bash
# Configure token limit for neighboring topics context
export LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT=500 # Default: 500 tokens (increased for better device detection)
# Example: Increase token limit for large home automation setups
export LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT=1000
# Example: Decrease token limit to reduce API costs (may reduce proposal quality)
export LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT=200
```
## Complete Example for Server Deployment
```bash
#!/bin/bash
# start-mqtt-explorer.sh
# MQTT Connection
export MQTT_EXPLORER_SKIP_AUTH=true # Or configure authentication
export MQTT_AUTO_CONNECT_HOST=mqtt.example.com
export MQTT_AUTO_CONNECT_PORT=1883
# LLM Configuration
export LLM_PROVIDER=gemini
export GEMINI_API_KEY=AIzaxxxxxxxxxxxxxxxxxxxx
export LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT=500
# Start the server
node dist/src/server.js
```
## Docker Example
```dockerfile
# Dockerfile
FROM node:24-alpine
WORKDIR /app
COPY . .
RUN yarn install && yarn build:server
# Environment variables can be set at runtime
ENV LLM_PROVIDER=openai
ENV LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT=500
EXPOSE 3000
CMD ["node", "dist/src/server.js"]
```
```bash
# Run with docker
docker run -d \
-e OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxx \
-e LLM_PROVIDER=openai \
-e LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT=500 \
-e MQTT_AUTO_CONNECT_HOST=mqtt.example.com \
-p 3000:3000 \
mqtt-explorer
```
## Context Generation with Token Limits
The `LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT` controls how many tokens are allocated for neighboring topics in the context. The default has been increased from 100 to 500 tokens to provide better device relationship detection and enable multi-device automation proposals.
### With Default 500 Tokens (Recommended)
```
Topic Path: home/living_room/light
Value: {"state":"ON","brightness":75,"color_temp":350}
Status: Retained
Related Topics (18 shown):
home/living_room: {"scene":"evening"}
home/living_room/thermostat: {"temperature":22.5,"target":23,"mode":"heat"}
home/living_room/motion: true
home/living_room/humidity: 65
home/living_room/light/set: (command topic)
home/living_room/light/availability: "online"
home/living_room/light/config: {"transition":0.5,"fade":true}
home/living_room/blinds: {"position":75,"state":"open"}
home/living_room/blinds/set: (command topic)
home/living_room/tv: {"power":"ON","input":"HDMI1"}
home/kitchen/light: {"state":"ON","brightness":100}
home/bedroom/light: {"state":"OFF"}
home/living_room/light/brightness/set: (command topic)
home/living_room/light/color/set: (command topic)
home/living_room/motion_sensor/battery: 95
home/living_room/motion_sensor/last_motion: "2026-01-27T19:45:30Z"
Message Count: 42
Subtopics: 5
```
**Benefits:** AI can see full room context (multiple devices), detect controllable devices (set topics), understand device hierarchies (parent/child relationships), and propose coordinated multi-device actions like "turn off all living room devices" or "set evening scene".
### With 200 Tokens (Reduced - May Miss Context)
```
Topic Path: home/living_room/light
Value: {"state":"ON","brightness":75,"color_temp":350}
Status: Retained
Related Topics (8 shown):
home/living_room: {"scene":"evening"}
home/living_room/thermostat: {"temperature":22.5,"target":23}
home/living_room/motion: true
home/living_room/light/set: (command topic)
home/living_room/blinds: {"position":75}
home/kitchen/light: {"state":"ON","brightness":100}
Message Count: 42
Subtopics: 5
```
**Limitations:** Less context = fewer multi-device proposals, may miss related devices in same room.
### With 1000 Tokens (Maximum - For Large Setups)
Use for extensive home automation with many rooms and devices. Provides comprehensive context including grandchildren, cousins, and extended device relationships.
## Priority Order
The AI Assistant checks configuration in this order:
1. **Environment Variables** (highest priority)
- Provider-specific: `OPENAI_API_KEY`, `GEMINI_API_KEY`
- Generic fallback: `LLM_API_KEY`
- Provider selection: `LLM_PROVIDER`
- Token limit: `LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT`
2. **localStorage** (browser/UI configuration)
- Set via the configuration dialog in the UI
- Only used if environment variables are not set
3. **Defaults** (lowest priority)
- Provider: `openai`
- Token limit: `100`
## Security Recommendations
- **Never commit API keys** to version control
- Use environment variables or secrets management
- In production, use `.env` files (not committed) or container secrets
- Rotate API keys regularly
- Monitor API usage and set billing alerts
## Troubleshooting
### API Key Not Working
Check priority order:
```bash
# Check if env vars are set
echo $OPENAI_API_KEY
echo $LLM_API_KEY
echo $LLM_PROVIDER
# Verify they're available to the Node process
node -e "console.log(process.env.OPENAI_API_KEY)"
```
### Token Limit Too Low
If you're seeing truncated context or poor multi-device proposals:
```bash
# Increase the token limit (recommended: 500-1000 for home automation)
export LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT=1000
```
**Note:** The default was increased from 100 to 500 tokens to better support:
- Multi-device detection and relationships
- Hierarchical topic structures (parent → children → grandchildren)
- Room-level automation proposals
- Complex home automation scenarios
### Want to Use UI Configuration
Simply don't set the environment variables - the UI configuration will be used instead.
-222
View File
@@ -1,222 +0,0 @@
# LLM Integration Implementation Summary
## Overview
This implementation adds an AI-powered assistant to MQTT Explorer that helps users interact with and understand MQTT topics using Large Language Models (LLMs). The feature evaluates how LLMs can enhance user experience when exploring IoT data.
## Implementation Approach
### Minimal, Surgical Changes
The implementation follows the principle of making the **smallest possible changes** to achieve the goal:
- **3 new files created**:
- `app/src/services/llmService.ts` (229 lines) - LLM service layer
- `app/src/components/Sidebar/AIAssistant.tsx` (387 lines) - UI component
- `LLM_INTEGRATION.md` (198 lines) - User documentation
- **1 existing file modified**:
- `app/src/components/Sidebar/DetailsTab.tsx` (4 lines changed) - Integration point
- **Total new code**: ~620 lines
- **Total modified code**: 4 lines
### Architecture
```
User Interface (React + Material-UI)
AIAssistant Component
LLMService (Singleton)
OpenAI API (via Axios)
```
## Key Features
### 1. Contextual Understanding
The AI assistant automatically extracts relevant context from selected MQTT topics:
- Topic path
- Message metadata (timestamp, QoS, retained status)
- Current value
- Message count and subtopics
### 2. Quick Suggestions
Pre-generated questions based on topic characteristics:
- "Explain this data structure" (for topics with payloads)
- "What does this value mean?" (for topics with values)
- "Summarize all subtopics" (for parent topics)
- "What can I do with this topic?" (universal suggestion)
### 3. Conversational Interface
- Chat-style interaction with message history
- Maintains context across multiple questions
- Collapsible panel to save screen space
- Loading states and error handling
### 4. Privacy-Conscious Design
- API keys stored locally (localStorage)
- No data sent to MQTT Explorer servers
- Clear documentation about data sharing with OpenAI
- User control over when to use the feature
## Code Quality
### TypeScript Best Practices
- ✅ Proper type definitions (no `any` types)
- ✅ Interface-based design
- ✅ Null safety with explicit checks
- ✅ Type guards for error handling
### Security
- ✅ CodeQL scan passed with 0 vulnerabilities
- ✅ API key stored securely in localStorage
- ✅ Rate limiting error handling
- ✅ Timeout protection (30s)
- ✅ Input validation
### Testing
- ✅ All existing unit tests pass (79 tests)
- ✅ Manual testing verified
- ✅ Cross-browser compatibility (tested in Chromium)
- ✅ No breaking changes to existing functionality
## User Experience
### Before
Users had to:
- Manually interpret MQTT message data
- Search documentation for MQTT concepts
- Use external tools to understand IoT data patterns
### After
Users can:
- Ask natural language questions about topics
- Get instant explanations of data structures
- Learn MQTT concepts in context
- Discover possibilities for topic usage
## Technical Highlights
### 1. Singleton Pattern for LLM Service
Ensures a single instance manages all API calls and conversation history:
```typescript
export function getLLMService(): LLMService {
if (!llmServiceInstance) {
llmServiceInstance = new LLMService()
}
return llmServiceInstance
}
```
### 2. Context Generation
Automatically extracts meaningful information from topics:
```typescript
public generateTopicContext(topic: TopicType): string {
const context = []
if (topic.path) context.push(`Topic Path: ${topic.path()}`)
if (topic.message) {
context.push(`Timestamp: ${topic.message.received}`)
context.push(`QoS: ${topic.message.qos}`)
// ... more context
}
return context.join('\n')
}
```
### 3. Conversation History Management
Maintains last 10 messages plus system prompt for efficient API usage:
```typescript
if (this.conversationHistory.length > 11) {
this.conversationHistory = [
this.conversationHistory[0], // System message
...this.conversationHistory.slice(-10) // Last 10 messages
]
}
```
### 4. Material-UI Integration
Follows existing design patterns with proper theming:
```typescript
const styles = (theme: Theme) => ({
root: {
marginTop: theme.spacing(2),
border: `1px solid ${theme.palette.divider}`,
borderRadius: theme.shape.borderRadius,
},
// ... consistent with existing components
})
```
## Evaluation Metrics
### How LLMs Help Users Interact with Topics
1. **Reduced Learning Curve**
- Users don't need to understand MQTT protocol details immediately
- Natural language interaction lowers barrier to entry
- Contextual help exactly when needed
2. **Faster Problem Resolution**
- Instant answers to common questions
- No need to leave the application
- Personalized explanations based on actual data
3. **Discovery & Exploration**
- Suggests actions users might not have considered
- Helps understand complex data structures
- Reveals patterns in MQTT usage
4. **Knowledge Building**
- Users learn MQTT concepts through interaction
- Explanations tailored to their specific use case
- Builds confidence in using MQTT
## Future Enhancements
Potential improvements identified:
1. **Multi-Provider Support**
- Anthropic Claude
- Azure OpenAI
- Local LLM models
2. **Enhanced Context**
- Historical message patterns
- Related topics analysis
- Device identification
3. **Automation Integration**
- Generate automation rules from descriptions
- Create custom dashboards
- Export scripts for common tasks
4. **Collaboration Features**
- Share helpful conversations
- Template library for common queries
- Team knowledge base
## Conclusion
This implementation successfully demonstrates how LLMs can enhance user interaction with MQTT topics by:
- ✅ Providing instant, contextual help
- ✅ Lowering the learning curve for MQTT concepts
- ✅ Enabling natural language interaction with technical data
- ✅ Maintaining privacy and security
- ✅ Integrating seamlessly with existing UI
The feature is production-ready, well-documented, and follows all best practices for code quality and security.
---
**Total Implementation Time**: ~2 hours
**Lines of Code**: ~620 new, 4 modified
**Test Coverage**: All existing tests pass
**Security**: Zero vulnerabilities detected
**Documentation**: Comprehensive user guide included
+18 -18
View File
@@ -1,10 +1,10 @@
When distributing, the attribution and donation page may not be altered or made less accessible without explicit approval.
## creative commons
# Creative Commons Attribution-NoDerivatives 4.0 International
# Attribution-NoDerivatives 4.0 International
Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible.
**Using Creative Commons Public Licenses**
### Using Creative Commons Public Licenses
Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses.
@@ -26,19 +26,17 @@ c. __Effective Technological Measures__ means those measures that, in the absenc
d. __Exceptions and Limitations__ means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material.
e. __License Elements__ means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution and NoDerivatives.
e. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
f. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License.
f. __Licensed Rights__ means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
g. __Licensed Rights__ means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license.
g. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License.
h. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License.
h. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
i. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them.
i. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
j. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world.
k. __You__ means the individual or entity exercising the Licensed Rights under this Public License. __Your__ has a corresponding meaning.
j. __You__ means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning.
### Section 2 Scope.
@@ -46,9 +44,9 @@ a. ___License grant.___
1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to:
A. reproduce and Share the Licensed Material, in whole or in part; but not
A. reproduce and Share the Licensed Material, in whole or in part; and
B. produce, reproduce, or Share Adapted Material.
B. produce and reproduce, but not Share, Adapted Material.
2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions.
@@ -62,7 +60,6 @@ a. ___License grant.___
B. __No downstream restrictions.__ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material.
6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i).
b. ___Other rights.___
@@ -79,7 +76,7 @@ Your exercise of the Licensed Rights is expressly made subject to the following
a. ___Attribution.___
1. If You Share the Licensed Material (including in modified form), You must:
1. If You Share the Licensed Material, You must:
A. retain the following if it is supplied by the Licensor with the Licensed Material:
@@ -97,6 +94,8 @@ a. ___Attribution.___
C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License.
For the avoidance of doubt, You do not have permission under this Public License to Share Adapted Material.
2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information.
3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable.
@@ -105,7 +104,7 @@ a. ___Attribution.___
Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material:
a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database;
a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database, provided You do not Share Adapted Material;
b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and
@@ -153,6 +152,7 @@ c. No term or condition of this Public License will be waived and no failure to
d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority.
> Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” The text of the Creative Commons public licenses is dedicated to the public domain under the [CC0 Public Domain Dedication](https://creativecommons.org/publicdomain/zero/1.0/legalcode). Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses.
> Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses.
>
> Creative Commons may be contacted at creativecommons.org.
> Creative Commons may be contacted at creativecommons.org
-222
View File
@@ -1,222 +0,0 @@
# LLM Integration for Topic Interaction
## Overview
MQTT Explorer now includes an AI-powered assistant to help users understand and interact with MQTT topics and their data. This feature uses Large Language Models (LLMs) to provide intelligent insights, explanations, and suggestions about your MQTT data.
## Features
### AI Assistant Panel
The AI Assistant appears in the Details tab when you select any topic in the tree. It provides:
- **Quick Suggestions**: Pre-generated questions based on the selected topic
- **Interactive Chat**: Ask custom questions about the topic, its data, or MQTT concepts
- **Context-Aware**: Automatically includes topic metadata and message details in queries
- **Conversation History**: Maintains context across multiple questions
- **Collapsible Interface**: Minimizes when not needed to save screen space
### Capabilities
The AI Assistant can help you:
1. **Understand Data Structures**: Get explanations of JSON payloads and complex data formats
2. **Interpret Values**: Learn what specific values mean in the context of IoT devices
3. **Analyze Patterns**: Understand message patterns and frequencies
4. **Discover Possibilities**: Learn what actions you can perform with specific topics
5. **Learn MQTT Concepts**: Get answers about QoS, retained messages, and MQTT protocol features
## Configuration
### Setting Up Your API Key
The AI Assistant uses a **backend proxy architecture** for security. API keys are configured server-side only and are never exposed to the frontend.
#### For Server/Docker Deployments
Configure the AI Assistant using environment variables:
```bash
# Provider selection (optional, defaults to 'openai')
export LLM_PROVIDER=openai # or 'gemini'
# API Keys - provider-specific or generic
export OPENAI_API_KEY=sk-... # For OpenAI
export GEMINI_API_KEY=AIza... # For Gemini
export LLM_API_KEY=... # Generic fallback for either provider
# Token limit for neighboring topics context (optional, defaults to 500)
# Increased from 100 to 500 for better device relationship and hierarchy detection
export LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT=500
# Start the server
node dist/src/server.js
```
**Architecture**:
- Backend reads API keys from environment variables
- Backend proxies all LLM API requests via WebSocket RPC (`llm/chat` event)
- Frontend only receives an availability flag (no credentials)
- API keys never leave the server
- Communication happens over the existing WebSocket connection
**Environment Variable Priority:**
1. Provider-specific keys (`OPENAI_API_KEY`, `GEMINI_API_KEY`) are checked first
2. Generic `LLM_API_KEY` is used as fallback
**Note**: If no LLM environment variables are set, the AI Assistant feature will be completely hidden from all users.
### Getting API Keys
#### OpenAI API Key
1. Visit [https://platform.openai.com/api-keys](https://platform.openai.com/api-keys)
2. Sign up or log in to your OpenAI account
3. Create a new API key
4. Set `OPENAI_API_KEY` environment variable on your server
**Note**: Using the AI Assistant will consume OpenAI API credits based on your usage. Please review OpenAI's pricing at [https://openai.com/pricing](https://openai.com/pricing).
#### Google Gemini API Key
1. Visit [https://aistudio.google.com/app/apikey](https://aistudio.google.com/app/apikey)
2. Sign in with your Google account
3. Create a new API key
4. Copy the key and paste it into MQTT Explorer's configuration dialog or set `GEMINI_API_KEY` environment variable
**Note**: Google Gemini offers a generous free tier. Review Google's pricing at [https://ai.google.dev/pricing](https://ai.google.dev/pricing).
## Usage
### Basic Interaction
1. **Connect** to your MQTT broker
2. **Select** a topic from the tree
3. **Expand** the "AI Assistant" panel in the Details tab
4. **Click** on a quick suggestion or type your own question
5. **Send** your question and wait for the AI response
### Example Questions
- "What does this temperature value represent?"
- "How should I interpret this JSON structure?"
- "Why is this message retained?"
- "What QoS level should I use for this topic?"
- "How can I monitor changes to this value?"
- "What devices typically publish to topics like this?"
### Quick Suggestions
The AI Assistant provides contextual suggestions based on the selected topic:
- **"Explain this data structure"**: Get a breakdown of complex payloads
- **"What does this value mean?"**: Understand specific measurements or states
- **"Summarize all subtopics"**: Get an overview of nested topic hierarchies
- **"What can I do with this topic?"**: Discover possible actions and integrations
### Context Intelligence
The AI Assistant automatically includes relevant context with your questions:
- **Current Topic**: The selected topic path and its current value (with preview for large payloads)
- **Neighboring Topics**: Related topics with hierarchical context (parent, siblings, children, grandchildren, cousins), limited to 500 tokens by default (increased from 100 for better device relationship detection)
- **Topic Metadata**: Message count, subtopic count, and retained status
- **Smart Truncation**: Large values and topic lists are intelligently truncated to stay within token limits
The neighboring topics context can be adjusted using the `LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT` environment variable. We recommend 500-1000 tokens for production deployments to enable better multi-device and room-level automation proposals.
## Privacy & Security
### Data Handling
- **API Keys**: Stored locally in browser localStorage, never transmitted to MQTT Explorer servers
- **Topic Data**: Topic paths and message payloads are sent to OpenAI's API to provide context
- **Conversation History**: Maintained client-side and reset when you clear the chat
### Best Practices
1. **Sensitive Data**: Be cautious when using the AI Assistant with topics containing sensitive information
2. **API Key Security**: Never share your OpenAI API key with others
3. **Rate Limiting**: The service implements error handling for rate limits
4. **Offline Operation**: The AI Assistant requires internet connectivity to function
## Technical Details
### Architecture
- **Frontend**: React component with Material-UI styling
- **Service Layer**: Singleton LLM service for API communication
- **API Integration**: OpenAI Chat Completions API (GPT-4o Mini by default)
- **Context Generation**: Automatic extraction of topic metadata for relevant queries
### Implementation
The AI Assistant uses:
- **OpenAI SDK**: Official `openai` package (v6.16.0) for reliable OpenAI API communication
- Automatic retry logic with exponential backoff
- Built-in timeout handling (30 seconds)
- TypeScript type safety
- Better error messages
- **Axios**: Direct HTTP calls for Gemini API (Google doesn't provide official Node.js SDK)
- **Model**: `gpt-5-mini` (latest OpenAI mini model, 400K context window)
- **Architecture**: Server-side proxy - API keys never sent to browser
### Configuration Options
The LLM service supports:
- **Custom API Endpoints**: Can be configured to use compatible APIs
- **Model Selection**: Defaults to `gpt-5-mini` (latest OpenAI mini model)
- **Conversation History**: Automatically manages context (keeps last 10 messages)
- **Timeout Handling**: 30-second timeout for API requests with automatic retries
- **Debug Mode**: View complete API request and response data via debug button
## Troubleshooting
### "Please configure your OpenAI API key first"
**Solution**: Click the settings icon and add your API key.
### "Invalid API key"
**Solutions**:
- Verify the API key is correct
- Check that your OpenAI account is active
- Ensure you have available API credits
### "Rate limit exceeded"
**Solutions**:
- Wait a few minutes before trying again
- Check your OpenAI API usage dashboard
- Consider upgrading your OpenAI plan if needed
### "Request timeout"
**Solutions**:
- Check your internet connection
- Try asking a simpler question
- Verify OpenAI's service status
## Limitations
- Requires active internet connection
- Needs valid OpenAI API key with available credits
- Responses are limited to 500 tokens for performance
- May not have knowledge of proprietary or custom MQTT implementations
- Beta feature - under active development
## Future Enhancements
Potential improvements being considered:
- Support for additional LLM providers (Anthropic, Azure OpenAI, etc.)
- Ability to save and share helpful conversations
- Integration with automation and scripting features
- Custom prompts and templates for specific use cases
- Offline mode with cached responses for common questions
## Feedback
This is a beta feature. If you encounter issues or have suggestions, please open an issue on the [GitHub repository](https://github.com/thomasnordquist/MQTT-Explorer/issues).
-87
View File
@@ -1,87 +0,0 @@
# LLM Tests Debugging Summary
## GitHub Workflow Issue Fixed ✅
### Problem Identified
The `.github/workflows/copilot-setup-steps.yml` had a critical step ordering issue:
**Before (BROKEN):**
1. Create `.env.llm-tests` file
2. Checkout code ← **This overwrites the directory, losing the .env file!**
3. Run tests
**After (FIXED):**
1. Checkout code
2. Create `.env.llm-tests` file ← **Now persists correctly**
3. Run tests
### Changes Made
- Moved "Persist Secrets to Agent Environment" step AFTER "Checkout code"
- Added `export` prefix to environment variables for proper shell sourcing
- Added `RUN_LLM_TESTS=true` to enable tests automatically
- Added `chmod 600` for security
- Added verification logging to confirm file creation
## Environment Setup Verification
### API Key Sourcing ✅
The `.env.llm-tests` sourcing mechanism works correctly:
```bash
# Create .env file
echo 'export OPENAI_API_KEY=sk-your-key' > .env.llm-tests
echo 'export RUN_LLM_TESTS=true' >> .env.llm-tests
# Source and verify
source .env.llm-tests
echo $OPENAI_API_KEY # Shows the key
```
### Test Detection ✅
When the environment is properly sourced, tests correctly:
- Detect the API key presence
- Enable live test execution (not skipped)
- Show provider detection: "Running LLM integration tests with provider: openai"
### Current Limitation ⚠️
Tests fail in the jsdom environment with network errors:
```
Error: Cross origin null forbidden
Error: LLM API call failed: Network Error
```
This is expected because:
1. Tests run in a jsdom environment (not a real browser)
2. axios HTTP requests fail due to CORS restrictions in jsdom
3. Live API tests need a proper Node.js environment or network mocking
## Recommendations
### For Local Development
Run tests with a real API key in a Node environment:
```bash
source .env.llm-tests
cd app && yarn test
```
### For CI/CD
The workflow now correctly:
1. Checks out the repository first
2. Creates `.env.llm-tests` in the workspace
3. Makes the API key available to subsequent steps
Consider:
1. Running tests in a Node environment (not jsdom)
2. Using nock or msw to mock HTTP requests in tests
3. Running live tests only in scheduled jobs with proper network access
## Verified Working
-`.env.llm-tests` creation via workflow (step order fixed)
-`.env.llm-tests` creation via `setup-llm-env.sh`
- ✅ Environment variable sourcing
- ✅ Test detection of API keys
- ✅ Provider auto-detection (OpenAI/Gemini)
- ✅ Proper skip behavior when no API key
## Status
The infrastructure is now working correctly. The workflow step order has been fixed to ensure `.env.llm-tests` persists after checkout.
-156
View File
@@ -1,156 +0,0 @@
# Mobile Compatibility Concept
## Overview
This document outlines the mobile compatibility strategy for MQTT Explorer, focusing on providing a good mobile experience without requiring a complete UI rewrite.
## Target Device
**Reference Device:** Google Pixel 6
- Viewport: 412x915 pixels (portrait)
- Typical modern smartphone dimensions
- Good representation of common mobile browsers
## Strategy
### 1. Browser Mode First
Mobile compatibility focuses on the browser mode (`yarn dev:server`) rather than native mobile apps, as:
- Browser mode already supports any device with a modern web browser
- No app store deployment complexities
- Users can access via mobile browser or save as PWA
### 2. Responsive Design Enhancements
Without rewriting the UI, we implement strategic responsive improvements:
#### Viewport Configuration
- Ensure proper viewport meta tag for mobile scaling
- Already present: `<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no" />`
#### Layout Adaptations
- **Tree Panel**: Make touch-friendly (larger tap targets, better scrolling)
- **Sidebar**: Collapsible by default on mobile, swipe-friendly
- **Chart Panel**: Stack vertically instead of side-by-side
- **Split Panes**: Adjust minimum sizes and default positions for mobile
#### Touch Interactions
- Increase tap target sizes for mobile (minimum 44x44px)
- Improve scrolling performance
- Add touch-friendly gestures where applicable
### 3. Minimal CSS Changes
Use CSS media queries to adapt the UI for mobile viewports:
```css
@media (max-width: 768px) {
/* Mobile-specific overrides */
}
```
Key areas for CSS adjustments:
- Typography sizing (ensure readability on small screens)
- Padding and margins (optimize for touch)
- Button and icon sizes (larger for touch targets)
- Navigation (hamburger menu, collapsible sections)
### 4. Feature Prioritization
On mobile devices, prioritize:
1. **Core Functionality**: View topics, read messages, basic navigation
2. **Search**: Easy topic filtering and search
3. **Connection Management**: Connect/disconnect, basic settings
4. **Publishing**: Simple message publishing
Less critical on mobile (can be de-emphasized):
- Advanced connection settings (can use smaller text/collapse)
- Extensive keyboard shortcuts
- Multi-panel simultaneous viewing
## Implementation Approach
### Phase 1: Foundation (Current)
- Document mobile compatibility concept ✓
- Create mobile demo video showing current experience
- Identify pain points and opportunities
### Phase 2: Quick Wins (Minimal Changes)
- Adjust default split pane positions for mobile
- Increase touch target sizes in critical areas
- Improve sidebar collapse behavior on small screens
- Optimize tree node spacing for touch
### Phase 3: Enhanced Experience (Future)
- Add PWA manifest for "add to home screen"
- Implement swipe gestures
- Optimize connection dialog for mobile
- Add mobile-specific keyboard (numeric for ports, etc.)
## Demo Video
### Purpose
Create a demonstration video showing MQTT Explorer running on a mobile viewport (Pixel 6 dimensions) to:
- Showcase current mobile experience
- Identify UX issues
- Demonstrate the feasibility of mobile usage
- Guide future improvements
### Technical Implementation
- Use Playwright with Chromium in mobile emulation mode
- Viewport size: 412x915 (Pixel 6 portrait)
- Record typical mobile use cases:
- Connecting to broker
- Browsing topic tree (with touch gestures)
- Viewing message details
- Searching topics
- Publishing messages
### Script Location
`src/spec/demoVideoMobile.ts` - Mobile-specific demo video script
## Testing Strategy
### Manual Testing
- Test on real mobile devices (iOS Safari, Android Chrome)
- Use Chrome DevTools device emulation during development
- Verify touch interactions work smoothly
### Automated Testing
- Create mobile-specific UI tests
- Run demo video generation with mobile viewport
- Validate responsive breakpoints
## Future Considerations
### Progressive Web App (PWA)
Add PWA capabilities:
- Service worker for offline support
- App manifest for installability
- App icon and splash screen
### Platform-Specific Optimizations
- iOS: Handle safe areas, notch
- Android: Material Design guidelines
- Dark mode (already supported via theme)
### Performance
- Optimize bundle size for mobile networks
- Implement lazy loading for large topic trees
- Add connection retry logic for unreliable mobile networks
## Metrics for Success
A successful mobile experience should provide:
- ✅ All core features accessible on mobile
- ✅ No horizontal scrolling required
- ✅ Touch targets minimum 44x44px
- ✅ Readable text without zooming
- ✅ Smooth scrolling and interactions
- ✅ Quick load times (<3s on 3G)
## Resources
- [Google Mobile-Friendly Test](https://search.google.com/test/mobile-friendly)
- [Material Design Touch Target Guidelines](https://material.io/design/usability/accessibility.html#layout-typography)
- [MDN Responsive Design](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Responsive_Design)
- [Playwright Device Emulation](https://playwright.dev/docs/emulation)
-180
View File
@@ -1,180 +0,0 @@
# Mobile Testing Guide
This document describes how to run and debug mobile UI tests for MQTT Explorer.
## Overview
The mobile tests simulate MQTT Explorer running in a mobile browser (Google Pixel 6 viewport: 412x914px) and generate demo videos showing the mobile user experience.
## Prerequisites
### System Dependencies
```bash
sudo apt-get install -y ffmpeg tmux xvfb x11vnc mosquitto
```
### Node Dependencies
```bash
yarn install
npx playwright install --with-deps chromium
```
## Running Mobile Tests
### 1. Build the Application
```bash
yarn build:server # For browser mode
```
### 2. Run Tests
```bash
./scripts/uiTestsMobile.sh
```
This will:
- Start Xvfb (virtual framebuffer)
- Start mosquitto MQTT broker
- Start MQTT Explorer server in browser mode
- Run Playwright tests with mobile viewport
- Record video of the test session
### 3. Post-Process Video
```bash
./scripts/prepareVideoMobile.sh
```
This converts the raw video to MP4 and GIF formats and creates individual segments for each test scene.
## Output Files
- `ui-test-mobile.mp4` - Full mobile test video (MP4)
- `ui-test-mobile.gif` - Full mobile test video (GIF)
- `segment-mobile-*.gif` - Individual scene segments
- `scenes-mobile.json` - Scene timing metadata
All video files are automatically excluded from git (see `.gitignore`).
## Debugging
### View Test in VNC
During test execution, you can connect with VNC to watch in real-time:
```bash
# Password: bierbier
vncviewer localhost:5900
```
### Common Issues
#### 1. Playwright Browsers Not Installed
**Error:** `Executable doesn't exist at .../chromium_headless_shell-1200/chrome-headless-shell`
**Solution:**
```bash
npx playwright install --with-deps chromium
```
#### 2. Video Encoding Fails
**Error:** `height not divisible by 2`
**Solution:** Ensure viewport height is even. Mobile viewport is set to 412x914 (not 915).
#### 3. Elements Outside Viewport
**Error:** `element is outside of the viewport`
**Solution:** The fix adds `scrollIntoViewIfNeeded()` before clicking elements. For modal/dialog elements that intercept clicks, use `force: true`.
#### 4. MQTT Broker Already Running
**Error:** `Address already in use` on port 1883
**Solution:** Kill existing mosquitto process:
```bash
pkill mosquitto
```
## Mobile UI Enhancements
The tests revealed several mobile UI improvements that were implemented:
### 1. Connection Dialog Responsiveness
Added responsive CSS to `ConnectionSetup.tsx`:
- Mobile viewports use 95vw width and 85vh height
- Enabled scrolling on the right panel
- Hide profile list on mobile to save space
### 2. Click Handling
Enhanced `clickOn` helper in `util/index.ts`:
- Added `scrollIntoViewIfNeeded()` to ensure elements are in viewport
- Support for `force: true` to bypass overlay elements
### 3. Tree Node Expansion
Updated `expandTopic` helper:
- Use `force: true` for tree clicks to bypass accordion overlays
- Better handling of nested topic expansion
## Test Scenes
The mobile demo includes these scenes:
1. **mobile_intro** - Introduction screen
2. **mobile_connect** - Connect to MQTT broker
3. **mobile_browse_topics** - Browse topic tree
4. **mobile_search** - Search and filter topics
5. **mobile_view_message** - View message details
6. **mobile_json_view** - JSON formatting display
7. **mobile_clipboard** - Copy operations
8. **mobile_plots** - Numeric data visualization
9. **mobile_menu** - Settings and menu
10. **mobile_end** - Conclusion screen
## CI Integration
Mobile tests run in the `demo-video-mobile` job in `.github/workflows/tests.yml`:
```yaml
demo-video-mobile:
runs-on: ubuntu-latest
container:
image: ghcr.io/thomasnordquist/mqtt-explorer-ui-tests:latest
steps:
- name: Generate Mobile Demo Video
run: ./scripts/uiTestsMobile.sh
- name: Post-processing
run: ./scripts/prepareVideoMobile.sh
```
Videos are uploaded to S3 and linked in PR comments.
## Technical Notes
### Viewport Configuration
- **Width:** 412px (Pixel 6)
- **Height:** 914px (must be even for h264 encoding)
- **Device Scale Factor:** 2.625
- **Mobile Mode:** Enabled with touch events
### Video Recording
- Raw video: YUV420P format
- Frame rate: 20 fps
- Recording tool: ffmpeg via tmux
### Post-Processing
- MP4 encoding: h264 codec
- GIF palette: 256 colors optimized per segment
- Segment creation: Based on scene timing in `scenes-mobile.json`
## Future Improvements
Potential areas for enhancement:
1. **Touch Gestures** - Add swipe and pinch interactions
2. **Performance** - Optimize for slower mobile networks
3. **Accessibility** - Larger touch targets, better contrast
4. **PWA Support** - Add manifest for "add to home screen"
5. **Orientation** - Test landscape mode
## References
- [MOBILE_COMPATIBILITY.md](./MOBILE_COMPATIBILITY.md) - Mobile compatibility strategy
- [Playwright Device Emulation](https://playwright.dev/docs/emulation)
- [Material-UI Responsive Design](https://mui.com/material-ui/customization/breakpoints/)
-143
View File
@@ -1,143 +0,0 @@
# macOS Notarization Setup
This document explains how to set up notarization for macOS builds of MQTT Explorer.
## Overview
macOS notarization is a security feature required by Apple for all software distributed outside the Mac App Store. Starting with macOS 10.15 (Catalina), all software must be notarized to run without warnings on macOS.
## Prerequisites
1. An active Apple Developer account
2. Xcode command line tools installed on the build machine
3. An app-specific password for notarization
## Setup Steps
### 1. Create an App-Specific Password
1. Sign in to [appleid.apple.com](https://appleid.apple.com)
2. Navigate to "Sign-In and Security" section
3. Under "App-Specific Passwords", click "Generate an app-specific password"
4. Enter a descriptive name (e.g., "MQTT Explorer Notarization")
5. Copy the generated password (you won't be able to see it again)
### 2. Find Your Team ID
1. Sign in to [developer.apple.com](https://developer.apple.com/account)
2. Navigate to "Membership Details"
3. Copy your Team ID (a 10-character alphanumeric string)
### 3. Configure GitHub Secrets
Add the following secrets to your GitHub repository:
- `APPLE_ID`: Your Apple ID email address (e.g., `your.email@example.com`)
- `APPLE_APP_SPECIFIC_PASSWORD`: The app-specific password created in step 1
- `APPLE_TEAM_ID`: Your Team ID from step 2
To add secrets:
1. Go to your repository on GitHub
2. Navigate to Settings → Secrets and variables → Actions
3. Click "New repository secret" for each of the above
## How It Works
### Build Configuration
The notarization process is configured in `package.json`:
```json
{
"build": {
"mac": {
"hardenedRuntime": true,
"gatekeeperAssess": false,
"entitlements": "res/entitlements.mac.plist",
"entitlementsInherit": "res/entitlements.mac.inherit.plist"
},
"afterSign": "./dist/scripts/notarize.js"
}
}
```
### Notarization Script
The `scripts/notarize.ts` script handles the notarization process:
1. Checks if the build is for macOS
2. Verifies that required environment variables are set
3. Submits the app to Apple's notarization service
4. Waits for notarization to complete
5. Staples the notarization ticket to the app
### Entitlements
Different entitlements are used for different build types:
- **DMG builds** (regular distribution):
- `res/entitlements.mac.plist` - Main entitlements
- `res/entitlements.mac.inherit.plist` - Inherited entitlements for child processes
- **MAS builds** (Mac App Store):
- `res/entitlements.mas.plist` - App Store specific entitlements
### CI/CD Integration
The GitHub Actions workflow (`platform-builds.yml`) automatically:
1. Builds the macOS app when code is pushed to `release` or `beta` branches
2. Signs the app with the developer certificate
3. Notarizes the app using the configured secrets
4. Publishes the notarized app to GitHub releases
## Troubleshooting
### Notarization Fails
If notarization fails, check:
1. **Credentials**: Ensure all three secrets are correctly set in GitHub
2. **App-specific password**: Verify it hasn't expired or been revoked
3. **Team ID**: Confirm it matches your developer account
4. **Entitlements**: Ensure the entitlements files are valid and appropriate for your app
### Checking Notarization Status
You can check the notarization status of a built app:
```bash
# Check if an app is notarized
spctl -a -vv /path/to/MQTT\ Explorer.app
# Check notarization history
xcrun notarytool history --apple-id your.email@example.com --team-id YOUR_TEAM_ID
```
### Local Testing
To test notarization locally:
```bash
# Set environment variables
export APPLE_ID="your.email@example.com"
export APPLE_APP_SPECIFIC_PASSWORD="your-app-specific-password"
export APPLE_TEAM_ID="YOUR_TEAM_ID"
# Build and notarize
yarn build
yarn package mac
```
## Security Considerations
- Never commit Apple credentials to the repository
- Use app-specific passwords, not your main Apple ID password
- Rotate app-specific passwords periodically
- Limit access to GitHub secrets to trusted maintainers only
## References
- [Apple Notarization Documentation](https://developer.apple.com/documentation/security/notarizing_macos_software_before_distribution)
- [electron-builder Code Signing](https://www.electron.build/code-signing)
- [@electron/notarize](https://github.com/electron/notarize)
+19 -239
View File
@@ -6,281 +6,61 @@
[![Build status](https://ci.appveyor.com/api/projects/status/c35tkm29rm4m5364/branch/master?svg=true)](https://ci.appveyor.com/project/thomasnordquist/mqtt-explorer/branch/master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/47b26e03fce543ceac7914214482334a)](https://app.codacy.com/app/thomasnordquist/MQTT-Explorer?utm_source=github.com&utm_medium=referral&utm_content=thomasnordquist/MQTT-Explorer&utm_campaign=Badge_Grade_Dashboard)
| | | |
| :---------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------: |
| [![screen_composite](https://mqtt-explorer.com/img/screen-composite_small.png)](https://mqtt-explorer.com/img/screen-composite.png) | [![screen2_small](https://mqtt-explorer.com/img/screen2_small.png)](https://mqtt-explorer.com/img/screen2.png) | [![screen3_small](https://mqtt-explorer.com/img/screen3_small.png)](https://mqtt-explorer.com/img/screen3.png) |
| | | |
|:---:|:---:|:---:|
|[![screen_composite](https://mqtt-explorer.com/img/screen-composite_small.png)](https://mqtt-explorer.com/img/screen-composite.png)|[![screen2_small](https://mqtt-explorer.com/img/screen2_small.png)](https://mqtt-explorer.com/img/screen2.png)|[![screen3_small](https://mqtt-explorer.com/img/screen3_small.png)](https://mqtt-explorer.com/img/screen3.png)|
# The App has moved to [mqtt-explorer.com](https://mqtt-explorer.com)
MQTT Explorer is a comprehensive and easy-to-use MQTT Client.
Downloads can be found at the link above.
This page is dedicated to its development.
Pull-Requests and error reports are welcome.
## Quick Start with GitHub Codespaces
The fastest way to start developing is with GitHub Codespaces:
1. Click the green "Code" button above
2. Select "Codespaces" tab
3. Click "Create codespace on [branch]"
4. Wait for the environment to set up (includes Node.js and MQTT broker)
5. Run `yarn dev:server` to start development
The devcontainer includes a pre-configured MQTT broker and all development tools. See [.devcontainer/README.md](.devcontainer/README.md) for details.
## Run from sources
### Desktop Application (Electron)
```bash
npm install -g yarn
yarn
yarn build
yarn start
```
### Browser Mode (Web Application)
MQTT Explorer can also run as a web application served by a Node.js server:
```bash
npm install -g yarn
yarn
yarn build:server
yarn start:server
```
Then open your browser to `http://localhost:3000`. For more details, see [BROWSER_MODE.md](BROWSER_MODE.md).
### Docker (Browser Mode)
[![Try in PWD](https://raw.githubusercontent.com/play-with-docker/stacks/master/assets/images/button.png)](https://labs.play-with-docker.com/?stack=https://raw.githubusercontent.com/thomasnordquist/MQTT-Explorer/master/docker-compose.yml)
Run MQTT Explorer in a Docker container:
```bash
docker run -d \
-p 3000:3000 \
-e MQTT_EXPLORER_USERNAME=admin \
-e MQTT_EXPLORER_PASSWORD=your_secure_password \
-v mqtt-explorer-data:/app/data \
ghcr.io/thomasnordquist/mqtt-explorer:latest
```
**Supports multiple platforms**: amd64, arm64 (Raspberry Pi 3/4/5), arm/v7 (Raspberry Pi 2/3).
**Enterprise integration**: Set `MQTT_EXPLORER_SKIP_AUTH=true` to disable built-in authentication when deploying behind a secure authentication proxy (e.g., OAuth2 Proxy, SSO).
For complete Docker documentation including authentication options, deployment examples, and security best practices, see [DOCKER.md](DOCKER.md).
## Develop
### Desktop Application
Launch Application
```bash
npm install -g yarn
yarn
yarn dev
```
### Browser Mode
Launch in development mode with hot reload:
```bash
npm install -g yarn
yarn
yarn dev:server
```
The `app` directory contains all the rendering logic, the `backend` directory currently contains the models, tests, connection management, `src` contains all the electron bindings. [mqttjs](https://github.com/mqttjs/MQTT.js) is used to facilitate communication to MQTT brokers.
For information on styling conventions and visual design patterns, see [STYLING.md](STYLING.md).
## Automated Tests
MQTT Explorer uses multiple test suites to ensure reliability and quality:
To achieve a reliable product automated tests run regularly on travis.
### Unit Tests
- Data model
- MQTT integration
- UI-Tests (The demo is a recorded ui test)
**App tests** - Frontend component and logic tests:
## Run UI-tests
A [mosquitto](https://mosquitto.org/) MQTT broker is required to run the ui-tests.
Run tests with
```bash
yarn test:app
# Run chromedriver in a separate terminal session
./node_modules/.bin/chromedriver --url-base=wd/hub --port=9515 --verbose
```
**Backend tests** - Data model and business logic tests:
Compile and execute tests
```bash
yarn test:backend
npm run build
node dist/src/spec/webdriverio.js
```
**Run all unit tests**:
```bash
yarn test
```
### LLM Testing
The AI Assistant feature includes comprehensive tests to validate proposal quality and LLM integration.
**Offline tests** (default - no API key needed):
```bash
yarn test:app
```
**Live LLM integration tests** (requires API key):
```bash
# Set your API key
export OPENAI_API_KEY=sk-your-key-here
# Or use Gemini
export GEMINI_API_KEY=your-key-here
# Opt-in to live tests
export RUN_LLM_TESTS=true
# Run tests
yarn test:app
```
For detailed LLM testing documentation, see [app/src/services/spec/README.md](app/src/services/spec/README.md).
### Integration & UI Tests
**UI test suite** - Independent, deterministic browser tests:
```bash
yarn build
yarn test:ui
```
**Demo video generation** - UI test recording for documentation:
```bash
yarn build
yarn test:demo-video
```
Note: Requires Xvfb, mosquitto broker, tmux, and ffmpeg. For full video recording setup, use `./scripts/uiTests.sh`.
**MCP introspection tests** - Model Context Protocol validation:
```bash
yarn build
yarn test:mcp
```
**Run all tests** (unit tests + demo video):
```bash
yarn build
yarn test:all
```
### Run UI Test Suite
The UI test suite validates core functionality through automated browser tests. Each test is independent and deterministic.
```bash
# Run with automated setup (recommended)
./scripts/runUiTests.sh
# Or run directly (requires manual MQTT broker setup)
yarn build
yarn test:ui
```
See [docs/UI-TEST-SUITE.md](docs/UI-TEST-SUITE.md) for more details.
### Run Demo Video Generation
The demo video is used for documentation and showcases key features. It requires additional dependencies:
```bash
yarn build
yarn test:demo-video
```
**Requirements:**
- mosquitto MQTT broker
- Xvfb (virtual framebuffer)
- tmux (terminal multiplexer)
- ffmpeg (video encoding)
**For full video recording with post-processing:**
```bash
yarn build
./scripts/uiTests.sh
```
This script handles Xvfb setup, mosquitto startup, video recording, and cleanup.
### Mobile Demo Video
A mobile-focused demo video showcases MQTT Explorer in a mobile viewport (Pixel 6: 412x915px):
```bash
yarn build
yarn test:demo-video:mobile
```
Or with full recording setup:
```bash
yarn build
./scripts/uiTestsMobile.sh
```
This demonstrates the mobile compatibility features and responsive design improvements. See [MOBILE_COMPATIBILITY.md](MOBILE_COMPATIBILITY.md) for the mobile strategy and implementation details.
## Mobile Compatibility
MQTT Explorer supports mobile devices through its browser mode with responsive design enhancements:
- **Target Device**: Google Pixel 6 (412x915px viewport)
- **Touch-Friendly UI**: Minimum 44px tap targets for better mobile UX
- **Responsive Layout**: Sidebar and panels adapt to mobile viewports
- **Browser Mode**: Access via mobile browser or install as PWA
For the complete mobile compatibility concept, implementation phases, and future roadmap, see [MOBILE_COMPATIBILITY.md](MOBILE_COMPATIBILITY.md).
## Create a release
Create a PR to `release` branch.
There needs to be a "feat: some new feature" or "fix: some bugfix" commit for a new release to be created
### macOS Notarization
macOS builds are automatically notarized during the release process. To set up notarization credentials, see [NOTARIZATION.md](NOTARIZATION.md).
## Create a beta release
Create a PR to `beta` branch. A "feat" or "fix" commit is necessary to create a new version.
## Write docs
```
git clone --single-branch -b gh-pages https://github.com/thomasnordquist/MQTT-Explorer.git mqtt-explorer-pages
cd mqtt-explorer-pages
bundle install
bundle exec jekyll serve --incremental
```
Readme file: `Readme.tpl.md`
Preview is available at
http://localhost:4000/Readme.tpl
## Update docs
```
npm install
./updateReadme.ts
```
The readme will be generated from the docs.
## License
![CC BY-SA 4.0](https://img.shields.io/badge/License-CC%20BY--SA%204.0-blue.svg)
[CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/)
![CC-BY-ND 4.0](https://img.shields.io/badge/License-CC%20BY--ND%204.0-blue.svg)
[CC-BY-ND 4.0](https://creativecommons.org/licenses/by-nd/4.0/)
**Special requirement:** When distributing, the attribution and donation page may not be altered or made less accessible without explicit approval.
The license allows for anyone to adapt, share, and redistribute the material, as long as they give appropriate credit and distribute any derivative works under the same license.
The license is a little restrictive to distributing derived work, this may change in the future if the interest arises or more people work on this project.
-194
View File
@@ -1,194 +0,0 @@
# Security Policy
## Supported Versions
Security updates are provided for the latest release of MQTT Explorer.
| Version | Supported |
| ------- | ------------------ |
| 0.4.x | :white_check_mark: |
| < 0.4 | :x: |
## Reporting a Vulnerability
We take security vulnerabilities seriously. If you discover a security issue, please follow these steps:
### How to Report
1. **DO NOT** create a public GitHub issue for security vulnerabilities
2. Report via one of these channels:
- GitHub Security Advisories (preferred): https://github.com/thomasnordquist/MQTT-Explorer/security/advisories/new
- Email the maintainer directly
3. Include the following information:
- Description of the vulnerability
- Steps to reproduce
- Potential impact
- Any suggested fixes (optional)
### What to Expect
- **Acknowledgment**: We will acknowledge receipt of your report within 48 hours
- **Updates**: We will provide updates on the status of your report within 7 days
- **Fix Timeline**: We aim to release security fixes within 30 days for critical issues
- **Credit**: With your permission, we will credit you in the security advisory and release notes
## Security Features
### Browser Mode Security
MQTT Explorer's browser mode includes several security features:
#### Authentication
- **bcrypt Password Hashing**: All passwords are hashed with bcrypt (10 rounds)
- **Constant-Time Comparison**: Username comparison uses crypto.timingSafeEqual() to prevent timing attacks
- **Environment Variable Configuration**: Credentials can be set via environment variables for production
- **Automatic Credential Generation**: Secure random credentials generated if not provided
#### Rate Limiting
- **Authentication Rate Limiting**: Maximum 5 failed authentication attempts per IP per 15 minutes
- **Per-IP Tracking**: Failed attempts tracked separately for each client IP
- **Automatic Reset**: Rate limit counters automatically reset after 15 minutes
#### HTTP Security Headers (helmet.js)
- **Content Security Policy (CSP)**: Restricts resource loading to prevent XSS attacks
- **HTTP Strict Transport Security (HSTS)**: Enforces HTTPS in production
- **X-Content-Type-Options**: Prevents MIME type sniffing
- **X-Frame-Options**: Prevents clickjacking attacks
- **X-XSS-Protection**: Enables browser XSS protection
#### Input Validation
- **File Size Limits**: Maximum 16MB for file uploads
- **Path Traversal Protection**: All file paths validated and sanitized
- **Filename Sanitization**: Removes path separators, null bytes, and validates against traversal patterns
- **Real Path Validation**: Ensures resolved paths stay within allowed directories
- **Base64 Validation**: All file data properly validated before processing
#### CORS Configuration
- **Configurable Origins**: CORS origins configurable via ALLOWED_ORIGINS environment variable
- **Production Restrictions**: Wildcard CORS automatically disabled in production
- **Credential Support**: CORS configured with credentials: true for authenticated requests
#### Error Handling
- **Generic Error Messages**: Detailed errors only shown in development mode
- **No Information Leakage**: Error messages sanitized to prevent information disclosure
- **Secure Logging**: Sensitive information not logged in production
## Security Best Practices
### For Server Deployment
1. **Always Use HTTPS in Production**
- Use a reverse proxy (nginx, Apache) with TLS certificates
- Never expose the Node.js server directly to the internet
- Use Let's Encrypt for free TLS certificates
2. **Set Strong Credentials**
```bash
export MQTT_EXPLORER_USERNAME=your_secure_username
export MQTT_EXPLORER_PASSWORD=your_strong_password_min_12_chars
export NODE_ENV=production
```
3. **Configure CORS Properly**
```bash
# Single origin
export ALLOWED_ORIGINS=https://mqtt-explorer.example.com
# Multiple origins
export ALLOWED_ORIGINS=https://app1.example.com,https://app2.example.com
```
4. **Network Security**
- Deploy behind a firewall or VPN
- Use IP whitelisting when possible
- Implement network-level rate limiting
- Monitor access logs regularly
5. **Keep Dependencies Updated**
```bash
yarn audit
yarn upgrade-interactive
```
6. **Regular Security Audits**
- Run security tests: `yarn test:security`
- Review access logs for suspicious activity
- Monitor authentication failures
- Check for outdated dependencies
### For MQTT Connections
1. **Use TLS/SSL**: Always connect to MQTT brokers using TLS encryption
2. **Strong Credentials**: Use unique, strong passwords for MQTT authentication
3. **Certificate Validation**: Verify broker certificates in production
4. **Least Privilege**: Connect with minimal required permissions
## Security Testing
The project includes comprehensive security tests:
```bash
# Run all tests including security tests
yarn test
# Run only security tests
npx mocha --require source-map-support/register dist/src/spec/security-tests.spec.js
```
Security tests cover:
- Path traversal attack prevention
- Input validation and sanitization
- Authentication security
- CORS configuration
- Rate limiting
- Error handling
- Data sanitization
## Security Audit History
### December 2024 - Initial Security Review
- Added helmet.js for HTTP security headers
- Implemented rate limiting for authentication
- Added path traversal protection with sanitization
- Implemented constant-time comparison for credentials
- Added input validation and size limits
- Removed credential logging in production
- Added configurable CORS origins
- Created comprehensive security test suite (19 tests)
- Enhanced documentation with security best practices
## Known Limitations
### Browser Mode
- File system access limited to server-side directories
- No native OS dialogs (uses browser file input)
- Session management is stateless (no persistent sessions)
### Desktop Mode (Electron)
- Inherits security model from Electron framework
- IPC communication between renderer and main process
- No network exposure by default
## Recommended Security Tools
- **Dependency Scanning**: Dependabot, Snyk, or npm audit
- **SAST**: SonarQube, ESLint security plugins
- **Container Scanning**: If using Docker deployment
- **TLS Testing**: SSL Labs, testssl.sh
- **Penetration Testing**: OWASP ZAP, Burp Suite
## References
- [OWASP Top 10](https://owasp.org/www-project-top-ten/)
- [Node.js Security Best Practices](https://nodejs.org/en/docs/guides/security/)
- [Express Security Best Practices](https://expressjs.com/en/advanced/best-practice-security.html)
- [helmet.js Documentation](https://helmetjs.github.io/)
- [MQTT Security](https://mqtt.org/mqtt-specification/)
## Contact
For security-related questions or concerns:
- GitHub Security Advisories: https://github.com/thomasnordquist/MQTT-Explorer/security/advisories
- Project Issues (for non-sensitive topics): https://github.com/thomasnordquist/MQTT-Explorer/issues
Thank you for helping keep MQTT Explorer secure!
-212
View File
@@ -1,212 +0,0 @@
# MQTT Explorer Styling Conventions
This document outlines the styling conventions used in MQTT Explorer for visual consistency and maintainable code.
## UI Framework
Material-UI (MUI) v7 with JSS styling via `withStyles` HOC.
**Stack:**
- `@mui/material` (v7) - Core components and theming
- `@mui/icons-material` (v7) - Icons
- `@mui/styles` (v6) - JSS styling with `withStyles`
- `@emotion/react` & `@emotion/styled` - CSS-in-JS foundation
## Theming
**Location:** `app/src/theme.ts`
**Configuration:**
- Light and dark modes supported
- Primary color: `#335C67` (teal/blue-green)
- Secondary: Material-UI `amber` palette
- Base typography: `0.9rem`, `userSelect: 'none'`
**Application:**
```typescript
<ThemeProvider theme={theme}>
<LegacyThemeProvider theme={theme}>
<App />
</LegacyThemeProvider>
</ThemeProvider>
```
## Colors
**Access theme colors:**
```typescript
backgroundColor: theme.palette.background.default
color: theme.palette.text.primary
borderColor: theme.palette.divider
```
**Material-UI palettes:**
```typescript
import { blueGrey, amber, green, red, orange } from '@mui/material/colors'
backgroundColor: blueGrey[100] // Light shade
backgroundColor: blueGrey[700] // Dark shade
```
**Theme-conditional:**
```typescript
const color = theme.palette.mode === 'light' ? blueGrey[300] : theme.palette.primary.main
```
**Code editor colors:** Defined in `app/src/components/Sidebar/CodeBlockColors.ts`
## Typography
**Variants:**
```typescript
<Typography variant="h6">Heading</Typography>
<Typography variant="body1">Body text</Typography>
<Typography variant="caption">Caption</Typography>
```
**Font sizes:**
```typescript
fontSize: theme.typography.pxToRem(15)
```
**Monospace:** `"12px/normal 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace"`
## Spacing
**8px grid system:**
```typescript
margin: theme.spacing(1) // 8px
padding: theme.spacing(2) // 16px
marginLeft: theme.spacing(1.5) // 12px (tree indentation)
```
**Border radius:**
```typescript
borderRadius: theme.shape.borderRadius // 4px default
```
## Component Styling
**Primary approach - withStyles HOC:**
```typescript
import { withStyles } from '@mui/styles'
import { Theme } from '@mui/material/styles'
const styles = (theme: Theme) => ({
root: {
backgroundColor: theme.palette.background.default,
padding: theme.spacing(2),
},
})
export default withStyles(styles)(MyComponent)
```
**Type assertions:**
```typescript
display: 'block' as 'block'
whiteSpace: 'nowrap' as 'nowrap'
overflow: 'hidden' as 'hidden'
```
**Responsive:**
```typescript
[theme.breakpoints.up(750)]: {
display: 'block',
}
```
**sx prop (simple cases):**
```typescript
<Button sx={{ color: 'primary.contrastText' }}>Text</Button>
```
## Animations
**CSS animations:**
```typescript
animation: 'updateLight 0.5s'
```
**Theme transitions:**
```typescript
transition: theme.transitions.create('transform', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
})
```
## Interactive States
**Hover:**
```typescript
'&:hover': {
backgroundColor: theme.palette.mode === 'light'
? blueGrey[100]
: theme.palette.primary.light,
}
```
**Selection:**
```typescript
selected: {
backgroundColor: (theme.palette.mode === 'light'
? blueGrey[300]
: theme.palette.primary.main) + ' !important',
}
```
## Common Patterns
**Tree nodes:**
```typescript
node: {
overflow: 'hidden',
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
}
subnodes: {
marginLeft: theme.spacing(1.5),
}
```
**Buttons:**
```typescript
<Button variant="contained" color="primary">Submit</Button>
<Button variant="outlined" color="primary">Cancel</Button>
<Button>Learn More</Button>
```
**Icons:**
```typescript
<Icon fontSize="inherit" />
<Icon style={{ fontSize: '16px' }} />
```
## Best Practices
**DO:**
✅ Use theme variables (`theme.palette.*`, `theme.spacing()`, `theme.typography.*`)
✅ Use `withStyles` HOC for component styles
✅ Use `theme.palette.mode` for light/dark conditional styling
✅ Import Material-UI color palettes for extended colors
✅ Keep styles co-located with components
**DON'T:**
❌ Hardcode colors or spacing values
❌ Create global CSS files
❌ Duplicate style definitions
❌ Use inline styles for complex patterns
## Resources
- [Material-UI Documentation](https://mui.com/material-ui/getting-started/)
- [Color System](https://mui.com/material-ui/customization/color/)
- [Theming Guide](https://mui.com/material-ui/customization/theming/)
**Testing:** Verify in both light/dark themes, check responsive behavior, ensure accessibility.
## Related
- [README.md](./Readme.md) - Project overview
- [BROWSER_MODE.md](./BROWSER_MODE.md) - Browser mode
- [.github/copilot-instructions.md](./.github/copilot-instructions.md) - Copilot instructions
-201
View File
@@ -1,201 +0,0 @@
# Quick Reference: Running LLM Tests with OpenAI API
## Prerequisites
✅ OpenAI API key added to GitHub Copilot environment
✅ Test infrastructure installed (100 offline + 11 live tests)
✅ Helper script available: `scripts/run-llm-tests.sh`
## Usage
### Option 1: Use Helper Script (Recommended)
```bash
# If secret is in environment
./scripts/run-llm-tests.sh
# Or provide explicitly
OPENAI_API_KEY=sk-your-key ./scripts/run-llm-tests.sh
```
### Option 2: Manual Execution
```bash
# Set environment variables
export OPENAI_API_KEY=sk-your-key
export RUN_LLM_TESTS=true
# Run tests
cd app && yarn test
```
### Option 3: Single Command
```bash
cd /home/runner/work/MQTT-Explorer/MQTT-Explorer && \
RUN_LLM_TESTS=true \
OPENAI_API_KEY=${OPENAI_API_KEY} \
yarn test:app
```
## Expected Results
### Without Live Tests (Default)
```
100 passing (2s)
11 pending
```
### With Live Tests Enabled
```
LLM Integration Tests (Live API)
Home Automation System Detection
✓ should detect zigbee2mqtt topics (2145ms)
✓ should detect Home Assistant topics (1892ms)
✓ should detect Tasmota topics (1756ms)
Proposal Quality Validation
✓ should propose multiple actions (2234ms)
✓ should provide clear descriptions (1678ms)
✓ should match system formats (1923ms)
Edge Cases
✓ should not propose for sensors (1567ms)
✓ should handle nested topics (1834ms)
✓ should handle special chars (1456ms)
Question Generation
✓ should generate relevant questions (2012ms)
✓ should generate analytical questions (1789ms)
111 passing (22s)
```
## Validation Points
Each live test validates:
**Topic Format**
- Matches system pattern (zigbee2mqtt, homeassistant, etc.)
- No wildcards
- Valid segments
**Payload Quality**
- Valid JSON (when appropriate)
- Correct format for target system
- No injection attempts
**QoS Value**
- Must be 0, 1, or 2
- Typically 0 for home automation
**Description**
- Actionable (uses imperative verbs)
- Clear and concise
- Under 100 characters
## Troubleshooting
### Secret Not Available
If you get "No API key found":
```bash
# Check environment
env | grep OPENAI_API_KEY
# If not set, the secret may need to be:
# 1. Refreshed in the Copilot environment
# 2. Made available to the runtime
# 3. Accessed through a different mechanism
```
### Tests Still Pending
If live tests don't run:
```bash
# Ensure flag is set
export RUN_LLM_TESTS=true
echo $RUN_LLM_TESTS # Should output: true
# Check for API key
[ -n "$OPENAI_API_KEY" ] && echo "Key is set" || echo "Key not found"
```
## What Gets Tested
### Home Automation Systems
**zigbee2mqtt:**
```typescript
// Expected proposal
{
topic: "zigbee2mqtt/light/set",
payload: '{"state": "ON"}',
qos: 0,
description: "Turn on the light"
}
```
**Home Assistant:**
```typescript
{
topic: "homeassistant/light/lamp/set",
payload: "ON",
qos: 0,
description: "Turn on the lamp"
}
```
**Tasmota:**
```typescript
{
topic: "cmnd/device/POWER",
payload: "ON",
qos: 0,
description: "Turn on the device"
}
```
### Question Generation
For a topic like `zigbee2mqtt/bedroom_light`:
```typescript
// Expected questions
[
"How can I turn this light on?",
"What brightness levels are supported?",
"Can I adjust the color?",
"How do I automate this light?"
]
```
## Cost Estimate
Per full test run:
- **API Calls:** ~11 requests
- **Tokens:** ~5,000-8,000 total
- **Cost:** ~$0.001-0.002 USD (GPT-4o Mini is ~10x cheaper than GPT-3.5 Turbo)
## Documentation
- **Test Strategy:** `app/src/services/spec/README.md`
- **Test Results:** `docs/LLM_TEST_RESULTS.md`
- **Helper Script:** `scripts/run-llm-tests.sh`
## Success Criteria
When tests pass, you'll have validated:
✅ AI can detect home automation systems correctly
✅ Generated proposals have valid MQTT topic format
✅ Payloads match system-specific requirements
✅ Descriptions are clear and actionable
✅ Questions are relevant and diverse
✅ No security issues (injection, size limits)
---
**Ready to test?** Run: `./scripts/run-llm-tests.sh`
Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

-309
View File
@@ -1,309 +0,0 @@
# React Component Testing Guide
This guide explains how to write tests for React components in the MQTT-Explorer project using the generic testing utilities.
## Overview
We use the following testing stack:
- **Mocha** - Test framework
- **Chai** - Assertion library
- **React Testing Library** - React component testing utilities
- **JSDOM** - DOM implementation for Node.js
- **Custom Test Utilities** - Located in `src/utils/spec/testUtils.tsx`
## Quick Start
### 1. Create a Test File
Test files should be placed next to the component they test with the `.spec.tsx` extension:
```
src/components/MyComponent/
├── MyComponent.tsx
└── MyComponent.spec.tsx
```
### 2. Basic Test Structure
```typescript
import React from 'react'
import { expect } from 'chai'
import { describe, it } from 'mocha'
import MyComponent from './MyComponent'
import { renderWithProviders } from '../../utils/spec/testUtils'
describe('MyComponent', () => {
it('should render correctly', () => {
const { container } = renderWithProviders(<MyComponent />)
expect(container).to.exist
})
})
```
## Using Test Utilities
### `renderWithProviders`
This function wraps your component with necessary providers (Theme, Redux).
```typescript
import { renderWithProviders } from '../../utils/spec/testUtils'
// Render with theme only (default)
const { container } = renderWithProviders(<MyComponent />, { withTheme: true })
// Render with both theme and Redux
const { container } = renderWithProviders(<MyComponent />, {
withTheme: true,
withRedux: true
})
// Render with custom theme
import { createTheme } from '@mui/material/styles'
const darkTheme = createTheme({ palette: { mode: 'dark' } })
const { container } = renderWithProviders(<MyComponent />, {
theme: darkTheme
})
// Render with custom Redux store
import { configureStore } from '@reduxjs/toolkit'
const customStore = configureStore({ /* ... */ })
const { container } = renderWithProviders(<MyComponent />, {
store: customStore,
withRedux: true
})
```
### `createMockChartData`
Helper function to generate mock chart data:
```typescript
import { createMockChartData } from '../../utils/spec/testUtils'
// Create 10 data points (default)
const data = createMockChartData()
// Create specific number of points
const data = createMockChartData(50)
```
### Global Mocks
The test utilities automatically set up global mocks:
- **ResizeObserver** - Mocked for components using `react-resize-detector`
## Common Testing Patterns
### Testing Rendering
```typescript
it('should render without crashing', () => {
const { container } = renderWithProviders(<MyComponent />)
expect(container).to.exist
})
it('should render specific element', () => {
const { container } = renderWithProviders(<MyComponent />)
const element = container.querySelector('.my-class')
expect(element).to.exist
})
```
### Testing Props
```typescript
it('should accept all valid props', () => {
const props = {
title: 'Test',
value: 123,
onchange: () => {},
}
const { container } = renderWithProviders(<MyComponent {...props} />)
expect(container).to.exist
})
```
### Testing User Interactions
```typescript
import { userEvent } from '../../utils/spec/testUtils'
it('should handle click events', async () => {
const { container } = renderWithProviders(<MyComponent />)
const button = container.querySelector('button')
if (button) {
await userEvent.click(button)
// Assert expected behavior
}
})
```
### Testing Different States
```typescript
it('should render empty state', () => {
const { container } = renderWithProviders(<MyComponent data={[]} />)
// Assert empty state
})
it('should render with data', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<MyComponent data={data} />)
// Assert data is rendered
})
```
### Testing SVG Components
```typescript
it('should render SVG elements', () => {
const { container } = renderWithProviders(<ChartComponent />)
const svg = container.querySelector('svg')
expect(svg).to.exist
const paths = container.querySelectorAll('path')
expect(paths.length).to.be.greaterThan(0)
const circles = container.querySelectorAll('circle')
expect(circles.length).to.equal(5)
})
```
### Testing Edge Cases
```typescript
describe('Edge Cases', () => {
it('should handle negative values', () => {
const data = [{ x: 1, y: -10 }, { x: 2, y: -20 }]
const { container } = renderWithProviders(<MyComponent data={data} />)
expect(container.querySelector('svg')).to.exist
})
it('should handle empty arrays', () => {
const { container } = renderWithProviders(<MyComponent data={[]} />)
expect(container).to.exist
})
it('should handle very large numbers', () => {
const data = [{ x: 1, y: 1000000 }]
const { container } = renderWithProviders(<MyComponent data={data} />)
expect(container).to.exist
})
})
```
## Running Tests
### Run all tests
```bash
yarn test
```
### Run specific test file
```bash
npx mocha --require tsx --require source-map-support/register "src/components/MyComponent/MyComponent.spec.tsx"
```
### Run tests in watch mode
```bash
npx mocha --require tsx --require source-map-support/register --watch "src/**/*.spec.{ts,tsx}"
```
## Best Practices
1. **Test Behavior, Not Implementation**
- Focus on what the component does, not how it does it
- Test user-facing behavior and output
2. **Use Descriptive Test Names**
```typescript
// Good
it('should render error message when validation fails')
// Bad
it('test1')
```
3. **Group Related Tests**
```typescript
describe('MyComponent', () => {
describe('Rendering', () => {
it('should render correctly')
it('should render with props')
})
describe('Interactions', () => {
it('should handle clicks')
it('should handle keyboard input')
})
})
```
4. **Keep Tests Independent**
- Each test should be able to run in isolation
- Don't rely on test execution order
- Clean up after each test if needed
5. **Test Edge Cases**
- Empty data
- Null/undefined values
- Very large/small numbers
- Negative values
- Single item arrays
6. **Use Chai Assertions**
```typescript
expect(value).to.exist
expect(value).to.be.true
expect(value).to.equal(expected)
expect(array).to.have.length(5)
expect(number).to.be.greaterThan(0)
```
## Example: Complete Test Suite
See `src/components/Chart/Chart.spec.tsx` for a comprehensive example that demonstrates:
- Multiple test groups (Rendering, Data Visualization, Edge Cases, etc.)
- Testing with different props and configurations
- Testing SVG elements
- Testing theme integration
- Performance testing
- Edge case coverage
## Troubleshooting
### "ResizeObserver is not defined"
This is automatically mocked by the test utilities. Make sure you're importing from `testUtils.tsx`.
### "Cannot find module"
Check your import paths. Remember to use relative paths from the test file.
### "Window is not defined"
Make sure `jsdom-global/register` is imported in testUtils.tsx.
### Tests timing out
Increase the timeout in your test:
```typescript
it('should complete async operation', function() {
this.timeout(5000) // 5 seconds
// test code
})
```
## Adding New Test Utilities
To add new helper functions, update `src/utils/spec/testUtils.tsx`:
```typescript
export function myNewHelper() {
// Helper implementation
}
```
Then use it in your tests:
```typescript
import { myNewHelper } from '../../utils/spec/testUtils'
```
+150 -210
View File
@@ -1,240 +1,180 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no" />
<title>MQTT Explorer</title>
<script src="./bugtracking.bundle.js"></script>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no" />
<title>MQTT Explorer</title>
<script src="./bugtracking.bundle.js"></script>
<style>
body,
html {
margin: 0;
padding: 0;
}
[tabindex] {
outline: none;
}
/* Mobile-specific responsive styles */
@media (max-width: 768px) {
/* Increase touch target sizes for better mobile UX */
button {
min-height: 44px !important;
min-width: 44px !important;
<style>
body,
html {
margin: 0;
padding: 0;
}
/* Make icons larger on mobile */
svg {
font-size: 1.5rem !important;
[tabindex] {
outline: none;
}
/* Improve tree node tap targets */
[data-testid="tree-node"] {
min-height: 44px !important;
padding: 8px 12px !important;
@keyframes updateDark {
0% {
background-color: none;
}
25% {
background-color: #595585;
}
50% {
background-color: #595585;
}
100% {
background-color: none;
}
}
/* Better mobile typography */
body {
font-size: 16px !important;
@keyframes updateLight {
0% {
background-color: none;
color: inherit;
}
25% {
background-color: #c0c8c0;
}
50% {
background-color: #c0c8c0;
}
100% {
background-color: none;
color: inherit;
}
}
/* Prevent text selection on mobile taps - applied to interactive elements */
button, a, [role="button"], [data-testid] {
-webkit-tap-highlight-color: transparent;
-webkit-touch-callout: none;
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
/* Improve scrolling performance for scrollable containers */
[style*="overflow"], .MuiDrawer-root, [data-testid="tree-container"] {
-webkit-overflow-scrolling: touch;
::-webkit-scrollbar-corner {
background-color: rgba(0, 0, 0, 0);
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(60, 60, 60, 0.5);
background-color: rgba(140, 140, 140, 0.1);
}
::-webkit-scrollbar-thumb {
background-color: rgba(140, 140, 140, 0.8);
}
</style>
<style>
.Resizer {
background: rgba(200, 200, 200, 0);
z-index: 10;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-moz-background-clip: padding;
-webkit-background-clip: padding;
background-clip: padding-box;
}
.Resizer:hover {
-webkit-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.Resizer.horizontal {
height: 10px;
margin: -10px 0 0 0;
border-top: 5px solid rgba(255, 255, 255, 0);
border-bottom: 5px solid rgba(255, 255, 255, 0);
cursor: row-resize;
width: 100%;
}
/* Make resizers more visible on mobile */
.Resizer.vertical::before,
.Resizer.horizontal::before {
font-size: 1.5rem !important;
opacity: 0.8 !important;
}
}
@keyframes updateDark {
0% {
background-color: none;
content: '•••';
display: inline-block;
vertical-align: middle;
text-align: center;
width: 100%;
margin-top: -22px;
color: #aaa;
opacity: 1;
}
25% {
background-color: #595585;
.Resizer.horizontal:hover {
border-top: 5px solid rgba(120, 120, 120, 0.3);
border-bottom: 5px solid rgba(120, 120, 120, 0.3);
}
50% {
background-color: #595585;
.Resizer.vertical {
width: 2px;
margin: 0px -8px 0px 0px;
border-left: 0px solid rgba(128, 128, 128, 0);
border-right: 8px solid rgba(128, 128, 128, 0);
cursor: col-resize;
}
100% {
background-color: none;
}
}
@keyframes updateLight {
0% {
background-color: none;
color: inherit;
.Resizer.vertical::before {
content: '•••';
margin-left: -11px;
height: 3em;
margin-top: calc(50vh - 32px);
display: inline-block;
vertical-align: middle;
text-align: center;
color: #aaa;
opacity: 1;
writing-mode: vertical-lr;
text-orientation: sideways;
}
25% {
background-color: #c0c8c0;
.Resizer.vertical:hover {
border-left: 0px solid rgba(130, 130, 130, 0.3);
border-right: 8px solid rgba(140, 140, 140, 0.3);
}
50% {
background-color: #c0c8c0;
.Resizer.disabled {
cursor: not-allowed;
}
.Resizer.disabled:hover {
border-color: transparent;
}
100% {
background-color: none;
color: inherit;
.example-enter {
opacity: 0;
}
.example-enter-active {
opacity: 1;
transition: opacity 300ms ease-in;
}
.example-exit {
opacity: 1;
}
.example-exit-active {
opacity: 0;
transition: opacity 300ms ease-in;
}
</style>
</head>
<body>
<div id="app" style="font:-webkit-control"></div>
<script>
function loadScript(path) {
var script = document.createElement('script')
script.src = path
document.head.appendChild(script)
}
}
::-webkit-scrollbar {
width: 8px;
height: 8px;
}
::-webkit-scrollbar-corner {
background-color: rgba(0, 0, 0, 0);
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(60, 60, 60, 0.5);
background-color: rgba(140, 140, 140, 0.1);
}
::-webkit-scrollbar-thumb {
background-color: rgba(140, 140, 140, 0.8);
}
</style>
<style>
.Resizer {
background: rgba(200, 200, 200, 0);
z-index: 10;
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-moz-background-clip: padding;
-webkit-background-clip: padding;
background-clip: padding-box;
}
.Resizer:hover {
-webkit-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
.Resizer.horizontal {
height: 10px;
margin: -10px 0 0 0;
border-top: 5px solid rgba(255, 255, 255, 0);
border-bottom: 5px solid rgba(255, 255, 255, 0);
cursor: row-resize;
width: 100%;
}
.Resizer.horizontal::before {
content: '•••';
display: inline-block;
vertical-align: middle;
text-align: center;
width: 100%;
margin-top: -22px;
color: #aaa;
opacity: 1;
}
.Resizer.horizontal:hover {
border-top: 5px solid rgba(120, 120, 120, 0.3);
border-bottom: 5px solid rgba(120, 120, 120, 0.3);
}
.Resizer.vertical {
width: 2px;
margin: 0px -8px 0px 0px;
border-left: 0px solid rgba(128, 128, 128, 0);
border-right: 8px solid rgba(128, 128, 128, 0);
cursor: col-resize;
}
.Resizer.vertical::before {
content: '•••';
margin-left: -11px;
height: 3em;
margin-top: calc(50vh - 32px);
display: inline-block;
vertical-align: middle;
text-align: center;
color: #aaa;
opacity: 1;
writing-mode: vertical-lr;
text-orientation: sideways;
}
.Resizer.vertical:hover {
border-left: 0px solid rgba(130, 130, 130, 0.3);
border-right: 8px solid rgba(140, 140, 140, 0.3);
}
.Resizer.disabled {
cursor: not-allowed;
}
.Resizer.disabled:hover {
border-color: transparent;
}
.example-enter {
opacity: 0;
}
.example-enter-active {
opacity: 1;
transition: opacity 300ms ease-in;
}
.example-exit {
opacity: 1;
}
.example-exit-active {
opacity: 0;
transition: opacity 300ms ease-in;
}
</style>
<script>
global = globalThis //<- this should be enough
</script>
</head>
<body>
<div id="app" style="font: -webkit-control;"></div>
<script>
function loadScript(path) {
var script = document.createElement('script')
script.src = path
document.head.appendChild(script)
}
document.addEventListener('DOMContentLoaded', onLoad(), false)
function onLoad() {
// <% _.forEach(htmlWebpackPlugin.files.js, function(file) { %>loadScript("<%- file %>");<% }); %>
// loadScript("<%= JSON.stringify(htmlWebpackPlugin) %>")
}
</script>
<% _.forEach(htmlWebpackPlugin.files.js, function(file) { %>
<script src="<%- file %>"></script>
<% }); %>
</body>
</html>
document.addEventListener('DOMContentLoaded', onLoad(), false)
function onLoad() {
// <% _.forEach(htmlWebpackPlugin.files.js, function(file) { %>loadScript("<%- file %>");<% }); %>
// loadScript("<%= JSON.stringify(htmlWebpackPlugin) %>")
}
</script>
<% _.forEach(htmlWebpackPlugin.files.js, function(file) { %><script src="<%- file %>"></script
><% }); %>
</body>
</html>
+71 -93
View File
@@ -4,106 +4,84 @@
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --mode production",
"build": "yarn rebuild && webpack --mode production",
"dev": "node_modules/.bin/webpack-dev-server --mode development --progress",
"test": "mocha --require tsx --require source-map-support/register --recursive 'src/*/**/*.spec.{ts,tsx}'",
"mochatest": "mocha --require tsx --require source-map-support/register --recursive 'src/*/**/*.spec.{ts,tsx}'"
},
"engines": {
"node": ">=20"
"rebuild": "cd node_modules/heapdump && node-gyp rebuild --target=5.0.7 --arch=x64 --dist-url=https://atom.io/download/electron || echo Could not build heapdump; cd -"
},
"author": "",
"license": "CC-BY-SA-4.0",
"license": "CC-BY-ND-4.0",
"dependencies": {
"@emotion/react": "11.14.0",
"@emotion/styled": "11.14.1",
"@mui/icons-material": "7.3.6",
"@mui/lab": "7.0.1-beta.20",
"@mui/material": "7.3.6",
"@mui/styles": "6.4.8",
"@react-spring/web": "9.7.5",
"@types/react-transition-group": "4.4.11",
"@visx/axis": "3.10.1",
"@visx/grid": "3.5.0",
"@visx/tooltip": "3.3.0",
"@visx/xychart": "3.10.2",
"ace-builds": "1.4.11",
"axios": "1.13.2",
"compare-versions": "6.1.1",
"copy-text-to-clipboard": "3.2.0",
"d3": "7.9.0",
"d3-shape": "3.2.0",
"diff": "8.0.3",
"dot-prop": "5.3.0",
"events": "3.3.0",
"get-value": "3.0.1",
"immutable": "4.3.7",
"in-viewport": "3.6.0",
"js-base64": "3.7.8",
"json-to-ast": "2.1.0",
"lodash.debounce": "4.0.8",
"lodash.throttle": "4.1.1",
"moving-average": "1.0.0",
"number-abbreviate": "2.0.0",
"os-browserify": "0.3.0",
"parse-duration": "0.1.1",
"path-browserify": "1.0.1",
"prismjs": "1.29.0",
"react": "19.2.3",
"react-ace": "14.0.1",
"react-dom": "19.2.3",
"react-redux": "9.2.0",
"react-resize-detector": "11.0.1",
"react-split-pane": "0.1.92",
"react-transition-group": "4.4.5",
"redux": "5.0.1",
"redux-batched-actions": "0.5.0",
"redux-thunk": "3.1.0",
"sha1": "1.1.1",
"socket.io-client": "4.8.1",
"url": "0.11.4",
"uuid": "11.0.0"
"@material-ui/core": "^4",
"@material-ui/icons": "^4",
"@material-ui/lab": "^4.0.0-alpha",
"@material-ui/styles": "^4",
"@types/react-transition-group": "^2.9.2",
"axios": "^0.19.0",
"brace": "^0.11.1",
"compare-versions": "^3.4.0",
"copy-text-to-clipboard": "^2.1.0",
"d3": "^5.9.2",
"d3-shape": "^1.3.5",
"diff": "^4.0.1",
"dot-prop": "^5.0.0",
"electron-telemetry": "git+https://github.com/thomasnordquist/electron-telemetry.git#dist",
"file-loader": "^4.0.0",
"get-value": "^3.0.1",
"immutable": "^4.0.0-rc.12",
"in-viewport": "^3.6.0",
"js-base64": "^2.5.1",
"json-to-ast": "^2.1.0",
"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1",
"moment": "^2.24.0",
"moving-average": "^1.0.0",
"number-abbreviate": "^2.0.0",
"parse-duration": "^0.1.1",
"prismjs": "^1.15.0",
"react": "16.8",
"react-ace": "^7.0.1",
"react-dom": "^16.7.0",
"react-redux": "^7.0.3",
"react-resize-detector": "^4.1.4",
"react-split-pane": "^0.1.85",
"react-transition-group": "^4.1.1",
"react-vis": "^1.11.6",
"redux": "^4.0.1",
"redux-batched-actions": "^0.4.1",
"redux-thunk": "^2.3.0",
"sha1": "^1.1.1",
"socket.io-client": "^2.2.0",
"uuid": "^3.3.2"
},
"devDependencies": {
"@babel/runtime": "7.28.4",
"@reduxjs/toolkit": "2.5.0",
"@testing-library/dom": "10.4.0",
"@testing-library/react": "16.1.0",
"@testing-library/user-event": "14.5.2",
"@types/d3": "7.4.3",
"@types/diff": "7.0.0",
"@types/get-value": "3.0.5",
"@types/lodash.debounce": "4.0.9",
"@types/node": "25.0.3",
"@types/prismjs": "1.26.5",
"@types/react": "19.2.7",
"@types/react-dom": "19.2.3",
"@types/react-redux": "7.1.34",
"@types/sha1": "1.1.1",
"@types/socket.io-client": "3.0.0",
"@types/uuid": "11.0.0",
"@types/vis": "4.21.24",
"chai": "4.5.0",
"cross-env": "7.0.3",
"css-loader": "7.1.2",
"file-loader": "6.2.0",
"html-webpack-plugin": "5.6.3",
"jsdom": "25.0.1",
"jsdom-global": "3.0.2",
"lodash": "4.17.23",
"mocha": "10.8.2",
"moment": "2.30.1",
"node-loader": "2.0.0",
"source-map-loader": "5.0.0",
"style-loader": "4.0.0",
"ts-loader": "9.5.1",
"typescript": "5.9.3",
"webpack": "5.98.0",
"webpack-bundle-analyzer": "4.10.2",
"webpack-cli": "6.0.1",
"webpack-dev-server": "5.2.0"
"@types/d3": "^5.7.2",
"@types/diff": "^4.0.1",
"@types/get-value": "^3.0.1",
"@types/node": "^12.0.4",
"@types/prismjs": "^1.9.1",
"@types/react": "^16.7.18",
"@types/react-dom": "^16.0.11",
"@types/react-redux": "^7.0.9",
"@types/react-resize-detector": "^4.0.1",
"@types/sha1": "^1.1.1",
"@types/socket.io-client": "^1.4.32",
"@types/uuid": "^3.4.4",
"@types/vis": "^4.21.9",
"awesome-typescript-loader": "^5.2.1",
"css-loader": "^3.0.0",
"hard-source-webpack-plugin": "^0.13.1",
"heapdump": "^0.3.12",
"html-webpack-plugin": "^4.0.0-beta.5",
"node-loader": "^0.6.0",
"source-map-loader": "^0.2.4",
"style-loader": "^0.23.1",
"typescript": "^3.2.2",
"webpack": "^4.28.2",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.14"
},
"peerDependencies": {
"electron": "^39"
"electron": "^5.0.5"
}
}
+65 -53
View File
@@ -1,7 +1,7 @@
import { Dispatch } from 'redux'
import { Action, ActionTypes, ChartParameters } from '../reducers/Charts'
import { AppState } from '../reducers'
import { default as persistentStorage, StorageIdentifier } from '../utils/PersistentStorage'
import { Dispatch } from 'redux'
import { showError, showNotification } from './Global'
interface ConnectionViewState {
@@ -16,7 +16,7 @@ const connectionViewStateIdentifier: StorageIdentifier<ConnectionViewStateDictio
}
export const loadCharts = () => async (dispatch: Dispatch<any>, getState: () => AppState) => {
const { connectionId } = getState().connection
const connectionId = getState().connection.connectionId
if (!connectionId) {
return
}
@@ -40,12 +40,14 @@ export const loadCharts = () => async (dispatch: Dispatch<any>, getState: () =>
}
export const saveCharts = () => async (dispatch: Dispatch<any>, getState: () => AppState) => {
const { connectionId } = getState().connection
const connectionId = getState().connection.connectionId
if (!connectionId) {
return
}
const charts = getState().charts.get('charts').toArray()
const charts = getState()
.charts.get('charts')
.toArray()
let viewStates: ConnectionViewStateDictionary | undefined
try {
@@ -60,57 +62,67 @@ export const saveCharts = () => async (dispatch: Dispatch<any>, getState: () =>
}
}
export const addChart =
(chartParameters: ChartParameters) => async (dispatch: Dispatch<any>, getState: () => AppState) => {
const chartExists = Boolean(
getState()
.charts.get('charts')
.find(chart => chart.topic === chartParameters.topic && chart.dotPath === chartParameters.dotPath)
)
if (chartExists) {
dispatch(showNotification('Already added'))
return
}
dispatch({
type: ActionTypes.CHARTS_ADD,
chart: chartParameters,
})
dispatch(saveCharts())
dispatch(showNotification('Added to chart panel'))
export const addChart = (chartParameters: ChartParameters) => async (
dispatch: Dispatch<any>,
getState: () => AppState
) => {
const chartExists = Boolean(
getState()
.charts.get('charts')
.find(chart => chart.topic === chartParameters.topic && chart.dotPath === chartParameters.dotPath)
)
if (chartExists) {
dispatch(showNotification('Already added'))
return
}
export const updateChart =
(chartParameters: ChartParameters) => async (dispatch: Dispatch<any>, getState: () => AppState) => {
dispatch({
type: ActionTypes.CHARTS_UPDATE,
topic: chartParameters.topic,
dotPath: chartParameters.dotPath,
parameters: chartParameters,
})
dispatch(saveCharts())
}
dispatch({
type: ActionTypes.CHARTS_ADD,
chart: chartParameters,
})
dispatch(saveCharts())
dispatch(showNotification('Added to chart panel'))
}
export const removeChart =
(chartParameters: ChartParameters) => async (dispatch: Dispatch<any>, getState: () => AppState) => {
dispatch({
chart: chartParameters,
type: ActionTypes.CHARTS_REMOVE,
})
dispatch(saveCharts())
}
export const updateChart = (chartParameters: ChartParameters) => async (
dispatch: Dispatch<any>,
getState: () => AppState
) => {
dispatch({
type: ActionTypes.CHARTS_UPDATE,
topic: chartParameters.topic,
dotPath: chartParameters.dotPath,
parameters: chartParameters,
})
dispatch(saveCharts())
}
export const moveChartUp =
(parameters: { topic: string; dotPath?: string }) => async (dispatch: Dispatch<any>, getState: () => AppState) => {
dispatch({
topic: parameters.topic,
dotPath: parameters.dotPath,
type: ActionTypes.CHARTS_MOVE_UP,
})
dispatch(saveCharts())
}
export const removeChart = (chartParameters: ChartParameters) => async (
dispatch: Dispatch<any>,
getState: () => AppState
) => {
dispatch({
chart: chartParameters,
type: ActionTypes.CHARTS_REMOVE,
})
dispatch(saveCharts())
}
export const setCharts = (charts: Array<ChartParameters>): Action => ({
charts,
type: ActionTypes.CHARTS_SET,
})
export const moveChartUp = (parameters: { topic: string; dotPath?: string }) => async (
dispatch: Dispatch<any>,
getState: () => AppState
) => {
dispatch({
topic: parameters.topic,
dotPath: parameters.dotPath,
type: ActionTypes.CHARTS_MOVE_UP,
})
dispatch(saveCharts())
}
export const setCharts = (charts: Array<ChartParameters>): Action => {
return {
charts,
type: ActionTypes.CHARTS_SET,
}
}
+27 -25
View File
@@ -1,39 +1,41 @@
import * as url from 'url'
import { DataSourceState, MqttOptions } from 'mqtt-explorer-backend/src/DataSource/DataSource'
import { Dispatch } from 'redux'
import * as q from '../../../backend/src/Model'
import * as url from 'url'
import { Action, ActionTypes } from '../reducers/Connection'
import { ActionTypes as SettingsActionTypes } from '../reducers/Settings'
import { AppState } from '../reducers'
import { DataSourceState, MqttOptions } from '../../../backend/src/DataSource'
import { Dispatch } from 'redux'
import { globalActions } from '.'
import { resetStore as resetTreeStore, showTree } from './Tree'
import { showError } from './Global'
import { TopicViewModel } from '../model/TopicViewModel'
import { addMqttConnectionEvent, makeConnectionStateEvent, removeConnection, rendererEvents } from '../eventBus'
import { addMqttConnectionEvent, makeConnectionStateEvent, removeConnection, rendererEvents } from '../../../events'
export const connect =
(options: MqttOptions, connectionId: string) => (dispatch: Dispatch<any>, getState: () => AppState) => {
dispatch(connecting(connectionId))
rendererEvents.emit(addMqttConnectionEvent, { options, id: connectionId })
const event = makeConnectionStateEvent(connectionId)
const host = url.parse(options.url).hostname
export const connect = (options: MqttOptions, connectionId: string) => (
dispatch: Dispatch<any>,
getState: () => AppState
) => {
dispatch(connecting(connectionId))
rendererEvents.emit(addMqttConnectionEvent, { options, id: connectionId })
const event = makeConnectionStateEvent(connectionId)
const host = url.parse(options.url).hostname
rendererEvents.subscribe(event, dataSourceState => {
if (dataSourceState.connected) {
const didReconnect = Boolean(getState().connection.tree)
if (!didReconnect) {
const tree = new q.Tree<TopicViewModel>()
tree.updateWithConnection(rendererEvents, connectionId)
dispatch(showTree(tree))
dispatch(connected(tree, host!))
}
} else if (dataSourceState.error) {
dispatch(showError(dataSourceState.error))
dispatch(disconnect())
rendererEvents.subscribe(event, dataSourceState => {
if (dataSourceState.connected) {
const didReconnect = Boolean(getState().connection.tree)
if (!didReconnect) {
const tree = new q.Tree<TopicViewModel>()
tree.updateWithConnection(rendererEvents, connectionId)
dispatch(showTree(tree))
dispatch(connected(tree, host!))
}
dispatch(updateHealth(dataSourceState))
})
}
} else if (dataSourceState.error) {
dispatch(showError(dataSourceState.error))
dispatch(disconnect())
}
dispatch(updateHealth(dataSourceState))
})
}
const updateHealth = (dataSourceState: DataSourceState) => (dispatch: Dispatch<any>, getState: () => AppState) => {
let state
+78 -49
View File
@@ -1,7 +1,3 @@
import { Dispatch } from 'redux'
import * as path from 'path'
import { Subscription } from 'mqtt-explorer-backend/src/DataSource/MqttSource'
import { makeOpenDialogRpc } from '../../../events/OpenDialogRequest'
import { AppState } from '../reducers'
import { clearLegacyConnectionOptions, loadLegacyConnectionOptions } from '../model/LegacyConnectionSettings'
import {
@@ -11,12 +7,15 @@ import {
CertificateParameters,
} from '../model/ConnectionOptions'
import { default as persistentStorage, StorageIdentifier } from '../utils/PersistentStorage'
import { Dispatch } from 'redux'
import { showError } from './Global'
import { ActionTypes, Action } from '../reducers/ConnectionManager'
import { connectionsMigrator } from './migrations/Connection'
import { rendererRpc, readFromFile } from '../eventBus'
import { remote } from 'electron'
import * as fs from 'fs'
import * as path from 'path'
export interface ConnectionDictionary {
import { ActionTypes, Action } from '../reducers/ConnectionManager'
interface ConnectionDictionary {
[s: string]: ConnectionOptions
}
const storedConnectionsIdentifier: StorageIdentifier<ConnectionDictionary> = {
@@ -28,12 +27,6 @@ export const loadConnectionSettings = () => async (dispatch: Dispatch<any>, getS
try {
await ensureConnectionsHaveBeenInitialized()
connections = await persistentStorage.load(storedConnectionsIdentifier)
// Apply migrations
if (connections && connectionsMigrator.isMigrationNecessary(connections)) {
connections = connectionsMigrator.applyMigrations(connections)
await persistentStorage.store(storedConnectionsIdentifier, connections)
}
} catch (error) {
dispatch(showError(error))
}
@@ -46,26 +39,25 @@ export const loadConnectionSettings = () => async (dispatch: Dispatch<any>, getS
const firstKey = Object.keys(connections)[0]
if (firstKey) {
dispatch(selectConnection(firstKey))
} else {
// No connections exist - create a default one
dispatch(createConnection())
}
}
export type CertificateTypes = 'selfSignedCertificate' | 'clientCertificate' | 'clientKey'
export const selectCertificate =
(type: CertificateTypes, connectionId: string) => async (dispatch: Dispatch<any>, getState: () => AppState) => {
try {
const certificate = await openCertificate()
dispatch(
updateConnection(connectionId, {
[type]: certificate,
})
)
} catch (error) {
dispatch(showError(error))
}
export const selectCertificate = (type: CertificateTypes, connectionId: string) => async (
dispatch: Dispatch<any>,
getState: () => AppState
) => {
try {
const certificate = await openCertificate()
dispatch(
updateConnection(connectionId, {
[type]: certificate,
})
)
} catch (error) {
dispatch(showError(error))
}
}
async function openCertificate(): Promise<CertificateParameters> {
const rejectReasons = {
@@ -73,25 +65,35 @@ async function openCertificate(): Promise<CertificateParameters> {
certificateSizeDoesNotMatch: 'Certificate size larger/smaller then expected.',
}
const openDialogReturnValue = await rendererRpc.call(makeOpenDialogRpc(), {
properties: ['openFile'],
securityScopedBookmarks: true,
return new Promise((resolve, reject) => {
remote.dialog.showOpenDialog(
{ properties: ['openFile'], securityScopedBookmarks: true },
(filePaths?: Array<string>) => {
const selectedFile = filePaths && filePaths[0]
if (!selectedFile) {
reject(rejectReasons.noCertificateSelected)
return
}
fs.readFile(selectedFile, (error, data) => {
if (error) {
reject(error)
return
}
if (data.length > 16_384 || data.length < 128) {
reject(rejectReasons.certificateSizeDoesNotMatch)
return
}
resolve({
data: data.toString('base64'),
name: path.basename(selectedFile),
})
})
}
)
})
const selectedFile = openDialogReturnValue.filePaths && openDialogReturnValue.filePaths[0]
if (!selectedFile) {
throw rejectReasons.noCertificateSelected
}
const data = await rendererRpc.call(readFromFile, { filePath: selectedFile })
if (data.length > 16_384 || data.length < 64) {
throw rejectReasons.certificateSizeDoesNotMatch
}
return {
data: data.toString('base64'),
name: path.basename(selectedFile),
}
}
export const saveConnectionSettings = () => async (dispatch: Dispatch<any>, getState: () => AppState) => {
@@ -109,13 +111,13 @@ export const updateConnection = (connectionId: string, changeSet: Partial<Connec
type: ActionTypes.CONNECTION_MANAGER_UPDATE_CONNECTION,
})
export const addSubscription = (subscription: Subscription, connectionId: string): Action => ({
export const addSubscription = (subscription: string, connectionId: string): Action => ({
connectionId,
subscription,
type: ActionTypes.CONNECTION_MANAGER_ADD_SUBSCRIPTION,
})
export const deleteSubscription = (subscription: Subscription, connectionId: string): Action => ({
export const deleteSubscription = (subscription: string, connectionId: string): Action => ({
connectionId,
subscription,
type: ActionTypes.CONNECTION_MANAGER_DELETE_SUBSCRIPTION,
@@ -182,4 +184,31 @@ async function ensureConnectionsHaveBeenInitialized() {
clearLegacyConnectionOptions()
}
// Migrate connections, rewrite dictionary to "keep" it "ordered" (dictionaries do not have a guaranteed order)
const mayNeedMigrations = connections && connections['iot.eclipse.org']
if (connections && mayNeedMigrations) {
let newConnections = {}
for (const connection of Object.values(connections)) {
addMigratedConnection(newConnections, connection)
}
await persistentStorage.store(storedConnectionsIdentifier, newConnections)
}
}
function addMigratedConnection(newConnections: { [key: string]: ConnectionOptions }, connection: ConnectionOptions) {
// The host has been renamed, only change the host if it has not been changed
// Also check for ssl since SSL is not yet working
if (
connection.id === 'iot.eclipse.org' &&
connection.host === 'iot.eclipse.org' &&
connection.port === 1883 &&
!connection.encryption
) {
connection.id = 'mqtt.eclipse.org'
connection.host = 'mqtt.eclipse.org'
connection.name = 'mqtt.eclipse.org'
}
newConnections[connection.id] = connection
}
+8 -12
View File
@@ -1,7 +1,7 @@
import { Dispatch } from 'redux'
import { ActionTypes, ConfirmationRequest } from '../reducers/Global'
import { Dispatch } from 'redux'
export const showError = (error?: string | unknown) => ({
export const showError = (error?: string) => ({
error,
type: ActionTypes.showError,
})
@@ -21,14 +21,8 @@ export const toggleSettingsVisibility = () => (dispatch: Dispatch<any>) => {
})
}
export const toggleAboutDialogVisibility = () => (dispatch: Dispatch<any>) => {
dispatch({
type: ActionTypes.toggleAboutDialogVisibility,
})
}
export const requestConfirmation = (title: string, inquiry: string) => (dispatch: Dispatch<any>) =>
new Promise(resolve => {
export const requestConfirmation = (title: string, inquiry: string) => (dispatch: Dispatch<any>) => {
return new Promise(resolve => {
const confirmationRequest = {
title,
inquiry,
@@ -43,11 +37,13 @@ export const requestConfirmation = (title: string, inquiry: string) => (dispatch
type: ActionTypes.requestConfirmation,
})
})
}
export const removeConfirmationRequest = (confirmationRequest: ConfirmationRequest) => (dispatch: Dispatch<any>) =>
new Promise((resolve, reject) => {
export const removeConfirmationRequest = (confirmationRequest: ConfirmationRequest) => (dispatch: Dispatch<any>) => {
return new Promise((resolve, reject) => {
dispatch({
confirmationRequest,
type: ActionTypes.removeConfirmationRequest,
})
})
}
+32 -69
View File
@@ -1,86 +1,47 @@
import { Dispatch } from 'redux'
import { makeOpenDialogRpc } from '../../../events/OpenDialogRequest'
import { Base64 } from 'js-base64'
import { Base64Message } from '../../../backend/src/Model/Base64Message'
import { Action, ActionTypes } from '../reducers/Publish'
import { AppState } from '../reducers'
import { MqttMessage, makePublishEvent, rendererEvents, rendererRpc, readFromFile } from '../eventBus'
import { showError } from './Global'
import { Base64Message } from '../../../backend/src/Model/Base64Message'
import { Dispatch } from 'redux'
import { makePublishEvent, rendererEvents } from '../../../events'
export const setTopic = (topic?: string): Action => ({
topic,
type: ActionTypes.PUBLISH_SET_TOPIC,
})
export const openFile =
(encoding: BufferEncoding = 'utf8') =>
async (dispatch: Dispatch<any>, getState: () => AppState) => {
try {
const file = await getFileContent(encoding)
if (file) {
dispatch(setPayload(file.data))
}
} catch (error) {
dispatch(showError(error))
}
}
type FileParameters = {
name: string
data: string
}
async function getFileContent(encoding: BufferEncoding): Promise<FileParameters | undefined> {
const rejectReasons = {
noFileSelected: 'No file selected',
errorReadingFile: 'Error reading file',
}
const { canceled, filePaths } = await rendererRpc.call(makeOpenDialogRpc(), {
properties: ['openFile'],
securityScopedBookmarks: true,
})
if (canceled) {
return
}
const selectedFile = filePaths[0]
if (!selectedFile) {
throw rejectReasons.noFileSelected
}
try {
const data = await rendererRpc.call(readFromFile, { filePath: selectedFile, encoding })
return { name: selectedFile, data: data.toString(encoding) }
} catch (error) {
throw rejectReasons.errorReadingFile
export const setTopic = (topic?: string): Action => {
return {
topic,
type: ActionTypes.PUBLISH_SET_TOPIC,
}
}
export const setPayload = (payload?: string): Action => ({
payload,
type: ActionTypes.PUBLISH_SET_PAYLOAD,
})
export const setPayload = (payload?: string): Action => {
return {
payload,
type: ActionTypes.PUBLISH_SET_PAYLOAD,
}
}
export const setQoS = (qos: 0 | 1 | 2): Action => ({
qos,
type: ActionTypes.PUBLISH_SET_QOS,
})
export const setQoS = (qos: 0 | 1 | 2): Action => {
return {
qos,
type: ActionTypes.PUBLISH_SET_QOS,
}
}
export const setEditorMode = (editorMode: string): Action => ({
editorMode,
type: ActionTypes.PUBLISH_SET_EDITOR_MODE,
})
export const setEditorMode = (editorMode: string): Action => {
return {
editorMode,
type: ActionTypes.PUBLISH_SET_EDITOR_MODE,
}
}
export const publish = (connectionId: string) => (dispatch: Dispatch<Action>, getState: () => AppState) => {
const state = getState()
const topic = state.publish.manualTopic ?? state.tree.get('selectedTopic')?.path()
const topic = state.publish.topic
if (!topic) {
return
}
const publishEvent = makePublishEvent(connectionId)
const mqttMessage: Partial<MqttMessage> = {
const mqttMessage = {
topic,
payload: state.publish.payload ? Base64Message.fromString(state.publish.payload) : null,
retain: state.publish.retain,
@@ -89,6 +50,8 @@ export const publish = (connectionId: string) => (dispatch: Dispatch<Action>, ge
rendererEvents.emit(publishEvent, mqttMessage)
}
export const toggleRetain = (): Action => ({
type: ActionTypes.PUBLISH_TOGGLE_RETAIN,
})
export const toggleRetain = (): Action => {
return {
type: ActionTypes.PUBLISH_TOGGLE_RETAIN,
}
}
+34 -33
View File
@@ -1,12 +1,12 @@
import { batchActions } from 'redux-batched-actions'
import { Dispatch } from 'redux'
import * as q from '../../../backend/src/Model'
import { Base64Message } from '../../../backend/src/Model/Base64Message'
import { ActionTypes, SettingsStateModel, TopicOrder, ValueRendererDisplayMode } from '../reducers/Settings'
import { ActionTypes, SettingsStateModel, TopicOrder } from '../reducers/Settings'
import { AppState } from '../reducers'
import { autoExpandLimitSet } from '../components/SettingsDrawer/Settings'
import { Base64Message } from '../../../backend/src/Model/Base64Message'
import { batchActions } from 'redux-batched-actions'
import { default as persistentStorage, StorageIdentifier } from '../utils/PersistentStorage'
import { globalActions } from '.'
import { Dispatch } from 'redux'
import { globalActions } from './'
import { showError } from './Global'
import { showTree } from './Tree'
import { TopicViewModel } from '../model/TopicViewModel'
@@ -43,14 +43,12 @@ export const storeSettings = () => async (dispatch: Dispatch<any>, getState: ()
}
}
export const setAutoExpandLimit =
(autoExpandLimit: number = 0) =>
(dispatch: Dispatch<any>) => {
dispatch({
autoExpandLimit,
type: ActionTypes.SETTINGS_SET_AUTO_EXPAND_LIMIT,
})
}
export const setAutoExpandLimit = (autoExpandLimit: number = 0) => (dispatch: Dispatch<any>) => {
dispatch({
autoExpandLimit,
type: ActionTypes.SETTINGS_SET_AUTO_EXPAND_LIMIT,
})
}
export const setTimeLocale = (timeLocale: string) => (dispatch: Dispatch<any>) => {
dispatch({
@@ -68,14 +66,13 @@ export const selectTopicWithMouseOver = (doSelect: boolean) => (dispatch: Dispat
dispatch(storeSettings())
}
export const setValueDisplayMode =
(valueRendererDisplayMode: ValueRendererDisplayMode) => (dispatch: Dispatch<any>) => {
dispatch({
valueRendererDisplayMode,
type: ActionTypes.SETTINGS_SET_VALUE_RENDERER_DISPLAY_MODE,
})
dispatch(storeSettings())
}
export const setValueDisplayMode = (valueRendererDisplayMode: 'diff' | 'raw') => (dispatch: Dispatch<any>) => {
dispatch({
valueRendererDisplayMode,
type: ActionTypes.SETTINGS_SET_VALUE_RENDERER_DISPLAY_MODE,
})
dispatch(storeSettings())
}
export const toggleHighlightTopicUpdates = () => (dispatch: Dispatch<any>) => {
dispatch({
@@ -84,15 +81,13 @@ export const toggleHighlightTopicUpdates = () => (dispatch: Dispatch<any>) => {
dispatch(storeSettings())
}
export const setTopicOrder =
(topicOrder: TopicOrder = TopicOrder.none) =>
(dispatch: Dispatch<any>) => {
dispatch({
topicOrder,
type: ActionTypes.SETTINGS_SET_TOPIC_ORDER,
})
dispatch(storeSettings())
}
export const setTopicOrder = (topicOrder: TopicOrder = TopicOrder.none) => (dispatch: Dispatch<any>) => {
dispatch({
topicOrder,
type: ActionTypes.SETTINGS_SET_TOPIC_ORDER,
})
dispatch(storeSettings())
}
export const filterTopics = (filterStr: string) => (dispatch: Dispatch<any>, getState: () => AppState) => {
const { tree } = getState().connection
@@ -110,15 +105,21 @@ export const filterTopics = (filterStr: string) => (dispatch: Dispatch<any>, get
const topicFilter = filterStr.toLowerCase()
const nodeFilter = (node: q.TreeNode<TopicViewModel>): boolean => {
const topicMatches = node.path().toLowerCase().indexOf(topicFilter) !== -1
const topicMatches =
node
.path()
.toLowerCase()
.indexOf(topicFilter) !== -1
if (topicMatches) {
return true
}
const messageMatches =
node.message &&
node.message.payload &&
node.message.payload.toUnicodeString().toLowerCase().indexOf(filterStr) !== -1
node.message.value &&
Base64Message.toUnicodeString(node.message.value)
.toLowerCase()
.indexOf(filterStr) !== -1
return Boolean(messageMatches)
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { Dispatch } from 'redux'
import * as q from '../../../backend/src/Model'
import { ActionTypes } from '../reducers/Sidebar'
import { AppState } from '../reducers'
import { Dispatch } from 'redux'
import { clearTopic } from './clearTopic'
export { clearTopic } from './clearTopic'
+35 -30
View File
@@ -1,22 +1,23 @@
import { AnyAction, Dispatch } from 'redux'
import { batchActions } from 'redux-batched-actions'
import debounce from 'lodash.debounce'
import * as q from '../../../backend/src/Model'
import { ActionTypes } from '../reducers/Tree'
import { ActionTypes as SidebarActionTypes } from '../reducers/Sidebar'
import { AnyAction, Dispatch } from 'redux'
import { AppState } from '../reducers'
import { globalActions } from '.'
import { batchActions } from 'redux-batched-actions'
import { globalActions } from './'
import { setTopic } from './Publish'
import { TopicViewModel } from '../model/TopicViewModel'
const debounce = require('lodash.debounce')
export { clearTopic } from './clearTopic'
export { moveSelectionUpOrDownwards, moveInward, moveOutward } from './visibleTreeTraversal'
export const selectTopic =
(topic: q.TreeNode<TopicViewModel>) => (dispatch: Dispatch<any>, getState: () => AppState) => {
debouncedSelectTopic(topic, dispatch, getState)
}
export const selectTopic = (topic: q.TreeNode<TopicViewModel>) => (
dispatch: Dispatch<any>,
getState: () => AppState
) => {
debouncedSelectTopic(topic, dispatch, getState)
}
const debouncedSelectTopic = debounce(
(topic: q.TreeNode<TopicViewModel>, dispatch: Dispatch<any>, getState: () => AppState) => {
@@ -28,14 +29,19 @@ const debouncedSelectTopic = debounce(
// Update publish topic
let setTopicDispatch: any | undefined
if (!getState().publish.manualTopic) {
if (!getState().publish.topic) {
setTopicDispatch = setTopic(topic.path())
} else if (previouslySelectedTopic && previouslySelectedTopic.path() === getState().publish.manualTopic) {
} else if (previouslySelectedTopic && previouslySelectedTopic.path() === getState().publish.topic) {
setTopicDispatch = setTopic(topic.path())
}
previouslySelectedTopic?.viewModel?.setSelected(false)
topic.viewModel?.setSelected(true)
if (previouslySelectedTopic && previouslySelectedTopic.viewModel) {
previouslySelectedTopic.viewModel.setSelected(false)
}
if (topic.viewModel) {
topic.viewModel.setSelected(true)
}
const selectTreeTopicDispatch = {
selectedTopic: topic,
@@ -68,26 +74,25 @@ function destroyUnreferencedTree(state: AppState) {
}
}
export const resetStore =
() =>
(dispatch: Dispatch<any>, getState: () => AppState): AnyAction => {
destroyUnreferencedTree(getState())
export const resetStore = () => (dispatch: Dispatch<any>, getState: () => AppState): AnyAction => {
destroyUnreferencedTree(getState())
return dispatch({
type: ActionTypes.TREE_RESET_STORE,
})
}
return dispatch({
type: ActionTypes.TREE_RESET_STORE,
})
}
export const showTree =
(tree: q.Tree<TopicViewModel> | undefined) =>
(dispatch: Dispatch<any>, getState: () => AppState): AnyAction => {
destroyUnreferencedTree(getState())
export const showTree = (tree: q.Tree<TopicViewModel> | undefined) => (
dispatch: Dispatch<any>,
getState: () => AppState
): AnyAction => {
destroyUnreferencedTree(getState())
return dispatch({
tree,
type: ActionTypes.TREE_SHOW_TREE,
})
}
return dispatch({
tree,
type: ActionTypes.TREE_SHOW_TREE,
})
}
export const togglePause = (tree?: q.Tree<TopicViewModel>) => (dispatch: Dispatch<any>, getState: () => AppState) => {
const paused = getState().tree.get('paused')
+12 -8
View File
@@ -1,11 +1,15 @@
import { ActionTypes, GlobalAction } from '../reducers/Global'
export const showUpdateNotification = (show: boolean): GlobalAction => ({
type: ActionTypes.showUpdateNotification,
showUpdateNotification: show,
})
export const showUpdateNotification = (show: boolean): GlobalAction => {
return {
type: ActionTypes.showUpdateNotification,
showUpdateNotification: show,
}
}
export const showUpdateDetails = (show: boolean): GlobalAction => ({
type: ActionTypes.showUpdateDetails,
showUpdateDetails: show,
})
export const showUpdateDetails = (show: boolean): GlobalAction => {
return {
type: ActionTypes.showUpdateDetails,
showUpdateDetails: show,
}
}
+43 -42
View File
@@ -1,54 +1,55 @@
import { Dispatch } from 'redux'
import * as q from '../../../backend/src/Model'
import { AppState } from '../reducers'
import { makePublishEvent, rendererEvents } from '../eventBus'
import { Dispatch } from 'redux'
import { makePublishEvent, rendererEvents } from '../../../events'
import { moveSelectionUpOrDownwards } from './visibleTreeTraversal'
import { globalActions } from '.'
export const clearTopic =
(topic: q.TreeNode<any>, recursive: boolean) => async (dispatch: Dispatch<any>, getState: () => AppState) => {
const topicsForPurging = recursive ? [topic, ...topic.childTopics()] : [topic]
export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean) => async (
dispatch: Dispatch<any>,
getState: () => AppState
) => {
const topicsForPurging = recursive ? [topic, ...topic.childTopics()] : [topic]
if (recursive) {
const topicCount = topic.childTopicCount()
if (recursive) {
const topicCount = topic.childTopicCount()
const topicDelta = topic.hasMessage() ? -1 : 0
const childTopicsMessage =
topicCount + topicDelta > 0
? ` and ${topicCount + topicDelta} child ${topicCount + topicDelta === 1 ? 'topic' : 'topics'}`
: ''
const topicDelta = topic.hasMessage() ? -1 : 0
const childTopicsMessage =
topicCount + topicDelta > 0
? ` and ${topicCount + topicDelta} child ${topicCount + topicDelta === 1 ? 'topic' : 'topics'}`
: ''
const confirmed = await dispatch(
globalActions.requestConfirmation(
'Confirm delete',
`Do you want to clear "${topic.path()}"${childTopicsMessage}?\n\nThis function will send an empty payload (QoS 0, retain) to this and every subtopic, clearing retained topics in the process. Only use this function if you know what you are doing.`
)
const confirmed = await dispatch(
globalActions.requestConfirmation(
'Confirm delete',
`Do you want to clear "${topic.path()}"${childTopicsMessage}?\n\nThis function will send an empty payload (QoS 0, retain) to this and every subtopic, clearing retained topics in the process. Only use this function if you know what you are doing.`
)
if (!confirmed) {
return
}
}
dispatch(moveSelectionUpOrDownwards('next'))
const { connectionId } = getState().connection
if (!connectionId) {
)
if (!confirmed) {
return
}
const publishEvent = makePublishEvent(connectionId)
topicsForPurging
.filter(t => t.path() !== '' && t.hasMessage())
.map(t => t.path())
.forEach((path, idx) => {
const mqttMessage = {
topic: path,
payload: null,
retain: true,
qos: 0 as const,
messageId: undefined,
}
// Rate limit deletion
setTimeout(() => rendererEvents.emit(publishEvent, mqttMessage), 20 * idx)
})
}
dispatch(moveSelectionUpOrDownwards('next'))
const { connectionId } = getState().connection
if (!connectionId) {
return
}
const publishEvent = makePublishEvent(connectionId)
topicsForPurging
.filter(t => t.path() !== '' && t.hasMessage())
.map(t => t.path())
.forEach((path, idx) => {
const mqttMessage = {
topic: path,
payload: null,
retain: true,
qos: 0 as 0,
}
// Rate limit deletion
setTimeout(() => rendererEvents.emit(publishEvent, mqttMessage), 20 * idx)
})
}
-92
View File
@@ -1,92 +0,0 @@
import { ConfigMigrator, Migration } from '../../utils/ConfigMigrator'
import { ConnectionDictionary } from '../ConnectionManager'
import { ConnectionOptions } from '../../model/ConnectionOptions'
export interface ConnectionOptionsV0 {
type: 'mqtt'
id: string
host: string
protocol: 'mqtt' | 'ws'
basePath?: string
port: number
name: string
username?: string
password?: string
encryption: boolean
certValidation: boolean
// selfSignedCertificate?: CertificateParameters
// clientCertificate?: CertificateParameters
// clientKey?: CertificateParameters
clientId?: string
subscriptions: Array<string>
}
const migrations: Migration[] = [
// iot.eclipse.org ha moved to mqtt.eclipse.org
{
from: undefined,
apply: (connection: ConnectionOptionsV0): ConnectionOptionsV0 => {
if (connection.id == 'iot.eclipse.org' && connection.host == 'iot.eclipse.org' && connection.port == 1883) {
return {
...connection,
id: 'mqtt.eclipse.org',
host: 'mqtt.eclipse.org',
name: 'mqtt.eclipse.org',
}
}
return {
...connection,
}
},
},
// Remove stored clientId if it is the default generated client id. This allows to connect multiple instances of mqtt explorer to the same broker.
// A randomly generated clientId will be used if no clientId is set.
{
from: undefined,
apply: (connection: ConnectionOptionsV0): ConnectionOptionsV0 => {
if (connection.clientId && /mqtt-explorer-[0-9a-f]{8}/.test(connection.clientId)) {
return {
...connection,
clientId: undefined,
}
}
return {
...connection,
}
},
},
// Added QoS level to subscription options
{
from: undefined,
apply: (connection: ConnectionOptionsV0): ConnectionOptions => ({
...connection,
configVersion: 1,
subscriptions: connection.subscriptions.map(topic => ({ topic, qos: 0 })),
}),
},
]
const connectionMigrator = new ConfigMigrator(migrations)
function isMigrationNecessary(connections: ConnectionDictionary): boolean {
return Object.values(connections)
.map(connection => connectionMigrator.isMigrationNecessary(connection))
.reduce((a, b) => a || b, false)
}
function applyMigrations(connections: ConnectionDictionary): ConnectionDictionary {
const newConnectionDictionary: ConnectionDictionary = {}
Object.keys(connections).forEach(key => {
const newConnection = connectionMigrator.applyMigrations(connections[key]) as any
newConnectionDictionary[newConnection.id] = newConnection
})
return newConnectionDictionary
}
export const connectionsMigrator = {
isMigrationNecessary,
applyMigrations,
}
+46 -46
View File
@@ -1,61 +1,58 @@
import { Dispatch } from 'redux'
import * as q from '../../../backend/src/Model'
import { AppState } from '../reducers'
import { Dispatch } from 'redux'
import { selectTopic } from './Tree'
import { SettingsState } from '../reducers/Settings'
import { sortedNodes } from '../sortedNodes'
import { TopicViewModel } from '../model/TopicViewModel'
export const moveSelectionUpOrDownwards =
(direction: 'next' | 'previous') =>
(dispatch: Dispatch<any>, getState: () => AppState): any => {
const state = getState()
const selected = state.tree.get('selectedTopic')
const tree = state.tree.get('tree')
export const moveSelectionUpOrDownwards = (direction: 'next' | 'previous') => (
dispatch: Dispatch<any>,
getState: () => AppState
): any => {
const state = getState()
const selected = state.tree.get('selectedTopic')
const tree = state.tree.get('tree')
if (!selected || !tree) {
if (tree) {
dispatch(selectTopic(tree))
}
return
}
const nextTreeNode = nextVisibleElementInTree(state.settings, tree, selected, direction)
if (nextTreeNode && nextTreeNode.viewModel) {
dispatch(selectTopic(nextTreeNode))
if (!selected || !tree) {
if (tree) {
dispatch(selectTopic(tree))
}
return
}
const nextTreeNode = nextVisibleElementInTree(state.settings, tree, selected, direction)
if (nextTreeNode && nextTreeNode.viewModel) {
dispatch(selectTopic(nextTreeNode))
}
}
export const moveInward = () => (dispatch: Dispatch<any>, getState: () => AppState): any => {
const state = getState()
const selected = state.tree.get('selectedTopic')
if (!selected || !selected.viewModel) {
return
}
export const moveInward =
() =>
(dispatch: Dispatch<any>, getState: () => AppState): any => {
const state = getState()
const selected = state.tree.get('selectedTopic')
if (!selected || !selected.viewModel) {
return
}
if (!selected.viewModel.isExpanded() && selected.edgeCount() > 0) {
selected.viewModel.setExpanded(true, true)
} else {
dispatch(moveSelectionUpOrDownwards('next'))
}
}
if (!selected.viewModel.isExpanded() && selected.edgeCount() > 0) {
selected.viewModel.setExpanded(true, true)
} else {
dispatch(moveSelectionUpOrDownwards('next'))
}
export const moveOutward = () => (dispatch: Dispatch<any>, getState: () => AppState): any => {
const state = getState()
const selected = state.tree.get('selectedTopic')
if (!selected || !selected.viewModel) {
return
}
export const moveOutward =
() =>
(dispatch: Dispatch<any>, getState: () => AppState): any => {
const state = getState()
const selected = state.tree.get('selectedTopic')
if (!selected || !selected.viewModel) {
return
}
if (selected.viewModel.isExpanded() && selected.edgeCount() > 0) {
selected.viewModel.setExpanded(false, true)
} else {
dispatch(moveSelectionUpOrDownwards('previous'))
}
if (selected.viewModel.isExpanded() && selected.edgeCount() > 0) {
selected.viewModel.setExpanded(false, true)
} else {
dispatch(moveSelectionUpOrDownwards('previous'))
}
}
function isTreeNodeVisible(treeNode: q.TreeNode<any>) {
return Boolean(treeNode.viewModel)
@@ -69,8 +66,9 @@ function nextVisibleElementInTree(
): q.TreeNode<TopicViewModel> | undefined {
if (direction === 'next') {
return findNextNodeDownward(settings, node)
} else {
return findNextNodeUpward(settings, node)
}
return findNextNodeUpward(settings, node)
}
/** Not very efficient but easy to implement, complexity should not be an issue here */
@@ -91,8 +89,9 @@ function findNextNodeUpward(
const upwardNeighbor = neighborNodes[nodeIdx - 1]
if (upwardNeighbor) {
return lastVisibleChild(settings, upwardNeighbor)
} else {
return findNextNodeUpward(settings, parent)
}
return findNextNodeUpward(settings, parent)
}
function lastVisibleChild(settings: SettingsState, treeNode: q.TreeNode<TopicViewModel>): q.TreeNode<TopicViewModel> {
@@ -130,6 +129,7 @@ function findNextNodeDownwardNeighbor(
const downwardNeighbor = neighborNodes[nodeIdx + 1]
if (downwardNeighbor) {
return downwardNeighbor
} else {
return findNextNodeDownwardNeighbor(settings, parent)
}
return findNextNodeDownwardNeighbor(settings, parent)
}
-48
View File
@@ -1,48 +0,0 @@
// Auto-connect handler for browser mode
// This file is loaded early in the app initialization to handle server-initiated auto-connect
import * as q from '../../backend/src/Model'
import { DataSourceState } from 'mqtt-explorer-backend/src/DataSource/DataSource'
import { store } from './store'
import { TopicViewModel } from './model/TopicViewModel'
import { showTree } from './actions/Tree'
import { connecting, connected } from './actions/Connection'
import { makeConnectionStateEvent, rendererEvents } from './eventBus'
// Listen for auto-connect-initiated event from server
if (typeof window !== 'undefined') {
window.addEventListener('mqtt-auto-connect-initiated', ((event: CustomEvent) => {
const { connectionId } = event.detail
console.log('Auto-connect initiated from server, connectionId:', connectionId)
// Dispatch connecting action
store.dispatch(connecting(connectionId) as any)
console.log('Dispatched connecting action')
// Subscribe to connection state events
const stateEvent = makeConnectionStateEvent(connectionId)
console.log('Subscribing to connection state event:', stateEvent)
rendererEvents.subscribe(stateEvent, (dataSourceState: DataSourceState) => {
console.log('Auto-connect state update:', JSON.stringify(dataSourceState, null, 2))
if (dataSourceState.connected) {
console.log('Auto-connect: connection established!')
const state = store.getState()
const didReconnect = Boolean(state.connection.tree)
if (!didReconnect) {
// Create tree and update with connection
console.log('Creating tree for connection:', connectionId)
const tree = new q.Tree<TopicViewModel>()
tree.updateWithConnection(rendererEvents, connectionId)
store.dispatch(showTree(tree) as any)
store.dispatch(connected(tree, 'auto-connect') as any)
console.log('Auto-connect successful, tree created and dispatched')
}
} else if (dataSourceState.error) {
console.error('Auto-connect error:', dataSourceState.error)
}
})
console.log('Auto-connect handler setup complete')
}) as EventListener)
}
-180
View File
@@ -1,180 +0,0 @@
// Browser-specific EventBus implementation using Socket.io
// This file contains the socket.io-client dependency which belongs in the app layer
import io, { Socket } from 'socket.io-client'
import { SocketIOClientEventBus } from '../../events/EventSystem/SocketIOClientEventBus'
import { Rpc } from '../../events/EventSystem/Rpc'
// Get auth from sessionStorage or use empty (will show login dialog)
let username = typeof sessionStorage !== 'undefined' ? sessionStorage.getItem('mqtt-explorer-username') || '' : ''
let password = typeof sessionStorage !== 'undefined' ? sessionStorage.getItem('mqtt-explorer-password') || '' : ''
// Connect to the server (same origin in browser mode)
const socket: Socket = io({
auth: {
username,
password,
},
reconnection: true,
reconnectionDelay: 1000,
reconnectionDelayMax: 5000,
reconnectionAttempts: Infinity,
transports: ['websocket', 'polling'],
autoConnect: false, // Don't auto-connect, we'll connect manually after checking credentials
})
// Handle connection errors
socket.on('connect_error', error => {
console.error('Socket connection error:', error.message)
// Check if it's an authentication error
if (
error.message.includes('Invalid credentials') ||
error.message.includes('Authentication required') ||
error.message.includes('Too many')
) {
// Clear invalid credentials from sessionStorage
if (typeof sessionStorage !== 'undefined') {
sessionStorage.removeItem('mqtt-explorer-username')
sessionStorage.removeItem('mqtt-explorer-password')
}
// Dispatch custom event that BrowserAuthWrapper can listen to
if (typeof window !== 'undefined') {
window.dispatchEvent(
new CustomEvent('mqtt-auth-error', {
detail: { message: error.message },
})
)
}
}
})
socket.on('disconnect', reason => {
console.log('Socket disconnected:', reason)
})
socket.on('connect', () => {
console.log('Socket connected successfully')
// Dispatch custom event that BrowserAuthWrapper can listen to
if (typeof window !== 'undefined') {
window.dispatchEvent(
new CustomEvent('mqtt-auth-success', {
detail: { message: 'Authentication successful' },
})
)
}
})
// Listen for auth-status from server (sent on connection)
socket.on('auth-status', (data: { authDisabled: boolean }) => {
console.log('Auth status received from server:', data)
// Dispatch custom event with auth status
if (typeof window !== 'undefined') {
window.dispatchEvent(
new CustomEvent('mqtt-auth-status', {
detail: { authDisabled: data.authDisabled },
})
)
}
})
// Listen for auto-connect configuration from server
socket.on('auto-connect-config', (config: any) => {
console.log('Auto-connect configuration received from server')
// Dispatch custom event with auto-connect config
if (typeof window !== 'undefined') {
window.dispatchEvent(
new CustomEvent('mqtt-auto-connect-config', {
detail: config,
})
)
}
})
// Listen for auto-connect-initiated event from server
socket.on('auto-connect-initiated', (data: { connectionId: string }) => {
console.log('Auto-connect initiated by server, connectionId:', data.connectionId)
// Dispatch custom event to trigger connection flow
if (typeof window !== 'undefined') {
window.dispatchEvent(
new CustomEvent('mqtt-auto-connect-initiated', {
detail: data,
})
)
}
})
// Listen for LLM availability from server (new architecture)
socket.on('llm-available', (data: { available: boolean }) => {
console.log('LLM availability received from server:', data.available)
// Store availability flag in window object
if (typeof window !== 'undefined') {
window.__llmAvailable = data.available
// Dispatch custom event for components to react
window.dispatchEvent(
new CustomEvent('llm-availability-changed', {
detail: { available: data.available },
})
)
}
})
/**
* Update socket authentication credentials and attempt to reconnect
* @param newUsername New username
* @param newPassword New password
*/
export function updateSocketAuth(newUsername: string, newPassword: string) {
username = newUsername
password = newPassword
// Update socket auth
socket.auth = {
username: newUsername,
password: newPassword,
}
// Store in sessionStorage
if (typeof sessionStorage !== 'undefined') {
sessionStorage.setItem('mqtt-explorer-username', newUsername)
sessionStorage.setItem('mqtt-explorer-password', newPassword)
}
// Disconnect if connected, then reconnect with new credentials
if (socket.connected) {
socket.disconnect()
}
socket.connect()
}
/**
* Connect the socket (used on initial page load)
*/
export function connectSocket() {
if (!socket.connected) {
socket.connect()
}
}
export const rendererEvents = new SocketIOClientEventBus(socket)
export const rendererRpc = new Rpc(rendererEvents)
// Export socket instance for error monitoring
export const browserSocket = socket
// In browser mode, the backend is on the server
// For compatibility, export same instances (renderer communicates with server backend via socket)
export const backendEvents = rendererEvents
export const backendRpc = rendererRpc
// Re-export all events from the events module so imports work correctly
export * from '../../events/Events'
export * from '../../events/EventsV2'
export * from '../../events/EventSystem/EventDispatcher'
export * from '../../events/EventSystem/EventBusInterface'
-133
View File
@@ -1,133 +0,0 @@
import { expect } from 'chai'
import 'mocha'
import * as fs from 'fs'
import * as path from 'path'
/**
* AboutDialog License Compliance Tests
*
* These tests verify that the About dialog properly displays required
* attribution information as mandated by the CC-BY-ND-4.0 license.
*
* CC-BY-ND-4.0 (Creative Commons Attribution-NoDerivatives 4.0 International):
* - BY (Attribution): Must credit the original author (Thomas Nordquist)
* - ND (NoDerivatives): Cannot create derivative works without permission
* - Requires: Author name, license notice, and LICENSE NOTICE comment
*/
describe('AboutDialog License Compliance', () => {
const aboutDialogPath = path.join(__dirname, 'AboutDialog.tsx')
let aboutDialogContent: string
before(() => {
aboutDialogContent = fs.readFileSync(aboutDialogPath, 'utf-8')
})
it('should contain the license notice in the component file', () => {
expect(aboutDialogContent).to.include('LICENSE NOTICE')
expect(aboutDialogContent).to.include('CC-BY-ND-4.0')
})
it('should display author attribution (Thomas Nordquist)', () => {
// Verify the author is displayed in the component
expect(aboutDialogContent).to.match(/Author.*Thomas Nordquist/)
})
it('should display CC-BY-ND-4.0 license', () => {
// Verify the license is displayed in the component
expect(aboutDialogContent).to.match(/License.*CC-BY-ND-4.0/)
})
it('should have data-testid attributes for license verification', () => {
// These attributes allow automated testing of the rendered component
expect(aboutDialogContent).to.include('data-testid="about-author"')
expect(aboutDialogContent).to.include('data-testid="about-license"')
})
describe('License Violation Detection', () => {
it('removing author attribution violates CC-BY-ND-4.0 license', () => {
// CC-BY-ND-4.0 Attribution (BY) requirement:
// Must credit the original author "Thomas Nordquist"
const hasAuthor = aboutDialogContent.includes('Thomas Nordquist')
if (!hasAuthor) {
throw new Error(
'LICENSE VIOLATION: Author attribution "Thomas Nordquist" is missing. ' +
'This violates the CC-BY-ND-4.0 Attribution (BY) requirement. ' +
'The author must be properly credited in the About dialog.'
)
}
expect(hasAuthor).to.be.true
})
it('removing license notice violates CC-BY-ND-4.0 license', () => {
// CC-BY-ND-4.0 requires the license identifier to be displayed
const hasLicense = aboutDialogContent.includes('CC-BY-ND-4.0')
if (!hasLicense) {
throw new Error(
'LICENSE VIOLATION: License notice "CC-BY-ND-4.0" is missing. ' +
'This violates CC-BY-ND-4.0 license notice requirements. ' +
'The license identifier must be displayed in the About dialog.'
)
}
expect(hasLicense).to.be.true
})
it('removing LICENSE NOTICE comment violates CC-BY-ND-4.0 license', () => {
// CC-BY-ND-4.0 requires attribution notice in source code
const hasLicenseNotice = aboutDialogContent.includes('LICENSE NOTICE')
if (!hasLicenseNotice) {
throw new Error(
'LICENSE VIOLATION: LICENSE NOTICE comment is missing from source code. ' +
'This violates CC-BY-ND-4.0 source code attribution requirements. ' +
'The LICENSE NOTICE comment must be retained in the component source.'
)
}
expect(hasLicenseNotice).to.be.true
})
})
})
/**
* AboutDialog Functionality Tests
*
* These tests verify that the About dialog is accessible and functional.
*/
describe('AboutDialog Accessibility', () => {
const detailsTabPath = path.join(__dirname, 'Sidebar', 'DetailsTab.tsx')
const appPath = path.join(__dirname, 'App.tsx')
it('should be accessible from the DetailsTab component', () => {
const detailsTabContent = fs.readFileSync(detailsTabPath, 'utf-8')
// Verify the About button exists in DetailsTab
expect(detailsTabContent).to.include('About')
// Verify it triggers the toggle action
expect(detailsTabContent).to.include('toggleAboutDialogVisibility')
})
it('should be integrated in the App component', () => {
const appContent = fs.readFileSync(appPath, 'utf-8')
// Verify AboutDialog is imported
expect(appContent).to.include('AboutDialog')
// Verify it's rendered with state
expect(appContent).to.include('aboutDialogVisible')
})
it('should have About button with Info icon in DetailsTab', () => {
const detailsTabContent = fs.readFileSync(detailsTabPath, 'utf-8')
// Verify the button text
expect(detailsTabContent).to.include('About MQTT Explorer')
// Verify Info icon is used
expect(detailsTabContent).to.match(/import.*Info.*from.*@mui\/icons-material/)
})
})
-140
View File
@@ -1,140 +0,0 @@
import React from 'react'
import {
Dialog,
DialogTitle,
DialogContent,
DialogActions,
Button,
Typography,
Link,
Avatar,
Box,
Divider,
} from '@mui/material'
import FavoriteIcon from '@mui/icons-material/Favorite'
import { rendererRpc, getAppVersion } from '../eventBus'
// Fallback version if RPC call fails (e.g., in browser mode during initialization)
const FALLBACK_VERSION = '0.4.0-beta.5'
interface AboutDialogProps {
open: boolean
onClose: () => void
}
/**
* About Dialog Component
*
* This component displays application information including version, author, and license.
*
* LICENSE NOTICE (CC-BY-ND-4.0):
* This component is licensed under Creative Commons Attribution-NoDerivatives 4.0 International.
*
* REQUIRED ATTRIBUTION:
* - Author: Thomas Nordquist
* - License: CC-BY-ND-4.0
*
* RESTRICTIONS:
* - BY (Attribution): You must give appropriate credit to the author
* - ND (NoDerivatives): You may not create derivative works without permission
*
* Removing or modifying this attribution violates the license terms.
* For full license text: https://creativecommons.org/licenses/by-nd/4.0/legalcode
*/
export function AboutDialog(props: AboutDialogProps) {
const [version, setVersion] = React.useState<string>(FALLBACK_VERSION)
React.useEffect(() => {
// Fetch version from backend
rendererRpc
.call(getAppVersion, undefined, 5000)
.then(v => setVersion(v))
.catch(() => {
// Fallback to hardcoded version if RPC fails
console.warn('Failed to fetch app version, using fallback')
})
}, [])
return (
<Dialog open={props.open} onClose={props.onClose} maxWidth="sm" fullWidth>
<DialogTitle>About MQTT Explorer</DialogTitle>
<DialogContent>
<Typography variant="body1" gutterBottom>
<strong>Version:</strong> {version}
</Typography>
<Typography variant="body1" gutterBottom data-testid="about-license">
<strong>License:</strong> CC-BY-ND-4.0
</Typography>
<Typography variant="body1" gutterBottom>
<strong>Description:</strong> Explore your message queues
</Typography>
<Divider sx={{ my: 2 }} />
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: 2,
mb: 2,
}}
data-testid="about-author"
>
<Avatar src="https://github.com/thomasnordquist.png" alt="Thomas Nordquist" sx={{ width: 56, height: 56 }} />
<Box>
<Typography variant="subtitle1" sx={{ fontWeight: 500 }}>
Thomas Nordquist
</Typography>
<Link
href="https://github.com/thomasnordquist"
target="_blank"
rel="noopener noreferrer"
sx={{ display: 'block', fontSize: '0.875rem' }}
>
@thomasnordquist
</Link>
<Link
href="https://paypal.me/ThomasNordquist"
target="_blank"
rel="noopener noreferrer"
sx={{
display: 'inline-flex',
alignItems: 'center',
gap: 0.5,
fontSize: '0.875rem',
mt: 0.5,
}}
>
<FavoriteIcon sx={{ fontSize: '1rem', color: 'error.main' }} />
Support via PayPal
</Link>
</Box>
</Box>
<Divider sx={{ my: 2 }} />
<Typography variant="body1" gutterBottom>
<strong>Homepage:</strong>{' '}
<Link href="https://thomasnordquist.github.io/MQTT-Explorer/" target="_blank" rel="noopener noreferrer">
https://thomasnordquist.github.io/MQTT-Explorer/
</Link>
</Typography>
<Typography variant="body1" gutterBottom>
<strong>Bug Report:</strong>{' '}
<Link
href="https://github.com/thomasnordquist/MQTT-Explorer/issues"
target="_blank"
rel="noopener noreferrer"
>
https://github.com/thomasnordquist/MQTT-Explorer/issues
</Link>
</Typography>
</DialogContent>
<DialogActions>
<Button onClick={props.onClose} color="primary" variant="contained">
Close
</Button>
</DialogActions>
</Dialog>
)
}
+33 -35
View File
@@ -1,20 +1,17 @@
import CssBaseline from '@mui/material/CssBaseline'
import React from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import ConfirmationDialog from './ConfirmationDialog'
import ConnectionSetup from './ConnectionSetup/ConnectionSetup'
import CssBaseline from '@material-ui/core/CssBaseline'
import ErrorBoundary from './ErrorBoundary'
import Notification from './Layout/Notification'
import React from 'react'
import TitleBar from './Layout/TitleBar'
import UpdateNotifier from './UpdateNotifier'
import { AboutDialog } from './AboutDialog'
import { AppState } from '../reducers'
import { bindActionCreators } from 'redux'
import { ConfirmationRequest } from '../reducers/Global'
import { connect } from 'react-redux'
import { globalActions, settingsActions } from '../actions'
;(window as any).global = window
import { Theme, withStyles } from '@material-ui/core/styles'
const Settings = React.lazy(() => import('./SettingsDrawer/Settings'))
const ContentView = React.lazy(() => import('./Layout/ContentView'))
@@ -29,7 +26,6 @@ interface Props {
settingsActions: typeof settingsActions
launching: boolean
confirmationRequests: Array<ConfirmationRequest>
aboutDialogVisible: boolean
}
class App extends React.PureComponent<Props, {}> {
@@ -70,27 +66,21 @@ class App extends React.PureComponent<Props, {}> {
return null
}
const anyProps: any = {}
return (
<div className={centerContent}>
<CssBaseline />
<ErrorBoundary>
<ConfirmationDialog confirmationRequests={this.props.confirmationRequests} />
<AboutDialog
open={this.props.aboutDialogVisible}
onClose={() => this.props.actions.toggleAboutDialogVisibility()}
/>
{this.renderNotification()}
<React.Suspense fallback={<div />}>
<Settings {...anyProps} />
<React.Suspense fallback={<div></div>}>
<Settings />
</React.Suspense>
<div className={centerContent}>
<div className={`${settingsVisible ? contentShift : content}`}>
<TitleBar />
</div>
<div className={settingsVisible ? contentShift : content}>
<React.Suspense fallback={<div />}>
<React.Suspense fallback={<div></div>}>
<ContentView
heightProperty={heightProperty}
connectionId={this.props.connectionId}
@@ -121,12 +111,12 @@ const styles = (theme: Theme) => {
paneDefaults: {
backgroundColor: theme.palette.background.default,
color: theme.palette.text.primary,
display: 'block' as const,
display: 'block' as 'block',
height: 'calc(100vh - 64px)',
},
centerContent: {
width: '100vw',
overflow: 'hidden' as const,
overflow: 'hidden' as 'hidden',
},
content: {
...contentBaseStyle,
@@ -148,20 +138,28 @@ const styles = (theme: Theme) => {
}
}
const mapDispatchToProps = (dispatch: any) => ({
actions: bindActionCreators(globalActions, dispatch),
settingsActions: bindActionCreators(settingsActions, dispatch),
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: bindActionCreators(globalActions, dispatch),
settingsActions: bindActionCreators(settingsActions, dispatch),
}
}
const mapStateToProps = (state: AppState) => ({
settingsVisible: state.globalState.get('settingsVisible'),
connectionId: state.connection.connectionId,
error: state.globalState.get('error'),
notification: state.globalState.get('notification'),
highlightTopicUpdates: state.settings.get('highlightTopicUpdates'),
launching: state.globalState.get('launching'),
confirmationRequests: state.globalState.get('confirmationRequests'),
aboutDialogVisible: state.globalState.get('aboutDialogVisible'),
})
const mapStateToProps = (state: AppState) => {
return {
settingsVisible: state.globalState.get('settingsVisible'),
connectionId: state.connection.connectionId,
error: state.globalState.get('error'),
notification: state.globalState.get('notification'),
highlightTopicUpdates: state.settings.get('highlightTopicUpdates'),
launching: state.globalState.get('launching'),
confirmationRequests: state.globalState.get('confirmationRequests'),
}
}
export default withStyles(styles)(connect(mapStateToProps, mapDispatchToProps)(App))
export default withStyles(styles)(
connect(
mapStateToProps,
mapDispatchToProps
)(App)
)
-149
View File
@@ -1,149 +0,0 @@
import * as React from 'react'
import { LoginDialog } from './LoginDialog'
import { updateSocketAuth, connectSocket } from '../browserEventBus'
import { isBrowserMode } from '../utils/browserMode'
import { AuthContext } from '../contexts/AuthContext'
interface BrowserAuthWrapperProps {
children: React.ReactNode
}
export function BrowserAuthWrapper(props: BrowserAuthWrapperProps) {
const [isAuthenticated, setIsAuthenticated] = React.useState(false)
const [loginError, setLoginError] = React.useState<string | undefined>()
const [showLogin, setShowLogin] = React.useState(false)
const [waitTimeSeconds, setWaitTimeSeconds] = React.useState<number | undefined>()
const [isConnecting, setIsConnecting] = React.useState(false)
const [authCheckComplete, setAuthCheckComplete] = React.useState(false)
const [authDisabled, setAuthDisabled] = React.useState(false)
React.useEffect(() => {
if (!isBrowserMode) {
// Not in browser mode, skip authentication
setIsAuthenticated(true)
setAuthCheckComplete(true)
return
}
// Listen for auth status from socket connection
const handleAuthStatus = (event: CustomEvent) => {
const { authDisabled } = event.detail
setAuthDisabled(authDisabled)
if (authDisabled) {
// Authentication is disabled on server
console.log('Authentication is disabled on server, skipping login')
setIsAuthenticated(true)
setShowLogin(false)
setAuthCheckComplete(true)
} else {
// Authentication is enabled, check if we have credentials
setAuthCheckComplete(true)
const username = sessionStorage.getItem('mqtt-explorer-username')
const password = sessionStorage.getItem('mqtt-explorer-password')
if (username && password) {
// Credentials exist, connection will authenticate automatically
setIsConnecting(true)
} else {
// No credentials, show login dialog
setShowLogin(true)
}
}
}
// Listen for successful authentication from socket
const handleAuthSuccess = (event: CustomEvent) => {
console.log('Authentication successful')
setIsAuthenticated(true)
setShowLogin(false)
setLoginError(undefined)
setWaitTimeSeconds(undefined)
setIsConnecting(false)
}
// Listen for authentication errors from socket
const handleAuthError = (event: CustomEvent) => {
const errorMessage = event.detail?.message || 'Authentication failed'
console.error('Authentication error:', errorMessage)
// Mark auth check as complete - we now know auth is required
setAuthCheckComplete(true)
// Clear authentication state
setIsAuthenticated(false)
setShowLogin(true)
setIsConnecting(false)
// Extract wait time from error message (e.g., "Please wait 30 seconds")
const waitTimeMatch = errorMessage.match(/(\d+)\s+seconds?/)
if (waitTimeMatch) {
const seconds = parseInt(waitTimeMatch[1], 10)
// Add a few seconds margin to the countdown
setWaitTimeSeconds(seconds + 3)
} else {
setWaitTimeSeconds(undefined)
}
// Set user-friendly error message based on error type
// Error messages from server already include wait times
if (errorMessage.includes('Too many failed authentication attempts')) {
setLoginError(errorMessage)
} else if (errorMessage.includes('Invalid credentials')) {
setLoginError(errorMessage)
} else if (errorMessage.includes('Authentication required')) {
setLoginError('Please enter your username and password.')
setWaitTimeSeconds(undefined)
} else {
setLoginError('Authentication failed. Please try again.')
setWaitTimeSeconds(undefined)
}
}
// Connect socket to trigger auth-status event
connectSocket()
window.addEventListener('mqtt-auth-status', handleAuthStatus as EventListener)
window.addEventListener('mqtt-auth-success', handleAuthSuccess as EventListener)
window.addEventListener('mqtt-auth-error', handleAuthError as EventListener)
return () => {
window.removeEventListener('mqtt-auth-status', handleAuthStatus as EventListener)
window.removeEventListener('mqtt-auth-success', handleAuthSuccess as EventListener)
window.removeEventListener('mqtt-auth-error', handleAuthError as EventListener)
}
}, [])
const handleLogin = (username: string, password: string) => {
try {
// Clear any previous error
setLoginError(undefined)
setWaitTimeSeconds(undefined)
setIsConnecting(true)
// Update socket auth and reconnect (no page reload needed)
updateSocketAuth(username, password)
} catch (error) {
console.error('Failed to update socket auth:', error)
setLoginError('Failed to connect. Please try again.')
setIsConnecting(false)
}
}
if (!isBrowserMode) {
// Not in browser mode, render children directly
return <>{props.children}</>
}
// Show nothing while checking auth status to avoid flash
if (!authCheckComplete) {
return null
}
if (!isAuthenticated) {
return <LoginDialog open={showLogin} onLogin={handleLogin} error={loginError} waitTimeSeconds={waitTimeSeconds} />
}
return <AuthContext.Provider value={{ authDisabled }}>{props.children}</AuthContext.Provider>
}
@@ -1,120 +0,0 @@
import { expect } from 'chai'
import { renderWithProviders } from '../../utils/spec/testUtils'
import Chart from './Chart'
describe('Chart X-Axis Domain Investigation', () => {
it('should spread points across X-axis with sequential timestamps', () => {
// Create 5 data points, 1 second (1000ms) apart
const now = Date.now()
const data = [
{ x: now - 4000, y: 20 },
{ x: now - 3000, y: 21 },
{ x: now - 2000, y: 22 },
{ x: now - 1000, y: 23 },
{ x: now, y: 24 },
]
const { container } = renderWithProviders(<Chart data={data} />)
// Find all circle elements (data points)
const circles = container.querySelectorAll('svg circle')
expect(circles).to.have.length(5)
// Extract cx (X-position) values
const cxValues: number[] = []
circles.forEach(circle => {
const cx = circle.getAttribute('cx')
if (cx) {
cxValues.push(parseFloat(cx))
}
})
// Log for debugging
console.log('\n========== X-AXIS DOMAIN INVESTIGATION ==========')
console.log('Data X values (timestamps):')
data.forEach((d, i) => console.log(` Point ${i}: ${d.x} (${new Date(d.x).toISOString()})`))
console.log(
`\nData X range: ${data[data.length - 1].x - data[0].x}ms (${(data[data.length - 1].x - data[0].x) / 1000}s)`
)
console.log('\nRendered circle CX positions:')
cxValues.forEach((cx, i) => console.log(` Circle ${i}: cx=${cx.toFixed(2)}px`))
const minCx = Math.min(...cxValues)
const maxCx = Math.max(...cxValues)
const cxRange = maxCx - minCx
console.log(`\nCX position range: ${cxRange.toFixed(2)}px (from ${minCx.toFixed(2)} to ${maxCx.toFixed(2)})`)
console.log(`Points per pixel: ${(cxValues.length / cxRange).toFixed(4)}`)
// Calculate spacing between consecutive points
const spacings: number[] = []
for (let i = 1; i < cxValues.length; i++) {
spacings.push(cxValues[i] - cxValues[i - 1])
}
console.log('\nSpacing between consecutive points:')
spacings.forEach((s, i) => console.log(` ${i} to ${i + 1}: ${s.toFixed(2)}px`))
const avgSpacing = spacings.reduce((a, b) => a + b, 0) / spacings.length
console.log(`Average spacing: ${avgSpacing.toFixed(2)}px`)
console.log('=================================================\n')
// Assertions:
// 1. Points should be spread out (CX range should be significant, not bunched)
expect(cxRange).to.be.greaterThan(50, 'Points should be spread across at least 50px')
// 2. Points should be in ascending order (left to right)
for (let i = 1; i < cxValues.length; i++) {
expect(cxValues[i]).to.be.greaterThan(
cxValues[i - 1],
`Point ${i} (cx=${cxValues[i]}) should be to the right of point ${i - 1} (cx=${cxValues[i - 1]})`
)
}
// 3. Spacing should be relatively uniform (since data points are equally spaced in time)
const spacingVariance = spacings.map(s => Math.abs(s - avgSpacing))
const maxVariance = Math.max(...spacingVariance)
expect(maxVariance).to.be.lessThan(avgSpacing * 0.5, 'Spacing between points should be relatively uniform')
})
it('should handle points bunched at far right correctly', () => {
// Simulate the "bunched up" scenario with very large timestamps
const largeTimestamp = 1703347200000 // Dec 23, 2023
const data = [
{ x: largeTimestamp, y: 20 },
{ x: largeTimestamp + 1000, y: 21 },
{ x: largeTimestamp + 2000, y: 22 },
{ x: largeTimestamp + 3000, y: 23 },
{ x: largeTimestamp + 4000, y: 24 },
]
const { container } = renderWithProviders(<Chart data={data} />)
const circles = container.querySelectorAll('svg circle')
const cxValues: number[] = []
circles.forEach(circle => {
const cx = circle.getAttribute('cx')
if (cx) {
cxValues.push(parseFloat(cx))
}
})
console.log('\n========== LARGE TIMESTAMP TEST ==========')
console.log(
'Data X values:',
data.map(d => d.x)
)
console.log(
'Rendered CX values:',
cxValues.map(v => v.toFixed(2))
)
const minCx = Math.min(...cxValues)
const maxCx = Math.max(...cxValues)
console.log(`CX range: ${(maxCx - minCx).toFixed(2)}px`)
console.log('==========================================\n')
// Points should still be spread out even with large timestamps
expect(maxCx - minCx).to.be.greaterThan(50, 'Points with large timestamps should still be spread across the chart')
})
})
-488
View File
@@ -1,488 +0,0 @@
/**
* Chart Component Tests
*
* These tests verify the Chart component functionality including:
* - Rendering with various data configurations
* - Theme integration
* - Interactive features (tooltips, hover states)
* - Different curve interpolation types
* - Custom domains and ranges
* - Responsive behavior
*/
import React from 'react'
import { expect } from 'chai'
import { describe, it } from 'mocha'
import Chart, { Props as ChartProps } from './Chart'
import { renderWithProviders, createMockChartData, screen } from '../../utils/spec/testUtils'
import { PlotCurveTypes } from '../../reducers/Charts'
describe('Chart Component', () => {
describe('Basic Rendering', () => {
it('should render without crashing with valid data', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
expect(container).to.exist
expect(container.querySelector('svg')).to.exist
})
it('should render NoData component when data is empty', () => {
const { container } = renderWithProviders(<Chart data={[]} />, { withTheme: true })
expect(container).to.exist
// NoData component should be rendered
const noDataElement = container.querySelector('div')
expect(noDataElement).to.exist
})
it('should render chart with correct height', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
const chartContainer = container.querySelector('[style*="height"]') as HTMLElement
expect(chartContainer).to.exist
expect(chartContainer.style.height).to.equal('150px')
})
it('should render SVG chart elements', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
// Check for SVG element
const svg = container.querySelector('svg')
expect(svg).to.exist
// Check for chart elements (paths for line series)
const paths = container.querySelectorAll('path')
expect(paths.length).to.be.greaterThan(0)
})
})
describe('Data Visualization', () => {
it('should render data points as glyphs', () => {
const data = createMockChartData(3)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
// Check for circles (glyphs representing data points)
const circles = container.querySelectorAll('circle')
expect(circles.length).to.be.greaterThan(0)
})
it('should render exact number of data points matching data length', () => {
const dataLength = 5
const data = createMockChartData(dataLength)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
// Each data point should render as a circle
const circles = container.querySelectorAll('circle')
expect(circles.length).to.equal(dataLength, `Expected ${dataLength} circles for ${dataLength} data points`)
// Verify each circle has proper attributes
circles.forEach((circle, index) => {
expect(circle.getAttribute('cx')).to.exist
expect(circle.getAttribute('cy')).to.exist
expect(circle.getAttribute('r')).to.equal('3')
expect(circle.getAttribute('fill')).to.exist
})
})
it('should position data points with valid coordinates', () => {
const data = createMockChartData(3)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
const circles = container.querySelectorAll('circle')
circles.forEach(circle => {
const cx = parseFloat(circle.getAttribute('cx') || '0')
const cy = parseFloat(circle.getAttribute('cy') || '0')
// Coordinates should be valid numbers
expect(cx).to.be.a('number')
expect(cy).to.be.a('number')
expect(isNaN(cx)).to.be.false
expect(isNaN(cy)).to.be.false
// Coordinates should be within chart bounds (positive values)
expect(cx).to.be.greaterThan(0)
expect(cy).to.be.greaterThan(0)
})
})
it('should render line connecting data points', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
// Line series should create a path element
const paths = container.querySelectorAll('path')
expect(paths.length).to.be.greaterThan(0)
})
it('should handle single data point', () => {
const data = [{ x: Date.now(), y: 50 }]
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
const circles = container.querySelectorAll('circle')
expect(circles.length).to.equal(1, 'Single data point should render as one circle')
})
it('should handle large datasets', () => {
const data = createMockChartData(100)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
const circles = container.querySelectorAll('circle')
expect(circles.length).to.equal(100, '100 data points should render as 100 circles')
})
})
describe('Curve Interpolation', () => {
const curveTypes: PlotCurveTypes[] = ['curve', 'linear', 'cubic_basis_spline', 'step_after', 'step_before']
curveTypes.forEach(interpolation => {
it(`should render with ${interpolation} interpolation`, () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} interpolation={interpolation} />, {
withTheme: true,
})
expect(container.querySelector('svg')).to.exist
const paths = container.querySelectorAll('path')
expect(paths.length).to.be.greaterThan(0)
})
})
})
describe('Custom Styling', () => {
it('should apply custom color', () => {
const data = createMockChartData(5)
const customColor = '#ff0000'
const { container } = renderWithProviders(<Chart data={data} color={customColor} />, { withTheme: true })
// Check if custom color is applied to line or glyphs
const svg = container.querySelector('svg')
expect(svg).to.exist
})
it('should use theme colors when no custom color provided', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
})
})
describe('Custom Domains and Ranges', () => {
it('should render with custom Y range', () => {
const data = createMockChartData(5)
const range: [number, number] = [0, 100]
const { container } = renderWithProviders(<Chart data={data} range={range} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
})
it('should render with custom time range', () => {
const data = createMockChartData(5)
const timeRangeStart = 60000 // 1 minute
const { container } = renderWithProviders(<Chart data={data} timeRangeStart={timeRangeStart} />, {
withTheme: true,
})
expect(container.querySelector('svg')).to.exist
})
it('should render with partial Y range (only min)', () => {
const data = createMockChartData(5)
const range: [number?, number?] = [0, undefined]
const { container } = renderWithProviders(<Chart data={data} range={range} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
})
it('should render with partial Y range (only max)', () => {
const data = createMockChartData(5)
const range: [number?, number?] = [undefined, 100]
const { container } = renderWithProviders(<Chart data={data} range={range} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
})
})
describe('Chart Components', () => {
it('should render Y-axis', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
// Y-axis should be present (look for axis group or tick marks)
const svg = container.querySelector('svg')
expect(svg).to.exist
// Axis typically contains text elements for labels
const texts = container.querySelectorAll('text')
expect(texts.length).to.be.greaterThan(0)
})
it('should render X-axis with time labels', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
// X-axis should be present with text labels
const svg = container.querySelector('svg')
expect(svg).to.exist
// X-axis has text labels for timestamps
const texts = container.querySelectorAll('text')
expect(texts.length).to.be.greaterThan(0, 'X-axis and Y-axis should have text labels')
// At least one text element should contain time format (e.g., contains ":")
let hasTimeFormat = false
texts.forEach(text => {
if (text.textContent && text.textContent.includes(':')) {
hasTimeFormat = true
}
})
expect(hasTimeFormat).to.be.true
})
it('should render both X and Y axes', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
const svg = container.querySelector('svg')
expect(svg).to.exist
// Both axes should render tick marks (lines)
const lines = container.querySelectorAll('line')
expect(lines.length).to.be.greaterThan(0, 'Axes should render tick marks')
// Both axes should have labels (text)
const texts = container.querySelectorAll('text')
expect(texts.length).to.be.greaterThan(2, 'Both axes should have multiple labels')
})
it('should render grid lines', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
// Grid lines are rendered as line elements
const svg = container.querySelector('svg')
expect(svg).to.exist
})
it('should have proper chart margins', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
const svg = container.querySelector('svg')
expect(svg).to.exist
// SVG should have proper dimensions
expect(svg?.getAttribute('width')).to.exist
expect(svg?.getAttribute('height')).to.exist
})
})
describe('Edge Cases', () => {
it('should handle negative values', () => {
const data = [
{ x: Date.now() - 2000, y: -50 },
{ x: Date.now() - 1000, y: -25 },
{ x: Date.now(), y: -75 },
]
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
})
it('should handle zero values', () => {
const data = [
{ x: Date.now() - 2000, y: 0 },
{ x: Date.now() - 1000, y: 0 },
{ x: Date.now(), y: 0 },
]
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
})
it('should handle very large numbers', () => {
const data = [
{ x: Date.now() - 2000, y: 1000000 },
{ x: Date.now() - 1000, y: 2000000 },
{ x: Date.now(), y: 3000000 },
]
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
// Y-axis should abbreviate large numbers
const texts = container.querySelectorAll('text')
expect(texts.length).to.be.greaterThan(0)
})
it('should handle identical values', () => {
const data = [
{ x: Date.now() - 2000, y: 50 },
{ x: Date.now() - 1000, y: 50 },
{ x: Date.now(), y: 50 },
]
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
})
})
describe('Component Props', () => {
it('should accept all valid props without errors', () => {
const data = createMockChartData(5)
const props: ChartProps = {
data,
interpolation: 'curve',
range: [0, 100],
timeRangeStart: 60000,
color: '#00ff00',
}
const { container } = renderWithProviders(<Chart {...props} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
})
it('should work with minimal props', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
})
})
describe('Theme Integration', () => {
it('should render in light theme', () => {
const data = createMockChartData(5)
const { container } = renderWithProviders(<Chart data={data} />, { withTheme: true })
expect(container.querySelector('svg')).to.exist
})
// Note: Testing dark theme would require a custom theme provider
// This demonstrates how the test structure supports theme variations
})
describe('Performance', () => {
it('should memoize component with same props', () => {
const data = createMockChartData(5)
const { rerender } = renderWithProviders(<Chart data={data} />, { withTheme: true })
// Component should not re-render with same props due to React.memo
expect(() => {
rerender(<Chart data={data} />)
}).to.not.throw()
})
it('should handle rapid data updates', () => {
const { rerender, container } = renderWithProviders(<Chart data={createMockChartData(5)} />, { withTheme: true })
// Simulate rapid updates
for (let i = 0; i < 10; i++) {
rerender(<Chart data={createMockChartData(5)} />)
}
expect(container.querySelector('svg')).to.exist
})
})
describe('Interactive Data Updates', () => {
it('should dynamically update when data points are added', () => {
// Start with 3 data points
const initialData = createMockChartData(3)
const { rerender, container } = renderWithProviders(<Chart data={initialData} />, { withTheme: true })
// Verify initial state: should have 3 data points
const initialCircles = container.querySelectorAll('circle')
expect(initialCircles.length).to.equal(3, 'Should initially render 3 data points')
// Verify each initial circle has valid attributes
initialCircles.forEach((circle, index) => {
const cx = circle.getAttribute('cx')
const cy = circle.getAttribute('cy')
const r = circle.getAttribute('r')
expect(cx).to.exist
expect(cy).to.exist
expect(r).to.equal('3')
expect(parseFloat(cx!)).to.be.a('number').and.not.NaN
expect(parseFloat(cy!)).to.be.a('number').and.not.NaN
})
// Update state: add 2 more data points (total 5)
const updatedData = createMockChartData(5)
rerender(<Chart data={updatedData} />)
// Verify updated state: should now have 5 data points
const updatedCircles = container.querySelectorAll('circle')
expect(updatedCircles.length).to.equal(5, 'Should render 5 data points after update')
// Verify each updated circle has valid attributes
updatedCircles.forEach((circle, index) => {
const cx = circle.getAttribute('cx')
const cy = circle.getAttribute('cy')
const r = circle.getAttribute('r')
const fill = circle.getAttribute('fill')
expect(cx).to.exist
expect(cy).to.exist
expect(r).to.equal('3')
expect(fill).to.exist
expect(parseFloat(cx!)).to.be.a('number').and.not.NaN
expect(parseFloat(cy!)).to.be.a('number').and.not.NaN
expect(parseFloat(cy!)).to.be.greaterThan(0, 'Y coordinate should be positive')
})
// Verify the line path is updated to connect all 5 points
const linePath = container.querySelector('path[stroke]')
expect(linePath).to.exist
expect(linePath!.getAttribute('d')).to.exist
// The path should start with MoveTo (M) command and contain curve/line commands
const pathData = linePath!.getAttribute('d')
expect(pathData).to.include('M') // MoveTo command for first point
// Path may contain 'L' (line) or 'C' (curve) commands depending on interpolation
expect(pathData!.length).to.be.greaterThan(10, 'Path should have substantial data for 5 points')
})
it('should handle data point removal', () => {
// Start with 5 data points
const initialData = createMockChartData(5)
const { rerender, container } = renderWithProviders(<Chart data={initialData} />, { withTheme: true })
// Verify initial state
let circles = container.querySelectorAll('circle')
expect(circles.length).to.equal(5, 'Should initially render 5 data points')
// Remove 2 data points (now 3)
const reducedData = createMockChartData(3)
rerender(<Chart data={reducedData} />)
// Verify reduced state
circles = container.querySelectorAll('circle')
expect(circles.length).to.equal(3, 'Should render 3 data points after removal')
})
it('should maintain chart structure during data updates', () => {
const initialData = createMockChartData(3)
const { rerender, container } = renderWithProviders(<Chart data={initialData} />, { withTheme: true })
// Verify chart structure exists initially
expect(container.querySelector('svg')).to.exist
expect(container.querySelectorAll('line').length).to.be.greaterThan(0, 'Should have axis/grid lines')
expect(container.querySelectorAll('text').length).to.be.greaterThan(0, 'Should have axis labels')
// Update data
const updatedData = createMockChartData(5)
rerender(<Chart data={updatedData} />)
// Verify chart structure is maintained after update
expect(container.querySelector('svg')).to.exist
expect(container.querySelectorAll('line').length).to.be.greaterThan(0, 'Should still have axis/grid lines')
expect(container.querySelectorAll('text').length).to.be.greaterThan(0, 'Should still have axis labels')
})
})
})
+70 -129
View File
@@ -1,164 +1,105 @@
import React, { memo, useCallback, useMemo } from 'react'
import { useResizeDetector } from 'react-resize-detector'
import { emphasize, useTheme } from '@mui/material/styles'
import { XYChart, Axis, Grid, LineSeries, GlyphSeries } from '@visx/xychart'
import DateFormatter from '../helper/DateFormatter'
import NoData from './NoData'
import NumberFormatter from '../helper/NumberFormatter'
import React, { memo, useCallback } from 'react'
import TooltipComponent from './TooltipComponent'
import { default as ReactResizeDetector } from 'react-resize-detector'
import { emphasize } from '@material-ui/core/styles'
import { mapCurveType } from './mapCurveType'
import { PlotCurveTypes } from '../../reducers/Charts'
import { Point, Tooltip } from './Model'
import { Theme, withTheme } from '@material-ui/core'
import { useCustomXDomain } from './effects/useCustomXDomain'
import { useCustomYDomain } from './effects/useCustomYDomain'
import 'react-vis/dist/style.css'
const { XYPlot, LineMarkSeries, YAxis, HorizontalGridLines, Hint } = require('react-vis')
const abbreviate = require('number-abbreviate')
export interface Props {
data: Array<{ x: number; y: number }>
theme: Theme
interpolation?: PlotCurveTypes
range?: [number?, number?]
timeRangeStart?: number
color?: string
}
const CHART_HEIGHT = 150
export default withTheme(
memo((props: Props) => {
const [width, setWidth] = React.useState(300)
const [tooltip, setTooltip] = React.useState<Tooltip | undefined>()
const detectResize = React.useCallback(newWidth => setWidth(newWidth), [])
export default memo((props: Props) => {
const theme = useTheme()
const [tooltip, setTooltip] = React.useState<Tooltip | undefined>()
const [hoveredPoint, setHoveredPoint] = React.useState<Point | undefined>()
const { width = 300, ref } = useResizeDetector()
const chartContainerRef = React.useRef<HTMLDivElement>(null)
const hintFormatter = React.useCallback(
(point: any) => [
{ title: <b>Time</b>, value: <DateFormatter timeFirst={true} date={new Date(point.x)} /> },
{ title: <b>Value</b>, value: <NumberFormatter value={point.y} /> },
{ title: <b>Raw</b>, value: <span>{point.y}</span> },
],
[]
)
const hintFormatter = React.useCallback(
(point: any) => [
{ title: <b>Time</b>, value: <DateFormatter timeFirst date={new Date(point.x)} /> },
{ title: <b>Value</b>, value: <NumberFormatter value={point.y} /> },
{ title: <b>Raw</b>, value: <span>{point.y}</span> },
],
[]
)
const onMouseLeave = React.useCallback(() => {
setTooltip(undefined)
}, [])
const onMouseLeave = React.useCallback(() => {
setTooltip(undefined)
setHoveredPoint(undefined)
}, [])
const showTooltip = React.useCallback(
(point: Point) => {
if (!chartContainerRef.current) {
const showTooltip = React.useCallback((point: Point, something: { event: MouseEvent }) => {
if (!something) {
return
}
setHoveredPoint(point)
setTooltip({ point, value: hintFormatter(point), element: chartContainerRef.current })
},
[hintFormatter]
)
setTooltip({ point, value: hintFormatter(point), element: something.event.target as any })
}, [])
const paletteColor = theme.palette.mode === 'light' ? theme.palette.secondary.dark : theme.palette.primary.light
const color = props.color ? props.color : paletteColor
const paletteColor =
props.theme.palette.type === 'light' ? props.theme.palette.secondary.dark : props.theme.palette.primary.light
const color = props.color ? props.color : paletteColor
const highlightSelectedPoint = useCallback(
(point: Point) => {
const highlight = hoveredPoint && hoveredPoint.x === point.x && hoveredPoint.y === point.y
return highlight ? emphasize(color, 0.8) : color
},
[hoveredPoint, color]
)
const highlightSelectedPoint = useCallback(
(point: Point) => {
const highlight = tooltip && tooltip.point.x === point.x && tooltip.point.y === point.y
return highlight ? emphasize(color, 0.8) : color
},
[tooltip, color]
)
const formatYAxis = useCallback((num: number) => abbreviate(num), [])
const formatYAxis = useCallback((num: number) => abbreviate(num), [])
const formatXAxis = useCallback((timestamp: number) => {
const date = new Date(timestamp)
const hours = date.getHours().toString().padStart(2, '0')
const minutes = date.getMinutes().toString().padStart(2, '0')
const seconds = date.getSeconds().toString().padStart(2, '0')
return `${hours}:${minutes}:${seconds}`
}, [])
const xDomain = useCustomXDomain(props)
const yDomain = useCustomYDomain(props)
const xDomain = useCustomXDomain(props)
const yDomain = useCustomYDomain(props)
const { data } = props
const hasData = data.length > 0
const dummyDomain: [number, number] = [-1, 1]
const dummyData = [{ x: -2, y: -2 }]
const accessors = useMemo(
() => ({
xAccessor: (d: Point) => d.x,
yAccessor: (d: Point) => d.y,
}),
[]
)
return (
<div>
<div ref={ref} style={{ height: `${CHART_HEIGHT}px`, width: '100%', position: 'relative' }}>
{data.length === 0 ? <NoData /> : null}
<div ref={chartContainerRef}>
<XYChart
width={width || 300}
height={CHART_HEIGHT}
margin={{
top: 10,
right: 10,
bottom: 30,
left: 50,
}}
xScale={{ type: 'time', domain: xDomain || dummyDomain }}
yScale={{ type: 'linear', domain: hasData ? yDomain : dummyDomain }}
onPointerOut={onMouseLeave}
const data = props.data
const hasData = data.length > 0
const dummyDomain = [-1, 1]
const dummyData = [{ x: -2, y: -2 }]
return (
<div>
<div style={{ height: '150px', width: '100%', position: 'relative' }}>
{data.length === 0 ? <NoData /> : null}
<XYPlot
width={width}
height={180}
yDomain={hasData ? yDomain : dummyDomain}
xDomain={hasData ? xDomain : dummyDomain}
onMouseLeave={onMouseLeave}
>
<Grid rows columns={false} stroke={theme.palette.divider} strokeOpacity={0.3} />
<Axis
orientation="left"
numTicks={5}
tickFormat={formatYAxis}
stroke={theme.palette.text.secondary}
tickStroke={theme.palette.text.secondary}
tickLabelProps={() => ({ fontSize: 11, fill: theme.palette.text.secondary })}
/>
<Axis
orientation="bottom"
numTicks={4}
tickFormat={formatXAxis}
stroke={theme.palette.text.secondary}
tickStroke={theme.palette.text.secondary}
tickLabelProps={() => ({ fontSize: 10, fill: theme.palette.text.secondary, textAnchor: 'middle' })}
/>
<LineSeries
dataKey="line"
<HorizontalGridLines />
<YAxis width={45} tickFormat={formatYAxis} />
<LineMarkSeries
color={color}
colorType="literal"
getColor={highlightSelectedPoint}
onValueMouseOver={showTooltip}
size={3}
data={hasData ? data : dummyData}
xAccessor={accessors.xAccessor}
yAccessor={accessors.yAccessor}
stroke={color}
strokeWidth={2}
curve={mapCurveType(props.interpolation)}
onPointerMove={datum => {
if (datum && datum.datum) {
const point = datum.datum as Point
showTooltip(point)
}
}}
/>
<GlyphSeries
dataKey="points"
data={hasData ? data : dummyData}
xAccessor={accessors.xAccessor}
yAccessor={accessors.yAccessor}
renderGlyph={glyphProps => {
const point = glyphProps.datum as Point
const pointColor = highlightSelectedPoint(point)
return <circle cx={glyphProps.x} cy={glyphProps.y} r={3} fill={pointColor} />
}}
/>
</XYChart>
<Hint value={{ x: 0, y: 0 }} style={{ pointerEvents: 'none' }}>
<TooltipComponent tooltip={tooltip} theme={props.theme} />
</Hint>
</XYPlot>
<ReactResizeDetector handleWidth={true} onResize={detectResize} />
</div>
{/* Custom tooltip outside of visx to maintain exact same appearance */}
<TooltipComponent tooltip={tooltip} />
</div>
</div>
)
})
)
})
)
+1 -1
View File
@@ -1,5 +1,5 @@
import React, { memo } from 'react'
import { Typography } from '@mui/material'
import { Typography } from '@material-ui/core'
function NoData() {
return (
@@ -1,16 +1,15 @@
import React, { memo } from 'react'
import { alpha as fade, useTheme } from '@mui/material/styles'
import { Fade, Grow, Paper, Popper, Typography } from '@mui/material'
import { fade } from '@material-ui/core/styles'
import { Fade, Grow, Paper, Popper, Theme, Typography, withTheme } from '@material-ui/core'
import { Tooltip } from './Model'
function TooltipComponent(props: { tooltip?: Tooltip }) {
const theme = useTheme()
function TooltipComponent(props: { tooltip?: Tooltip; theme: Theme }) {
const { tooltip } = props
return (
<Popper
style={tooltip ? { transition: 'all 0.1s ease-out' } : undefined}
style={Boolean(tooltip) ? { transition: 'all 0.1s ease-out' } : undefined}
open={Boolean(tooltip)}
transition
transition={true}
placement="top"
anchorEl={tooltip && tooltip.element}
>
@@ -27,7 +26,9 @@ function TooltipComponent(props: { tooltip?: Tooltip }) {
padding: '4px',
marginTop: '-12px',
backgroundColor: fade(
theme.palette.mode === 'light' ? theme.palette.background.paper : theme.palette.background.default,
props.theme.palette.type === 'light'
? props.theme.palette.background.paper
: props.theme.palette.background.default,
0.7
),
}}
@@ -55,4 +56,4 @@ function TooltipComponent(props: { tooltip?: Tooltip }) {
)
}
export default memo(TooltipComponent)
export default withTheme(memo(TooltipComponent))
@@ -3,21 +3,8 @@ import { Props } from '../Chart'
export function useCustomXDomain(props: Props): [number, number] | undefined {
return useMemo(() => {
if (props.data.length === 0) {
return undefined
}
const lastDataPoint = [...props.data].sort((a, b) => b.x - a.x)[0]
const lastDataDate = lastDataPoint ? lastDataPoint.x : Date.now()
if (props.timeRangeStart) {
// Custom time range mode
return [Date.now() - props.timeRangeStart, lastDataDate]
}
// Auto-calculate from data (like react-vis did)
const xValues = props.data.map(d => d.x)
const minX = Math.min(...xValues)
const maxX = Math.max(...xValues)
return [minX, maxX]
return props.timeRangeStart ? [Date.now() - props.timeRangeStart, lastDataDate] : undefined
}, [props.data, props.timeRangeStart])
}
@@ -1,21 +1,17 @@
import { useMemo } from 'react'
import { Props } from '../Chart'
import { useMemo } from 'react'
import { Point } from '../Model'
function defaultFor(a: number | undefined, b: number) {
return a === undefined ? b : a
}
export function useCustomYDomain(props: Props) {
return useMemo(() => {
const { data } = props
const data = props.data
const calculatedDomain = domainForData(data)
const yDomain: [number, number] = props.range
? [defaultFor(props.range[0], calculatedDomain[0]), defaultFor(props.range[1], calculatedDomain[1])]
? [props.range[0] || calculatedDomain[0], props.range[1] || calculatedDomain[1]]
: calculatedDomain
return yDomain
}, [props.data, props.range])
}, [props.data])
}
function domainForData(data: Array<Point>): [number, number] {
@@ -23,10 +19,8 @@ function domainForData(data: Array<Point>): [number, number] {
const defaultDomain: [number, number] = [-1, 1]
return defaultDomain
}
let max = data[0].y
let min = data[0].y
data.forEach(d => {
if (max < d.y) {
max = d.y
+6 -8
View File
@@ -1,19 +1,17 @@
import * as d3Shape from 'd3-shape'
import { PlotCurveTypes } from '../../reducers/Charts'
export function mapCurveType(type: PlotCurveTypes | undefined) {
switch (type) {
case 'curve':
return d3Shape.curveMonotoneX
return 'curveMonotoneX'
case 'linear':
return d3Shape.curveLinear
return 'curveLinear'
case 'cubic_basis_spline':
return d3Shape.curveBasis
return 'curveBasis'
case 'step_after':
return d3Shape.curveStepAfter
return 'curveStepAfter'
case 'step_before':
return d3Shape.curveStepBefore
return 'curveStepBefore'
default:
return d3Shape.curveMonotoneX
return 'curveMonotoneX'
}
}
@@ -1,7 +1,7 @@
import React, { useRef } from 'react'
import Play from '@mui/icons-material/PlayArrow'
import Pause from '@mui/icons-material/PauseCircleFilled'
import Clear from '@mui/icons-material/Clear'
import Play from '@material-ui/icons/PlayArrow'
import Pause from '@material-ui/icons/PauseCircleFilled'
import Clear from '@material-ui/icons/Clear'
import CustomIconButton from '../helper/CustomIconButton'
import { ChartParameters } from '../../reducers/Charts'
import { SettingsButton } from './ChartSettings/SettingsButton'
@@ -1,9 +1,9 @@
import React, { memo } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Menu, MenuItem } from '@mui/material'
import { chartActions } from '../../../actions'
import { ChartParameters } from '../../../reducers/Charts'
import { connect } from 'react-redux'
import { Menu, MenuItem } from '@material-ui/core'
import { colors as createColors } from './colors'
function chartParametersForColor(chart: ChartParameters, color?: string) {
@@ -30,24 +30,17 @@ function ColorSettings(props: {
[props.chart]
)
const menuItems = React.useMemo(
() =>
colors.map(color => (
<MenuItem
style={{
minWidth: '8em',
minHeight: '36px',
backgroundColor: color,
textAlign: 'center',
}}
key={color}
onClick={() => setColor(color)}
>
{props.chart.color === color ? 'X' : ''}
</MenuItem>
)),
[colors, props.chart]
)
const menuItems = React.useMemo(() => {
return colors.map(color => (
<MenuItem
style={{ minWidth: '8em', minHeight: '36px', backgroundColor: color, textAlign: 'center' }}
key={color}
onClick={() => setColor(color)}
>
{props.chart.color === color ? 'X' : ''}
</MenuItem>
))
}, [colors, props.chart])
return (
<Menu anchorEl={props.anchorEl} open={props.open} onClose={props.close}>
@@ -64,10 +57,15 @@ function ColorSettings(props: {
)
}
const mapDispatchToProps = (dispatch: any) => ({
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
}
}
export default connect(undefined, mapDispatchToProps)(memo(ColorSettings))
export default connect(
undefined,
mapDispatchToProps
)(memo(ColorSettings))
@@ -1,10 +1,10 @@
import * as React from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Menu, MenuItem, Typography } from '@mui/material'
import { AppState } from '../../../reducers'
import { bindActionCreators } from 'redux'
import { chartActions } from '../../../actions'
import { ChartParameters, PlotCurveTypes } from '../../../reducers/Charts'
import { connect } from 'react-redux'
import { Menu, MenuItem, Typography } from '@material-ui/core'
function chartParametersForAction(chart: ChartParameters, action: string) {
return {
@@ -37,20 +37,13 @@ function InterpolationSettings(props: {
return callbacks
}, [curves])
const menuItems = React.useMemo(
() =>
curves.map(curve => (
<MenuItem
key={curve}
onClick={callbacks[curve]}
selected={props.chart.interpolation === curve}
data-menu-item={curve.replace(/_/g, ' ')}
>
<Typography variant="inherit">{curve.replace(/_/g, ' ')}</Typography>
</MenuItem>
)),
[curves, props.chart]
)
const menuItems = React.useMemo(() => {
return curves.map(curve => (
<MenuItem key={curve} onClick={callbacks[curve]} selected={props.chart.interpolation === curve}>
<Typography variant="inherit">{curve.replace(/_/g, ' ')}</Typography>
</MenuItem>
))
}, [curves, props.chart])
return (
<Menu anchorEl={props.anchorEl} open={props.open} onClose={props.close}>
@@ -59,10 +52,15 @@ function InterpolationSettings(props: {
)
}
const mapDispatchToProps = (dispatch: any) => ({
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
}
}
export default connect(undefined, mapDispatchToProps)(InterpolationSettings)
export default connect(
undefined,
mapDispatchToProps
)(InterpolationSettings)
@@ -1,10 +1,10 @@
import * as React from 'react'
import ArrowUpward from '@mui/icons-material/ArrowUpward'
import ArrowUpward from '@material-ui/icons/ArrowUpward'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { MenuItem, Typography, ListItemIcon } from '@mui/material'
import { chartActions } from '../../../actions'
import { ChartParameters } from '../../../reducers/Charts'
import { connect } from 'react-redux'
import { MenuItem, Typography, ListItemIcon } from '@material-ui/core'
function MoveUp(props: { actions: { chart: typeof chartActions }; chart: ChartParameters; close: () => void }) {
const moveUp = React.useCallback(() => {
@@ -25,10 +25,15 @@ function MoveUp(props: { actions: { chart: typeof chartActions }; chart: ChartPa
)
}
const mapDispatchToProps = (dispatch: any) => ({
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
}
}
export default connect(undefined, mapDispatchToProps)(MoveUp)
export default connect(
undefined,
mapDispatchToProps
)(MoveUp)
@@ -1,8 +1,8 @@
import React, { useCallback, useState, ChangeEvent, MouseEvent, useRef, useEffect, useMemo } from 'react'
import { Menu, TextField, Typography } from '@mui/material'
import { ChartParameters } from '../../../reducers/Charts'
import { Menu, TextField, Typography } from '@material-ui/core'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { ChartParameters } from '../../../reducers/Charts'
import { chartActions } from '../../../actions'
import { KeyCodes } from '../../../utils/KeyCodes'
@@ -50,7 +50,7 @@ function RangeSettings(props: Props) {
() => (
<Menu
style={{ textAlign: 'center' }}
keepMounted
keepMounted={true}
anchorEl={props.anchorEl}
open={props.open}
onClose={props.onClose}
@@ -62,7 +62,7 @@ function RangeSettings(props: Props) {
inputProps={{
ref: rangeFromRef,
}}
autoFocus
autoFocus={true}
style={{ marginTop: '0' }}
label="from"
value={rangeFrom}
@@ -87,13 +87,18 @@ function RangeSettings(props: Props) {
)
}
const mapDispatchToProps = (dispatch: any) => ({
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
}
}
export default connect(undefined, mapDispatchToProps)(RangeSettings)
export default connect(
undefined,
mapDispatchToProps
)(RangeSettings)
function useRangeStateToFireUpdateAction(
rangeFrom: string | number | undefined,
@@ -1,7 +1,7 @@
import * as React from 'react'
import MoreVertIcon from '@mui/icons-material/Settings'
import ChartSettings from '.'
import CustomIconButton from '../../helper/CustomIconButton'
import MoreVertIcon from '@material-ui/icons/Settings'
import { ChartParameters } from '../../../reducers/Charts'
export function SettingsButton(props: {
@@ -1,8 +1,8 @@
import React, { memo } from 'react'
import { Menu, MenuItem, TextField, Typography } from '@mui/material'
import { ChartParameters } from '../../../reducers/Charts'
import { Menu, MenuItem, TextField, Typography } from '@material-ui/core'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { ChartParameters } from '../../../reducers/Charts'
import { chartActions } from '../../../actions'
function Size(props: {
@@ -39,10 +39,15 @@ function Size(props: {
)
}
const mapDispatchToProps = (dispatch: any) => ({
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
}
}
export default connect(undefined, mapDispatchToProps)(memo(Size))
export default connect(
undefined,
mapDispatchToProps
)(memo(Size))
@@ -1,10 +1,9 @@
import React, { ChangeEvent, MouseEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { bindActionCreators } from 'redux'
import { Button, Menu, TextField, Typography } from '@mui/material'
import { connect } from 'react-redux'
import { Button, Menu, TextField, Typography } from '@material-ui/core'
import { chartActions } from '../../../actions'
import { ChartParameters } from '../../../reducers/Charts'
import { connect } from 'react-redux'
const parseDuration = require('parse-duration')
interface Props {
@@ -52,23 +51,25 @@ function TimeRangeSettings(props: Props) {
return (
<Menu
style={{ textAlign: 'center' }}
keepMounted
keepMounted={true}
anchorEl={props.anchorEl}
open={props.open}
onClose={props.onClose}
>
<Typography>Chart data within a time interval</Typography>
<div style={{ padding: '0 16px', width: '275px', textAlign: 'center' }}>
{ranges.map(r => (
<Button
style={{ margin: '4px', textTransform: 'none' }}
variant="contained"
key={r}
onClick={createRangeHandler(r)}
>
{r}
</Button>
))}
{ranges.map(r => {
return (
<Button
style={{ margin: '4px', textTransform: 'none' }}
variant="contained"
key={r}
onClick={createRangeHandler(r)}
>
{r}
</Button>
)
})}
</div>
<Typography style={{ fontSize: '0.75em' }}>
<i>Limited to 500 data points</i>
@@ -87,10 +88,15 @@ function TimeRangeSettings(props: Props) {
}, [value, props.open])
}
const mapDispatchToProps = (dispatch: any) => ({
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
}
}
export default connect(undefined, mapDispatchToProps)(TimeRangeSettings)
export default connect(
undefined,
mapDispatchToProps
)(TimeRangeSettings)
@@ -12,7 +12,7 @@ import {
yellow,
brown,
blueGrey,
} from '@mui/material/colors'
} from '@material-ui/core/colors'
export function colors() {
function colorToInt(color: string): [number, number, number] {
@@ -22,7 +22,7 @@ export function colors() {
function colorCompare(colorA: string, colorB: string) {
const a = colorToInt(colorA)
const b = colorToInt(colorB)
return Math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 + (a[2] - b[2]) ** 2)
return Math.sqrt(Math.pow(a[0] - b[0], 2) + Math.pow(a[1] - b[1], 2) + Math.pow(a[2] - b[2], 2))
}
const colors: Array<string> = [
brown,
@@ -1,17 +1,17 @@
import BarChart from '@mui/icons-material/BarChart'
import Clear from '@mui/icons-material/Refresh'
import ColorLens from '@mui/icons-material/ColorLens'
import MultilineChart from '@mui/icons-material/MultilineChart'
import React, { memo } from 'react'
import Sort from '@mui/icons-material/Sort'
import { Menu, MenuItem, ListItemIcon, Typography } from '@mui/material'
import BarChart from '@material-ui/icons/BarChart'
import Clear from '@material-ui/icons/Refresh'
import ColorLens from '@material-ui/icons/ColorLens'
import ColorSettings from './ColorSettings'
import InterpolationSettings from './InterpolationSettings'
import MoveUp from './MoveUp'
import MultilineChart from '@material-ui/icons/MultilineChart'
import RangeSettings from './RangeSettings'
import React, { memo } from 'react'
import Size from './Size'
import Sort from '@material-ui/icons/Sort'
import TimeRangeSettings from './TimeRangeSettings'
import { ChartParameters } from '../../../reducers/Charts'
import { Menu, MenuItem, ListItemIcon, Typography } from '@material-ui/core'
function ChartSettings(props: {
open: boolean
@@ -25,7 +25,6 @@ function ChartSettings(props: {
const [interpolationVisible, setInterpolationVisible] = React.useState(false)
const [sizeVisible, setSizeVisible] = React.useState(false)
const [colorVisible, setColorVisible] = React.useState(false)
const { open } = props
const toggleRange = React.useCallback(() => {
if (open) {
@@ -65,37 +64,37 @@ function ChartSettings(props: {
return (
<span>
<Menu id="long-menu" anchorEl={props.anchorEl.current} open={props.open} onClose={props.close}>
<MenuItem key="range" onClick={toggleRange} data-menu-item="Y-Axis range (Values)">
<MenuItem key="range" onClick={toggleRange}>
<ListItemIcon>
<BarChart />
</ListItemIcon>
<Typography variant="inherit">Y-Axis range (Values)</Typography>
</MenuItem>
<MenuItem key="timeRange" onClick={toggleTimeRange} data-menu-item="X-Axis range (Time)">
<MenuItem key="timeRange" onClick={toggleTimeRange}>
<ListItemIcon>
<BarChart />
</ListItemIcon>
<Typography variant="inherit">X-Axis range (Time)</Typography>
</MenuItem>
<MenuItem key="interpolation" onClick={toggleInterpolation} data-menu-item="Curve interpolation">
<MenuItem key="interpolation" onClick={toggleInterpolation}>
<ListItemIcon>
<MultilineChart />
</ListItemIcon>
<Typography variant="inherit">Curve interpolation</Typography>
</MenuItem>
<MenuItem key="size" onClick={toggleSize} data-menu-item="Size">
<MenuItem key="size" onClick={toggleSize}>
<ListItemIcon>
<Sort />
</ListItemIcon>
<Typography variant="inherit">Size</Typography>
</MenuItem>
<MenuItem key="color" onClick={toggleColor} data-menu-item="Color">
<MenuItem key="color" onClick={toggleColor}>
<ListItemIcon>
<ColorLens />
</ListItemIcon>
<Typography variant="inherit">Color</Typography>
</MenuItem>
<MenuItem key="clear" onClick={props.resetDataAction} data-menu-item="Clear data">
<MenuItem key="clear" onClick={props.resetDataAction}>
<ListItemIcon>
<Clear />
</ListItemIcon>
+6 -8
View File
@@ -1,8 +1,6 @@
import * as React from 'react'
import { Typography } from '@mui/material'
import { withStyles } from '@mui/styles'
import { Theme } from '@mui/material/styles'
import { ChartParameters } from '../../reducers/Charts'
import { Typography, Theme, withStyles } from '@material-ui/core'
function ChartTitle(props: { parameters: ChartParameters; classes: any }) {
const { classes, parameters } = props
@@ -13,7 +11,7 @@ function ChartTitle(props: { parameters: ChartParameters; classes: any }) {
</Typography>
<br />
<Typography variant="caption" className={classes.topic}>
{parameters.dotPath ? parameters.topic : <span dangerouslySetInnerHTML={{ __html: '&nbsp;' }} />}
{parameters.dotPath ? parameters.topic : <span dangerouslySetInnerHTML={{ __html: '&nbsp;' }}></span>}
</Typography>
</div>
)
@@ -21,10 +19,10 @@ function ChartTitle(props: { parameters: ChartParameters; classes: any }) {
const styles = (theme: Theme) => ({
topic: {
wordBreak: 'break-all' as const,
whiteSpace: 'nowrap' as const,
overflow: 'hidden' as const,
textOverflow: 'ellipsis' as const,
wordBreak: 'break-all' as 'break-all',
whiteSpace: 'nowrap' as 'nowrap',
overflow: 'hidden' as 'hidden',
textOverflow: 'ellipsis' as 'ellipsis',
},
})
@@ -1,5 +1,5 @@
import React from 'react'
import * as q from '../../../../backend/src/Model'
import React from 'react'
import TopicChart from './TopicChart'
import { ChartParameters } from '../../reducers/Charts'
import { usePollingToFetchTreeNode } from '../helper/usePollingToFetchTreeNode'
+15 -12
View File
@@ -1,14 +1,13 @@
import React, { useState, useCallback, memo, useRef } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Paper } from '@mui/material'
import * as q from '../../../../backend/src/Model'
import ChartTitle from './ChartTitle'
import React, { useState, useCallback, memo, useRef } from 'react'
import TopicPlot from '../TopicPlot'
import { bindActionCreators } from 'redux'
import { ChartActions } from './ChartActions'
import { chartActions } from '../../actions'
import { ChartParameters } from '../../reducers/Charts'
import { connect } from 'react-redux'
import { Paper } from '@material-ui/core'
const throttle = require('lodash.throttle')
class ClearableMessageBuffer extends q.RingBuffer<q.Message> {
@@ -115,7 +114,6 @@ function TopicChart(props: Props) {
</div>
</div>
<TopicPlot
node={props.treeNode ? props.treeNode : undefined}
color={props.parameters.color}
interpolation={props.parameters.interpolation}
timeInterval={props.parameters.timeRange ? props.parameters.timeRange.until : undefined}
@@ -127,10 +125,15 @@ function TopicChart(props: Props) {
)
}
const mapDispatchToProps = (dispatch: any) => ({
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
}
}
export default connect(undefined, mapDispatchToProps)(memo(TopicChart))
export default connect(
undefined,
mapDispatchToProps
)(memo(TopicChart))
+41 -61
View File
@@ -1,17 +1,14 @@
import * as React from 'react'
import ShowChart from '@mui/icons-material/ShowChart'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Grid, Typography } from '@mui/material'
import { withStyles } from '@mui/styles'
import { Theme } from '@mui/material/styles'
import { List } from 'immutable'
import * as q from '../../../../backend/src/Model'
import * as React from 'react'
import ShowChart from '@material-ui/icons/ShowChart'
import { AppState } from '../../reducers'
import { ChartWithTreeNode } from './ChartWithTreeNode'
import { ChartParameters } from '../../reducers/Charts'
import { bindActionCreators } from 'redux'
import { chartActions } from '../../actions'
import { ChartParameters } from '../../reducers/Charts'
import { ChartWithTreeNode } from './ChartWithTreeNode'
import { connect } from 'react-redux'
import { Grid, Theme, Typography, withStyles } from '@material-ui/core'
import { List } from 'immutable'
const { TransitionGroup, CSSTransition } = require('react-transition-group/esm')
interface Props {
@@ -27,11 +24,11 @@ interface Props {
function spacingForChartCount(count: number): 4 | 6 | 12 {
if (count >= 5) {
return 4
}
if (count >= 2) {
} else if (count >= 2) {
return 6
} else {
return 12
}
return 12
}
function mapWidth(width: 'big' | 'medium' | 'small' | undefined, calculatedSpacing: 4 | 6 | 12): 4 | 6 | 12 {
@@ -47,14 +44,10 @@ function mapWidth(width: 'big' | 'medium' | 'small' | undefined, calculatedSpaci
}
}
// Helper function to generate unique keys for charts
const getChartKey = (chart: ChartParameters) => `${chart.topic}-${chart.dotPath || ''}`
function ChartPanel(props: Props) {
const chartsInView = props.charts.count()
const [spacing, setSpacing] = React.useState(spacingForChartCount(chartsInView))
const nodeRefsMap = React.useRef<Map<string, React.RefObject<HTMLDivElement>>>(new Map())
React.useEffect(() => {
props.actions.chart.loadCharts()
@@ -70,37 +63,17 @@ function ChartPanel(props: Props) {
}
}, [chartsInView])
// Clean up refs for removed charts
React.useEffect(() => {
const currentKeys = new Set(props.charts.map(getChartKey).toArray())
const refsToDelete: string[] = []
nodeRefsMap.current.forEach((_, key) => {
if (!currentKeys.has(key)) {
refsToDelete.push(key)
}
})
refsToDelete.forEach(key => nodeRefsMap.current.delete(key))
}, [props.charts])
const charts = props.charts.map(chartParameters => {
const key = getChartKey(chartParameters)
// Get or create a ref for this specific chart
if (!nodeRefsMap.current.has(key)) {
nodeRefsMap.current.set(key, React.createRef<HTMLDivElement>())
}
const nodeRef = nodeRefsMap.current.get(key)!
return (
<CSSTransition key={key} timeout={{ enter: 500, exit: 500 }} classNames="example" nodeRef={nodeRef}>
<Grid item xs={mapWidth(chartParameters.width, spacing)} ref={nodeRef}>
<ChartWithTreeNode tree={props.tree} parameters={chartParameters} />
</Grid>
</CSSTransition>
)
})
const charts = props.charts.map(chartParameters => (
<CSSTransition
key={`${chartParameters.topic}-${chartParameters.dotPath || ''}`}
timeout={{ enter: 500, exit: 500 }}
classNames="example"
>
<Grid item xs={mapWidth(chartParameters.width, spacing)}>
<ChartWithTreeNode tree={props.tree} parameters={chartParameters} />
</Grid>
</CSSTransition>
))
return (
<div className={props.classes.container}>
@@ -126,17 +99,21 @@ function NoCharts() {
)
}
const mapStateToProps = (state: AppState) => ({
charts: state.charts.get('charts'),
connectionId: state.connection.connectionId,
tree: state.connection.tree,
})
const mapStateToProps = (state: AppState) => {
return {
charts: state.charts.get('charts'),
connectionId: state.connection.connectionId,
tree: state.connection.tree,
}
}
const mapDispatchToProps = (dispatch: any) => ({
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: {
chart: bindActionCreators(chartActions, dispatch),
},
}
}
const styles = (theme: Theme) => ({
container: {
@@ -145,8 +122,11 @@ const styles = (theme: Theme) => ({
height: '100%',
padding: '8px',
flex: 1,
overflow: 'auto',
overflow: 'hidden scroll',
},
})
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(ChartPanel) as any)
export default connect(
mapStateToProps,
mapDispatchToProps
)(withStyles(styles)(ChartPanel))
+2 -2
View File
@@ -1,6 +1,6 @@
import React, { useRef, useCallback, memo } from 'react'
import { Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, Button } from '@mui/material'
import { ConfirmationRequest } from '../reducers/Global'
import { Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, Button } from '@material-ui/core'
import { KeyCodes } from '../utils/KeyCodes'
function ConfirmationDialog(props: { confirmationRequests: Array<ConfirmationRequest> }) {
@@ -34,7 +34,7 @@ function ConfirmationDialog(props: { confirmationRequests: Array<ConfirmationReq
return (
<Dialog
open
open={true}
onClose={reject}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
@@ -1,20 +1,16 @@
import * as React from 'react'
import { useState, useCallback, memo } from 'react'
import Add from '@mui/icons-material/Add'
import Lock from '@mui/icons-material/Lock'
import Undo from '@mui/icons-material/Undo'
import Add from '@material-ui/icons/Add'
import ClearAdornment from '../helper/ClearAdornment'
import Delete from '@material-ui/icons/Delete'
import Lock from '@material-ui/icons/Lock'
import Undo from '@material-ui/icons/Undo'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import { Button, Grid, TextField, Tooltip } from '@mui/material'
import { QoS } from 'mqtt-explorer-backend/src/DataSource/MqttSource'
import { connectionManagerActions } from '../../actions'
import { QosSelect } from '../QosSelect'
import { ConnectionOptions } from '../../model/ConnectionOptions'
import Subscriptions from './Subscriptions'
import { Theme, withStyles } from '@material-ui/core/styles'
const SubscriptionsAny = Subscriptions as any
import { Button, Grid, IconButton, TextField, List, ListItem, ListItemText, Tooltip } from '@material-ui/core'
interface Props {
connection: ConnectionOptions
@@ -22,99 +18,122 @@ interface Props {
managerActions: typeof connectionManagerActions
}
const ConnectionSettings = memo((props: Props) => {
const [qos, setQos] = useState<QoS>(0)
const [topic, setTopic] = useState('')
const { classes } = props
interface State {
subscription: string
}
const updateSubscription = useCallback(
(event: React.ChangeEvent<HTMLInputElement>) => setTopic(event.target.value),
[]
)
class ConnectionSettings extends React.Component<Props, State> {
constructor(props: any) {
super(props)
this.state = { subscription: '' }
}
const handleChange = useCallback(
(name: string) => (event: any) => {
props.managerActions.updateConnection(props.connection.id, {
[name]: event.target.value,
})
},
[]
)
private handleChange = (name: string) => (event: any) => {
this.props.managerActions.updateConnection(this.props.connection.id, {
[name]: event.target.value,
})
}
private renderSubscriptions() {
const connection = this.props.connection
return connection.subscriptions.map(subscription => (
<Subscription
deleteAction={() => this.props.managerActions.deleteSubscription(subscription, connection.id)}
subscription={subscription}
key={subscription}
/>
))
}
public render() {
const { classes } = this.props
return (
<div>
<form className={classes.container} noValidate={true} autoComplete="off">
<Grid container={true} spacing={3}>
<Grid item={true} xs={10} className={classes.gridPadding}>
<TextField
className={classes.fullWidth}
label="Subscription"
margin="normal"
onChange={(event: React.ChangeEvent<HTMLInputElement>) =>
this.setState({ subscription: event.target.value })
}
/>
</Grid>
<Grid item={true} xs={2} className={classes.gridPadding}>
<Button
className={classes.button}
color="secondary"
onClick={() =>
this.props.managerActions.addSubscription(this.state.subscription, this.props.connection.id)
}
variant="contained"
>
<Add /> Add
</Button>
</Grid>
<Grid item={true} xs={12} style={{ padding: 0 }}>
<List className={`${classes.topicList} advanced-connection-settings-topic-list`} component="nav">
<div className={classes.list}>{this.renderSubscriptions()}</div>
</List>
</Grid>
<Grid item={true} xs={7} className={classes.gridPadding}>
<TextField
className={classes.fullWidth}
label="MQTT Client ID"
margin="normal"
value={this.props.connection.clientId}
onChange={this.handleChange('clientId')}
/>
</Grid>
<Grid item={true} xs={3} className={classes.gridPadding}>
<div>
<Tooltip title="Manage tls connection certificates" placement="top">
<Button
variant="contained"
className={classes.button}
onClick={() => this.props.managerActions.toggleCertificateSettings()}
>
<Lock /> Certificates
</Button>
</Tooltip>
</div>
</Grid>
<Grid item={true} xs={2} className={classes.gridPadding}>
<Button
variant="contained"
className={classes.button}
onClick={this.props.managerActions.toggleAdvancedSettings}
>
<Undo /> Back
</Button>
</Grid>
</Grid>
</form>
</div>
)
}
}
const Subscription = (props: { subscription: string; deleteAction: any }) => {
return (
<div>
<form className={classes.container} noValidate autoComplete="off">
<Grid container spacing={3}>
<Grid item xs={8} className={classes.gridPadding}>
<TextField
className={`${classes.fullWidth} advanced-connection-settings-topic-input`}
label="Topic"
placeholder="example/topic"
margin="normal"
value={topic}
onChange={updateSubscription}
/>
</Grid>
<Grid item xs={2} className={classes.gridPadding}>
<div className={classes.qos}>
<QosSelect label="QoS" selected={qos} onChange={setQos} />
</div>
</Grid>
<Grid item xs={2} className={classes.gridPadding}>
<Button
className={classes.button}
color="secondary"
onClick={() => props.managerActions.addSubscription({ topic, qos }, props.connection.id)}
variant="contained"
data-testid="add-subscription-button"
>
<Add /> Add
</Button>
</Grid>
<Grid item xs={12} style={{ padding: 0 }}>
<SubscriptionsAny connection={props.connection} />
</Grid>
<Grid item xs={7} className={classes.gridPadding}>
<TextField
className={classes.fullWidth}
label="MQTT Client ID"
margin="normal"
value={props.connection.clientId}
onChange={handleChange('clientId')}
/>
</Grid>
<Grid item xs={3} className={classes.gridPadding}>
<div>
<Tooltip title="Manage tls connection certificates" placement="top">
<Button
variant="contained"
className={classes.button}
onClick={() => props.managerActions.toggleCertificateSettings()}
>
<Lock /> Certificates
</Button>
</Tooltip>
</div>
</Grid>
<Grid item xs={2} className={classes.gridPadding}>
<Button
variant="contained"
className={classes.button}
onClick={props.managerActions.toggleAdvancedSettings}
data-testid="back-button"
>
<Undo /> Back
</Button>
</Grid>
</Grid>
</form>
</div>
<ListItem style={{ padding: '0 0 0 8px' }}>
<ListItemText>
<IconButton onClick={props.deleteAction} style={{ padding: '6px' }}>
<Delete />
</IconButton>
{props.subscription}
</ListItemText>
</ListItem>
)
})
}
const mapDispatchToProps = (dispatch: any) => ({
managerActions: bindActionCreators(connectionManagerActions, dispatch),
})
const mapDispatchToProps = (dispatch: any) => {
return {
managerActions: bindActionCreators(connectionManagerActions, dispatch),
}
}
const styles = (theme: Theme) => ({
fullWidth: {
@@ -123,13 +142,19 @@ const styles = (theme: Theme) => ({
gridPadding: {
padding: '0 12px !important',
},
topicList: {
height: '180px',
overflowY: 'scroll' as 'scroll',
margin: '8px 16px',
backgroundColor: theme.palette.background.default,
},
button: {
marginTop: theme.spacing(3),
float: 'right' as const,
},
qos: {
marginTop: theme.spacing(1),
float: 'right' as 'right',
},
})
export default connect(undefined, mapDispatchToProps)(withStyles(styles)(ConnectionSettings) as any)
export default connect(
undefined,
mapDispatchToProps
)(withStyles(styles)(ConnectionSettings))
@@ -1,138 +0,0 @@
import * as React from 'react'
import Lock from '@mui/icons-material/Lock'
import { bindActionCreators } from 'redux'
import { Button, Theme, Tooltip, Typography } from '@mui/material'
import { connect } from 'react-redux'
import { withStyles } from '@mui/styles'
import { RpcEvents } from '../../../../events/EventsV2'
import { CertificateParameters, ConnectionOptions } from '../../model/ConnectionOptions'
import { CertificateTypes } from '../../actions/ConnectionManager'
import { connectionManagerActions } from '../../actions'
import ClearAdornment from '../helper/ClearAdornment'
import { rendererRpc } from '../../eventBus'
function BrowserCertificateFileSelection(props: {
certificateType: CertificateTypes
title: string
certificate?: CertificateParameters
classes: any
actions: {
connectionManager: typeof connectionManagerActions
}
connection: ConnectionOptions
}) {
const fileInputRef = React.useRef<HTMLInputElement>(null)
const clearCertificate = React.useCallback(() => {
props.actions.connectionManager.updateConnection(props.connection.id, {
[props.certificateType]: undefined,
})
}, [props.connection, props.certificateType])
const handleFileSelect = React.useCallback(
async (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0]
if (!file) {
return
}
try {
// Read file content
const reader = new FileReader()
reader.onload = async e => {
const content = e.target?.result
if (typeof content === 'string') {
// Convert to base64
const base64Data = content.split(',')[1] || content
// Upload via IPC instead of HTTP POST
const result = await rendererRpc.call(RpcEvents.uploadCertificate, {
filename: file.name,
data: base64Data,
})
// Create certificate parameters
const certificate: CertificateParameters = {
name: result.name,
data: result.data,
}
// Update connection
props.actions.connectionManager.updateConnection(props.connection.id, {
[props.certificateType]: certificate,
})
}
}
reader.readAsDataURL(file)
} catch (error) {
console.error('Error uploading certificate:', error)
}
// Reset input
if (fileInputRef.current) {
fileInputRef.current.value = ''
}
},
[props.connection.id, props.certificateType, props.actions.connectionManager]
)
const handleButtonClick = () => {
fileInputRef.current?.click()
}
return (
<span>
<input
ref={fileInputRef}
type="file"
accept=".pem,.crt,.cer,.key"
style={{ display: 'none' }}
onChange={handleFileSelect}
/>
<Tooltip title="Select certificate" placement="top">
<Button variant="contained" className={props.classes.button} onClick={handleButtonClick}>
<Lock /> {props.title}
</Button>
</Tooltip>
<ClearCertificate classes={props.classes} certificate={props.certificate} action={clearCertificate} />
</span>
)
}
function ClearCertificate(props: { classes: any; certificate?: CertificateParameters; action: () => void }) {
if (!props.certificate) {
return null
}
return (
<Tooltip title={props.certificate.name}>
<Typography className={props.classes.certificateName}>
<ClearAdornment action={props.action} value={props.certificate.name} />
{props.certificate.name}
</Typography>
</Tooltip>
)
}
const mapDispatchToProps = (dispatch: any) => ({
actions: {
connectionManager: bindActionCreators(connectionManagerActions, dispatch),
},
})
const styles = (theme: Theme) => ({
certificateName: {
width: '100%',
height: 'calc(1em + 4px)',
overflow: 'hidden' as const,
whiteSpace: 'nowrap' as const,
textOverflow: 'ellipsis' as const,
color: theme.palette.text.secondary,
},
button: {
marginTop: theme.spacing(3),
marginRight: theme.spacing(2),
},
})
export default connect(undefined, mapDispatchToProps)(withStyles(styles)(BrowserCertificateFileSelection) as any)
@@ -1,13 +1,15 @@
import * as React from 'react'
import Lock from '@mui/icons-material/Lock'
import Add from '@material-ui/icons/Add'
import ClearAdornment from '../helper/ClearAdornment'
import Delete from '@material-ui/icons/Delete'
import Lock from '@material-ui/icons/Lock'
import { bindActionCreators } from 'redux'
import { Button, Theme, Tooltip, Typography } from '@mui/material'
import { connect } from 'react-redux'
import { withStyles } from '@mui/styles'
import { Button, Theme, Tooltip, Typography } from '@material-ui/core'
import { CertificateParameters, ConnectionOptions } from '../../model/ConnectionOptions'
import { CertificateTypes } from '../../actions/ConnectionManager'
import { connect } from 'react-redux'
import { connectionManagerActions } from '../../actions'
import ClearAdornment from '../helper/ClearAdornment'
import { withStyles } from '@material-ui/styles'
function CertificateFileSelection(props: {
certificateType: CertificateTypes
@@ -56,20 +58,22 @@ function ClearCertificate(props: { classes: any; certificate?: CertificateParame
)
}
const mapDispatchToProps = (dispatch: any) => ({
actions: {
connectionManager: bindActionCreators(connectionManagerActions, dispatch),
},
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: {
connectionManager: bindActionCreators(connectionManagerActions, dispatch),
},
}
}
const styles = (theme: Theme) => ({
certificateName: {
width: '100%',
height: 'calc(1em + 4px)',
overflow: 'hidden' as const,
whiteSpace: 'nowrap' as const,
textOverflow: 'ellipsis' as const,
color: theme.palette.text.secondary,
overflow: 'hidden' as 'hidden',
whiteSpace: 'nowrap' as 'nowrap',
textOverflow: 'ellipsis' as 'ellipsis',
color: theme.palette.text.hint,
},
button: {
marginTop: theme.spacing(3),
@@ -77,4 +81,7 @@ const styles = (theme: Theme) => ({
},
})
export default connect(undefined, mapDispatchToProps)(withStyles(styles)(CertificateFileSelection) as any)
export default connect(
undefined,
mapDispatchToProps
)(withStyles(styles)(CertificateFileSelection))
@@ -1,18 +1,12 @@
import * as React from 'react'
import Undo from '@mui/icons-material/Undo'
import CertificateFileSelection from './CertificateFileSelection'
import Undo from '@material-ui/icons/Undo'
import { bindActionCreators } from 'redux'
import { Button, Grid } from '@mui/material'
import { Button, Grid } from '@material-ui/core'
import { connect } from 'react-redux'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import { connectionManagerActions } from '../../actions'
import { ConnectionOptions } from '../../model/ConnectionOptions'
import BrowserCertificateFileSelection from './BrowserCertificateFileSelection'
import CertificateFileSelection from './CertificateFileSelection'
import { isBrowserMode } from '../../utils/browserMode'
// Use browser or desktop file selection based on mode
const CertSelector: any = isBrowserMode ? BrowserCertificateFileSelection : CertificateFileSelection
import { Theme, withStyles } from '@material-ui/core/styles'
interface Props {
connection: ConnectionOptions
@@ -48,33 +42,33 @@ class Certificates extends React.PureComponent<Props, State> {
const { classes } = this.props
return (
<div>
<form noValidate autoComplete="off">
<Grid container spacing={3}>
<Grid item xs={12} className={classes.gridPadding}>
<CertSelector
<form noValidate={true} autoComplete="off">
<Grid container={true} spacing={3}>
<Grid item={true} xs={12} className={classes.gridPadding}>
<CertificateFileSelection
connection={this.props.connection}
certificate={this.props.connection.selfSignedCertificate}
title="Server Certificate (CA)"
certificateType="selfSignedCertificate"
/>
</Grid>
<Grid item xs={12} className={classes.gridPadding}>
<CertSelector
<Grid item={true} xs={12} className={classes.gridPadding}>
<CertificateFileSelection
connection={this.props.connection}
certificate={this.props.connection.clientCertificate}
title="Client Certificate"
certificateType="clientCertificate"
/>
</Grid>
<Grid item xs={12} className={classes.gridPadding}>
<CertSelector
<Grid item={true} xs={12} className={classes.gridPadding}>
<CertificateFileSelection
connection={this.props.connection}
certificate={this.props.connection.clientKey}
title="Client Key"
certificateType="clientKey"
/>
</Grid>
<Grid item xs={2} className={classes.gridPadding}>
<Grid item={true} xs={2} className={classes.gridPadding}>
<br />
<Button
variant="contained"
@@ -91,9 +85,11 @@ class Certificates extends React.PureComponent<Props, State> {
}
}
const mapDispatchToProps = (dispatch: any) => ({
managerActions: bindActionCreators(connectionManagerActions, dispatch),
})
const mapDispatchToProps = (dispatch: any) => {
return {
managerActions: bindActionCreators(connectionManagerActions, dispatch),
}
}
const styles = (theme: Theme) => ({
fullWidth: {
@@ -108,4 +104,7 @@ const styles = (theme: Theme) => ({
},
})
export default connect(undefined, mapDispatchToProps)(withStyles(styles)(Certificates) as any)
export default connect(
undefined,
mapDispatchToProps
)(withStyles(styles)(Certificates))
@@ -1,36 +1,22 @@
import PowerSettingsNew from '@mui/icons-material/PowerSettingsNew'
import React from 'react'
import { Button } from '@mui/material'
import ConnectionHealthIndicator from '../helper/ConnectionHealthIndicator'
import PowerSettingsNew from '@material-ui/icons/PowerSettingsNew'
import React from 'react'
import { Button } from '@material-ui/core'
function ConnectButton(props: { connecting: boolean; classes: any; toggle: () => void }) {
const { classes, toggle, connecting } = props
if (connecting) {
return (
<Button
variant="contained"
color="primary"
className={classes.button}
onClick={toggle}
data-testid="abort-button"
aria-label="Cancel connection attempt"
>
<Button variant="contained" color="primary" className={classes.button} onClick={toggle}>
<ConnectionHealthIndicator />
&nbsp;&nbsp;Cancel
&nbsp;&nbsp;Abort
</Button>
)
}
return (
<Button
variant="contained"
color="primary"
className={classes.button}
onClick={toggle}
data-testid="connect-button"
aria-label="Connect to MQTT broker"
>
<Button variant="contained" color="primary" className={classes.button} onClick={toggle}>
<PowerSettingsNew /> Connect
</Button>
)
@@ -1,28 +1,36 @@
import ConnectButton from './ConnectButton'
import Delete from '@material-ui/icons/Delete'
import React, { useCallback, useState } from 'react'
import Save from '@mui/icons-material/Save'
import Delete from '@mui/icons-material/Delete'
import Settings from '@mui/icons-material/Settings'
import Visibility from '@mui/icons-material/Visibility'
import VisibilityOff from '@mui/icons-material/VisibilityOff'
import Save from '@material-ui/icons/Save'
import Settings from '@material-ui/icons/Settings'
import Visibility from '@material-ui/icons/Visibility'
import VisibilityOff from '@material-ui/icons/VisibilityOff'
import { AppState } from '../../reducers'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import { Button, Grid, IconButton, InputAdornment, MenuItem, TextField, Tooltip } from '@mui/material'
import { AppState } from '../../reducers'
import { connectionActions, connectionManagerActions, globalActions } from '../../actions'
import { connectionActions, connectionManagerActions } from '../../actions'
import { ConnectionOptions, toMqttConnection } from '../../model/ConnectionOptions'
import { KeyCodes } from '../../utils/KeyCodes'
import { Theme, withStyles } from '@material-ui/core/styles'
import { ToggleSwitch } from './ToggleSwitch'
import { useGlobalKeyEventHandler } from '../../effects/useGlobalKeyEventHandler'
import ConnectButton from './ConnectButton'
import {
Button,
FormControl,
Grid,
IconButton,
Input,
InputAdornment,
InputLabel,
MenuItem,
TextField,
} from '@material-ui/core'
interface Props {
connection: ConnectionOptions
classes: { [s: string]: string }
actions: typeof connectionActions
managerActions: typeof connectionManagerActions
globalActions: typeof globalActions
connected: boolean
connecting: boolean
}
@@ -32,17 +40,6 @@ const protocols = ['mqtt', 'ws']
function ConnectionSettings(props: Props) {
const [showPassword, setShowPassword] = useState(false)
const handleDelete = useCallback(async () => {
const confirmed = await props.globalActions.requestConfirmation(
'Delete Connection',
`Are you sure you want to delete the connection "${props.connection.name}"?\n\nThis action cannot be undone.`
)
if (confirmed) {
props.managerActions.deleteConnection(props.connection.id)
}
}, [props.connection.id, props.connection.name, props.globalActions, props.managerActions])
const toggleConnect = useCallback(() => {
if (props.connecting) {
props.actions.disconnect()
@@ -72,13 +69,13 @@ function ConnectionSettings(props: Props) {
function renderBasePathInput() {
return (
<Grid item xs={4}>
<Grid item={true} xs={4}>
<TextField
label="Basepath"
className={props.classes.textField}
value={props.connection.basePath}
onChange={handleChange('basePath')}
margin="dense"
margin="normal"
/>
</Grid>
)
@@ -103,33 +100,26 @@ function ConnectionSettings(props: Props) {
const protocolItems = protocols.map((value: string) => (
<MenuItem key={value} value={value}>
{value}
://
{value === 'mqtt' ? '(Standard)' : '(WebSocket)'}
{value}://
</MenuItem>
))
return (
<Tooltip title="Use 'mqtt' for standard connections or 'ws' for WebSocket connections" arrow>
<TextField
select
label="Protocol"
className={classes.textField}
value={connection.protocol}
onChange={updateProtocol}
margin="dense"
inputProps={{
'aria-label': 'MQTT protocol',
}}
>
{protocolItems}
</TextField>
</Tooltip>
<TextField
select={true}
label="Protocol"
className={classes.textField}
value={connection.protocol}
onChange={updateProtocol}
margin="normal"
>
{protocolItems}
</TextField>
)
}
const updateProtocol = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.target
const value = event.target.value
updateConnection('protocol', value)
if (event.target.value === 'mqtt') {
updateConnection('basePath', undefined)
@@ -153,15 +143,9 @@ function ConnectionSettings(props: Props) {
function PasswordVisibilityButton(props: { showPassword: boolean; toggle: () => void }) {
return (
<InputAdornment position="end">
<Tooltip title={props.showPassword ? 'Hide password' : 'Show password'} arrow>
<IconButton
aria-label={props.showPassword ? 'Hide password' : 'Show password'}
onClick={props.toggle}
edge="end"
>
{props.showPassword ? <Visibility /> : <VisibilityOff />}
</IconButton>
</Tooltip>
<IconButton aria-label="Toggle password visibility" onClick={props.toggle}>
{props.showPassword ? <Visibility /> : <VisibilityOff />}
</IconButton>
</InputAdornment>
)
}
@@ -169,24 +153,20 @@ function ConnectionSettings(props: Props) {
const { classes, connection } = props
return (
<div style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
<form className={classes.container} noValidate autoComplete="off" style={{ flex: 1, overflow: 'auto' }}>
<Grid container spacing={2}>
<Grid item xs={5}>
<div>
<form className={classes.container} noValidate={true} autoComplete="off">
<Grid container={true} spacing={3}>
<Grid item={true} xs={5}>
<TextField
autoFocus
autoFocus={true}
label="Name"
className={classes.textField}
value={connection.name}
onChange={handleChange('name')}
margin="dense"
placeholder="My MQTT Connection"
inputProps={{
'aria-label': 'Connection name',
}}
margin="normal"
/>
</Grid>
<Grid item xs={4}>
<Grid item={true} xs={4}>
<ToggleSwitch
label="Validate certificate"
classes={classes}
@@ -194,139 +174,101 @@ function ConnectionSettings(props: Props) {
toggle={toggleCertValidation}
/>
</Grid>
<Grid item xs={3}>
<Grid item={true} xs={3}>
<ToggleSwitch label="Encryption (tls)" classes={classes} value={connection.encryption} toggle={toggleTls} />
</Grid>
<Grid item xs={2}>
<Grid item={true} xs={2}>
{renderProtocols()}
</Grid>
<Grid item xs={7}>
<Grid item={true} xs={7}>
<TextField
label="Host"
className={classes.textField}
value={connection.host}
onChange={handleChange('host')}
margin="dense"
placeholder="broker.example.com"
inputProps={{
'data-testid': 'host-input',
'aria-label': 'MQTT broker host',
}}
margin="normal"
/>
</Grid>
<Grid item xs={3}>
<Grid item={true} xs={3}>
<TextField
label="Port"
className={classes.textField}
value={connection.port}
onChange={handleChange('port')}
margin="dense"
type="number"
placeholder="1883"
inputProps={{
'aria-label': 'MQTT broker port',
min: 1,
max: 65535,
}}
margin="normal"
/>
</Grid>
{requiresBasePath() ? renderBasePathInput() : null}
<Grid item xs={requiresBasePath() ? 4 : 6}>
<Grid item={true} xs={requiresBasePath() ? 4 : 6}>
<TextField
label="Username"
className={classes.textField}
value={connection.username}
onChange={handleChange('username')}
margin="dense"
placeholder="Optional"
inputProps={{
'aria-label': 'MQTT username',
autoComplete: 'username',
}}
margin="normal"
/>
</Grid>
<Grid item xs={requiresBasePath() ? 4 : 6}>
<TextField
label="Password"
className={classes.textField}
type={showPassword ? 'text' : 'password'}
value={connection.password}
onChange={handleChange('password')}
margin="dense"
placeholder="Optional"
InputProps={{
endAdornment: <PasswordVisibilityButton showPassword={showPassword} toggle={handleClickShowPassword} />,
}}
inputProps={{
'aria-label': 'MQTT password',
autoComplete: 'current-password',
}}
/>
<Grid item={true} xs={requiresBasePath() ? 4 : 6}>
<FormControl className={`${classes.textField} ${classes.inputFormControl}`}>
<InputLabel htmlFor="adornment-password">Password</InputLabel>
<Input
id="adornment-password"
type={showPassword ? 'text' : 'password'}
value={connection.password}
onChange={handleChange('password')}
endAdornment={<PasswordVisibilityButton showPassword={showPassword} toggle={handleClickShowPassword} />}
/>
</FormControl>
</Grid>
</Grid>
</form>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
paddingTop: '16px',
borderTop: '1px solid rgba(0, 0, 0, 0.12)',
}}
>
<br />
<div>
<Tooltip title="Delete this connection permanently" arrow>
<div style={{ float: 'left' }}>
<Button
variant="contained"
color="error"
className={classes.button}
onClick={handleDelete}
aria-label="Delete connection"
onClick={() => props.managerActions.deleteConnection(props.connection.id)}
>
<Delete /> Delete
Delete <Delete />
</Button>
</Tooltip>
<Tooltip title="Advanced connection settings" arrow>
<Button
variant="contained"
className={classes.button}
onClick={props.managerActions.toggleAdvancedSettings}
data-testid="advanced-button"
aria-label="Show advanced settings"
>
<Settings /> Advanced
</Button>
</Tooltip>
</div>
<div>
<Tooltip title="Save connection settings" arrow>
</div>
<div style={{ float: 'right' }}>
<Button
variant="contained"
color="secondary"
className={classes.button}
onClick={props.managerActions.saveConnectionSettings}
aria-label="Save connection"
>
<Save /> Save
</Button>
</Tooltip>
<ConnectButton toggle={toggleConnect} connecting={props.connecting} classes={classes} />
<ConnectButton toggle={toggleConnect} connecting={props.connecting} classes={classes} />
</div>
</div>
</div>
</form>
</div>
)
}
const mapStateToProps = (state: AppState) => ({
connected: state.connection.connected,
connecting: state.connection.connecting,
})
const mapStateToProps = (state: AppState) => {
return {
connected: state.connection.connected,
connecting: state.connection.connecting,
}
}
const mapDispatchToProps = (dispatch: any) => ({
actions: bindActionCreators(connectionActions, dispatch),
managerActions: bindActionCreators(connectionManagerActions, dispatch),
globalActions: bindActionCreators(globalActions, dispatch),
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: bindActionCreators(connectionActions, dispatch),
managerActions: bindActionCreators(connectionManagerActions, dispatch),
}
}
const styles = (theme: Theme) => ({
textField: {
@@ -343,4 +285,7 @@ const styles = (theme: Theme) => ({
},
})
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(ConnectionSettings) as any)
export default connect(
mapStateToProps,
mapDispatchToProps
)(withStyles(styles)(ConnectionSettings))
@@ -1,22 +1,16 @@
import * as React from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import { Modal, Paper, Toolbar, Typography, Collapse } from '@mui/material'
import ConnectionSettings from './ConnectionSettings'
import ProfileList from './ProfileList'
import MobileConnectionSelector from './MobileConnectionSelector'
import { AppState } from '../../reducers'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { connectionManagerActions } from '../../actions'
import { ConnectionOptions, toMqttConnection } from '../../model/ConnectionOptions'
import { Theme, withStyles } from '@material-ui/core/styles'
import { Modal, Paper, Toolbar, Typography, Collapse } from '@material-ui/core'
import AdvancedConnectionSettings from './AdvancedConnectionSettings'
import Certificates from './Certificates'
const ConnectionSettingsAny = ConnectionSettings as any
const AdvancedConnectionSettingsAny = AdvancedConnectionSettings as any
const CertificatesAny = Certificates as any
interface Props {
actions: any
classes: any
@@ -40,13 +34,13 @@ class ConnectionSetup extends React.PureComponent<Props, {}> {
return (
<div>
<Collapse in={!showAdvancedSettings && !showCertificateSettings}>
<ConnectionSettingsAny connection={connection} />
<ConnectionSettings connection={connection} />
</Collapse>
<Collapse in={showAdvancedSettings && !showCertificateSettings}>
<AdvancedConnectionSettingsAny connection={connection} />
<AdvancedConnectionSettings connection={connection} />
</Collapse>
<Collapse in={showCertificateSettings}>
<CertificatesAny connection={connection} />
<Certificates connection={connection} />
</Collapse>
</div>
)
@@ -61,22 +55,17 @@ class ConnectionSetup extends React.PureComponent<Props, {}> {
const mqttConnection = connection && toMqttConnection(connection)
return (
<div>
<Modal open={visible} disableAutoFocus>
<Modal open={visible} disableAutoFocus={true}>
<Paper className={classes.root}>
<div className={classes.left}>
<ProfileList />
</div>
<div className={classes.right} key={connection && connection.id}>
<Toolbar>
<div className={classes.toolbarContent}>
<div className={classes.desktopTitle}>
<Typography className={classes.title} variant="h6" color="inherit">
MQTT Connection
</Typography>
<Typography className={classes.connectionUri}>{mqttConnection && mqttConnection.url}</Typography>
</div>
<MobileConnectionSelector />
</div>
<Typography className={classes.title} variant="h6" color="inherit">
MQTT Connection
</Typography>
<Typography className={classes.connectionUri}>{mqttConnection && mqttConnection.url}</Typography>
</Toolbar>
{this.renderSettings()}
</div>
@@ -91,85 +80,61 @@ const connectionHeight = '440px'
const styles = (theme: Theme) => ({
title: {
color: theme.palette.text.primary,
whiteSpace: 'nowrap' as const,
},
toolbarContent: {
width: '100%',
display: 'flex',
alignItems: 'center',
},
desktopTitle: {
display: 'flex',
alignItems: 'center',
flex: 1,
// Hide on mobile - connection selector will take its place
[theme.breakpoints.down('md')]: {
display: 'none' as const,
},
whiteSpace: 'nowrap' as 'nowrap',
},
root: {
margin: `calc((100vh - ${connectionHeight}) / 2) auto 0 auto`,
minWidth: '800px',
maxWidth: '850px',
height: connectionHeight,
outline: 'none' as const,
display: 'flex' as const,
// Mobile responsive adjustments
[theme.breakpoints.down('md')]: {
minWidth: '95vw',
maxWidth: '95vw',
height: '85vh',
margin: '7.5vh auto 0 auto',
flexDirection: 'column' as const,
},
outline: 'none' as 'none',
display: 'flex' as 'flex',
},
left: {
borderRightStyle: 'dotted' as const,
borderRightStyle: 'dotted' as 'dotted',
borderRadius: `${theme.shape.borderRadius}px 0 0 ${theme.shape.borderRadius}px`,
paddingTop: theme.spacing(2),
flex: 3,
overflow: 'hidden' as const,
overflow: 'hidden' as 'hidden',
backgroundColor: theme.palette.background.default,
color: theme.palette.text.primary,
overflowY: 'auto' as const,
// Mobile: hide profile list to save space
[theme.breakpoints.down('md')]: {
display: 'none' as const,
},
overflowY: 'auto' as 'auto',
},
right: {
borderRadius: `0 ${theme.shape.borderRadius}px ${theme.shape.borderRadius}px 0`,
backgroundColor: theme.palette.background.paper,
padding: theme.spacing(2),
flex: 10,
// Mobile: enable scrolling
[theme.breakpoints.down('md')]: {
borderRadius: `${theme.shape.borderRadius}px`,
overflowY: 'auto' as const,
},
},
connectionUri: {
width: '27em',
textOverflow: 'ellipsis' as const,
whiteSpace: 'nowrap' as const,
overflow: 'hidden' as const,
color: theme.palette.text.secondary,
textOverflow: 'ellipsis' as 'ellipsis',
whiteSpace: 'nowrap' as 'nowrap',
overflow: 'hidden' as 'hidden',
color: theme.palette.text.hint,
fontSize: '0.9em',
marginLeft: theme.spacing(4),
},
})
const mapStateToProps = (state: AppState) => ({
visible: !state.connection.connected,
showAdvancedSettings: state.connectionManager.showAdvancedSettings,
showCertificateSettings: state.connectionManager.showCertificateSettings,
connection: state.connectionManager.selected
? state.connectionManager.connections[state.connectionManager.selected]
: undefined,
})
const mapStateToProps = (state: AppState) => {
return {
visible: !state.connection.connected,
showAdvancedSettings: state.connectionManager.showAdvancedSettings,
showCertificateSettings: state.connectionManager.showCertificateSettings,
connection: state.connectionManager.selected
? state.connectionManager.connections[state.connectionManager.selected]
: undefined,
}
}
const mapDispatchToProps = (dispatch: any) => ({
actions: bindActionCreators(connectionManagerActions, dispatch),
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: bindActionCreators(connectionManagerActions, dispatch),
}
}
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(ConnectionSetup) as any)
export default connect(
mapStateToProps,
mapDispatchToProps
)(withStyles(styles)(ConnectionSetup))
@@ -1,137 +0,0 @@
import * as React from 'react'
import Add from '@mui/icons-material/Add'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { IconButton, MenuItem, Select, SelectChangeEvent } from '@mui/material'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import { connectionManagerActions } from '../../actions'
import { AppState } from '../../reducers'
const styles = (theme: Theme) => ({
container: {
display: 'none',
// Only show on mobile, takes full width
[theme.breakpoints.down('md')]: {
display: 'flex',
flex: 1,
alignItems: 'center',
gap: theme.spacing(1),
},
},
select: {
flex: 1,
fontSize: '1rem',
'& .MuiSelect-select': {
paddingTop: theme.spacing(1),
paddingBottom: theme.spacing(1),
},
},
addButton: {
padding: theme.spacing(1),
},
})
interface Props {
classes: any
connections: Array<{ id: string; name?: string; host?: string }>
currentConnectionId?: string
isConnected: boolean
currentActiveConnectionId?: string
actions: typeof connectionManagerActions
}
class MobileConnectionSelector extends React.PureComponent<Props, {}> {
private handleConnectionChange = (event: SelectChangeEvent<string>) => {
const connectionId = event.target.value
this.props.actions.selectConnection(connectionId)
}
private handleCreateConnection = () => {
this.props.actions.createConnection()
}
private getConnectionDisplayName = (connection: { name?: string; host?: string }) =>
connection.name || connection.host || 'Unnamed Connection'
public render() {
const { classes, connections, currentConnectionId, isConnected, currentActiveConnectionId } = this.props
if (!connections || connections.length === 0) {
return null
}
return (
<div className={classes.container}>
<Select
className={classes.select}
value={currentConnectionId || ''}
onChange={this.handleConnectionChange}
aria-label="Select MQTT connection"
displayEmpty
MenuProps={{
PaperProps: {
style: {
maxHeight: '60vh',
},
},
}}
>
{connections.map(conn => {
// Show "(Connected)" only when:
// 1. This connection is selected in the UI (currentConnectionId)
// 2. There's an active MQTT connection (isConnected)
// 3. The active connection matches this connection (currentActiveConnectionId)
// This prevents showing "Connected" when a connection is selected but not connected,
// or when switching between connections during a disconnect/reconnect cycle.
const showConnectedStatus =
conn.id === currentConnectionId && isConnected && conn.id === currentActiveConnectionId
const displayName = this.getConnectionDisplayName(conn)
return (
<MenuItem key={conn.id} value={conn.id}>
{displayName}
{showConnectedStatus && ' (Connected)'}
</MenuItem>
)
})}
</Select>
<IconButton
className={classes.addButton}
onClick={this.handleCreateConnection}
aria-label="Create new connection"
size="medium"
>
<Add />
</IconButton>
</div>
)
}
}
const mapStateToProps = (state: AppState) => {
const { connectionManager } = state
const connections =
connectionManager && connectionManager.connections
? Object.values(connectionManager.connections).map(conn => ({
id: conn.id,
name: conn.name,
host: conn.host,
}))
: []
return {
connections,
currentConnectionId: state.connectionManager?.selected,
isConnected: state.connection.connected,
currentActiveConnectionId: state.connection.connectionId,
}
}
const mapDispatchToProps = (dispatch: any) => ({
actions: bindActionCreators(connectionManagerActions, dispatch),
})
// Using 'as any' here is consistent with other Material-UI + Redux connected components
// in this codebase (see ConnectionSettings.tsx, ProfileList/index.tsx, ChartPanel/index.tsx)
// to work around complex TypeScript type inference issues with the withStyles + connect HOCs
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(MobileConnectionSelector) as any)
@@ -1,8 +1,7 @@
import * as React from 'react'
import Add from '@mui/icons-material/Add'
import { Fab } from '@mui/material'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import Add from '@material-ui/icons/Add'
import { Fab } from '@material-ui/core'
import { Theme, withStyles } from '@material-ui/core/styles'
const styles = (theme: Theme) => ({
addButton: {
@@ -15,10 +14,12 @@ const styles = (theme: Theme) => ({
},
})
export const AddButton = withStyles(styles)((props: { classes: any; action: any }) => (
<span id="addProfileButton" style={{ marginRight: '12px' }}>
<Fab size="small" color="secondary" aria-label="Add" className={props.classes.addButton} onClick={props.action}>
<Add className={props.classes.addIcon} />
</Fab>
</span>
))
export const AddButton = withStyles(styles)((props: { classes: any; action: any }) => {
return (
<span id="addProfileButton" style={{ marginRight: '12px' }}>
<Fab size="small" color="secondary" aria-label="Add" className={props.classes.addButton} onClick={props.action}>
<Add className={props.classes.addIcon} />
</Fab>
</span>
)
})
@@ -1,41 +1,26 @@
import React, { useCallback } from 'react'
import React from 'react'
import { connect } from 'react-redux'
import { ListItem, Typography } from '@mui/material'
import { withStyles } from '@mui/styles'
import { Theme } from '@mui/material/styles'
import { bindActionCreators } from 'redux'
import { ListItem, Typography } from '@material-ui/core'
import { toMqttConnection, ConnectionOptions } from '../../../model/ConnectionOptions'
import { connectionActions, connectionManagerActions } from '../../../actions'
import { withStyles, Theme } from '@material-ui/core/styles'
import { bindActionCreators } from 'redux'
import { connectionManagerActions } from '../../../actions'
export interface Props {
connection: ConnectionOptions
actions: {
connection: any
connectionManager: any
}
actions: any
selected: boolean
classes: any
}
function ConnectionItem(props: Props) {
const connect = useCallback(() => {
const mqttOptions = toMqttConnection(props.connection)
if (mqttOptions) {
props.actions.connection.connect(mqttOptions, props.connection.id)
}
}, [props.connection, props])
const ConnectionItem = (props: Props) => {
const connection = props.connection.host && toMqttConnection(props.connection)
return (
<ListItem
button
button={true}
selected={props.selected}
style={{ display: 'block' }}
onClick={() => props.actions.connectionManager.selectConnection(props.connection.id)}
onDoubleClick={() => {
props.actions.connectionManager.selectConnection(props.connection.id)
connect()
}}
onClick={() => props.actions.selectConnection(props.connection.id)}
>
<Typography className={props.classes.name}>{props.connection.name || 'mqtt broker'}</Typography>
<Typography className={props.classes.details}>{connection && connection.url}</Typography>
@@ -43,27 +28,30 @@ function ConnectionItem(props: Props) {
)
}
export const mapDispatchToProps = (dispatch: any) => ({
actions: {
connection: bindActionCreators(connectionActions, dispatch),
connectionManager: bindActionCreators(connectionManagerActions, dispatch),
},
})
export const mapDispatchToProps = (dispatch: any) => {
return {
actions: bindActionCreators(connectionManagerActions, dispatch),
}
}
export const connectionItemStyle = (theme: Theme) => ({
name: {
width: '100%',
textOverflow: 'ellipsis' as const,
whiteSpace: 'nowrap' as const,
overflow: 'hidden' as const,
textOverflow: 'ellipsis' as 'ellipsis',
whiteSpace: 'nowrap' as 'nowrap',
overflow: 'hidden' as 'hidden',
},
details: {
width: '100%',
textOverflow: 'ellipsis' as const,
whiteSpace: 'nowrap' as const,
overflow: 'hidden' as const,
color: theme.palette.text.secondary,
textOverflow: 'ellipsis' as 'ellipsis',
whiteSpace: 'nowrap' as 'nowrap',
overflow: 'hidden' as 'hidden',
color: theme.palette.text.hint,
fontSize: '0.7em',
},
})
export default connect(null, mapDispatchToProps)(withStyles(connectionItemStyle)(ConnectionItem) as any)
export default connect(
null,
mapDispatchToProps
)(withStyles(connectionItemStyle)(ConnectionItem))
@@ -1,19 +1,16 @@
import React from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { List } from '@mui/material'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import ConnectionItem from './ConnectionItem'
import React from 'react'
import { AddButton } from './AddButton'
import { AppState } from '../../../reducers'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import { connectionManagerActions } from '../../../actions'
import { ConnectionOptions } from '../../../model/ConnectionOptions'
import { KeyCodes } from '../../../utils/KeyCodes'
import { List, ListSubheader } from '@material-ui/core'
import { Theme, withStyles } from '@material-ui/core/styles'
import { useGlobalKeyEventHandler } from '../../../effects/useGlobalKeyEventHandler'
const ConnectionItemAny = ConnectionItem as any
interface Props {
classes: any
selected?: string
@@ -52,7 +49,7 @@ function ProfileList(props: Props) {
<List style={{ height: '100%' }} component="nav" subheader={createConnectionButton}>
<div className={classes.list}>
{Object.values(connections).map(connection => (
<ConnectionItemAny connection={connection} key={connection.id} selected={selected === connection.id} />
<ConnectionItem connection={connection} key={connection.id} selected={selected === connection.id} />
))}
</div>
</List>
@@ -63,17 +60,24 @@ const styles = (theme: Theme) => ({
list: {
marginTop: theme.spacing(1),
height: `calc(100% - ${theme.spacing(6)})`,
overflowY: 'auto' as const,
overflowY: 'auto' as 'auto',
},
})
const mapDispatchToProps = (dispatch: any) => ({
actions: bindActionCreators(connectionManagerActions, dispatch),
})
const mapDispatchToProps = (dispatch: any) => {
return {
actions: bindActionCreators(connectionManagerActions, dispatch),
}
}
const mapStateToProps = (state: AppState) => ({
connections: state.connectionManager.connections,
selected: state.connectionManager.selected,
})
const mapStateToProps = (state: AppState) => {
return {
connections: state.connectionManager.connections,
selected: state.connectionManager.selected,
}
}
export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(ProfileList) as any)
export default connect(
mapStateToProps,
mapDispatchToProps
)(withStyles(styles)(ProfileList))
@@ -1,88 +0,0 @@
import React, { useCallback, useState } from 'react'
import Delete from '@mui/icons-material/Delete'
import {
IconButton,
TableContainer,
Table,
TableHead,
TableRow,
TableCell,
TableBody,
Paper,
Theme,
} from '@mui/material'
import { bindActionCreators } from 'redux'
import { withStyles } from '@mui/styles'
import { connect } from 'react-redux'
import { ConnectionOptions } from '../../model/ConnectionOptions'
import { connectionManagerActions } from '../../actions'
function Subscriptions(props: {
classes: any
connection: ConnectionOptions
managerActions: typeof connectionManagerActions
}) {
const { classes, connection, managerActions } = props
return (
<TableContainer component={Paper} className={`${classes.topicList} advanced-connection-settings-topic-list`}>
<Table size="small">
<TableHead>
<TableRow>
<TableCell align="left" padding="checkbox" className={classes.tableTitleCell} />
<TableCell className={classes.tableTitleCell}>Topic</TableCell>
<TableCell align="right" className={classes.tableTitleCell}>
QoS
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{connection.subscriptions.map(subscription => (
<TableRow key={`${subscription.topic}_qos_${subscription.qos}`}>
<TableCell align="right" className={classes.tableCell}>
<IconButton
onClick={() => managerActions.deleteSubscription(subscription, connection.id)}
style={{ padding: '6px' }}
>
<Delete />
</IconButton>
</TableCell>
<TableCell component="th" scope="row" className={classes.tableCell}>
{subscription.topic}
</TableCell>
<TableCell align="right" className={classes.tableCell}>
{subscription.qos}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
)
}
const mapDispatchToProps = (dispatch: any) => ({
managerActions: bindActionCreators(connectionManagerActions, dispatch),
})
const styles = (theme: Theme) => ({
tableCell: {
paddingTop: 0,
paddingBottom: 0,
wordBbreak: 'break-word',
},
tableTitleCell: {
paddingTop: `${theme.spacing(0.5)}px`,
paddingBottom: `${theme.spacing(0.5)}px`,
},
topicList: {
height: '196px',
overflowY: 'scroll' as const,
margin: `${theme.spacing(1)}px ${theme.spacing(1)}px 0 ${theme.spacing(1)}px`,
backgroundColor: theme.palette.background.default,
width: 'auto',
},
})
export default connect(undefined, mapDispatchToProps)(withStyles(styles)(Subscriptions) as any)
@@ -1,23 +1,12 @@
import React from 'react'
import { FormControlLabel, Switch } from '@mui/material'
import { FormControlLabel, Switch } from '@material-ui/core'
export function ToggleSwitch(props: { value: boolean; classes: any; toggle: () => void; label: string }) {
const { classes, value, toggle, label } = props
const toggleSwitch = (
<Switch
checked={value}
onChange={toggle}
color="primary"
role="switch"
aria-checked={value}
inputProps={{
'aria-label': label,
}}
/>
)
const toggleSwitch = <Switch checked={value} onChange={toggle} color="primary" />
return (
<div className={classes.switch}>
<FormControlLabel control={toggleSwitch} label={`${label} (${value ? 'On' : 'Off'})`} labelPlacement="bottom" />
<FormControlLabel control={toggleSwitch} label={label} labelPlacement="bottom" />
</div>
)
}
+5 -6
View File
@@ -1,6 +1,5 @@
import * as React from 'react'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import { Theme, withStyles } from '@material-ui/core'
interface Props {
keyboardKey: string
@@ -24,20 +23,20 @@ class Key extends React.Component<Props, {}> {
const style = (theme: Theme) => ({
keyStyle: {
display: 'inline-block' as const,
display: 'inline-block' as 'inline-block',
width: '1em',
height: '1em',
backgroundColor: '#bbb',
borderRadius: '10%',
verticalAlign: 'middle' as const,
textAlign: 'center' as const,
verticalAlign: 'middle' as 'middle',
textAlign: 'center' as 'center',
textShadow: '1px 1px rgba(255,255,255,0.45)',
boxShadow: '0.08em 0.15em 0.01em 0px rgba(100,100,100,0.75)',
},
keyTextStyle: {
marginTop: '0.65em',
fontSize: '0.4em',
fontWeight: 'bold' as const,
fontWeight: 'bold' as 'bold',
},
})
+6 -20
View File
@@ -1,7 +1,5 @@
import * as React from 'react'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import { Theme, withStyles } from '@material-ui/core'
const cursor = require('./cursor.png')
interface State {
@@ -14,18 +12,11 @@ interface State {
class Demo extends React.Component<{ classes: any }, State> {
private timer: any
private frameInterval = 20
constructor(props: any) {
super(props)
this.state = {
enabled: false,
target: { x: 0, y: 0 },
position: { x: 0, y: 0 },
stepSizeX: 1,
stepSizeY: 1,
}
this.state = { enabled: false, target: { x: 0, y: 0 }, position: { x: 0, y: 0 }, stepSizeX: 1, stepSizeY: 1 }
}
private moveCloser(steps: number = 0) {
@@ -58,12 +49,7 @@ class Demo extends React.Component<{ classes: any }, State> {
;(window as any).demo.moveMouse = (x: number, y: number, animationTime: number) => {
const stepSizeX = Math.abs(this.state.position.x - x) / (animationTime / this.frameInterval)
const stepSizeY = Math.abs(this.state.position.y - y) / (animationTime / this.frameInterval)
this.setState({
stepSizeX,
stepSizeY,
enabled: true,
target: { x, y },
})
this.setState({ stepSizeX, stepSizeY, enabled: true, target: { x, y } })
this.moveCloser()
}
}
@@ -86,10 +72,10 @@ const style = (theme: Theme) => ({
cursor: {
width: '32px',
height: '32px',
position: 'fixed' as const,
position: 'fixed' as 'fixed',
zIndex: 1000000,
filter: theme.palette.mode === 'light' ? undefined : 'invert(100%)',
pointerEvents: 'none' as const,
filter: theme.palette.type === 'light' ? undefined : 'invert(100%)',
pointerEvents: 'none' as 'none',
},
})
+7 -7
View File
@@ -1,6 +1,5 @@
import * as React from 'react'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import { Theme, withStyles } from '@material-ui/core'
import Key from './Key'
interface State {
@@ -11,7 +10,6 @@ interface State {
class Demo extends React.Component<{ classes: any }, State> {
private timer: any
constructor(props: any) {
super(props)
this.state = { location: 'bottom', keys: [] }
@@ -45,7 +43,7 @@ class Demo extends React.Component<{ classes: any }, State> {
middle: -32,
}
const style = {
position: 'fixed' as const,
position: 'fixed' as 'fixed',
left: '5vw',
zIndex: 1000000,
margin: '30vw auto 50vw',
@@ -53,7 +51,7 @@ class Demo extends React.Component<{ classes: any }, State> {
bottom: `${positions[this.state.location]}vh`,
}
const style2 = {
textAlign: 'center' as const,
textAlign: 'center' as 'center',
fontSize: '4em',
color: 'white',
backgroundColor: 'rgba(0, 0, 0, 0.8)',
@@ -68,7 +66,9 @@ class Demo extends React.Component<{ classes: any }, State> {
if (this.state.keys.length > 0) {
keys = this.state.keys
.map(key => [<Key key={key} keyboardKey={key} />])
.reduce((prev, current) => [prev, '+' as any, current])
.reduce((prev, current) => {
return [prev, '+' as any, current]
})
}
return (
@@ -85,7 +85,7 @@ class Demo extends React.Component<{ classes: any }, State> {
const style = (theme: Theme) => ({
keysStyle: {
fontSize: '1em',
display: 'inline-block' as const,
display: 'inline-block' as 'inline-block',
transform: 'translateY(0.3em) translateX(0.8em)',
},
})
+1 -2
View File
@@ -1,12 +1,11 @@
import * as React from 'react'
import ShowText from './ShowText'
import Mouse from './Mouse'
let heapdump: any
function writeHeapdump(path?: string) {
if (!heapdump) {
// <heapdump = require('heapdump')
heapdump = require('heapdump')
}
heapdump.writeSnapshot(path || `${Date.now()}.heapsnapshot`)
+13 -15
View File
@@ -1,10 +1,10 @@
import * as React from 'react'
import SentimentDissatisfied from '@mui/icons-material/SentimentDissatisfied'
import Warning from '@mui/icons-material/Warning'
import { Theme } from '@mui/material/styles'
import { withStyles } from '@mui/styles'
import { Button, Modal, Paper, Toolbar, Typography } from '@mui/material'
import PersistentStorage from '../utils/PersistentStorage'
import SentimentDissatisfied from '@material-ui/icons/SentimentDissatisfied'
import Warning from '@material-ui/icons/Warning'
import { electronRendererTelemetry } from 'electron-telemetry'
import { Theme, withStyles } from '@material-ui/core/styles'
import { Button, Modal, Paper, Toolbar, Typography } from '@material-ui/core'
interface State {
error?: Error
@@ -12,30 +12,28 @@ interface State {
interface Props {
classes: any
children?: React.ReactNode
}
class ErrorBoundary extends React.PureComponent<Props, State> {
public static getDerivedStateFromError(error: Error) {
return { error }
}
constructor(props: Props) {
super(props)
this.state = {}
}
private restart = () => {
window.location.reload()
window.location = window.location
}
private clearStorage = () => {
PersistentStorage.clear()
window.location.reload()
window.location = window.location
}
public componentDidCatch(error: Error, errorInfo: any) {
// electronRendererTelemetry.trackError(error)
electronRendererTelemetry.trackError(error)
console.log('did catch', error)
}
@@ -46,7 +44,7 @@ class ErrorBoundary extends React.PureComponent<Props, State> {
const { classes } = this.props
return (
<Modal open disableAutoFocus>
<Modal open={true} disableAutoFocus={true}>
<Paper className={classes.root}>
<Toolbar style={{ padding: '0' }}>
<Typography className={classes.title} variant="h6" color="inherit">
@@ -102,17 +100,17 @@ const styles = (theme: Theme) => ({
title: {
color: theme.palette.text.primary,
margin: '0',
textAlign: 'center' as const,
textAlign: 'center' as 'center',
},
textColor: {
color: theme.palette.text.primary,
userSelect: 'all' as const,
userSelect: 'all' as 'all',
},
centered: {
textAlign: 'center' as const,
textAlign: 'center' as 'center',
},
buttonPositioning: {
textAlign: 'center' as const,
textAlign: 'center' as 'center',
marginTop: theme.spacing(2),
},
})

Some files were not shown because too many files have changed in this diff Show More