Compare commits
97
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e5da08719 | ||
|
|
1abd95f9e1 | ||
|
|
d7476f0fe8 | ||
|
|
75bb0af9fd | ||
|
|
0c11e11c27 | ||
|
|
c1924060eb | ||
|
|
28dfce246a | ||
|
|
a0624789ce | ||
|
|
a8d00056ff | ||
|
|
639b80f468 | ||
|
|
718a12c2f4 | ||
|
|
4e55d14599 | ||
|
|
0f84db57f1 | ||
|
|
959b3b70c9 | ||
|
|
2281a8729b | ||
|
|
e3c2c0cebb | ||
|
|
daecf3d539 | ||
|
|
71259bc11d | ||
|
|
d085ea3ded | ||
|
|
1273491eee | ||
|
|
6cba785e2f | ||
|
|
5152fffe82 | ||
|
|
9df8a652dc | ||
|
|
e577ee8683 | ||
|
|
0e998333e0 | ||
|
|
2840df68b2 | ||
|
|
0341fc2201 | ||
|
|
bba6eb2f94 | ||
|
|
531754c3fa | ||
|
|
cafc126d1b | ||
|
|
f24a1b7dd5 | ||
|
|
63c2df96f1 | ||
|
|
23fa302b25 | ||
|
|
f43d902297 | ||
|
|
2129708819 | ||
|
|
6e9b99e415 | ||
|
|
8aadbd25fb | ||
|
|
9f341719ef | ||
|
|
5de9272281 | ||
|
|
a6d468bd2c | ||
|
|
b0f2c72b5f | ||
|
|
e586ab9bd9 | ||
|
|
68415f805b | ||
|
|
a4bfa3117f | ||
|
|
8935783371 | ||
|
|
cf56840df9 | ||
|
|
1c5c906cbb | ||
|
|
ac12301818 | ||
|
|
84dba6d670 | ||
|
|
ff83b6c7da | ||
|
|
a328ef5ea7 | ||
|
|
7d366e6368 | ||
|
|
5ea1e38f25 | ||
|
|
d99bb75fc2 | ||
|
|
d79415cbb3 | ||
|
|
1eea4eb8d8 | ||
|
|
385f51f3ba | ||
|
|
540a7ec96b | ||
|
|
4e79d3cd81 | ||
|
|
cbfd4404c1 | ||
|
|
50820b8b40 | ||
|
|
502a3e4f2c | ||
|
|
b57b55f3e1 | ||
|
|
06c662042b | ||
|
|
461669b3fb | ||
|
|
9580a7b2df | ||
|
|
86f9ac5603 | ||
|
|
6a91ce30e3 | ||
|
|
aa3bae9020 | ||
|
|
ba46789226 | ||
|
|
4e494ce4fd | ||
|
|
8c6158e8e3 | ||
|
|
b4cfe050fa | ||
|
|
a199700878 | ||
|
|
2a46b355db | ||
|
|
a50dce2755 | ||
|
|
8dbd319bba | ||
|
|
67e230a647 | ||
|
|
ad155e269c | ||
|
|
f268d0e3eb | ||
|
|
a779ab4667 | ||
|
|
e6aacc899d | ||
|
|
4dab218b75 | ||
|
|
622924ed53 | ||
|
|
6c43b53590 | ||
|
|
e66e53c817 | ||
|
|
a71be39076 | ||
|
|
5ec9fd0bc3 | ||
|
|
80d9af42b5 | ||
|
|
dcb002304b | ||
|
|
196bf4c2e8 | ||
|
|
0e47623a6b | ||
|
|
90be5a5490 | ||
|
|
1a2e786ca8 | ||
|
|
d34ea9e943 | ||
|
|
310997c3ae | ||
|
|
7acd1bc5a1 |
No files matched your search
@@ -7,3 +7,4 @@ node_modules
|
|||||||
**/*.log
|
**/*.log
|
||||||
data
|
data
|
||||||
keys
|
keys
|
||||||
|
**/*.tsbuildinfo
|
||||||
+41
-12
@@ -1,17 +1,46 @@
|
|||||||
NODE_ENV=development
|
## Optional overrides: copy to .env and uncomment the settings you need.
|
||||||
PORT=3000
|
## Every setting has a default (shown below), so liqa runs without a .env file.
|
||||||
|
##
|
||||||
|
## Lines starting with "##" are descriptions.
|
||||||
|
## Lines starting with "# " are settings: remove the "# " to enable one.
|
||||||
|
|
||||||
# Directory (relative to cwd) containing *.json key descriptors
|
## production in the Docker image; also selects the default CORS origins
|
||||||
KEYS_DIR=keys
|
# NODE_ENV=development
|
||||||
|
# PORT=3000
|
||||||
|
|
||||||
# SQLite database path
|
## Origins allowed to call the API cross-origin (comma separated). Default: the
|
||||||
DB_PATH=data/sessions.db
|
## Vite dev server (http://localhost:5173) in development, the compose port
|
||||||
|
## (http://localhost:13000) in production
|
||||||
|
# CORS_ORIGINS=http://localhost:5173,http://127.0.0.1:5173
|
||||||
|
|
||||||
# Playwright executable (set in Docker; leave empty to use system default)
|
## SQLite database path
|
||||||
|
# DB_PATH=data/liqa.db
|
||||||
|
|
||||||
|
## Stored scenario files and run artifacts (downloads, failure dumps, traces)
|
||||||
|
# FILES_DIR=data/files
|
||||||
|
## Days to keep run artifacts before they are deleted
|
||||||
|
# FILE_RUN_EXPIRATION_DAYS=7
|
||||||
|
## When expired files are deleted (cron expression)
|
||||||
|
# FILE_CLEANUP_CRON=0 3 * * *
|
||||||
|
|
||||||
|
## Close open sessions that have been idle for longer than this many minutes
|
||||||
|
# SESSION_IDLE_TIMEOUT_MINUTES=30
|
||||||
|
## Delete closed sessions whose updatedAt is older than this many days
|
||||||
|
# SESSION_DELETE_CLOSED_DAYS=7
|
||||||
|
|
||||||
|
## Playwright trace recording for scenario runs: on | retain-on-failure | off
|
||||||
|
## (traces often reach ~10 MB per run; can be overridden per run in the run modal)
|
||||||
|
# PLAYWRIGHT_TRACE_MODE=off
|
||||||
|
|
||||||
|
## Run log data blocks whose pretty-printed JSON exceeds either limit start
|
||||||
|
## collapsed in the UI (bytes, lines); served to the client via /manifest.json
|
||||||
|
# RUN_LOG_DATA_COLLAPSE_BYTES=256
|
||||||
|
# RUN_LOG_DATA_COLLAPSE_LINES=5
|
||||||
|
|
||||||
|
## Chromium binary to use instead of Playwright's own (not needed in Docker,
|
||||||
|
## which ships Playwright's chromium-headless-shell)
|
||||||
# PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium
|
# PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH=/usr/bin/chromium
|
||||||
|
|
||||||
# Session lifecycle
|
## Directory with the built client to serve at / (the Docker image sets it to
|
||||||
# Close open sessions that have been idle for longer than this many minutes
|
## "client"; leave unset to not serve the UI, e.g. when using the Vite dev server)
|
||||||
SESSION_IDLE_TIMEOUT_MINUTES=30
|
# CLIENT_DIR=client
|
||||||
# Delete closed sessions whose updatedAt is older than this many days
|
|
||||||
SESSION_DELETE_CLOSED_DAYS=7
|
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
# Code quality checks on master and pull requests. The server and client jobs
|
||||||
|
# only run when their directory (or shared root files) changed. On a release
|
||||||
|
# tag push (vX.Y.Z), runs both jobs unconditionally and then builds the Docker
|
||||||
|
# image and pushes it to this Gitea instance's container registry, tagged with
|
||||||
|
# the version and `latest`. The tag must match the root package.json version.
|
||||||
|
#
|
||||||
|
# Needs a repository (or owner) secret REGISTRY_TOKEN: a Gitea access token
|
||||||
|
# with package write access for the repository owner. The registry host is
|
||||||
|
# set explicitly below rather than taken from the server URL, which is the
|
||||||
|
# address the runner was registered with and may be internal-only.
|
||||||
|
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [master]
|
||||||
|
tags: ['v[0-9]+.[0-9]+.[0-9]+']
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: git.hq.ars9.space
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
# Not needed on tag pushes: server and client always run there
|
||||||
|
changes:
|
||||||
|
if: ${{ !startsWith(github.ref, 'refs/tags/') }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
server: ${{ steps.filter.outputs.server }}
|
||||||
|
client: ${{ steps.filter.outputs.client }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: dorny/paths-filter@v3
|
||||||
|
id: filter
|
||||||
|
with:
|
||||||
|
filters: |
|
||||||
|
server:
|
||||||
|
- 'server/**'
|
||||||
|
- 'package.json'
|
||||||
|
- 'package-lock.json'
|
||||||
|
- '.gitea/workflows/ci.yml'
|
||||||
|
client:
|
||||||
|
- 'client/**'
|
||||||
|
- 'package.json'
|
||||||
|
- 'package-lock.json'
|
||||||
|
- '.gitea/workflows/ci.yml'
|
||||||
|
|
||||||
|
server:
|
||||||
|
needs: changes
|
||||||
|
# changes is skipped on tag pushes, hence !cancelled()
|
||||||
|
if: |
|
||||||
|
!cancelled() &&
|
||||||
|
(startsWith(github.ref, 'refs/tags/') || needs.changes.outputs.server == 'true')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 24
|
||||||
|
cache: npm
|
||||||
|
- run: npm ci -w server
|
||||||
|
- name: Lint
|
||||||
|
run: npm run -w server lint -- --max-warnings=0
|
||||||
|
- name: Type-check
|
||||||
|
run: npx tsc --noEmit -p server/tsconfig.json
|
||||||
|
- name: Test
|
||||||
|
run: npm test -w server
|
||||||
|
- name: Build
|
||||||
|
run: npm run -w server build
|
||||||
|
|
||||||
|
client:
|
||||||
|
needs: changes
|
||||||
|
# changes is skipped on tag pushes, hence !cancelled()
|
||||||
|
if: |
|
||||||
|
!cancelled() &&
|
||||||
|
(startsWith(github.ref, 'refs/tags/') || needs.changes.outputs.client == 'true')
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: 24
|
||||||
|
cache: npm
|
||||||
|
- run: npm ci -w client
|
||||||
|
- name: Lint
|
||||||
|
run: npm run -w client lint -- --max-warnings=0
|
||||||
|
- name: Build
|
||||||
|
run: npm run -w client build
|
||||||
|
- name: Install headless Chromium for Storybook tests
|
||||||
|
run: npx playwright install --with-deps --only-shell chromium
|
||||||
|
- name: Storybook tests
|
||||||
|
run: npm run -w client test:storybook
|
||||||
|
|
||||||
|
image:
|
||||||
|
needs: [server, client]
|
||||||
|
if: ${{ !failure() && !cancelled() && startsWith(github.ref, 'refs/tags/') }}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Check the tag matches package.json
|
||||||
|
run: |
|
||||||
|
version=$(node -p "require('./package.json').version")
|
||||||
|
if [ "${GITHUB_REF_NAME}" != "v${version}" ]; then
|
||||||
|
echo "tag ${GITHUB_REF_NAME} does not match package.json version ${version}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo "VERSION=${version}" >> "$GITHUB_ENV"
|
||||||
|
- name: Log in to the registry
|
||||||
|
env:
|
||||||
|
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
OWNER: ${{ github.repository_owner }}
|
||||||
|
run: |
|
||||||
|
echo "IMAGE=${REGISTRY}/$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_ENV"
|
||||||
|
echo "$REGISTRY_TOKEN" | docker login "$REGISTRY" -u "$OWNER" --password-stdin
|
||||||
|
- name: Build
|
||||||
|
run: docker build --build-arg VERSION="${VERSION}" -t "${IMAGE}:${VERSION}" -t "${IMAGE}:latest" .
|
||||||
|
- name: Push
|
||||||
|
run: |
|
||||||
|
docker push "${IMAGE}:${VERSION}"
|
||||||
|
docker push "${IMAGE}:latest"
|
||||||
+10
@@ -1,5 +1,6 @@
|
|||||||
# runtime
|
# runtime
|
||||||
/data
|
/data
|
||||||
|
server/data/
|
||||||
.env
|
.env
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
@@ -12,3 +13,12 @@ server/dist
|
|||||||
client/dist
|
client/dist
|
||||||
*storybook.log
|
*storybook.log
|
||||||
storybook-static
|
storybook-static
|
||||||
|
tsconfig.tsbuildinfo
|
||||||
|
|
||||||
|
# organization
|
||||||
|
TODO.md
|
||||||
|
|
||||||
|
# IDE/editor
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
.github/
|
||||||
+412
@@ -0,0 +1,412 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## 1.24.3 - 2026-10-02
|
||||||
|
|
||||||
|
Changes since 1.24.2:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `examples/` directory with ready-to-import example resources. The first one, `examples/self-test`, is a scenario that tests the liqa instance it runs on: it creates a temporary scenario through the REST API, runs it, checks the run and its page in the UI, and cleans up. It uses an environment, a credential, snippets and assertions.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- CI builds and pushes the Docker image only when a `vX.Y.Z` release tag is pushed, not on every merge to `master`.
|
||||||
|
|
||||||
|
## 1.24.2 - 2026-10-02
|
||||||
|
|
||||||
|
Changes since 1.24.1:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Large run log data blocks start collapsed behind a "Show data (size, lines)" toggle: data whose pretty-printed JSON is over `RUN_LOG_DATA_COLLAPSE_BYTES` (default 256) bytes or `RUN_LOG_DATA_COLLAPSE_LINES` (default 5) lines. An "Expand data" / "Collapse data" button next to the Logs heading opens or closes all of them.
|
||||||
|
- "Copy logs" button on the run page: copies the currently filtered logs to the clipboard as plain text, with every data block expanded.
|
||||||
|
- `GET /manifest.json`: public client configuration served by the server - the app name and version, and the run log data limits. The UI caches it in `localStorage` and revalidates it on page load and when the tab is refocused after a while.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The sidebar footer shows the server's version (from `/manifest.json`); its tooltip suggests reloading the page when it differs from the version the UI was built with.
|
||||||
|
- Run log data blocks are aligned with the context/message column instead of the level column.
|
||||||
|
|
||||||
|
## 1.24.1 - 2026-10-02
|
||||||
|
|
||||||
|
Changes since 1.24.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `context.assert(fn, description, details?)`: optional `details` argument. On failure, the `assertion:fail` log entry stores `{ details, error }` as data (`error` is the exception message when `fn` threw), so large diagnostics such as a response body can stay out of the message. The exported e2e runtime accepts and prints it too.
|
||||||
|
- The "Step N passed" log entry carries the step's return value as data.
|
||||||
|
- File names in the run Artifacts and scenario Files tables link to the file content, opening it in a new tab (shown inline when the browser can display it).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- For assertion failures, the "Step N failed" and "Snippet X failed" log entries name only the assertion (`Assertion failed: <description>`) instead of repeating the failure details. The step run's description keeps the full message.
|
||||||
|
- Log output shows elapsed time in whole seconds (`+14s`), matching the stored timestamp resolution.
|
||||||
|
|
||||||
|
## 1.24.0 - 2026-10-01
|
||||||
|
|
||||||
|
Changes since 1.23.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Code reference in the UI: a (?) button next to the Code label on the step and snippet create/edit pages opens a modal documenting the script runtime - the globals (`context`, `expect`, `console`, and `args` in snippets) and every `context` member with examples, including pitfalls such as awaiting `getStepOutput()` and `assert()`, and `downloadFile()` not sending the browser's cookies.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- `Modal` UI component: new `size="lg"` for long, document-like content. Dialogs are now capped to the viewport height and their body scrolls, instead of overflowing the screen.
|
||||||
|
|
||||||
|
## 1.23.0 - 2026-10-01
|
||||||
|
|
||||||
|
Changes since 1.22.2:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Run log entries now carry a `context` (where the message was generated: `step:<N>`, `snippet:<alias>`, `assertion:pass`/`fail`, or `run`) and a `data` field: `context.log`/`warn`/`error` and `console.*` split their arguments so strings join into `message` while object/array arguments are kept separate as `data` (JSON), instead of being `JSON.stringify`'d into the message text.
|
||||||
|
- Added a `debug` log level (`context.debug()`, `console.debug()`), alongside `log`/`warn`/`error`.
|
||||||
|
- New `LogOutput` UI component: a terminal-style log viewer on the run detail page, color-coded by level, with an elapsed-time-since-start column, a context tag, and `data` rendered pretty-printed in a separate block below the message. The full log list is shown (no more pagination), capped to a scrollable block.
|
||||||
|
- Run log CSV/Markdown export (`GET /scenarios/:id/runs/:runId/export`) include the new `context` and `data` columns/blocks; the logs search (`?q=`) also matches `context`.
|
||||||
|
|
||||||
|
## 1.22.2 - 2026-10-01
|
||||||
|
|
||||||
|
Changes since 1.22.1:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- MIT license (`LICENSE`), declared in all `package.json` files and the README.
|
||||||
|
- The Docker image includes the license notices of everything it ships: `scripts/third-party-licenses.mjs` collects the license of every production dependency of the client and server, the Node.js license is added, and the result is served at `/licenses.txt`, linked as "Licenses" in the sidebar footer.
|
||||||
|
- OCI image labels for title, version, license and source; CI passes the version as the `VERSION` build arg.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- The Docker image keeps packages' `LICENSE.md`/`NOTICE.md` files, which the 1.22.1 slimming step deleted along with other Markdown files.
|
||||||
|
|
||||||
|
## 1.22.1 - 2026-10-01
|
||||||
|
|
||||||
|
Changes since 1.22.0:
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The Docker image is about 20% smaller (1.09 GB → 876 MB on disk, 251 MB → 220 MB compressed). Production dependencies and Chromium are installed in a separate stage that drops files nothing loads at runtime (source maps, TypeScript sources and declarations, docs, TypeORM's browser build, better-sqlite3's C sources, Playwright's ffmpeg). The runtime image is `debian:bookworm-slim` with only the `node` binary, so it no longer contains `npm`, `npx`, `yarn` or `corepack`.
|
||||||
|
|
||||||
|
## 1.22.0 - 2026-10-01
|
||||||
|
|
||||||
|
Changes since 1.21.1:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- The Export Scenario dialog lists the snippets the scenario uses (including ones used only through other snippets), all checked by default. A selected snippet is exported once per version the scenario uses: the latest for `runSnippet("alias")`, plus each version pinned with `alias@N`. `GET /scenarios/:id/export` takes the new `snippetIds` query parameter for this.
|
||||||
|
- The Export Scenario dialog shows the scenario version next to its name and id.
|
||||||
|
|
||||||
|
## 1.21.1 - 2026-10-01
|
||||||
|
|
||||||
|
Changes since 1.21.0:
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The credential page hides the credential data when it opens; a Reveal button shows it and Hide hides it again. The data is not rendered on the page until revealed.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- A `RevealableCodeBlock` UI component (a CodeBlock that starts hidden behind a Reveal/Hide button), with a Storybook story.
|
||||||
|
|
||||||
|
## 1.21.0 - 2026-10-01
|
||||||
|
|
||||||
|
Changes since 1.20.2:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- UUID badges show a small colored circle in front of the short id. Its color comes from the first 6 hex digits of the UUID, so the same id always gets the same color, and its border uses the badge text color to stay visible in both themes.
|
||||||
|
- UUID badges get lighter on hover to show they can be clicked.
|
||||||
|
- `Badge` accepts an optional `className`.
|
||||||
|
- A Storybook "Colors" story for UuidBadge with six sample ids and a button to randomize them.
|
||||||
|
|
||||||
|
## 1.20.2 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.20.1:
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Text contrast now meets WCAG AA (4.5:1) in both themes:
|
||||||
|
- the "Live" refresh label and the table sort icon use a new `--color-primary-text` token (dark lime in the light theme) instead of the light lime brand color;
|
||||||
|
- the idle refresh label is no longer dimmed with opacity;
|
||||||
|
- the light theme's danger button is a little darker, and the dark theme's danger hover is lighter so its dark text stays readable;
|
||||||
|
- syntax highlighting colors are defined per theme (`--hl-*` tokens), darker in the light theme;
|
||||||
|
- muted text is slightly darker in the light theme.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- A Storybook "Accessibility / Contrast" page that measures the contrast of the most contrast-prone components in both themes.
|
||||||
|
- Storybook accessibility checks now fail the tests on violations (`a11y.test: 'error'`). The Colors story shows each token's current value per theme and includes the syntax colors.
|
||||||
|
|
||||||
|
## 1.20.1 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.20.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Storybook stories for AutoRefreshIndicator, CodeBlock, CodeEditor, MarkdownContent, Modal, Notification, Search, Textarea, Toast and UuidBadge, with interaction tests where the component has behavior. The DescriptionList story covers all four layouts.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Updated all client and server dependencies to the latest versions within their ranges, including React 19.3, Storybook 10.6, NestJS 11.2, TypeORM 0.3.31 and Playwright 1.63 (the Docker image now ships HeadlessChrome 153).
|
||||||
|
- The Storybook tests are part of the pre-commit checks.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Code flagged by the stricter React hooks lint rules: the runs list no longer writes refs during render, and the scenario list, scenario files and sessions list no longer set state synchronously inside effects.
|
||||||
|
|
||||||
|
## 1.20.0 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.19.3:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Database migrations: the SQLite schema is now managed by TypeORM migrations (`server/src/database/migrations/`) instead of `synchronize`. The Docker container applies pending migrations before starting the server, and the server refuses to start while migrations are pending.
|
||||||
|
- `npm -w server run migration:run`, `migration:show` and `migration:generate` scripts; the workflow for schema changes is described in `docs/development.md`.
|
||||||
|
- A test that fails when an entity changes without a matching migration.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Databases created before migrations (by `synchronize`) are adopted automatically: the initial migration is recorded as applied without changing them.
|
||||||
|
- Tests now build their database from the migrations instead of `synchronize`.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Startup failures were logged but the process exited with code 0; they now exit with code 1.
|
||||||
|
|
||||||
|
## 1.19.3 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.19.2:
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The Docker image runs with `NODE_ENV=production`.
|
||||||
|
- The origins allowed to call the API cross-origin depend on `NODE_ENV`: the Vite dev server (`http://localhost:5173`, `http://127.0.0.1:5173`) in development, the compose port (`http://localhost:13000`, `http://127.0.0.1:13000`) in production. The new `CORS_ORIGINS` setting (comma separated) overrides both. A `NODE_ENV=development` in `.env` overrides the image's production mode.
|
||||||
|
- `.env` is optional: compose loads it only when it exists, and every setting in `.env.example` is commented out and shows its default.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- The unused `KEYS_DIR` setting and the `./keys` mount in `compose.yaml`.
|
||||||
|
|
||||||
|
## 1.19.2 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.19.1:
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Running a scenario from its detail page could preselect the first environment in the list instead of the scenario's default environment, depending on whether the environment list or the scenario loaded first. The default environment is now chosen when the run modal opens.
|
||||||
|
- Made the run status filter test deterministic; it could fail when the scheduler picked up the test's pending run mid-test.
|
||||||
|
|
||||||
|
## 1.19.1 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.19.0:
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Upgraded to Node.js 24: the Docker image is based on `node:24-slim`, and the root `package.json` declares `"engines": { "node": ">=24" }`.
|
||||||
|
- The server reads the app name and version (startup log, Swagger, MCP server info, `APP_NAME`/`APP_VERSION`) from the workspace root `package.json`. Previously local runs reported the server workspace's own `liqa-server` / `1.0.0`; the server workspace no longer has a version.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Tests using a local HTTP server bind to `127.0.0.1` instead of `localhost`, which could resolve to an unreachable `::1` inside Docker containers.
|
||||||
|
|
||||||
|
## 1.19.0 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.18.0:
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Breaking (deployment):** the whole application now runs from a single image and container. The server serves the built client itself (new `CLIENT_DIR` setting, set by the image) next to the API, MCP and Swagger, so the UI moved from http://localhost:13001 to **http://localhost:13000**. The root `Dockerfile` replaces `server/Dockerfile`, `client/Dockerfile` and `client/nginx.conf`, and `compose.yaml` has a single `liqa` service. When upgrading, run `docker compose up -d --build --remove-orphans` to remove the old `server` and `client` containers.
|
||||||
|
- The image uses Playwright's headless-only Chromium build (`chromium-headless-shell`, always matching the installed Playwright version) with only the libraries it needs, instead of Debian's desktop `chromium` package. Fonts are now DejaVu and Liberation (metric-compatible with Arial/Times) instead of Noto. Together with clearing the npm cache, this shrinks the image from 1.76 GB to 1.07 GB.
|
||||||
|
|
||||||
|
## 1.18.0 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.17.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added a central import: `POST /import`, an Import page in the UI, and the `import_yaml` MCP tool. It takes YAML made of `---`-separated documents, each holding one exported item or a list of items (JSON is accepted too), with any mix of environments, credentials, snippets and scenarios. All items are validated before anything is imported, and they are imported in dependency order (environments, credentials, snippets, scenarios), so a scenario can reference an environment or credential from the same file.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The Import buttons on the scenario, snippet, credential and environment list pages use the central import. When the file holds exactly one item of the page's kind, that item is opened; otherwise the Import page shows everything that was imported.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Scenario exports that included the environment or credentials were not valid YAML (all entities were written into one document). Each entity is now a separate `---` document.
|
||||||
|
|
||||||
|
## 1.17.0 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.16.1:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Files can be deleted from a run: a delete button (with confirmation) in the Files section of the run detail page, `DELETE /scenarios/:id/runs/:runId/files/:fileId`, and the `delete_run_file` MCP tool. The stored file is removed once no scenario or run references it.
|
||||||
|
|
||||||
|
## 1.16.1 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.16.0:
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Playwright traces are now off by default (`PLAYWRIGHT_TRACE_MODE` defaults to `off`), since a trace often reaches ~10 MB per run. Traces can still be enabled per run in the run modal, via `traceMode` in `POST /scenarios/:id/run`, or for all runs by setting `PLAYWRIGHT_TRACE_MODE`.
|
||||||
|
|
||||||
|
## 1.16.0 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.15.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Scenarios and snippets are now versioned, starting at version 1. A scenario's version goes up when its name, description, default environment, timeout or steps change; a snippet's when its alias, title, description or code changes. Saving without changes does not create a new version. Credential assignments and scenario files are not versioned.
|
||||||
|
- Each run records the scenario version it runs. The run modal has a version picker (latest by default), `POST /scenarios/:id/run` and the `run_scenario` MCP tool accept an optional `version`, and "Repeat run" reuses the run's version.
|
||||||
|
- `context.runSnippet("alias@N")` pins version N of a snippet; `runSnippet("alias")` keeps using the latest. The scenario page's "Used Snippets" section shows which snippets are pinned.
|
||||||
|
- Version numbers are shown on the scenario, snippet and run pages and in the scenario and run lists.
|
||||||
|
- Added `GET /scenarios/:id/versions[/:version]` and `GET /snippets/:id/versions[/:version]`, and the `list_scenario_versions`, `get_scenario_version`, `list_snippet_versions` and `get_snippet_version` MCP tools.
|
||||||
|
- Scenario and snippet exports accept `?version=N` (the `export_scenario` MCP tool takes `version`).
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Breaking:** scenario and snippet exports now include `version`, and imports require it. An import restores that exact version by id + version: an existing version is left untouched, and a new one is stored under its number and becomes the latest when it is higher than the current latest. Export files from earlier releases need a `version` field added before they can be imported.
|
||||||
|
- Scenario exports now include scenario and step timeouts.
|
||||||
|
- Runs keep their own copy of the steps they were created with. Editing or deleting a step no longer changes past runs, and deleting a step no longer deletes its results from past runs. Existing run steps are backfilled from the current steps on startup.
|
||||||
|
|
||||||
|
## 1.15.0 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.14.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Scenario runs now record a Playwright trace (screenshots and DOM snapshots) and upload it to the run's files as `trace.zip` when the run finishes. Open it with `npx playwright show-trace trace.zip` or at https://trace.playwright.dev.
|
||||||
|
- Added the `PLAYWRIGHT_TRACE_MODE` setting (`on` (default), `retain-on-failure`, or `off`) that controls which traces are kept.
|
||||||
|
- Added a "Playwright trace" option to the run modal to override the trace mode for a single run. It defaults to the server's `PLAYWRIGHT_TRACE_MODE`, served by the new `GET /scenarios/run-defaults` endpoint.
|
||||||
|
- `POST /scenarios/:id/run` and the `run_scenario` MCP tool accept an optional `traceMode`. The trace mode is stored on the run, shown on the run detail page, and reused by "Repeat run".
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The run modals on the scenario list and scenario detail pages now share one component.
|
||||||
|
- `server/data/` is now git-ignored.
|
||||||
|
|
||||||
|
## 1.14.0 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.13.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added a "Repeat run" button on the scenario run detail page that starts a new run of the same scenario with the same environment and "save session" setting, then navigates to it. The button is disabled when the run's environment has since been deleted.
|
||||||
|
|
||||||
|
## 1.13.0 - 2026-09-30
|
||||||
|
|
||||||
|
Changes since 1.12.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added credential CRUD tools to the MCP server: `list_credentials`, `get_credential`, `create_credential`, `update_credential`, and `delete_credential`. Combined with the existing `add_scenario_credential` tool, credentials can now be created and attached to scenarios entirely via MCP.
|
||||||
|
|
||||||
|
## 1.12.0 - 2026-09-16
|
||||||
|
|
||||||
|
Changes since 1.11.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- When a scenario or snippet step fails, a full-page screenshot and the current page HTML are captured and uploaded as run artifacts, so failures can be diagnosed from the run's file list.
|
||||||
|
|
||||||
|
## 1.11.0 - 2026-09-15
|
||||||
|
|
||||||
|
Changes since 1.10.1:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added export of a scenario as a standalone, plug-and-play Playwright e2e test project (zip archive with `package.json`, `playwright.config.ts`, `test.spec.ts`, `README.md`, `.env`, `credentials.json`, `snippets/*.js`, and any attached scenario files) that runs entirely independently of the liqa backend. Available as a "Export e2e test" button on the scenario detail page, `GET /scenarios/:id/export-e2e`, and the `export_e2e_test` MCP tool.
|
||||||
|
- The exported test only bundles the credentials, snippets, and attached files actually referenced (directly or transitively) by the scenario's steps.
|
||||||
|
- Added a "Used Snippets" section on the scenario detail page listing the snippets referenced by the scenario's steps, linking to each snippet's detail page. Backed by `GET /scenarios/:id/used-snippets`.
|
||||||
|
|
||||||
|
## 1.10.1 - 2026-09-15
|
||||||
|
|
||||||
|
Changes since 1.10.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `context.runSnippet()` now logs "Snippet started"/"finished"/"failed" entries, matching the automatic step start/pass/fail logging.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Reworked the Markdown log export format: each log entry is now its own `## [level] timestamp` section with the message as its body, instead of a single large table.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Run logs could persist out of call order (e.g. a snippet's "started" log appearing after its "finished" log) because writes were fire-and-forget and raced against each other. Log entries now carry a per-run sequence number assigned in call order, and queries/exports sort by it.
|
||||||
|
|
||||||
|
## 1.10.0 - 2026-09-15
|
||||||
|
|
||||||
|
Changes since 1.9.1:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added a "Download logs" button on the scenario run detail page: opens a modal to choose Markdown (default) or CSV, then downloads the run's logs in that format.
|
||||||
|
- Added `GET /scenarios/:id/run/:runId/logs/export?format=csv|md` backend endpoint to export a run's logs.
|
||||||
|
|
||||||
|
## 1.9.1 - 2026-09-15
|
||||||
|
|
||||||
|
Changes since 1.9.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Scenario run logs now include an automatic entry when a step starts and when it finishes (pass or fail), so step boundaries are visible in run logs even for steps that don't call `context.log`/`context.assert` themselves.
|
||||||
|
|
||||||
|
## 1.9.0 - 2026-09-15
|
||||||
|
|
||||||
|
Changes since 1.8.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added `context.assert(fn, description)` for scenario/snippet script steps: runs the given function, requires it to return `true`, logs the outcome (`log` on success, `error` on failure or exception), and throws to stop the step on failure.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Documented `context.assert` in `docs/scenario.md`.
|
||||||
|
|
||||||
|
## 1.8.0 - 2026-09-15
|
||||||
|
|
||||||
|
Changes since 1.7.1:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- `context.downloadFile()` now accepts `data:` URIs, so scenario steps can save in-script generated content (e.g. a credential JWT) as a run artifact without a network fetch.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Documented the full scenario step `context` file API (`getScenarioFiles`, `downloadFile`) in `docs/scenario.md`.
|
||||||
|
|
||||||
|
## 1.7.1 - 2026-04-21
|
||||||
|
|
||||||
|
Changes since 1.7.0:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added MCP tools to upload, list, and fetch scenario files using base64 content payloads.
|
||||||
|
- Added MCP tools to list run artifacts and fetch run artifact content with metadata.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Documented MCP binary content handling for scenario files and run artifacts.
|
||||||
|
|
||||||
|
## 1.7.0 - 2026-04-21
|
||||||
|
|
||||||
|
Changes since 1.6.1:
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added scenario file storage and run artifact support on the backend.
|
||||||
|
- Added file management UI for scenarios and run details, including artifact lists.
|
||||||
|
- Added snippet CRUD tools to the MCP server.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Added dynamic page titles based on the active client content.
|
||||||
|
- Extended the scenarios list to show the latest run status and timestamp.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Exposed file expiry metadata in scenario and run file responses.
|
||||||
|
- Disabled expired download actions in the UI while keeping the action visible.
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
# liqa
|
||||||
|
|
||||||
|
liqa is a browser automation and QA service for web applications. It stores **scenarios** (ordered Playwright steps), **snippets** (reusable code run via `context.runSnippet`), **environments**, **credentials** and **sessions**, and runs scenarios in headless Chromium. Scenarios and snippets are versioned; each run records the scenario version it executed.
|
||||||
|
|
||||||
|
It is an npm workspace with two packages:
|
||||||
|
|
||||||
|
- `server/` - NestJS API + scheduler + MCP server, SQLite via TypeORM; the schema is managed by migrations in `server/src/database/migrations/` (see "Database migrations" in `docs/development.md`). Any entity change needs a generated migration - `test/migrations.spec.ts` fails otherwise. REST API under `/api/v1`, Swagger UI at `/docs`, MCP at `/mcp`, health at `/health`, public client configuration at `/manifest.json`.
|
||||||
|
- `client/` - React 19 + Vite SPA (i18n strings in `client/src/i18n/locales/en.json`).
|
||||||
|
|
||||||
|
## Docs
|
||||||
|
|
||||||
|
- [README.md](README.md) - overview
|
||||||
|
- [docs/architecture.md](docs/architecture.md) - services and modules
|
||||||
|
- [docs/development.md](docs/development.md) - local setup, running, testing, Docker
|
||||||
|
- [docs/scenario.md](docs/scenario.md) - scenario execution, script `context` API, versioning, export/import, Playwright traces
|
||||||
|
- [docs/mcp.md](docs/mcp.md) - MCP tool reference
|
||||||
|
- [examples/](examples/README.md) - ready-to-import example resources (YAML); `server/test/examples.spec.ts` imports each file, so keep them in sync with the import format
|
||||||
|
- [CHANGELOG.md](CHANGELOG.md) - release notes per version
|
||||||
|
- [Dockerfile](Dockerfile) - single image: builds client and server, runtime serves both
|
||||||
|
- [.env.example](.env.example) - all configuration variables (validated in `server/src/config/app.config.ts`)
|
||||||
|
|
||||||
|
## Default deployment (docker compose)
|
||||||
|
|
||||||
|
`compose.yaml` at the repo root runs a single `liqa` container, built from the root `Dockerfile`, at http://localhost:13000. The server serves everything: the UI at `/` (the built client, via `CLIENT_DIR`), the REST API at `/api/v1`, MCP at `/mcp`, Swagger at `/docs`. It reads `.env` if present (optional - every setting has a default) and mounts `./data` (SQLite DB `data/liqa.db` + stored files).
|
||||||
|
|
||||||
|
Rebuild and restart: `docker compose up -d --build`. Check with `docker compose ps`, `curl localhost:13000/health` and `docker compose logs liqa`.
|
||||||
|
|
||||||
|
The live database is `data/liqa.db`. The container applies pending migrations before starting the server, so back it up before deploying a release with new migrations.
|
||||||
|
|
||||||
|
## Branching
|
||||||
|
|
||||||
|
Never commit directly to `master` when implementing a feature, chore or bug fix: create a separate branch for the work first, forked from `master`. These commits don't change the version or `CHANGELOG.md`; the branch is merged back to `master` through a pull request. Only release commits (see "Releasing a new version") are made on `master`.
|
||||||
|
|
||||||
|
When committing on a work branch, also update the docs affected by the change (`docs/*.md`, `README.md`, `.env.example`, MCP tool descriptions) in the same branch.
|
||||||
|
|
||||||
|
## Code quality
|
||||||
|
|
||||||
|
Before committing, run and pass all of these (and report the results):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# server
|
||||||
|
cd server && npm run lint && npx tsc --noEmit -p tsconfig.json && npm test && npm run build
|
||||||
|
# client
|
||||||
|
cd client && npm run lint && npm run build && npm run test:storybook
|
||||||
|
```
|
||||||
|
|
||||||
|
- Lint must stay clean in both packages (no errors, no warnings).
|
||||||
|
- `test:storybook` runs every story in `client/.storybook/stories/` in headless Chromium (needs `npx playwright install --only-shell chromium` once, and again after Playwright updates). Add or update a story when adding or changing a `client/src/ui/` component.
|
||||||
|
- Don't run prettier over whole existing files; several aren't prettier-clean and it produces unrelated diffs. Format only new files or the lines you changed.
|
||||||
|
- Server tests use an in-memory DB, a Playwright mock (`server/test/__mocks__/playwright.ts`), and a temporary files directory per test app (see `server/test/app.harness.ts`).
|
||||||
|
- Import Node.js built-in modules with the `node:` prefix (`node:fs`, `node:path`, `node:crypto`, ...).
|
||||||
|
|
||||||
|
## Releasing a new version
|
||||||
|
|
||||||
|
A release is cut on `master` after one or more work branches have been merged (their pull request checks are already green). CI builds and pushes the Docker image only when a `vX.Y.Z` tag is pushed, not on merges.
|
||||||
|
|
||||||
|
When asked to release:
|
||||||
|
|
||||||
|
1. Make sure you're on an up-to-date, clean `master` (`git switch master && git pull`), and collect the changes since the last release: `git log --oneline "$(git describe --tags --abbrev=0)"..HEAD`.
|
||||||
|
2. **Ask which version to bump** - major, minor or patch - and propose a sensible default based on those changes: patch for fixes and small behavior/default tweaks, minor for new features, major for breaking changes (e.g. changed API or export/import formats that old clients or files can't use).
|
||||||
|
3. Bump `version` in the root `package.json` and in both places at the top of `package-lock.json` (the root entry and `packages[""]`). `server/package.json` and `client/package.json` keep their own versions; don't bump them.
|
||||||
|
4. Add a `## <version> - <YYYY-MM-DD>` entry at the top of `CHANGELOG.md` ("Changes since <previous version>:", then `### Added` / `### Changed` / `### Fixed`). Mark breaking changes with **Breaking:**.
|
||||||
|
5. Commit only these release changes on `master`. Build the commit message with the `/git-commit` skill if it is available, following its format and rules. Otherwise use a conventional commit message (`type(scope): subject`, then a bullet list body). Either way, put the version bump in the body as a bullet (e.g. `- bump version to <version>`), not in the subject line. This overrides the skill's rule of putting versions in the subject.
|
||||||
|
6. **Tag the release commit** with an annotated tag `v<version>` whose message is that version's `CHANGELOG.md` entry, verbatim (from its `## <version>` heading up to the next version's heading). `--cleanup=whitespace` is required: the default cleanup strips lines starting with `#`, which would drop the entry's headings:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
v=<version>
|
||||||
|
awk -v v="$v" 'index($0, "## " v " ") == 1 {p = 1; print; next} p && /^## / {exit} p' CHANGELOG.md \
|
||||||
|
| git tag -a "v$v" --cleanup=whitespace -F -
|
||||||
|
```
|
||||||
|
|
||||||
|
7. **Ask the user before pushing**, then push the commit and the tag together with `git push --follow-tags` (it also pushes annotated tags). The tag push triggers the image build; it fails if the tag doesn't match the `package.json` version.
|
||||||
|
8. **Ask the user whether to rebuild and restart the docker compose containers** (`docker compose up -d --build`); don't do it without confirmation.
|
||||||
+157
@@ -0,0 +1,157 @@
|
|||||||
|
# Single image serving the whole application: the NestJS server (API, MCP,
|
||||||
|
# scheduler) also serves the built client, so one container is enough.
|
||||||
|
|
||||||
|
# ── Client build ──────────────────────────────────────────────────────────────
|
||||||
|
FROM node:24-slim AS client-build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Root lockfile + workspace manifest so npm ci can resolve the full graph
|
||||||
|
COPY package*.json ./
|
||||||
|
COPY client/package.json ./client/
|
||||||
|
RUN npm ci -w client
|
||||||
|
|
||||||
|
COPY client ./client
|
||||||
|
RUN npm run -w client build
|
||||||
|
|
||||||
|
# ── Server build ──────────────────────────────────────────────────────────────
|
||||||
|
FROM node:24-slim AS server-build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
COPY server/package.json ./server/
|
||||||
|
RUN npm ci -w server
|
||||||
|
|
||||||
|
COPY server/nest-cli.json ./server/
|
||||||
|
COPY server/tsconfig*.json ./server/
|
||||||
|
COPY server/src ./server/src
|
||||||
|
RUN npm run -w server build
|
||||||
|
|
||||||
|
# ── Runtime dependencies ──────────────────────────────────────────────────────
|
||||||
|
FROM node:24-slim AS runtime-deps
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
COPY server/package.json ./server/
|
||||||
|
|
||||||
|
# Production dependencies and Playwright's headless-only Chromium build,
|
||||||
|
# matching the installed Playwright version. All browser launches are
|
||||||
|
# headless, so the full desktop Chromium (GTK, Mesa/LLVM, icon themes) isn't
|
||||||
|
# needed, and neither is ffmpeg (only used for video recording).
|
||||||
|
#
|
||||||
|
# Then drop what nothing loads at runtime: source maps, TypeScript sources and
|
||||||
|
# declarations, docs (but not license files), TypeORM's browser build and
|
||||||
|
# better-sqlite3's C sources (the addon is already compiled).
|
||||||
|
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
||||||
|
RUN npm ci --omit=dev -w server \
|
||||||
|
&& npx playwright install --only-shell chromium \
|
||||||
|
&& rm -rf /ms-playwright/ffmpeg-* \
|
||||||
|
&& find node_modules -type f \( \
|
||||||
|
-name '*.map' -o -name '*.ts' -o -name '*.mts' -o -name '*.cts' \
|
||||||
|
-o \( \( -iname '*.md' -o -iname '*.markdown' \) \
|
||||||
|
! -iname 'licen[cs]e*' ! -iname 'notice*' ! -iname 'copying*' \) \
|
||||||
|
\) -delete \
|
||||||
|
&& rm -rf node_modules/typeorm/browser \
|
||||||
|
node_modules/better-sqlite3/deps \
|
||||||
|
node_modules/better-sqlite3/src
|
||||||
|
|
||||||
|
# ── License notices ───────────────────────────────────────────────────────────
|
||||||
|
# One file with the project's LICENSE and the license of everything the image
|
||||||
|
# ships: the production dependencies of both workspaces (the client's are
|
||||||
|
# bundled into its build, so their license files aren't in the image
|
||||||
|
# otherwise) and the Node.js binary, whose LICENSE the node image doesn't
|
||||||
|
# include.
|
||||||
|
FROM node:24-slim AS licenses
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json LICENSE ./
|
||||||
|
COPY client/package.json ./client/
|
||||||
|
COPY server/package.json ./server/
|
||||||
|
COPY scripts/third-party-licenses.mjs ./scripts/
|
||||||
|
RUN npm ci --omit=dev --ignore-scripts \
|
||||||
|
&& node scripts/third-party-licenses.mjs > licenses.txt \
|
||||||
|
&& node -e ' \
|
||||||
|
const url = `https://raw.githubusercontent.com/nodejs/node/v${process.versions.node}/LICENSE`; \
|
||||||
|
fetch(url).then(async (r) => { \
|
||||||
|
if (!r.ok) throw new Error(`${url}: ${r.status}`); \
|
||||||
|
const rule = "-".repeat(79); \
|
||||||
|
process.stdout.write(`\n${rule}\n\nnode@${process.versions.node}\nLicense: MIT\n\n${(await r.text()).trim()}\n`); \
|
||||||
|
}).catch((e) => { console.error(e.message); process.exit(1); });' >> licenses.txt
|
||||||
|
|
||||||
|
# ── Runtime ───────────────────────────────────────────────────────────────────
|
||||||
|
# Plain Debian with just the node binary: npm, yarn, corepack and the C
|
||||||
|
# headers that come with the node image aren't needed to run the app.
|
||||||
|
FROM debian:bookworm-slim AS runtime
|
||||||
|
|
||||||
|
# Set by CI from the root package.json version
|
||||||
|
ARG VERSION=dev
|
||||||
|
LABEL org.opencontainers.image.title="liqa" \
|
||||||
|
org.opencontainers.image.version="${VERSION}" \
|
||||||
|
org.opencontainers.image.licenses="MIT" \
|
||||||
|
org.opencontainers.image.source="https://git.hq.ars9.space/ars9/liqa"
|
||||||
|
|
||||||
|
# Runtime only: in the build stages it would make npm ci skip devDependencies
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
|
||||||
|
# Shared libraries chrome-headless-shell links against (from `ldd`), plus
|
||||||
|
# fontconfig and basic fonts for text rendering. Playwright's `--with-deps`
|
||||||
|
# would also pull in xvfb (with Mesa/LLVM) and extra font packages, which
|
||||||
|
# headless-only use doesn't need.
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
ca-certificates \
|
||||||
|
fontconfig \
|
||||||
|
fonts-dejavu-core \
|
||||||
|
fonts-liberation \
|
||||||
|
libasound2 \
|
||||||
|
libatk-bridge2.0-0 \
|
||||||
|
libatk1.0-0 \
|
||||||
|
libatspi2.0-0 \
|
||||||
|
libdbus-1-3 \
|
||||||
|
libexpat1 \
|
||||||
|
libgbm1 \
|
||||||
|
libglib2.0-0 \
|
||||||
|
libnspr4 \
|
||||||
|
libnss3 \
|
||||||
|
libx11-6 \
|
||||||
|
libxcb1 \
|
||||||
|
libxcomposite1 \
|
||||||
|
libxdamage1 \
|
||||||
|
libxext6 \
|
||||||
|
libxfixes3 \
|
||||||
|
libxkbcommon0 \
|
||||||
|
libxrandr2 \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
COPY --from=runtime-deps /usr/local/bin/node /usr/local/bin/node
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY package*.json ./
|
||||||
|
COPY server/package.json ./server/
|
||||||
|
|
||||||
|
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
||||||
|
COPY --from=runtime-deps /ms-playwright /ms-playwright
|
||||||
|
COPY --from=runtime-deps /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
COPY --from=server-build /app/server/dist ./dist
|
||||||
|
COPY --from=client-build /app/client/dist ./client
|
||||||
|
|
||||||
|
# The project's license, and every shipped component's license notices (also
|
||||||
|
# served by the app at /licenses.txt)
|
||||||
|
COPY LICENSE ./
|
||||||
|
COPY --from=licenses /app/licenses.txt ./client/licenses.txt
|
||||||
|
|
||||||
|
# Serve the built client at / (see server/src/common/client-static.ts)
|
||||||
|
ENV CLIENT_DIR=client
|
||||||
|
|
||||||
|
# Runtime directory (SQLite DB and stored files, mounted as a volume)
|
||||||
|
RUN mkdir -p data
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
# Apply pending database migrations, then start the server (which refuses to
|
||||||
|
# start while migrations are pending)
|
||||||
|
CMD ["sh", "-c", "node dist/database/migrate && exec node dist/main"]
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2026 Andrii Arsenin
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -1,46 +1,63 @@
|
|||||||
# liquio-qa-bot
|
# liqa
|
||||||
|
|
||||||
A headless QA automation service for Liquio environments. Exposes an **MCP (Model Context Protocol)** server that lets AI agents define, run, and monitor multi-step browser test scenarios using [Playwright](https://playwright.dev/).
|
A browser automation and QA service for web applications. It stores multi-step browser scenarios, runs them with [Playwright](https://playwright.dev/) in headless Chromium, and keeps their results, logs and artifacts. Scenarios are managed from a web UI, a REST API, or an **MCP (Model Context Protocol)** server that lets AI agents define, run and debug them.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Quick start
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker compose up -d --build
|
||||||
|
```
|
||||||
|
|
||||||
|
No configuration is needed: every setting has a default. To override one, copy `.env.example` to `.env` and uncomment it.
|
||||||
|
|
||||||
|
Everything is served from one container at **http://localhost:13000**: the UI at `/`, the REST API at `/api/v1`, MCP at `/mcp`, Swagger at `/docs`. Data is kept in `./data/`.
|
||||||
|
|
||||||
|
To see it work, import and run the [self-test example](examples/self-test/): a scenario that tests liqa itself using an environment, a credential and snippets.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
To install liqa from the published image, without cloning this repo:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -fsSL https://git.hq.ars9.space/ars9/liqa/raw/branch/master/scripts/install.sh | bash
|
||||||
|
```
|
||||||
|
|
||||||
|
This asks for an install directory, a port and a version (latest by default), then writes a `compose.yaml` and a `data/` directory there. Start it with `docker compose up -d` in that directory.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
The bot manages four core concepts:
|
|
||||||
|
|
||||||
| Concept | Description |
|
| Concept | Description |
|
||||||
|---|---|
|
|---|---|
|
||||||
| **Environment** | A named set of URLs for a deployment target (e.g. `liquio-diia-stg`) |
|
| **Scenario** | An ordered list of steps (async Playwright JS) that run in sequence in one browser. Versioned: every content change creates a new version |
|
||||||
| **Key** | A JSON descriptor in `keys/` that points to an EDS key file + password |
|
| **Run** | One execution of a scenario version in an environment, with per-step status and output, logs, and run files (downloads, failure screenshots, Playwright traces) |
|
||||||
| **Session** | Saved browser state (cookies + localStorage) produced by a login |
|
| **Snippet** | Reusable, versioned code called from steps with `context.runSnippet("alias")` (or `"alias@N"` for a specific version) |
|
||||||
| **Scenario** | An ordered list of steps that run in sequence against a shared browser instance |
|
| **Environment** | A named set of key/value settings for a deployment target (URLs etc.), read with `context.getEnv(key)` |
|
||||||
|
| **Credential** | Secret data (e.g. a key file and password), assigned to scenarios under an alias and read with `context.getCredential(alias)` |
|
||||||
|
| **Session** | Saved browser state (cookies + localStorage), e.g. kept from a run with "save session" |
|
||||||
|
|
||||||
|
Scenarios, snippets, environments and credentials can be exported as YAML and imported back (one file may hold several of them).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Architecture
|
## Documentation
|
||||||
|
|
||||||
See [docs/architecture.md](docs/architecture.md).
|
- [docs/architecture.md](docs/architecture.md) - components, data model, client
|
||||||
|
- [docs/scenario.md](docs/scenario.md) - runs, the script `context` API, versioning, import/export, Playwright traces
|
||||||
|
- [docs/mcp.md](docs/mcp.md) - MCP tool reference
|
||||||
|
- [docs/development.md](docs/development.md) - setup, configuration, running, testing, linting, Docker
|
||||||
|
- [examples/](examples/) - ready-to-import example scenarios
|
||||||
|
- [CHANGELOG.md](CHANGELOG.md) - release notes
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Key descriptors
|
## License
|
||||||
|
|
||||||
See [docs/key-descriptors.md](docs/key-descriptors.md).
|
[MIT](LICENSE) © 2026 Andrii Arsenin
|
||||||
|
|
||||||
---
|
Third-party packages keep their own licenses. The Docker image includes all their notices, and the app serves them at `/licenses.txt` (linked as "Licenses" in the sidebar footer). See [docs/development.md](docs/development.md#licenses).
|
||||||
|
|
||||||
## MCP tools
|
|
||||||
|
|
||||||
See [docs/mcp.md](docs/mcp.md).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Scenario execution
|
|
||||||
|
|
||||||
See [docs/scenario.md](docs/scenario.md).
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
See [docs/development.md](docs/development.md) for setup, running, testing, linting, and Docker instructions.
|
|
||||||
@@ -12,7 +12,7 @@ function getAbsolutePath(value: string) {
|
|||||||
return dirname(fileURLToPath(import.meta.resolve(`${value}/package.json`)));
|
return dirname(fileURLToPath(import.meta.resolve(`${value}/package.json`)));
|
||||||
}
|
}
|
||||||
const config: StorybookConfig = {
|
const config: StorybookConfig = {
|
||||||
stories: ['./stories/**/*.mdx', './stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
|
stories: ['./stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
|
||||||
addons: [
|
addons: [
|
||||||
getAbsolutePath('@storybook/addon-vitest'),
|
getAbsolutePath('@storybook/addon-vitest'),
|
||||||
getAbsolutePath('@storybook/addon-a11y'),
|
getAbsolutePath('@storybook/addon-a11y'),
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ const preview: Preview = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
a11y: {
|
a11y: {
|
||||||
test: 'todo',
|
// Accessibility violations (e.g. color contrast) fail the story's test
|
||||||
|
test: 'error',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { expect, fn, userEvent, within } from 'storybook/test';
|
||||||
|
import { AutoRefreshIndicator } from '../../src/ui/AutoRefreshIndicator/AutoRefreshIndicator';
|
||||||
|
|
||||||
|
const meta: Meta<typeof AutoRefreshIndicator> = {
|
||||||
|
title: 'UI/AutoRefreshIndicator',
|
||||||
|
component: AutoRefreshIndicator,
|
||||||
|
parameters: { layout: 'centered' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
args: { onClick: fn() },
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof AutoRefreshIndicator>;
|
||||||
|
|
||||||
|
export const Active: Story = { args: { active: true, pulseKey: 1 } };
|
||||||
|
export const Idle: Story = { args: { active: false } };
|
||||||
|
export const Errored: Story = { args: { active: false, error: true } };
|
||||||
|
|
||||||
|
export const ClickToRefresh: Story = {
|
||||||
|
args: { active: false },
|
||||||
|
play: async ({ args, canvasElement }) => {
|
||||||
|
await userEvent.click(within(canvasElement).getByRole('button'));
|
||||||
|
await expect(args.onClick).toHaveBeenCalled();
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { expect } from 'storybook/test';
|
||||||
|
import { CodeBlock } from '../../src/ui/CodeBlock/CodeBlock';
|
||||||
|
|
||||||
|
const meta: Meta<typeof CodeBlock> = {
|
||||||
|
title: 'UI/CodeBlock',
|
||||||
|
component: CodeBlock,
|
||||||
|
parameters: { layout: 'padded' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof CodeBlock>;
|
||||||
|
|
||||||
|
export const JavaScript: Story = {
|
||||||
|
args: {
|
||||||
|
language: 'javascript',
|
||||||
|
code: "const url = context.getEnv('BASE_URL');\nawait context.page.goto(url);\nreturn await context.page.title();",
|
||||||
|
},
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
// Highlighting splits the code into many spans: check the whole text and
|
||||||
|
// that highlighting actually happened
|
||||||
|
const code = canvasElement.querySelector('code');
|
||||||
|
await expect(code).toHaveTextContent('await context.page.goto(url);');
|
||||||
|
await expect(code?.querySelector('.hljs-keyword')).not.toBeNull();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Json: Story = {
|
||||||
|
args: {
|
||||||
|
language: 'json',
|
||||||
|
code: JSON.stringify({ status: 'pass', output: { title: 'Dashboard' } }, null, 2),
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { CodeEditor, type CodeEditorProps } from '../../src/ui/CodeEditor/CodeEditor';
|
||||||
|
|
||||||
|
// Monaco is loaded from a CDN at runtime, so these stories only check that the
|
||||||
|
// editor mounts; they have no interaction tests.
|
||||||
|
function ControlledEditor(
|
||||||
|
props: Omit<CodeEditorProps, 'value' | 'onChange'> & { initial: string },
|
||||||
|
) {
|
||||||
|
const { initial, ...rest } = props;
|
||||||
|
const [value, setValue] = useState(initial);
|
||||||
|
return <CodeEditor {...rest} value={value} onChange={setValue} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const meta: Meta<typeof ControlledEditor> = {
|
||||||
|
title: 'UI/CodeEditor',
|
||||||
|
component: ControlledEditor,
|
||||||
|
parameters: { layout: 'padded' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof ControlledEditor>;
|
||||||
|
|
||||||
|
export const JavaScript: Story = {
|
||||||
|
args: {
|
||||||
|
language: 'javascript',
|
||||||
|
rows: 8,
|
||||||
|
initial:
|
||||||
|
"await context.page.goto(context.getEnv('BASE_URL'));\nreturn await context.page.title();",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WithError: Story = {
|
||||||
|
args: { language: 'javascript', rows: 4, error: true, initial: 'await context.page.goto(' },
|
||||||
|
};
|
||||||
@@ -1,10 +1,16 @@
|
|||||||
import React from 'react';
|
import React, { useLayoutEffect, useRef, useState } from 'react';
|
||||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
|
||||||
const palette = [
|
const palette = [
|
||||||
{ name: 'Atlantis', token: '--color-primary', hex: '#9DD341', role: 'Primary / Action' },
|
{ name: 'Atlantis', token: '--color-primary', hex: '#9DD341', role: 'Primary / Action' },
|
||||||
|
{
|
||||||
|
name: 'Atlantis text',
|
||||||
|
token: '--color-primary-text',
|
||||||
|
hex: '#496904',
|
||||||
|
role: 'Primary as text / icon',
|
||||||
|
},
|
||||||
{ name: 'Outer Space', token: '--color-text', hex: '#2D3339', role: 'Text / Surface' },
|
{ name: 'Outer Space', token: '--color-text', hex: '#2D3339', role: 'Text / Surface' },
|
||||||
{ name: 'Kimberly', token: '--color-text-muted', hex: '#6650C0', role: 'Muted text / Info' },
|
{ name: 'Kimberly', token: '--color-text-muted', hex: '#634DBD', role: 'Muted text / Info' },
|
||||||
{ name: 'Powder Ash', token: '--color-border', hex: '#AFBFB9', role: 'Border / Neutral' },
|
{ name: 'Powder Ash', token: '--color-border', hex: '#AFBFB9', role: 'Border / Neutral' },
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -23,12 +29,23 @@ const semanticColors = [
|
|||||||
{ name: 'Running fg', token: '--color-running-fg', hex: '#6B4A00' },
|
{ name: 'Running fg', token: '--color-running-fg', hex: '#6B4A00' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const syntaxColors = [
|
||||||
|
{ name: 'Comment', token: '--hl-comment', hex: '#4F6557' },
|
||||||
|
{ name: 'Keyword', token: '--hl-keyword', hex: '#764E99' },
|
||||||
|
{ name: 'String / title', token: '--hl-string', hex: '#4F6821' },
|
||||||
|
{ name: 'Number', token: '--hl-number', hex: '#895403' },
|
||||||
|
{ name: 'Function', token: '--hl-function', hex: '#056980' },
|
||||||
|
{ name: 'Variable / params', token: '--hl-variable', hex: '#815354' },
|
||||||
|
{ name: 'Property', token: '--hl-property', hex: '#1D6971' },
|
||||||
|
{ name: 'Meta', token: '--hl-meta', hex: '#615B7E' },
|
||||||
|
];
|
||||||
|
|
||||||
const surfaceColors = [
|
const surfaceColors = [
|
||||||
{ name: 'Background', token: '--color-bg', hex: '#E6EDEA' },
|
{ name: 'Background', token: '--color-bg', hex: '#E6EDEA' },
|
||||||
{ name: 'Background subtle', token: '--color-bg-subtle', hex: '#D8E2DE' },
|
{ name: 'Background subtle', token: '--color-bg-subtle', hex: '#D8E2DE' },
|
||||||
{ name: 'Secondary', token: '--color-secondary', hex: '#EDF1EF' },
|
{ name: 'Secondary', token: '--color-secondary', hex: '#EDF1EF' },
|
||||||
{ name: 'Secondary hover', token: '--color-secondary-hover', hex: '#DFE6E3' },
|
{ name: 'Secondary hover', token: '--color-secondary-hover', hex: '#DFE6E3' },
|
||||||
{ name: 'Danger', token: '--color-danger', hex: '#D94F4F' },
|
{ name: 'Danger', token: '--color-danger', hex: '#CE4546' },
|
||||||
{ name: 'Primary fg', token: '--color-primary-fg', hex: '#2D3339' },
|
{ name: 'Primary fg', token: '--color-primary-fg', hex: '#2D3339' },
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -43,8 +60,27 @@ function Swatch({
|
|||||||
hex: string;
|
hex: string;
|
||||||
role?: string;
|
role?: string;
|
||||||
}) {
|
}) {
|
||||||
|
// Show the token's current value (per theme) rather than a hard-coded copy
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
const [value, setValue] = useState(hex);
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
const read = () => {
|
||||||
|
if (!ref.current) return;
|
||||||
|
const resolved = getComputedStyle(ref.current).getPropertyValue(token).trim();
|
||||||
|
if (resolved) setValue(resolved.toUpperCase());
|
||||||
|
};
|
||||||
|
read();
|
||||||
|
// Re-read when the theme toolbar switches data-theme on <html>
|
||||||
|
const observer = new MutationObserver(read);
|
||||||
|
observer.observe(document.documentElement, {
|
||||||
|
attributes: true,
|
||||||
|
attributeFilter: ['data-theme'],
|
||||||
|
});
|
||||||
|
return () => observer.disconnect();
|
||||||
|
}, [token]);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
|
ref={ref}
|
||||||
style={{
|
style={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
flexDirection: 'column',
|
flexDirection: 'column',
|
||||||
@@ -72,7 +108,7 @@ function Swatch({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<div style={{ fontSize: 11, fontFamily: 'monospace', color: 'var(--color-text-muted)' }}>
|
<div style={{ fontSize: 11, fontFamily: 'monospace', color: 'var(--color-text-muted)' }}>
|
||||||
{hex}
|
{value}
|
||||||
</div>
|
</div>
|
||||||
<div style={{ fontSize: 11, fontFamily: 'monospace', color: 'var(--color-text-muted)' }}>
|
<div style={{ fontSize: 11, fontFamily: 'monospace', color: 'var(--color-text-muted)' }}>
|
||||||
{token}
|
{token}
|
||||||
@@ -128,6 +164,11 @@ function ColorPalette() {
|
|||||||
<Swatch key={c.token} {...c} />
|
<Swatch key={c.token} {...c} />
|
||||||
))}
|
))}
|
||||||
</Section>
|
</Section>
|
||||||
|
<Section title="Syntax highlighting">
|
||||||
|
{syntaxColors.map((c) => (
|
||||||
|
<Swatch key={c.token} {...c} />
|
||||||
|
))}
|
||||||
|
</Section>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export default meta;
|
|||||||
type Story = StoryObj<typeof ContextMenu>;
|
type Story = StoryObj<typeof ContextMenu>;
|
||||||
|
|
||||||
const trigger = (
|
const trigger = (
|
||||||
<Button variant="ghost" size="sm">
|
<Button variant="ghost" size="sm" aria-label="Actions">
|
||||||
<Settings size={16} />
|
<Settings size={16} />
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,330 @@
|
|||||||
|
import React, { useLayoutEffect, useRef, useState } from 'react';
|
||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { AutoRefreshIndicator } from '../../src/ui/AutoRefreshIndicator/AutoRefreshIndicator';
|
||||||
|
import { Button } from '../../src/ui/Button/Button';
|
||||||
|
import { CodeBlock } from '../../src/ui/CodeBlock/CodeBlock';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Text contrast review page (WCAG AA: 4.5:1 for normal text, 3:1 for large
|
||||||
|
* text) for the components where contrast is easiest to get wrong: light
|
||||||
|
* brand colors used as text, dimmed labels, colored buttons and syntax
|
||||||
|
* highlighting. Every sample is the real component, shown in both themes, and
|
||||||
|
* the contrast of each piece of text is measured live from the rendered
|
||||||
|
* colors - so this page stays accurate as the design tokens change.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// ── Contrast measurement ─────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
type Rgba = [number, number, number, number];
|
||||||
|
|
||||||
|
function parseColor(value: string): Rgba {
|
||||||
|
const parts = value.match(/[\d.]+/g)?.map(Number) ?? [0, 0, 0];
|
||||||
|
return [parts[0], parts[1], parts[2], parts[3] ?? 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
function luminance([r, g, b]: Rgba): number {
|
||||||
|
const channel = (c: number) => {
|
||||||
|
const s = c / 255;
|
||||||
|
return s <= 0.03928 ? s / 12.92 : ((s + 0.055) / 1.055) ** 2.4;
|
||||||
|
};
|
||||||
|
return 0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
function contrast(a: Rgba, b: Rgba): number {
|
||||||
|
const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
|
||||||
|
return (hi + 0.05) / (lo + 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Blends `top` over an opaque `bottom`. */
|
||||||
|
function blend(top: Rgba, bottom: Rgba): Rgba {
|
||||||
|
const a = top[3];
|
||||||
|
return [0, 1, 2].map((i) => top[i] * a + bottom[i] * (1 - a)).concat(1) as Rgba;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Product of the `opacity` of `el` and its ancestors (e.g. a dimmed idle label). */
|
||||||
|
function opacityChain(el: Element): number {
|
||||||
|
let opacity = 1;
|
||||||
|
for (let node: Element | null = el; node; node = node.parentElement) {
|
||||||
|
opacity *= parseFloat(getComputedStyle(node).opacity);
|
||||||
|
}
|
||||||
|
return opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The opaque color behind `el`, from its own and its ancestors' backgrounds. */
|
||||||
|
function effectiveBackground(el: Element): Rgba {
|
||||||
|
const layers: Rgba[] = [];
|
||||||
|
for (let node: Element | null = el; node; node = node.parentElement) {
|
||||||
|
const bg = parseColor(getComputedStyle(node).backgroundColor);
|
||||||
|
bg[3] *= opacityChain(node);
|
||||||
|
if (bg[3] > 0) layers.push(bg);
|
||||||
|
if (bg[3] >= 1) break;
|
||||||
|
}
|
||||||
|
return layers.reduceRight<Rgba>((under, layer) => blend(layer, under), [255, 255, 255, 1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const hex = ([r, g, b]: Rgba) =>
|
||||||
|
'#' + [r, g, b].map((c) => Math.round(c).toString(16).padStart(2, '0')).join('');
|
||||||
|
|
||||||
|
interface Measurement {
|
||||||
|
text: string;
|
||||||
|
fg: string;
|
||||||
|
bg: string;
|
||||||
|
ratio: number;
|
||||||
|
required: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Measures every element that directly contains visible text. */
|
||||||
|
function measure(root: HTMLElement): Measurement[] {
|
||||||
|
const seen = new Set<string>();
|
||||||
|
const results: Measurement[] = [];
|
||||||
|
for (const el of Array.from(root.querySelectorAll<HTMLElement>('*'))) {
|
||||||
|
const text = Array.from(el.childNodes)
|
||||||
|
.filter((n) => n.nodeType === Node.TEXT_NODE)
|
||||||
|
.map((n) => n.textContent ?? '')
|
||||||
|
.join('')
|
||||||
|
.trim();
|
||||||
|
if (!text || el.closest('[aria-hidden="true"]')) continue;
|
||||||
|
const style = getComputedStyle(el);
|
||||||
|
const fontSize = parseFloat(style.fontSize);
|
||||||
|
const bold = Number(style.fontWeight) >= 700;
|
||||||
|
// WCAG "large text": at least 24px, or 18.66px bold
|
||||||
|
const required = fontSize >= 24 || (bold && fontSize >= 18.66) ? 3 : 4.5;
|
||||||
|
const bgColor = effectiveBackground(el);
|
||||||
|
const fg = parseColor(style.color);
|
||||||
|
fg[3] *= opacityChain(el);
|
||||||
|
const fgColor = blend(fg, bgColor);
|
||||||
|
const key = `${hex(fgColor)}|${hex(bgColor)}|${required}`;
|
||||||
|
if (seen.has(key)) continue;
|
||||||
|
seen.add(key);
|
||||||
|
results.push({
|
||||||
|
text: text.length > 28 ? `${text.slice(0, 28)}…` : text,
|
||||||
|
fg: hex(fgColor),
|
||||||
|
bg: hex(bgColor),
|
||||||
|
ratio: contrast(fgColor, bgColor),
|
||||||
|
required,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return results.sort((a, b) => a.ratio / a.required - b.ratio / b.required);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Readout({ items }: { items: Measurement[] }) {
|
||||||
|
return (
|
||||||
|
<table style={{ width: '100%', borderCollapse: 'collapse', fontSize: 12, marginTop: 8 }}>
|
||||||
|
<tbody>
|
||||||
|
{items.map((m) => {
|
||||||
|
const pass = m.ratio >= m.required;
|
||||||
|
return (
|
||||||
|
<tr
|
||||||
|
key={`${m.fg}${m.bg}${m.required}`}
|
||||||
|
style={{ borderTop: '1px solid var(--color-border)' }}
|
||||||
|
>
|
||||||
|
<td style={{ padding: '4px 6px' }}>
|
||||||
|
<span
|
||||||
|
style={{
|
||||||
|
display: 'inline-block',
|
||||||
|
padding: '1px 6px',
|
||||||
|
borderRadius: 3,
|
||||||
|
background: m.bg,
|
||||||
|
color: m.fg,
|
||||||
|
fontFamily: 'monospace',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{m.text}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
style={{
|
||||||
|
padding: '4px 6px',
|
||||||
|
fontFamily: 'monospace',
|
||||||
|
color: 'var(--color-text-muted)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{m.fg} on {m.bg}
|
||||||
|
</td>
|
||||||
|
<td
|
||||||
|
style={{
|
||||||
|
padding: '4px 6px',
|
||||||
|
textAlign: 'right',
|
||||||
|
fontWeight: 700,
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
color: pass ? 'var(--color-text)' : 'var(--color-danger)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{m.ratio.toFixed(2)}:1 {pass ? '✓' : `✗ needs ${m.required}:1`}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Renders a sample and measures its text contrast after layout. */
|
||||||
|
function Sample({ children }: { children: React.ReactNode }) {
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
const [items, setItems] = useState<Measurement[]>([]);
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
const el = ref.current;
|
||||||
|
if (!el) return;
|
||||||
|
// Measure after the theme/styles have applied
|
||||||
|
const frame = requestAnimationFrame(() => setItems(measure(el)));
|
||||||
|
return () => cancelAnimationFrame(frame);
|
||||||
|
}, []);
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div ref={ref}>{children}</div>
|
||||||
|
<Readout items={items} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Page ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
// Covers every syntax color: comment, keyword, string, number, function
|
||||||
|
// (title), params, property
|
||||||
|
const JS_CODE = [
|
||||||
|
'// Open the app and wait for the dashboard',
|
||||||
|
'async function openDashboard(context, timeoutMs) {',
|
||||||
|
" const url = context.getEnv('BASE_URL');",
|
||||||
|
' await context.page.goto(url, { timeout: timeoutMs ?? 30000 });',
|
||||||
|
' return context.page.title();',
|
||||||
|
'}',
|
||||||
|
].join('\n');
|
||||||
|
const JSON_CODE = JSON.stringify(
|
||||||
|
{ status: 'pass', attempts: 2, cached: false, output: { title: 'Dashboard' } },
|
||||||
|
null,
|
||||||
|
2,
|
||||||
|
);
|
||||||
|
|
||||||
|
interface Issue {
|
||||||
|
title: string;
|
||||||
|
note: string;
|
||||||
|
render: () => React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ISSUES: Issue[] = [
|
||||||
|
{
|
||||||
|
title: 'AutoRefreshIndicator label',
|
||||||
|
note: 'Active ("Live", --color-primary-text), idle and error labels (runs pages).',
|
||||||
|
render: () => (
|
||||||
|
<div style={{ display: 'flex', gap: 12, flexWrap: 'wrap' }}>
|
||||||
|
<AutoRefreshIndicator active pulseKey={1} />
|
||||||
|
<AutoRefreshIndicator active={false} />
|
||||||
|
<AutoRefreshIndicator active={false} error />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Danger button',
|
||||||
|
note: 'Danger, primary and secondary buttons (text on colored backgrounds).',
|
||||||
|
render: () => (
|
||||||
|
<div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
|
||||||
|
<Button variant="danger">Delete</Button>
|
||||||
|
<Button variant="danger" size="sm">
|
||||||
|
Delete
|
||||||
|
</Button>
|
||||||
|
<Button variant="primary">Run</Button>
|
||||||
|
<Button variant="secondary">Cancel</Button>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Code highlighting - JavaScript',
|
||||||
|
note: 'All --hl-* syntax colors on the page background (step code, snippets).',
|
||||||
|
render: () => <CodeBlock language="javascript" code={JS_CODE} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Code highlighting - JSON',
|
||||||
|
note: 'Keys, strings, numbers and literals in JSON step outputs.',
|
||||||
|
render: () => <CodeBlock language="json" code={JSON_CODE} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: 'Muted text',
|
||||||
|
note: '--color-text-muted on both background shades (hints, table headers, descriptions).',
|
||||||
|
render: () => (
|
||||||
|
<div style={{ display: 'flex', gap: 8 }}>
|
||||||
|
{['var(--color-bg)', 'var(--color-bg-subtle)'].map((bg) => (
|
||||||
|
<span
|
||||||
|
key={bg}
|
||||||
|
style={{
|
||||||
|
background: bg,
|
||||||
|
color: 'var(--color-text-muted)',
|
||||||
|
padding: '4px 8px',
|
||||||
|
fontSize: 13,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Last run 2 minutes ago
|
||||||
|
</span>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
function Panel({ theme }: { theme: 'light' | 'dark' }) {
|
||||||
|
return (
|
||||||
|
<section
|
||||||
|
// The dark tokens apply under [data-theme="dark"]; light is the page default
|
||||||
|
data-theme={theme === 'dark' ? 'dark' : undefined}
|
||||||
|
style={{
|
||||||
|
flex: '1 1 420px',
|
||||||
|
minWidth: 0,
|
||||||
|
padding: 16,
|
||||||
|
borderRadius: 8,
|
||||||
|
background: 'var(--color-bg)',
|
||||||
|
color: 'var(--color-text)',
|
||||||
|
border: '1px solid var(--color-border)',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<h2 style={{ margin: '0 0 12px', fontSize: 16 }}>
|
||||||
|
{theme === 'dark' ? 'Dark theme' : 'Light theme'}
|
||||||
|
</h2>
|
||||||
|
{ISSUES.map((issue) => (
|
||||||
|
<div key={issue.title} style={{ marginBottom: 24 }}>
|
||||||
|
<h3 style={{ margin: '0 0 2px', fontSize: 14 }}>{issue.title}</h3>
|
||||||
|
<p style={{ margin: '0 0 8px', fontSize: 12, color: 'var(--color-text-muted)' }}>
|
||||||
|
{issue.note}
|
||||||
|
</p>
|
||||||
|
<Sample>{issue.render()}</Sample>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ContrastPage() {
|
||||||
|
return (
|
||||||
|
<div style={{ padding: 16 }}>
|
||||||
|
<p
|
||||||
|
style={{
|
||||||
|
margin: '0 0 16px',
|
||||||
|
fontSize: 13,
|
||||||
|
color: 'var(--color-text-muted)',
|
||||||
|
maxWidth: 820,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Text contrast of the components where it's easiest to get wrong (WCAG AA: 4.5:1 for normal
|
||||||
|
text, 3:1 for large text). Each row is a piece of text in the sample, measured from its
|
||||||
|
rendered colors, worst first.
|
||||||
|
</p>
|
||||||
|
<div style={{ display: 'flex', gap: 16, flexWrap: 'wrap', alignItems: 'flex-start' }}>
|
||||||
|
<Panel theme="light" />
|
||||||
|
<Panel theme="dark" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const meta: Meta<typeof ContrastPage> = {
|
||||||
|
title: 'Accessibility/Contrast',
|
||||||
|
component: ContrastPage,
|
||||||
|
// a11y checks use the project default ('error' in preview.tsx)
|
||||||
|
parameters: { layout: 'fullscreen' },
|
||||||
|
// The light panel relies on the page default (light) theme
|
||||||
|
globals: { theme: 'light' },
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof ContrastPage>;
|
||||||
|
|
||||||
|
export const Overview: Story = {};
|
||||||
@@ -15,7 +15,7 @@ const meta: Meta<typeof DescriptionList> = {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
argTypes: {
|
argTypes: {
|
||||||
layout: { control: 'select', options: ['inline', 'compact'] },
|
layout: { control: 'select', options: ['inline', 'compact', 'comfortable', 'grid'] },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
export default meta;
|
export default meta;
|
||||||
@@ -35,6 +35,14 @@ export const Compact: Story = {
|
|||||||
args: { items: urlItems, layout: 'compact' },
|
args: { items: urlItems, layout: 'compact' },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const Comfortable: Story = {
|
||||||
|
args: { items: urlItems, layout: 'comfortable' },
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Grid: Story = {
|
||||||
|
args: { items: urlItems, layout: 'grid' },
|
||||||
|
};
|
||||||
|
|
||||||
export const WithLinks: Story = {
|
export const WithLinks: Story = {
|
||||||
args: {
|
args: {
|
||||||
layout: 'inline',
|
layout: 'inline',
|
||||||
|
|||||||
@@ -0,0 +1,197 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { expect, userEvent, within } from 'storybook/test';
|
||||||
|
import { LogOutput, type LogOutputEntry } from '../../src/ui/LogOutput/LogOutput';
|
||||||
|
import { formatLogText } from '../../src/ui/LogOutput/logText';
|
||||||
|
|
||||||
|
const meta: Meta<typeof LogOutput> = {
|
||||||
|
title: 'UI/LogOutput',
|
||||||
|
component: LogOutput,
|
||||||
|
tags: ['autodocs'],
|
||||||
|
parameters: { layout: 'padded' },
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
|
||||||
|
type Story = StoryObj<typeof LogOutput>;
|
||||||
|
|
||||||
|
const secondsAgo = (n: number) => new Date(Date.now() - n * 1000).toISOString();
|
||||||
|
|
||||||
|
export const Default: Story = {
|
||||||
|
args: {
|
||||||
|
startTime: secondsAgo(60),
|
||||||
|
entries: [
|
||||||
|
{
|
||||||
|
id: 0,
|
||||||
|
level: 'debug',
|
||||||
|
context: 'step:1',
|
||||||
|
message: 'Resolved credential alias "sdJwtKey" to a file credential',
|
||||||
|
createdAt: secondsAgo(61),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
level: 'log',
|
||||||
|
context: 'step:1',
|
||||||
|
message: 'Step 1 started: Login with PKCS',
|
||||||
|
createdAt: secondsAgo(60),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
level: 'log',
|
||||||
|
context: 'snippet:loginWithPkcs',
|
||||||
|
message: 'Snippet "loginWithPkcs" started',
|
||||||
|
createdAt: secondsAgo(58),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
level: 'log',
|
||||||
|
context: 'snippet:loginWithPkcs',
|
||||||
|
message: 'Saved credential as run file:',
|
||||||
|
data: JSON.stringify({
|
||||||
|
id: '181d8ae2-4aee-4f33-a657-210efe7fe668',
|
||||||
|
name: 'credential.sd-jwt',
|
||||||
|
mimeType: 'application/octet-stream',
|
||||||
|
size: 1657,
|
||||||
|
sha256: '9c4226999c700a39bda30279907e4479a5b3920ccde5c75771ea0e264c638c0',
|
||||||
|
path: 'data/files/18/181d/181d8ae2-4aee-4f33-a657-210efe7fe668',
|
||||||
|
}),
|
||||||
|
createdAt: secondsAgo(57),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
level: 'log',
|
||||||
|
context: 'snippet:loginWithPkcs',
|
||||||
|
message: 'Navigating to ID login: https://id.example.com',
|
||||||
|
createdAt: secondsAgo(57),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
level: 'log',
|
||||||
|
context: 'assertion:pass',
|
||||||
|
message: 'Assertion passed: page must have redirected to cabinet URL',
|
||||||
|
createdAt: secondsAgo(40),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 6,
|
||||||
|
level: 'warn',
|
||||||
|
context: 'snippet:loginWithPkcs',
|
||||||
|
message: 'Retrying file upload after a transient error',
|
||||||
|
createdAt: secondsAgo(39),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 7,
|
||||||
|
level: 'log',
|
||||||
|
context: 'step:1',
|
||||||
|
message: 'Step 1 passed',
|
||||||
|
createdAt: secondsAgo(30),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 8,
|
||||||
|
level: 'error',
|
||||||
|
context: 'assertion:fail',
|
||||||
|
message: 'Assertion failed: Document validation must pass (got 422)',
|
||||||
|
createdAt: secondsAgo(10),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 9,
|
||||||
|
level: 'error',
|
||||||
|
context: 'step:2',
|
||||||
|
message: 'Step 2 failed: Document validation must pass (got 422)',
|
||||||
|
createdAt: secondsAgo(9),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Scrollable: Story = {
|
||||||
|
args: {
|
||||||
|
maxHeight: 160,
|
||||||
|
startTime: secondsAgo(60),
|
||||||
|
entries: Array.from({ length: 30 }, (_, i) => ({
|
||||||
|
id: i,
|
||||||
|
level: (['log', 'log', 'log', 'warn', 'error'] as const)[i % 5],
|
||||||
|
context: `step:${Math.floor(i / 6) + 1}`,
|
||||||
|
message: `Log entry ${i + 1}`,
|
||||||
|
createdAt: secondsAgo(60 - i * 2),
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const largeDataEntries: LogOutputEntry[] = [
|
||||||
|
{
|
||||||
|
id: 0,
|
||||||
|
level: 'log',
|
||||||
|
context: 'step:1',
|
||||||
|
message: 'Small payload:',
|
||||||
|
data: JSON.stringify({ status: 200 }),
|
||||||
|
createdAt: secondsAgo(20),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
level: 'log',
|
||||||
|
context: 'step:1',
|
||||||
|
message: 'Large payload:',
|
||||||
|
data: JSON.stringify({
|
||||||
|
user: { id: 42, name: 'Jane Doe', roles: ['admin', 'qa'] },
|
||||||
|
token: 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI0MiJ9',
|
||||||
|
}),
|
||||||
|
createdAt: secondsAgo(18),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
level: 'warn',
|
||||||
|
context: 'step:2',
|
||||||
|
message: 'Another large payload:',
|
||||||
|
data: JSON.stringify(Array.from({ length: 8 }, (_, i) => ({ row: i }))),
|
||||||
|
createdAt: secondsAgo(10),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
function LargeDataLog() {
|
||||||
|
const [expanded, setExpanded] = useState(false);
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, alignItems: 'flex-start' }}>
|
||||||
|
<button type="button" onClick={() => setExpanded((v) => !v)}>
|
||||||
|
{expanded ? 'Collapse all' : 'Expand all'}
|
||||||
|
</button>
|
||||||
|
<LogOutput startTime={secondsAgo(20)} entries={largeDataEntries} dataExpanded={expanded} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Data blocks over the default limits (256 bytes, 5 lines) start collapsed. */
|
||||||
|
export const LargeData: Story = {
|
||||||
|
render: () => <LargeDataLog />,
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
// Data blocks are syntax-highlighted into separate tokens, so check the log's text
|
||||||
|
const log = canvas.getByRole('log');
|
||||||
|
// Only the small payload is visible initially
|
||||||
|
await expect(log).toHaveTextContent('"status": 200');
|
||||||
|
await expect(log).not.toHaveTextContent('Jane Doe');
|
||||||
|
const toggles = canvas.getAllByRole('button', { name: /^Show data/ });
|
||||||
|
await expect(toggles).toHaveLength(2);
|
||||||
|
|
||||||
|
await userEvent.click(toggles[0]);
|
||||||
|
await expect(log).toHaveTextContent('Jane Doe');
|
||||||
|
await userEvent.click(canvas.getByRole('button', { name: 'Hide data' }));
|
||||||
|
await expect(log).not.toHaveTextContent('Jane Doe');
|
||||||
|
|
||||||
|
await userEvent.click(canvas.getByRole('button', { name: 'Expand all' }));
|
||||||
|
await expect(log).toHaveTextContent('Jane Doe');
|
||||||
|
await expect(canvas.getAllByRole('button', { name: 'Hide data' })).toHaveLength(2);
|
||||||
|
await userEvent.click(canvas.getByRole('button', { name: 'Collapse all' }));
|
||||||
|
await expect(log).not.toHaveTextContent('Jane Doe');
|
||||||
|
|
||||||
|
// The plain-text form always includes every data block
|
||||||
|
const text = formatLogText(largeDataEntries, largeDataEntries[0].createdAt);
|
||||||
|
await expect(text).toContain('[step:1] Large payload:\n {');
|
||||||
|
await expect(text).toContain('"name": "Jane Doe"');
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Empty: Story = {
|
||||||
|
args: {
|
||||||
|
entries: [],
|
||||||
|
emptyMessage: 'No logs yet.',
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { expect, within } from 'storybook/test';
|
||||||
|
import { MarkdownContent } from '../../src/ui/MarkdownContent/MarkdownContent';
|
||||||
|
|
||||||
|
const meta: Meta<typeof MarkdownContent> = {
|
||||||
|
title: 'UI/MarkdownContent',
|
||||||
|
component: MarkdownContent,
|
||||||
|
parameters: { layout: 'padded' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof MarkdownContent>;
|
||||||
|
|
||||||
|
export const Description: Story = {
|
||||||
|
args: {
|
||||||
|
content: [
|
||||||
|
'## Login flow',
|
||||||
|
'',
|
||||||
|
'Logs in with the **test user** and checks the dashboard.',
|
||||||
|
'',
|
||||||
|
'- Uses the `BASE_URL` environment value',
|
||||||
|
'- Needs the `user` credential alias',
|
||||||
|
'',
|
||||||
|
'```js',
|
||||||
|
"await context.page.goto(context.getEnv('BASE_URL'));",
|
||||||
|
'```',
|
||||||
|
].join('\n'),
|
||||||
|
},
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
await expect(canvas.getByRole('heading', { name: 'Login flow' })).toBeInTheDocument();
|
||||||
|
await expect(canvas.getByText('test user').tagName).toBe('STRONG');
|
||||||
|
await expect(canvas.getAllByRole('listitem')).toHaveLength(2);
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { expect, userEvent, within } from 'storybook/test';
|
||||||
|
import { Modal } from '../../src/ui/Modal/Modal';
|
||||||
|
import { Button } from '../../src/ui/Button/Button';
|
||||||
|
|
||||||
|
function ModalDemo({
|
||||||
|
title,
|
||||||
|
body,
|
||||||
|
size,
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
body: React.ReactNode;
|
||||||
|
size?: 'md' | 'lg';
|
||||||
|
}) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button onClick={() => setOpen(true)}>Open modal</Button>
|
||||||
|
<Modal
|
||||||
|
open={open}
|
||||||
|
size={size}
|
||||||
|
title={title}
|
||||||
|
onClose={() => setOpen(false)}
|
||||||
|
footer={
|
||||||
|
<>
|
||||||
|
<Button variant="secondary" onClick={() => setOpen(false)}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button onClick={() => setOpen(false)}>Confirm</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{body}
|
||||||
|
</Modal>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const meta: Meta<typeof ModalDemo> = {
|
||||||
|
title: 'UI/Modal',
|
||||||
|
component: ModalDemo,
|
||||||
|
parameters: { layout: 'centered' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
args: { title: 'Delete scenario', body: 'This deletes the scenario, its versions and its runs.' },
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof ModalDemo>;
|
||||||
|
|
||||||
|
export const Default: Story = {
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
await userEvent.click(canvas.getByRole('button', { name: 'Open modal' }));
|
||||||
|
const dialog = canvas.getByRole('dialog', { name: 'Delete scenario' });
|
||||||
|
await expect(dialog).toHaveTextContent('its versions and its runs');
|
||||||
|
await userEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }));
|
||||||
|
await expect(canvas.queryByRole('dialog')).not.toBeInTheDocument();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const ClosesOnEscapeAndBackdrop: Story = {
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
await userEvent.click(canvas.getByRole('button', { name: 'Open modal' }));
|
||||||
|
await userEvent.keyboard('{Escape}');
|
||||||
|
await expect(canvas.queryByRole('dialog')).not.toBeInTheDocument();
|
||||||
|
|
||||||
|
await userEvent.click(canvas.getByRole('button', { name: 'Open modal' }));
|
||||||
|
await userEvent.click(canvas.getByRole('presentation'));
|
||||||
|
await expect(canvas.queryByRole('dialog')).not.toBeInTheDocument();
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Large: Story = {
|
||||||
|
args: {
|
||||||
|
title: 'Code reference',
|
||||||
|
size: 'lg',
|
||||||
|
body: (
|
||||||
|
<>
|
||||||
|
{Array.from({ length: 60 }, (_, i) => (
|
||||||
|
<p key={i}>Paragraph {i + 1} of a long, document-like modal body.</p>
|
||||||
|
))}
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
await userEvent.click(canvas.getByRole('button', { name: 'Open modal' }));
|
||||||
|
const dialog = canvas.getByRole('dialog', { name: 'Code reference' });
|
||||||
|
// The dialog stays within the viewport; its body scrolls instead.
|
||||||
|
await expect(dialog.getBoundingClientRect().height).toBeLessThanOrEqual(window.innerHeight);
|
||||||
|
const body = within(dialog).getByText(
|
||||||
|
'Paragraph 1 of a long, document-like modal body.',
|
||||||
|
).parentElement!;
|
||||||
|
await expect(body.scrollHeight).toBeGreaterThan(body.clientHeight);
|
||||||
|
await expect(within(dialog).getByRole('button', { name: 'Confirm' })).toBeVisible();
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { Notification } from '../../src/ui/Notification/Notification';
|
||||||
|
|
||||||
|
const meta: Meta<typeof Notification> = {
|
||||||
|
title: 'UI/Notification',
|
||||||
|
component: Notification,
|
||||||
|
parameters: { layout: 'padded' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
argTypes: {
|
||||||
|
variant: { control: 'select', options: ['info', 'success', 'error', 'warning', 'note'] },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof Notification>;
|
||||||
|
|
||||||
|
export const Info: Story = {
|
||||||
|
args: {
|
||||||
|
variant: 'info',
|
||||||
|
title: 'Traces are off',
|
||||||
|
children: 'Enable them per run in the run modal.',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export const Success: Story = { args: { variant: 'success', children: 'Scenario imported.' } };
|
||||||
|
export const Error: Story = {
|
||||||
|
args: { variant: 'error', title: 'Run failed', children: 'Step 2 timed out after 60s.' },
|
||||||
|
};
|
||||||
|
export const Warning: Story = {
|
||||||
|
args: { variant: 'warning', children: 'The environment of this run no longer exists.' },
|
||||||
|
};
|
||||||
|
export const Note: Story = { args: { variant: 'note', children: 'Pinned snippet version: v3.' } };
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { expect, userEvent, within } from 'storybook/test';
|
||||||
|
import { RevealableCodeBlock } from '../../src/ui/RevealableCodeBlock/RevealableCodeBlock';
|
||||||
|
|
||||||
|
const meta: Meta<typeof RevealableCodeBlock> = {
|
||||||
|
title: 'UI/RevealableCodeBlock',
|
||||||
|
component: RevealableCodeBlock,
|
||||||
|
parameters: { layout: 'padded' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof RevealableCodeBlock>;
|
||||||
|
|
||||||
|
export const Default: Story = {
|
||||||
|
args: {
|
||||||
|
language: 'json',
|
||||||
|
code: JSON.stringify({ username: 'admin', password: 's3cr3t-p4ss' }, null, 2),
|
||||||
|
},
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
// The code is not rendered until revealed, and hidden again on the second click
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
const toggle = canvas.getByRole('button');
|
||||||
|
await expect(canvasElement).not.toHaveTextContent('s3cr3t-p4ss');
|
||||||
|
await expect(toggle).toHaveAttribute('aria-expanded', 'false');
|
||||||
|
|
||||||
|
await userEvent.click(toggle);
|
||||||
|
await expect(canvasElement.querySelector('code')).toHaveTextContent('s3cr3t-p4ss');
|
||||||
|
await expect(toggle).toHaveAttribute('aria-expanded', 'true');
|
||||||
|
|
||||||
|
await userEvent.click(toggle);
|
||||||
|
await expect(canvasElement).not.toHaveTextContent('s3cr3t-p4ss');
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { expect, userEvent, within } from 'storybook/test';
|
||||||
|
import { Search } from '../../src/ui/Search/Search';
|
||||||
|
|
||||||
|
function ControlledSearch({ placeholder }: { placeholder?: string }) {
|
||||||
|
const [value, setValue] = useState('');
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Search value={value} onChange={setValue} placeholder={placeholder} />
|
||||||
|
<p data-testid="query">{value}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const meta: Meta<typeof ControlledSearch> = {
|
||||||
|
title: 'UI/Search',
|
||||||
|
component: ControlledSearch,
|
||||||
|
parameters: { layout: 'centered' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof ControlledSearch>;
|
||||||
|
|
||||||
|
export const Default: Story = {};
|
||||||
|
|
||||||
|
export const Typing: Story = {
|
||||||
|
args: { placeholder: 'Filter logs…' },
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
await userEvent.type(canvas.getByPlaceholderText('Filter logs…'), 'timeout');
|
||||||
|
await expect(canvas.getByTestId('query')).toHaveTextContent('timeout');
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { expect, within } from 'storybook/test';
|
||||||
|
import { Textarea } from '../../src/ui/Textarea/Textarea';
|
||||||
|
|
||||||
|
const meta: Meta<typeof Textarea> = {
|
||||||
|
title: 'UI/Textarea',
|
||||||
|
component: Textarea,
|
||||||
|
parameters: { layout: 'centered' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
decorators: [
|
||||||
|
(Story) => (
|
||||||
|
<div style={{ width: 360 }}>
|
||||||
|
<Story />
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof Textarea>;
|
||||||
|
|
||||||
|
export const Default: Story = {
|
||||||
|
args: { label: 'Description', placeholder: 'Describe this scenario', rows: 4 },
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WithHint: Story = {
|
||||||
|
args: { label: 'Description', hint: 'Markdown is supported.', rows: 4 },
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WithError: Story = {
|
||||||
|
args: { label: 'Description', error: 'Description is too long.', rows: 4 },
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
const textarea = canvas.getByLabelText('Description');
|
||||||
|
await expect(textarea).toHaveAttribute('aria-invalid', 'true');
|
||||||
|
await expect(canvas.getByRole('alert')).toHaveTextContent('Description is too long.');
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { expect, userEvent, within } from 'storybook/test';
|
||||||
|
import { ToastProvider } from '../../src/ui/Toast/ToastProvider';
|
||||||
|
import { useToast } from '../../src/ui/Toast/useToast';
|
||||||
|
import { Button } from '../../src/ui/Button/Button';
|
||||||
|
|
||||||
|
function ToastButtons() {
|
||||||
|
const toast = useToast();
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', gap: 8 }}>
|
||||||
|
<Button onClick={() => toast.success('Scenario run started')}>Success</Button>
|
||||||
|
<Button variant="danger" onClick={() => toast.error('Environment not found')}>
|
||||||
|
Error
|
||||||
|
</Button>
|
||||||
|
<Button variant="secondary" onClick={() => toast.info('Traces are off')}>
|
||||||
|
Info
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const meta: Meta<typeof ToastProvider> = {
|
||||||
|
title: 'UI/Toast',
|
||||||
|
component: ToastProvider,
|
||||||
|
parameters: { layout: 'centered' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
args: { durationMs: 3500, children: <ToastButtons /> },
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof ToastProvider>;
|
||||||
|
|
||||||
|
export const Default: Story = {};
|
||||||
|
|
||||||
|
export const ShowsToast: Story = {
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
await userEvent.click(canvas.getByRole('button', { name: 'Success' }));
|
||||||
|
await expect(await within(document.body).findByText('Scenario run started')).toBeVisible();
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { expect, within } from 'storybook/test';
|
||||||
|
import { Button } from '../../src/ui/Button/Button';
|
||||||
|
import { UuidBadge } from '../../src/ui/UuidBadge/UuidBadge';
|
||||||
|
|
||||||
|
const meta: Meta<typeof UuidBadge> = {
|
||||||
|
title: 'UI/UuidBadge',
|
||||||
|
component: UuidBadge,
|
||||||
|
parameters: { layout: 'centered' },
|
||||||
|
tags: ['autodocs'],
|
||||||
|
};
|
||||||
|
export default meta;
|
||||||
|
type Story = StoryObj<typeof UuidBadge>;
|
||||||
|
|
||||||
|
export const Default: Story = {
|
||||||
|
args: { id: '61d2b1c2-7664-4dca-974f-436c2ee90b2e' },
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
// Shows a shortened id and keeps the full one in the tooltip
|
||||||
|
const badge = within(canvasElement).getByTitle('61d2b1c2-7664-4dca-974f-436c2ee90b2e');
|
||||||
|
await expect(badge).toHaveTextContent('61d2…0b2e');
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const SAMPLE_IDS = [
|
||||||
|
'61d2b1c2-7664-4dca-974f-436c2ee90b2e',
|
||||||
|
'e83f0a5d-1b9c-4f27-8d6e-2a4c9b7f1e03',
|
||||||
|
'0c7a94f1-3e52-4b8d-a1f6-9d2e5c8b4a70',
|
||||||
|
'f4b21e8c-9a07-4c63-b5d2-7e1f0a3c6d98',
|
||||||
|
'8d5e3a10-c4f7-4e29-9b81-5f6a2d0c7e14',
|
||||||
|
'2a9fc067-58d3-4a1e-86b4-c3e7f19d5b2a',
|
||||||
|
];
|
||||||
|
|
||||||
|
function Gallery() {
|
||||||
|
const [ids, setIds] = useState(SAMPLE_IDS);
|
||||||
|
return (
|
||||||
|
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'flex-start', gap: 12 }}>
|
||||||
|
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 16 }}>
|
||||||
|
{ids.map((id) => (
|
||||||
|
<UuidBadge key={id} id={id} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
size="sm"
|
||||||
|
variant="secondary"
|
||||||
|
onClick={() => setIds(ids.map(() => crypto.randomUUID()))}
|
||||||
|
>
|
||||||
|
Randomize
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Colors: Story = {
|
||||||
|
render: () => <Gallery />,
|
||||||
|
play: async ({ canvasElement }) => {
|
||||||
|
// Each sample id gets its own badge
|
||||||
|
const canvas = within(canvasElement);
|
||||||
|
for (const id of SAMPLE_IDS) {
|
||||||
|
await expect(canvas.getByTitle(id)).toBeInTheDocument();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
# ── Build stage ───────────────────────────────────────────────────────────────
|
|
||||||
FROM node:22-slim AS builder
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Copy root lockfile + workspace manifests so npm ci can resolve the full graph
|
|
||||||
COPY package*.json ./
|
|
||||||
COPY client/package.json ./client/
|
|
||||||
RUN npm ci -w client
|
|
||||||
|
|
||||||
COPY client ./client
|
|
||||||
RUN npm run -w client build
|
|
||||||
|
|
||||||
# ── Runtime stage ─────────────────────────────────────────────────────────────
|
|
||||||
FROM nginx:alpine AS runtime
|
|
||||||
|
|
||||||
COPY --from=builder /app/client/dist /usr/share/nginx/html
|
|
||||||
|
|
||||||
EXPOSE 80
|
|
||||||
@@ -1,13 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "liqa-client",
|
"name": "liqa-client",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"license": "MIT",
|
||||||
|
"author": "Andrii Arsenin",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
"dev:compose-api": "VITE_API_URL=http://localhost:13000/api/v1 vite",
|
||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && vite build",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"storybook": "storybook dev -p 6006",
|
"storybook": "storybook dev -p 6006",
|
||||||
"build-storybook": "storybook build",
|
"build-storybook": "storybook build",
|
||||||
|
"test:compile": "tsc --noEmit",
|
||||||
"test:storybook": "vitest run --project storybook",
|
"test:storybook": "vitest run --project storybook",
|
||||||
"lint": "eslint src .storybook",
|
"lint": "eslint src .storybook",
|
||||||
"lint:fix": "eslint src .storybook --fix",
|
"lint:fix": "eslint src .storybook --fix",
|
||||||
@@ -15,6 +19,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@monaco-editor/react": "^4.7.0",
|
"@monaco-editor/react": "^4.7.0",
|
||||||
|
"@tanstack/react-query": "^5.99.0",
|
||||||
"highlight.js": "^11.11.1",
|
"highlight.js": "^11.11.1",
|
||||||
"i18next": "^26.0.4",
|
"i18next": "^26.0.4",
|
||||||
"lucide-react": "^1.7.0",
|
"lucide-react": "^1.7.0",
|
||||||
|
|||||||
@@ -52,6 +52,16 @@
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.versionLink {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.versionLink:hover,
|
||||||
|
.versionLink:focus-visible {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
.navItem {
|
.navItem {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -95,6 +105,12 @@
|
|||||||
background: var(--color-secondary-hover);
|
background: var(--color-secondary-hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.navSeparator {
|
||||||
|
height: var(--border-width);
|
||||||
|
background: var(--color-border);
|
||||||
|
margin: var(--space-2) var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
.main {
|
.main {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|||||||
+68
-28
@@ -1,23 +1,30 @@
|
|||||||
import { lazy, Suspense } from 'react';
|
import { lazy, Suspense } from 'react';
|
||||||
import { NavLink, Navigate, Route, Routes } from 'react-router-dom';
|
import { NavLink, Navigate, Route, Routes } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Globe, Monitor, ClipboardList, Activity, KeyRound, Braces } from 'lucide-react';
|
import { Globe, Monitor, ClipboardList, Activity, KeyRound, Braces, Upload } from 'lucide-react';
|
||||||
import type { LucideIcon } from 'lucide-react';
|
import type { LucideIcon } from 'lucide-react';
|
||||||
import styles from './App.module.css';
|
import styles from './App.module.css';
|
||||||
import { SidePanel, ThemeSwitcher } from './ui';
|
import { SidePanel, ThemeSwitcher } from './ui';
|
||||||
import liqaLogo from './assets/liqa.svg';
|
import liqaLogo from './assets/liqa.svg';
|
||||||
|
import { useManifest } from './hooks/useManifest';
|
||||||
|
|
||||||
const EnvironmentsPage = lazy(() =>
|
const EnvironmentsPage = lazy(() =>
|
||||||
import('./pages/environment/EnvironmentsPage').then((m) => ({ default: m.EnvironmentsPage })),
|
import('./pages/environment/EnvironmentsPage').then((m) => ({ default: m.EnvironmentsPage })),
|
||||||
);
|
);
|
||||||
const EnvironmentDetailPage = lazy(() =>
|
const EnvironmentDetailPage = lazy(() =>
|
||||||
import('./pages/environment/EnvironmentDetailPage').then((m) => ({ default: m.EnvironmentDetailPage })),
|
import('./pages/environment/EnvironmentDetailPage').then((m) => ({
|
||||||
|
default: m.EnvironmentDetailPage,
|
||||||
|
})),
|
||||||
);
|
);
|
||||||
const CreateEnvironmentPage = lazy(() =>
|
const CreateEnvironmentPage = lazy(() =>
|
||||||
import('./pages/environment/CreateEnvironmentPage').then((m) => ({ default: m.CreateEnvironmentPage })),
|
import('./pages/environment/CreateEnvironmentPage').then((m) => ({
|
||||||
|
default: m.CreateEnvironmentPage,
|
||||||
|
})),
|
||||||
);
|
);
|
||||||
const EditEnvironmentPage = lazy(() =>
|
const EditEnvironmentPage = lazy(() =>
|
||||||
import('./pages/environment/EditEnvironmentPage').then((m) => ({ default: m.EditEnvironmentPage })),
|
import('./pages/environment/EditEnvironmentPage').then((m) => ({
|
||||||
|
default: m.EditEnvironmentPage,
|
||||||
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
const SessionsPage = lazy(() =>
|
const SessionsPage = lazy(() =>
|
||||||
@@ -46,9 +53,7 @@ const EditStepPage = lazy(() =>
|
|||||||
import('./pages/scenario/EditStepPage').then((m) => ({ default: m.EditStepPage })),
|
import('./pages/scenario/EditStepPage').then((m) => ({ default: m.EditStepPage })),
|
||||||
);
|
);
|
||||||
|
|
||||||
const RunsPage = lazy(() =>
|
const RunsPage = lazy(() => import('./pages/run/RunsPage').then((m) => ({ default: m.RunsPage })));
|
||||||
import('./pages/run/RunsPage').then((m) => ({ default: m.RunsPage })),
|
|
||||||
);
|
|
||||||
const RunDetailPage = lazy(() =>
|
const RunDetailPage = lazy(() =>
|
||||||
import('./pages/run/RunDetailPage').then((m) => ({ default: m.RunDetailPage })),
|
import('./pages/run/RunDetailPage').then((m) => ({ default: m.RunDetailPage })),
|
||||||
);
|
);
|
||||||
@@ -60,13 +65,17 @@ const CredentialsPage = lazy(() =>
|
|||||||
import('./pages/credential/CredentialsPage').then((m) => ({ default: m.CredentialsPage })),
|
import('./pages/credential/CredentialsPage').then((m) => ({ default: m.CredentialsPage })),
|
||||||
);
|
);
|
||||||
const CreateCredentialPage = lazy(() =>
|
const CreateCredentialPage = lazy(() =>
|
||||||
import('./pages/credential/CreateCredentialPage').then((m) => ({ default: m.CreateCredentialPage })),
|
import('./pages/credential/CreateCredentialPage').then((m) => ({
|
||||||
|
default: m.CreateCredentialPage,
|
||||||
|
})),
|
||||||
);
|
);
|
||||||
const EditCredentialPage = lazy(() =>
|
const EditCredentialPage = lazy(() =>
|
||||||
import('./pages/credential/EditCredentialPage').then((m) => ({ default: m.EditCredentialPage })),
|
import('./pages/credential/EditCredentialPage').then((m) => ({ default: m.EditCredentialPage })),
|
||||||
);
|
);
|
||||||
const CredentialDetailPage = lazy(() =>
|
const CredentialDetailPage = lazy(() =>
|
||||||
import('./pages/credential/CredentialDetailPage').then((m) => ({ default: m.CredentialDetailPage })),
|
import('./pages/credential/CredentialDetailPage').then((m) => ({
|
||||||
|
default: m.CredentialDetailPage,
|
||||||
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
const SnippetsPage = lazy(() =>
|
const SnippetsPage = lazy(() =>
|
||||||
@@ -81,18 +90,25 @@ const EditSnippetPage = lazy(() =>
|
|||||||
const SnippetDetailPage = lazy(() =>
|
const SnippetDetailPage = lazy(() =>
|
||||||
import('./pages/snippet/SnippetDetailPage').then((m) => ({ default: m.SnippetDetailPage })),
|
import('./pages/snippet/SnippetDetailPage').then((m) => ({ default: m.SnippetDetailPage })),
|
||||||
);
|
);
|
||||||
|
const ImportPage = lazy(() =>
|
||||||
|
import('./pages/import/ImportPage').then((m) => ({ default: m.ImportPage })),
|
||||||
|
);
|
||||||
|
|
||||||
const NAV: { path: string; labelKey: string; Icon: LucideIcon }[] = [
|
const NAV: ({ path: string; labelKey: string; Icon: LucideIcon } | { separator: true })[] = [
|
||||||
{ path: '/environments', labelKey: 'nav.environments', Icon: Globe },
|
|
||||||
{ path: '/credentials', labelKey: 'nav.credentials', Icon: KeyRound },
|
|
||||||
{ path: '/snippets', labelKey: 'nav.snippets', Icon: Braces },
|
|
||||||
{ path: '/sessions', labelKey: 'nav.sessions', Icon: Monitor },
|
|
||||||
{ path: '/scenarios', labelKey: 'nav.scenarios', Icon: ClipboardList },
|
|
||||||
{ path: '/runs', labelKey: 'nav.runs', Icon: Activity },
|
{ path: '/runs', labelKey: 'nav.runs', Icon: Activity },
|
||||||
|
{ path: '/sessions', labelKey: 'nav.sessions', Icon: Monitor },
|
||||||
|
{ separator: true },
|
||||||
|
{ path: '/scenarios', labelKey: 'nav.scenarios', Icon: ClipboardList },
|
||||||
|
{ path: '/snippets', labelKey: 'nav.snippets', Icon: Braces },
|
||||||
|
{ path: '/credentials', labelKey: 'nav.credentials', Icon: KeyRound },
|
||||||
|
{ path: '/environments', labelKey: 'nav.environments', Icon: Globe },
|
||||||
|
{ separator: true },
|
||||||
|
{ path: '/import', labelKey: 'nav.import', Icon: Upload },
|
||||||
];
|
];
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { version } = useManifest();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.shell}>
|
<div className={styles.shell}>
|
||||||
@@ -106,23 +122,46 @@ export default function App() {
|
|||||||
>
|
>
|
||||||
<div className={styles.sideContent}>
|
<div className={styles.sideContent}>
|
||||||
<nav className={styles.nav}>
|
<nav className={styles.nav}>
|
||||||
{NAV.map(({ path, labelKey, Icon }) => (
|
{NAV.map((item, index) =>
|
||||||
<NavLink
|
'separator' in item ? (
|
||||||
key={path}
|
<div key={`separator-${index}`} className={styles.navSeparator} />
|
||||||
to={path}
|
) : (
|
||||||
className={({ isActive }) =>
|
<NavLink
|
||||||
[styles.navItem, isActive ? styles.navItemActive : ''].filter(Boolean).join(' ')
|
key={item.path}
|
||||||
}
|
to={item.path}
|
||||||
>
|
className={({ isActive }) =>
|
||||||
<Icon size={16} className={styles.navIcon} aria-hidden="true" />
|
[styles.navItem, isActive ? styles.navItemActive : ''].filter(Boolean).join(' ')
|
||||||
{t(labelKey)}
|
}
|
||||||
</NavLink>
|
>
|
||||||
))}
|
<item.Icon size={16} className={styles.navIcon} aria-hidden="true" />
|
||||||
|
{t(item.labelKey)}
|
||||||
|
</NavLink>
|
||||||
|
),
|
||||||
|
)}
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div className={styles.sideFooter}>
|
<div className={styles.sideFooter}>
|
||||||
<ThemeSwitcher />
|
<ThemeSwitcher />
|
||||||
<div className={styles.version}>v{__APP_VERSION__}</div>
|
<div className={styles.version}>
|
||||||
|
<span
|
||||||
|
title={
|
||||||
|
version !== __APP_VERSION__
|
||||||
|
? t('nav.version_mismatch', { client: __APP_VERSION__ })
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
v{version}
|
||||||
|
</span>{' '}
|
||||||
|
·{' '}
|
||||||
|
<a
|
||||||
|
className={styles.versionLink}
|
||||||
|
href="/licenses.txt"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
{t('nav.licenses')}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</SidePanel>
|
</SidePanel>
|
||||||
@@ -150,6 +189,7 @@ export default function App() {
|
|||||||
<Route path="/credentials/:id/edit" element={<EditCredentialPage />} />
|
<Route path="/credentials/:id/edit" element={<EditCredentialPage />} />
|
||||||
<Route path="/credentials/:id" element={<CredentialDetailPage />} />
|
<Route path="/credentials/:id" element={<CredentialDetailPage />} />
|
||||||
<Route path="/snippets" element={<SnippetsPage />} />
|
<Route path="/snippets" element={<SnippetsPage />} />
|
||||||
|
<Route path="/import" element={<ImportPage />} />
|
||||||
<Route path="/snippets/new" element={<CreateSnippetPage />} />
|
<Route path="/snippets/new" element={<CreateSnippetPage />} />
|
||||||
<Route path="/snippets/:id/edit" element={<EditSnippetPage />} />
|
<Route path="/snippets/:id/edit" element={<EditSnippetPage />} />
|
||||||
<Route path="/snippets/:id" element={<SnippetDetailPage />} />
|
<Route path="/snippets/:id" element={<SnippetDetailPage />} />
|
||||||
|
|||||||
+167
-48
@@ -2,6 +2,10 @@ import type {
|
|||||||
PaginatedResponse,
|
PaginatedResponse,
|
||||||
Credential,
|
Credential,
|
||||||
Environment,
|
Environment,
|
||||||
|
FileMetadata,
|
||||||
|
FileListResponse,
|
||||||
|
ImportResult,
|
||||||
|
RunDefaults,
|
||||||
ScenarioCredential,
|
ScenarioCredential,
|
||||||
Session,
|
Session,
|
||||||
Scenario,
|
Scenario,
|
||||||
@@ -9,20 +13,32 @@ import type {
|
|||||||
ScenarioRunDetail,
|
ScenarioRunDetail,
|
||||||
ScenarioRunStep,
|
ScenarioRunStep,
|
||||||
ScenarioStep,
|
ScenarioStep,
|
||||||
|
ScenarioVersion,
|
||||||
Snippet,
|
Snippet,
|
||||||
|
SnippetVersion,
|
||||||
|
TraceMode,
|
||||||
|
UsedSnippet,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { emitApiErrorToast } from '../lib/toast-events';
|
import { emitApiErrorToast } from '../lib/toast-events';
|
||||||
|
|
||||||
// API calls are versioned under /api/v1 by default.
|
// API calls are versioned under /api/v1 by default.
|
||||||
// Set VITE_API_URL (for example, http://localhost:13000/api/v1) to use a different origin.
|
// Set VITE_API_URL (for example, http://localhost:13000/api/v1) to use a different origin.
|
||||||
const BASE_URL = ((import.meta.env.VITE_API_URL as string | undefined) ?? '/api/v1').replace(/\/$/, '');
|
const BASE_URL = ((import.meta.env.VITE_API_URL as string | undefined) ?? '/api/v1').replace(
|
||||||
|
/\/$/,
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
|
||||||
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||||
let res: Response;
|
let res: Response;
|
||||||
try {
|
try {
|
||||||
|
const headers = new Headers(init?.headers);
|
||||||
|
if (!(init?.body instanceof FormData) && !headers.has('Content-Type')) {
|
||||||
|
headers.set('Content-Type', 'application/json');
|
||||||
|
}
|
||||||
|
|
||||||
res = await fetch(`${BASE_URL}${path}`, {
|
res = await fetch(`${BASE_URL}${path}`, {
|
||||||
headers: { 'Content-Type': 'application/json', ...init?.headers },
|
|
||||||
...init,
|
...init,
|
||||||
|
headers,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message || 'Network request failed';
|
const message = (err as Error).message || 'Network request failed';
|
||||||
@@ -73,12 +89,6 @@ export const credentials = {
|
|||||||
exportCredential(id: string): Promise<unknown> {
|
exportCredential(id: string): Promise<unknown> {
|
||||||
return request(`/credentials/${id}/export`);
|
return request(`/credentials/${id}/export`);
|
||||||
},
|
},
|
||||||
importCredential(payload: unknown): Promise<Credential> {
|
|
||||||
return request('/credentials/import', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ── Snippets ──────────────────────────────────────────────────────────────────
|
// ── Snippets ──────────────────────────────────────────────────────────────────
|
||||||
@@ -90,7 +100,9 @@ export const snippets = {
|
|||||||
get(id: string): Promise<Snippet> {
|
get(id: string): Promise<Snippet> {
|
||||||
return request(`/snippets/${id}`);
|
return request(`/snippets/${id}`);
|
||||||
},
|
},
|
||||||
create(payload: Pick<Snippet, 'alias' | 'title' | 'code'> & { description?: string }): Promise<Snippet> {
|
create(
|
||||||
|
payload: Pick<Snippet, 'alias' | 'title' | 'code'> & { description?: string },
|
||||||
|
): Promise<Snippet> {
|
||||||
return request('/snippets', {
|
return request('/snippets', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
@@ -108,14 +120,12 @@ export const snippets = {
|
|||||||
remove(id: string): Promise<void> {
|
remove(id: string): Promise<void> {
|
||||||
return request(`/snippets/${id}`, { method: 'DELETE' });
|
return request(`/snippets/${id}`, { method: 'DELETE' });
|
||||||
},
|
},
|
||||||
exportSnippet(id: string): Promise<unknown> {
|
versions(id: string): Promise<SnippetVersion[]> {
|
||||||
return request(`/snippets/${id}/export`);
|
return request(`/snippets/${id}/versions`);
|
||||||
},
|
},
|
||||||
importSnippet(payload: unknown): Promise<Snippet> {
|
exportSnippet(id: string, version?: number): Promise<unknown> {
|
||||||
return request('/snippets/import', {
|
const query = version === undefined ? '' : `?version=${version}`;
|
||||||
method: 'POST',
|
return request(`/snippets/${id}/export${query}`);
|
||||||
body: JSON.stringify(payload),
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -128,13 +138,16 @@ export const environments = {
|
|||||||
get(id: string): Promise<Environment> {
|
get(id: string): Promise<Environment> {
|
||||||
return request(`/environments/${id}`);
|
return request(`/environments/${id}`);
|
||||||
},
|
},
|
||||||
create(name: string, data: Environment['data']): Promise<Environment> {
|
create(name: string, data: Environment['data'], description?: string): Promise<Environment> {
|
||||||
return request('/environments', {
|
return request('/environments', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ name, data }),
|
body: JSON.stringify({ name, description, data }),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
update(id: string, patch: Partial<Pick<Environment, 'name' | 'data'>>): Promise<Environment> {
|
update(
|
||||||
|
id: string,
|
||||||
|
patch: Partial<Pick<Environment, 'name' | 'description' | 'data'>>,
|
||||||
|
): Promise<Environment> {
|
||||||
return request(`/environments/${id}`, {
|
return request(`/environments/${id}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
body: JSON.stringify(patch),
|
body: JSON.stringify(patch),
|
||||||
@@ -146,19 +159,18 @@ export const environments = {
|
|||||||
exportEnvironment(id: string): Promise<unknown> {
|
exportEnvironment(id: string): Promise<unknown> {
|
||||||
return request(`/environments/${id}/export`);
|
return request(`/environments/${id}/export`);
|
||||||
},
|
},
|
||||||
importEnvironment(payload: unknown): Promise<Environment> {
|
|
||||||
return request('/environments/import', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(payload),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ── Sessions ──────────────────────────────────────────────────────────────────
|
// ── Sessions ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export const sessions = {
|
export const sessions = {
|
||||||
list(page = 1, limit = 50): Promise<PaginatedResponse<Session>> {
|
list(
|
||||||
return request(`/sessions?page=${page}&limit=${limit}`);
|
page = 1,
|
||||||
|
limit = 50,
|
||||||
|
orderBy = 'id',
|
||||||
|
orderDir: 'ASC' | 'DESC' = 'DESC',
|
||||||
|
): Promise<PaginatedResponse<Session>> {
|
||||||
|
return request(`/sessions?page=${page}&limit=${limit}&orderBy=${orderBy}&orderDir=${orderDir}`);
|
||||||
},
|
},
|
||||||
get(id: string): Promise<Session> {
|
get(id: string): Promise<Session> {
|
||||||
return request(`/sessions/${id}`);
|
return request(`/sessions/${id}`);
|
||||||
@@ -171,19 +183,29 @@ export const sessions = {
|
|||||||
// ── Scenarios ─────────────────────────────────────────────────────────────────
|
// ── Scenarios ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export const scenarios = {
|
export const scenarios = {
|
||||||
list(page = 1, limit = 50): Promise<PaginatedResponse<Scenario>> {
|
list(
|
||||||
return request(`/scenarios?page=${page}&limit=${limit}&orderBy=updatedAt&orderDir=DESC`);
|
page = 1,
|
||||||
|
limit = 50,
|
||||||
|
orderBy = 'updatedAt',
|
||||||
|
orderDir: 'ASC' | 'DESC' = 'DESC',
|
||||||
|
): Promise<PaginatedResponse<Scenario>> {
|
||||||
|
return request(
|
||||||
|
`/scenarios?page=${page}&limit=${limit}&orderBy=${orderBy}&orderDir=${orderDir}`,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
get(id: string): Promise<Scenario & { steps: ScenarioStep[] }> {
|
get(id: string): Promise<Scenario & { steps: ScenarioStep[] }> {
|
||||||
return request(`/scenarios/${id}`);
|
return request(`/scenarios/${id}`);
|
||||||
},
|
},
|
||||||
create(name: string): Promise<Scenario> {
|
create(name: string, description?: string, environmentId?: string): Promise<Scenario> {
|
||||||
return request('/scenarios', {
|
return request('/scenarios', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ name }),
|
body: JSON.stringify({ name, description, environmentId }),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
update(id: string, patch: Partial<Pick<Scenario, 'name'>>): Promise<Scenario> {
|
update(
|
||||||
|
id: string,
|
||||||
|
patch: Partial<Pick<Scenario, 'name' | 'description' | 'environmentId' | 'timeoutSeconds'>>,
|
||||||
|
): Promise<Scenario> {
|
||||||
return request(`/scenarios/${id}`, {
|
return request(`/scenarios/${id}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
body: JSON.stringify(patch),
|
body: JSON.stringify(patch),
|
||||||
@@ -192,12 +214,25 @@ export const scenarios = {
|
|||||||
remove(id: string): Promise<void> {
|
remove(id: string): Promise<void> {
|
||||||
return request(`/scenarios/${id}`, { method: 'DELETE' });
|
return request(`/scenarios/${id}`, { method: 'DELETE' });
|
||||||
},
|
},
|
||||||
run(id: string, environmentId: string): Promise<ScenarioRun> {
|
run(
|
||||||
|
id: string,
|
||||||
|
environmentId: string,
|
||||||
|
saveSession?: boolean,
|
||||||
|
traceMode?: TraceMode,
|
||||||
|
/** Scenario version to run; omit for the latest. */
|
||||||
|
version?: number,
|
||||||
|
): Promise<ScenarioRun> {
|
||||||
return request(`/scenarios/${id}/run`, {
|
return request(`/scenarios/${id}/run`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ environmentId }),
|
body: JSON.stringify({ environmentId, saveSession, traceMode, version }),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
versions(id: string): Promise<ScenarioVersion[]> {
|
||||||
|
return request(`/scenarios/${id}/versions`);
|
||||||
|
},
|
||||||
|
runDefaults(): Promise<RunDefaults> {
|
||||||
|
return request('/scenarios/run-defaults');
|
||||||
|
},
|
||||||
getRun(scenarioId: string, runId: string): Promise<ScenarioRunDetail> {
|
getRun(scenarioId: string, runId: string): Promise<ScenarioRunDetail> {
|
||||||
return request(`/scenarios/${scenarioId}/run/${runId}`);
|
return request(`/scenarios/${scenarioId}/run/${runId}`);
|
||||||
},
|
},
|
||||||
@@ -211,14 +246,37 @@ export const scenarios = {
|
|||||||
): Promise<PaginatedResponse<ScenarioRun & { stepRuns: ScenarioRunStep[] }>> {
|
): Promise<PaginatedResponse<ScenarioRun & { stepRuns: ScenarioRunStep[] }>> {
|
||||||
return request(`/scenarios/${scenarioId}/runs?page=${page}&limit=${limit}`);
|
return request(`/scenarios/${scenarioId}/runs?page=${page}&limit=${limit}`);
|
||||||
},
|
},
|
||||||
exportScenario(id: string): Promise<string> {
|
exportScenario(
|
||||||
return request(`/scenarios/${id}/export`);
|
id: string,
|
||||||
|
options: {
|
||||||
|
includeEnvironment: boolean;
|
||||||
|
credentialIds: string[];
|
||||||
|
snippetIds: string[];
|
||||||
|
version?: number;
|
||||||
|
} = {
|
||||||
|
includeEnvironment: false,
|
||||||
|
credentialIds: [],
|
||||||
|
snippetIds: [],
|
||||||
|
},
|
||||||
|
): Promise<string> {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
params.set('includeEnvironment', String(options.includeEnvironment));
|
||||||
|
if (options.version !== undefined) {
|
||||||
|
params.set('version', String(options.version));
|
||||||
|
}
|
||||||
|
for (const cid of options.credentialIds) {
|
||||||
|
params.append('credentialIds', cid);
|
||||||
|
}
|
||||||
|
for (const sid of options.snippetIds) {
|
||||||
|
params.append('snippetIds', sid);
|
||||||
|
}
|
||||||
|
return request(`/scenarios/${id}/export?${params.toString()}`);
|
||||||
},
|
},
|
||||||
importScenario(payload: unknown): Promise<Scenario> {
|
exportE2eTestUrl(id: string): string {
|
||||||
return request('/scenarios/import', {
|
return `${BASE_URL}/scenarios/${id}/export-e2e`;
|
||||||
method: 'POST',
|
},
|
||||||
body: JSON.stringify(payload),
|
usedSnippets(id: string): Promise<UsedSnippet[]> {
|
||||||
});
|
return request(`/scenarios/${id}/used-snippets`);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -229,12 +287,10 @@ export const runs = {
|
|||||||
page = 1,
|
page = 1,
|
||||||
limit = 20,
|
limit = 20,
|
||||||
status?: string,
|
status?: string,
|
||||||
): Promise<
|
orderBy = 'createdAt',
|
||||||
PaginatedResponse<
|
orderDir: 'ASC' | 'DESC' = 'DESC',
|
||||||
ScenarioRun & { stepRuns: ScenarioRunStep[]; scenario: { id: string; name: string } }
|
): Promise<PaginatedResponse<ScenarioRun & { scenario: { id: string; name: string } }>> {
|
||||||
>
|
const q = new URLSearchParams({ page: String(page), limit: String(limit), orderBy, orderDir });
|
||||||
> {
|
|
||||||
const q = new URLSearchParams({ page: String(page), limit: String(limit) });
|
|
||||||
if (status) q.set('status', status);
|
if (status) q.set('status', status);
|
||||||
return request(`/scenarios/runs?${q}`);
|
return request(`/scenarios/runs?${q}`);
|
||||||
},
|
},
|
||||||
@@ -242,13 +298,20 @@ export const runs = {
|
|||||||
scenarioId: string,
|
scenarioId: string,
|
||||||
page = 1,
|
page = 1,
|
||||||
limit = 20,
|
limit = 20,
|
||||||
|
orderBy = 'createdAt',
|
||||||
|
orderDir: 'ASC' | 'DESC' = 'DESC',
|
||||||
): Promise<PaginatedResponse<ScenarioRun & { stepRuns: ScenarioRunStep[] }>> {
|
): Promise<PaginatedResponse<ScenarioRun & { stepRuns: ScenarioRunStep[] }>> {
|
||||||
return request(`/scenarios/${scenarioId}/runs?page=${page}&limit=${limit}`);
|
return request(
|
||||||
|
`/scenarios/${scenarioId}/runs?page=${page}&limit=${limit}&orderBy=${orderBy}&orderDir=${orderDir}`,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
get(scenarioId: string, runId: string, q?: string): Promise<ScenarioRunDetail> {
|
get(scenarioId: string, runId: string, q?: string): Promise<ScenarioRunDetail> {
|
||||||
const qs = q?.trim() ? `?q=${encodeURIComponent(q.trim())}` : '';
|
const qs = q?.trim() ? `?q=${encodeURIComponent(q.trim())}` : '';
|
||||||
return request(`/scenarios/${scenarioId}/run/${runId}${qs}`);
|
return request(`/scenarios/${scenarioId}/run/${runId}${qs}`);
|
||||||
},
|
},
|
||||||
|
exportLogs(scenarioId: string, runId: string, format: 'csv' | 'md'): Promise<string> {
|
||||||
|
return request(`/scenarios/${scenarioId}/run/${runId}/logs/export?format=${format}`);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// ── Scenario Credentials ──────────────────────────────────────────────────────
|
// ── Scenario Credentials ──────────────────────────────────────────────────────
|
||||||
@@ -274,12 +337,14 @@ export const scenarioCredentials = {
|
|||||||
export interface CreateStepPayload {
|
export interface CreateStepPayload {
|
||||||
title?: string;
|
title?: string;
|
||||||
execCode?: string;
|
execCode?: string;
|
||||||
|
timeoutSeconds?: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateStepPayload {
|
export interface UpdateStepPayload {
|
||||||
title?: string;
|
title?: string;
|
||||||
order?: number;
|
order?: number;
|
||||||
execCode?: string;
|
execCode?: string;
|
||||||
|
timeoutSeconds?: number | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const steps = {
|
export const steps = {
|
||||||
@@ -302,3 +367,57 @@ export const steps = {
|
|||||||
return request(`/scenarios/${scenarioId}/steps/${stepId}`, { method: 'DELETE' });
|
return request(`/scenarios/${scenarioId}/steps/${stepId}`, { method: 'DELETE' });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ── Scenario Files ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const scenarioFiles = {
|
||||||
|
upload(scenarioId: string, file: File, expiresAt?: Date): Promise<FileMetadata> {
|
||||||
|
const form = new FormData();
|
||||||
|
form.append('file', file);
|
||||||
|
if (expiresAt) form.append('expiresAt', expiresAt.toISOString());
|
||||||
|
return request(`/scenarios/${scenarioId}/files`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: form,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
list(scenarioId: string, limit = 20, offset = 0): Promise<FileListResponse> {
|
||||||
|
return request(`/scenarios/${scenarioId}/files?limit=${limit}&offset=${offset}`);
|
||||||
|
},
|
||||||
|
/** Returns a URL that can be used as an <a href> for direct download. */
|
||||||
|
contentUrl(scenarioId: string, fileId: string): string {
|
||||||
|
return `${BASE_URL}/scenarios/${scenarioId}/files/${fileId}/content`;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// ── Run Files ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const runFiles = {
|
||||||
|
list(scenarioId: string, runId: string, limit = 20, offset = 0): Promise<FileListResponse> {
|
||||||
|
return request(`/scenarios/${scenarioId}/runs/${runId}/files?limit=${limit}&offset=${offset}`);
|
||||||
|
},
|
||||||
|
/** Returns a URL that can be used as an <a href> for direct download. */
|
||||||
|
contentUrl(scenarioId: string, runId: string, fileId: string): string {
|
||||||
|
return `${BASE_URL}/scenarios/${scenarioId}/runs/${runId}/files/${fileId}/content`;
|
||||||
|
},
|
||||||
|
remove(scenarioId: string, runId: string, fileId: string): Promise<void> {
|
||||||
|
return request(`/scenarios/${scenarioId}/runs/${runId}/files/${fileId}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// ── Import ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export const imports = {
|
||||||
|
/**
|
||||||
|
* Imports any mix of environments, credentials, snippets and scenarios from
|
||||||
|
* YAML (`---`-separated documents, each one item or a list of items).
|
||||||
|
*/
|
||||||
|
yaml(text: string): Promise<ImportResult> {
|
||||||
|
return request('/import', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/yaml' },
|
||||||
|
body: text,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
+107
-4
@@ -16,6 +16,7 @@ export interface EnvironmentData {
|
|||||||
export interface Environment {
|
export interface Environment {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
description?: string;
|
||||||
data: EnvironmentData;
|
data: EnvironmentData;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
@@ -40,10 +41,29 @@ export interface Snippet {
|
|||||||
title: string;
|
title: string;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
code: string;
|
code: string;
|
||||||
|
/** Latest version number. */
|
||||||
|
version: number;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SnippetVersion {
|
||||||
|
id: string;
|
||||||
|
snippetId: string;
|
||||||
|
version: number;
|
||||||
|
alias: string;
|
||||||
|
title: string;
|
||||||
|
description: string | null;
|
||||||
|
code: string;
|
||||||
|
createdAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A snippet referenced by a scenario's steps. */
|
||||||
|
export interface UsedSnippet extends Snippet {
|
||||||
|
/** Version pinned via runSnippet('alias@N'), or null for the latest. */
|
||||||
|
pinnedVersion: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
// ── Sessions ──────────────────────────────────────────────────────────────────
|
// ── Sessions ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export type SessionStatus = 'open' | 'closed';
|
export type SessionStatus = 'open' | 'closed';
|
||||||
@@ -66,6 +86,7 @@ export interface ScenarioStep {
|
|||||||
order: number;
|
order: number;
|
||||||
title: string | null;
|
title: string | null;
|
||||||
execCode: string | null;
|
execCode: string | null;
|
||||||
|
timeoutSeconds: number | null;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
@@ -82,23 +103,64 @@ export interface ScenarioCredential {
|
|||||||
export interface Scenario {
|
export interface Scenario {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
|
description?: string;
|
||||||
|
environmentId?: string | null;
|
||||||
|
timeoutSeconds?: number | null;
|
||||||
|
/** Latest version number. */
|
||||||
|
version: number;
|
||||||
|
environment?: Pick<Environment, 'id' | 'name'>;
|
||||||
steps?: ScenarioStep[];
|
steps?: ScenarioStep[];
|
||||||
scenarioCredentials?: ScenarioCredential[];
|
scenarioCredentials?: ScenarioCredential[];
|
||||||
|
lastRunStatus?: ScenarioRunStatus | null;
|
||||||
|
lastRunAt?: string | null;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ScenarioStepSnapshot {
|
||||||
|
id: string | null;
|
||||||
|
order: number;
|
||||||
|
title: string | null;
|
||||||
|
execCode: string | null;
|
||||||
|
timeoutSeconds: number | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ScenarioVersion {
|
||||||
|
id: string;
|
||||||
|
scenarioId: string;
|
||||||
|
version: number;
|
||||||
|
name: string;
|
||||||
|
description: string | null;
|
||||||
|
environmentId: string | null;
|
||||||
|
timeoutSeconds: number | null;
|
||||||
|
steps: ScenarioStepSnapshot[];
|
||||||
|
createdAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type ScenarioRunStatus = 'pending' | 'in_progress' | 'pass' | 'fail';
|
export type ScenarioRunStatus = 'pending' | 'in_progress' | 'pass' | 'fail';
|
||||||
|
|
||||||
|
export type TraceMode = 'on' | 'retain-on-failure' | 'off';
|
||||||
|
|
||||||
|
export interface RunDefaults {
|
||||||
|
traceMode: TraceMode;
|
||||||
|
}
|
||||||
|
|
||||||
export type RunStepStatus = 'waiting' | 'pending' | 'in_progress' | 'pass' | 'fail' | 'cancelled';
|
export type RunStepStatus = 'waiting' | 'pending' | 'in_progress' | 'pass' | 'fail' | 'cancelled';
|
||||||
|
|
||||||
export type LogLevel = 'log' | 'warn' | 'error';
|
export type LogLevel = 'debug' | 'log' | 'warn' | 'error';
|
||||||
|
|
||||||
export interface ScenarioRun {
|
export interface ScenarioRun {
|
||||||
id: string;
|
id: string;
|
||||||
scenarioId: string;
|
scenarioId: string;
|
||||||
environmentId: string;
|
environmentId: string | null;
|
||||||
|
sessionId?: string | null;
|
||||||
|
saveSession: boolean;
|
||||||
|
traceMode: TraceMode | null;
|
||||||
|
/** Scenario version the run executes; null for runs created before versioning. */
|
||||||
|
scenarioVersion: number | null;
|
||||||
scenario?: Pick<Scenario, 'id' | 'name'>;
|
scenario?: Pick<Scenario, 'id' | 'name'>;
|
||||||
|
environment?: Pick<Environment, 'id' | 'name'>;
|
||||||
|
session?: { id: string; sessionName: string };
|
||||||
status: ScenarioRunStatus;
|
status: ScenarioRunStatus;
|
||||||
stepRuns?: ScenarioRunStep[];
|
stepRuns?: ScenarioRunStep[];
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
@@ -108,8 +170,12 @@ export interface ScenarioRun {
|
|||||||
export interface ScenarioRunStep {
|
export interface ScenarioRunStep {
|
||||||
id: string;
|
id: string;
|
||||||
runId: string;
|
runId: string;
|
||||||
scenarioStepId: string;
|
/** Live step this run step came from; null once that step is deleted. */
|
||||||
scenarioStep: ScenarioStep;
|
scenarioStepId: string | null;
|
||||||
|
// Step content as of the run's scenario version
|
||||||
|
title: string | null;
|
||||||
|
execCode: string | null;
|
||||||
|
timeoutSeconds: number | null;
|
||||||
status: RunStepStatus;
|
status: RunStepStatus;
|
||||||
order: number;
|
order: number;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
@@ -123,7 +189,11 @@ export interface ScenarioRunLog {
|
|||||||
runId: string;
|
runId: string;
|
||||||
stepRunId: string | null;
|
stepRunId: string | null;
|
||||||
level: LogLevel;
|
level: LogLevel;
|
||||||
|
/** Where the message was generated, e.g. "step:2", "snippet:login", "assertion:pass". */
|
||||||
|
context: string | null;
|
||||||
message: string;
|
message: string;
|
||||||
|
/** JSON payload attached to the message (e.g. a created file's metadata), as a raw string. */
|
||||||
|
data: string | null;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,3 +201,36 @@ export interface ScenarioRunDetail extends ScenarioRun {
|
|||||||
stepRuns: ScenarioRunStep[];
|
stepRuns: ScenarioRunStep[];
|
||||||
logs: ScenarioRunLog[];
|
logs: ScenarioRunLog[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Files ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export interface FileMetadata {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
mimeType: string;
|
||||||
|
size: number;
|
||||||
|
sha256: string;
|
||||||
|
expiresAt: string | null;
|
||||||
|
createdAt: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FileListResponse {
|
||||||
|
items: FileMetadata[];
|
||||||
|
total: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Import ────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
export type ImportKind = 'environment' | 'credential' | 'snippet' | 'scenario';
|
||||||
|
|
||||||
|
export interface ImportedItem {
|
||||||
|
kind: ImportKind;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
/** Version stored for versioned kinds (snippets, scenarios). */
|
||||||
|
version?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ImportResult {
|
||||||
|
imported: ImportedItem[];
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
.helpButton {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
padding: 2px;
|
||||||
|
border: none;
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
background: none;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.helpButton:hover {
|
||||||
|
color: var(--color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.helpButton:focus-visible {
|
||||||
|
outline: none;
|
||||||
|
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.35);
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { CircleHelp, X } from 'lucide-react';
|
||||||
|
import { Modal, Button, MarkdownContent } from '../../ui';
|
||||||
|
import content from './code-help.md?raw';
|
||||||
|
import styles from './CodeHelpModal.module.css';
|
||||||
|
|
||||||
|
export interface CodeHelpModalProps {
|
||||||
|
open: boolean;
|
||||||
|
onClose: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reference for the script runtime (`context`, `expect`, ...) available to step and snippet code. */
|
||||||
|
export function CodeHelpModal({ open, onClose }: CodeHelpModalProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
open={open}
|
||||||
|
size="lg"
|
||||||
|
title={t('code_help.title')}
|
||||||
|
onClose={onClose}
|
||||||
|
footer={
|
||||||
|
<Button variant="secondary" onClick={onClose}>
|
||||||
|
<X size={14} />
|
||||||
|
{t('code_help.close')}
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<MarkdownContent content={content} />
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A (?) button that opens the {@link CodeHelpModal}; place it next to a code field label. */
|
||||||
|
export function CodeHelpButton() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={styles.helpButton}
|
||||||
|
onClick={() => setOpen(true)}
|
||||||
|
aria-label={t('code_help.open')}
|
||||||
|
title={t('code_help.open')}
|
||||||
|
>
|
||||||
|
<CircleHelp size={16} />
|
||||||
|
</button>
|
||||||
|
<CodeHelpModal open={open} onClose={() => setOpen(false)} />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { X, Trash2 } from 'lucide-react';
|
||||||
|
import { Modal, Button } from '../../ui';
|
||||||
|
|
||||||
|
export interface DeleteConfirmationModalProps {
|
||||||
|
open: boolean;
|
||||||
|
title: string;
|
||||||
|
message: string;
|
||||||
|
onClose: () => void;
|
||||||
|
onConfirm: () => void;
|
||||||
|
isDeleting: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DeleteConfirmationModal({
|
||||||
|
open,
|
||||||
|
title,
|
||||||
|
message,
|
||||||
|
onClose,
|
||||||
|
onConfirm,
|
||||||
|
isDeleting,
|
||||||
|
}: DeleteConfirmationModalProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
open={open}
|
||||||
|
title={title}
|
||||||
|
onClose={() => !isDeleting && onClose()}
|
||||||
|
footer={
|
||||||
|
<>
|
||||||
|
<Button variant="secondary" onClick={onClose} disabled={isDeleting}>
|
||||||
|
<X size={14} />
|
||||||
|
{t('common.button_cancel')}
|
||||||
|
</Button>
|
||||||
|
<Button variant="danger" onClick={onConfirm} disabled={isDeleting}>
|
||||||
|
<Trash2 size={14} />
|
||||||
|
{t('common.button_delete')}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{message}
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
.section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionTitle {
|
||||||
|
font-size: 0.8125rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-muted, #888);
|
||||||
|
margin: 0;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radioRow {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radioRow input[type='radio'] {
|
||||||
|
cursor: pointer;
|
||||||
|
accent-color: var(--color-primary);
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { X, Download } from 'lucide-react';
|
||||||
|
import { Modal, Button } from '../../ui';
|
||||||
|
import styles from './ExportLogsModal.module.css';
|
||||||
|
|
||||||
|
export type LogExportFormat = 'md' | 'csv';
|
||||||
|
|
||||||
|
export interface ExportLogsModalProps {
|
||||||
|
open: boolean;
|
||||||
|
format: LogExportFormat;
|
||||||
|
onFormatChange: (format: LogExportFormat) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
onExport: () => void;
|
||||||
|
isExporting: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ExportLogsModal({
|
||||||
|
open,
|
||||||
|
format,
|
||||||
|
onFormatChange,
|
||||||
|
onClose,
|
||||||
|
onExport,
|
||||||
|
isExporting,
|
||||||
|
}: ExportLogsModalProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
open={open}
|
||||||
|
title={t('runs.export_logs_modal_title')}
|
||||||
|
onClose={() => !isExporting && onClose()}
|
||||||
|
footer={
|
||||||
|
<>
|
||||||
|
<Button variant="secondary" onClick={onClose} disabled={isExporting}>
|
||||||
|
<X size={14} />
|
||||||
|
{t('common.button_cancel')}
|
||||||
|
</Button>
|
||||||
|
<Button variant="primary" onClick={onExport} disabled={isExporting}>
|
||||||
|
<Download size={14} />
|
||||||
|
{t('runs.action_export')}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<div className={styles.section}>
|
||||||
|
<h4 className={styles.sectionTitle}>{t('runs.export_logs_format')}</h4>
|
||||||
|
<label className={styles.radioRow}>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="log-export-format"
|
||||||
|
checked={format === 'md'}
|
||||||
|
onChange={() => onFormatChange('md')}
|
||||||
|
/>
|
||||||
|
<span>{t('runs.export_logs_format_md')}</span>
|
||||||
|
</label>
|
||||||
|
<label className={styles.radioRow}>
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
name="log-export-format"
|
||||||
|
checked={format === 'csv'}
|
||||||
|
onChange={() => onFormatChange('csv')}
|
||||||
|
/>
|
||||||
|
<span>{t('runs.export_logs_format_csv')}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
.exportModal {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 1.25rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.scenarioMeta {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
padding: 0.75rem 1rem;
|
||||||
|
background: var(--color-primary);
|
||||||
|
border-radius: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metaRow {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.75rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metaLabel {
|
||||||
|
font-size: 0.75rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--color-primary-fg);
|
||||||
|
opacity: 0.7;
|
||||||
|
min-width: 4rem;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.metaValue {
|
||||||
|
font-size: 0.875rem;
|
||||||
|
color: var(--color-primary-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.section {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sectionTitle {
|
||||||
|
font-size: 0.8125rem;
|
||||||
|
font-weight: 600;
|
||||||
|
color: var(--text-muted, #888);
|
||||||
|
margin: 0;
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.04em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkboxRow {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.checkboxRow input[type='checkbox'] {
|
||||||
|
cursor: pointer;
|
||||||
|
accent-color: var(--color-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.versions {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
font-size: var(--font-size-xs);
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { X, Upload } from 'lucide-react';
|
||||||
|
import { Modal, Button, UuidBadge } from '../../ui';
|
||||||
|
import type { Scenario, ScenarioCredential, UsedSnippet } from '../../api';
|
||||||
|
import styles from './ExportScenarioModal.module.css';
|
||||||
|
|
||||||
|
export interface ExportScenarioModalProps {
|
||||||
|
open: boolean;
|
||||||
|
scenario: Scenario | null;
|
||||||
|
scenarioCredentials: ScenarioCredential[];
|
||||||
|
environment: Pick<{ id: string; name: string }, 'id' | 'name'> | null;
|
||||||
|
includeEnvironment: boolean;
|
||||||
|
onIncludeEnvironmentChange: (v: boolean) => void;
|
||||||
|
includedCredentialIds: Set<string>;
|
||||||
|
onCredentialToggle: (id: string, checked: boolean) => void;
|
||||||
|
usedSnippets: UsedSnippet[];
|
||||||
|
includedSnippetIds: Set<string>;
|
||||||
|
onSnippetToggle: (id: string, checked: boolean) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
onExport: () => void;
|
||||||
|
isExporting: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ExportScenarioModal({
|
||||||
|
open,
|
||||||
|
scenario,
|
||||||
|
scenarioCredentials,
|
||||||
|
environment,
|
||||||
|
includeEnvironment,
|
||||||
|
onIncludeEnvironmentChange,
|
||||||
|
includedCredentialIds,
|
||||||
|
onCredentialToggle,
|
||||||
|
usedSnippets,
|
||||||
|
includedSnippetIds,
|
||||||
|
onSnippetToggle,
|
||||||
|
onClose,
|
||||||
|
onExport,
|
||||||
|
isExporting,
|
||||||
|
}: ExportScenarioModalProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
// One row per snippet, listing every version the scenario uses (latest or pinned)
|
||||||
|
const snippetRows = new Map<string, { alias: string; versions: number[] }>();
|
||||||
|
for (const s of usedSnippets) {
|
||||||
|
const row = snippetRows.get(s.id) ?? { alias: s.alias, versions: [] };
|
||||||
|
const version = s.pinnedVersion ?? s.version;
|
||||||
|
if (!row.versions.includes(version)) row.versions.push(version);
|
||||||
|
snippetRows.set(s.id, row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
open={open}
|
||||||
|
title={t('scenarios.export_modal_title')}
|
||||||
|
onClose={() => !isExporting && onClose()}
|
||||||
|
footer={
|
||||||
|
<>
|
||||||
|
<Button variant="secondary" onClick={onClose} disabled={isExporting}>
|
||||||
|
<X size={14} />
|
||||||
|
{t('common.button_cancel')}
|
||||||
|
</Button>
|
||||||
|
<Button variant="primary" onClick={onExport} disabled={isExporting}>
|
||||||
|
<Upload size={14} />
|
||||||
|
{t('scenarios.action_export')}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{scenario && (
|
||||||
|
<div className={styles.exportModal}>
|
||||||
|
<div className={styles.scenarioMeta}>
|
||||||
|
<div className={styles.metaRow}>
|
||||||
|
<span className={styles.metaLabel}>{t('scenarios.field_name')}</span>
|
||||||
|
<span className={styles.metaValue}>{scenario.name}</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.metaRow}>
|
||||||
|
<span className={styles.metaLabel}>{t('scenarios.field_id')}</span>
|
||||||
|
<span className={styles.metaValue}>
|
||||||
|
<UuidBadge id={scenario.id} />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className={styles.metaRow}>
|
||||||
|
<span className={styles.metaLabel}>{t('scenarios.field_version')}</span>
|
||||||
|
<span className={styles.metaValue}>v{scenario.version}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{environment && (
|
||||||
|
<div className={styles.section}>
|
||||||
|
<h4 className={styles.sectionTitle}>{t('scenarios.export_include_environment')}</h4>
|
||||||
|
<label className={styles.checkboxRow}>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={includeEnvironment}
|
||||||
|
onChange={(e) => onIncludeEnvironmentChange(e.target.checked)}
|
||||||
|
/>
|
||||||
|
<span>{environment.name}</span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{scenarioCredentials.length > 0 && (
|
||||||
|
<div className={styles.section}>
|
||||||
|
<h4 className={styles.sectionTitle}>{t('scenarios.export_include_credentials')}</h4>
|
||||||
|
{scenarioCredentials.map((sc) => (
|
||||||
|
<label key={sc.credentialId} className={styles.checkboxRow}>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={includedCredentialIds.has(sc.credentialId)}
|
||||||
|
onChange={(e) => onCredentialToggle(sc.credentialId, e.target.checked)}
|
||||||
|
/>
|
||||||
|
<span>{sc.credential?.name ?? sc.alias}</span>
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{snippetRows.size > 0 && (
|
||||||
|
<div className={styles.section}>
|
||||||
|
<h4 className={styles.sectionTitle}>{t('scenarios.export_include_snippets')}</h4>
|
||||||
|
{[...snippetRows].map(([snippetId, row]) => (
|
||||||
|
<label key={snippetId} className={styles.checkboxRow}>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={includedSnippetIds.has(snippetId)}
|
||||||
|
onChange={(e) => onSnippetToggle(snippetId, e.target.checked)}
|
||||||
|
/>
|
||||||
|
<span>{row.alias}</span>
|
||||||
|
<span className={styles.versions}>
|
||||||
|
{row.versions.map((v) => `v${v}`).join(', ')}
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { X, Play } from 'lucide-react';
|
||||||
|
import { Modal, Button, Select } from '../../ui';
|
||||||
|
import type { Environment, ScenarioVersion, TraceMode } from '../../api';
|
||||||
|
|
||||||
|
const TRACE_MODES: TraceMode[] = ['on', 'retain-on-failure', 'off'];
|
||||||
|
|
||||||
|
export interface RunScenarioModalProps {
|
||||||
|
open: boolean;
|
||||||
|
environments: Environment[];
|
||||||
|
selectedEnvId: string;
|
||||||
|
onEnvSelect: (envId: string) => void;
|
||||||
|
saveSessionFlag: boolean;
|
||||||
|
onSaveSessionChange: (flag: boolean) => void;
|
||||||
|
/** Scenario versions, newest first; empty while loading. */
|
||||||
|
versions: Pick<ScenarioVersion, 'version' | 'createdAt'>[];
|
||||||
|
/** Selected version, or null for the latest. */
|
||||||
|
selectedVersion: number | null;
|
||||||
|
onVersionChange: (version: number | null) => void;
|
||||||
|
traceMode: TraceMode;
|
||||||
|
defaultTraceMode: TraceMode | null;
|
||||||
|
onTraceModeChange: (mode: TraceMode) => void;
|
||||||
|
onClose: () => void;
|
||||||
|
onRun: () => void;
|
||||||
|
isRunning: boolean;
|
||||||
|
actionLabel?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RunScenarioModal({
|
||||||
|
open,
|
||||||
|
environments,
|
||||||
|
selectedEnvId,
|
||||||
|
onEnvSelect,
|
||||||
|
saveSessionFlag,
|
||||||
|
onSaveSessionChange,
|
||||||
|
versions,
|
||||||
|
selectedVersion,
|
||||||
|
onVersionChange,
|
||||||
|
traceMode,
|
||||||
|
defaultTraceMode,
|
||||||
|
onTraceModeChange,
|
||||||
|
onClose,
|
||||||
|
onRun,
|
||||||
|
isRunning,
|
||||||
|
actionLabel,
|
||||||
|
}: RunScenarioModalProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal
|
||||||
|
open={open}
|
||||||
|
title={t('scenarios.run_modal_title')}
|
||||||
|
onClose={() => !isRunning && onClose()}
|
||||||
|
footer={
|
||||||
|
<>
|
||||||
|
<Button variant="secondary" onClick={onClose} disabled={isRunning}>
|
||||||
|
<X size={14} />
|
||||||
|
{t('common.button_cancel')}
|
||||||
|
</Button>
|
||||||
|
<Button variant="primary" onClick={onRun} disabled={isRunning || !selectedEnvId}>
|
||||||
|
<Play size={14} />
|
||||||
|
{actionLabel || t('scenarios.action_run')}
|
||||||
|
</Button>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{environments.length === 0 ? (
|
||||||
|
<p>{t('scenarios.run_modal_no_env')}</p>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<Select
|
||||||
|
label={t('scenarios.run_modal_env_label')}
|
||||||
|
value={selectedEnvId}
|
||||||
|
onChange={(e) => onEnvSelect(e.target.value)}
|
||||||
|
options={environments.map((env) => ({ value: env.id, label: env.name }))}
|
||||||
|
/>
|
||||||
|
<div style={{ marginTop: '1rem' }}>
|
||||||
|
<Select
|
||||||
|
label={t('scenarios.run_modal_version_label')}
|
||||||
|
value={selectedVersion == null ? '' : String(selectedVersion)}
|
||||||
|
onChange={(e) => onVersionChange(e.target.value ? Number(e.target.value) : null)}
|
||||||
|
options={[
|
||||||
|
{
|
||||||
|
value: '',
|
||||||
|
label: versions[0]
|
||||||
|
? t('scenarios.run_modal_version_latest_n', { version: versions[0].version })
|
||||||
|
: t('scenarios.run_modal_version_latest'),
|
||||||
|
},
|
||||||
|
...versions.map((v) => ({
|
||||||
|
value: String(v.version),
|
||||||
|
label: `v${v.version} — ${new Date(v.createdAt).toLocaleString()}`,
|
||||||
|
})),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<label
|
||||||
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
marginTop: '1rem',
|
||||||
|
gap: '0.5rem',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
checked={saveSessionFlag}
|
||||||
|
onChange={(e) => onSaveSessionChange(e.target.checked)}
|
||||||
|
/>
|
||||||
|
<span>{t('common.save_session')}</span>
|
||||||
|
</label>
|
||||||
|
<div style={{ marginTop: '1rem' }}>
|
||||||
|
<Select
|
||||||
|
label={t('scenarios.run_modal_trace_label')}
|
||||||
|
value={traceMode}
|
||||||
|
onChange={(e) => onTraceModeChange(e.target.value as TraceMode)}
|
||||||
|
options={TRACE_MODES.map((mode) => ({
|
||||||
|
value: mode,
|
||||||
|
label:
|
||||||
|
t(`scenarios.trace_mode_${mode.replace(/-/g, '_')}`) +
|
||||||
|
(mode === defaultTraceMode ? ` ${t('scenarios.trace_mode_default_suffix')}` : ''),
|
||||||
|
}))}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
Step code and snippet code are the **body of an async function**. Use `await` freely; whatever you `return` becomes the step (or snippet) output.
|
||||||
|
|
||||||
|
```js
|
||||||
|
async (context) => {
|
||||||
|
// your code here
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
All steps of a run share one browser, one browser context and one page, so state carries over from step to step: the current URL, cookies, local storage, open dialogs.
|
||||||
|
|
||||||
|
A step **passes** when its code returns, and **fails** when it throws or exceeds its timeout. When a step fails, the remaining steps are cancelled, and a screenshot and the page HTML are saved to the run's files.
|
||||||
|
|
||||||
|
## Globals
|
||||||
|
|
||||||
|
| Name | Description |
|
||||||
|
| --- | --- |
|
||||||
|
| `context` | The run context, described below. |
|
||||||
|
| `expect` | Playwright's [`expect`](https://playwright.dev/docs/test-assertions), with auto-retrying web assertions. |
|
||||||
|
| `console` | Writes to the run log: `log`/`info` → `log`, plus `warn`, `error` and `debug`. |
|
||||||
|
| `args` | **Snippets only.** The extra arguments passed to `context.runSnippet(name, ...args)`. |
|
||||||
|
|
||||||
|
Code runs in the server process with Node.js. It is trusted code, not sandboxed.
|
||||||
|
|
||||||
|
## Browser
|
||||||
|
|
||||||
|
### `context.page`
|
||||||
|
|
||||||
|
The Playwright [`Page`](https://playwright.dev/docs/api/class-page) of the run.
|
||||||
|
|
||||||
|
```js
|
||||||
|
await context.page.goto(context.getEnv("base_url"));
|
||||||
|
await context.page.getByRole("button", { name: "Sign in" }).click();
|
||||||
|
await expect(context.page.locator("h1")).toHaveText("Dashboard");
|
||||||
|
```
|
||||||
|
|
||||||
|
### `context.browser`
|
||||||
|
|
||||||
|
The Playwright [`BrowserContext`](https://playwright.dev/docs/api/class-browsercontext) the page belongs to. Use it for cookies, storage state, extra pages and HTTP requests that share the browser's cookies.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const cookies = await context.browser.cookies();
|
||||||
|
const res = await context.browser.request.get(context.getEnv("api_url") + "/me");
|
||||||
|
```
|
||||||
|
|
||||||
|
### `context.dumpDom(selector?)` → `Promise<DomNode>`
|
||||||
|
|
||||||
|
Returns a simplified tree of the live DOM, starting at `selector` (default `"body"`). Decorative and layout elements are filtered out. The tree keeps landmarks, interactive elements, and elements with `role`, `data-testid`, `data-qa`, `data-action` or `data-element-id`. Each node has `tag` and `children`, plus `role`, `testid`, `id`, `name`, `type`, `text`, `href`, `checked`, `disabled`, etc. when they are present. This is useful for finding selectors without a screenshot.
|
||||||
|
|
||||||
|
If nothing matches `selector`, it returns a node with `tag: "ERROR"` instead of throwing.
|
||||||
|
|
||||||
|
```js
|
||||||
|
context.log("Login form:", await context.dumpDom("form"));
|
||||||
|
```
|
||||||
|
|
||||||
|
## Environment
|
||||||
|
|
||||||
|
### `context.env`
|
||||||
|
|
||||||
|
A copy of the selected environment's key/value map, `{}` when there is none. A missing key reads as `undefined`.
|
||||||
|
|
||||||
|
### `context.getEnv(key)` → `string`
|
||||||
|
|
||||||
|
Returns the environment value for `key`, and **throws** if it is not defined. Prefer it over `context.env[key]` for required settings: the step then fails with a clear message.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const baseUrl = context.getEnv("base_url");
|
||||||
|
const locale = context.env.locale ?? "en";
|
||||||
|
```
|
||||||
|
|
||||||
|
## Credentials
|
||||||
|
|
||||||
|
### `context.getCredential(alias)` → `unknown`
|
||||||
|
|
||||||
|
Returns the payload of the credential assigned to this scenario under `alias` (see **Credentials** on the scenario page). JSON data is returned parsed, anything else as a string. **Throws** if no credential has that alias.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { username, password } = context.getCredential("admin");
|
||||||
|
await context.page.getByLabel("Username").fill(username);
|
||||||
|
await context.page.getByLabel("Password").fill(password);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Step outputs
|
||||||
|
|
||||||
|
### `context.getStepOutput(order)` → `Promise<unknown>`
|
||||||
|
|
||||||
|
Returns the output (the return value) of another step in the same run. **It is async, so `await` it.**
|
||||||
|
|
||||||
|
- A positive `order` is absolute: `1` is the first step.
|
||||||
|
- A negative `order` is relative: `-1` is the previous step.
|
||||||
|
|
||||||
|
Returns `null` if that step does not exist, has not run, or returned nothing. A step's output is stored as JSON, so only JSON-serializable values come back as they were returned (no functions, `Date` becomes a string, Playwright objects are not usable).
|
||||||
|
|
||||||
|
```js
|
||||||
|
// step 2
|
||||||
|
return { orderId: await context.page.locator("#order-id").textContent() };
|
||||||
|
|
||||||
|
// step 3
|
||||||
|
const { orderId } = await context.getStepOutput(-1);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Logging
|
||||||
|
|
||||||
|
### `context.log(...args)`, `context.warn(...args)`, `context.error(...args)`, `context.debug(...args)`
|
||||||
|
|
||||||
|
Write an entry with that level to the run log. `console.*` does the same. Strings, numbers and booleans are joined with spaces into the message. Objects and arrays are kept separate as structured **data**, shown pretty-printed under the message: one object is stored as is, several are stored as an array.
|
||||||
|
|
||||||
|
```js
|
||||||
|
context.log("Created user", user.id, user); // message "Created user 42", data = user
|
||||||
|
```
|
||||||
|
|
||||||
|
Every entry is tagged with where it came from: `step:<N>`, or `snippet:<alias>` while a snippet runs.
|
||||||
|
|
||||||
|
## Assertions
|
||||||
|
|
||||||
|
### `context.assert(fn, description, details?)` → `Promise<void>`
|
||||||
|
|
||||||
|
Runs `fn` (sync or async) and requires it to return exactly `true`.
|
||||||
|
|
||||||
|
- On success, it logs `description` (tagged `assertion:pass`).
|
||||||
|
- If `fn` returns anything else or throws, it logs `Assertion failed: <description>` as an error (tagged `assertion:fail`) and throws, which fails the step. The entry's data holds `details` (if given) and the exception message as `error` (if `fn` threw).
|
||||||
|
|
||||||
|
Await it, or a failure will not stop the step.
|
||||||
|
|
||||||
|
```js
|
||||||
|
await context.assert(
|
||||||
|
async () => (await context.page.locator(".cart-item").count()) === 3,
|
||||||
|
"Cart contains 3 items",
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
Pass large diagnostics (e.g. a response body) as `details` rather than in `description`, so the message stays short:
|
||||||
|
|
||||||
|
```js
|
||||||
|
await context.assert(() => response.ok(), "Validation must pass", {
|
||||||
|
status: response.status(),
|
||||||
|
body: await response.json(),
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `expect` instead for assertions that wait and retry until the page matches, e.g. `await expect(locator).toBeVisible()`.
|
||||||
|
|
||||||
|
## Snippets
|
||||||
|
|
||||||
|
### `context.runSnippet(name, ...args)` → `Promise<unknown>`
|
||||||
|
|
||||||
|
Runs a stored snippet with the same `context` (same page, environment and credentials) and returns the snippet's return value. Extra arguments are available inside the snippet as `args`.
|
||||||
|
|
||||||
|
- `name` is the snippet alias, which runs its latest version.
|
||||||
|
- `alias@<version>` (e.g. `login@3`) pins a specific version.
|
||||||
|
|
||||||
|
Start, finish and failure are logged. If the snippet throws, the error propagates and fails the calling step unless you catch it. Snippets can call other snippets.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// step code
|
||||||
|
const user = await context.runSnippet("login", "admin", { remember: true });
|
||||||
|
|
||||||
|
// snippet "login"
|
||||||
|
const [alias, opts] = args;
|
||||||
|
const { username, password } = context.getCredential(alias);
|
||||||
|
// ...
|
||||||
|
return { username };
|
||||||
|
```
|
||||||
|
|
||||||
|
## Files
|
||||||
|
|
||||||
|
### `context.getScenarioFiles(opts?)` → `Promise<{ items, total }>`
|
||||||
|
|
||||||
|
Lists the files uploaded to this scenario (see **Files** on the scenario page). `opts` takes `limit` and `offset` for paging. Each item has `id`, `name`, `mimeType`, `size`, `sha256` and `path`, the absolute path on the server's disk, which you can pass to Playwright:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { items } = await context.getScenarioFiles();
|
||||||
|
const doc = items.find((f) => f.name === "contract.pdf");
|
||||||
|
await context.page.locator("input[type=file]").setInputFiles(doc.path);
|
||||||
|
```
|
||||||
|
|
||||||
|
### `context.downloadFile(url, opts?)` → `Promise<FileInfo>`
|
||||||
|
|
||||||
|
Fetches `url` on the server and saves the response as a file of the current run. It returns the same fields as a scenario file (`id`, `name`, `mimeType`, `size`, `sha256`, `path`).
|
||||||
|
|
||||||
|
- `opts`: `method`, `headers`, `body` (a string) and `filename`. Without `filename`, the last segment of the URL path is used, and the MIME type is derived from the file extension.
|
||||||
|
- Redirects are followed. Any final status other than 200 throws. The limits are 100 MB and a 30 s timeout.
|
||||||
|
- `url` may be a `data:` URI (`data:<type>;base64,<data>` or `data:<type>,<percent-encoded>`), which saves content generated in the script without a network request. Pass `filename` in this case.
|
||||||
|
- Only works during a real scenario run. It throws in ad-hoc execution such as the `exec_code` MCP tool.
|
||||||
|
- This is a server-side request: it does **not** send the browser's cookies. Pass them in `headers` if the URL needs a session.
|
||||||
|
|
||||||
|
```js
|
||||||
|
await context.downloadFile(
|
||||||
|
"data:application/json;base64," + btoa(JSON.stringify(report)),
|
||||||
|
{ filename: "report.json" },
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Timeouts
|
||||||
|
|
||||||
|
Each step has its own timeout, or else the scenario's timeout, or else 60 s. The whole run fails once it exceeds the scenario's timeout (600 s by default). That check happens between steps.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
export { DeleteConfirmationModal } from './DeleteConfirmationModal';
|
||||||
|
export type { DeleteConfirmationModalProps } from './DeleteConfirmationModal';
|
||||||
|
export { ExportScenarioModal } from './ExportScenarioModal';
|
||||||
|
export type { ExportScenarioModalProps } from './ExportScenarioModal';
|
||||||
|
export { RunScenarioModal } from './RunScenarioModal';
|
||||||
|
export type { RunScenarioModalProps } from './RunScenarioModal';
|
||||||
|
export { ExportLogsModal } from './ExportLogsModal';
|
||||||
|
export type { ExportLogsModalProps, LogExportFormat } from './ExportLogsModal';
|
||||||
|
export { CodeHelpModal, CodeHelpButton } from './CodeHelpModal';
|
||||||
|
export type { CodeHelpModalProps } from './CodeHelpModal';
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import type { ChangeEvent } from 'react';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { imports } from '../api';
|
||||||
|
import type { ImportedItem, ImportKind } from '../api';
|
||||||
|
import { useToast } from '../ui';
|
||||||
|
|
||||||
|
/** Detail page path of an imported item. */
|
||||||
|
export function importedItemPath(item: ImportedItem): string {
|
||||||
|
return `/${item.kind}s/${item.id}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a file input `onChange` handler that imports the chosen YAML file
|
||||||
|
* through the central import. When the file holds exactly one item of `kind`
|
||||||
|
* (e.g. a scenario export with its environment), opens that item; otherwise
|
||||||
|
* opens the import page with the full result.
|
||||||
|
*/
|
||||||
|
export function useImportFile(kind: ImportKind) {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const toast = useToast();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return async (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const file = e.target.files?.[0];
|
||||||
|
if (!file) return;
|
||||||
|
e.target.value = '';
|
||||||
|
try {
|
||||||
|
const result = await imports.yaml(await file.text());
|
||||||
|
const own = result.imported.filter((item) => item.kind === kind);
|
||||||
|
if (own.length === 1) {
|
||||||
|
if (result.imported.length > 1) {
|
||||||
|
toast.success(t('import.imported_count', { count: result.imported.length }));
|
||||||
|
}
|
||||||
|
navigate(importedItemPath(own[0]));
|
||||||
|
} else {
|
||||||
|
navigate('/import', { state: { results: [{ fileName: file.name, result }] } });
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// error toast is already emitted by the API client
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { useSyncExternalStore } from 'react';
|
||||||
|
import { getManifest, subscribeManifest, type Manifest } from '../lib/manifest';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Public client configuration from the server's /manifest.json: the cached
|
||||||
|
* copy (or defaults) at first, updated once the fresh one arrives.
|
||||||
|
*/
|
||||||
|
export function useManifest(): Manifest {
|
||||||
|
return useSyncExternalStore(subscribeManifest, getManifest);
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
|
const APP_NAME = 'Liqa';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets document.title to "<title> | Liqa" for the current page.
|
||||||
|
* Pass undefined or empty string to fall back to just "Liqa".
|
||||||
|
*/
|
||||||
|
export function usePageTitle(title: string | null | undefined): void {
|
||||||
|
useEffect(() => {
|
||||||
|
const prev = document.title;
|
||||||
|
document.title = title ? `${title} | ${APP_NAME}` : APP_NAME;
|
||||||
|
return () => {
|
||||||
|
document.title = prev;
|
||||||
|
};
|
||||||
|
}, [title]);
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import { scenarios } from '../api';
|
||||||
|
import type { RunDefaults } from '../api';
|
||||||
|
|
||||||
|
// Server run defaults don't change while the app is open; fetch them once
|
||||||
|
let cached: Promise<RunDefaults> | null = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the server-configured defaults for new scenario runs, or null
|
||||||
|
* while they are loading (or if the request failed).
|
||||||
|
*/
|
||||||
|
export function useRunDefaults(): RunDefaults | null {
|
||||||
|
const [defaults, setDefaults] = useState<RunDefaults | null>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
cached ??= scenarios.runDefaults().catch((err: unknown) => {
|
||||||
|
cached = null;
|
||||||
|
throw err;
|
||||||
|
});
|
||||||
|
cached.then((d) => !cancelled && setDefaults(d)).catch(() => undefined);
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
return defaults;
|
||||||
|
}
|
||||||
@@ -1,4 +1,22 @@
|
|||||||
{
|
{
|
||||||
|
"common": {
|
||||||
|
"button_cancel": "Cancel",
|
||||||
|
"button_confirm": "Confirm",
|
||||||
|
"button_delete": "Delete",
|
||||||
|
"confirm_delete_credential": "Are you sure you want to delete this credential?",
|
||||||
|
"confirm_delete_environment": "Are you sure you want to delete this environment?",
|
||||||
|
"confirm_delete_scenario": "Are you sure you want to delete this scenario?",
|
||||||
|
"confirm_delete_step": "Are you sure you want to delete this step?",
|
||||||
|
"confirm_delete_session": "Are you sure you want to delete this session?",
|
||||||
|
"confirm_delete_snippet": "Are you sure you want to delete this snippet?",
|
||||||
|
"confirm_remove_credential": "Are you sure you want to remove this credential from scenario?",
|
||||||
|
"save_session": "Save session"
|
||||||
|
},
|
||||||
|
"code_help": {
|
||||||
|
"open": "Code reference",
|
||||||
|
"title": "Code reference",
|
||||||
|
"close": "Close"
|
||||||
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
"not_found": "Not found",
|
"not_found": "Not found",
|
||||||
"not_found_session": "Session {{id}} does not exist or has been deleted.",
|
"not_found_session": "Session {{id}} does not exist or has been deleted.",
|
||||||
@@ -9,18 +27,40 @@
|
|||||||
"generic": "Something went wrong. Please try again."
|
"generic": "Something went wrong. Please try again."
|
||||||
},
|
},
|
||||||
"nav": {
|
"nav": {
|
||||||
|
"licenses": "Licenses",
|
||||||
|
"version_mismatch": "Server version; this page was built for v{{client}}. Reload to update.",
|
||||||
"environments": "Environments",
|
"environments": "Environments",
|
||||||
"credentials": "Credentials",
|
"credentials": "Credentials",
|
||||||
"snippets": "Snippets",
|
"snippets": "Snippets",
|
||||||
"keys": "Keys",
|
"keys": "Keys",
|
||||||
"sessions": "Sessions",
|
"sessions": "Sessions",
|
||||||
"scenarios": "Scenarios",
|
"scenarios": "Scenarios",
|
||||||
"runs": "Runs"
|
"runs": "Runs",
|
||||||
|
"import": "Import"
|
||||||
|
},
|
||||||
|
"import": {
|
||||||
|
"title": "Import",
|
||||||
|
"action_choose": "Choose files",
|
||||||
|
"description": "Import exported environments, credentials, snippets and scenarios. Each YAML file may hold several items as ---separated documents, and each document may hold one item or a list of items. JSON files work too.",
|
||||||
|
"description_validation": "Every item in a file is checked before anything is imported: if one item is invalid, nothing from that file is imported. Items are imported in dependency order (environments, credentials, snippets, scenarios), and snippets and scenarios keep the version they were exported with.",
|
||||||
|
"imported_count_one": "Imported {{count}} item",
|
||||||
|
"imported_count_other": "Imported {{count}} items",
|
||||||
|
"col_file": "File",
|
||||||
|
"col_kind": "Kind",
|
||||||
|
"col_name": "Name",
|
||||||
|
"col_version": "Version",
|
||||||
|
"kind_environment": "Environment",
|
||||||
|
"kind_credential": "Credential",
|
||||||
|
"kind_snippet": "Snippet",
|
||||||
|
"kind_scenario": "Scenario"
|
||||||
},
|
},
|
||||||
"environments": {
|
"environments": {
|
||||||
"title": "Environments",
|
"title": "Environments",
|
||||||
|
"created": "Environment created",
|
||||||
|
"updated": "Environment updated",
|
||||||
"col_id": "ID",
|
"col_id": "ID",
|
||||||
"col_name": "Name",
|
"col_name": "Name",
|
||||||
|
"col_description": "Description",
|
||||||
"col_data": "Data",
|
"col_data": "Data",
|
||||||
"col_updated": "Updated",
|
"col_updated": "Updated",
|
||||||
"empty": "No environments yet.",
|
"empty": "No environments yet.",
|
||||||
@@ -41,16 +81,21 @@
|
|||||||
"form_name": "Name",
|
"form_name": "Name",
|
||||||
"form_name_placeholder": "e.g. staging, production",
|
"form_name_placeholder": "e.g. staging, production",
|
||||||
"form_name_required": "Name is required",
|
"form_name_required": "Name is required",
|
||||||
|
"form_description": "Description",
|
||||||
|
"form_description_placeholder": "Describe this environment",
|
||||||
"form_data": "Data (JSON)",
|
"form_data": "Data (JSON)",
|
||||||
"form_data_invalid_json": "Must be a valid JSON object",
|
"form_data_invalid_json": "Must be a valid JSON object",
|
||||||
"back": "Environments",
|
"back": "Environments",
|
||||||
"field_id": "ID",
|
"field_id": "ID",
|
||||||
|
"field_description": "Description",
|
||||||
"field_created": "Created",
|
"field_created": "Created",
|
||||||
"field_updated": "Updated",
|
"field_updated": "Updated",
|
||||||
"section_data": "Data"
|
"section_data": "Data"
|
||||||
},
|
},
|
||||||
"credentials": {
|
"credentials": {
|
||||||
"title": "Credentials",
|
"title": "Credentials",
|
||||||
|
"created": "Credential created",
|
||||||
|
"updated": "Credential updated",
|
||||||
"empty": "No credentials yet.",
|
"empty": "No credentials yet.",
|
||||||
"loading": "Loading…",
|
"loading": "Loading…",
|
||||||
"menu_label": "Credential options",
|
"menu_label": "Credential options",
|
||||||
@@ -98,9 +143,16 @@
|
|||||||
"field_updated": "Updated",
|
"field_updated": "Updated",
|
||||||
"field_lastUsed": "Last Used"
|
"field_lastUsed": "Last Used"
|
||||||
},
|
},
|
||||||
"scenarios": { "title": "Scenarios",
|
"scenarios": {
|
||||||
|
"title": "Scenarios",
|
||||||
|
"created": "Scenario created",
|
||||||
|
"updated": "Scenario updated",
|
||||||
|
"run_started": "Scenario run started",
|
||||||
"col_id": "ID",
|
"col_id": "ID",
|
||||||
"col_name": "Name",
|
"col_name": "Name",
|
||||||
|
"col_version": "Version",
|
||||||
|
"col_description": "Description",
|
||||||
|
"col_last_run": "Last Run",
|
||||||
"col_updated": "Updated",
|
"col_updated": "Updated",
|
||||||
"empty": "No scenarios yet.",
|
"empty": "No scenarios yet.",
|
||||||
"loading": "Loading…",
|
"loading": "Loading…",
|
||||||
@@ -108,6 +160,8 @@
|
|||||||
"action_delete": "Delete",
|
"action_delete": "Delete",
|
||||||
"field_id": "ID",
|
"field_id": "ID",
|
||||||
"field_name": "Name",
|
"field_name": "Name",
|
||||||
|
"field_version": "Version",
|
||||||
|
"field_description": "Description",
|
||||||
"field_steps": "Steps",
|
"field_steps": "Steps",
|
||||||
"field_created": "Created",
|
"field_created": "Created",
|
||||||
"field_updated": "Updated",
|
"field_updated": "Updated",
|
||||||
@@ -121,6 +175,7 @@
|
|||||||
"action_edit": "Edit",
|
"action_edit": "Edit",
|
||||||
"action_runs": "Runs",
|
"action_runs": "Runs",
|
||||||
"action_export": "Export",
|
"action_export": "Export",
|
||||||
|
"action_export_e2e": "Export e2e test",
|
||||||
"action_import": "Import",
|
"action_import": "Import",
|
||||||
"import_error": "Failed to import scenario",
|
"import_error": "Failed to import scenario",
|
||||||
"action_save": "Create",
|
"action_save": "Create",
|
||||||
@@ -128,10 +183,18 @@
|
|||||||
"action_cancel": "Cancel",
|
"action_cancel": "Cancel",
|
||||||
"create_title": "New Scenario",
|
"create_title": "New Scenario",
|
||||||
"edit_title": "Edit Scenario",
|
"edit_title": "Edit Scenario",
|
||||||
|
"form_description": "Description",
|
||||||
|
"form_description_placeholder": "Describe this scenario",
|
||||||
|
"form_environment": "Default Environment",
|
||||||
|
"form_environment_none": "None (no default environment)",
|
||||||
|
"field_environment": "Default Environment",
|
||||||
"form_name": "Name",
|
"form_name": "Name",
|
||||||
"form_name_placeholder": "e.g. Login flow",
|
"form_name_placeholder": "e.g. Login flow",
|
||||||
"form_name_required": "Name is required",
|
"form_name_required": "Name is required",
|
||||||
"credentials_heading": "Credentials",
|
"credentials_heading": "Credentials",
|
||||||
|
"used_snippets_heading": "Used Snippets",
|
||||||
|
"used_snippet_pinned": "v{{version}} (pinned)",
|
||||||
|
"used_snippet_latest": "Latest (v{{version}})",
|
||||||
"cred_empty": "No credentials assigned.",
|
"cred_empty": "No credentials assigned.",
|
||||||
"cred_col_alias": "Alias",
|
"cred_col_alias": "Alias",
|
||||||
"cred_col_name": "Credential",
|
"cred_col_name": "Credential",
|
||||||
@@ -149,7 +212,22 @@
|
|||||||
"run_modal_title": "Select environment",
|
"run_modal_title": "Select environment",
|
||||||
"run_modal_env_label": "Environment",
|
"run_modal_env_label": "Environment",
|
||||||
"run_modal_no_env": "No environments found. Create an environment before running a scenario.",
|
"run_modal_no_env": "No environments found. Create an environment before running a scenario.",
|
||||||
"run_modal_env_required": "Please select an environment"
|
"run_modal_env_required": "Please select an environment",
|
||||||
|
"run_modal_version_label": "Version",
|
||||||
|
"run_modal_version_latest": "Latest",
|
||||||
|
"run_modal_version_latest_n": "Latest (v{{version}})",
|
||||||
|
"run_modal_trace_label": "Playwright trace",
|
||||||
|
"trace_mode_on": "Always keep",
|
||||||
|
"trace_mode_retain_on_failure": "Keep on failure",
|
||||||
|
"trace_mode_off": "Off",
|
||||||
|
"trace_mode_default_suffix": "(default)",
|
||||||
|
"export_modal_title": "Export Scenario",
|
||||||
|
"export_include_environment": "Include Environment",
|
||||||
|
"export_include_credentials": "Include Credentials",
|
||||||
|
"export_include_snippets": "Include Snippets",
|
||||||
|
"form_timeout": "Scenario Timeout (seconds)",
|
||||||
|
"form_timeout_placeholder": "Default: 600",
|
||||||
|
"form_timeout_hint": "Max seconds for the entire scenario run (default: 600)"
|
||||||
},
|
},
|
||||||
"theme": {
|
"theme": {
|
||||||
"switch_to_light": "Switch to light theme",
|
"switch_to_light": "Switch to light theme",
|
||||||
@@ -157,6 +235,11 @@
|
|||||||
"light_mode": "Light mode",
|
"light_mode": "Light mode",
|
||||||
"dark_mode": "Dark mode"
|
"dark_mode": "Dark mode"
|
||||||
},
|
},
|
||||||
|
"revealable": {
|
||||||
|
"hidden": "Hidden so secrets aren't exposed on screen.",
|
||||||
|
"reveal": "Reveal",
|
||||||
|
"hide": "Hide"
|
||||||
|
},
|
||||||
"pagination": {
|
"pagination": {
|
||||||
"prev": "Previous page",
|
"prev": "Previous page",
|
||||||
"next": "Next page",
|
"next": "Next page",
|
||||||
@@ -165,6 +248,8 @@
|
|||||||
"page_size": "Items per page"
|
"page_size": "Items per page"
|
||||||
},
|
},
|
||||||
"steps": {
|
"steps": {
|
||||||
|
"created": "Step created",
|
||||||
|
"updated": "Step updated",
|
||||||
"create_title": "Add Step",
|
"create_title": "Add Step",
|
||||||
"edit_title": "Edit Step #{{order}}",
|
"edit_title": "Edit Step #{{order}}",
|
||||||
"loading": "Loading…",
|
"loading": "Loading…",
|
||||||
@@ -183,7 +268,10 @@
|
|||||||
"form_session_placeholder": "e.g. my-session",
|
"form_session_placeholder": "e.g. my-session",
|
||||||
"form_session_required": "Session name is required",
|
"form_session_required": "Session name is required",
|
||||||
"form_exec_code": "Exec code",
|
"form_exec_code": "Exec code",
|
||||||
"form_exec_code_placeholder": "return await page.title();"
|
"form_exec_code_placeholder": "return await page.title();",
|
||||||
|
"form_timeout": "Step Timeout (seconds)",
|
||||||
|
"form_timeout_placeholder": "Default: 60",
|
||||||
|
"form_timeout_hint": "Max seconds for this step (default: 60)"
|
||||||
},
|
},
|
||||||
"runs": {
|
"runs": {
|
||||||
"title": "Runs",
|
"title": "Runs",
|
||||||
@@ -194,12 +282,15 @@
|
|||||||
"col_scenario": "Scenario",
|
"col_scenario": "Scenario",
|
||||||
"col_status": "Status",
|
"col_status": "Status",
|
||||||
"col_steps": "Steps",
|
"col_steps": "Steps",
|
||||||
|
"col_version": "Version",
|
||||||
"col_created": "Started",
|
"col_created": "Started",
|
||||||
"field_id": "ID",
|
"field_id": "ID",
|
||||||
"field_status": "Status",
|
"field_status": "Status",
|
||||||
"field_steps": "Steps",
|
"field_steps": "Steps",
|
||||||
"field_created": "Started",
|
"field_created": "Started",
|
||||||
"field_updated": "Updated",
|
"field_updated": "Updated",
|
||||||
|
"field_trace": "Playwright trace",
|
||||||
|
"field_scenario_version": "Scenario version",
|
||||||
"steps_heading": "Step runs",
|
"steps_heading": "Step runs",
|
||||||
"step_title": "Title",
|
"step_title": "Title",
|
||||||
"logs_heading": "Logs",
|
"logs_heading": "Logs",
|
||||||
@@ -211,10 +302,28 @@
|
|||||||
"step_description": "Result",
|
"step_description": "Result",
|
||||||
"log_level": "Level",
|
"log_level": "Level",
|
||||||
"log_message": "Message",
|
"log_message": "Message",
|
||||||
"log_time": "Time"
|
"log_time": "Time",
|
||||||
|
"action_download_logs": "Download logs",
|
||||||
|
"action_copy_logs": "Copy logs",
|
||||||
|
"logs_copied": "Logs copied to clipboard",
|
||||||
|
"logs_copy_failed": "Could not copy logs to clipboard",
|
||||||
|
"logs_expand_data": "Expand data",
|
||||||
|
"logs_collapse_data": "Collapse data",
|
||||||
|
"logs_show_data_one": "Show data ({{size}}, {{count}} line)",
|
||||||
|
"logs_show_data_other": "Show data ({{size}}, {{count}} lines)",
|
||||||
|
"logs_hide_data": "Hide data",
|
||||||
|
"action_repeat": "Repeat run",
|
||||||
|
"repeat_no_environment": "The environment used by this run no longer exists",
|
||||||
|
"export_logs_modal_title": "Export logs",
|
||||||
|
"export_logs_format": "Format",
|
||||||
|
"export_logs_format_md": "Markdown (.md)",
|
||||||
|
"export_logs_format_csv": "CSV (.csv)",
|
||||||
|
"action_export": "Export"
|
||||||
},
|
},
|
||||||
"snippets": {
|
"snippets": {
|
||||||
"title": "Snippets",
|
"title": "Snippets",
|
||||||
|
"created": "Snippet created",
|
||||||
|
"updated": "Snippet updated",
|
||||||
"empty": "No snippets yet.",
|
"empty": "No snippets yet.",
|
||||||
"loading": "Loading…",
|
"loading": "Loading…",
|
||||||
"menu_label": "Snippet options",
|
"menu_label": "Snippet options",
|
||||||
@@ -239,6 +348,7 @@
|
|||||||
"form_code_required": "Code is required",
|
"form_code_required": "Code is required",
|
||||||
"field_id": "ID",
|
"field_id": "ID",
|
||||||
"field_alias": "Alias",
|
"field_alias": "Alias",
|
||||||
|
"field_version": "Version",
|
||||||
"field_title": "Title",
|
"field_title": "Title",
|
||||||
"field_description": "Description",
|
"field_description": "Description",
|
||||||
"field_created": "Created",
|
"field_created": "Created",
|
||||||
@@ -247,5 +357,26 @@
|
|||||||
"action_export": "Export",
|
"action_export": "Export",
|
||||||
"action_import": "Import",
|
"action_import": "Import",
|
||||||
"import_error": "Failed to import snippet"
|
"import_error": "Failed to import snippet"
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
"title": "Files",
|
||||||
|
"upload": "Upload",
|
||||||
|
"uploadTitle": "Upload File",
|
||||||
|
"uploadSuccess": "File uploaded successfully",
|
||||||
|
"name": "Name",
|
||||||
|
"mimeType": "MIME Type",
|
||||||
|
"size": "Size",
|
||||||
|
"expiresAt": "Expires At",
|
||||||
|
"expiresAtLabel": "Expires At (optional)",
|
||||||
|
"createdAt": "Created",
|
||||||
|
"download": "Download",
|
||||||
|
"delete": "Delete",
|
||||||
|
"deleteTitle": "Delete file",
|
||||||
|
"confirmDelete": "Are you sure you want to delete \"{{name}}\" from this run?",
|
||||||
|
"deleteSuccess": "File deleted",
|
||||||
|
"expiredTooltip": "File is expired",
|
||||||
|
"empty": "No files uploaded.",
|
||||||
|
"totalCount": "Total: {{count}} file(s)",
|
||||||
|
"artifactsTitle": "Artifacts"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
import { DEFAULT_LOG_DATA_LIMITS, type LogDataLimits } from '../ui/LogOutput/logText';
|
||||||
|
|
||||||
|
/** Public client configuration served by the server at /manifest.json. */
|
||||||
|
export interface Manifest {
|
||||||
|
name: string;
|
||||||
|
/** Server version; can differ from the client build's __APP_VERSION__ until the page is reloaded. */
|
||||||
|
version: string;
|
||||||
|
runLogs: {
|
||||||
|
dataLimits: LogDataLimits;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DEFAULT_MANIFEST: Manifest = {
|
||||||
|
name: 'liqa',
|
||||||
|
version: __APP_VERSION__,
|
||||||
|
runLogs: { dataLimits: DEFAULT_LOG_DATA_LIMITS },
|
||||||
|
};
|
||||||
|
|
||||||
|
const STORAGE_KEY = 'liqa-manifest';
|
||||||
|
/** A tab coming back into view refetches the manifest if it is older than this. */
|
||||||
|
const REFRESH_AFTER_MS = 5 * 60 * 1000;
|
||||||
|
|
||||||
|
// Served next to the API's /api/v1 (so "/manifest.json" by default, or on
|
||||||
|
// VITE_API_URL's origin when the client talks to another server)
|
||||||
|
const MANIFEST_URL = new URL(
|
||||||
|
'../../manifest.json',
|
||||||
|
new URL(
|
||||||
|
`${(import.meta.env.VITE_API_URL ?? '/api/v1').replace(/\/$/, '')}/`,
|
||||||
|
window.location.href,
|
||||||
|
),
|
||||||
|
).toString();
|
||||||
|
|
||||||
|
/** Fills fields missing from `raw` (e.g. a manifest cached by an older version) with defaults. */
|
||||||
|
function normalize(raw: unknown): Manifest | null {
|
||||||
|
if (typeof raw !== 'object' || raw === null) return null;
|
||||||
|
const m = raw as Partial<Manifest>;
|
||||||
|
const limits: Partial<LogDataLimits> = m.runLogs?.dataLimits ?? {};
|
||||||
|
const num = (v: unknown, fallback: number) => (typeof v === 'number' && v >= 0 ? v : fallback);
|
||||||
|
return {
|
||||||
|
name: typeof m.name === 'string' ? m.name : DEFAULT_MANIFEST.name,
|
||||||
|
version: typeof m.version === 'string' ? m.version : DEFAULT_MANIFEST.version,
|
||||||
|
runLogs: {
|
||||||
|
dataLimits: {
|
||||||
|
bytes: num(limits.bytes, DEFAULT_LOG_DATA_LIMITS.bytes),
|
||||||
|
lines: num(limits.lines, DEFAULT_LOG_DATA_LIMITS.lines),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Storage can be unavailable (private mode, blocked site data): the manifest
|
||||||
|
// then just comes from the network on every page load
|
||||||
|
function readCache(): Manifest | null {
|
||||||
|
try {
|
||||||
|
const stored = localStorage.getItem(STORAGE_KEY);
|
||||||
|
return stored ? normalize(JSON.parse(stored)) : null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeCache(manifest: Manifest) {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(manifest));
|
||||||
|
} catch {
|
||||||
|
// ignore, see readCache
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let current: Manifest = readCache() ?? DEFAULT_MANIFEST;
|
||||||
|
let fetchedAt = 0;
|
||||||
|
let inFlight: Promise<void> | null = null;
|
||||||
|
const listeners = new Set<() => void>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetches the manifest and notifies subscribers if it changed. Failures are
|
||||||
|
* silent: the cached (or default) manifest stays in use.
|
||||||
|
*/
|
||||||
|
export function refreshManifest(): Promise<void> {
|
||||||
|
inFlight ??= fetch(MANIFEST_URL, { headers: { Accept: 'application/json' } })
|
||||||
|
.then((res) => (res.ok ? res.json() : null))
|
||||||
|
.then((raw: unknown) => {
|
||||||
|
const next = normalize(raw);
|
||||||
|
if (!next) return;
|
||||||
|
fetchedAt = Date.now();
|
||||||
|
writeCache(next);
|
||||||
|
if (JSON.stringify(next) !== JSON.stringify(current)) {
|
||||||
|
current = next;
|
||||||
|
listeners.forEach((l) => l());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => undefined)
|
||||||
|
.finally(() => {
|
||||||
|
inFlight = null;
|
||||||
|
});
|
||||||
|
return inFlight;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onVisibilityChange() {
|
||||||
|
if (document.visibilityState === 'visible' && Date.now() - fetchedAt > REFRESH_AFTER_MS) {
|
||||||
|
void refreshManifest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stale-while-revalidate: subscribers get the localStorage copy right away,
|
||||||
|
* and the manifest is refetched once per page load (the server answers 304
|
||||||
|
* while it is unchanged) and when the tab becomes visible again after a while.
|
||||||
|
*/
|
||||||
|
export function subscribeManifest(listener: () => void): () => void {
|
||||||
|
if (listeners.size === 0) document.addEventListener('visibilitychange', onVisibilityChange);
|
||||||
|
listeners.add(listener);
|
||||||
|
if (fetchedAt === 0) void refreshManifest();
|
||||||
|
return () => {
|
||||||
|
listeners.delete(listener);
|
||||||
|
if (listeners.size === 0) document.removeEventListener('visibilitychange', onVisibilityChange);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getManifest(): Manifest {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ export interface ApiErrorToastDetail {
|
|||||||
|
|
||||||
export function emitApiErrorToast(message: string): void {
|
export function emitApiErrorToast(message: string): void {
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
|
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new CustomEvent<ApiErrorToastDetail>(API_ERROR_TOAST_EVENT, {
|
new CustomEvent<ApiErrorToastDetail>(API_ERROR_TOAST_EVENT, {
|
||||||
detail: { message },
|
detail: { message },
|
||||||
@@ -13,17 +14,17 @@ export function emitApiErrorToast(message: string): void {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function subscribeApiErrorToasts(
|
export function subscribeApiErrorToasts(handler: (message: string) => void): () => void {
|
||||||
handler: (message: string) => void,
|
|
||||||
): () => void {
|
|
||||||
if (typeof window === 'undefined') return () => {};
|
if (typeof window === 'undefined') return () => {};
|
||||||
|
|
||||||
const listener = (event: Event) => {
|
const listener = (event: Event) => {
|
||||||
const custom = event as CustomEvent<ApiErrorToastDetail>;
|
const custom = event as CustomEvent<ApiErrorToastDetail>;
|
||||||
const message = custom.detail?.message;
|
const message = custom.detail?.message;
|
||||||
if (message) handler(message);
|
if (message) handler(message);
|
||||||
};
|
};
|
||||||
window.addEventListener(API_ERROR_TOAST_EVENT, listener as EventListener);
|
|
||||||
|
window.addEventListener(API_ERROR_TOAST_EVENT, listener);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener(API_ERROR_TOAST_EVENT, listener as EventListener);
|
window.removeEventListener(API_ERROR_TOAST_EVENT, listener);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
+10
-5
@@ -1,17 +1,22 @@
|
|||||||
import { StrictMode } from 'react';
|
import { StrictMode } from 'react';
|
||||||
import { createRoot } from 'react-dom/client';
|
import { createRoot } from 'react-dom/client';
|
||||||
import { BrowserRouter } from 'react-router-dom';
|
import { BrowserRouter } from 'react-router-dom';
|
||||||
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||||
import './i18n';
|
import './i18n';
|
||||||
import './ui/tokens.css';
|
import './ui/tokens.css';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import { ToastProvider } from './ui';
|
import { ToastProvider } from './ui';
|
||||||
|
|
||||||
|
const queryClient = new QueryClient();
|
||||||
|
|
||||||
createRoot(document.getElementById('root')!).render(
|
createRoot(document.getElementById('root')!).render(
|
||||||
<StrictMode>
|
<StrictMode>
|
||||||
<ToastProvider>
|
<QueryClientProvider client={queryClient}>
|
||||||
<BrowserRouter>
|
<ToastProvider>
|
||||||
<App />
|
<BrowserRouter>
|
||||||
</BrowserRouter>
|
<App />
|
||||||
</ToastProvider>
|
</BrowserRouter>
|
||||||
|
</ToastProvider>
|
||||||
|
</QueryClientProvider>
|
||||||
</StrictMode>,
|
</StrictMode>,
|
||||||
);
|
);
|
||||||
@@ -255,6 +255,12 @@
|
|||||||
color: var(--color-text);
|
color: var(--color-text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.labelRow {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-1);
|
||||||
|
}
|
||||||
|
|
||||||
.textarea {
|
.textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: var(--space-2) var(--space-3);
|
padding: var(--space-2) var(--space-3);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState, SubmitEvent } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { KeyRound, X, Save } from 'lucide-react';
|
import { KeyRound, X, Save } from 'lucide-react';
|
||||||
import { credentials } from '../../api';
|
import { credentials } from '../../api';
|
||||||
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
||||||
@@ -8,6 +9,7 @@ import styles from '../Page.module.css';
|
|||||||
|
|
||||||
export function CreateCredentialPage() {
|
export function CreateCredentialPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
usePageTitle(t('credentials.create_title'));
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
@@ -16,9 +18,8 @@ export function CreateCredentialPage() {
|
|||||||
const [nameError, setNameError] = useState('');
|
const [nameError, setNameError] = useState('');
|
||||||
const [dataError, setDataError] = useState('');
|
const [dataError, setDataError] = useState('');
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let valid = true;
|
let valid = true;
|
||||||
if (!name.trim()) {
|
if (!name.trim()) {
|
||||||
@@ -35,14 +36,12 @@ export function CreateCredentialPage() {
|
|||||||
}
|
}
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
|
||||||
try {
|
try {
|
||||||
const credential = await credentials.create(name.trim(), data.trim() || undefined);
|
const credential = await credentials.create(name.trim(), data.trim() || undefined);
|
||||||
toast.success('Credential created');
|
toast.success(t('credentials.created'));
|
||||||
navigate(`/credentials/${credential.id}`);
|
navigate(`/credentials/${credential.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message;
|
const message = (err as Error).message;
|
||||||
setError(message);
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
@@ -54,7 +53,11 @@ export function CreateCredentialPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('credentials.title'), icon: <KeyRound size={14} />, onClick: () => navigate('/credentials') },
|
{
|
||||||
|
label: t('credentials.title'),
|
||||||
|
icon: <KeyRound size={14} />,
|
||||||
|
onClick: () => navigate('/credentials'),
|
||||||
|
},
|
||||||
{ label: t('credentials.create_title') },
|
{ label: t('credentials.create_title') },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { Upload, Pencil, Trash2, KeyRound } from 'lucide-react';
|
import { Upload, Pencil, Trash2, KeyRound } from 'lucide-react';
|
||||||
import { CodeBlock } from '../../ui';
|
|
||||||
import { stringify as yamlStringify } from 'yaml';
|
import { stringify as yamlStringify } from 'yaml';
|
||||||
import { credentials } from '../../api';
|
import { credentials } from '../../api';
|
||||||
import type { Credential } from '../../api';
|
import type { Credential } from '../../api';
|
||||||
@@ -11,10 +11,11 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Card,
|
Card,
|
||||||
DescriptionList,
|
DescriptionList,
|
||||||
Modal,
|
RevealableCodeBlock,
|
||||||
Timestamp,
|
Timestamp,
|
||||||
UuidBadge,
|
UuidBadge,
|
||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
|
import { DeleteConfirmationModal } from '../../components/modals';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function CredentialDetailPage() {
|
export function CredentialDetailPage() {
|
||||||
@@ -23,7 +24,7 @@ export function CredentialDetailPage() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [credential, setCredential] = useState<Credential | null>(null);
|
const [credential, setCredential] = useState<Credential | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
usePageTitle(credential?.name ?? null);
|
||||||
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false);
|
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
|
|
||||||
@@ -32,7 +33,6 @@ export function CredentialDetailPage() {
|
|||||||
credentials
|
credentials
|
||||||
.get(id)
|
.get(id)
|
||||||
.then(setCredential)
|
.then(setCredential)
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
@@ -65,7 +65,11 @@ export function CredentialDetailPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('credentials.title'), icon: <KeyRound size={14} />, onClick: () => navigate('/credentials') },
|
{
|
||||||
|
label: t('credentials.title'),
|
||||||
|
icon: <KeyRound size={14} />,
|
||||||
|
onClick: () => navigate('/credentials'),
|
||||||
|
},
|
||||||
{ label: credential?.name ?? `#${id}` },
|
{ label: credential?.name ?? `#${id}` },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
@@ -120,7 +124,8 @@ export function CredentialDetailPage() {
|
|||||||
<div className={styles.stepsSection}>
|
<div className={styles.stepsSection}>
|
||||||
<h2 className={styles.sectionHeading}>{t('credentials.section_data')}</h2>
|
<h2 className={styles.sectionHeading}>{t('credentials.section_data')}</h2>
|
||||||
<Card>
|
<Card>
|
||||||
<CodeBlock
|
<RevealableCodeBlock
|
||||||
|
key={credential.id}
|
||||||
language="json"
|
language="json"
|
||||||
code={(() => {
|
code={(() => {
|
||||||
try {
|
try {
|
||||||
@@ -136,23 +141,14 @@ export function CredentialDetailPage() {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Modal
|
<DeleteConfirmationModal
|
||||||
open={confirmDeleteOpen}
|
open={confirmDeleteOpen}
|
||||||
title={t('credentials.action_delete')}
|
title={t('credentials.action_delete')}
|
||||||
onClose={() => !deleting && setConfirmDeleteOpen(false)}
|
message={t('common.confirm_delete_credential')}
|
||||||
footer={(
|
onClose={() => setConfirmDeleteOpen(false)}
|
||||||
<>
|
onConfirm={handleDelete}
|
||||||
<Button variant="secondary" onClick={() => setConfirmDeleteOpen(false)} disabled={deleting}>
|
isDeleting={deleting}
|
||||||
Cancel
|
/>
|
||||||
</Button>
|
|
||||||
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
|
||||||
{t('credentials.action_delete')}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
Are you sure you want to delete this credential?
|
|
||||||
</Modal>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
|
import { useImportFile } from '../../hooks/useImportFile';
|
||||||
import { Settings, Pencil, Trash2, Plus, Download, KeyRound } from 'lucide-react';
|
import { Settings, Pencil, Trash2, Plus, Download, KeyRound } from 'lucide-react';
|
||||||
import { parse as yamlParse } from 'yaml';
|
|
||||||
import { credentials } from '../../api';
|
import { credentials } from '../../api';
|
||||||
import type { Credential } from '../../api';
|
import type { Credential } from '../../api';
|
||||||
import {
|
import {
|
||||||
@@ -11,10 +12,10 @@ import {
|
|||||||
Card,
|
Card,
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
DescriptionList,
|
DescriptionList,
|
||||||
Modal,
|
|
||||||
Timestamp,
|
Timestamp,
|
||||||
UuidBadge,
|
UuidBadge,
|
||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
|
import { DeleteConfirmationModal } from '../../components/modals';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
function CredentialCard({
|
function CredentialCard({
|
||||||
@@ -100,10 +101,9 @@ function AddCredentialCard() {
|
|||||||
|
|
||||||
export function CredentialsPage() {
|
export function CredentialsPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
usePageTitle(t('credentials.title'));
|
||||||
const [items, setItems] = useState<Credential[]>([]);
|
const [items, setItems] = useState<Credential[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
@@ -112,7 +112,6 @@ export function CredentialsPage() {
|
|||||||
credentials
|
credentials
|
||||||
.list()
|
.list()
|
||||||
.then((res) => setItems(res.data))
|
.then((res) => setItems(res.data))
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -136,19 +135,7 @@ export function CredentialsPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleImport = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleImport = useImportFile('credential');
|
||||||
const file = e.target.files?.[0];
|
|
||||||
if (!file) return;
|
|
||||||
e.target.value = '';
|
|
||||||
try {
|
|
||||||
const text = await file.text();
|
|
||||||
const payload = yamlParse(text) as unknown;
|
|
||||||
const imported = await credentials.importCredential(payload);
|
|
||||||
navigate(`/credentials/${imported.id}`);
|
|
||||||
} catch (err) {
|
|
||||||
setError(err instanceof Error ? err.message : String(err));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -179,23 +166,14 @@ export function CredentialsPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Modal
|
<DeleteConfirmationModal
|
||||||
open={deleteId != null}
|
open={deleteId != null}
|
||||||
title={t('credentials.action_delete')}
|
title={t('credentials.action_delete')}
|
||||||
onClose={() => !deleting && setDeleteId(null)}
|
message={t('common.confirm_delete_credential')}
|
||||||
footer={(
|
onClose={() => setDeleteId(null)}
|
||||||
<>
|
onConfirm={handleDelete}
|
||||||
<Button variant="secondary" onClick={() => setDeleteId(null)} disabled={deleting}>
|
isDeleting={deleting}
|
||||||
Cancel
|
/>
|
||||||
</Button>
|
|
||||||
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
|
||||||
{t('credentials.action_delete')}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
Are you sure you want to delete this credential?
|
|
||||||
</Modal>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState, SubmitEvent } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { KeyRound, X, Save } from 'lucide-react';
|
import { KeyRound, X, Save } from 'lucide-react';
|
||||||
import { credentials } from '../../api';
|
import { credentials } from '../../api';
|
||||||
import type { Credential } from '../../api';
|
import type { Credential } from '../../api';
|
||||||
@@ -15,12 +16,16 @@ export function EditCredentialPage() {
|
|||||||
|
|
||||||
const [credential, setCredential] = useState<Credential | null>(null);
|
const [credential, setCredential] = useState<Credential | null>(null);
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
|
usePageTitle(
|
||||||
|
credential
|
||||||
|
? `${t('credentials.edit_title')} — ${credential.name}`
|
||||||
|
: t('credentials.edit_title'),
|
||||||
|
);
|
||||||
const [data, setData] = useState('');
|
const [data, setData] = useState('');
|
||||||
const [nameError, setNameError] = useState('');
|
const [nameError, setNameError] = useState('');
|
||||||
const [dataError, setDataError] = useState('');
|
const [dataError, setDataError] = useState('');
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
@@ -31,11 +36,10 @@ export function EditCredentialPage() {
|
|||||||
setName(c.name);
|
setName(c.name);
|
||||||
setData(c.data ?? '');
|
setData(c.data ?? '');
|
||||||
})
|
})
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let valid = true;
|
let valid = true;
|
||||||
if (!name.trim()) {
|
if (!name.trim()) {
|
||||||
@@ -52,17 +56,15 @@ export function EditCredentialPage() {
|
|||||||
}
|
}
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
|
||||||
try {
|
try {
|
||||||
await credentials.update(id!, {
|
await credentials.update(id!, {
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
data: data.trim() || null,
|
data: data.trim() || null,
|
||||||
});
|
});
|
||||||
toast.success('Credential updated');
|
toast.success(t('credentials.updated'));
|
||||||
navigate(`/credentials/${id}`);
|
navigate(`/credentials/${id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message;
|
const message = (err as Error).message;
|
||||||
setError(message);
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
@@ -74,7 +76,11 @@ export function EditCredentialPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('credentials.title'), icon: <KeyRound size={14} />, onClick: () => navigate('/credentials') },
|
{
|
||||||
|
label: t('credentials.title'),
|
||||||
|
icon: <KeyRound size={14} />,
|
||||||
|
onClick: () => navigate('/credentials'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: credential?.name ?? `#${id}`,
|
label: credential?.name ?? `#${id}`,
|
||||||
onClick: () => navigate(`/credentials/${id}`),
|
onClick: () => navigate(`/credentials/${id}`),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useState } from 'react';
|
import { useState, SubmitEvent } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { X, Globe, Save } from 'lucide-react';
|
import { X, Globe, Save } from 'lucide-react';
|
||||||
import { environments } from '../../api';
|
import { environments } from '../../api';
|
||||||
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
||||||
@@ -8,17 +9,18 @@ import styles from '../Page.module.css';
|
|||||||
|
|
||||||
export function CreateEnvironmentPage() {
|
export function CreateEnvironmentPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
usePageTitle(t('environments.create_title'));
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
|
const [description, setDescription] = useState('');
|
||||||
const [dataJson, setDataJson] = useState('{\n "id": "https://id.example.com"\n}');
|
const [dataJson, setDataJson] = useState('{\n "id": "https://id.example.com"\n}');
|
||||||
const [nameError, setNameError] = useState('');
|
const [nameError, setNameError] = useState('');
|
||||||
const [dataError, setDataError] = useState('');
|
const [dataError, setDataError] = useState('');
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!name.trim()) {
|
if (!name.trim()) {
|
||||||
setNameError(t('environments.form_name_required'));
|
setNameError(t('environments.form_name_required'));
|
||||||
@@ -42,14 +44,16 @@ export function CreateEnvironmentPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
|
||||||
try {
|
try {
|
||||||
const env = await environments.create(name.trim(), parsedData);
|
const env = await environments.create(
|
||||||
toast.success('Environment created');
|
name.trim(),
|
||||||
|
parsedData,
|
||||||
|
description.trim() || undefined,
|
||||||
|
);
|
||||||
|
toast.success(t('environments.created'));
|
||||||
navigate(`/environments/${env.id}`);
|
navigate(`/environments/${env.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message;
|
const message = (err as Error).message;
|
||||||
setError(message);
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
@@ -61,7 +65,11 @@ export function CreateEnvironmentPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('environments.title'), icon: <Globe size={14} />, onClick: () => navigate('/environments') },
|
{
|
||||||
|
label: t('environments.title'),
|
||||||
|
icon: <Globe size={14} />,
|
||||||
|
onClick: () => navigate('/environments'),
|
||||||
|
},
|
||||||
{ label: t('environments.create_title') },
|
{ label: t('environments.create_title') },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
@@ -82,6 +90,15 @@ export function CreateEnvironmentPage() {
|
|||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
|
<div className={styles.formField}>
|
||||||
|
<label className={styles.fieldLabel}>{t('environments.form_description')}</label>
|
||||||
|
<CodeEditor
|
||||||
|
language="markdown"
|
||||||
|
value={description}
|
||||||
|
onChange={setDescription}
|
||||||
|
rows={6}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className={styles.formField}>
|
<div className={styles.formField}>
|
||||||
<label className={styles.fieldLabel}>{t('environments.form_data')}</label>
|
<label className={styles.fieldLabel}>{t('environments.form_data')}</label>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState, SubmitEvent } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { X, Globe, Save } from 'lucide-react';
|
import { X, Globe, Save } from 'lucide-react';
|
||||||
import { environments } from '../../api';
|
import { environments } from '../../api';
|
||||||
import type { Environment } from '../../api';
|
import type { Environment } from '../../api';
|
||||||
@@ -15,12 +16,15 @@ export function EditEnvironmentPage() {
|
|||||||
|
|
||||||
const [env, setEnv] = useState<Environment | null>(null);
|
const [env, setEnv] = useState<Environment | null>(null);
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
|
usePageTitle(
|
||||||
|
env ? `${t('environments.edit_title')} — ${env.name}` : t('environments.edit_title'),
|
||||||
|
);
|
||||||
|
const [description, setDescription] = useState('');
|
||||||
const [dataJson, setDataJson] = useState('{}');
|
const [dataJson, setDataJson] = useState('{}');
|
||||||
const [nameError, setNameError] = useState('');
|
const [nameError, setNameError] = useState('');
|
||||||
const [dataError, setDataError] = useState('');
|
const [dataError, setDataError] = useState('');
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
@@ -29,13 +33,13 @@ export function EditEnvironmentPage() {
|
|||||||
.then((data) => {
|
.then((data) => {
|
||||||
setEnv(data);
|
setEnv(data);
|
||||||
setName(data.name);
|
setName(data.name);
|
||||||
|
setDescription(data.description || '');
|
||||||
setDataJson(JSON.stringify(data.data ?? {}, null, 2));
|
setDataJson(JSON.stringify(data.data ?? {}, null, 2));
|
||||||
})
|
})
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!name.trim()) {
|
if (!name.trim()) {
|
||||||
setNameError(t('environments.form_name_required'));
|
setNameError(t('environments.form_name_required'));
|
||||||
@@ -59,17 +63,16 @@ export function EditEnvironmentPage() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
|
||||||
try {
|
try {
|
||||||
await environments.update(id!, {
|
await environments.update(id!, {
|
||||||
name: name.trim(),
|
name: name.trim(),
|
||||||
|
description: description.trim() || undefined,
|
||||||
data: parsedData,
|
data: parsedData,
|
||||||
});
|
});
|
||||||
toast.success('Environment updated');
|
toast.success(t('environments.updated'));
|
||||||
navigate(`/environments/${id}`);
|
navigate(`/environments/${id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message;
|
const message = (err as Error).message;
|
||||||
setError(message);
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
@@ -81,7 +84,11 @@ export function EditEnvironmentPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('environments.title'), icon: <Globe size={14} />, onClick: () => navigate('/environments') },
|
{
|
||||||
|
label: t('environments.title'),
|
||||||
|
icon: <Globe size={14} />,
|
||||||
|
onClick: () => navigate('/environments'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: env?.name ?? `#${id}`,
|
label: env?.name ?? `#${id}`,
|
||||||
onClick: () => navigate(`/environments/${id}`),
|
onClick: () => navigate(`/environments/${id}`),
|
||||||
@@ -109,6 +116,15 @@ export function EditEnvironmentPage() {
|
|||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
|
<div className={styles.formField}>
|
||||||
|
<label className={styles.fieldLabel}>{t('environments.form_description')}</label>
|
||||||
|
<CodeEditor
|
||||||
|
language="markdown"
|
||||||
|
value={description}
|
||||||
|
onChange={setDescription}
|
||||||
|
rows={6}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className={styles.formField}>
|
<div className={styles.formField}>
|
||||||
<label className={styles.fieldLabel}>{t('environments.form_data')}</label>
|
<label className={styles.fieldLabel}>{t('environments.form_data')}</label>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
|
|||||||
@@ -1,20 +1,32 @@
|
|||||||
|
import { Globe, Pencil, Trash2, Upload } from 'lucide-react';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Upload, Pencil, Trash2, Globe } from 'lucide-react';
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { stringify as yamlStringify } from 'yaml';
|
import { stringify as yamlStringify } from 'yaml';
|
||||||
import { environments } from '../../api';
|
|
||||||
import type { Environment } from '../../api';
|
import type { Environment } from '../../api';
|
||||||
import { Breadcrumbs, Button, Card, DescriptionList, Modal, Timestamp, UuidBadge } from '../../ui';
|
import { environments } from '../../api';
|
||||||
|
import { DeleteConfirmationModal } from '../../components/modals';
|
||||||
|
import {
|
||||||
|
Breadcrumbs,
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
DescriptionList,
|
||||||
|
Timestamp,
|
||||||
|
UuidBadge,
|
||||||
|
MarkdownContent,
|
||||||
|
useToast,
|
||||||
|
} from '../../ui';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function EnvironmentDetailPage() {
|
export function EnvironmentDetailPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const toast = useToast();
|
||||||
const { id } = useParams<{ id: string }>();
|
const { id } = useParams<{ id: string }>();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [env, setEnv] = useState<Environment | null>(null);
|
const [env, setEnv] = useState<Environment | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
usePageTitle(env?.name ?? null);
|
||||||
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false);
|
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
const dataEntries = Object.entries(env?.data ?? {}).filter(([, v]) => v);
|
const dataEntries = Object.entries(env?.data ?? {}).filter(([, v]) => v);
|
||||||
@@ -24,9 +36,9 @@ export function EnvironmentDetailPage() {
|
|||||||
environments
|
environments
|
||||||
.get(id)
|
.get(id)
|
||||||
.then(setEnv)
|
.then(setEnv)
|
||||||
.catch((err: Error) => setError(err.message))
|
.catch((err: Error) => toast.error((err as Error).message))
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [id]);
|
}, [id, toast]);
|
||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
if (!env) return;
|
if (!env) return;
|
||||||
@@ -57,7 +69,11 @@ export function EnvironmentDetailPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('environments.title'), icon: <Globe size={14} />, onClick: () => navigate('/environments') },
|
{
|
||||||
|
label: t('environments.title'),
|
||||||
|
icon: <Globe size={14} />,
|
||||||
|
onClick: () => navigate('/environments'),
|
||||||
|
},
|
||||||
{ label: env?.name ?? `#${id}` },
|
{ label: env?.name ?? `#${id}` },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
@@ -104,15 +120,26 @@ export function EnvironmentDetailPage() {
|
|||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{env.description && (
|
||||||
|
<div className={styles.stepsSection}>
|
||||||
|
<div className={styles.sectionHeadingRow}>
|
||||||
|
<h2 className={styles.sectionHeading}>{t('environments.field_description')}</h2>
|
||||||
|
</div>
|
||||||
|
<Card>
|
||||||
|
<MarkdownContent content={env.description} />
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<div className={styles.stepsSection}>
|
<div className={styles.stepsSection}>
|
||||||
<h2 className={styles.sectionHeading}>{t('environments.section_data')}</h2>
|
<h2 className={styles.sectionHeading}>{t('environments.section_data')}</h2>
|
||||||
<Card>
|
<Card>
|
||||||
{dataEntries.length === 0 ? (
|
{dataEntries.length === 0 ? (
|
||||||
<p className={styles.muted}>{t('environments.no_data')}</p>
|
<p className={styles.muted}>{t('environments.no_data')}</p>
|
||||||
) : (
|
) : (
|
||||||
<DescriptionList
|
<DescriptionList
|
||||||
layout="grid"
|
layout="grid"
|
||||||
items={dataEntries.map(([key, value]) => ({
|
items={dataEntries.map(([key, value]) => ({
|
||||||
term: key,
|
term: key,
|
||||||
detail: (
|
detail: (
|
||||||
<a href={value} target="_blank" rel="noopener noreferrer">
|
<a href={value} target="_blank" rel="noopener noreferrer">
|
||||||
@@ -120,30 +147,21 @@ export function EnvironmentDetailPage() {
|
|||||||
</a>
|
</a>
|
||||||
),
|
),
|
||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Modal
|
<DeleteConfirmationModal
|
||||||
open={confirmDeleteOpen}
|
open={confirmDeleteOpen}
|
||||||
title={t('environments.action_delete')}
|
title={t('environments.action_delete')}
|
||||||
onClose={() => !deleting && setConfirmDeleteOpen(false)}
|
message={t('common.confirm_delete_environment')}
|
||||||
footer={(
|
onClose={() => setConfirmDeleteOpen(false)}
|
||||||
<>
|
onConfirm={handleDelete}
|
||||||
<Button variant="secondary" onClick={() => setConfirmDeleteOpen(false)} disabled={deleting}>
|
isDeleting={deleting}
|
||||||
Cancel
|
/>
|
||||||
</Button>
|
|
||||||
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
|
||||||
{t('environments.action_delete')}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
Are you sure you want to delete this environment?
|
|
||||||
</Modal>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
|
import { useImportFile } from '../../hooks/useImportFile';
|
||||||
import { Settings, ExternalLink, Pencil, Trash2, Plus, Globe, Download } from 'lucide-react';
|
import { Settings, ExternalLink, Pencil, Trash2, Plus, Globe, Download } from 'lucide-react';
|
||||||
import { parse as yamlParse } from 'yaml';
|
|
||||||
import { stringify as yamlStringify } from 'yaml';
|
import { stringify as yamlStringify } from 'yaml';
|
||||||
import { environments } from '../../api';
|
import { environments } from '../../api';
|
||||||
import type { Environment } from '../../api';
|
import type { Environment } from '../../api';
|
||||||
@@ -12,10 +13,10 @@ import {
|
|||||||
Card,
|
Card,
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
DescriptionList,
|
DescriptionList,
|
||||||
Modal,
|
|
||||||
Timestamp,
|
Timestamp,
|
||||||
UuidBadge,
|
UuidBadge,
|
||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
|
import { DeleteConfirmationModal } from '../../components/modals';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
function EnvironmentCard({ env, onDelete }: { env: Environment; onDelete: (id: string) => void }) {
|
function EnvironmentCard({ env, onDelete }: { env: Environment; onDelete: (id: string) => void }) {
|
||||||
@@ -117,10 +118,9 @@ function AddEnvironmentCard() {
|
|||||||
|
|
||||||
export function EnvironmentsPage() {
|
export function EnvironmentsPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
usePageTitle(t('environments.title'));
|
||||||
const [items, setItems] = useState<Environment[]>([]);
|
const [items, setItems] = useState<Environment[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
@@ -129,7 +129,6 @@ export function EnvironmentsPage() {
|
|||||||
environments
|
environments
|
||||||
.list()
|
.list()
|
||||||
.then((res) => setItems(res.data))
|
.then((res) => setItems(res.data))
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -153,19 +152,7 @@ export function EnvironmentsPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleImport = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleImport = useImportFile('environment');
|
||||||
const file = e.target.files?.[0];
|
|
||||||
if (!file) return;
|
|
||||||
e.target.value = '';
|
|
||||||
try {
|
|
||||||
const text = await file.text();
|
|
||||||
const payload = yamlParse(text) as unknown;
|
|
||||||
const imported = await environments.importEnvironment(payload);
|
|
||||||
navigate(`/environments/${imported.id}`);
|
|
||||||
} catch (err) {
|
|
||||||
setError(err instanceof Error ? err.message : String(err));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -196,23 +183,14 @@ export function EnvironmentsPage() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Modal
|
<DeleteConfirmationModal
|
||||||
open={deleteId != null}
|
open={deleteId != null}
|
||||||
title={t('environments.action_delete')}
|
title={t('environments.action_delete')}
|
||||||
onClose={() => !deleting && setDeleteId(null)}
|
message={t('common.confirm_delete_environment')}
|
||||||
footer={(
|
onClose={() => setDeleteId(null)}
|
||||||
<>
|
onConfirm={handleDelete}
|
||||||
<Button variant="secondary" onClick={() => setDeleteId(null)} disabled={deleting}>
|
isDeleting={deleting}
|
||||||
Cancel
|
/>
|
||||||
</Button>
|
|
||||||
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
|
||||||
{t('environments.action_delete')}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
Are you sure you want to delete this environment?
|
|
||||||
</Modal>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import { useRef, useState, type ChangeEvent } from 'react';
|
||||||
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { Upload } from 'lucide-react';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
|
import { importedItemPath } from '../../hooks/useImportFile';
|
||||||
|
import { imports } from '../../api';
|
||||||
|
import type { ImportedItem, ImportResult } from '../../api';
|
||||||
|
import { Badge, Breadcrumbs, Button, Card, Table, type TableColumn } from '../../ui';
|
||||||
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
|
interface FileResult {
|
||||||
|
fileName: string;
|
||||||
|
result: ImportResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
type Row = ImportedItem & { fileName: string; rowKey: string };
|
||||||
|
|
||||||
|
export function ImportPage() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
usePageTitle(t('import.title'));
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const location = useLocation();
|
||||||
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
// List pages hand over the result of an import they ran
|
||||||
|
const [results, setResults] = useState<FileResult[]>(
|
||||||
|
() => (location.state as { results?: FileResult[] } | null)?.results ?? [],
|
||||||
|
);
|
||||||
|
const [importing, setImporting] = useState(false);
|
||||||
|
|
||||||
|
const handleFiles = async (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
|
const files = Array.from(e.target.files ?? []);
|
||||||
|
e.target.value = '';
|
||||||
|
if (files.length === 0) return;
|
||||||
|
setImporting(true);
|
||||||
|
const next: FileResult[] = [];
|
||||||
|
try {
|
||||||
|
for (const file of files) {
|
||||||
|
try {
|
||||||
|
next.push({ fileName: file.name, result: await imports.yaml(await file.text()) });
|
||||||
|
} catch {
|
||||||
|
// error toast is already emitted by the API client; nothing from
|
||||||
|
// this file was imported, continue with the next one
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setResults(next);
|
||||||
|
setImporting(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const rows: Row[] = results.flatMap(({ fileName, result }) =>
|
||||||
|
result.imported.map((item, i) => ({ ...item, fileName, rowKey: `${fileName}-${i}` })),
|
||||||
|
);
|
||||||
|
|
||||||
|
const columns: TableColumn<Row>[] = [
|
||||||
|
{ key: 'fileName', header: t('import.col_file'), render: (r) => r.fileName },
|
||||||
|
{
|
||||||
|
key: 'kind',
|
||||||
|
header: t('import.col_kind'),
|
||||||
|
width: 120,
|
||||||
|
render: (r) => <Badge variant="neutral">{t(`import.kind_${r.kind}`)}</Badge>,
|
||||||
|
},
|
||||||
|
{ key: 'name', header: t('import.col_name'), render: (r) => r.name },
|
||||||
|
{
|
||||||
|
key: 'version',
|
||||||
|
header: t('import.col_version'),
|
||||||
|
width: 90,
|
||||||
|
render: (r) =>
|
||||||
|
r.version != null ? `v${r.version}` : <span className={styles.muted}>–</span>,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<div className={styles.pageToolbar}>
|
||||||
|
<Breadcrumbs items={[{ label: t('import.title'), icon: <Upload size={14} /> }]} />
|
||||||
|
<div className={styles.toolbarActions}>
|
||||||
|
<input
|
||||||
|
ref={fileInputRef}
|
||||||
|
type="file"
|
||||||
|
accept=".yaml,.yml,.json"
|
||||||
|
multiple
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
onChange={handleFiles}
|
||||||
|
/>
|
||||||
|
<Button size="sm" onClick={() => fileInputRef.current?.click()} disabled={importing}>
|
||||||
|
<Upload size={14} />
|
||||||
|
{t('import.action_choose')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<p>{t('import.description')}</p>
|
||||||
|
<p className={styles.muted}>{t('import.description_validation')}</p>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
{rows.length > 0 && (
|
||||||
|
<div className={styles.stepsSection}>
|
||||||
|
<h2 className={styles.sectionHeading}>
|
||||||
|
{t('import.imported_count', { count: rows.length })}
|
||||||
|
</h2>
|
||||||
|
<Table<Row>
|
||||||
|
columns={columns}
|
||||||
|
data={rows}
|
||||||
|
rowKey={(r) => r.rowKey}
|
||||||
|
loading={false}
|
||||||
|
emptyMessage=""
|
||||||
|
onRowClick={(r) => navigate(importedItemPath(r))}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { Activity } from 'lucide-react';
|
import { Activity } from 'lucide-react';
|
||||||
import { runs } from '../../api';
|
import { runs } from '../../api';
|
||||||
import type { ScenarioRun, ScenarioRunStep, ScenarioRunStatus } from '../../api';
|
import type { ScenarioRun, ScenarioRunStatus } from '../../api';
|
||||||
import {
|
import {
|
||||||
AutoRefreshIndicator,
|
AutoRefreshIndicator,
|
||||||
Badge,
|
Badge,
|
||||||
@@ -12,6 +14,7 @@ import {
|
|||||||
Timestamp,
|
Timestamp,
|
||||||
UuidBadge,
|
UuidBadge,
|
||||||
type TableColumn,
|
type TableColumn,
|
||||||
|
type SortDirection,
|
||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
import type { BadgeVariant } from '../../ui';
|
import type { BadgeVariant } from '../../ui';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
@@ -31,49 +34,49 @@ const STATUS_LABEL: Record<ScenarioRunStatus, string> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type AllRunRow = ScenarioRun & {
|
type AllRunRow = ScenarioRun & {
|
||||||
stepRuns: ScenarioRunStep[];
|
scenario: { id: string; name: string };
|
||||||
scenario: { id: number; name: string };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function AllRunsPage() {
|
export function AllRunsPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
usePageTitle(t('runs.title'));
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [items, setItems] = useState<AllRunRow[]>([]);
|
const [sortBy, setSortBy] = useState('createdAt');
|
||||||
const [loading, setLoading] = useState(true);
|
const [sortDir, setSortDir] = useState<SortDirection>('desc');
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [page, setPage] = useState(1);
|
||||||
const [pulseKey, setPulseKey] = useState(0);
|
const [pageSize, setPageSize] = useState(20);
|
||||||
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
|
||||||
const hasDataRef = useRef(false);
|
|
||||||
|
|
||||||
const load = useCallback(() => {
|
const { data, isLoading, error, refetch } = useQuery({
|
||||||
if (!hasDataRef.current) setLoading(true);
|
queryKey: ['runs', sortBy, sortDir, page, pageSize],
|
||||||
runs
|
queryFn: () =>
|
||||||
.listAll()
|
runs.listAll(page, pageSize, undefined, sortBy, sortDir === 'asc' ? 'ASC' : 'DESC'),
|
||||||
.then((res) => {
|
refetchInterval: 10_000,
|
||||||
setItems(res.data as AllRunRow[]);
|
staleTime: 0,
|
||||||
setError(null);
|
});
|
||||||
setPulseKey((k) => k + 1);
|
|
||||||
hasDataRef.current = true;
|
|
||||||
})
|
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
const items = (data?.data ?? []) as AllRunRow[];
|
||||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
const total = data?.total ?? 0;
|
||||||
load();
|
|
||||||
pollRef.current = setInterval(load, 10_000);
|
const handleSort = (key: string, dir: SortDirection) => {
|
||||||
return () => {
|
setSortBy(key);
|
||||||
if (pollRef.current) clearInterval(pollRef.current);
|
setSortDir(dir);
|
||||||
};
|
setPage(1);
|
||||||
}, []);
|
};
|
||||||
|
|
||||||
|
const handlePageChange = (p: number) => setPage(p);
|
||||||
|
|
||||||
|
const handlePageSizeChange = (size: number) => {
|
||||||
|
setPageSize(size);
|
||||||
|
setPage(1);
|
||||||
|
};
|
||||||
|
|
||||||
const columns: TableColumn<AllRunRow>[] = [
|
const columns: TableColumn<AllRunRow>[] = [
|
||||||
{ key: 'id', header: t('runs.col_id'), render: (r) => <UuidBadge id={r.id} />, width: 60 },
|
{ key: 'id', header: t('runs.col_id'), render: (r) => <UuidBadge id={r.id} />, width: 60 },
|
||||||
{
|
{
|
||||||
key: 'scenario',
|
key: 'scenario.name',
|
||||||
header: t('runs.col_scenario'),
|
header: t('runs.col_scenario'),
|
||||||
|
sortable: true,
|
||||||
render: (r) => (
|
render: (r) => (
|
||||||
<span
|
<span
|
||||||
className={styles.linkCell}
|
className={styles.linkCell}
|
||||||
@@ -90,18 +93,25 @@ export function AllRunsPage() {
|
|||||||
key: 'status',
|
key: 'status',
|
||||||
header: t('runs.col_status'),
|
header: t('runs.col_status'),
|
||||||
width: 110,
|
width: 110,
|
||||||
|
sortable: true,
|
||||||
render: (r) => <Badge variant={STATUS_VARIANT[r.status]}>{STATUS_LABEL[r.status]}</Badge>,
|
render: (r) => <Badge variant={STATUS_VARIANT[r.status]}>{STATUS_LABEL[r.status]}</Badge>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'steps',
|
key: 'scenarioVersion',
|
||||||
header: t('runs.col_steps'),
|
header: t('runs.col_version'),
|
||||||
width: 80,
|
width: 80,
|
||||||
render: (r) => r.stepRuns.length,
|
render: (r) =>
|
||||||
|
r.scenarioVersion != null ? (
|
||||||
|
`v${r.scenarioVersion}`
|
||||||
|
) : (
|
||||||
|
<span className={styles.muted}>–</span>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'created',
|
key: 'createdAt',
|
||||||
header: t('runs.col_created'),
|
header: t('runs.col_created'),
|
||||||
width: 160,
|
width: 160,
|
||||||
|
sortable: true,
|
||||||
render: (r) => <Timestamp value={r.createdAt} />,
|
render: (r) => <Timestamp value={r.createdAt} />,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -110,18 +120,30 @@ export function AllRunsPage() {
|
|||||||
<div>
|
<div>
|
||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs items={[{ label: t('runs.title'), icon: <Activity size={14} /> }]} />
|
<Breadcrumbs items={[{ label: t('runs.title'), icon: <Activity size={14} /> }]} />
|
||||||
<AutoRefreshIndicator active pulseKey={pulseKey} error={!!error} onClick={load} />
|
<AutoRefreshIndicator
|
||||||
|
active
|
||||||
|
pulseKey={items.length}
|
||||||
|
error={!!error}
|
||||||
|
onClick={() => refetch()}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Table
|
<Table
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={items}
|
data={items}
|
||||||
rowKey={(r) => r.id}
|
rowKey={(r) => r.id}
|
||||||
loading={loading}
|
loading={isLoading}
|
||||||
emptyMessage={t('runs.empty')}
|
emptyMessage={t('runs.empty')}
|
||||||
pageSize={20}
|
pageSize={pageSize}
|
||||||
pageSizeOptions={[10, 20, 50]}
|
pageSizeOptions={[10, 20, 50]}
|
||||||
onRowClick={(r) => navigate(`/scenarios/${r.scenarioId}/runs/${r.id}`)}
|
onRowClick={(r) => navigate(`/scenarios/${r.scenarioId}/runs/${r.id}`)}
|
||||||
|
sortBy={sortBy}
|
||||||
|
sortDir={sortDir}
|
||||||
|
onSort={handleSort}
|
||||||
|
total={total}
|
||||||
|
page={page}
|
||||||
|
onPageChange={handlePageChange}
|
||||||
|
onPageSizeChange={handlePageSizeChange}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,33 +1,52 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useMemo, useRef, useState, useCallback } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams, Link } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { runs } from '../../api';
|
import { useManifest } from '../../hooks/useManifest';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
|
import { runs, runFiles } from '../../api';
|
||||||
import type {
|
import type {
|
||||||
Scenario,
|
Scenario,
|
||||||
ScenarioRunDetail,
|
ScenarioRunDetail,
|
||||||
ScenarioRunStep,
|
ScenarioRunStep,
|
||||||
ScenarioRunLog,
|
|
||||||
ScenarioRunStatus,
|
ScenarioRunStatus,
|
||||||
RunStepStatus,
|
RunStepStatus,
|
||||||
LogLevel,
|
FileMetadata,
|
||||||
} from '../../api';
|
} from '../../api';
|
||||||
import { scenarios } from '../../api';
|
import { scenarios } from '../../api';
|
||||||
|
import {
|
||||||
|
DeleteConfirmationModal,
|
||||||
|
ExportLogsModal,
|
||||||
|
type LogExportFormat,
|
||||||
|
} from '../../components/modals';
|
||||||
import {
|
import {
|
||||||
AutoRefreshIndicator,
|
AutoRefreshIndicator,
|
||||||
Badge,
|
Badge,
|
||||||
|
Button,
|
||||||
Breadcrumbs,
|
Breadcrumbs,
|
||||||
Card,
|
Card,
|
||||||
|
CodeBlock,
|
||||||
DescriptionList,
|
DescriptionList,
|
||||||
Notification,
|
formatLogText,
|
||||||
Pagination,
|
hasLargeData,
|
||||||
|
LogOutput,
|
||||||
Search,
|
Search,
|
||||||
Table,
|
Table,
|
||||||
Timestamp,
|
Timestamp,
|
||||||
UuidBadge,
|
UuidBadge,
|
||||||
|
useToast,
|
||||||
type TableColumn,
|
type TableColumn,
|
||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
import type { BadgeVariant } from '../../ui';
|
import type { BadgeVariant } from '../../ui';
|
||||||
import { ClipboardList, Activity } from 'lucide-react';
|
import {
|
||||||
|
ChevronDown,
|
||||||
|
ChevronRight,
|
||||||
|
ClipboardList,
|
||||||
|
Copy,
|
||||||
|
Activity,
|
||||||
|
Download,
|
||||||
|
Trash2,
|
||||||
|
RotateCcw,
|
||||||
|
} from 'lucide-react';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
const RUN_STATUS_VARIANT: Record<ScenarioRunStatus, BadgeVariant> = {
|
const RUN_STATUS_VARIANT: Record<ScenarioRunStatus, BadgeVariant> = {
|
||||||
@@ -53,30 +72,43 @@ const STEP_STATUS_VARIANT: Record<RunStepStatus, BadgeVariant> = {
|
|||||||
cancelled: 'warning',
|
cancelled: 'warning',
|
||||||
};
|
};
|
||||||
|
|
||||||
const LOG_LEVEL_VARIANT: Record<LogLevel, BadgeVariant> = {
|
|
||||||
log: 'neutral',
|
|
||||||
warn: 'warning',
|
|
||||||
error: 'error',
|
|
||||||
};
|
|
||||||
|
|
||||||
const FINAL: ScenarioRunStatus[] = ['pass', 'fail'];
|
const FINAL: ScenarioRunStatus[] = ['pass', 'fail'];
|
||||||
|
|
||||||
export function RunDetailPage() {
|
export function RunDetailPage() {
|
||||||
|
const { runId } = useParams<{ runId: string }>();
|
||||||
|
// Remount per run so "Repeat run" navigation starts from a clean state
|
||||||
|
return <RunDetail key={runId} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function RunDetail() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { id, runId } = useParams<{ id: string; runId: string }>();
|
const { id, runId } = useParams<{ id: string; runId: string }>();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const toast = useToast();
|
||||||
|
const logDataLimits = useManifest().runLogs.dataLimits;
|
||||||
|
|
||||||
const [scenario, setScenario] = useState<Scenario | null>(null);
|
const [scenario, setScenario] = useState<Scenario | null>(null);
|
||||||
const [run, setRun] = useState<ScenarioRunDetail | null>(null);
|
const [run, setRun] = useState<ScenarioRunDetail | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
usePageTitle(scenario ? `${t('runs.title')} — ${scenario.name}` : t('runs.title'));
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [polling, setPolling] = useState(false);
|
const [polling, setPolling] = useState(false);
|
||||||
const [pulseKey, setPulseKey] = useState(0);
|
const [pulseKey, setPulseKey] = useState(0);
|
||||||
const [logPage, setLogPage] = useState(1);
|
|
||||||
const [logSearch, setLogSearch] = useState('');
|
const [logSearch, setLogSearch] = useState('');
|
||||||
const [debouncedSearch, setDebouncedSearch] = useState('');
|
const [debouncedSearch, setDebouncedSearch] = useState('');
|
||||||
|
const [expandAll, setExpandAll] = useState(false);
|
||||||
|
const [expandedStepIds, setExpandedStepIds] = useState<Set<string>>(new Set());
|
||||||
|
const [artifacts, setArtifacts] = useState<FileMetadata[]>([]);
|
||||||
|
const [artifactsTotal, setArtifactsTotal] = useState(0);
|
||||||
|
const [artifactsLoading, setArtifactsLoading] = useState(false);
|
||||||
|
const [exportLogsOpen, setExportLogsOpen] = useState(false);
|
||||||
|
const [exportLogsFormat, setExportLogsFormat] = useState<LogExportFormat>('md');
|
||||||
|
const [exportingLogs, setExportingLogs] = useState(false);
|
||||||
|
const [pendingDeleteFile, setPendingDeleteFile] = useState<FileMetadata | null>(null);
|
||||||
|
const [deletingFile, setDeletingFile] = useState(false);
|
||||||
|
const [repeating, setRepeating] = useState(false);
|
||||||
|
const [logDataExpanded, setLogDataExpanded] = useState(false);
|
||||||
const logSearchRef = useRef('');
|
const logSearchRef = useRef('');
|
||||||
const LOG_PAGE_SIZE = 25;
|
|
||||||
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||||
|
|
||||||
const stopPolling = () => {
|
const stopPolling = () => {
|
||||||
@@ -87,6 +119,99 @@ export function RunDetailPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleFileDownload = (url: string, filename: string) => {
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = filename;
|
||||||
|
link.click();
|
||||||
|
};
|
||||||
|
|
||||||
|
const isFileExpired = (file: FileMetadata) =>
|
||||||
|
file.expiresAt != null && new Date(file.expiresAt).getTime() <= Date.now();
|
||||||
|
|
||||||
|
const handleExportLogs = async () => {
|
||||||
|
if (!id || !runId) return;
|
||||||
|
setExportingLogs(true);
|
||||||
|
try {
|
||||||
|
const content = await runs.exportLogs(id, runId, exportLogsFormat);
|
||||||
|
const mimeType = exportLogsFormat === 'csv' ? 'text/csv' : 'text/markdown';
|
||||||
|
const blob = new Blob([content], { type: mimeType });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = `run-${runId}-logs.${exportLogsFormat}`;
|
||||||
|
a.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
setExportLogsOpen(false);
|
||||||
|
} catch {
|
||||||
|
// error toast is already emitted by the API client
|
||||||
|
} finally {
|
||||||
|
setExportingLogs(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const logEntries = useMemo(
|
||||||
|
() =>
|
||||||
|
(run?.logs ?? []).map((l) => ({
|
||||||
|
id: l.id,
|
||||||
|
level: l.level,
|
||||||
|
context: l.context,
|
||||||
|
message: l.message,
|
||||||
|
data: l.data,
|
||||||
|
createdAt: l.createdAt,
|
||||||
|
})),
|
||||||
|
[run?.logs],
|
||||||
|
);
|
||||||
|
const logsHaveLargeData = useMemo(
|
||||||
|
() => hasLargeData(logEntries, logDataLimits),
|
||||||
|
[logEntries, logDataLimits],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Copies the (filtered) logs as plain text with every data block expanded
|
||||||
|
const handleCopyLogs = async () => {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(formatLogText(logEntries, run?.createdAt));
|
||||||
|
toast.success(t('runs.logs_copied'));
|
||||||
|
} catch {
|
||||||
|
toast.error(t('runs.logs_copy_failed'));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRepeatRun = async () => {
|
||||||
|
if (!id || !run?.environmentId) return;
|
||||||
|
setRepeating(true);
|
||||||
|
try {
|
||||||
|
const newRun = await scenarios.run(
|
||||||
|
id,
|
||||||
|
run.environmentId,
|
||||||
|
run.saveSession,
|
||||||
|
run.traceMode ?? undefined,
|
||||||
|
run.scenarioVersion ?? undefined,
|
||||||
|
);
|
||||||
|
toast.success(t('scenarios.run_started'));
|
||||||
|
navigate(`/scenarios/${id}/runs/${newRun.id}`);
|
||||||
|
} catch (err) {
|
||||||
|
toast.error((err as Error).message);
|
||||||
|
} finally {
|
||||||
|
setRepeating(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDeleteFile = async () => {
|
||||||
|
if (!id || !runId || !pendingDeleteFile) return;
|
||||||
|
setDeletingFile(true);
|
||||||
|
try {
|
||||||
|
await runFiles.remove(id, runId, pendingDeleteFile.id);
|
||||||
|
toast.success(t('files.deleteSuccess'));
|
||||||
|
setPendingDeleteFile(null);
|
||||||
|
await loadArtifacts();
|
||||||
|
} catch {
|
||||||
|
// error toast is already emitted by the API client
|
||||||
|
} finally {
|
||||||
|
setDeletingFile(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const manualRefresh = () => {
|
const manualRefresh = () => {
|
||||||
if (!id || !runId) return;
|
if (!id || !runId) return;
|
||||||
runs
|
runs
|
||||||
@@ -99,11 +224,26 @@ export function RunDetailPage() {
|
|||||||
.catch((err: Error) => setError(err.message));
|
.catch((err: Error) => setError(err.message));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loadArtifacts = useCallback(async () => {
|
||||||
|
if (!id || !runId) return;
|
||||||
|
setArtifactsLoading(true);
|
||||||
|
try {
|
||||||
|
const result = await runFiles.list(id, runId);
|
||||||
|
setArtifacts(result.items);
|
||||||
|
setArtifactsTotal(result.total);
|
||||||
|
} catch {
|
||||||
|
// Silently fail - artifacts are not critical
|
||||||
|
setArtifacts([]);
|
||||||
|
setArtifactsTotal(0);
|
||||||
|
} finally {
|
||||||
|
setArtifactsLoading(false);
|
||||||
|
}
|
||||||
|
}, [id, runId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const t = setTimeout(() => {
|
const t = setTimeout(() => {
|
||||||
setDebouncedSearch(logSearch);
|
setDebouncedSearch(logSearch);
|
||||||
logSearchRef.current = logSearch;
|
logSearchRef.current = logSearch;
|
||||||
setLogPage(1);
|
|
||||||
}, 300);
|
}, 300);
|
||||||
return () => clearTimeout(t);
|
return () => clearTimeout(t);
|
||||||
}, [logSearch]);
|
}, [logSearch]);
|
||||||
@@ -125,6 +265,7 @@ export function RunDetailPage() {
|
|||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
setScenario(sc);
|
setScenario(sc);
|
||||||
setRun(r);
|
setRun(r);
|
||||||
|
loadArtifacts();
|
||||||
if (!FINAL.includes(r.status)) {
|
if (!FINAL.includes(r.status)) {
|
||||||
setPolling(true);
|
setPolling(true);
|
||||||
pollRef.current = setInterval(async () => {
|
pollRef.current = setInterval(async () => {
|
||||||
@@ -133,7 +274,10 @@ export function RunDetailPage() {
|
|||||||
if (cancelled) return;
|
if (cancelled) return;
|
||||||
setRun(updated);
|
setRun(updated);
|
||||||
setPulseKey((k) => k + 1);
|
setPulseKey((k) => k + 1);
|
||||||
if (FINAL.includes(updated.status)) stopPolling();
|
if (FINAL.includes(updated.status)) {
|
||||||
|
stopPolling();
|
||||||
|
await loadArtifacts();
|
||||||
|
}
|
||||||
} catch {
|
} catch {
|
||||||
stopPolling();
|
stopPolling();
|
||||||
}
|
}
|
||||||
@@ -151,7 +295,7 @@ export function RunDetailPage() {
|
|||||||
cancelled = true;
|
cancelled = true;
|
||||||
stopPolling();
|
stopPolling();
|
||||||
};
|
};
|
||||||
}, [id, runId]);
|
}, [id, runId, loadArtifacts]);
|
||||||
|
|
||||||
const stepColumns: TableColumn<ScenarioRunStep>[] = [
|
const stepColumns: TableColumn<ScenarioRunStep>[] = [
|
||||||
{ key: 'order', header: t('runs.step_order'), render: (s) => s.order, width: 50 },
|
{ key: 'order', header: t('runs.step_order'), render: (s) => s.order, width: 50 },
|
||||||
@@ -159,7 +303,7 @@ export function RunDetailPage() {
|
|||||||
key: 'title',
|
key: 'title',
|
||||||
header: t('runs.step_title'),
|
header: t('runs.step_title'),
|
||||||
width: 220,
|
width: 220,
|
||||||
render: (s) => s.scenarioStep?.title ?? <span className={styles.muted}>–</span>,
|
render: (s) => s.title ?? <span className={styles.muted}>–</span>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'status',
|
key: 'status',
|
||||||
@@ -171,24 +315,110 @@ export function RunDetailPage() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'description',
|
key: 'description',
|
||||||
header: t('runs.step_description'),
|
header: (
|
||||||
render: (s) => s.description ?? <span className={styles.muted}>–</span>,
|
<div
|
||||||
},
|
style={{
|
||||||
];
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
gap: '8px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span>{t('runs.step_description')}</span>
|
||||||
|
{run?.stepRuns.some((s) => s.output) && (
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
if (expandAll) {
|
||||||
|
setExpandAll(false);
|
||||||
|
setExpandedStepIds(new Set());
|
||||||
|
} else {
|
||||||
|
setExpandAll(true);
|
||||||
|
setExpandedStepIds(
|
||||||
|
new Set(run?.stepRuns.filter((s) => s.output).map((s) => s.id) ?? []),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
background: 'none',
|
||||||
|
border: 'none',
|
||||||
|
padding: '0 4px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
color: 'inherit',
|
||||||
|
}}
|
||||||
|
title={expandAll ? 'Collapse all' : 'Expand all'}
|
||||||
|
>
|
||||||
|
{expandAll ? <ChevronDown size={16} /> : <ChevronRight size={16} />}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
render: (s) => {
|
||||||
|
const isExpanded = expandAll || expandedStepIds.has(s.id);
|
||||||
|
|
||||||
const logColumns: TableColumn<ScenarioRunLog>[] = [
|
return (
|
||||||
{
|
<div>
|
||||||
key: 'level',
|
<div
|
||||||
header: t('runs.log_level'),
|
style={{
|
||||||
width: 70,
|
display: 'flex',
|
||||||
render: (l) => <Badge variant={LOG_LEVEL_VARIANT[l.level]}>{l.level}</Badge>,
|
alignItems: 'flex-start',
|
||||||
},
|
gap: '8px',
|
||||||
{ key: 'message', header: t('runs.log_message'), render: (l) => l.message },
|
marginBottom: isExpanded && s.output ? '8px' : 0,
|
||||||
{
|
}}
|
||||||
key: 'time',
|
>
|
||||||
header: t('runs.log_time'),
|
{s.output && (
|
||||||
width: 160,
|
<button
|
||||||
render: (l) => <Timestamp value={l.createdAt} />,
|
onClick={() => {
|
||||||
|
const newSet = new Set(expandedStepIds);
|
||||||
|
if (newSet.has(s.id)) {
|
||||||
|
newSet.delete(s.id);
|
||||||
|
} else {
|
||||||
|
newSet.add(s.id);
|
||||||
|
}
|
||||||
|
setExpandedStepIds(newSet);
|
||||||
|
}}
|
||||||
|
style={{
|
||||||
|
background: 'none',
|
||||||
|
border: 'none',
|
||||||
|
padding: 0,
|
||||||
|
cursor: 'pointer',
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
flexShrink: 0,
|
||||||
|
marginTop: '2px',
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{isExpanded ? <ChevronDown size={16} /> : <ChevronRight size={16} />}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<code style={{ wordBreak: 'break-word' }}>
|
||||||
|
{s.description ? (
|
||||||
|
s.description
|
||||||
|
) : s.output ? (
|
||||||
|
<span title={`${s.output.length} bytes`}>{s.output.length} bytes</span>
|
||||||
|
) : (
|
||||||
|
<span className={styles.muted}>–</span>
|
||||||
|
)}
|
||||||
|
</code>
|
||||||
|
</div>
|
||||||
|
{isExpanded && s.output && (
|
||||||
|
<div style={{ marginLeft: '24px' }}>
|
||||||
|
<CodeBlock
|
||||||
|
code={(() => {
|
||||||
|
try {
|
||||||
|
return JSON.stringify(JSON.parse(s.output), null, 2);
|
||||||
|
} catch {
|
||||||
|
return s.output;
|
||||||
|
}
|
||||||
|
})()}
|
||||||
|
language="json"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -197,9 +427,13 @@ export function RunDetailPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('scenarios.title'), icon: <ClipboardList size={14} />, onClick: () => navigate('/scenarios') },
|
|
||||||
{
|
{
|
||||||
label: scenario?.name ?? `#${id}`,
|
label: t('scenarios.title'),
|
||||||
|
icon: <ClipboardList size={14} />,
|
||||||
|
onClick: () => navigate('/scenarios'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: scenario?.name ?? `${id}`,
|
||||||
onClick: () => navigate(`/scenarios/${id}`),
|
onClick: () => navigate(`/scenarios/${id}`),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -207,10 +441,30 @@ export function RunDetailPage() {
|
|||||||
icon: <Activity size={14} />,
|
icon: <Activity size={14} />,
|
||||||
onClick: () => navigate(`/scenarios/${id}/runs`),
|
onClick: () => navigate(`/scenarios/${id}/runs`),
|
||||||
},
|
},
|
||||||
{ label: `#${runId}` },
|
{ label: `${runId}` },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<AutoRefreshIndicator active={polling} pulseKey={pulseKey} error={!!error} onClick={manualRefresh} />
|
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
||||||
|
{run && (
|
||||||
|
<span title={run.environmentId ? undefined : t('runs.repeat_no_environment')}>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleRepeatRun}
|
||||||
|
disabled={!run.environmentId || repeating}
|
||||||
|
>
|
||||||
|
<RotateCcw size={14} />
|
||||||
|
{t('runs.action_repeat')}
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<AutoRefreshIndicator
|
||||||
|
active={polling}
|
||||||
|
pulseKey={pulseKey}
|
||||||
|
error={!!error}
|
||||||
|
onClick={manualRefresh}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{loading && <p className={styles.muted}>{t('runs.loading')}</p>}
|
{loading && <p className={styles.muted}>{t('runs.loading')}</p>}
|
||||||
@@ -220,19 +474,62 @@ export function RunDetailPage() {
|
|||||||
<Card>
|
<Card>
|
||||||
<DescriptionList
|
<DescriptionList
|
||||||
layout="grid"
|
layout="grid"
|
||||||
items={[
|
items={(() => {
|
||||||
{ term: t('runs.field_id'), detail: <UuidBadge id={run.id} /> },
|
const items = [
|
||||||
{
|
{ term: t('runs.field_id'), detail: <UuidBadge id={run.id} /> },
|
||||||
term: t('runs.field_status'),
|
{
|
||||||
detail: (
|
term: t('runs.field_status'),
|
||||||
<Badge variant={RUN_STATUS_VARIANT[run.status]}>
|
detail: (
|
||||||
{RUN_STATUS_LABEL[run.status]}
|
<Badge variant={RUN_STATUS_VARIANT[run.status]}>
|
||||||
</Badge>
|
{RUN_STATUS_LABEL[run.status]}
|
||||||
),
|
</Badge>
|
||||||
},
|
),
|
||||||
{ term: t('runs.field_created'), detail: <Timestamp value={run.createdAt} /> },
|
},
|
||||||
{ term: t('runs.field_updated'), detail: <Timestamp value={run.updatedAt} /> },
|
{ term: t('runs.field_created'), detail: <Timestamp value={run.createdAt} /> },
|
||||||
]}
|
{ term: t('runs.field_updated'), detail: <Timestamp value={run.updatedAt} /> },
|
||||||
|
];
|
||||||
|
if (run.scenarioVersion != null) {
|
||||||
|
items.push({
|
||||||
|
term: t('runs.field_scenario_version'),
|
||||||
|
detail: <span>v{run.scenarioVersion}</span>,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (run.traceMode) {
|
||||||
|
items.push({
|
||||||
|
term: t('runs.field_trace'),
|
||||||
|
detail: (
|
||||||
|
<span>{t(`scenarios.trace_mode_${run.traceMode.replace(/-/g, '_')}`)}</span>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (run.environment) {
|
||||||
|
items.push({
|
||||||
|
term: 'Environment',
|
||||||
|
detail: (
|
||||||
|
<Link
|
||||||
|
to={`/environments/${run.environment.id}`}
|
||||||
|
style={{ color: 'var(--color-link)' }}
|
||||||
|
>
|
||||||
|
{run.environment.name}
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (run.session) {
|
||||||
|
items.push({
|
||||||
|
term: 'Session',
|
||||||
|
detail: (
|
||||||
|
<Link
|
||||||
|
to={`/sessions/${run.session.id}`}
|
||||||
|
style={{ color: 'var(--color-link)' }}
|
||||||
|
>
|
||||||
|
{run.session.sessionName}
|
||||||
|
</Link>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
})()}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
@@ -252,32 +549,168 @@ export function RunDetailPage() {
|
|||||||
{run.logs.length > 0 && (
|
{run.logs.length > 0 && (
|
||||||
<div className={styles.stepsSection}>
|
<div className={styles.stepsSection}>
|
||||||
<div className={styles.sectionHeadingRow}>
|
<div className={styles.sectionHeadingRow}>
|
||||||
<h2 className={styles.sectionHeading}>{t('runs.logs_heading')}</h2>
|
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
||||||
<Search
|
<h2 className={styles.sectionHeading} style={{ margin: 0 }}>
|
||||||
value={logSearch}
|
{t('runs.logs_heading')}
|
||||||
onChange={setLogSearch}
|
</h2>
|
||||||
placeholder={t('runs.logs_search_placeholder')}
|
{logsHaveLargeData && (
|
||||||
/>
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="sm"
|
||||||
|
aria-expanded={logDataExpanded}
|
||||||
|
onClick={() => setLogDataExpanded((v) => !v)}
|
||||||
|
>
|
||||||
|
{logDataExpanded ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
|
||||||
|
{logDataExpanded ? t('runs.logs_collapse_data') : t('runs.logs_expand_data')}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
|
||||||
|
<Search
|
||||||
|
value={logSearch}
|
||||||
|
onChange={setLogSearch}
|
||||||
|
placeholder={t('runs.logs_search_placeholder')}
|
||||||
|
/>
|
||||||
|
<Button variant="secondary" size="sm" onClick={() => setExportLogsOpen(true)}>
|
||||||
|
<Download size={14} />
|
||||||
|
{t('runs.action_download_logs')}
|
||||||
|
</Button>
|
||||||
|
<Button variant="secondary" size="sm" onClick={handleCopyLogs}>
|
||||||
|
<Copy size={14} />
|
||||||
|
{t('runs.action_copy_logs')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Table
|
<LogOutput
|
||||||
columns={logColumns}
|
startTime={run.createdAt}
|
||||||
data={run.logs.slice((logPage - 1) * LOG_PAGE_SIZE, logPage * LOG_PAGE_SIZE)}
|
maxHeight={480}
|
||||||
rowKey={(l) => l.id}
|
entries={logEntries}
|
||||||
loading={false}
|
dataLimits={logDataLimits}
|
||||||
|
dataExpanded={logDataExpanded}
|
||||||
|
showDataLabel={({ bytes, lines }) =>
|
||||||
|
t('runs.logs_show_data', {
|
||||||
|
size: bytes < 1024 ? `${bytes} B` : `${(bytes / 1024).toFixed(1)} KB`,
|
||||||
|
count: lines,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
hideDataLabel={t('runs.logs_hide_data')}
|
||||||
emptyMessage=""
|
emptyMessage=""
|
||||||
/>
|
/>
|
||||||
{run.logs.length > LOG_PAGE_SIZE && (
|
</div>
|
||||||
<Pagination
|
)}
|
||||||
page={logPage}
|
|
||||||
pageSize={LOG_PAGE_SIZE}
|
{(artifactsTotal > 0 || artifactsLoading) && (
|
||||||
total={run.logs.length}
|
<div className={styles.stepsSection}>
|
||||||
onPageChange={setLogPage}
|
<h2 className={styles.sectionHeading}>{t('files.artifactsTitle')}</h2>
|
||||||
/>
|
<Table<FileMetadata>
|
||||||
)}
|
loading={artifactsLoading}
|
||||||
|
data={artifacts}
|
||||||
|
rowKey={(f) => f.id}
|
||||||
|
columns={
|
||||||
|
[
|
||||||
|
{
|
||||||
|
key: 'name',
|
||||||
|
header: t('files.name'),
|
||||||
|
// Served inline, so the browser shows what it can (images, text, PDF).
|
||||||
|
render: (f) =>
|
||||||
|
isFileExpired(f) ? (
|
||||||
|
f.name
|
||||||
|
) : (
|
||||||
|
<a
|
||||||
|
href={runFiles.contentUrl(id!, runId!, f.id)}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
{f.name}
|
||||||
|
</a>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'mimeType',
|
||||||
|
header: t('files.mimeType'),
|
||||||
|
render: (f) => f.mimeType,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'size',
|
||||||
|
header: t('files.size'),
|
||||||
|
render: (f) => `${(f.size / 1024).toFixed(1)} KB`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'expiresAt',
|
||||||
|
header: t('files.expiresAt'),
|
||||||
|
render: (f) => (f.expiresAt ? <Timestamp value={f.expiresAt} /> : '—'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'createdAt',
|
||||||
|
header: t('files.createdAt'),
|
||||||
|
render: (f) => <Timestamp value={f.createdAt} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'download',
|
||||||
|
header: '',
|
||||||
|
render: (f) => {
|
||||||
|
const expired = isFileExpired(f);
|
||||||
|
const tooltip = expired ? t('files.expiredTooltip') : t('files.download');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span title={tooltip}>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
title={tooltip}
|
||||||
|
aria-label={tooltip}
|
||||||
|
disabled={expired}
|
||||||
|
onClick={() =>
|
||||||
|
handleFileDownload(runFiles.contentUrl(id!, runId!, f.id), f.name)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Download size={14} />
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'delete',
|
||||||
|
header: '',
|
||||||
|
render: (f) => (
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
title={t('files.delete')}
|
||||||
|
aria-label={t('files.delete')}
|
||||||
|
onClick={() => setPendingDeleteFile(f)}
|
||||||
|
>
|
||||||
|
<Trash2 size={14} />
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
] satisfies TableColumn<FileMetadata>[]
|
||||||
|
}
|
||||||
|
emptyMessage={t('files.empty')}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<ExportLogsModal
|
||||||
|
open={exportLogsOpen}
|
||||||
|
format={exportLogsFormat}
|
||||||
|
onFormatChange={setExportLogsFormat}
|
||||||
|
onClose={() => setExportLogsOpen(false)}
|
||||||
|
onExport={handleExportLogs}
|
||||||
|
isExporting={exportingLogs}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<DeleteConfirmationModal
|
||||||
|
open={pendingDeleteFile != null}
|
||||||
|
title={t('files.deleteTitle')}
|
||||||
|
message={t('files.confirmDelete', { name: pendingDeleteFile?.name ?? '' })}
|
||||||
|
onClose={() => setPendingDeleteFile(null)}
|
||||||
|
onConfirm={handleDeleteFile}
|
||||||
|
isDeleting={deletingFile}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,10 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { Play, ClipboardList, Activity } from 'lucide-react';
|
import { Play, ClipboardList, Activity } from 'lucide-react';
|
||||||
import { environments, scenarios, runs } from '../../api';
|
import { environments, scenarios, runs } from '../../api';
|
||||||
import type {
|
import type { Environment, Scenario, ScenarioRun, ScenarioRunStatus } from '../../api';
|
||||||
Environment,
|
|
||||||
Scenario,
|
|
||||||
ScenarioRun,
|
|
||||||
ScenarioRunStep,
|
|
||||||
ScenarioRunStatus,
|
|
||||||
} from '../../api';
|
|
||||||
import {
|
import {
|
||||||
AutoRefreshIndicator,
|
AutoRefreshIndicator,
|
||||||
Badge,
|
Badge,
|
||||||
@@ -22,6 +17,7 @@ import {
|
|||||||
UuidBadge,
|
UuidBadge,
|
||||||
useToast,
|
useToast,
|
||||||
type TableColumn,
|
type TableColumn,
|
||||||
|
type SortDirection,
|
||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
import type { BadgeVariant } from '../../ui';
|
import type { BadgeVariant } from '../../ui';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
@@ -40,7 +36,7 @@ const STATUS_LABEL: Record<ScenarioRunStatus, string> = {
|
|||||||
fail: 'Fail',
|
fail: 'Fail',
|
||||||
};
|
};
|
||||||
|
|
||||||
type RunRow = ScenarioRun & { stepRuns: ScenarioRunStep[] };
|
type RunRow = ScenarioRun;
|
||||||
|
|
||||||
export function RunsPage() {
|
export function RunsPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -50,6 +46,7 @@ export function RunsPage() {
|
|||||||
|
|
||||||
const [scenario, setScenario] = useState<Scenario | null>(null);
|
const [scenario, setScenario] = useState<Scenario | null>(null);
|
||||||
const [items, setItems] = useState<RunRow[]>([]);
|
const [items, setItems] = useState<RunRow[]>([]);
|
||||||
|
usePageTitle(scenario ? `${t('runs.title')} — ${scenario.name}` : t('runs.title'));
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [pulseKey, setPulseKey] = useState(0);
|
const [pulseKey, setPulseKey] = useState(0);
|
||||||
@@ -60,30 +57,75 @@ export function RunsPage() {
|
|||||||
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||||
const hasDataRef = useRef(false);
|
const hasDataRef = useRef(false);
|
||||||
|
|
||||||
const load = useCallback(() => {
|
const [sortBy, setSortBy] = useState('createdAt');
|
||||||
if (!id) return;
|
const [sortDir, setSortDir] = useState<SortDirection>('desc');
|
||||||
if (!hasDataRef.current) setLoading(true);
|
const [page, setPage] = useState(1);
|
||||||
Promise.all([scenarios.get(id!), runs.list(id!)])
|
const [pageSize, setPageSize] = useState(20);
|
||||||
.then(([sc, res]) => {
|
const [total, setTotal] = useState(0);
|
||||||
setScenario(sc);
|
|
||||||
setItems(res.data);
|
// Keep refs so the poll interval always reads current values
|
||||||
setError(null);
|
const sortByRef = useRef(sortBy);
|
||||||
setPulseKey((k) => k + 1);
|
const sortDirRef = useRef(sortDir);
|
||||||
hasDataRef.current = true;
|
const pageRef = useRef(page);
|
||||||
})
|
const pageSizeRef = useRef(pageSize);
|
||||||
.catch((err: Error) => setError(err.message))
|
useEffect(() => {
|
||||||
.finally(() => setLoading(false));
|
sortByRef.current = sortBy;
|
||||||
}, [id]);
|
sortDirRef.current = sortDir;
|
||||||
|
pageRef.current = page;
|
||||||
|
pageSizeRef.current = pageSize;
|
||||||
|
}, [sortBy, sortDir, page, pageSize]);
|
||||||
|
|
||||||
|
const load = useCallback(
|
||||||
|
(orderBy: string, orderDir: SortDirection, p: number, limit: number) => {
|
||||||
|
if (!id) return;
|
||||||
|
if (!hasDataRef.current) setLoading(true);
|
||||||
|
Promise.all([
|
||||||
|
scenarios.get(id!),
|
||||||
|
runs.list(id!, p, limit, orderBy, orderDir === 'asc' ? 'ASC' : 'DESC'),
|
||||||
|
])
|
||||||
|
.then(([sc, res]) => {
|
||||||
|
setScenario(sc);
|
||||||
|
setItems(res.data);
|
||||||
|
setTotal(res.total);
|
||||||
|
setError(null);
|
||||||
|
setPulseKey((k) => k + 1);
|
||||||
|
hasDataRef.current = true;
|
||||||
|
})
|
||||||
|
.catch((err: Error) => setError(err.message))
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
},
|
||||||
|
[id],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
load('createdAt', 'desc', 1, 20);
|
||||||
load();
|
pollRef.current = setInterval(
|
||||||
pollRef.current = setInterval(load, 10_000);
|
() => load(sortByRef.current, sortDirRef.current, pageRef.current, pageSizeRef.current),
|
||||||
|
10_000,
|
||||||
|
);
|
||||||
return () => {
|
return () => {
|
||||||
if (pollRef.current) clearInterval(pollRef.current);
|
if (pollRef.current) clearInterval(pollRef.current);
|
||||||
};
|
};
|
||||||
}, [load]);
|
}, [load]);
|
||||||
|
|
||||||
|
const handleSort = (key: string, dir: SortDirection) => {
|
||||||
|
setSortBy(key);
|
||||||
|
setSortDir(dir);
|
||||||
|
setPage(1);
|
||||||
|
load(key, dir, 1, pageSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePageChange = (p: number) => {
|
||||||
|
setPage(p);
|
||||||
|
load(sortBy, sortDir, p, pageSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePageSizeChange = (size: number) => {
|
||||||
|
setPageSize(size);
|
||||||
|
setPage(1);
|
||||||
|
load(sortBy, sortDir, 1, size);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
environments
|
environments
|
||||||
.list(1, 200)
|
.list(1, 200)
|
||||||
@@ -102,7 +144,7 @@ export function RunsPage() {
|
|||||||
setRunning(true);
|
setRunning(true);
|
||||||
try {
|
try {
|
||||||
const run = await scenarios.run(id!, selectedEnvId);
|
const run = await scenarios.run(id!, selectedEnvId);
|
||||||
toast.success('Scenario run started');
|
toast.success(t('scenarios.run_started'));
|
||||||
navigate(`/scenarios/${id}/runs/${run.id}`);
|
navigate(`/scenarios/${id}/runs/${run.id}`);
|
||||||
setRunModalOpen(false);
|
setRunModalOpen(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -118,18 +160,25 @@ export function RunsPage() {
|
|||||||
key: 'status',
|
key: 'status',
|
||||||
header: t('runs.col_status'),
|
header: t('runs.col_status'),
|
||||||
width: 100,
|
width: 100,
|
||||||
|
sortable: true,
|
||||||
render: (r) => <Badge variant={STATUS_VARIANT[r.status]}>{STATUS_LABEL[r.status]}</Badge>,
|
render: (r) => <Badge variant={STATUS_VARIANT[r.status]}>{STATUS_LABEL[r.status]}</Badge>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'steps',
|
key: 'scenarioVersion',
|
||||||
header: t('runs.col_steps'),
|
header: t('runs.col_version'),
|
||||||
width: 80,
|
width: 80,
|
||||||
render: (r) => r.stepRuns.length,
|
render: (r) =>
|
||||||
|
r.scenarioVersion != null ? (
|
||||||
|
`v${r.scenarioVersion}`
|
||||||
|
) : (
|
||||||
|
<span className={styles.muted}>–</span>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'created',
|
key: 'createdAt',
|
||||||
header: t('runs.col_created'),
|
header: t('runs.col_created'),
|
||||||
width: 160,
|
width: 160,
|
||||||
|
sortable: true,
|
||||||
render: (r) => <Timestamp value={r.createdAt} />,
|
render: (r) => <Timestamp value={r.createdAt} />,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
@@ -139,7 +188,11 @@ export function RunsPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('scenarios.title'), icon: <ClipboardList size={14} />, onClick: () => navigate('/scenarios') },
|
{
|
||||||
|
label: t('scenarios.title'),
|
||||||
|
icon: <ClipboardList size={14} />,
|
||||||
|
onClick: () => navigate('/scenarios'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: scenario?.name ?? `#${id}`,
|
label: scenario?.name ?? `#${id}`,
|
||||||
onClick: () => navigate(`/scenarios/${id}`),
|
onClick: () => navigate(`/scenarios/${id}`),
|
||||||
@@ -148,7 +201,12 @@ export function RunsPage() {
|
|||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<div className={styles.toolbarActions}>
|
<div className={styles.toolbarActions}>
|
||||||
<AutoRefreshIndicator active pulseKey={pulseKey} error={!!error} onClick={load} />
|
<AutoRefreshIndicator
|
||||||
|
active
|
||||||
|
pulseKey={pulseKey}
|
||||||
|
error={!!error}
|
||||||
|
onClick={() => load(sortBy, sortDir, page, pageSize)}
|
||||||
|
/>
|
||||||
<Button size="sm" onClick={() => setRunModalOpen(true)}>
|
<Button size="sm" onClick={() => setRunModalOpen(true)}>
|
||||||
<Play size={14} />
|
<Play size={14} />
|
||||||
{t('runs.action_run')}
|
{t('runs.action_run')}
|
||||||
@@ -162,25 +220,32 @@ export function RunsPage() {
|
|||||||
rowKey={(r) => r.id}
|
rowKey={(r) => r.id}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
emptyMessage={t('runs.empty')}
|
emptyMessage={t('runs.empty')}
|
||||||
pageSize={20}
|
pageSize={pageSize}
|
||||||
pageSizeOptions={[10, 20, 50]}
|
pageSizeOptions={[10, 20, 50]}
|
||||||
onRowClick={(r) => navigate(`/scenarios/${id}/runs/${r.id}`)}
|
onRowClick={(r) => navigate(`/scenarios/${id}/runs/${r.id}`)}
|
||||||
|
sortBy={sortBy}
|
||||||
|
sortDir={sortDir}
|
||||||
|
onSort={handleSort}
|
||||||
|
total={total}
|
||||||
|
page={page}
|
||||||
|
onPageChange={handlePageChange}
|
||||||
|
onPageSizeChange={handlePageSizeChange}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
open={runModalOpen}
|
open={runModalOpen}
|
||||||
title={t('scenarios.run_modal_title')}
|
title={t('scenarios.run_modal_title')}
|
||||||
onClose={() => !running && setRunModalOpen(false)}
|
onClose={() => !running && setRunModalOpen(false)}
|
||||||
footer={(
|
footer={
|
||||||
<>
|
<>
|
||||||
<Button variant="secondary" onClick={() => setRunModalOpen(false)} disabled={running}>
|
<Button variant="secondary" onClick={() => setRunModalOpen(false)} disabled={running}>
|
||||||
Cancel
|
{t('common.button_cancel')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="primary" onClick={handleRun} disabled={running || !selectedEnvId}>
|
<Button variant="primary" onClick={handleRun} disabled={running || !selectedEnvId}>
|
||||||
{t('runs.action_run')}
|
{t('runs.action_run')}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
}
|
||||||
>
|
>
|
||||||
{envs.length === 0 ? (
|
{envs.length === 0 ? (
|
||||||
<p>{t('scenarios.run_modal_no_env')}</p>
|
<p>{t('scenarios.run_modal_no_env')}</p>
|
||||||
|
|||||||
@@ -1,36 +1,50 @@
|
|||||||
import { useState } from 'react';
|
import { useEffect, useState, SubmitEvent } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { X, Save, ClipboardList } from 'lucide-react';
|
import { X, Save, ClipboardList } from 'lucide-react';
|
||||||
import { scenarios } from '../../api';
|
import { scenarios, environments } from '../../api';
|
||||||
import { Breadcrumbs, Button, Card, Input, useToast } from '../../ui';
|
import type { Environment } from '../../api';
|
||||||
|
import { Breadcrumbs, Button, Card, Input, CodeEditor, Select, useToast } from '../../ui';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function CreateScenarioPage() {
|
export function CreateScenarioPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
usePageTitle(t('scenarios.create_title'));
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
|
const [description, setDescription] = useState('');
|
||||||
|
const [environmentId, setEnvironmentId] = useState('');
|
||||||
|
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||||
const [nameError, setNameError] = useState('');
|
const [nameError, setNameError] = useState('');
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
useEffect(() => {
|
||||||
|
environments
|
||||||
|
.list(1, 200)
|
||||||
|
.then((r) => setEnvs(r?.data ?? []))
|
||||||
|
.catch(() => {});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleSubmit = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!name.trim()) {
|
if (!name.trim()) {
|
||||||
setNameError(t('scenarios.form_name_required'));
|
setNameError(t('scenarios.form_name_required'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
|
||||||
try {
|
try {
|
||||||
const scenario = await scenarios.create(name.trim());
|
const scenario = await scenarios.create(
|
||||||
toast.success('Scenario created');
|
name.trim(),
|
||||||
|
description.trim() || undefined,
|
||||||
|
environmentId || undefined,
|
||||||
|
);
|
||||||
|
toast.success(t('scenarios.created'));
|
||||||
navigate(`/scenarios/${scenario.id}`);
|
navigate(`/scenarios/${scenario.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message;
|
const message = (err as Error).message;
|
||||||
setError(message);
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
@@ -42,7 +56,11 @@ export function CreateScenarioPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('scenarios.title'), icon: <ClipboardList size={14} />, onClick: () => navigate('/scenarios') },
|
{
|
||||||
|
label: t('scenarios.title'),
|
||||||
|
icon: <ClipboardList size={14} />,
|
||||||
|
onClick: () => navigate('/scenarios'),
|
||||||
|
},
|
||||||
{ label: t('scenarios.create_title') },
|
{ label: t('scenarios.create_title') },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
@@ -63,6 +81,24 @@ export function CreateScenarioPage() {
|
|||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
|
<div className={styles.formField}>
|
||||||
|
<label className={styles.fieldLabel}>{t('scenarios.form_description')}</label>
|
||||||
|
<CodeEditor
|
||||||
|
language="markdown"
|
||||||
|
value={description}
|
||||||
|
onChange={setDescription}
|
||||||
|
rows={8}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Select
|
||||||
|
label={t('scenarios.form_environment')}
|
||||||
|
value={environmentId}
|
||||||
|
onChange={(e) => setEnvironmentId(e.target.value)}
|
||||||
|
options={[
|
||||||
|
{ value: '', label: t('scenarios.form_environment_none') },
|
||||||
|
...envs.map((env) => ({ value: env.id, label: env.name })),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.formActions}>
|
<div className={styles.formActions}>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState, SubmitEvent } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { X, Save, ClipboardList } from 'lucide-react';
|
import { X, Save, ClipboardList } from 'lucide-react';
|
||||||
import { scenarios, steps } from '../../api';
|
import { scenarios, steps } from '../../api';
|
||||||
import type { Scenario } from '../../api';
|
import type { Scenario } from '../../api';
|
||||||
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
||||||
|
import { CodeHelpButton } from '../../components/modals';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function CreateStepPage() {
|
export function CreateStepPage() {
|
||||||
@@ -14,10 +16,11 @@ export function CreateStepPage() {
|
|||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
const [scenario, setScenario] = useState<Scenario | null>(null);
|
const [scenario, setScenario] = useState<Scenario | null>(null);
|
||||||
|
usePageTitle(t('steps.create_title'));
|
||||||
const [title, setTitle] = useState('');
|
const [title, setTitle] = useState('');
|
||||||
const [execCode, setExecCode] = useState('');
|
const [execCode, setExecCode] = useState('');
|
||||||
|
const [timeoutSeconds, setTimeoutSeconds] = useState<string>('');
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
@@ -27,20 +30,19 @@ export function CreateStepPage() {
|
|||||||
.catch(() => null);
|
.catch(() => null);
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
|
||||||
try {
|
try {
|
||||||
await steps.create(id!, {
|
await steps.create(id!, {
|
||||||
title: title.trim() || undefined,
|
title: title.trim() || undefined,
|
||||||
execCode: execCode.trim() || undefined,
|
execCode: execCode.trim() || undefined,
|
||||||
|
timeoutSeconds: timeoutSeconds.trim() ? Number(timeoutSeconds) : undefined,
|
||||||
});
|
});
|
||||||
toast.success('Step created');
|
toast.success(t('steps.created'));
|
||||||
navigate(`/scenarios/${id}`);
|
navigate(`/scenarios/${id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message;
|
const message = (err as Error).message;
|
||||||
setError(message);
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
@@ -52,7 +54,11 @@ export function CreateStepPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('scenarios.title'), icon: <ClipboardList size={14} />, onClick: () => navigate('/scenarios') },
|
{
|
||||||
|
label: t('scenarios.title'),
|
||||||
|
icon: <ClipboardList size={14} />,
|
||||||
|
onClick: () => navigate('/scenarios'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: scenario?.name ?? `#${id}`,
|
label: scenario?.name ?? `#${id}`,
|
||||||
onClick: () => navigate(`/scenarios/${id}`),
|
onClick: () => navigate(`/scenarios/${id}`),
|
||||||
@@ -72,9 +78,21 @@ export function CreateStepPage() {
|
|||||||
onChange={(e) => setTitle(e.target.value)}
|
onChange={(e) => setTitle(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<div className={styles.formField}>
|
<div className={styles.formField}>
|
||||||
<label className={styles.fieldLabel}>{t('steps.form_exec_code')}</label>
|
<div className={styles.labelRow}>
|
||||||
|
<label className={styles.fieldLabel}>{t('steps.form_exec_code')}</label>
|
||||||
|
<CodeHelpButton />
|
||||||
|
</div>
|
||||||
<CodeEditor value={execCode} onChange={setExecCode} rows={6} />
|
<CodeEditor value={execCode} onChange={setExecCode} rows={6} />
|
||||||
</div>
|
</div>
|
||||||
|
<Input
|
||||||
|
label={t('steps.form_timeout')}
|
||||||
|
placeholder={t('steps.form_timeout_placeholder')}
|
||||||
|
type="number"
|
||||||
|
min={1}
|
||||||
|
value={timeoutSeconds}
|
||||||
|
onChange={(e) => setTimeoutSeconds(e.target.value)}
|
||||||
|
hint={t('steps.form_timeout_hint')}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.formActions}>
|
<div className={styles.formActions}>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState, SubmitEvent } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { X, Save, ClipboardList } from 'lucide-react';
|
import { X, Save, ClipboardList } from 'lucide-react';
|
||||||
import { scenarios } from '../../api';
|
import { scenarios, environments } from '../../api';
|
||||||
import type { Scenario } from '../../api';
|
import type { Scenario, Environment } from '../../api';
|
||||||
import { Breadcrumbs, Button, Card, Input, useToast } from '../../ui';
|
import { Breadcrumbs, Button, Card, Input, CodeEditor, Select, useToast } from '../../ui';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function EditScenarioPage() {
|
export function EditScenarioPage() {
|
||||||
@@ -15,10 +16,16 @@ export function EditScenarioPage() {
|
|||||||
|
|
||||||
const [scenario, setScenario] = useState<Scenario | null>(null);
|
const [scenario, setScenario] = useState<Scenario | null>(null);
|
||||||
const [name, setName] = useState('');
|
const [name, setName] = useState('');
|
||||||
|
usePageTitle(
|
||||||
|
scenario ? `${t('scenarios.edit_title')} — ${scenario.name}` : t('scenarios.edit_title'),
|
||||||
|
);
|
||||||
|
const [description, setDescription] = useState('');
|
||||||
|
const [environmentId, setEnvironmentId] = useState<string>('');
|
||||||
|
const [timeoutSeconds, setTimeoutSeconds] = useState<string>('');
|
||||||
|
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||||
const [nameError, setNameError] = useState('');
|
const [nameError, setNameError] = useState('');
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
@@ -27,26 +34,35 @@ export function EditScenarioPage() {
|
|||||||
.then((data) => {
|
.then((data) => {
|
||||||
setScenario(data);
|
setScenario(data);
|
||||||
setName(data.name);
|
setName(data.name);
|
||||||
|
setDescription(data.description || '');
|
||||||
|
setEnvironmentId(data.environmentId ?? '');
|
||||||
|
setTimeoutSeconds(data.timeoutSeconds != null ? String(data.timeoutSeconds) : '');
|
||||||
})
|
})
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
|
environments
|
||||||
|
.list(1, 200)
|
||||||
|
.then((r) => setEnvs(r?.data ?? []))
|
||||||
|
.catch(() => {});
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!name.trim()) {
|
if (!name.trim()) {
|
||||||
setNameError(t('scenarios.form_name_required'));
|
setNameError(t('scenarios.form_name_required'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
|
||||||
try {
|
try {
|
||||||
await scenarios.update(id!, { name: name.trim() });
|
await scenarios.update(id!, {
|
||||||
toast.success('Scenario updated');
|
name: name.trim(),
|
||||||
|
description: description.trim() || undefined,
|
||||||
|
environmentId: environmentId || null,
|
||||||
|
timeoutSeconds: timeoutSeconds.trim() ? Number(timeoutSeconds) : null,
|
||||||
|
});
|
||||||
|
toast.success(t('scenarios.updated'));
|
||||||
navigate(`/scenarios/${id}`);
|
navigate(`/scenarios/${id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message;
|
const message = (err as Error).message;
|
||||||
setError(message);
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
@@ -58,7 +74,11 @@ export function EditScenarioPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('scenarios.title'), icon: <ClipboardList size={14} />, onClick: () => navigate('/scenarios') },
|
{
|
||||||
|
label: t('scenarios.title'),
|
||||||
|
icon: <ClipboardList size={14} />,
|
||||||
|
onClick: () => navigate('/scenarios'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: scenario?.name ?? `#${id}`,
|
label: scenario?.name ?? `#${id}`,
|
||||||
onClick: () => navigate(`/scenarios/${id}`),
|
onClick: () => navigate(`/scenarios/${id}`),
|
||||||
@@ -86,6 +106,33 @@ export function EditScenarioPage() {
|
|||||||
required
|
required
|
||||||
autoFocus
|
autoFocus
|
||||||
/>
|
/>
|
||||||
|
<div className={styles.formField}>
|
||||||
|
<label className={styles.fieldLabel}>{t('scenarios.form_description')}</label>
|
||||||
|
<CodeEditor
|
||||||
|
language="markdown"
|
||||||
|
value={description}
|
||||||
|
onChange={setDescription}
|
||||||
|
rows={8}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Select
|
||||||
|
label={t('scenarios.form_environment')}
|
||||||
|
value={environmentId}
|
||||||
|
onChange={(e) => setEnvironmentId(e.target.value)}
|
||||||
|
options={[
|
||||||
|
{ value: '', label: t('scenarios.form_environment_none') },
|
||||||
|
...envs.map((env) => ({ value: env.id, label: env.name })),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
label={t('scenarios.form_timeout')}
|
||||||
|
placeholder={t('scenarios.form_timeout_placeholder')}
|
||||||
|
type="number"
|
||||||
|
min={1}
|
||||||
|
value={timeoutSeconds}
|
||||||
|
onChange={(e) => setTimeoutSeconds(e.target.value)}
|
||||||
|
hint={t('scenarios.form_timeout_hint')}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.formActions}>
|
<div className={styles.formActions}>
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState, SubmitEvent } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { X, Save, ClipboardList } from 'lucide-react';
|
import { X, Save, ClipboardList } from 'lucide-react';
|
||||||
import { scenarios, steps } from '../../api';
|
import { scenarios, steps } from '../../api';
|
||||||
import type { Scenario, ScenarioStep } from '../../api';
|
import type { Scenario, ScenarioStep } from '../../api';
|
||||||
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
||||||
|
import { CodeHelpButton } from '../../components/modals';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function EditStepPage() {
|
export function EditStepPage() {
|
||||||
@@ -15,11 +17,14 @@ export function EditStepPage() {
|
|||||||
|
|
||||||
const [scenario, setScenario] = useState<Scenario | null>(null);
|
const [scenario, setScenario] = useState<Scenario | null>(null);
|
||||||
const [step, setStep] = useState<ScenarioStep | null>(null);
|
const [step, setStep] = useState<ScenarioStep | null>(null);
|
||||||
|
usePageTitle(
|
||||||
|
step ? t('steps.edit_title', { order: step.order }) : t('steps.edit_title', { order: '' }),
|
||||||
|
);
|
||||||
const [title, setTitle] = useState('');
|
const [title, setTitle] = useState('');
|
||||||
const [execCode, setExecCode] = useState('');
|
const [execCode, setExecCode] = useState('');
|
||||||
|
const [timeoutSeconds, setTimeoutSeconds] = useState<string>('');
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id || !stepId) return;
|
if (!id || !stepId) return;
|
||||||
@@ -29,25 +34,24 @@ export function EditStepPage() {
|
|||||||
setStep(st);
|
setStep(st);
|
||||||
setTitle(st.title ?? '');
|
setTitle(st.title ?? '');
|
||||||
setExecCode(st.execCode ?? '');
|
setExecCode(st.execCode ?? '');
|
||||||
|
setTimeoutSeconds(st.timeoutSeconds != null ? String(st.timeoutSeconds) : '');
|
||||||
})
|
})
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [id, stepId]);
|
}, [id, stepId]);
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
|
||||||
try {
|
try {
|
||||||
await steps.update(id!, stepId!, {
|
await steps.update(id!, stepId!, {
|
||||||
title: title.trim() || undefined,
|
title: title.trim() || undefined,
|
||||||
execCode: execCode.trim() || undefined,
|
execCode: execCode.trim() || undefined,
|
||||||
|
timeoutSeconds: timeoutSeconds.trim() ? Number(timeoutSeconds) : null,
|
||||||
});
|
});
|
||||||
toast.success('Step updated');
|
toast.success(t('steps.updated'));
|
||||||
navigate(`/scenarios/${id}`);
|
navigate(`/scenarios/${id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message;
|
const message = (err as Error).message;
|
||||||
setError(message);
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
@@ -59,12 +63,16 @@ export function EditStepPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('scenarios.title'), icon: <ClipboardList size={14} />, onClick: () => navigate('/scenarios') },
|
{
|
||||||
|
label: t('scenarios.title'),
|
||||||
|
icon: <ClipboardList size={14} />,
|
||||||
|
onClick: () => navigate('/scenarios'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: scenario?.name ?? `#${id}`,
|
label: scenario?.name ?? `#${id}`,
|
||||||
onClick: () => navigate(`/scenarios/${id}`),
|
onClick: () => navigate(`/scenarios/${id}`),
|
||||||
},
|
},
|
||||||
{ label: t('steps.edit_title', { order: step ? step.order + 1 : stepId }) },
|
{ label: t('steps.edit_title', { order: step ? step.order : stepId }) },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -82,9 +90,21 @@ export function EditStepPage() {
|
|||||||
onChange={(e) => setTitle(e.target.value)}
|
onChange={(e) => setTitle(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<div className={styles.formField}>
|
<div className={styles.formField}>
|
||||||
<label className={styles.fieldLabel}>{t('steps.form_exec_code')}</label>
|
<div className={styles.labelRow}>
|
||||||
|
<label className={styles.fieldLabel}>{t('steps.form_exec_code')}</label>
|
||||||
|
<CodeHelpButton />
|
||||||
|
</div>
|
||||||
<CodeEditor value={execCode} onChange={setExecCode} rows={6} />
|
<CodeEditor value={execCode} onChange={setExecCode} rows={6} />
|
||||||
</div>
|
</div>
|
||||||
|
<Input
|
||||||
|
label={t('steps.form_timeout')}
|
||||||
|
placeholder={t('steps.form_timeout_placeholder')}
|
||||||
|
type="number"
|
||||||
|
min={1}
|
||||||
|
value={timeoutSeconds}
|
||||||
|
onChange={(e) => setTimeoutSeconds(e.target.value)}
|
||||||
|
hint={t('steps.form_timeout_hint')}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.formActions}>
|
<div className={styles.formActions}>
|
||||||
|
|||||||
@@ -1,10 +1,38 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState, useCallback, SubmitEvent } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Play, Pencil, Plus, History, Trash2, Upload, GripVertical, ClipboardList } from 'lucide-react';
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { stringify as yamlStringify } from 'yaml';
|
import {
|
||||||
import { environments, scenarios, steps, scenarioCredentials, credentials as credentialsApi } from '../../api';
|
Play,
|
||||||
import type { Scenario, ScenarioStep, ScenarioCredential, Credential, Environment } from '../../api';
|
Pencil,
|
||||||
|
Plus,
|
||||||
|
History,
|
||||||
|
Download,
|
||||||
|
Trash2,
|
||||||
|
Upload,
|
||||||
|
GripVertical,
|
||||||
|
ClipboardList,
|
||||||
|
FileArchive,
|
||||||
|
} from 'lucide-react';
|
||||||
|
import {
|
||||||
|
environments,
|
||||||
|
scenarios,
|
||||||
|
steps,
|
||||||
|
scenarioCredentials,
|
||||||
|
scenarioFiles,
|
||||||
|
credentials as credentialsApi,
|
||||||
|
} from '../../api';
|
||||||
|
import type {
|
||||||
|
Scenario,
|
||||||
|
ScenarioStep,
|
||||||
|
ScenarioCredential,
|
||||||
|
Credential,
|
||||||
|
Environment,
|
||||||
|
FileMetadata,
|
||||||
|
ScenarioVersion,
|
||||||
|
TraceMode,
|
||||||
|
UsedSnippet,
|
||||||
|
} from '../../api';
|
||||||
import {
|
import {
|
||||||
Breadcrumbs,
|
Breadcrumbs,
|
||||||
Button,
|
Button,
|
||||||
@@ -16,9 +44,12 @@ import {
|
|||||||
Table,
|
Table,
|
||||||
Timestamp,
|
Timestamp,
|
||||||
UuidBadge,
|
UuidBadge,
|
||||||
|
MarkdownContent,
|
||||||
useToast,
|
useToast,
|
||||||
type TableColumn,
|
type TableColumn,
|
||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
|
import { ExportScenarioModal, RunScenarioModal } from '../../components/modals';
|
||||||
|
import { useRunDefaults } from '../../hooks/useRunDefaults';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function ScenarioDetailPage() {
|
export function ScenarioDetailPage() {
|
||||||
@@ -28,7 +59,7 @@ export function ScenarioDetailPage() {
|
|||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const [scenario, setScenario] = useState<(Scenario & { steps: ScenarioStep[] }) | null>(null);
|
const [scenario, setScenario] = useState<(Scenario & { steps: ScenarioStep[] }) | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
usePageTitle(scenario?.name ?? null);
|
||||||
|
|
||||||
// Credentials state
|
// Credentials state
|
||||||
const [scenarioCreds, setScenarioCreds] = useState<ScenarioCredential[]>([]);
|
const [scenarioCreds, setScenarioCreds] = useState<ScenarioCredential[]>([]);
|
||||||
@@ -44,6 +75,14 @@ export function ScenarioDetailPage() {
|
|||||||
const [reorderingSteps, setReorderingSteps] = useState(false);
|
const [reorderingSteps, setReorderingSteps] = useState(false);
|
||||||
const [runModalOpen, setRunModalOpen] = useState(false);
|
const [runModalOpen, setRunModalOpen] = useState(false);
|
||||||
const [running, setRunning] = useState(false);
|
const [running, setRunning] = useState(false);
|
||||||
|
const [saveSessionFlag, setSaveSessionFlag] = useState(false);
|
||||||
|
// null = use the server's configured default
|
||||||
|
const [traceModeOverride, setTraceModeOverride] = useState<TraceMode | null>(null);
|
||||||
|
const runDefaults = useRunDefaults();
|
||||||
|
const [runVersions, setRunVersions] = useState<ScenarioVersion[]>([]);
|
||||||
|
// null = latest
|
||||||
|
const [runVersion, setRunVersion] = useState<number | null>(null);
|
||||||
|
const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'off';
|
||||||
const [envs, setEnvs] = useState<Environment[]>([]);
|
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||||
const [selectedEnvId, setSelectedEnvId] = useState('');
|
const [selectedEnvId, setSelectedEnvId] = useState('');
|
||||||
const [pendingDelete, setPendingDelete] = useState<
|
const [pendingDelete, setPendingDelete] = useState<
|
||||||
@@ -51,6 +90,40 @@ export function ScenarioDetailPage() {
|
|||||||
>(null);
|
>(null);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
|
|
||||||
|
// Export modal state
|
||||||
|
const [exportModalOpen, setExportModalOpen] = useState(false);
|
||||||
|
const [includeEnvironment, setIncludeEnvironment] = useState(true);
|
||||||
|
const [includedCredentialIds, setIncludedCredentialIds] = useState<Set<string>>(new Set());
|
||||||
|
const [includedSnippetIds, setIncludedSnippetIds] = useState<Set<string>>(new Set());
|
||||||
|
const [isExporting, setIsExporting] = useState(false);
|
||||||
|
|
||||||
|
// Files state
|
||||||
|
const [files, setFiles] = useState<FileMetadata[]>([]);
|
||||||
|
const [filesLoading, setFilesLoading] = useState(true);
|
||||||
|
const [uploadOpen, setUploadOpen] = useState(false);
|
||||||
|
const [uploadFile, setUploadFile] = useState<File | null>(null);
|
||||||
|
const [uploadExpiresAt, setUploadExpiresAt] = useState('');
|
||||||
|
const [uploading, setUploading] = useState(false);
|
||||||
|
|
||||||
|
const [usedSnippets, setUsedSnippets] = useState<UsedSnippet[]>([]);
|
||||||
|
|
||||||
|
// Fetches the files; `filesLoading` starts as true for the fetch from the
|
||||||
|
// load effect, and `loadFiles` sets it for reloads (e.g. after an upload)
|
||||||
|
const fetchFiles = useCallback(async () => {
|
||||||
|
if (!id) return;
|
||||||
|
try {
|
||||||
|
const result = await scenarioFiles.list(id);
|
||||||
|
setFiles(result.items);
|
||||||
|
} finally {
|
||||||
|
setFilesLoading(false);
|
||||||
|
}
|
||||||
|
}, [id]);
|
||||||
|
|
||||||
|
const loadFiles = async () => {
|
||||||
|
setFilesLoading(true);
|
||||||
|
await fetchFiles();
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
void scenarios
|
void scenarios
|
||||||
@@ -59,8 +132,12 @@ export function ScenarioDetailPage() {
|
|||||||
setScenario(s);
|
setScenario(s);
|
||||||
setScenarioCreds(s.scenarioCredentials ?? []);
|
setScenarioCreds(s.scenarioCredentials ?? []);
|
||||||
})
|
})
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
|
void fetchFiles();
|
||||||
|
scenarios
|
||||||
|
.usedSnippets(id)
|
||||||
|
.then(setUsedSnippets)
|
||||||
|
.catch(() => {});
|
||||||
credentialsApi
|
credentialsApi
|
||||||
.list(1, 200)
|
.list(1, 200)
|
||||||
.then((r) => setAllCredentials(r.data))
|
.then((r) => setAllCredentials(r.data))
|
||||||
@@ -69,16 +146,37 @@ export function ScenarioDetailPage() {
|
|||||||
.list(1, 200)
|
.list(1, 200)
|
||||||
.then((r) => {
|
.then((r) => {
|
||||||
setEnvs(r.data);
|
setEnvs(r.data);
|
||||||
setSelectedEnvId((prev) => prev || r.data[0]?.id || '');
|
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}, [id]);
|
}, [id, fetchFiles]);
|
||||||
|
|
||||||
|
const openRunModal = () => {
|
||||||
|
// Preselect the scenario's default environment (or the first one) when the
|
||||||
|
// modal opens: by then both are loaded, and it follows default env edits
|
||||||
|
const preferred = scenario?.environmentId ?? null;
|
||||||
|
const exists = preferred ? envs.some((e) => e.id === preferred) : false;
|
||||||
|
setSelectedEnvId(exists ? preferred! : (envs[0]?.id ?? ''));
|
||||||
|
setTraceModeOverride(null);
|
||||||
|
setRunVersion(null);
|
||||||
|
setRunVersions([]);
|
||||||
|
if (id) {
|
||||||
|
scenarios
|
||||||
|
.versions(id)
|
||||||
|
.then(setRunVersions)
|
||||||
|
.catch(() => undefined);
|
||||||
|
}
|
||||||
|
setRunModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
const reloadScenario = async () => {
|
const reloadScenario = async () => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
const s = await scenarios.get(id);
|
const s = await scenarios.get(id);
|
||||||
setScenario(s);
|
setScenario(s);
|
||||||
setScenarioCreds(s.scenarioCredentials ?? []);
|
setScenarioCreds(s.scenarioCredentials ?? []);
|
||||||
|
scenarios
|
||||||
|
.usedSnippets(id)
|
||||||
|
.then(setUsedSnippets)
|
||||||
|
.catch(() => {});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRun = async () => {
|
const handleRun = async () => {
|
||||||
@@ -89,10 +187,17 @@ export function ScenarioDetailPage() {
|
|||||||
}
|
}
|
||||||
setRunning(true);
|
setRunning(true);
|
||||||
try {
|
try {
|
||||||
const run = await scenarios.run(scenario.id, selectedEnvId);
|
const run = await scenarios.run(
|
||||||
toast.success('Scenario run started');
|
scenario.id,
|
||||||
|
selectedEnvId,
|
||||||
|
saveSessionFlag,
|
||||||
|
traceModeOverride ?? undefined,
|
||||||
|
runVersion ?? undefined,
|
||||||
|
);
|
||||||
|
toast.success(t('scenarios.run_started'));
|
||||||
navigate(`/scenarios/${id}/runs/${run.id}`);
|
navigate(`/scenarios/${id}/runs/${run.id}`);
|
||||||
setRunModalOpen(false);
|
setRunModalOpen(false);
|
||||||
|
setSaveSessionFlag(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error((err as Error).message);
|
toast.error((err as Error).message);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -106,19 +211,73 @@ export function ScenarioDetailPage() {
|
|||||||
navigate('/scenarios');
|
navigate('/scenarios');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleOpenExportModal = () => {
|
||||||
|
if (!scenario) return;
|
||||||
|
// Initialise all credential and snippet checkboxes to checked
|
||||||
|
setIncludedCredentialIds(new Set(scenarioCreds.map((sc) => sc.credentialId)));
|
||||||
|
setIncludedSnippetIds(new Set(usedSnippets.map((s) => s.id)));
|
||||||
|
setIncludeEnvironment(true);
|
||||||
|
setExportModalOpen(true);
|
||||||
|
};
|
||||||
|
|
||||||
const handleExport = async () => {
|
const handleExport = async () => {
|
||||||
if (!scenario) return;
|
if (!scenario) return;
|
||||||
const data = await scenarios.exportScenario(scenario.id);
|
setIsExporting(true);
|
||||||
const yamlContent = typeof data === 'string' ? data : yamlStringify(data);
|
try {
|
||||||
const blob = new Blob([yamlContent], { type: 'application/yaml' });
|
const credIds = Array.from(includedCredentialIds);
|
||||||
const url = URL.createObjectURL(blob);
|
const yamlContent = await scenarios.exportScenario(scenario.id, {
|
||||||
const a = document.createElement('a');
|
includeEnvironment,
|
||||||
a.href = url;
|
credentialIds: credIds,
|
||||||
a.download = `${scenario.name}.yaml`;
|
snippetIds: Array.from(includedSnippetIds),
|
||||||
a.click();
|
version: scenario.version,
|
||||||
URL.revokeObjectURL(url);
|
});
|
||||||
|
const blob = new Blob([yamlContent], { type: 'application/yaml' });
|
||||||
|
const url = URL.createObjectURL(blob);
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = `${scenario.name}-v${scenario.version}.yaml`;
|
||||||
|
a.click();
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
setExportModalOpen(false);
|
||||||
|
} catch (err) {
|
||||||
|
toast.error((err as Error).message);
|
||||||
|
} finally {
|
||||||
|
setIsExporting(false);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleFileDownload = (url: string, filename: string) => {
|
||||||
|
const link = document.createElement('a');
|
||||||
|
link.href = url;
|
||||||
|
link.download = filename;
|
||||||
|
link.click();
|
||||||
|
};
|
||||||
|
|
||||||
|
const isFileExpired = (file: FileMetadata) =>
|
||||||
|
file.expiresAt != null && new Date(file.expiresAt).getTime() <= Date.now();
|
||||||
|
|
||||||
|
async function handleUpload(e: SubmitEvent) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!id || !uploadFile) return;
|
||||||
|
setUploading(true);
|
||||||
|
try {
|
||||||
|
await scenarioFiles.upload(
|
||||||
|
id,
|
||||||
|
uploadFile,
|
||||||
|
uploadExpiresAt ? new Date(uploadExpiresAt) : undefined,
|
||||||
|
);
|
||||||
|
setUploadOpen(false);
|
||||||
|
setUploadFile(null);
|
||||||
|
setUploadExpiresAt('');
|
||||||
|
await loadFiles();
|
||||||
|
toast.success(t('files.uploadSuccess'));
|
||||||
|
} catch {
|
||||||
|
// error toast already emitted by API client
|
||||||
|
} finally {
|
||||||
|
setUploading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleDeleteStep = async (stepId: string) => {
|
const handleDeleteStep = async (stepId: string) => {
|
||||||
await steps.remove(id!, stepId);
|
await steps.remove(id!, stepId);
|
||||||
await reloadScenario();
|
await reloadScenario();
|
||||||
@@ -138,7 +297,7 @@ export function ScenarioDetailPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAddCredential = async (e: React.FormEvent) => {
|
const handleAddCredential = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let valid = true;
|
let valid = true;
|
||||||
if (!addCredId) {
|
if (!addCredId) {
|
||||||
@@ -231,7 +390,7 @@ export function ScenarioDetailPage() {
|
|||||||
</span>
|
</span>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{ key: 'order', header: t('scenarios.step_order'), render: (s) => s.order + 1, width: 60 },
|
{ key: 'order', header: t('scenarios.step_order'), render: (s) => s.order, width: 60 },
|
||||||
{
|
{
|
||||||
key: 'title',
|
key: 'title',
|
||||||
header: t('scenarios.step_title'),
|
header: t('scenarios.step_title'),
|
||||||
@@ -319,13 +478,17 @@ export function ScenarioDetailPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('scenarios.title'), icon: <ClipboardList size={14} />, onClick: () => navigate('/scenarios') },
|
{
|
||||||
|
label: t('scenarios.title'),
|
||||||
|
icon: <ClipboardList size={14} />,
|
||||||
|
onClick: () => navigate('/scenarios'),
|
||||||
|
},
|
||||||
{ label: scenario?.name ?? `#${id}` },
|
{ label: scenario?.name ?? `#${id}` },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
{scenario && (
|
{scenario && (
|
||||||
<div className={styles.toolbarActions}>
|
<div className={styles.toolbarActions}>
|
||||||
<Button size="sm" onClick={() => setRunModalOpen(true)}>
|
<Button size="sm" onClick={openRunModal}>
|
||||||
<Play size={14} />
|
<Play size={14} />
|
||||||
{t('scenarios.action_run')}
|
{t('scenarios.action_run')}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -333,15 +496,29 @@ export function ScenarioDetailPage() {
|
|||||||
<History size={14} />
|
<History size={14} />
|
||||||
{t('scenarios.action_runs')}
|
{t('scenarios.action_runs')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="secondary" size="sm" onClick={handleExport}>
|
<Button variant="secondary" size="sm" onClick={handleOpenExportModal}>
|
||||||
<Upload size={14} />
|
<Upload size={14} />
|
||||||
{t('scenarios.action_export')}
|
{t('scenarios.action_export')}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
onClick={() =>
|
||||||
|
handleFileDownload(scenarios.exportE2eTestUrl(id!), `${scenario.name}-e2e-test.zip`)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<FileArchive size={14} />
|
||||||
|
{t('scenarios.action_export_e2e')}
|
||||||
|
</Button>
|
||||||
<Button variant="secondary" size="sm" onClick={() => navigate(`/scenarios/${id}/edit`)}>
|
<Button variant="secondary" size="sm" onClick={() => navigate(`/scenarios/${id}/edit`)}>
|
||||||
<Pencil size={14} />
|
<Pencil size={14} />
|
||||||
{t('scenarios.action_edit')}
|
{t('scenarios.action_edit')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="danger" size="sm" onClick={() => setPendingDelete({ type: 'scenario' })}>
|
<Button
|
||||||
|
variant="danger"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => setPendingDelete({ type: 'scenario' })}
|
||||||
|
>
|
||||||
<Trash2 size={14} />
|
<Trash2 size={14} />
|
||||||
{t('scenarios.action_delete')}
|
{t('scenarios.action_delete')}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -359,6 +536,25 @@ export function ScenarioDetailPage() {
|
|||||||
items={[
|
items={[
|
||||||
{ term: t('scenarios.field_id'), detail: <UuidBadge id={scenario.id} /> },
|
{ term: t('scenarios.field_id'), detail: <UuidBadge id={scenario.id} /> },
|
||||||
{ term: t('scenarios.field_name'), detail: scenario.name },
|
{ term: t('scenarios.field_name'), detail: scenario.name },
|
||||||
|
{ term: t('scenarios.field_version'), detail: `v${scenario.version}` },
|
||||||
|
...(scenario.environment
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
term: t('scenarios.field_environment'),
|
||||||
|
detail: (
|
||||||
|
<a
|
||||||
|
href={`/environments/${scenario.environment.id}`}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
navigate(`/environments/${scenario.environment!.id}`);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{scenario.environment.name}
|
||||||
|
</a>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
{
|
{
|
||||||
term: t('scenarios.field_created'),
|
term: t('scenarios.field_created'),
|
||||||
detail: <Timestamp value={scenario.createdAt} />,
|
detail: <Timestamp value={scenario.createdAt} />,
|
||||||
@@ -371,6 +567,17 @@ export function ScenarioDetailPage() {
|
|||||||
/>
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
|
{scenario.description && (
|
||||||
|
<div className={styles.stepsSection}>
|
||||||
|
<div className={styles.sectionHeadingRow}>
|
||||||
|
<h2 className={styles.sectionHeading}>{t('scenarios.field_description')}</h2>
|
||||||
|
</div>
|
||||||
|
<Card>
|
||||||
|
<MarkdownContent content={scenario.description} />
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{scenario.steps.length > 0 && (
|
{scenario.steps.length > 0 && (
|
||||||
<div className={styles.stepsSection}>
|
<div className={styles.stepsSection}>
|
||||||
<div className={styles.sectionToolbar}>
|
<div className={styles.sectionToolbar}>
|
||||||
@@ -498,6 +705,151 @@ export function ScenarioDetailPage() {
|
|||||||
<p className={styles.muted}>{t('scenarios.cred_empty')}</p>
|
<p className={styles.muted}>{t('scenarios.cred_empty')}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* ── Used snippets section ───────────────────────────────────────── */}
|
||||||
|
{usedSnippets.length > 0 && (
|
||||||
|
<div className={styles.stepsSection}>
|
||||||
|
<div className={styles.sectionToolbar}>
|
||||||
|
<h2 className={styles.sectionHeading}>{t('scenarios.used_snippets_heading')}</h2>
|
||||||
|
</div>
|
||||||
|
<Table<UsedSnippet>
|
||||||
|
data={usedSnippets}
|
||||||
|
rowKey={(s) => `${s.id}@${s.pinnedVersion ?? 'latest'}`}
|
||||||
|
loading={false}
|
||||||
|
emptyMessage=""
|
||||||
|
onRowClick={(s) => navigate(`/snippets/${s.id}`)}
|
||||||
|
columns={
|
||||||
|
[
|
||||||
|
{
|
||||||
|
key: 'alias',
|
||||||
|
header: t('snippets.field_alias'),
|
||||||
|
render: (s) => s.alias,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'title',
|
||||||
|
header: t('snippets.field_title'),
|
||||||
|
render: (s) => s.title,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'version',
|
||||||
|
header: t('snippets.field_version'),
|
||||||
|
render: (s) =>
|
||||||
|
s.pinnedVersion != null
|
||||||
|
? t('scenarios.used_snippet_pinned', { version: s.pinnedVersion })
|
||||||
|
: t('scenarios.used_snippet_latest', { version: s.version }),
|
||||||
|
},
|
||||||
|
] satisfies TableColumn<UsedSnippet>[]
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* ── Files section ───────────────────────────────────────────────── */}
|
||||||
|
<div className={styles.stepsSection}>
|
||||||
|
<div className={styles.sectionToolbar}>
|
||||||
|
<h2 className={styles.sectionHeading}>{t('files.title')}</h2>
|
||||||
|
<Button size="sm" onClick={() => setUploadOpen(true)}>
|
||||||
|
<Upload size={14} /> {t('files.upload')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Table<FileMetadata>
|
||||||
|
loading={filesLoading}
|
||||||
|
data={files}
|
||||||
|
rowKey={(f) => f.id}
|
||||||
|
columns={
|
||||||
|
[
|
||||||
|
{
|
||||||
|
key: 'name',
|
||||||
|
header: t('files.name'),
|
||||||
|
// Served inline, so the browser shows what it can (images, text, PDF).
|
||||||
|
render: (f) =>
|
||||||
|
isFileExpired(f) ? (
|
||||||
|
f.name
|
||||||
|
) : (
|
||||||
|
<a
|
||||||
|
href={scenarioFiles.contentUrl(id!, f.id)}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
>
|
||||||
|
{f.name}
|
||||||
|
</a>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'mimeType',
|
||||||
|
header: t('files.mimeType'),
|
||||||
|
render: (f) => f.mimeType,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'size',
|
||||||
|
header: t('files.size'),
|
||||||
|
render: (f) => `${(f.size / 1024).toFixed(1)} KB`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'expiresAt',
|
||||||
|
header: t('files.expiresAt'),
|
||||||
|
render: (f) => (f.expiresAt ? <Timestamp value={f.expiresAt} /> : '—'),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'createdAt',
|
||||||
|
header: t('files.createdAt'),
|
||||||
|
render: (f) => <Timestamp value={f.createdAt} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'download',
|
||||||
|
header: '',
|
||||||
|
render: (f) => {
|
||||||
|
const expired = isFileExpired(f);
|
||||||
|
const tooltip = expired ? t('files.expiredTooltip') : t('files.download');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<span title={tooltip}>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
title={tooltip}
|
||||||
|
aria-label={tooltip}
|
||||||
|
disabled={expired}
|
||||||
|
onClick={() =>
|
||||||
|
handleFileDownload(scenarioFiles.contentUrl(id!, f.id), f.name)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Download size={14} />
|
||||||
|
</Button>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
] satisfies TableColumn<FileMetadata>[]
|
||||||
|
}
|
||||||
|
emptyMessage={t('files.empty')}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* ── Upload modal ─────────────────────────────────────────────── */}
|
||||||
|
<Modal
|
||||||
|
open={uploadOpen}
|
||||||
|
title={t('files.uploadTitle')}
|
||||||
|
onClose={() => setUploadOpen(false)}
|
||||||
|
>
|
||||||
|
<form onSubmit={handleUpload}>
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
required
|
||||||
|
onChange={(e) => setUploadFile(e.target.files?.[0] ?? null)}
|
||||||
|
/>
|
||||||
|
<Input
|
||||||
|
label={t('files.expiresAtLabel')}
|
||||||
|
type="datetime-local"
|
||||||
|
value={uploadExpiresAt}
|
||||||
|
onChange={(e) => setUploadExpiresAt(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Button type="submit" loading={uploading} disabled={!uploadFile}>
|
||||||
|
{t('files.upload')}
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</Modal>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -511,48 +863,72 @@ export function ScenarioDetailPage() {
|
|||||||
: t('scenarios.action_delete')
|
: t('scenarios.action_delete')
|
||||||
}
|
}
|
||||||
onClose={() => !deleting && setPendingDelete(null)}
|
onClose={() => !deleting && setPendingDelete(null)}
|
||||||
footer={(
|
footer={
|
||||||
<>
|
<>
|
||||||
<Button variant="secondary" onClick={() => setPendingDelete(null)} disabled={deleting}>
|
<Button variant="secondary" onClick={() => setPendingDelete(null)} disabled={deleting}>
|
||||||
Cancel
|
{t('common.button_cancel')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="danger" onClick={confirmDelete} disabled={deleting}>
|
<Button variant="danger" onClick={confirmDelete} disabled={deleting}>
|
||||||
Confirm
|
{t('common.button_confirm')}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
}
|
||||||
>
|
>
|
||||||
{pendingDelete?.type === 'step' && 'Are you sure you want to delete this step?'}
|
{pendingDelete?.type === 'step' && t('common.confirm_delete_step')}
|
||||||
{pendingDelete?.type === 'credential' && 'Are you sure you want to remove this credential from scenario?'}
|
{pendingDelete?.type === 'credential' && t('common.confirm_remove_credential')}
|
||||||
{pendingDelete?.type === 'scenario' && 'Are you sure you want to delete this scenario?'}
|
{pendingDelete?.type === 'scenario' && t('common.confirm_delete_scenario')}
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<Modal
|
<RunScenarioModal
|
||||||
open={runModalOpen}
|
open={runModalOpen}
|
||||||
title={t('scenarios.run_modal_title')}
|
environments={envs}
|
||||||
onClose={() => !running && setRunModalOpen(false)}
|
selectedEnvId={selectedEnvId}
|
||||||
footer={(
|
onEnvSelect={setSelectedEnvId}
|
||||||
<>
|
saveSessionFlag={saveSessionFlag}
|
||||||
<Button variant="secondary" onClick={() => setRunModalOpen(false)} disabled={running}>
|
onSaveSessionChange={setSaveSessionFlag}
|
||||||
Cancel
|
versions={runVersions}
|
||||||
</Button>
|
selectedVersion={runVersion}
|
||||||
<Button variant="primary" onClick={handleRun} disabled={running || !selectedEnvId}>
|
onVersionChange={setRunVersion}
|
||||||
{t('scenarios.action_run')}
|
traceMode={traceMode}
|
||||||
</Button>
|
defaultTraceMode={runDefaults?.traceMode ?? null}
|
||||||
</>
|
onTraceModeChange={setTraceModeOverride}
|
||||||
)}
|
onClose={() => setRunModalOpen(false)}
|
||||||
>
|
onRun={handleRun}
|
||||||
{envs.length === 0 ? (
|
isRunning={running}
|
||||||
<p>{t('scenarios.run_modal_no_env')}</p>
|
/>
|
||||||
) : (
|
|
||||||
<Select
|
<ExportScenarioModal
|
||||||
label={t('scenarios.run_modal_env_label')}
|
open={exportModalOpen}
|
||||||
value={selectedEnvId}
|
scenario={scenario}
|
||||||
onChange={(e) => setSelectedEnvId(e.target.value)}
|
scenarioCredentials={scenarioCreds}
|
||||||
options={envs.map((env) => ({ value: env.id, label: env.name }))}
|
environment={
|
||||||
/>
|
scenario?.environment ?? envs.find((e) => e.id === scenario?.environmentId) ?? null
|
||||||
)}
|
}
|
||||||
</Modal>
|
includeEnvironment={includeEnvironment}
|
||||||
|
onIncludeEnvironmentChange={setIncludeEnvironment}
|
||||||
|
includedCredentialIds={includedCredentialIds}
|
||||||
|
onCredentialToggle={(credId, checked) => {
|
||||||
|
setIncludedCredentialIds((prev) => {
|
||||||
|
const next = new Set(prev);
|
||||||
|
if (checked) next.add(credId);
|
||||||
|
else next.delete(credId);
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
usedSnippets={usedSnippets}
|
||||||
|
includedSnippetIds={includedSnippetIds}
|
||||||
|
onSnippetToggle={(snippetId, checked) => {
|
||||||
|
setIncludedSnippetIds((prev) => {
|
||||||
|
const next = new Set(prev);
|
||||||
|
if (checked) next.add(snippetId);
|
||||||
|
else next.delete(snippetId);
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
}}
|
||||||
|
onClose={() => setExportModalOpen(false)}
|
||||||
|
onExport={handleExport}
|
||||||
|
isExporting={isExporting}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,68 +1,151 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
|
import { useImportFile } from '../../hooks/useImportFile';
|
||||||
import { Play, Plus, Trash2, Download, ClipboardList } from 'lucide-react';
|
import { Play, Plus, Trash2, Download, ClipboardList } from 'lucide-react';
|
||||||
import { parse as yamlParse } from 'yaml';
|
|
||||||
import { environments, scenarios } from '../../api';
|
import { environments, scenarios } from '../../api';
|
||||||
import type { Environment, Scenario } from '../../api';
|
import type { Environment, Scenario, ScenarioVersion, TraceMode } from '../../api';
|
||||||
|
import { RunScenarioModal } from '../../components/modals';
|
||||||
|
import { useRunDefaults } from '../../hooks/useRunDefaults';
|
||||||
import {
|
import {
|
||||||
|
Badge,
|
||||||
Breadcrumbs,
|
Breadcrumbs,
|
||||||
Button,
|
Button,
|
||||||
Modal,
|
Modal,
|
||||||
Select,
|
|
||||||
Table,
|
Table,
|
||||||
type TableColumn,
|
type TableColumn,
|
||||||
|
type SortDirection,
|
||||||
Timestamp,
|
Timestamp,
|
||||||
UuidBadge,
|
UuidBadge,
|
||||||
useToast,
|
useToast,
|
||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
|
import type { BadgeVariant } from '../../ui';
|
||||||
|
import type { ScenarioRunStatus } from '../../api';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
|
const LAST_RUN_VARIANT: Record<ScenarioRunStatus, BadgeVariant> = {
|
||||||
|
pending: 'neutral',
|
||||||
|
in_progress: 'info',
|
||||||
|
pass: 'success',
|
||||||
|
fail: 'error',
|
||||||
|
};
|
||||||
|
|
||||||
|
const LAST_RUN_LABEL: Record<ScenarioRunStatus, string> = {
|
||||||
|
pending: 'Pending',
|
||||||
|
in_progress: 'Running',
|
||||||
|
pass: 'Pass',
|
||||||
|
fail: 'Fail',
|
||||||
|
};
|
||||||
|
|
||||||
export function ScenariosPage() {
|
export function ScenariosPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
usePageTitle(t('scenarios.title'));
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
const [items, setItems] = useState<Scenario[]>([]);
|
const [items, setItems] = useState<Scenario[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
const [runScenarioId, setRunScenarioId] = useState<string | null>(null);
|
const [runScenarioId, setRunScenarioId] = useState<string | null>(null);
|
||||||
const [running, setRunning] = useState(false);
|
const [running, setRunning] = useState(false);
|
||||||
|
const [saveSessionFlag, setSaveSessionFlag] = useState(false);
|
||||||
|
// null = use the server's configured default
|
||||||
|
const [traceModeOverride, setTraceModeOverride] = useState<TraceMode | null>(null);
|
||||||
|
const runDefaults = useRunDefaults();
|
||||||
|
const [runVersions, setRunVersions] = useState<ScenarioVersion[]>([]);
|
||||||
|
// null = latest
|
||||||
|
const [runVersion, setRunVersion] = useState<number | null>(null);
|
||||||
|
const traceMode = traceModeOverride ?? runDefaults?.traceMode ?? 'off';
|
||||||
const [envs, setEnvs] = useState<Environment[]>([]);
|
const [envs, setEnvs] = useState<Environment[]>([]);
|
||||||
const [selectedEnvId, setSelectedEnvId] = useState('');
|
const [selectedEnvId, setSelectedEnvId] = useState('');
|
||||||
|
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const load = useCallback(() => {
|
const [sortBy, setSortBy] = useState('updatedAt');
|
||||||
Promise.all([scenarios.list(), environments.list(1, 200)])
|
const [sortDir, setSortDir] = useState<SortDirection>('desc');
|
||||||
.then(([scenarioRes, envRes]) => {
|
const [page, setPage] = useState(1);
|
||||||
setItems(scenarioRes.data);
|
const [pageSize, setPageSize] = useState(10);
|
||||||
setEnvs(envRes.data);
|
const [total, setTotal] = useState(0);
|
||||||
})
|
|
||||||
.catch((err: Error) => setError(err.message))
|
// Fetches a page; `loading` starts as true for the initial fetch from the
|
||||||
.finally(() => setLoading(false));
|
// effect, and `load` sets it for later ones (no setState inside the effect)
|
||||||
}, []);
|
const fetchPage = useCallback(
|
||||||
|
(orderBy: string, orderDir: SortDirection, p: number, limit: number) => {
|
||||||
|
Promise.all([
|
||||||
|
scenarios.list(p, limit, orderBy, orderDir === 'asc' ? 'ASC' : 'DESC'),
|
||||||
|
environments.list(1, 200),
|
||||||
|
])
|
||||||
|
.then(([scenarioRes, envRes]) => {
|
||||||
|
setItems(scenarioRes?.data ?? []);
|
||||||
|
setTotal(scenarioRes?.total ?? 0);
|
||||||
|
setEnvs(envRes?.data ?? []);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
toast.error((err as Error).message);
|
||||||
|
})
|
||||||
|
.finally(() => setLoading(false));
|
||||||
|
},
|
||||||
|
[toast],
|
||||||
|
);
|
||||||
|
|
||||||
|
const load = (orderBy: string, orderDir: SortDirection, p: number, limit: number) => {
|
||||||
|
setLoading(true);
|
||||||
|
fetchPage(orderBy, orderDir, p, limit);
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
load();
|
fetchPage('updatedAt', 'desc', 1, 10);
|
||||||
}, [load]);
|
}, [fetchPage]);
|
||||||
|
|
||||||
|
const handleSort = (key: string, dir: SortDirection) => {
|
||||||
|
setSortBy(key);
|
||||||
|
setSortDir(dir);
|
||||||
|
setPage(1);
|
||||||
|
load(key, dir, 1, pageSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePageChange = (p: number) => {
|
||||||
|
setPage(p);
|
||||||
|
load(sortBy, sortDir, p, pageSize);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePageSizeChange = (size: number) => {
|
||||||
|
setPageSize(size);
|
||||||
|
setPage(1);
|
||||||
|
load(sortBy, sortDir, 1, size);
|
||||||
|
};
|
||||||
|
|
||||||
const openRunModal = (id: string) => {
|
const openRunModal = (id: string) => {
|
||||||
setRunScenarioId(id);
|
setRunScenarioId(id);
|
||||||
if (!selectedEnvId && envs.length > 0) {
|
setTraceModeOverride(null);
|
||||||
setSelectedEnvId(envs[0].id);
|
setRunVersion(null);
|
||||||
}
|
setRunVersions([]);
|
||||||
|
scenarios
|
||||||
|
.versions(id)
|
||||||
|
.then(setRunVersions)
|
||||||
|
.catch(() => undefined);
|
||||||
|
const scenario = items.find((s) => s.id === id);
|
||||||
|
const preferred = scenario?.environmentId ?? null;
|
||||||
|
const exists = preferred ? envs.some((e) => e.id === preferred) : false;
|
||||||
|
setSelectedEnvId(exists ? preferred! : envs[0]?.id || '');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRun = async () => {
|
const handleRun = async () => {
|
||||||
if (!runScenarioId || !selectedEnvId) return;
|
if (!runScenarioId || !selectedEnvId) return;
|
||||||
setRunning(true);
|
setRunning(true);
|
||||||
try {
|
try {
|
||||||
const run = await scenarios.run(runScenarioId, selectedEnvId);
|
const run = await scenarios.run(
|
||||||
toast.success('Scenario run started');
|
runScenarioId,
|
||||||
|
selectedEnvId,
|
||||||
|
saveSessionFlag,
|
||||||
|
traceModeOverride ?? undefined,
|
||||||
|
runVersion ?? undefined,
|
||||||
|
);
|
||||||
|
toast.success(t('scenarios.run_started'));
|
||||||
navigate(`/scenarios/${runScenarioId}/runs/${run.id}`);
|
navigate(`/scenarios/${runScenarioId}/runs/${run.id}`);
|
||||||
setRunScenarioId(null);
|
setRunScenarioId(null);
|
||||||
|
setSaveSessionFlag(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
toast.error((err as Error).message);
|
toast.error((err as Error).message);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -75,35 +158,47 @@ export function ScenariosPage() {
|
|||||||
setDeleting(true);
|
setDeleting(true);
|
||||||
try {
|
try {
|
||||||
await scenarios.remove(deleteId);
|
await scenarios.remove(deleteId);
|
||||||
setLoading(true);
|
load(sortBy, sortDir, page, pageSize);
|
||||||
load();
|
|
||||||
setDeleteId(null);
|
setDeleteId(null);
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false);
|
setDeleting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleImport = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleImport = useImportFile('scenario');
|
||||||
const file = e.target.files?.[0];
|
|
||||||
if (!file) return;
|
|
||||||
e.target.value = '';
|
|
||||||
try {
|
|
||||||
const text = await file.text();
|
|
||||||
const payload = yamlParse(text) as unknown;
|
|
||||||
const imported = await scenarios.importScenario(payload);
|
|
||||||
navigate(`/scenarios/${imported.id}`);
|
|
||||||
} catch (err) {
|
|
||||||
setError((err as Error).message);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const columns: TableColumn<Scenario>[] = [
|
const columns: TableColumn<Scenario>[] = [
|
||||||
{ key: 'id', header: t('scenarios.col_id'), render: (s) => <UuidBadge id={s.id} />, width: 60 },
|
{ key: 'id', header: t('scenarios.col_id'), render: (s) => <UuidBadge id={s.id} />, width: 60 },
|
||||||
{ key: 'name', header: t('scenarios.col_name'), render: (s) => s.name },
|
{ key: 'name', header: t('scenarios.col_name'), render: (s) => s.name, sortable: true },
|
||||||
{
|
{
|
||||||
key: 'updated',
|
key: 'version',
|
||||||
|
header: t('scenarios.col_version'),
|
||||||
|
width: 80,
|
||||||
|
render: (s) => `v${s.version}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'lastRunStatus',
|
||||||
|
header: t('scenarios.col_last_run'),
|
||||||
|
width: 160,
|
||||||
|
render: (s) =>
|
||||||
|
s.lastRunStatus ? (
|
||||||
|
<span style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}>
|
||||||
|
<span style={{ display: 'inline-flex', minWidth: 62 }}>
|
||||||
|
<Badge variant={LAST_RUN_VARIANT[s.lastRunStatus]}>
|
||||||
|
{LAST_RUN_LABEL[s.lastRunStatus]}
|
||||||
|
</Badge>
|
||||||
|
</span>
|
||||||
|
{s.lastRunAt && <Timestamp value={s.lastRunAt} />}
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<span style={{ color: 'var(--color-text-muted)', fontSize: '0.8em' }}>—</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'updatedAt',
|
||||||
header: t('scenarios.col_updated'),
|
header: t('scenarios.col_updated'),
|
||||||
width: 140,
|
width: 140,
|
||||||
|
sortable: true,
|
||||||
render: (s) => <Timestamp value={s.updatedAt} />,
|
render: (s) => <Timestamp value={s.updatedAt} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -167,55 +262,53 @@ export function ScenariosPage() {
|
|||||||
rowKey={(s) => s.id}
|
rowKey={(s) => s.id}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
emptyMessage={t('scenarios.empty')}
|
emptyMessage={t('scenarios.empty')}
|
||||||
pageSize={10}
|
pageSize={pageSize}
|
||||||
pageSizeOptions={[10, 25, 50]}
|
pageSizeOptions={[10, 25, 50]}
|
||||||
onRowClick={(s) => navigate(`/scenarios/${s.id}`)}
|
onRowClick={(s) => navigate(`/scenarios/${s.id}`)}
|
||||||
|
sortBy={sortBy}
|
||||||
|
sortDir={sortDir}
|
||||||
|
onSort={handleSort}
|
||||||
|
total={total}
|
||||||
|
page={page}
|
||||||
|
onPageChange={handlePageChange}
|
||||||
|
onPageSizeChange={handlePageSizeChange}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
open={deleteId != null}
|
open={deleteId != null}
|
||||||
title={t('scenarios.action_delete')}
|
title={t('scenarios.action_delete')}
|
||||||
onClose={() => !deleting && setDeleteId(null)}
|
onClose={() => !deleting && setDeleteId(null)}
|
||||||
footer={(
|
footer={
|
||||||
<>
|
<>
|
||||||
<Button variant="secondary" onClick={() => setDeleteId(null)} disabled={deleting}>
|
<Button variant="secondary" onClick={() => setDeleteId(null)} disabled={deleting}>
|
||||||
Cancel
|
{t('common.button_cancel')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
||||||
{t('scenarios.action_delete')}
|
{t('scenarios.action_delete')}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
}
|
||||||
>
|
>
|
||||||
Are you sure you want to delete this scenario?
|
{t('common.confirm_delete_scenario')}
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<Modal
|
<RunScenarioModal
|
||||||
open={runScenarioId != null}
|
open={runScenarioId != null}
|
||||||
title={t('scenarios.run_modal_title')}
|
environments={envs}
|
||||||
onClose={() => !running && setRunScenarioId(null)}
|
selectedEnvId={selectedEnvId}
|
||||||
footer={(
|
onEnvSelect={setSelectedEnvId}
|
||||||
<>
|
saveSessionFlag={saveSessionFlag}
|
||||||
<Button variant="secondary" onClick={() => setRunScenarioId(null)} disabled={running}>
|
onSaveSessionChange={setSaveSessionFlag}
|
||||||
Cancel
|
versions={runVersions}
|
||||||
</Button>
|
selectedVersion={runVersion}
|
||||||
<Button variant="primary" onClick={handleRun} disabled={running || !selectedEnvId}>
|
onVersionChange={setRunVersion}
|
||||||
{t('scenarios.action_run')}
|
traceMode={traceMode}
|
||||||
</Button>
|
defaultTraceMode={runDefaults?.traceMode ?? null}
|
||||||
</>
|
onTraceModeChange={setTraceModeOverride}
|
||||||
)}
|
onClose={() => setRunScenarioId(null)}
|
||||||
>
|
onRun={handleRun}
|
||||||
{envs.length === 0 ? (
|
isRunning={running}
|
||||||
<p>{t('scenarios.run_modal_no_env')}</p>
|
/>
|
||||||
) : (
|
|
||||||
<Select
|
|
||||||
label={t('scenarios.run_modal_env_label')}
|
|
||||||
value={selectedEnvId}
|
|
||||||
onChange={(e) => setSelectedEnvId(e.target.value)}
|
|
||||||
options={envs.map((env) => ({ value: env.id, label: env.name }))}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Modal>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,19 +1,12 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { Trash2, Monitor } from 'lucide-react';
|
import { Trash2, Monitor } from 'lucide-react';
|
||||||
import { sessions } from '../../api';
|
import { sessions } from '../../api';
|
||||||
import type { Session } from '../../api';
|
import type { Session } from '../../api';
|
||||||
import {
|
import { Badge, Breadcrumbs, Button, Card, DescriptionList, Timestamp, UuidBadge } from '../../ui';
|
||||||
Badge,
|
import { DeleteConfirmationModal } from '../../components/modals';
|
||||||
Breadcrumbs,
|
|
||||||
Button,
|
|
||||||
Card,
|
|
||||||
DescriptionList,
|
|
||||||
Modal,
|
|
||||||
Timestamp,
|
|
||||||
UuidBadge,
|
|
||||||
} from '../../ui';
|
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function SessionDetailPage() {
|
export function SessionDetailPage() {
|
||||||
@@ -22,7 +15,7 @@ export function SessionDetailPage() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [session, setSession] = useState<Session | null>(null);
|
const [session, setSession] = useState<Session | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
usePageTitle(session?.sessionName ?? null);
|
||||||
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false);
|
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
|
|
||||||
@@ -31,7 +24,6 @@ export function SessionDetailPage() {
|
|||||||
sessions
|
sessions
|
||||||
.get(id)
|
.get(id)
|
||||||
.then(setSession)
|
.then(setSession)
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
@@ -52,7 +44,11 @@ export function SessionDetailPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('sessions.title'), icon: <Monitor size={14} />, onClick: () => navigate('/sessions') },
|
{
|
||||||
|
label: t('sessions.title'),
|
||||||
|
icon: <Monitor size={14} />,
|
||||||
|
onClick: () => navigate('/sessions'),
|
||||||
|
},
|
||||||
{ label: session?.sessionName ?? `#${id}` },
|
{ label: session?.sessionName ?? `#${id}` },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
@@ -102,23 +98,14 @@ export function SessionDetailPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Modal
|
<DeleteConfirmationModal
|
||||||
open={confirmDeleteOpen}
|
open={confirmDeleteOpen}
|
||||||
title={t('sessions.action_delete')}
|
title={t('sessions.action_delete')}
|
||||||
onClose={() => !deleting && setConfirmDeleteOpen(false)}
|
message={t('common.confirm_delete_session')}
|
||||||
footer={(
|
onClose={() => setConfirmDeleteOpen(false)}
|
||||||
<>
|
onConfirm={handleDelete}
|
||||||
<Button variant="secondary" onClick={() => setConfirmDeleteOpen(false)} disabled={deleting}>
|
isDeleting={deleting}
|
||||||
Cancel
|
/>
|
||||||
</Button>
|
|
||||||
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
|
||||||
{t('sessions.action_delete')}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
Are you sure you want to delete this session?
|
|
||||||
</Modal>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useCallback, useEffect, useState } from 'react';
|
import { useCallback, useEffect, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { Trash2, Monitor } from 'lucide-react';
|
import { Trash2, Monitor } from 'lucide-react';
|
||||||
import { sessions } from '../../api';
|
import { sessions } from '../../api';
|
||||||
import type { Session } from '../../api';
|
import type { Session } from '../../api';
|
||||||
@@ -8,42 +9,61 @@ import {
|
|||||||
Badge,
|
Badge,
|
||||||
Breadcrumbs,
|
Breadcrumbs,
|
||||||
Button,
|
Button,
|
||||||
Modal,
|
|
||||||
Table,
|
Table,
|
||||||
type TableColumn,
|
type TableColumn,
|
||||||
|
type SortDirection,
|
||||||
Timestamp,
|
Timestamp,
|
||||||
UuidBadge,
|
UuidBadge,
|
||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
|
import { DeleteConfirmationModal } from '../../components/modals';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function SessionsPage() {
|
export function SessionsPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
usePageTitle(t('sessions.title'));
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [items, setItems] = useState<Session[]>([]);
|
const [items, setItems] = useState<Session[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
// Loading until the current query's result has arrived (derived, so the
|
||||||
const [error, setError] = useState<string | null>(null);
|
// loading effect doesn't have to set state synchronously)
|
||||||
|
const [loadedQuery, setLoadedQuery] = useState<string | null>(null);
|
||||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
|
const [sortBy, setSortBy] = useState('id');
|
||||||
|
const [sortDir, setSortDir] = useState<SortDirection>('desc');
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [pageSize, setPageSize] = useState(10);
|
||||||
|
const [total, setTotal] = useState(0);
|
||||||
|
|
||||||
const load = useCallback(() => {
|
const query = `${sortBy}|${sortDir}|${page}|${pageSize}`;
|
||||||
|
const loading = loadedQuery !== query;
|
||||||
|
|
||||||
|
const load = useCallback((orderBy: string, orderDir: SortDirection, p: number, limit: number) => {
|
||||||
|
const key = `${orderBy}|${orderDir}|${p}|${limit}`;
|
||||||
sessions
|
sessions
|
||||||
.list()
|
.list(p, limit, orderBy, orderDir === 'asc' ? 'ASC' : 'DESC')
|
||||||
.then((res) => setItems(res.data))
|
.then((res) => {
|
||||||
.catch((err: Error) => setError(err.message))
|
setItems(res.data);
|
||||||
.finally(() => setLoading(false));
|
setTotal(res.total);
|
||||||
|
})
|
||||||
|
.finally(() => setLoadedQuery(key));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
load();
|
load(sortBy, sortDir, page, pageSize);
|
||||||
}, [load]);
|
}, [load, sortBy, sortDir, page, pageSize]);
|
||||||
|
|
||||||
|
const handleSort = (col: string, dir: SortDirection) => {
|
||||||
|
setSortBy(col);
|
||||||
|
setSortDir(dir);
|
||||||
|
setPage(1);
|
||||||
|
};
|
||||||
|
|
||||||
const handleDelete = async () => {
|
const handleDelete = async () => {
|
||||||
if (!deleteId) return;
|
if (!deleteId) return;
|
||||||
setDeleting(true);
|
setDeleting(true);
|
||||||
try {
|
try {
|
||||||
await sessions.remove(deleteId);
|
await sessions.remove(deleteId);
|
||||||
setLoading(true);
|
load(sortBy, sortDir, page, pageSize);
|
||||||
load();
|
|
||||||
setDeleteId(null);
|
setDeleteId(null);
|
||||||
} finally {
|
} finally {
|
||||||
setDeleting(false);
|
setDeleting(false);
|
||||||
@@ -52,17 +72,24 @@ export function SessionsPage() {
|
|||||||
|
|
||||||
const columns: TableColumn<Session>[] = [
|
const columns: TableColumn<Session>[] = [
|
||||||
{ key: 'id', header: t('sessions.col_id'), render: (s) => <UuidBadge id={s.id} />, width: 60 },
|
{ key: 'id', header: t('sessions.col_id'), render: (s) => <UuidBadge id={s.id} />, width: 60 },
|
||||||
{ key: 'name', header: t('sessions.col_name'), render: (s) => s.sessionName },
|
{
|
||||||
|
key: 'sessionName',
|
||||||
|
header: t('sessions.col_name'),
|
||||||
|
sortable: true,
|
||||||
|
render: (s) => s.sessionName,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'status',
|
key: 'status',
|
||||||
header: t('sessions.col_status'),
|
header: t('sessions.col_status'),
|
||||||
width: 100,
|
width: 100,
|
||||||
|
sortable: true,
|
||||||
render: (s) => <Badge variant={s.status === 'open' ? 'success' : 'error'}>{s.status}</Badge>,
|
render: (s) => <Badge variant={s.status === 'open' ? 'success' : 'error'}>{s.status}</Badge>,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'lastUsed',
|
key: 'lastUsedAt',
|
||||||
header: t('sessions.col_lastUsed'),
|
header: t('sessions.col_lastUsed'),
|
||||||
width: 160,
|
width: 160,
|
||||||
|
sortable: true,
|
||||||
render: (s) => (s.lastUsedAt ? <Timestamp value={s.lastUsedAt} /> : '—'),
|
render: (s) => (s.lastUsedAt ? <Timestamp value={s.lastUsedAt} /> : '—'),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -97,28 +124,28 @@ export function SessionsPage() {
|
|||||||
rowKey={(s) => s.id}
|
rowKey={(s) => s.id}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
emptyMessage={t('sessions.empty')}
|
emptyMessage={t('sessions.empty')}
|
||||||
pageSize={10}
|
sortBy={sortBy}
|
||||||
|
sortDir={sortDir}
|
||||||
|
onSort={handleSort}
|
||||||
|
total={total}
|
||||||
|
page={page}
|
||||||
|
onPageChange={setPage}
|
||||||
|
onPageSizeChange={(s) => {
|
||||||
|
setPageSize(s);
|
||||||
|
setPage(1);
|
||||||
|
}}
|
||||||
pageSizeOptions={[10, 25, 50]}
|
pageSizeOptions={[10, 25, 50]}
|
||||||
onRowClick={(s) => navigate(`/sessions/${s.id}`)}
|
onRowClick={(s) => navigate(`/sessions/${s.id}`)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Modal
|
<DeleteConfirmationModal
|
||||||
open={deleteId != null}
|
open={deleteId != null}
|
||||||
title={t('sessions.action_delete')}
|
title={t('sessions.action_delete')}
|
||||||
onClose={() => !deleting && setDeleteId(null)}
|
message={t('common.confirm_delete_session')}
|
||||||
footer={(
|
onClose={() => setDeleteId(null)}
|
||||||
<>
|
onConfirm={handleDelete}
|
||||||
<Button variant="secondary" onClick={() => setDeleteId(null)} disabled={deleting}>
|
isDeleting={deleting}
|
||||||
Cancel
|
/>
|
||||||
</Button>
|
|
||||||
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
|
||||||
{t('sessions.action_delete')}
|
|
||||||
</Button>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
Are you sure you want to delete this session?
|
|
||||||
</Modal>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
import { useState } from 'react';
|
import { useState, SubmitEvent } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { X, Save, Braces } from 'lucide-react';
|
import { X, Save, Braces } from 'lucide-react';
|
||||||
import { snippets } from '../../api';
|
import { snippets } from '../../api';
|
||||||
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
||||||
|
import { CodeHelpButton } from '../../components/modals';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function CreateSnippetPage() {
|
export function CreateSnippetPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
usePageTitle(t('snippets.create_title'));
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const toast = useToast();
|
const toast = useToast();
|
||||||
|
|
||||||
@@ -19,9 +22,8 @@ export function CreateSnippetPage() {
|
|||||||
const [titleError, setTitleError] = useState('');
|
const [titleError, setTitleError] = useState('');
|
||||||
const [codeError, setCodeError] = useState('');
|
const [codeError, setCodeError] = useState('');
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let valid = true;
|
let valid = true;
|
||||||
if (!alias.trim()) {
|
if (!alias.trim()) {
|
||||||
@@ -38,7 +40,6 @@ export function CreateSnippetPage() {
|
|||||||
}
|
}
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
|
||||||
try {
|
try {
|
||||||
const snippet = await snippets.create({
|
const snippet = await snippets.create({
|
||||||
alias: alias.trim(),
|
alias: alias.trim(),
|
||||||
@@ -46,11 +47,10 @@ export function CreateSnippetPage() {
|
|||||||
description: description.trim() || undefined,
|
description: description.trim() || undefined,
|
||||||
code: code.trim(),
|
code: code.trim(),
|
||||||
});
|
});
|
||||||
toast.success('Snippet created');
|
toast.success(t('snippets.created'));
|
||||||
navigate(`/snippets/${snippet.id}`);
|
navigate(`/snippets/${snippet.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message;
|
const message = (err as Error).message;
|
||||||
setError(message);
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
@@ -62,7 +62,11 @@ export function CreateSnippetPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('snippets.title'), icon: <Braces size={14} />, onClick: () => navigate('/snippets') },
|
{
|
||||||
|
label: t('snippets.title'),
|
||||||
|
icon: <Braces size={14} />,
|
||||||
|
onClick: () => navigate('/snippets'),
|
||||||
|
},
|
||||||
{ label: t('snippets.create_title') },
|
{ label: t('snippets.create_title') },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
@@ -104,10 +108,13 @@ export function CreateSnippetPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.formField}>
|
<div className={styles.formField}>
|
||||||
<label className={styles.fieldLabel}>
|
<div className={styles.labelRow}>
|
||||||
{t('snippets.form_code')}
|
<label className={styles.fieldLabel}>
|
||||||
<span className={styles.requiredMark}> *</span>
|
{t('snippets.form_code')}
|
||||||
</label>
|
<span className={styles.requiredMark}> *</span>
|
||||||
|
</label>
|
||||||
|
<CodeHelpButton />
|
||||||
|
</div>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
value={code}
|
value={code}
|
||||||
onChange={(v) => {
|
onChange={(v) => {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState, SubmitEvent } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { X, Save, Braces } from 'lucide-react';
|
import { X, Save, Braces } from 'lucide-react';
|
||||||
import { snippets } from '../../api';
|
import { snippets } from '../../api';
|
||||||
import type { Snippet } from '../../api';
|
import type { Snippet } from '../../api';
|
||||||
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
import { Breadcrumbs, Button, Card, Input, CodeEditor, useToast } from '../../ui';
|
||||||
|
import { CodeHelpButton } from '../../components/modals';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
export function EditSnippetPage() {
|
export function EditSnippetPage() {
|
||||||
@@ -15,6 +17,9 @@ export function EditSnippetPage() {
|
|||||||
|
|
||||||
const [snippet, setSnippet] = useState<Snippet | null>(null);
|
const [snippet, setSnippet] = useState<Snippet | null>(null);
|
||||||
const [alias, setAlias] = useState('');
|
const [alias, setAlias] = useState('');
|
||||||
|
usePageTitle(
|
||||||
|
snippet ? `${t('snippets.edit_title')} — ${snippet.title}` : t('snippets.edit_title'),
|
||||||
|
);
|
||||||
const [title, setTitle] = useState('');
|
const [title, setTitle] = useState('');
|
||||||
const [description, setDescription] = useState('');
|
const [description, setDescription] = useState('');
|
||||||
const [code, setCode] = useState('');
|
const [code, setCode] = useState('');
|
||||||
@@ -23,7 +28,6 @@ export function EditSnippetPage() {
|
|||||||
const [codeError, setCodeError] = useState('');
|
const [codeError, setCodeError] = useState('');
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
@@ -36,11 +40,10 @@ export function EditSnippetPage() {
|
|||||||
setDescription(s.description ?? '');
|
setDescription(s.description ?? '');
|
||||||
setCode(s.code);
|
setCode(s.code);
|
||||||
})
|
})
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: SubmitEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
let valid = true;
|
let valid = true;
|
||||||
if (!alias.trim()) {
|
if (!alias.trim()) {
|
||||||
@@ -57,7 +60,6 @@ export function EditSnippetPage() {
|
|||||||
}
|
}
|
||||||
if (!valid) return;
|
if (!valid) return;
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setError(null);
|
|
||||||
try {
|
try {
|
||||||
await snippets.update(id!, {
|
await snippets.update(id!, {
|
||||||
alias: alias.trim(),
|
alias: alias.trim(),
|
||||||
@@ -65,11 +67,10 @@ export function EditSnippetPage() {
|
|||||||
description: description.trim() || undefined,
|
description: description.trim() || undefined,
|
||||||
code: code.trim(),
|
code: code.trim(),
|
||||||
});
|
});
|
||||||
toast.success('Snippet updated');
|
toast.success(t('snippets.updated'));
|
||||||
navigate(`/snippets/${id}`);
|
navigate(`/snippets/${id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const message = (err as Error).message;
|
const message = (err as Error).message;
|
||||||
setError(message);
|
|
||||||
toast.error(message);
|
toast.error(message);
|
||||||
} finally {
|
} finally {
|
||||||
setSaving(false);
|
setSaving(false);
|
||||||
@@ -81,7 +82,11 @@ export function EditSnippetPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('snippets.title'), icon: <Braces size={14} />, onClick: () => navigate('/snippets') },
|
{
|
||||||
|
label: t('snippets.title'),
|
||||||
|
icon: <Braces size={14} />,
|
||||||
|
onClick: () => navigate('/snippets'),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: snippet?.title ?? `#${id}`,
|
label: snippet?.title ?? `#${id}`,
|
||||||
onClick: () => navigate(`/snippets/${id}`),
|
onClick: () => navigate(`/snippets/${id}`),
|
||||||
@@ -130,10 +135,13 @@ export function EditSnippetPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.formField}>
|
<div className={styles.formField}>
|
||||||
<label className={styles.fieldLabel}>
|
<div className={styles.labelRow}>
|
||||||
{t('snippets.form_code')}
|
<label className={styles.fieldLabel}>
|
||||||
<span className={styles.requiredMark}> *</span>
|
{t('snippets.form_code')}
|
||||||
</label>
|
<span className={styles.requiredMark}> *</span>
|
||||||
|
</label>
|
||||||
|
<CodeHelpButton />
|
||||||
|
</div>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
value={code}
|
value={code}
|
||||||
onChange={(v) => {
|
onChange={(v) => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useNavigate, useParams } from 'react-router-dom';
|
import { useNavigate, useParams } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
import { Upload, Pencil, Trash2, Braces } from 'lucide-react';
|
import { Upload, Pencil, Trash2, Braces } from 'lucide-react';
|
||||||
import { CodeBlock } from '../../ui';
|
import { CodeBlock } from '../../ui';
|
||||||
import { stringify as yamlStringify } from 'yaml';
|
import { stringify as yamlStringify } from 'yaml';
|
||||||
@@ -24,7 +25,7 @@ export function SnippetDetailPage() {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [snippet, setSnippet] = useState<Snippet | null>(null);
|
const [snippet, setSnippet] = useState<Snippet | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
usePageTitle(snippet?.title ?? null);
|
||||||
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false);
|
const [confirmDeleteOpen, setConfirmDeleteOpen] = useState(false);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
|
|
||||||
@@ -33,7 +34,6 @@ export function SnippetDetailPage() {
|
|||||||
snippets
|
snippets
|
||||||
.get(id)
|
.get(id)
|
||||||
.then(setSnippet)
|
.then(setSnippet)
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
@@ -51,12 +51,12 @@ export function SnippetDetailPage() {
|
|||||||
|
|
||||||
const handleExport = async () => {
|
const handleExport = async () => {
|
||||||
if (!snippet) return;
|
if (!snippet) return;
|
||||||
const data = await snippets.exportSnippet(snippet.id);
|
const data = await snippets.exportSnippet(snippet.id, snippet.version);
|
||||||
const blob = new Blob([yamlStringify(data)], { type: 'application/yaml' });
|
const blob = new Blob([yamlStringify(data)], { type: 'application/yaml' });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = url;
|
a.href = url;
|
||||||
a.download = `snippet-${snippet.alias}.yaml`;
|
a.download = `snippet-${snippet.alias}-v${snippet.version}.yaml`;
|
||||||
a.click();
|
a.click();
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
};
|
};
|
||||||
@@ -66,7 +66,11 @@ export function SnippetDetailPage() {
|
|||||||
<div className={styles.pageToolbar}>
|
<div className={styles.pageToolbar}>
|
||||||
<Breadcrumbs
|
<Breadcrumbs
|
||||||
items={[
|
items={[
|
||||||
{ label: t('snippets.title'), icon: <Braces size={14} />, onClick: () => navigate('/snippets') },
|
{
|
||||||
|
label: t('snippets.title'),
|
||||||
|
icon: <Braces size={14} />,
|
||||||
|
onClick: () => navigate('/snippets'),
|
||||||
|
},
|
||||||
{ label: snippet?.title ?? `#${id}` },
|
{ label: snippet?.title ?? `#${id}` },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
@@ -103,6 +107,7 @@ export function SnippetDetailPage() {
|
|||||||
{ term: t('snippets.field_id'), detail: <UuidBadge id={snippet.id} /> },
|
{ term: t('snippets.field_id'), detail: <UuidBadge id={snippet.id} /> },
|
||||||
{ term: t('snippets.field_alias'), detail: snippet.alias },
|
{ term: t('snippets.field_alias'), detail: snippet.alias },
|
||||||
{ term: t('snippets.field_title'), detail: snippet.title },
|
{ term: t('snippets.field_title'), detail: snippet.title },
|
||||||
|
{ term: t('snippets.field_version'), detail: `v${snippet.version}` },
|
||||||
{
|
{
|
||||||
term: t('snippets.field_created'),
|
term: t('snippets.field_created'),
|
||||||
detail: <Timestamp value={snippet.createdAt} />,
|
detail: <Timestamp value={snippet.createdAt} />,
|
||||||
@@ -141,18 +146,22 @@ export function SnippetDetailPage() {
|
|||||||
open={confirmDeleteOpen}
|
open={confirmDeleteOpen}
|
||||||
title={t('snippets.action_delete')}
|
title={t('snippets.action_delete')}
|
||||||
onClose={() => !deleting && setConfirmDeleteOpen(false)}
|
onClose={() => !deleting && setConfirmDeleteOpen(false)}
|
||||||
footer={(
|
footer={
|
||||||
<>
|
<>
|
||||||
<Button variant="secondary" onClick={() => setConfirmDeleteOpen(false)} disabled={deleting}>
|
<Button
|
||||||
Cancel
|
variant="secondary"
|
||||||
|
onClick={() => setConfirmDeleteOpen(false)}
|
||||||
|
disabled={deleting}
|
||||||
|
>
|
||||||
|
{t('common.button_cancel')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
||||||
{t('snippets.action_delete')}
|
{t('snippets.action_delete')}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
}
|
||||||
>
|
>
|
||||||
Are you sure you want to delete this snippet?
|
{t('common.confirm_delete_snippet')}
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useRef, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { usePageTitle } from '../../hooks/usePageTitle';
|
||||||
|
import { useImportFile } from '../../hooks/useImportFile';
|
||||||
import { Settings, Pencil, Trash2, Plus, Download, Braces } from 'lucide-react';
|
import { Settings, Pencil, Trash2, Plus, Download, Braces } from 'lucide-react';
|
||||||
import { parse as yamlParse } from 'yaml';
|
|
||||||
import { snippets } from '../../api';
|
import { snippets } from '../../api';
|
||||||
import type { Snippet } from '../../api';
|
import type { Snippet } from '../../api';
|
||||||
import {
|
import {
|
||||||
@@ -17,7 +18,10 @@ import {
|
|||||||
} from '../../ui';
|
} from '../../ui';
|
||||||
import styles from '../Page.module.css';
|
import styles from '../Page.module.css';
|
||||||
|
|
||||||
function firstParagraphBlocks(markdown: string, limit = 2): { preview: string; truncated: boolean } {
|
function firstParagraphBlocks(
|
||||||
|
markdown: string,
|
||||||
|
limit = 2,
|
||||||
|
): { preview: string; truncated: boolean } {
|
||||||
const blocks = markdown
|
const blocks = markdown
|
||||||
.split(/\n\s*\n/g)
|
.split(/\n\s*\n/g)
|
||||||
.map((block) => block.trim())
|
.map((block) => block.trim())
|
||||||
@@ -80,17 +84,19 @@ function SnippetCard({ snippet, onDelete }: { snippet: Snippet; onDelete: (id: s
|
|||||||
>
|
>
|
||||||
<p className={styles.muted}>
|
<p className={styles.muted}>
|
||||||
{t('snippets.field_alias')}: <code className={styles.codeInline}>{snippet.alias}</code>
|
{t('snippets.field_alias')}: <code className={styles.codeInline}>{snippet.alias}</code>
|
||||||
|
{' · '}v{snippet.version}
|
||||||
</p>
|
</p>
|
||||||
{snippet.description && (() => {
|
{snippet.description &&
|
||||||
const { preview, truncated } = firstParagraphBlocks(snippet.description, 2);
|
(() => {
|
||||||
if (!preview) return null;
|
const { preview, truncated } = firstParagraphBlocks(snippet.description, 2);
|
||||||
return (
|
if (!preview) return null;
|
||||||
<>
|
return (
|
||||||
<MarkdownContent content={preview} />
|
<>
|
||||||
{truncated && <p className={styles.muted}>...</p>}
|
<MarkdownContent content={preview} />
|
||||||
</>
|
{truncated && <p className={styles.muted}>...</p>}
|
||||||
);
|
</>
|
||||||
})()}
|
);
|
||||||
|
})()}
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -110,10 +116,9 @@ function AddSnippetCard() {
|
|||||||
|
|
||||||
export function SnippetsPage() {
|
export function SnippetsPage() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const navigate = useNavigate();
|
usePageTitle(t('snippets.title'));
|
||||||
const [items, setItems] = useState<Snippet[]>([]);
|
const [items, setItems] = useState<Snippet[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [deleteId, setDeleteId] = useState<string | null>(null);
|
const [deleteId, setDeleteId] = useState<string | null>(null);
|
||||||
const [deleting, setDeleting] = useState(false);
|
const [deleting, setDeleting] = useState(false);
|
||||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||||
@@ -122,7 +127,6 @@ export function SnippetsPage() {
|
|||||||
snippets
|
snippets
|
||||||
.list()
|
.list()
|
||||||
.then((res) => setItems(res.data))
|
.then((res) => setItems(res.data))
|
||||||
.catch((err: Error) => setError(err.message))
|
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -146,19 +150,7 @@ export function SnippetsPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleImport = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleImport = useImportFile('snippet');
|
||||||
const file = e.target.files?.[0];
|
|
||||||
if (!file) return;
|
|
||||||
e.target.value = '';
|
|
||||||
try {
|
|
||||||
const text = await file.text();
|
|
||||||
const payload = yamlParse(text) as unknown;
|
|
||||||
const imported = await snippets.importSnippet(payload);
|
|
||||||
navigate(`/snippets/${imported.id}`);
|
|
||||||
} catch (err) {
|
|
||||||
setError(err instanceof Error ? err.message : String(err));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
@@ -195,18 +187,18 @@ export function SnippetsPage() {
|
|||||||
open={deleteId != null}
|
open={deleteId != null}
|
||||||
title={t('snippets.action_delete')}
|
title={t('snippets.action_delete')}
|
||||||
onClose={() => !deleting && setDeleteId(null)}
|
onClose={() => !deleting && setDeleteId(null)}
|
||||||
footer={(
|
footer={
|
||||||
<>
|
<>
|
||||||
<Button variant="secondary" onClick={() => setDeleteId(null)} disabled={deleting}>
|
<Button variant="secondary" onClick={() => setDeleteId(null)} disabled={deleting}>
|
||||||
Cancel
|
{t('common.button_cancel')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
<Button variant="danger" onClick={handleDelete} disabled={deleting}>
|
||||||
{t('snippets.action_delete')}
|
{t('snippets.action_delete')}
|
||||||
</Button>
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
}
|
||||||
>
|
>
|
||||||
Are you sure you want to delete this snippet?
|
{t('common.confirm_delete_snippet')}
|
||||||
</Modal>
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.active .label {
|
.active .label {
|
||||||
color: var(--color-primary);
|
color: var(--color-primary-text);
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,8 +83,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.inactive .label {
|
.inactive .label {
|
||||||
|
/* Not dimmed with opacity: muted text already reads as inactive and keeps 4.5:1 */
|
||||||
color: var(--color-text-muted);
|
color: var(--color-text-muted);
|
||||||
opacity: 0.5;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── Error state ──────────────────────────────────────────── */
|
/* ── Error state ──────────────────────────────────────────── */
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ export type BadgeVariant = 'success' | 'error' | 'warning' | 'info' | 'neutral'
|
|||||||
export interface BadgeProps {
|
export interface BadgeProps {
|
||||||
variant?: BadgeVariant;
|
variant?: BadgeVariant;
|
||||||
dot?: boolean;
|
dot?: boolean;
|
||||||
|
className?: string;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Badge({ variant = 'neutral', dot = false, children }: BadgeProps) {
|
export function Badge({ variant = 'neutral', dot = false, className, children }: BadgeProps) {
|
||||||
return (
|
return (
|
||||||
<span className={[styles.badge, styles[variant]].join(' ')}>
|
<span className={[styles.badge, styles[variant], className].filter(Boolean).join(' ')}>
|
||||||
{dot && <span className={styles.dot} aria-hidden="true" />}
|
{dot && <span className={styles.dot} aria-hidden="true" />}
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -36,15 +36,18 @@ export function Breadcrumbs({ items, separator, className }: BreadcrumbsProps) {
|
|||||||
<li key={i} className={styles.item}>
|
<li key={i} className={styles.item}>
|
||||||
{isLast ? (
|
{isLast ? (
|
||||||
<span className={styles.current} aria-current="page">
|
<span className={styles.current} aria-current="page">
|
||||||
{item.icon}{item.label}
|
{item.icon}
|
||||||
|
{item.label}
|
||||||
</span>
|
</span>
|
||||||
) : item.href ? (
|
) : item.href ? (
|
||||||
<a href={item.href} className={styles.link} onClick={item.onClick}>
|
<a href={item.href} className={styles.link} onClick={item.onClick}>
|
||||||
{item.icon}{item.label}
|
{item.icon}
|
||||||
|
{item.label}
|
||||||
</a>
|
</a>
|
||||||
) : (
|
) : (
|
||||||
<button type="button" className={styles.link} onClick={item.onClick}>
|
<button type="button" className={styles.link} onClick={item.onClick}>
|
||||||
{item.icon}{item.label}
|
{item.icon}
|
||||||
|
{item.label}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{!isLast && <span className={styles.separator}>{sep}</span>}
|
{!isLast && <span className={styles.separator}>{sep}</span>}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
.code :global(.hljs-comment),
|
.code :global(.hljs-comment),
|
||||||
.code :global(.hljs-quote) {
|
.code :global(.hljs-quote) {
|
||||||
color: var(--hl-comment, #6A8072);
|
color: var(--hl-comment);
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
.code :global(.hljs-built_in),
|
.code :global(.hljs-built_in),
|
||||||
.code :global(.hljs-name),
|
.code :global(.hljs-name),
|
||||||
.code :global(.hljs-tag) {
|
.code :global(.hljs-tag) {
|
||||||
color: var(--hl-keyword, #A67DCC);
|
color: var(--hl-keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
.code :global(.hljs-string),
|
.code :global(.hljs-string),
|
||||||
@@ -39,32 +39,32 @@
|
|||||||
.code :global(.hljs-template-variable),
|
.code :global(.hljs-template-variable),
|
||||||
.code :global(.hljs-type),
|
.code :global(.hljs-type),
|
||||||
.code :global(.hljs-addition) {
|
.code :global(.hljs-addition) {
|
||||||
color: var(--hl-string, #9BB870);
|
color: var(--hl-string);
|
||||||
}
|
}
|
||||||
|
|
||||||
.code :global(.hljs-number),
|
.code :global(.hljs-number),
|
||||||
.code :global(.hljs-regexp),
|
.code :global(.hljs-regexp),
|
||||||
.code :global(.hljs-link) {
|
.code :global(.hljs-link) {
|
||||||
color: var(--hl-number, #E8A85F);
|
color: var(--hl-number);
|
||||||
}
|
}
|
||||||
|
|
||||||
.code :global(.hljs-function),
|
.code :global(.hljs-function),
|
||||||
.code :global(.hljs-title.hljs-function_) {
|
.code :global(.hljs-title.hljs-function_) {
|
||||||
color: var(--hl-function, #5BB8D4);
|
color: var(--hl-function);
|
||||||
}
|
}
|
||||||
|
|
||||||
.code :global(.hljs-variable),
|
.code :global(.hljs-variable),
|
||||||
.code :global(.hljs-params) {
|
.code :global(.hljs-params) {
|
||||||
color: var(--hl-variable, #D4A0A0);
|
color: var(--hl-variable);
|
||||||
}
|
}
|
||||||
|
|
||||||
.code :global(.hljs-property) {
|
.code :global(.hljs-property) {
|
||||||
color: var(--hl-property, #79C0C8);
|
color: var(--hl-property);
|
||||||
}
|
}
|
||||||
|
|
||||||
.code :global(.hljs-deletion),
|
.code :global(.hljs-deletion),
|
||||||
.code :global(.hljs-meta) {
|
.code :global(.hljs-meta) {
|
||||||
color: var(--hl-meta, #A9A3C9);
|
color: var(--hl-meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
.code :global(.hljs-emphasis) {
|
.code :global(.hljs-emphasis) {
|
||||||
|
|||||||
@@ -0,0 +1,147 @@
|
|||||||
|
.root {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
background: var(--color-bg-subtle);
|
||||||
|
border: var(--border-width) solid var(--color-border);
|
||||||
|
border-radius: var(--radius-md);
|
||||||
|
overflow: auto;
|
||||||
|
font-family: var(--font-mono, ui-monospace, 'Cascadia Code', 'Fira Code', monospace);
|
||||||
|
font-size: var(--font-size-xs);
|
||||||
|
/* Where the context/message column starts: timestamp + level + their gaps */
|
||||||
|
--log-body-offset: calc(7em + 4.5em + 2 * var(--space-2));
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty {
|
||||||
|
padding: var(--space-4);
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
font-size: var(--font-size-sm);
|
||||||
|
}
|
||||||
|
|
||||||
|
.line {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: var(--space-1);
|
||||||
|
padding: var(--space-1) var(--space-3);
|
||||||
|
border-left: 3px solid transparent;
|
||||||
|
border-bottom: 1px solid var(--color-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.line:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lineHeader {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.data {
|
||||||
|
margin: 0 0 var(--space-1) var(--log-body-offset);
|
||||||
|
border: var(--border-width) solid var(--color-border);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
background: var(--color-bg);
|
||||||
|
max-width: 100%;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.data > * {
|
||||||
|
margin: 0;
|
||||||
|
padding: var(--space-2) var(--space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.timestamp {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
min-width: 7em;
|
||||||
|
text-align: right;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.level {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
width: 4.5em;
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.context {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
color: var(--color-secondary-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.context::before {
|
||||||
|
content: '[';
|
||||||
|
}
|
||||||
|
|
||||||
|
.context::after {
|
||||||
|
content: ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
.message {
|
||||||
|
flex: 1 1 320px;
|
||||||
|
color: var(--color-text);
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.debug {
|
||||||
|
border-left-color: var(--color-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.debug .level,
|
||||||
|
.debug .message,
|
||||||
|
.debug .timestamp,
|
||||||
|
.debug .context {
|
||||||
|
color: var(--color-text-faint);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log {
|
||||||
|
border-left-color: var(--color-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log .level {
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.warn {
|
||||||
|
border-left-color: var(--color-warning-fg);
|
||||||
|
background: var(--color-warning-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.warn .level {
|
||||||
|
color: var(--color-warning-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
border-left-color: var(--color-error-fg);
|
||||||
|
background: var(--color-error-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.error .level {
|
||||||
|
color: var(--color-error-fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataToggle {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-1);
|
||||||
|
align-self: flex-start;
|
||||||
|
margin-left: var(--log-body-offset);
|
||||||
|
padding: 0;
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
font: inherit;
|
||||||
|
color: var(--color-text);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataToggle svg {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
color: var(--color-primary-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.dataToggle:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
@@ -0,0 +1,147 @@
|
|||||||
|
import { useMemo, useState } from 'react';
|
||||||
|
import { ChevronDown, ChevronRight } from 'lucide-react';
|
||||||
|
import { CodeBlock } from '../CodeBlock/CodeBlock';
|
||||||
|
import {
|
||||||
|
DEFAULT_LOG_DATA_LIMITS,
|
||||||
|
exceedsLimits,
|
||||||
|
formatElapsed,
|
||||||
|
measureData,
|
||||||
|
prettyData,
|
||||||
|
type LogDataLimits,
|
||||||
|
} from './logText';
|
||||||
|
import styles from './LogOutput.module.css';
|
||||||
|
|
||||||
|
export type LogOutputLevel = 'debug' | 'log' | 'warn' | 'error';
|
||||||
|
|
||||||
|
export interface LogOutputEntry {
|
||||||
|
id: string | number;
|
||||||
|
level: LogOutputLevel;
|
||||||
|
/** Where the message was generated, e.g. "step:2", "snippet:login", "assertion:pass". */
|
||||||
|
context?: string | null;
|
||||||
|
message: string;
|
||||||
|
/** JSON payload attached to the message, as a raw string; rendered pretty-printed, separately from the message. */
|
||||||
|
data?: string | null;
|
||||||
|
createdAt: string | number | Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LogOutputProps {
|
||||||
|
entries: LogOutputEntry[];
|
||||||
|
/** Reference point for the elapsed-time column; defaults to the first entry's timestamp. */
|
||||||
|
startTime?: string | number | Date;
|
||||||
|
/** Caps the block's height (e.g. "400px"), scrolling once entries overflow it. */
|
||||||
|
maxHeight?: string | number;
|
||||||
|
emptyMessage?: string;
|
||||||
|
className?: string;
|
||||||
|
/** Data blocks whose pretty-printed JSON exceeds either limit start collapsed behind a toggle. */
|
||||||
|
dataLimits?: LogDataLimits;
|
||||||
|
/**
|
||||||
|
* Expands (true) or collapses (false) every large data block. Changing it
|
||||||
|
* discards the per-entry toggles made since the last change.
|
||||||
|
*/
|
||||||
|
dataExpanded?: boolean;
|
||||||
|
/** Label of a collapsed data block's toggle, e.g. "Show data (1.2 KB, 40 lines)". */
|
||||||
|
showDataLabel?: (size: { bytes: number; lines: number }) => string;
|
||||||
|
hideDataLabel?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatBytes(bytes: number): string {
|
||||||
|
return bytes < 1024 ? `${bytes} B` : `${(bytes / 1024).toFixed(1)} KB`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultShowDataLabel = ({ bytes, lines }: { bytes: number; lines: number }) =>
|
||||||
|
`Show data (${formatBytes(bytes)}, ${lines} ${lines === 1 ? 'line' : 'lines'})`;
|
||||||
|
|
||||||
|
/** Terminal-style log viewer: one line per entry, color-coded by level. */
|
||||||
|
export function LogOutput({
|
||||||
|
entries,
|
||||||
|
startTime,
|
||||||
|
maxHeight,
|
||||||
|
emptyMessage = 'No logs.',
|
||||||
|
className,
|
||||||
|
dataLimits = DEFAULT_LOG_DATA_LIMITS,
|
||||||
|
dataExpanded = false,
|
||||||
|
showDataLabel = defaultShowDataLabel,
|
||||||
|
hideDataLabel = 'Hide data',
|
||||||
|
}: LogOutputProps) {
|
||||||
|
// Per-entry toggles, reset whenever dataExpanded changes
|
||||||
|
const [toggled, setToggled] = useState<Set<LogOutputEntry['id']>>(() => new Set());
|
||||||
|
const [prevDataExpanded, setPrevDataExpanded] = useState(dataExpanded);
|
||||||
|
if (prevDataExpanded !== dataExpanded) {
|
||||||
|
setPrevDataExpanded(dataExpanded);
|
||||||
|
setToggled(new Set());
|
||||||
|
}
|
||||||
|
|
||||||
|
const dataBlocks = useMemo(() => {
|
||||||
|
const blocks = new Map<
|
||||||
|
LogOutputEntry['id'],
|
||||||
|
{ pretty: string; bytes: number; lines: number }
|
||||||
|
>();
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (!entry.data) continue;
|
||||||
|
const pretty = prettyData(entry.data);
|
||||||
|
blocks.set(entry.id, { pretty, ...measureData(pretty) });
|
||||||
|
}
|
||||||
|
return blocks;
|
||||||
|
}, [entries]);
|
||||||
|
|
||||||
|
const toggle = (id: LogOutputEntry['id']) =>
|
||||||
|
setToggled((prev) => {
|
||||||
|
const next = new Set(prev);
|
||||||
|
if (!next.delete(id)) next.add(id);
|
||||||
|
return next;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (entries.length === 0) {
|
||||||
|
return <div className={styles.empty}>{emptyMessage}</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startMs = new Date(startTime ?? entries[0].createdAt).getTime();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={[styles.root, className].filter(Boolean).join(' ')}
|
||||||
|
style={maxHeight !== undefined ? { maxHeight } : undefined}
|
||||||
|
role="log"
|
||||||
|
tabIndex={0}
|
||||||
|
>
|
||||||
|
{entries.map((entry) => {
|
||||||
|
const entryMs = new Date(entry.createdAt).getTime();
|
||||||
|
const block = dataBlocks.get(entry.id);
|
||||||
|
const large = block != null && exceedsLimits(block, dataLimits);
|
||||||
|
const open = !large || dataExpanded !== toggled.has(entry.id);
|
||||||
|
return (
|
||||||
|
<div key={entry.id} className={[styles.line, styles[entry.level]].join(' ')}>
|
||||||
|
<div className={styles.lineHeader}>
|
||||||
|
<span className={styles.timestamp} title={new Date(entryMs).toISOString()}>
|
||||||
|
{formatElapsed(entryMs - startMs)}
|
||||||
|
</span>
|
||||||
|
<span className={styles.level}>{entry.level}</span>
|
||||||
|
{entry.context && <span className={styles.context}>{entry.context}</span>}
|
||||||
|
<span className={styles.message}>{entry.message}</span>
|
||||||
|
</div>
|
||||||
|
{block && large && (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className={styles.dataToggle}
|
||||||
|
aria-expanded={open}
|
||||||
|
onClick={() => toggle(entry.id)}
|
||||||
|
>
|
||||||
|
{open ? (
|
||||||
|
<ChevronDown size={14} strokeWidth={3} aria-hidden="true" />
|
||||||
|
) : (
|
||||||
|
<ChevronRight size={14} strokeWidth={3} aria-hidden="true" />
|
||||||
|
)}
|
||||||
|
{open ? hideDataLabel : showDataLabel(block)}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
{block && open && (
|
||||||
|
<div className={styles.data}>
|
||||||
|
<CodeBlock code={block.pretty} language="json" />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import type { LogOutputEntry } from './LogOutput';
|
||||||
|
|
||||||
|
/** Data blocks above either limit start collapsed. */
|
||||||
|
export interface LogDataLimits {
|
||||||
|
/** UTF-8 byte size of the pretty-printed data. */
|
||||||
|
bytes: number;
|
||||||
|
/** Line count of the pretty-printed data. */
|
||||||
|
lines: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const DEFAULT_LOG_DATA_LIMITS: LogDataLimits = { bytes: 256, lines: 5 };
|
||||||
|
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "+12s" (or "-" if before startTime, e.g. clock skew). Log timestamps are
|
||||||
|
* stored with second resolution, so fractions would be noise.
|
||||||
|
*/
|
||||||
|
export function formatElapsed(deltaMs: number): string {
|
||||||
|
const sign = deltaMs < 0 ? '-' : '+';
|
||||||
|
return `${sign}${Math.round(Math.abs(deltaMs) / 1000)}s`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Pretty-prints `data` if it's valid JSON, otherwise returns it as-is. */
|
||||||
|
export function prettyData(data: string): string {
|
||||||
|
try {
|
||||||
|
return JSON.stringify(JSON.parse(data), null, 2);
|
||||||
|
} catch {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Byte size and line count of an already pretty-printed data block. */
|
||||||
|
export function measureData(pretty: string): { bytes: number; lines: number } {
|
||||||
|
return { bytes: encoder.encode(pretty).length, lines: pretty.split('\n').length };
|
||||||
|
}
|
||||||
|
|
||||||
|
export function exceedsLimits(size: { bytes: number; lines: number }, limits: LogDataLimits) {
|
||||||
|
return size.bytes > limits.bytes || size.lines > limits.lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** True if any entry's data block exceeds the limits (i.e. renders collapsed by default). */
|
||||||
|
export function hasLargeData(
|
||||||
|
entries: Pick<LogOutputEntry, 'data'>[],
|
||||||
|
limits: LogDataLimits = DEFAULT_LOG_DATA_LIMITS,
|
||||||
|
): boolean {
|
||||||
|
return entries.some((e) => e.data && exceedsLimits(measureData(prettyData(e.data)), limits));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Plain-text rendering of the log, one entry per line with every data block
|
||||||
|
* pretty-printed and indented below its line (e.g. for copying to the clipboard).
|
||||||
|
*/
|
||||||
|
export function formatLogText(
|
||||||
|
entries: LogOutputEntry[],
|
||||||
|
startTime?: string | number | Date,
|
||||||
|
): string {
|
||||||
|
if (entries.length === 0) return '';
|
||||||
|
const startMs = new Date(startTime ?? entries[0].createdAt).getTime();
|
||||||
|
return entries
|
||||||
|
.map((entry) => {
|
||||||
|
const elapsed = formatElapsed(new Date(entry.createdAt).getTime() - startMs);
|
||||||
|
const context = entry.context ? ` [${entry.context}]` : '';
|
||||||
|
const header = `${elapsed.padStart(6)} ${entry.level.toUpperCase().padEnd(5)}${context} ${entry.message}`;
|
||||||
|
if (!entry.data) return header;
|
||||||
|
const data = prettyData(entry.data)
|
||||||
|
.split('\n')
|
||||||
|
.map((line) => ` ${line}`)
|
||||||
|
.join('\n');
|
||||||
|
return `${header}\n${data}`;
|
||||||
|
})
|
||||||
|
.join('\n');
|
||||||
|
}
|
||||||
@@ -16,6 +16,13 @@
|
|||||||
border-radius: var(--radius-lg);
|
border-radius: var(--radius-lg);
|
||||||
box-shadow: 0 20px 48px color-mix(in srgb, #000 28%, transparent);
|
box-shadow: 0 20px 48px color-mix(in srgb, #000 28%, transparent);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
max-height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lg {
|
||||||
|
width: min(880px, 100%);
|
||||||
}
|
}
|
||||||
|
|
||||||
.header {
|
.header {
|
||||||
@@ -31,6 +38,7 @@
|
|||||||
.body {
|
.body {
|
||||||
padding: var(--space-2) var(--space-5) var(--space-4);
|
padding: var(--space-2) var(--space-5) var(--space-4);
|
||||||
color: var(--color-text-muted);
|
color: var(--color-text-muted);
|
||||||
|
overflow-y: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ export interface ModalProps {
|
|||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
footer?: React.ReactNode;
|
footer?: React.ReactNode;
|
||||||
|
/** `lg` widens the dialog for long, document-like content. */
|
||||||
|
size?: 'md' | 'lg';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Modal({ open, title, children, onClose, footer }: ModalProps) {
|
export function Modal({ open, title, children, onClose, footer, size = 'md' }: ModalProps) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return;
|
if (!open) return;
|
||||||
const onKeyDown = (event: KeyboardEvent) => {
|
const onKeyDown = (event: KeyboardEvent) => {
|
||||||
@@ -24,7 +26,7 @@ export function Modal({ open, title, children, onClose, footer }: ModalProps) {
|
|||||||
return (
|
return (
|
||||||
<div className={styles.overlay} role="presentation" onClick={onClose}>
|
<div className={styles.overlay} role="presentation" onClick={onClose}>
|
||||||
<div
|
<div
|
||||||
className={styles.dialog}
|
className={size === 'lg' ? `${styles.dialog} ${styles.lg}` : styles.dialog}
|
||||||
role="dialog"
|
role="dialog"
|
||||||
aria-modal="true"
|
aria-modal="true"
|
||||||
aria-label={title}
|
aria-label={title}
|
||||||
@@ -33,7 +35,10 @@ export function Modal({ open, title, children, onClose, footer }: ModalProps) {
|
|||||||
<div className={styles.header}>
|
<div className={styles.header}>
|
||||||
<h3 className={styles.title}>{title}</h3>
|
<h3 className={styles.title}>{title}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.body}>{children}</div>
|
{/* Long (lg) content scrolls; make it focusable so the keyboard can scroll it. */}
|
||||||
|
<div className={styles.body} tabIndex={size === 'lg' ? 0 : undefined}>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
{footer && <div className={styles.footer}>{footer}</div>}
|
{footer && <div className={styles.footer}>{footer}</div>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
.wrapper {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: var(--space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.placeholder {
|
||||||
|
margin: 0;
|
||||||
|
color: var(--color-text-muted);
|
||||||
|
font-size: var(--font-size-sm);
|
||||||
|
line-height: 1.6;
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import { useState } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { Eye, EyeOff } from 'lucide-react';
|
||||||
|
import { Button } from '../Button/Button';
|
||||||
|
import { CodeBlock } from '../CodeBlock/CodeBlock';
|
||||||
|
import styles from './RevealableCodeBlock.module.css';
|
||||||
|
|
||||||
|
export interface RevealableCodeBlockProps {
|
||||||
|
code: string;
|
||||||
|
language?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A CodeBlock that starts hidden; the code is only rendered after the user reveals it. */
|
||||||
|
export function RevealableCodeBlock({ code, language }: RevealableCodeBlockProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const [revealed, setRevealed] = useState(false);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.wrapper}>
|
||||||
|
<div className={styles.content}>
|
||||||
|
{revealed ? (
|
||||||
|
<CodeBlock code={code} language={language} />
|
||||||
|
) : (
|
||||||
|
<p className={styles.placeholder}>{t('revealable.hidden')}</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
aria-expanded={revealed}
|
||||||
|
onClick={() => setRevealed((r) => !r)}
|
||||||
|
>
|
||||||
|
{revealed ? <EyeOff size={14} /> : <Eye size={14} />}
|
||||||
|
{revealed ? t('revealable.hide') : t('revealable.reveal')}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -27,11 +27,40 @@
|
|||||||
background: var(--color-secondary-fg);
|
background: var(--color-secondary-fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.thContent {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: var(--space-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.thSortable {
|
||||||
|
cursor: pointer;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.thSortable:hover {
|
||||||
|
background: color-mix(in srgb, var(--color-secondary-fg) 80%, var(--color-secondary-border) 20%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.sortIcon {
|
||||||
|
opacity: 0.4;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sortIconActive {
|
||||||
|
opacity: 1;
|
||||||
|
color: var(--color-primary-text);
|
||||||
|
}
|
||||||
|
|
||||||
[data-theme="dark"] .th {
|
[data-theme="dark"] .th {
|
||||||
background: var(--color-secondary);
|
background: var(--color-secondary);
|
||||||
color: var(--color-secondary-fg);
|
color: var(--color-secondary-fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[data-theme="dark"] .thSortable:hover {
|
||||||
|
background: color-mix(in srgb, var(--color-secondary) 80%, var(--color-secondary-border) 20%);
|
||||||
|
}
|
||||||
|
|
||||||
/* Rounded top corners on first/last header cells */
|
/* Rounded top corners on first/last header cells */
|
||||||
.th:first-child { border-radius: var(--radius-lg) 0 0 0; }
|
.th:first-child { border-radius: var(--radius-lg) 0 0 0; }
|
||||||
.th:last-child { border-radius: 0 var(--radius-lg) 0 0; }
|
.th:last-child { border-radius: 0 var(--radius-lg) 0 0; }
|
||||||
|
|||||||
+109
-24
@@ -1,13 +1,18 @@
|
|||||||
import { useState, type HTMLAttributes, type MouseEvent, type ReactNode } from 'react';
|
import { useState, type HTMLAttributes, type MouseEvent, type ReactNode } from 'react';
|
||||||
|
import { ArrowUp, ArrowDown, ArrowUpDown } from 'lucide-react';
|
||||||
import { Pagination } from '../Pagination/Pagination';
|
import { Pagination } from '../Pagination/Pagination';
|
||||||
import styles from './Table.module.css';
|
import styles from './Table.module.css';
|
||||||
|
|
||||||
|
export type SortDirection = 'asc' | 'desc';
|
||||||
|
|
||||||
export interface TableColumn<T> {
|
export interface TableColumn<T> {
|
||||||
key: string;
|
key: string;
|
||||||
header: ReactNode;
|
header: ReactNode;
|
||||||
render: (row: T) => ReactNode;
|
render: (row: T) => ReactNode;
|
||||||
width?: string | number;
|
width?: string | number;
|
||||||
align?: 'left' | 'center' | 'right';
|
align?: 'left' | 'center' | 'right';
|
||||||
|
/** If true, a sort icon is shown and clicking the header triggers onSort */
|
||||||
|
sortable?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableProps<T> {
|
export interface TableProps<T> {
|
||||||
@@ -17,7 +22,10 @@ export interface TableProps<T> {
|
|||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
emptyMessage?: string;
|
emptyMessage?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
/** Enable built-in client-side pagination with this default page size */
|
/**
|
||||||
|
* Client-side pagination: pass a default page size to enable.
|
||||||
|
* For server-side pagination use `total` + `page` + `onPageChange` instead.
|
||||||
|
*/
|
||||||
pageSize?: number;
|
pageSize?: number;
|
||||||
/** Offer a page-size selector when pagination is enabled */
|
/** Offer a page-size selector when pagination is enabled */
|
||||||
pageSizeOptions?: number[];
|
pageSizeOptions?: number[];
|
||||||
@@ -25,6 +33,21 @@ export interface TableProps<T> {
|
|||||||
onRowClick?: (row: T) => void;
|
onRowClick?: (row: T) => void;
|
||||||
/** Optional per-row props, useful for drag-and-drop and row-level attributes */
|
/** Optional per-row props, useful for drag-and-drop and row-level attributes */
|
||||||
getRowProps?: (row: T) => HTMLAttributes<HTMLTableRowElement>;
|
getRowProps?: (row: T) => HTMLAttributes<HTMLTableRowElement>;
|
||||||
|
/** Currently sorted column key (controlled) */
|
||||||
|
sortBy?: string;
|
||||||
|
/** Current sort direction (controlled) */
|
||||||
|
sortDir?: SortDirection;
|
||||||
|
/** Called when the user clicks a sortable column header */
|
||||||
|
onSort?: (key: string, dir: SortDirection) => void;
|
||||||
|
// ── Server-side pagination (controlled) ──────────────────────────────────
|
||||||
|
/** Total record count from server. Presence switches to server-side pagination mode. */
|
||||||
|
total?: number;
|
||||||
|
/** Controlled current page (1-based). Required when `total` is set. */
|
||||||
|
page?: number;
|
||||||
|
/** Called when the user navigates to a new page. Required when `total` is set. */
|
||||||
|
onPageChange?: (page: number) => void;
|
||||||
|
/** Called when the user changes page size. Optional for server-side pagination. */
|
||||||
|
onPageSizeChange?: (size: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Table<T>({
|
export function Table<T>({
|
||||||
@@ -38,34 +61,74 @@ export function Table<T>({
|
|||||||
pageSizeOptions,
|
pageSizeOptions,
|
||||||
onRowClick,
|
onRowClick,
|
||||||
getRowProps,
|
getRowProps,
|
||||||
|
sortBy,
|
||||||
|
sortDir,
|
||||||
|
onSort,
|
||||||
|
total,
|
||||||
|
page: controlledPage,
|
||||||
|
onPageChange,
|
||||||
|
onPageSizeChange,
|
||||||
}: TableProps<T>) {
|
}: TableProps<T>) {
|
||||||
const [page, setPage] = useState(1);
|
const [internalPage, setInternalPage] = useState(1);
|
||||||
const [pageSize, setPageSize] = useState(defaultPageSize ?? 0);
|
const [pageSize, setPageSize] = useState(defaultPageSize ?? 10);
|
||||||
|
|
||||||
const paginated = defaultPageSize !== undefined && !loading;
|
const serverMode = total !== undefined;
|
||||||
const visibleData = paginated ? data.slice((page - 1) * pageSize, page * pageSize) : data;
|
|
||||||
|
|
||||||
// Reset to page 1 when data changes and current page would be empty
|
const handleSortClick = (key: string) => {
|
||||||
const lastPage = pageSize > 0 ? Math.ceil(data.length / pageSize) : 1;
|
if (!onSort) return;
|
||||||
const safePage = Math.min(page, Math.max(1, lastPage));
|
const nextDir: SortDirection = sortBy === key && sortDir === 'asc' ? 'desc' : 'asc';
|
||||||
|
onSort(key, nextDir);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Client-side pagination
|
||||||
|
const clientPaginated = !serverMode && defaultPageSize !== undefined && !loading;
|
||||||
|
const visibleData = clientPaginated
|
||||||
|
? data.slice((internalPage - 1) * pageSize, internalPage * pageSize)
|
||||||
|
: data;
|
||||||
|
|
||||||
|
const lastClientPage = pageSize > 0 ? Math.ceil(data.length / pageSize) : 1;
|
||||||
|
const safeInternalPage = Math.min(internalPage, Math.max(1, lastClientPage));
|
||||||
|
|
||||||
|
// Server-side pagination display values
|
||||||
|
const serverPage = controlledPage ?? 1;
|
||||||
|
const serverTotal = total ?? 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`${styles.wrapper} ${className ?? ''}`}>
|
<div className={`${styles.wrapper} ${className ?? ''}`}>
|
||||||
<table className={styles.table}>
|
<table className={styles.table}>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
{columns.map((col) => (
|
{columns.map((col) => {
|
||||||
<th
|
const isSorted = col.sortable && sortBy === col.key;
|
||||||
key={col.key}
|
const SortIcon = isSorted ? (sortDir === 'asc' ? ArrowUp : ArrowDown) : ArrowUpDown;
|
||||||
className={styles.th}
|
|
||||||
style={{
|
return (
|
||||||
width: col.width,
|
<th
|
||||||
textAlign: col.align ?? 'left',
|
key={col.key}
|
||||||
}}
|
className={[styles.th, col.sortable ? styles.thSortable : '']
|
||||||
>
|
.filter(Boolean)
|
||||||
{col.header}
|
.join(' ')}
|
||||||
</th>
|
style={{
|
||||||
))}
|
width: col.width,
|
||||||
|
textAlign: col.align ?? 'left',
|
||||||
|
}}
|
||||||
|
onClick={col.sortable ? () => handleSortClick(col.key) : undefined}
|
||||||
|
>
|
||||||
|
<span className={styles.thContent}>
|
||||||
|
{col.header}
|
||||||
|
{col.sortable && (
|
||||||
|
<SortIcon
|
||||||
|
size={12}
|
||||||
|
className={[styles.sortIcon, isSorted ? styles.sortIconActive : '']
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(' ')}
|
||||||
|
aria-hidden="true"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</th>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -122,17 +185,39 @@ export function Table<T>({
|
|||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{paginated && data.length > 0 && (
|
{serverMode && serverTotal > 0 && onPageChange && (
|
||||||
<Pagination
|
<Pagination
|
||||||
page={safePage}
|
page={serverPage}
|
||||||
|
pageSize={pageSize}
|
||||||
|
total={serverTotal}
|
||||||
|
onPageChange={onPageChange}
|
||||||
|
onPageSizeChange={
|
||||||
|
onPageSizeChange
|
||||||
|
? (size) => {
|
||||||
|
setPageSize(size);
|
||||||
|
onPageSizeChange(size);
|
||||||
|
}
|
||||||
|
: pageSizeOptions
|
||||||
|
? (size) => {
|
||||||
|
setPageSize(size);
|
||||||
|
onPageChange(1);
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
pageSizeOptions={pageSizeOptions}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{clientPaginated && data.length > 0 && (
|
||||||
|
<Pagination
|
||||||
|
page={safeInternalPage}
|
||||||
pageSize={pageSize}
|
pageSize={pageSize}
|
||||||
total={data.length}
|
total={data.length}
|
||||||
onPageChange={setPage}
|
onPageChange={setInternalPage}
|
||||||
onPageSizeChange={
|
onPageSizeChange={
|
||||||
pageSizeOptions
|
pageSizeOptions
|
||||||
? (size) => {
|
? (size) => {
|
||||||
setPageSize(size);
|
setPageSize(size);
|
||||||
setPage(1);
|
setInternalPage(1);
|
||||||
}
|
}
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||||
import { AlertCircle, CheckCircle2, Info, X } from 'lucide-react';
|
import { AlertCircle, CheckCircle2, Info, X } from 'lucide-react';
|
||||||
import styles from './ToastProvider.module.css';
|
import styles from './ToastProvider.module.css';
|
||||||
import { subscribeApiErrorToasts } from '../../lib/toast-events';
|
import { subscribeApiErrorToasts } from '../../lib/toast-events';
|
||||||
|
import { ToastContext, type ToastApi, type ToastVariant } from './toast-context';
|
||||||
type ToastVariant = 'success' | 'error' | 'info';
|
|
||||||
|
|
||||||
interface ToastItem {
|
interface ToastItem {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -12,15 +11,6 @@ interface ToastItem {
|
|||||||
closing: boolean;
|
closing: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ToastApi {
|
|
||||||
show: (message: string, variant?: ToastVariant) => void;
|
|
||||||
success: (message: string) => void;
|
|
||||||
error: (message: string) => void;
|
|
||||||
info: (message: string) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ToastContext = createContext<ToastApi | null>(null);
|
|
||||||
|
|
||||||
const ICONS: Record<ToastVariant, React.ReactNode> = {
|
const ICONS: Record<ToastVariant, React.ReactNode> = {
|
||||||
success: <CheckCircle2 size={16} />,
|
success: <CheckCircle2 size={16} />,
|
||||||
error: <AlertCircle size={16} />,
|
error: <AlertCircle size={16} />,
|
||||||
@@ -41,33 +31,38 @@ export function ToastProvider({ children, durationMs = 3500 }: ToastProviderProp
|
|||||||
setItems((prev) => prev.filter((item) => item.id !== id));
|
setItems((prev) => prev.filter((item) => item.id !== id));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const dismiss = useCallback((id: number) => {
|
const dismiss = useCallback(
|
||||||
setItems((prev) =>
|
(id: number) => {
|
||||||
prev.map((item) =>
|
setItems((prev) => prev.map((item) => (item.id === id ? { ...item, closing: true } : item)));
|
||||||
item.id === id ? { ...item, closing: true } : item,
|
window.setTimeout(() => remove(id), EXIT_ANIMATION_MS);
|
||||||
),
|
},
|
||||||
);
|
[remove],
|
||||||
window.setTimeout(() => remove(id), EXIT_ANIMATION_MS);
|
);
|
||||||
}, [remove]);
|
|
||||||
|
|
||||||
const show = useCallback((message: string, variant: ToastVariant = 'info') => {
|
const show = useCallback(
|
||||||
const now = Date.now();
|
(message: string, variant: ToastVariant = 'info') => {
|
||||||
const dedupeKey = `${variant}:${message}`;
|
const now = Date.now();
|
||||||
const previousTs = lastShownAtRef.current.get(dedupeKey) ?? 0;
|
const dedupeKey = `${variant}:${message}`;
|
||||||
if (now - previousTs < 600) return;
|
const previousTs = lastShownAtRef.current.get(dedupeKey) ?? 0;
|
||||||
lastShownAtRef.current.set(dedupeKey, now);
|
if (now - previousTs < 600) return;
|
||||||
|
lastShownAtRef.current.set(dedupeKey, now);
|
||||||
|
|
||||||
const id = Date.now() + Math.floor(Math.random() * 1000);
|
const id = Date.now() + Math.floor(Math.random() * 1000);
|
||||||
setItems((prev) => [...prev, { id, message, variant, closing: false }]);
|
setItems((prev) => [...prev, { id, message, variant, closing: false }]);
|
||||||
window.setTimeout(() => dismiss(id), durationMs);
|
window.setTimeout(() => dismiss(id), durationMs);
|
||||||
}, [dismiss, durationMs]);
|
},
|
||||||
|
[dismiss, durationMs],
|
||||||
|
);
|
||||||
|
|
||||||
const api = useMemo<ToastApi>(() => ({
|
const api = useMemo<ToastApi>(
|
||||||
show,
|
() => ({
|
||||||
success: (message: string) => show(message, 'success'),
|
show,
|
||||||
error: (message: string) => show(message, 'error'),
|
success: (message: string) => show(message, 'success'),
|
||||||
info: (message: string) => show(message, 'info'),
|
error: (message: string) => show(message, 'error'),
|
||||||
}), [show]);
|
info: (message: string) => show(message, 'info'),
|
||||||
|
}),
|
||||||
|
[show],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return subscribeApiErrorToasts((message) => api.error(message));
|
return subscribeApiErrorToasts((message) => api.error(message));
|
||||||
@@ -86,7 +81,9 @@ export function ToastProvider({ children, durationMs = 3500 }: ToastProviderProp
|
|||||||
role="status"
|
role="status"
|
||||||
>
|
>
|
||||||
<div className={styles.content}>
|
<div className={styles.content}>
|
||||||
<span className={styles.icon} aria-hidden="true">{ICONS[item.variant]}</span>
|
<span className={styles.icon} aria-hidden="true">
|
||||||
|
{ICONS[item.variant]}
|
||||||
|
</span>
|
||||||
<p className={styles.message}>{item.message}</p>
|
<p className={styles.message}>{item.message}</p>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button
|
||||||
@@ -103,11 +100,3 @@ export function ToastProvider({ children, durationMs = 3500 }: ToastProviderProp
|
|||||||
</ToastContext.Provider>
|
</ToastContext.Provider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useToast(): ToastApi {
|
|
||||||
const ctx = useContext(ToastContext);
|
|
||||||
if (!ctx) {
|
|
||||||
throw new Error('useToast must be used within ToastProvider');
|
|
||||||
}
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { createContext } from 'react';
|
||||||
|
|
||||||
|
export type ToastVariant = 'success' | 'error' | 'info';
|
||||||
|
|
||||||
|
export interface ToastApi {
|
||||||
|
show: (message: string, variant?: ToastVariant) => void;
|
||||||
|
success: (message: string) => void;
|
||||||
|
error: (message: string) => void;
|
||||||
|
info: (message: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ToastContext = createContext<ToastApi | null>(null);
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import { useContext } from 'react';
|
||||||
|
import { ToastContext, type ToastApi } from './toast-context';
|
||||||
|
|
||||||
|
export function useToast(): ToastApi {
|
||||||
|
const ctx = useContext(ToastContext);
|
||||||
|
if (!ctx) {
|
||||||
|
throw new Error('useToast must be used within ToastProvider');
|
||||||
|
}
|
||||||
|
return ctx;
|
||||||
|
}
|
||||||
@@ -4,6 +4,23 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
transition: background var(--transition);
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge:hover {
|
||||||
|
background: color-mix(in srgb, var(--color-neutral-bg) 85%, white);
|
||||||
|
}
|
||||||
|
|
||||||
|
.swatch {
|
||||||
|
width: 8px;
|
||||||
|
height: 8px;
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 1px solid currentColor;
|
||||||
|
box-sizing: border-box;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
all: unset;
|
all: unset;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
|
|||||||
@@ -7,9 +7,15 @@ export interface UuidBadgeProps {
|
|||||||
id: string;
|
id: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function uuidColor(id: string): string | null {
|
||||||
|
const hex = id.replace(/-/g, '').slice(0, 6);
|
||||||
|
return /^[0-9a-f]{6}$/i.test(hex) ? `#${hex}` : null;
|
||||||
|
}
|
||||||
|
|
||||||
export function UuidBadge({ id }: UuidBadgeProps) {
|
export function UuidBadge({ id }: UuidBadgeProps) {
|
||||||
const [copied, setCopied] = useState(false);
|
const [copied, setCopied] = useState(false);
|
||||||
const short = `${id.slice(0, 4)}…${id.slice(-4)}`;
|
const short = `${id.slice(0, 4)}…${id.slice(-4)}`;
|
||||||
|
const color = uuidColor(id);
|
||||||
|
|
||||||
const handleClick = (e: React.MouseEvent) => {
|
const handleClick = (e: React.MouseEvent) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
@@ -21,7 +27,10 @@ export function UuidBadge({ id }: UuidBadgeProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={styles.wrapper} title={copied ? 'Copied!' : id}>
|
<span className={styles.wrapper} title={copied ? 'Copied!' : id}>
|
||||||
<Badge variant="neutral">
|
<Badge variant="neutral" className={styles.badge}>
|
||||||
|
{color && (
|
||||||
|
<span className={styles.swatch} style={{ background: color }} aria-hidden="true" />
|
||||||
|
)}
|
||||||
<button type="button" className={styles.button} onClick={handleClick}>
|
<button type="button" className={styles.button} onClick={handleClick}>
|
||||||
{short}
|
{short}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
+11
-2
@@ -27,8 +27,9 @@ export type { BreadcrumbsProps, BreadcrumbItem } from './Breadcrumbs/Breadcrumbs
|
|||||||
|
|
||||||
export { ThemeSwitcher } from './ThemeSwitcher/ThemeSwitcher';
|
export { ThemeSwitcher } from './ThemeSwitcher/ThemeSwitcher';
|
||||||
|
|
||||||
export { ToastProvider, useToast } from './Toast/ToastProvider';
|
export { ToastProvider } from './Toast/ToastProvider';
|
||||||
export type { ToastProviderProps } from './Toast/ToastProvider';
|
export type { ToastProviderProps } from './Toast/ToastProvider';
|
||||||
|
export { useToast } from './Toast/useToast';
|
||||||
|
|
||||||
export { Timestamp } from './Timestamp/Timestamp';
|
export { Timestamp } from './Timestamp/Timestamp';
|
||||||
export type { TimestampProps } from './Timestamp/Timestamp';
|
export type { TimestampProps } from './Timestamp/Timestamp';
|
||||||
@@ -42,6 +43,9 @@ export type { SearchProps } from './Search/Search';
|
|||||||
export { CodeBlock } from './CodeBlock/CodeBlock';
|
export { CodeBlock } from './CodeBlock/CodeBlock';
|
||||||
export type { CodeBlockProps } from './CodeBlock/CodeBlock';
|
export type { CodeBlockProps } from './CodeBlock/CodeBlock';
|
||||||
|
|
||||||
|
export { RevealableCodeBlock } from './RevealableCodeBlock/RevealableCodeBlock';
|
||||||
|
export type { RevealableCodeBlockProps } from './RevealableCodeBlock/RevealableCodeBlock';
|
||||||
|
|
||||||
export { CodeEditor } from './CodeEditor/CodeEditor';
|
export { CodeEditor } from './CodeEditor/CodeEditor';
|
||||||
export type { CodeEditorProps } from './CodeEditor/CodeEditor';
|
export type { CodeEditorProps } from './CodeEditor/CodeEditor';
|
||||||
|
|
||||||
@@ -61,7 +65,12 @@ export { Modal } from './Modal/Modal';
|
|||||||
export type { ModalProps } from './Modal/Modal';
|
export type { ModalProps } from './Modal/Modal';
|
||||||
|
|
||||||
export { Table } from './Table/Table';
|
export { Table } from './Table/Table';
|
||||||
export type { TableProps, TableColumn } from './Table/Table';
|
export type { TableProps, TableColumn, SortDirection } from './Table/Table';
|
||||||
|
|
||||||
export { UuidBadge } from './UuidBadge/UuidBadge';
|
export { UuidBadge } from './UuidBadge/UuidBadge';
|
||||||
export type { UuidBadgeProps } from './UuidBadge/UuidBadge';
|
export type { UuidBadgeProps } from './UuidBadge/UuidBadge';
|
||||||
|
|
||||||
|
export { LogOutput } from './LogOutput/LogOutput';
|
||||||
|
export type { LogOutputProps, LogOutputEntry, LogOutputLevel } from './LogOutput/LogOutput';
|
||||||
|
export { DEFAULT_LOG_DATA_LIMITS, formatLogText, hasLargeData } from './LogOutput/logText';
|
||||||
|
export type { LogDataLimits } from './LogOutput/logText';
|
||||||
@@ -11,6 +11,8 @@
|
|||||||
--color-primary-hover: #8ABD2E;
|
--color-primary-hover: #8ABD2E;
|
||||||
--color-primary-active: #77A320;
|
--color-primary-active: #77A320;
|
||||||
--color-primary-fg: #2D3339; /* Outer Space on bright green */
|
--color-primary-fg: #2D3339; /* Outer Space on bright green */
|
||||||
|
/* Primary as text/icon color on light surfaces (Atlantis is too light for text) */
|
||||||
|
--color-primary-text: #496904;
|
||||||
|
|
||||||
/* Secondary — Kimberly tint */
|
/* Secondary — Kimberly tint */
|
||||||
--color-secondary: #EDEAF8;
|
--color-secondary: #EDEAF8;
|
||||||
@@ -19,8 +21,8 @@
|
|||||||
--color-secondary-fg: #6650C0; /* Kimberly */
|
--color-secondary-fg: #6650C0; /* Kimberly */
|
||||||
--color-secondary-border: #B8B0E0;
|
--color-secondary-border: #B8B0E0;
|
||||||
|
|
||||||
/* Danger */
|
/* Danger (white text needs >= 4.5:1) */
|
||||||
--color-danger: #D94F4F;
|
--color-danger: #CE4546;
|
||||||
--color-danger-hover: #C03A3A;
|
--color-danger-hover: #C03A3A;
|
||||||
--color-danger-fg: #ffffff;
|
--color-danger-fg: #ffffff;
|
||||||
|
|
||||||
@@ -43,11 +45,22 @@
|
|||||||
--color-link-hover: #3D2F80;
|
--color-link-hover: #3D2F80;
|
||||||
|
|
||||||
--color-text: #2D3339;
|
--color-text: #2D3339;
|
||||||
--color-text-muted: #6650C0; /* Kimberly */
|
--color-text-muted: #634DBD; /* Kimberly, a touch darker for 4.5:1 on bg-subtle */
|
||||||
|
--color-text-faint: #5C6063; /* desaturated grey, ~4.5:1 on bg-subtle - as washed out as WCAG AA allows */
|
||||||
--color-border: #AFBFB9; /* Powder Ash */
|
--color-border: #AFBFB9; /* Powder Ash */
|
||||||
--color-bg: #E6EDEA; /* Powder Ash tint */
|
--color-bg: #E6EDEA; /* Powder Ash tint */
|
||||||
--color-bg-subtle: #D8E2DE; /* Powder Ash tint, 1 step darker */
|
--color-bg-subtle: #D8E2DE; /* Powder Ash tint, 1 step darker */
|
||||||
|
|
||||||
|
/* Syntax highlighting (CodeBlock); each >= 4.5:1 on bg and bg-subtle */
|
||||||
|
--hl-comment: #4F6557;
|
||||||
|
--hl-keyword: #764E99;
|
||||||
|
--hl-string: #4F6821;
|
||||||
|
--hl-number: #895403;
|
||||||
|
--hl-function: #056980;
|
||||||
|
--hl-variable: #815354;
|
||||||
|
--hl-property: #1D6971;
|
||||||
|
--hl-meta: #615B7E;
|
||||||
|
|
||||||
/* Spacing */
|
/* Spacing */
|
||||||
--space-1: 4px;
|
--space-1: 4px;
|
||||||
--space-2: 8px;
|
--space-2: 8px;
|
||||||
@@ -112,6 +125,7 @@ a:hover {
|
|||||||
--color-primary-hover: #AEDE55;
|
--color-primary-hover: #AEDE55;
|
||||||
--color-primary-active: #8ABD2E;
|
--color-primary-active: #8ABD2E;
|
||||||
--color-primary-fg: #1A1F24;
|
--color-primary-fg: #1A1F24;
|
||||||
|
--color-primary-text: #9DD341;
|
||||||
|
|
||||||
/* Secondary — dark Kimberly tint */
|
/* Secondary — dark Kimberly tint */
|
||||||
--color-secondary: #2A2548;
|
--color-secondary: #2A2548;
|
||||||
@@ -122,7 +136,7 @@ a:hover {
|
|||||||
|
|
||||||
/* Danger */
|
/* Danger */
|
||||||
--color-danger: #E06060;
|
--color-danger: #E06060;
|
||||||
--color-danger-hover: #CC4A4A;
|
--color-danger-hover: #F06E6D; /* lighter, so the dark text keeps >= 4.5:1 */
|
||||||
--color-danger-fg: #1A1F24;
|
--color-danger-fg: #1A1F24;
|
||||||
|
|
||||||
/* Semantic */
|
/* Semantic */
|
||||||
@@ -145,7 +159,18 @@ a:hover {
|
|||||||
|
|
||||||
--color-text: #E2EAE6;
|
--color-text: #E2EAE6;
|
||||||
--color-text-muted: #A9A3C9; /* lightened Kimberly */
|
--color-text-muted: #A9A3C9; /* lightened Kimberly */
|
||||||
|
--color-text-faint: #9A9A9A; /* desaturated grey, ~4.5:1 on dark bg-subtle - as washed out as WCAG AA allows */
|
||||||
--color-border: #3D4850;
|
--color-border: #3D4850;
|
||||||
--color-bg: #1A1F24; /* deeper than Outer Space */
|
--color-bg: #1A1F24; /* deeper than Outer Space */
|
||||||
--color-bg-subtle: #2D3339; /* Outer Space */
|
--color-bg-subtle: #2D3339; /* Outer Space */
|
||||||
|
|
||||||
|
/* Syntax highlighting (CodeBlock); each >= 4.5:1 on bg and bg-subtle */
|
||||||
|
--hl-comment: #8AA192;
|
||||||
|
--hl-keyword: #B38ADA;
|
||||||
|
--hl-string: #9BB870;
|
||||||
|
--hl-number: #E8A85F;
|
||||||
|
--hl-function: #5BB8D4;
|
||||||
|
--hl-variable: #D4A0A0;
|
||||||
|
--hl-property: #79C0C8;
|
||||||
|
--hl-meta: #A9A3C9;
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
{"root":["./src/App.tsx","./src/declarations.d.ts","./src/main.tsx","./src/api/client.ts","./src/api/index.ts","./src/api/types.ts","./src/hooks/useTheme.ts","./src/i18n/index.ts","./src/lib/hljs.ts","./src/lib/toast-events.ts","./src/pages/credential/CreateCredentialPage.tsx","./src/pages/credential/CredentialDetailPage.tsx","./src/pages/credential/CredentialsPage.tsx","./src/pages/credential/EditCredentialPage.tsx","./src/pages/environment/CreateEnvironmentPage.tsx","./src/pages/environment/EditEnvironmentPage.tsx","./src/pages/environment/EnvironmentDetailPage.tsx","./src/pages/environment/EnvironmentsPage.tsx","./src/pages/run/AllRunsPage.tsx","./src/pages/run/RunDetailPage.tsx","./src/pages/run/RunsPage.tsx","./src/pages/scenario/CreateScenarioPage.tsx","./src/pages/scenario/CreateStepPage.tsx","./src/pages/scenario/EditScenarioPage.tsx","./src/pages/scenario/EditStepPage.tsx","./src/pages/scenario/ScenarioDetailPage.tsx","./src/pages/scenario/ScenariosPage.tsx","./src/pages/session/SessionDetailPage.tsx","./src/pages/session/SessionsPage.tsx","./src/pages/snippet/CreateSnippetPage.tsx","./src/pages/snippet/EditSnippetPage.tsx","./src/pages/snippet/SnippetDetailPage.tsx","./src/pages/snippet/SnippetsPage.tsx","./src/ui/index.ts","./src/ui/AutoRefreshIndicator/AutoRefreshIndicator.tsx","./src/ui/Badge/Badge.tsx","./src/ui/Breadcrumbs/Breadcrumbs.tsx","./src/ui/Button/Button.tsx","./src/ui/Card/Card.tsx","./src/ui/CodeBlock/CodeBlock.tsx","./src/ui/CodeEditor/CodeEditor.tsx","./src/ui/ContextMenu/ContextMenu.tsx","./src/ui/DescriptionList/DescriptionList.tsx","./src/ui/Input/Input.tsx","./src/ui/MarkdownContent/MarkdownContent.tsx","./src/ui/Modal/Modal.tsx","./src/ui/Notification/Notification.tsx","./src/ui/Pagination/Pagination.tsx","./src/ui/Search/Search.tsx","./src/ui/Select/Select.tsx","./src/ui/SidePanel/SidePanel.tsx","./src/ui/Table/Table.tsx","./src/ui/Textarea/Textarea.tsx","./src/ui/ThemeSwitcher/ThemeSwitcher.tsx","./src/ui/Timestamp/Timestamp.tsx","./src/ui/Toast/ToastProvider.tsx","./src/ui/UuidBadge/UuidBadge.tsx"],"version":"5.8.3"}
|
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
services:
|
||||||
|
liqa:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
ports:
|
||||||
|
# UI, REST API (/api/v1), MCP (/mcp) and Swagger (/docs).
|
||||||
|
# The production CORS origins (server/src/common/cors.ts) use this port;
|
||||||
|
# set CORS_ORIGINS in .env when publishing it elsewhere.
|
||||||
|
- "13000:3000"
|
||||||
|
# Optional overrides (see .env.example); every setting has a default
|
||||||
|
env_file:
|
||||||
|
- path: .env
|
||||||
|
required: false
|
||||||
|
volumes:
|
||||||
|
# persist SQLite database across restarts
|
||||||
|
- ./data:/app/data
|
||||||
|
restart: unless-stopped
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
services:
|
|
||||||
server:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: server/Dockerfile
|
|
||||||
ports:
|
|
||||||
- "13000:3000"
|
|
||||||
env_file:
|
|
||||||
- .env
|
|
||||||
volumes:
|
|
||||||
# persist SQLite database across restarts
|
|
||||||
- ./data:/app/data
|
|
||||||
# mount key files into the container
|
|
||||||
- ./keys:/app/keys
|
|
||||||
restart: unless-stopped
|
|
||||||
|
|
||||||
client:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: client/Dockerfile
|
|
||||||
ports:
|
|
||||||
- "13001:80"
|
|
||||||
restart: unless-stopped
|
|
||||||
+70
-38
@@ -1,50 +1,82 @@
|
|||||||
# Architecture
|
# Architecture
|
||||||
|
|
||||||
```
|
```
|
||||||
┌──────────────────────────────────────────────────────┐
|
Browser (React SPA) MCP client (AI agent, IDE)
|
||||||
│ Browser (React SPA - client/) │
|
│ / and /api/v1 │ /mcp (Streamable HTTP)
|
||||||
│ │
|
└──────────────┬──────────────────┘
|
||||||
│ Environments Credentials Snippets │
|
▼
|
||||||
│ Sessions Scenarios Runs │
|
┌─────────────────────────────────────────────────────────────┐
|
||||||
└─────────────────────────────┬────────────────────────┘
|
│ liqa container (:13000 → 3000) NestJS app, server/src/ │
|
||||||
│ HTTP REST (:13000)
|
│ │
|
||||||
│
|
│ Routes / built client (ServeStaticModule) │
|
||||||
MCP client (AI agent / VS Code Copilot)
|
│ /api/v1 REST API /docs Swagger UI │
|
||||||
│ HTTP /mcp (Streamable MCP)
|
│ /mcp MCP tools /health health check │
|
||||||
▼
|
│ /manifest.json public client configuration │
|
||||||
┌──────────────────────────────────────────────────────┐
|
│ │
|
||||||
│ NestJS app (server/src/) │
|
│ McpService MCP tools → services below │
|
||||||
│ │
|
│ ScenarioService scenarios, steps, versions, runs │
|
||||||
│ McpService all MCP tools │
|
│ ScenarioSchedulerService @Interval(1 s) run worker │
|
||||||
│ SessionService session persistence │
|
│ E2eExportService standalone Playwright test zip │
|
||||||
│ SessionContextService live browser contexts │
|
│ SnippetService snippets + versions │
|
||||||
│ EnvironmentService environment CRUD + import │
|
│ EnvironmentService environments │
|
||||||
│ CredentialService credential CRUD + import │
|
│ CredentialService credentials │
|
||||||
│ SnippetService snippet CRUD + import │
|
│ ImportService central YAML import │
|
||||||
│ BrowserService ad-hoc open/exec │
|
│ FileStorageService scenario files + run artifacts │
|
||||||
│ CodeExecutorService sandboxed JS runtime │
|
│ SessionService saved browser sessions │
|
||||||
│ ScenarioService scenarios/steps/runs CRUD │
|
│ SessionContextService live Playwright contexts │
|
||||||
│ ScenarioSchedulerService @Interval(1 s) run worker │
|
│ SessionSchedulerService @Interval(60 s) session cleanup │
|
||||||
└───────────────────────┬──────────────────────────────┘
|
│ BrowserService ad-hoc open / exec │
|
||||||
│ better-sqlite3 (TypeORM)
|
│ CodeExecutorService runs step / snippet JS │
|
||||||
▼
|
└───────────────┬─────────────────────────────┬───────────────┘
|
||||||
data/sessions.db
|
│ TypeORM (better-sqlite3) │ Playwright
|
||||||
|
▼ ▼
|
||||||
|
data/liqa.db, data/files/ chromium-headless-shell
|
||||||
```
|
```
|
||||||
|
|
||||||
- **McpService** registers MCP tools and delegates to session, environment, browser, and scenario services.
|
Everything runs in one container built from the root `Dockerfile`: the server serves the API, MCP and Swagger, and also the built client. See [development.md](development.md) for running it.
|
||||||
- **SessionService** persists session records in SQLite. **SessionContextService** manages live Playwright contexts for open sessions.
|
|
||||||
- **EnvironmentService**, **CredentialService**, and **SnippetService** provide CRUD plus import/export upserts.
|
## Server components (`server/src/`)
|
||||||
- **BrowserService** handles stateless ad-hoc automation (`/open`, `/exec`) and session-aware browsing.
|
|
||||||
- **CodeExecutorService** validates and executes user JS with `page`, `context`, and helper APIs.
|
- **McpService** (`mcp/`) registers the MCP tools and delegates to the services below. Each request gets a fresh MCP server over the Streamable HTTP transport.
|
||||||
- **ScenarioService** manages scenarios, steps, credential aliases, runs, logs, and scenario import/export.
|
- **ScenarioService** (`scenario/`) manages scenarios, steps, credential aliases, versions, runs, run logs, scenario/run files, and scenario export/import.
|
||||||
- **ScenarioSchedulerService** polls pending runs every second and executes step runs to completion.
|
- **ScenarioSchedulerService** picks up pending runs every second (up to 10 in parallel) and executes their steps in order in one Playwright browser per run. It handles step and scenario timeouts, failure page dumps (screenshot + HTML), Playwright traces, and saving the browser as a session (`saveSession`).
|
||||||
|
- **E2eExportService** builds a standalone Playwright test project (zip) from a scenario, bundling the snippets, credentials and files it uses.
|
||||||
|
- **SnippetService** (`snippet/`), **EnvironmentService** (`environment/`) and **CredentialService** (`credential/`) provide CRUD plus export/import.
|
||||||
|
- **ImportService** (`import/`) implements `POST /import`: validates a YAML stream of mixed items, then imports them in dependency order (environments, credentials, snippets, scenarios).
|
||||||
|
- **FileStorageService** (`file/`) stores uploaded scenario files and run artifacts under `FILES_DIR`, and deletes expired files on a cron schedule (`FILE_CLEANUP_CRON`).
|
||||||
|
- **SessionService** (`session/`) persists saved sessions (cookies, localStorage); **SessionContextService** keeps their live Playwright contexts; **SessionSchedulerService** closes idle sessions and deletes old closed ones every minute.
|
||||||
|
- **BrowserService** (`browser/`) handles ad-hoc automation (`POST /api/v1/open`, `POST /api/v1/exec`, and the `open_url` / `exec_code` MCP tools), optionally in a saved session.
|
||||||
|
- **CodeExecutorService** (`code-executor/`) checks step and snippet code with acorn, then runs it with the `context` API (page, environment values, credentials, snippets, files, assertions, logs). It is not a security sandbox: step code is trusted.
|
||||||
|
|
||||||
|
Cross-cutting pieces:
|
||||||
|
|
||||||
|
- `config/app.config.ts` - all settings, validated at startup (see `.env.example`).
|
||||||
|
- `database/` - the entity list, TypeORM data source options (shared by the app, the migration runner and the TypeORM CLI), the migration runner and the migrations.
|
||||||
|
- `common/app-package.ts` - app name and version, read from the workspace root `package.json`.
|
||||||
|
- `common/client-static.ts` - serving the built client, with the `index.html` fallback for client-side routes.
|
||||||
|
- `common/body-parsers.ts` - YAML request bodies (`application/yaml`) for the import endpoint.
|
||||||
|
- `interceptors/` - a trace id per request (kept in `AsyncLocalStorage` and added to log lines) and request/response logging; `filters/` - consistent error responses.
|
||||||
|
|
||||||
|
## Data
|
||||||
|
|
||||||
|
SQLite via TypeORM. The schema is managed by migrations (`server/src/database/migrations/`, registered in `migrations/index.ts`); `synchronize` is off. The Docker container applies pending migrations (`node dist/database/migrate`) before starting the server, and the server refuses to start while migrations are pending. See "Database migrations" in [development.md](development.md). The main tables:
|
||||||
|
|
||||||
|
- `scenarios` / `scenario_steps` hold the **latest** version of each scenario; `scenario_versions` holds a snapshot of every version (content + steps).
|
||||||
|
- `snippets` holds the latest version of each snippet; `snippet_versions` holds every version. Step code pins a version with `runSnippet("alias@N")`.
|
||||||
|
- `scenario_runs` record the scenario version, environment, trace mode and status; `scenario_run_steps` keep their own copy of each step's code, so a run always shows what it executed; `scenario_run_logs` hold ordered run logs.
|
||||||
|
- `files` + `scenario_files` / `scenario_run_files` map stored files to scenarios and runs.
|
||||||
|
- `environments`, `credentials`, `scenario_credentials` (alias → credential per scenario), `sessions`.
|
||||||
|
|
||||||
|
See [scenario.md](scenario.md) for versioning, runs and import/export rules.
|
||||||
|
|
||||||
## Client (`client/`)
|
## Client (`client/`)
|
||||||
|
|
||||||
A React 19 + TypeScript SPA served separately by Vite during development. In Docker Compose the same build artefacts are served statically alongside the API.
|
A React 19 + TypeScript SPA. During development it's served by the Vite dev server; in the Docker image the server serves the built client from the same origin as the API.
|
||||||
|
|
||||||
The client calls the server REST endpoints directly — there is no separate BFF layer. Routing uses HashRouter so the Vite proxy and server-side routes are never ambiguous.
|
The client calls the server REST endpoints directly — there is no separate BFF layer. Routing uses `BrowserRouter`; the server answers any GET outside `/api`, `/mcp`, `/docs`, `/health` and `/manifest.json` with the client's `index.html`, so client-side routes survive a page refresh.
|
||||||
|
|
||||||
The sidebar footer contains the theme switcher and the app version (injected from the workspace root `package.json` at build time).
|
Pages: scenarios (with steps, versions, credentials, used snippets and files), runs, snippets, credentials, environments, sessions, and the central import page. The sidebar footer contains the theme switcher and the app version.
|
||||||
|
|
||||||
|
`GET /manifest.json` is the server's public configuration for the client: the app `name` and `version`, and settings the UI needs (currently `runLogs.dataLimits`, from `RUN_LOG_DATA_COLLAPSE_BYTES` / `RUN_LOG_DATA_COLLAPSE_LINES`). The client reads it through `client/src/lib/manifest.ts` and the `useManifest()` hook, stale-while-revalidate: the copy cached in `localStorage` (or built-in defaults on first visit) is used right away, and the manifest is refetched once per page load and when the tab becomes visible again after 5 minutes. The server sends it with `Cache-Control: no-cache` and an ETag, so an unchanged manifest costs a 304. Add new client-facing settings to the manifest (`server/src/manifest/`) rather than as build-time Vite variables.
|
||||||
|
|
||||||
See [development.md](development.md) for the full client tech stack and directory layout.
|
See [development.md](development.md) for the full client tech stack and directory layout.
|
||||||
Loaded 100 of 218 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user