mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-09-06 18:07:18 +02:00
Compare commits
94
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
646f5a09b0 | ||
|
|
e47088b507 | ||
|
|
3ad6172bb1 | ||
|
|
7bd159b0b1 | ||
|
|
b08b3277da | ||
|
|
19a43e3785 | ||
|
|
77fe1367a0 | ||
|
|
862fb6d65a | ||
|
|
d2d4b80a09 | ||
|
|
d461c982ec | ||
|
|
8eebee460e | ||
|
|
81a2a5d955 | ||
|
|
e63a87718c | ||
|
|
222ea9cb83 | ||
|
|
360c098b09 | ||
|
|
fce1039bac | ||
|
|
f18f93d613 | ||
|
|
661a384bed | ||
|
|
50cccf1d25 | ||
|
|
0aae516f3a | ||
|
|
b7b8ae5f94 | ||
|
|
6777003b70 | ||
|
|
426c6d5eb6 | ||
|
|
068afe325e | ||
|
|
cef1129d4b | ||
|
|
9a7bcf73bb | ||
|
|
aa76d501f0 | ||
|
|
ce8cb5e7bc | ||
|
|
66c13d7e13 | ||
|
|
388dd8815f | ||
|
|
cb295b7102 | ||
|
|
4e835cf7e8 | ||
|
|
2350689d7a | ||
|
|
4eebd606ef | ||
|
|
c4f96f3f11 | ||
|
|
71c217d3f0 | ||
|
|
d89831a84d | ||
|
|
3332ae263f | ||
|
|
df1fd864b2 | ||
|
|
a2d54ca774 | ||
|
|
36fec8b005 | ||
|
|
115615d994 | ||
|
|
538f782068 | ||
|
|
3f202ff664 | ||
|
|
131b7e5ab1 | ||
|
|
69083918f9 | ||
|
|
4b2dcf9a1a | ||
|
|
569f552d79 | ||
|
|
33f32cccf6 | ||
|
|
7ca772347f | ||
|
|
b89c448345 | ||
|
|
2021df112a | ||
|
|
2d2a390bfd | ||
|
|
5cce23566a | ||
|
|
e99f6d2bc7 | ||
|
|
bea58b16b4 | ||
|
|
93fba4d9b4 | ||
|
|
b9071eafe0 | ||
|
|
778c74c635 | ||
|
|
0f434361a7 | ||
|
|
d27d11af7c | ||
|
|
1a19a06a23 | ||
|
|
07a9a6c6c0 | ||
|
|
e54240d579 | ||
|
|
8bca013ab4 | ||
|
|
10e962a0e6 | ||
|
|
78954e10c8 | ||
|
|
9eb7a001da | ||
|
|
6a02cbe525 | ||
|
|
6f91f76064 | ||
|
|
32e92d484b | ||
|
|
cdbbef34f8 | ||
|
|
4838353585 | ||
|
|
93001e3da7 | ||
|
|
b31c066717 | ||
|
|
5d1d24870a | ||
|
|
6f0d0ef275 | ||
|
|
85a9b2a908 | ||
|
|
f3f05502d1 | ||
|
|
2e0f7d1818 | ||
|
|
dc793181bb | ||
|
|
7dfa7e07e3 | ||
|
|
23e7229e63 | ||
|
|
1f91cddab9 | ||
|
|
be004425fa | ||
|
|
4f03c5c390 | ||
|
|
cb43f0b9b9 | ||
|
|
68671377fd | ||
|
|
2383f06e71 | ||
|
|
0068be9ffc | ||
|
|
def7d752db | ||
|
|
85aed740a8 | ||
|
|
d3055c64b3 | ||
|
|
912aaeb7a7 |
@@ -0,0 +1,11 @@
|
|||||||
|
node_modules
|
||||||
|
**/node_modules
|
||||||
|
dist
|
||||||
|
**/dist
|
||||||
|
target
|
||||||
|
**/target
|
||||||
|
.claude
|
||||||
|
vendored
|
||||||
|
**/vendored
|
||||||
|
*.log
|
||||||
|
.git
|
||||||
@@ -31,3 +31,7 @@ jobs:
|
|||||||
run: vp test
|
run: vp test
|
||||||
- name: Run Rust Tests
|
- name: Run Rust Tests
|
||||||
run: cargo test --all --features yaak-app-client/wry
|
run: cargo test --all --features yaak-app-client/wry
|
||||||
|
- name: OpenAPI import round-trip
|
||||||
|
run: |
|
||||||
|
cargo build -p yaak-cli
|
||||||
|
node plugins/importer-openapi/tests/roundtrip.mjs
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ jobs:
|
|||||||
runtime: "wry"
|
runtime: "wry"
|
||||||
targets: "aarch64-pc-windows-msvc"
|
targets: "aarch64-pc-windows-msvc"
|
||||||
runs-on: ${{ matrix.platform }}
|
runs-on: ${{ matrix.platform }}
|
||||||
timeout-minutes: 40
|
timeout-minutes: 60
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout yaakapp/app
|
- name: Checkout yaakapp/app
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -103,6 +103,18 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y cmake ninja-build libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev libnss3 patchelf xdg-utils
|
sudo apt-get install -y cmake ninja-build libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev libnss3 patchelf xdg-utils
|
||||||
|
# crates/yaak-wasm compiles SQLite to wasm via sqlite-wasm-rs, whose C shim
|
||||||
|
# uses C23 [[noreturn]] and expects a freestanding wasm32 target. Ubuntu
|
||||||
|
# 22.04 ships only clang <=15: 14 rejects the attribute, and 15 falls
|
||||||
|
# through to host glibc headers ("bits/libc-header-start.h" not found).
|
||||||
|
# clang-18 handles it (it is what ubuntu-24.04 uses). Install it from
|
||||||
|
# apt.llvm.org since 22.04's repos stop at 15. Only the wasm build uses
|
||||||
|
# this compiler, so the shipped binary keeps 22.04's glibc floor.
|
||||||
|
wget -qO /tmp/llvm.sh https://apt.llvm.org/llvm.sh
|
||||||
|
chmod +x /tmp/llvm.sh
|
||||||
|
sudo /tmp/llvm.sh 18
|
||||||
|
echo "CC_wasm32_unknown_unknown=/usr/bin/clang-18" >> "$GITHUB_ENV"
|
||||||
|
echo "AR_wasm32_unknown_unknown=/usr/bin/llvm-ar-18" >> "$GITHUB_ENV"
|
||||||
|
|
||||||
- name: Install Protoc for plugin-runtime
|
- name: Install Protoc for plugin-runtime
|
||||||
uses: arduino/setup-protoc@v3
|
uses: arduino/setup-protoc@v3
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
name: Release web image
|
||||||
|
|
||||||
|
# Builds ghcr.io/mountain-loop/yaak-web: the browser client and the server that serves it.
|
||||||
|
# One image per architecture on its own native runner (emulating a Rust release build is hours),
|
||||||
|
# joined into one multi-arch tag at the end.
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: [v*]
|
||||||
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
version:
|
||||||
|
description: Version to publish, without the v (e.g. 2026.2.0). Empty publishes main and sha tags only.
|
||||||
|
required: false
|
||||||
|
type: string
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
env:
|
||||||
|
IMAGE: ghcr.io/mountain-loop/yaak-web
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
if: github.repository == 'mountain-loop/yaak'
|
||||||
|
name: Build ${{ matrix.platform }}
|
||||||
|
runs-on: ${{ matrix.runner }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- platform: linux/amd64
|
||||||
|
runner: ubuntu-22.04
|
||||||
|
arch: amd64
|
||||||
|
- platform: linux/arm64
|
||||||
|
runner: ubuntu-22.04-arm
|
||||||
|
arch: arm64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to GHCR
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push by digest
|
||||||
|
id: build
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: Dockerfile.web
|
||||||
|
platforms: ${{ matrix.platform }}
|
||||||
|
outputs: type=image,name=${{ env.IMAGE }},push-by-digest=true,name-canonical=true,push=true
|
||||||
|
|
||||||
|
- name: Export digest
|
||||||
|
run: |
|
||||||
|
mkdir -p "${{ runner.temp }}/digests"
|
||||||
|
digest="${{ steps.build.outputs.digest }}"
|
||||||
|
touch "${{ runner.temp }}/digests/${digest#sha256:}"
|
||||||
|
|
||||||
|
- name: Upload digest
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: digest-${{ matrix.arch }}
|
||||||
|
path: ${{ runner.temp }}/digests/*
|
||||||
|
if-no-files-found: error
|
||||||
|
retention-days: 1
|
||||||
|
|
||||||
|
publish:
|
||||||
|
name: Publish manifest
|
||||||
|
needs: build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download digests
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
path: ${{ runner.temp }}/digests
|
||||||
|
pattern: digest-*
|
||||||
|
merge-multiple: true
|
||||||
|
|
||||||
|
- name: Set up Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Log in to GHCR
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
# `latest` follows a release tag, and a manual run that names a version — the way to
|
||||||
|
# publish before the first release. A prerelease (v2026.2.1-beta.1) never takes it.
|
||||||
|
- name: Tags
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ env.IMAGE }}
|
||||||
|
flavor: latest=false
|
||||||
|
tags: |
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=raw,value=${{ inputs.version }},enable=${{ inputs.version != '' }}
|
||||||
|
type=raw,value=latest,enable=${{ inputs.version != '' || (github.event_name == 'push' && !contains(github.ref_name, '-')) }}
|
||||||
|
type=ref,event=branch
|
||||||
|
type=sha,format=short
|
||||||
|
|
||||||
|
- name: Create and push the manifest
|
||||||
|
working-directory: ${{ runner.temp }}/digests
|
||||||
|
run: |
|
||||||
|
docker buildx imagetools create \
|
||||||
|
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
|
||||||
|
$(printf '${{ env.IMAGE }}@sha256:%s ' *)
|
||||||
|
|
||||||
|
- name: Inspect
|
||||||
|
run: docker buildx imagetools inspect ${{ env.IMAGE }}:${{ steps.meta.outputs.version }}
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
**/bindings/**
|
|
||||||
**/routeTree.gen.ts
|
|
||||||
crates/yaak-templates/pkg/**
|
|
||||||
Generated
+451
-78
File diff suppressed because it is too large
Load Diff
@@ -2,9 +2,11 @@
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
members = [
|
members = [
|
||||||
"crates/yaak",
|
"crates/yaak",
|
||||||
|
"crates/yaak-commands",
|
||||||
# Common/foundation crates
|
# Common/foundation crates
|
||||||
"crates/common/yaak-database",
|
"crates/common/yaak-database",
|
||||||
"crates/common/yaak-rpc",
|
"crates/common/yaak-rpc",
|
||||||
|
"crates/common/yaak-rpc-schema",
|
||||||
# Shared crates (no Tauri dependency)
|
# Shared crates (no Tauri dependency)
|
||||||
"crates/yaak-core",
|
"crates/yaak-core",
|
||||||
"crates/yaak-common",
|
"crates/yaak-common",
|
||||||
@@ -12,6 +14,7 @@ members = [
|
|||||||
"crates/yaak-git",
|
"crates/yaak-git",
|
||||||
"crates/yaak-grpc",
|
"crates/yaak-grpc",
|
||||||
"crates/yaak-http",
|
"crates/yaak-http",
|
||||||
|
"crates/yaak-lifecycle",
|
||||||
"crates/yaak-models",
|
"crates/yaak-models",
|
||||||
"crates/yaak-plugins",
|
"crates/yaak-plugins",
|
||||||
"crates/yaak-sse",
|
"crates/yaak-sse",
|
||||||
@@ -19,10 +22,13 @@ members = [
|
|||||||
"crates/yaak-templates",
|
"crates/yaak-templates",
|
||||||
"crates/yaak-tls",
|
"crates/yaak-tls",
|
||||||
"crates/yaak-ws",
|
"crates/yaak-ws",
|
||||||
|
"crates/yaak-wasm",
|
||||||
"crates/yaak-api",
|
"crates/yaak-api",
|
||||||
"crates/yaak-proxy",
|
"crates/yaak-proxy",
|
||||||
# Proxy-specific crates
|
# Proxy-specific crates
|
||||||
"crates-proxy/yaak-proxy-lib",
|
"crates-proxy/yaak-proxy-lib",
|
||||||
|
# Server crates (the browser tier's hosted send executor)
|
||||||
|
"crates-server/yaak-web",
|
||||||
# CLI crates
|
# CLI crates
|
||||||
"crates-cli/yaak-cli",
|
"crates-cli/yaak-cli",
|
||||||
# Tauri-specific crates
|
# Tauri-specific crates
|
||||||
@@ -63,15 +69,18 @@ ts-rs = "11.1.0"
|
|||||||
# Internal crates - common/foundation
|
# Internal crates - common/foundation
|
||||||
yaak-database = { path = "crates/common/yaak-database" }
|
yaak-database = { path = "crates/common/yaak-database" }
|
||||||
yaak-rpc = { path = "crates/common/yaak-rpc" }
|
yaak-rpc = { path = "crates/common/yaak-rpc" }
|
||||||
|
yaak-rpc-schema = { path = "crates/common/yaak-rpc-schema" }
|
||||||
|
|
||||||
# Internal crates - shared
|
# Internal crates - shared
|
||||||
yaak-core = { path = "crates/yaak-core" }
|
yaak-core = { path = "crates/yaak-core" }
|
||||||
yaak = { path = "crates/yaak" }
|
yaak = { path = "crates/yaak" }
|
||||||
|
yaak-commands = { path = "crates/yaak-commands" }
|
||||||
yaak-common = { path = "crates/yaak-common" }
|
yaak-common = { path = "crates/yaak-common" }
|
||||||
yaak-crypto = { path = "crates/yaak-crypto" }
|
yaak-crypto = { path = "crates/yaak-crypto" }
|
||||||
yaak-git = { path = "crates/yaak-git" }
|
yaak-git = { path = "crates/yaak-git" }
|
||||||
yaak-grpc = { path = "crates/yaak-grpc" }
|
yaak-grpc = { path = "crates/yaak-grpc" }
|
||||||
yaak-http = { path = "crates/yaak-http" }
|
yaak-http = { path = "crates/yaak-http" }
|
||||||
|
yaak-lifecycle = { path = "crates/yaak-lifecycle" }
|
||||||
yaak-models = { path = "crates/yaak-models" }
|
yaak-models = { path = "crates/yaak-models" }
|
||||||
yaak-plugins = { path = "crates/yaak-plugins" }
|
yaak-plugins = { path = "crates/yaak-plugins" }
|
||||||
yaak-sse = { path = "crates/yaak-sse" }
|
yaak-sse = { path = "crates/yaak-sse" }
|
||||||
|
|||||||
@@ -44,6 +44,25 @@ After bootstrapping, start the app in development mode:
|
|||||||
npm start
|
npm start
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Run the App in a Browser
|
||||||
|
|
||||||
|
The client can also run as a plain web page, with no Tauri and no local process
|
||||||
|
behind it. Set `YAAK_TARGET=web` and start the frontend on its own:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
YAAK_TARGET=web npm run dev --workspace @yaakapp/yaak-client
|
||||||
|
```
|
||||||
|
|
||||||
|
That flag picks the browser host in `packages/platform/src/web/`, which answers
|
||||||
|
commands from an IndexedDB database the page owns instead of from the Rust
|
||||||
|
engine. Data persists across reloads and is shared between tabs on the same
|
||||||
|
origin. Sending HTTP is not available yet — the Send button reports that and
|
||||||
|
everything else about the request is still saved. `packages/platform/src/web/README.md`
|
||||||
|
lists which commands the browser host implements and which it declines.
|
||||||
|
|
||||||
|
Desktop builds are unaffected: without the flag the platform package installs
|
||||||
|
the Tauri host exactly as before.
|
||||||
|
|
||||||
## SQLite Migrations
|
## SQLite Migrations
|
||||||
|
|
||||||
New migrations can be created from the `src-tauri/` directory:
|
New migrations can be created from the `src-tauri/` directory:
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
# Yaak in a browser, whole: the web client and the server that executes its sends, in one
|
||||||
|
# image serving both from one origin.
|
||||||
|
#
|
||||||
|
# docker run -p 8080:8080 ghcr.io/mountain-loop/yaak-web
|
||||||
|
#
|
||||||
|
# See crates-server/yaak-web/README.md for the knobs.
|
||||||
|
|
||||||
|
FROM node:22-slim AS web
|
||||||
|
WORKDIR /app
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
git python3 make g++ ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||||
|
COPY . .
|
||||||
|
# `npm ci` runs a prepare hook (`vp config`) that shells out to git, and there is no .git in
|
||||||
|
# the build context — it is ignored, and in a worktree it is a pointer file anyway.
|
||||||
|
RUN git init -q && git add -A \
|
||||||
|
&& git -c user.email=build@yaak.app -c user.name=build commit -qm build
|
||||||
|
# Empty means the tab posts sends to its own origin, which is what this image serves. Set it
|
||||||
|
# only to build a bundle for a deployment whose server lives somewhere else.
|
||||||
|
ARG VITE_YAAK_WEB_URL=""
|
||||||
|
ENV VITE_YAAK_WEB_URL=$VITE_YAAK_WEB_URL
|
||||||
|
ENV YAAK_TARGET=web
|
||||||
|
# crates/yaak-wasm's wasm package is committed; rebuilding it needs a clang with a WebAssembly
|
||||||
|
# backend, which this image has no reason to carry.
|
||||||
|
ENV SKIP_WASM_BUILD=1
|
||||||
|
RUN npm ci
|
||||||
|
RUN node_modules/.bin/vp -C apps/yaak-client build
|
||||||
|
|
||||||
|
FROM rust:1-bookworm AS server
|
||||||
|
WORKDIR /app
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
pkg-config libssl-dev protobuf-compiler && rm -rf /var/lib/apt/lists/*
|
||||||
|
COPY . .
|
||||||
|
RUN cargo build --release -p yaak-web
|
||||||
|
|
||||||
|
FROM debian:bookworm-slim
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
ca-certificates libssl3 && rm -rf /var/lib/apt/lists/*
|
||||||
|
COPY --from=server /app/target/release/yaak-web /usr/local/bin/yaak-web
|
||||||
|
COPY --from=web /app/dist/apps/yaak-client /srv
|
||||||
|
ENV YAAK_WEB_BIND=0.0.0.0:8080
|
||||||
|
EXPOSE 8080
|
||||||
|
USER nobody
|
||||||
|
# Overriding the command (dropping --serve) leaves the stateless send executor:
|
||||||
|
# docker run ghcr.io/mountain-loop/yaak-web yaak-web
|
||||||
|
CMD ["yaak-web", "--serve", "/srv"]
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
# Request versioning (IntelliJ Local History style)
|
||||||
|
|
||||||
|
Working plan for `feat/request-versioning`. Tracks
|
||||||
|
[save-request-data-for-response-history](https://yaak.app/feedback/posts/save-request-data-for-response-history).
|
||||||
|
|
||||||
|
Selecting an old response should be able to show, and restore, the request that produced it.
|
||||||
|
|
||||||
|
## Model
|
||||||
|
|
||||||
|
One table, `model_versions`, versions every request type:
|
||||||
|
|
||||||
|
| column | meaning |
|
||||||
|
| --- | --- |
|
||||||
|
| `id`, `model`, `created_at`, `updated_at` | usual model columns |
|
||||||
|
| `workspace_id` | owning workspace |
|
||||||
|
| `model_type` | `http_request` / `grpc_request` / `websocket_request` |
|
||||||
|
| `model_id` | the request the version belongs to |
|
||||||
|
| `content_hash` | sha256 of the canonical document |
|
||||||
|
| `document` | JSON of the request's editable content |
|
||||||
|
| `reason` | `send` / `switch` / `idle` / `restore` / `manual` |
|
||||||
|
|
||||||
|
`http_responses`, `grpc_connections` and `websocket_connections` each gain a nullable
|
||||||
|
`version_id`.
|
||||||
|
|
||||||
|
A version's `document` is the model's JSON with bookkeeping keys removed — `model`, `id`,
|
||||||
|
`createdAt`, `updatedAt`, `workspaceId`, `folderId`, `sortPriority`. One rule, applied the same
|
||||||
|
way to all three request types; the hash is taken over exactly what the document holds, so moving
|
||||||
|
a request between folders or re-sorting it never mints a version.
|
||||||
|
|
||||||
|
`(model_id, content_hash)` is unique, so dedup is the database's job rather than a code path that
|
||||||
|
can be forgotten. Sending an unchanged request ten times leaves one version and ten responses
|
||||||
|
pointing at it.
|
||||||
|
|
||||||
|
## Snapshot
|
||||||
|
|
||||||
|
One primitive, `ClientDb::snapshot_request(request, reason)`: build the document, hash it, return
|
||||||
|
the existing row for that hash or insert a new one, then prune. Everything calls it.
|
||||||
|
|
||||||
|
- **Sends.** `resolve_send_inputs` (HTTP, every host — desktop, CLI, plugin-triggered) snapshots
|
||||||
|
before the response row is created, and the resulting id rides down to the response.
|
||||||
|
gRPC and WebSocket connect paths do the same at their own connection upserts.
|
||||||
|
- **Edit-session boundaries the frontend can see**, all through one RPC: switching to another
|
||||||
|
request, window blur, app close, and a 60s idle timer after the last edit.
|
||||||
|
|
||||||
|
Over-triggering is free, so the trigger code stays dumb.
|
||||||
|
|
||||||
|
## Restore
|
||||||
|
|
||||||
|
`restore_request_version(version_id)`:
|
||||||
|
|
||||||
|
1. Snapshot the live request (reason `restore`), so anything newer than its last version is kept.
|
||||||
|
2. Merge the version's document over the live model, keeping bookkeeping fields.
|
||||||
|
3. Upsert. The written content's hash already exists, so no new version row appears.
|
||||||
|
|
||||||
|
The frontend calls `wasUpdatedExternally` afterwards so open editors reload.
|
||||||
|
|
||||||
|
## Retention
|
||||||
|
|
||||||
|
An unreferenced version survives only while it is among the newest 50 for its request *and* newer
|
||||||
|
than 30 days. A version referenced by a response lives as long as that response. Deleting a
|
||||||
|
request deletes its versions. Versions are local history: not synced to the filesystem, not in
|
||||||
|
Git, not exported.
|
||||||
|
|
||||||
|
## UI (v1, HTTP)
|
||||||
|
|
||||||
|
When the selected response's version differs from the live request, the response header grows a
|
||||||
|
state-labelled dropdown ("Request Changed", following the GraphQL editor's pattern) with **View
|
||||||
|
Diff** and **Restore**. The diff reuses the Git dialog's `DiffViewer` over YAML renderings of the
|
||||||
|
two documents. No versions timeline panel in v1; gRPC and WebSocket are wired on the backend from
|
||||||
|
day one and their UI can follow.
|
||||||
|
|
||||||
|
## Status
|
||||||
|
|
||||||
|
- [x] Migration + `ModelVersion` model + bindings
|
||||||
|
- [x] Hashing / document extraction, with tests
|
||||||
|
- [x] Queries: snapshot, prune, restore, cascade
|
||||||
|
- [x] Send pipelines: HTTP, gRPC, WebSocket (plus the browser host's own)
|
||||||
|
- [x] RPC commands + web/wasm host
|
||||||
|
- [x] Frontend: snapshot triggers, dropdown, diff dialog, restore
|
||||||
|
|
||||||
|
## Deliberately not in v1
|
||||||
|
|
||||||
|
- **No versions timeline panel.** The only entry point is a response, which is
|
||||||
|
what the feedback asked for. A "browse all versions of this request" view is a
|
||||||
|
second feature on the same data and can land later without a schema change.
|
||||||
|
- **No gRPC or WebSocket UI.** Both record versions from day one, so the history
|
||||||
|
is accumulating; only the indicator is HTTP-only.
|
||||||
|
- **No `manual` trigger.** The reason exists so that adding a "Save version now"
|
||||||
|
action later is a UI change and not a migration.
|
||||||
|
- **Folders, environments and workspaces are not versioned.** The response
|
||||||
|
timeline already records what a send inherited from them.
|
||||||
|
|
||||||
|
## Notes for later
|
||||||
|
|
||||||
|
- The version's `document` is the model minus bookkeeping keys, so a restore
|
||||||
|
merges over the live model and a field added after a version was captured
|
||||||
|
keeps its live value rather than being blanked.
|
||||||
|
- `content_hash` sorts object keys before hashing. Relying on
|
||||||
|
`serde_json::Map` being a `BTreeMap` is not safe: `preserve_order` is on in
|
||||||
|
some builds of this workspace and off in others, which is exactly the bug the
|
||||||
|
`key_order_does_not_change_the_hash` test caught.
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import type { HttpRequest } from "@yaakapp-internal/models";
|
||||||
|
import { patchModelById } from "@yaakapp-internal/models";
|
||||||
|
import { activeWorkspaceIdAtom } from "../hooks/useActiveWorkspace";
|
||||||
|
import { createFastMutation } from "../hooks/useFastMutation";
|
||||||
|
import { wasUpdatedExternally } from "../hooks/useRequestUpdateKey";
|
||||||
|
import { createRequestAndNavigate } from "../lib/createRequestAndNavigate";
|
||||||
|
import { jotaiStore } from "../lib/jotai";
|
||||||
|
import { rpc } from "../lib/rpc";
|
||||||
|
import { showToast } from "../lib/toast";
|
||||||
|
|
||||||
|
export function looksLikeCurl(text: string) {
|
||||||
|
return text.trim().startsWith("curl ");
|
||||||
|
}
|
||||||
|
|
||||||
|
export const importCurl = createFastMutation<
|
||||||
|
void,
|
||||||
|
string,
|
||||||
|
{ overwriteRequestId?: string; command: string }
|
||||||
|
>({
|
||||||
|
mutationKey: ["import_curl"],
|
||||||
|
mutationFn: async ({ overwriteRequestId, command }) => {
|
||||||
|
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
||||||
|
const importedRequest: HttpRequest = await rpc("cmd_curl_to_request", {
|
||||||
|
command,
|
||||||
|
workspaceId,
|
||||||
|
});
|
||||||
|
|
||||||
|
let verb: string;
|
||||||
|
if (overwriteRequestId == null) {
|
||||||
|
verb = "Created";
|
||||||
|
await createRequestAndNavigate(importedRequest);
|
||||||
|
} else {
|
||||||
|
verb = "Updated";
|
||||||
|
await patchModelById(importedRequest.model, overwriteRequestId, (r: HttpRequest) => ({
|
||||||
|
...importedRequest,
|
||||||
|
id: r.id,
|
||||||
|
createdAt: r.createdAt,
|
||||||
|
workspaceId: r.workspaceId,
|
||||||
|
folderId: r.folderId,
|
||||||
|
name: r.name,
|
||||||
|
sortPriority: r.sortPriority,
|
||||||
|
}));
|
||||||
|
|
||||||
|
setTimeout(() => wasUpdatedExternally(overwriteRequestId), 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
showToast({
|
||||||
|
color: "success",
|
||||||
|
message: `${verb} request from Curl`,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -1,26 +1,44 @@
|
|||||||
import type { SettingsTab } from "../components/Settings/Settings";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
import type { SettingsTab, SettingsTabWithSubtab } from "../components/Settings/Settings";
|
||||||
import { activeWorkspaceIdAtom } from "../hooks/useActiveWorkspace";
|
import { activeWorkspaceIdAtom } from "../hooks/useActiveWorkspace";
|
||||||
import { createFastMutation } from "../hooks/useFastMutation";
|
import { createFastMutation } from "../hooks/useFastMutation";
|
||||||
|
import { showDialog } from "../lib/dialog";
|
||||||
import { jotaiStore } from "../lib/jotai";
|
import { jotaiStore } from "../lib/jotai";
|
||||||
import { router } from "../lib/router";
|
import { router } from "../lib/router";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
|
|
||||||
// Allow tab with optional subtab (e.g., "plugins:installed")
|
export const openSettings = createFastMutation<void, string, SettingsTabWithSubtab | null>({
|
||||||
type SettingsTabWithSubtab = SettingsTab | `${SettingsTab}:${string}` | null;
|
|
||||||
|
|
||||||
export const openSettings = createFastMutation<void, string, SettingsTabWithSubtab>({
|
|
||||||
mutationKey: ["open_settings"],
|
mutationKey: ["open_settings"],
|
||||||
mutationFn: async (tab) => {
|
mutationFn: async (tab) => {
|
||||||
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
||||||
if (workspaceId == null) return;
|
if (workspaceId == null) return;
|
||||||
|
|
||||||
|
// Settings is its own window where the host has windows to give. Where it
|
||||||
|
// doesn't — a browser tab — it's a dialog like any other, so opening it
|
||||||
|
// doesn't take you away from the request you were working on.
|
||||||
|
if (!platform.capabilities.multiWindow) {
|
||||||
|
// Imported here so Settings stays out of the startup bundle, the way the
|
||||||
|
// route that renders it on desktop already keeps it
|
||||||
|
const { default: Settings } = await import("../components/Settings/Settings");
|
||||||
|
showDialog({
|
||||||
|
id: "settings",
|
||||||
|
size: "md",
|
||||||
|
className: "h-[calc(100vh-5rem)] max-h-150! overflow-hidden",
|
||||||
|
noPadding: true,
|
||||||
|
noScroll: true,
|
||||||
|
// Keyed so opening a specific tab while the dialog is already up moves to it
|
||||||
|
render: ({ hide }) => <Settings key={tab ?? "general"} tab={tab} hide={hide} />,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const location = router.buildLocation({
|
const location = router.buildLocation({
|
||||||
to: "/workspaces/$workspaceId/settings",
|
to: "/workspaces/$workspaceId/settings",
|
||||||
params: { workspaceId },
|
params: { workspaceId },
|
||||||
search: { tab: (tab ?? undefined) as SettingsTab | undefined },
|
search: { tab: (tab ?? undefined) as SettingsTab | undefined },
|
||||||
});
|
});
|
||||||
|
|
||||||
await invokeCmd("cmd_new_child_window", {
|
await rpc("cmd_new_child_window", {
|
||||||
url: location.href,
|
url: location.href,
|
||||||
label: "settings",
|
label: "settings",
|
||||||
title: "Yaak Settings",
|
title: "Yaak Settings",
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import { createFastMutation } from "../hooks/useFastMutation";
|
import { createFastMutation } from "../hooks/useFastMutation";
|
||||||
import { getRecentCookieJars } from "../hooks/useRecentCookieJars";
|
import { getRecentCookieJars } from "../hooks/useRecentCookieJars";
|
||||||
import { getRecentEnvironments } from "../hooks/useRecentEnvironments";
|
import { getRecentEnvironments } from "../hooks/useRecentEnvironments";
|
||||||
import { getRecentRequests } from "../hooks/useRecentRequests";
|
import { getRecentRequests } from "../hooks/useRecentRequests";
|
||||||
import { router } from "../lib/router";
|
import { router } from "../lib/router";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
|
|
||||||
export const switchWorkspace = createFastMutation<
|
export const switchWorkspace = createFastMutation<
|
||||||
void,
|
void,
|
||||||
@@ -24,13 +25,15 @@ export const switchWorkspace = createFastMutation<
|
|||||||
request_id: requestId,
|
request_id: requestId,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (inNewWindow) {
|
// A host without windows opens the workspace here instead. Refusing would
|
||||||
|
// strand the user on the workspace they were trying to leave.
|
||||||
|
if (inNewWindow && platform.capabilities.multiWindow) {
|
||||||
const location = router.buildLocation({
|
const location = router.buildLocation({
|
||||||
to: "/workspaces/$workspaceId",
|
to: "/workspaces/$workspaceId",
|
||||||
params: { workspaceId },
|
params: { workspaceId },
|
||||||
search,
|
search,
|
||||||
});
|
});
|
||||||
await invokeCmd<void>("cmd_new_main_window", { url: location.href });
|
await rpc<void>("cmd_new_main_window", { url: location.href });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { open } from "@tauri-apps/plugin-dialog";
|
|
||||||
import { gitClone } from "@yaakapp-internal/git";
|
import { gitClone } from "@yaakapp-internal/git";
|
||||||
import { Banner, VStack } from "@yaakapp-internal/ui";
|
import { Banner, VStack } from "@yaakapp-internal/ui";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
@@ -11,6 +10,7 @@ import { Checkbox } from "./core/Checkbox";
|
|||||||
import { IconButton } from "./core/IconButton";
|
import { IconButton } from "./core/IconButton";
|
||||||
import { PlainInput } from "./core/PlainInput";
|
import { PlainInput } from "./core/PlainInput";
|
||||||
import { promptCredentials } from "./git/credentials";
|
import { promptCredentials } from "./git/credentials";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
hide: () => void;
|
hide: () => void;
|
||||||
@@ -38,7 +38,7 @@ export function CloneGitRepositoryDialog({ hide }: Props) {
|
|||||||
hasSubdirectory && subdirectory ? `${directory}${sep}${subdirectory}` : directory;
|
hasSubdirectory && subdirectory ? `${directory}${sep}${subdirectory}` : directory;
|
||||||
|
|
||||||
const handleSelectDirectory = async () => {
|
const handleSelectDirectory = async () => {
|
||||||
const dir = await open({
|
const dir = await platform.dialog.open({
|
||||||
title: "Select Directory",
|
title: "Select Directory",
|
||||||
directory: true,
|
directory: true,
|
||||||
multiple: false,
|
multiple: false,
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
import { checkLicense } from "@yaakapp-internal/license";
|
||||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
|
||||||
import type { LicenseCheckStatus } from "@yaakapp-internal/license";
|
|
||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { useKeyValue } from "../hooks/useKeyValue";
|
import { useKeyValue } from "../hooks/useKeyValue";
|
||||||
import { appInfo } from "../lib/appInfo";
|
import { appInfo } from "../lib/appInfo";
|
||||||
import { pricingUrl } from "../lib/pricingUrl";
|
import { pricingUrl } from "../lib/pricingUrl";
|
||||||
import { DismissibleBanner } from "./core/DismissibleBanner";
|
import { DismissibleBanner } from "./core/DismissibleBanner";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
const COMMERCIAL_USE_SNOOZE_MS = 7 * 24 * 60 * 60 * 1000;
|
const COMMERCIAL_USE_SNOOZE_MS = 7 * 24 * 60 * 60 * 1000;
|
||||||
const COMMERCIAL_USE_BANNER_MESSAGE =
|
const COMMERCIAL_USE_BANNER_MESSAGE =
|
||||||
@@ -95,7 +94,7 @@ async function shouldShowCommercialUsePrompt(): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const license = await invoke<LicenseCheckStatus>("plugin:yaak-license|check");
|
const license = await checkLicense();
|
||||||
return license.status === "personal_use";
|
return license.status === "personal_use";
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("Failed to check license before commercial-use prompt", err);
|
console.log("Failed to check license before commercial-use prompt", err);
|
||||||
@@ -104,7 +103,7 @@ async function shouldShowCommercialUsePrompt(): Promise<boolean> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function openCommercialUsePricing(source: string): Promise<void> {
|
async function openCommercialUsePricing(source: string): Promise<void> {
|
||||||
await openUrl(pricingUrl(`app.commercial-use.${source}`)).catch(console.error);
|
await platform.openUrl(pricingUrl(`app.commercial-use.${source}`)).catch(console.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSnoozed(value: string | null, ms: number): boolean {
|
function isSnoozed(value: string | null, ms: number): boolean {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { VStack } from "@yaakapp-internal/ui";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { router } from "../lib/router";
|
import { router } from "../lib/router";
|
||||||
import { setupOrConfigureEncryption } from "../lib/setupOrConfigureEncryption";
|
import { setupOrConfigureEncryption } from "../lib/setupOrConfigureEncryption";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { showErrorToast } from "../lib/toast";
|
import { showErrorToast } from "../lib/toast";
|
||||||
import { Button } from "./core/Button";
|
import { Button } from "./core/Button";
|
||||||
import { Checkbox } from "./core/Checkbox";
|
import { Checkbox } from "./core/Checkbox";
|
||||||
@@ -39,7 +39,7 @@ export function CreateWorkspaceDialog({ hide }: Props) {
|
|||||||
|
|
||||||
// Do getWorkspaceMeta instead of naively creating one because it might have
|
// Do getWorkspaceMeta instead of naively creating one because it might have
|
||||||
// been created already when the store refreshes the workspace meta after
|
// been created already when the store refreshes the workspace meta after
|
||||||
const workspaceMeta = await invokeCmd<WorkspaceMeta>("cmd_get_workspace_meta", {
|
const workspaceMeta = await rpc<WorkspaceMeta>("cmd_get_workspace_meta", {
|
||||||
workspaceId,
|
workspaceId,
|
||||||
});
|
});
|
||||||
await updateModel({
|
await updateModel({
|
||||||
|
|||||||
@@ -67,7 +67,14 @@ export const EnvironmentActionsDropdown = memo(function EnvironmentActionsDropdo
|
|||||||
)}
|
)}
|
||||||
// If no environments, the button simply opens the dialog.
|
// If no environments, the button simply opens the dialog.
|
||||||
// NOTE: We don't create a new button because we want to reuse the hotkey from the menu items
|
// NOTE: We don't create a new button because we want to reuse the hotkey from the menu items
|
||||||
onClick={subEnvironments.length === 0 ? () => editEnvironment(null) : undefined}
|
onClick={
|
||||||
|
subEnvironments.length === 0
|
||||||
|
? (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
editEnvironment(null);
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
{...buttonProps}
|
{...buttonProps}
|
||||||
>
|
>
|
||||||
<EnvironmentColorIndicator environment={activeEnvironment ?? null} />
|
<EnvironmentColorIndicator environment={activeEnvironment ?? null} />
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { save } from "@tauri-apps/plugin-dialog";
|
|
||||||
import type { Workspace } from "@yaakapp-internal/models";
|
import type { Workspace } from "@yaakapp-internal/models";
|
||||||
import { workspacesAtom } from "@yaakapp-internal/models";
|
import { workspacesAtom } from "@yaakapp-internal/models";
|
||||||
import { HStack, VStack } from "@yaakapp-internal/ui";
|
import { HStack, VStack } from "@yaakapp-internal/ui";
|
||||||
@@ -7,12 +6,13 @@ import { useCallback, useMemo, useState } from "react";
|
|||||||
import slugify from "slugify";
|
import slugify from "slugify";
|
||||||
import { activeWorkspaceAtom } from "../hooks/useActiveWorkspace";
|
import { activeWorkspaceAtom } from "../hooks/useActiveWorkspace";
|
||||||
import { pluralizeCount } from "../lib/pluralize";
|
import { pluralizeCount } from "../lib/pluralize";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { CommercialUseBanner } from "./CommercialUseBanner";
|
import { CommercialUseBanner } from "./CommercialUseBanner";
|
||||||
import { Button } from "./core/Button";
|
import { Button } from "./core/Button";
|
||||||
import { Checkbox } from "./core/Checkbox";
|
import { Checkbox } from "./core/Checkbox";
|
||||||
import { DetailsBanner } from "./core/DetailsBanner";
|
import { DetailsBanner } from "./core/DetailsBanner";
|
||||||
import { Link } from "./core/Link";
|
import { Link } from "./core/Link";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onHide: () => void;
|
onHide: () => void;
|
||||||
@@ -65,7 +65,7 @@ function ExportDataDialogContent({
|
|||||||
const ids = Object.keys(selectedWorkspaces).filter((k) => selectedWorkspaces[k]);
|
const ids = Object.keys(selectedWorkspaces).filter((k) => selectedWorkspaces[k]);
|
||||||
const workspace = ids.length === 1 ? workspaces.find((w) => w.id === ids[0]) : undefined;
|
const workspace = ids.length === 1 ? workspaces.find((w) => w.id === ids[0]) : undefined;
|
||||||
const slug = workspace ? slugify(workspace.name, { lower: true }) : "workspaces";
|
const slug = workspace ? slugify(workspace.name, { lower: true }) : "workspaces";
|
||||||
const exportPath = await save({
|
const exportPath = await platform.dialog.save({
|
||||||
title: "Export Data",
|
title: "Export Data",
|
||||||
defaultPath: `yaak.${slug}.json`,
|
defaultPath: `yaak.${slug}.json`,
|
||||||
});
|
});
|
||||||
@@ -73,7 +73,7 @@ function ExportDataDialogContent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await invokeCmd("cmd_export_data", {
|
await rpc("cmd_export_data", {
|
||||||
workspaceIds: ids,
|
workspaceIds: ids,
|
||||||
exportPath,
|
exportPath,
|
||||||
includePrivateEnvironments: includePrivateEnvironments,
|
includePrivateEnvironments: includePrivateEnvironments,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { HStack, VStack } from "@yaakapp-internal/ui";
|
|||||||
import { useRef, useState } from "react";
|
import { useRef, useState } from "react";
|
||||||
import type { FeedbackFeature } from "../lib/featureFeedbackConstants";
|
import type { FeedbackFeature } from "../lib/featureFeedbackConstants";
|
||||||
import { FEEDBACK_FEATURES } from "../lib/featureFeedbackConstants";
|
import { FEEDBACK_FEATURES } from "../lib/featureFeedbackConstants";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { hideToastById, showToast } from "../lib/toast";
|
import { hideToastById, showToast } from "../lib/toast";
|
||||||
import { Button } from "./core/Button";
|
import { Button } from "./core/Button";
|
||||||
import { Input } from "./core/Input";
|
import { Input } from "./core/Input";
|
||||||
@@ -31,7 +31,7 @@ export function FeedbackToast({ feature, onDone }: Props) {
|
|||||||
onDone();
|
onDone();
|
||||||
|
|
||||||
// Fire-and-forget; failures are intentionally ignored
|
// Fire-and-forget; failures are intentionally ignored
|
||||||
invokeCmd("cmd_send_feedback", { feature, text: trimmedText }).catch(() => {});
|
rpc("cmd_send_feedback", { feature, text: trimmedText }).catch(() => {});
|
||||||
showToast({
|
showToast({
|
||||||
id: `feature-feedback-${feature}`,
|
id: `feature-feedback-${feature}`,
|
||||||
timeout: 3000,
|
timeout: 3000,
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { linter } from "@codemirror/lint";
|
import { linter } from "@codemirror/lint";
|
||||||
import type { EditorView } from "@codemirror/view";
|
import type { EditorView } from "@codemirror/view";
|
||||||
import { jsoncLanguage } from "@shopify/lang-jsonc";
|
import { jsoncLanguage } from "@shopify/lang-jsonc";
|
||||||
import type { GrpcRequest } from "@yaakapp-internal/models";
|
import { type GrpcRequest, patchModel } from "@yaakapp-internal/models";
|
||||||
import { FormattedError, InlineCode, VStack } from "@yaakapp-internal/ui";
|
import { Banner, FormattedError, Icon, InlineCode, VStack } from "@yaakapp-internal/ui";
|
||||||
import classNames from "classnames";
|
|
||||||
import {
|
import {
|
||||||
handleRefresh,
|
handleRefresh,
|
||||||
jsonCompletion,
|
jsonCompletion,
|
||||||
@@ -11,12 +10,20 @@ import {
|
|||||||
stateExtensions,
|
stateExtensions,
|
||||||
updateSchema,
|
updateSchema,
|
||||||
} from "codemirror-json-schema";
|
} from "codemirror-json-schema";
|
||||||
|
import type { JSONSchema7 } from "json-schema";
|
||||||
|
import type { ReactNode } from "react";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import type { ReflectResponseService } from "../hooks/useGrpc";
|
import type { ReflectResponseService } from "../hooks/useGrpc";
|
||||||
|
import { wasUpdatedExternally } from "../hooks/useRequestUpdateKey";
|
||||||
import { showAlert } from "../lib/alert";
|
import { showAlert } from "../lib/alert";
|
||||||
|
import { showConfirm } from "../lib/confirm";
|
||||||
import { showDialog } from "../lib/dialog";
|
import { showDialog } from "../lib/dialog";
|
||||||
|
import type { JsonSchema } from "../lib/jsonSchemaExample";
|
||||||
|
import { buildExampleFromSchema } from "../lib/jsonSchemaExample";
|
||||||
import { pluralizeCount } from "../lib/pluralize";
|
import { pluralizeCount } from "../lib/pluralize";
|
||||||
|
import { queryClient } from "../lib/queryClient";
|
||||||
import { Button } from "./core/Button";
|
import { Button } from "./core/Button";
|
||||||
|
import { Dropdown } from "./core/Dropdown";
|
||||||
import type { EditorProps } from "./core/Editor/Editor";
|
import type { EditorProps } from "./core/Editor/Editor";
|
||||||
import { Editor } from "./core/Editor/LazyEditor";
|
import { Editor } from "./core/Editor/LazyEditor";
|
||||||
import { GrpcProtoSelectionDialog } from "./GrpcProtoSelectionDialog";
|
import { GrpcProtoSelectionDialog } from "./GrpcProtoSelectionDialog";
|
||||||
@@ -29,6 +36,11 @@ type Props = Pick<EditorProps, "heightMode" | "onChange" | "className" | "forceU
|
|||||||
protoFiles: string[];
|
protoFiles: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type MethodSchema =
|
||||||
|
| { type: "none" }
|
||||||
|
| { type: "schema"; schema: JsonSchema }
|
||||||
|
| { type: "error"; id: string; title: string; body: ReactNode; log: unknown[] };
|
||||||
|
|
||||||
export function GrpcEditor({
|
export function GrpcEditor({
|
||||||
services,
|
services,
|
||||||
reflectionError,
|
reflectionError,
|
||||||
@@ -42,21 +54,16 @@ export function GrpcEditor({
|
|||||||
setEditorView(h);
|
setEditorView(h);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Find the schema for the selected service and method and update the editor
|
// Find the schema for the selected service and method
|
||||||
useEffect(() => {
|
const methodSchema = useMemo<MethodSchema>(() => {
|
||||||
if (
|
if (services === null || request.service === null || request.method === null) {
|
||||||
editorView == null ||
|
return { type: "none" };
|
||||||
services === null ||
|
|
||||||
request.service === null ||
|
|
||||||
request.method === null
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const s = services.find((s) => s.name === request.service);
|
const s = services.find((s) => s.name === request.service);
|
||||||
if (s == null) {
|
if (s == null) {
|
||||||
console.log("Failed to find service", { service: request.service, services });
|
return {
|
||||||
showAlert({
|
type: "error",
|
||||||
id: "grpc-find-service-error",
|
id: "grpc-find-service-error",
|
||||||
title: "Couldn't Find Service",
|
title: "Couldn't Find Service",
|
||||||
body: (
|
body: (
|
||||||
@@ -64,14 +71,14 @@ export function GrpcEditor({
|
|||||||
Failed to find service <InlineCode>{request.service}</InlineCode> in schema
|
Failed to find service <InlineCode>{request.service}</InlineCode> in schema
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
});
|
log: ["Failed to find service", { service: request.service, services }],
|
||||||
return;
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = s.methods.find((m) => m.name === request.method)?.schema;
|
const schema = s.methods.find((m) => m.name === request.method)?.schema;
|
||||||
if (request.method != null && schema == null) {
|
if (schema == null) {
|
||||||
console.log("Failed to find method", { method: request.method, methods: s?.methods });
|
return {
|
||||||
showAlert({
|
type: "error",
|
||||||
id: "grpc-find-schema-error",
|
id: "grpc-find-schema-error",
|
||||||
title: "Couldn't Find Method",
|
title: "Couldn't Find Method",
|
||||||
body: (
|
body: (
|
||||||
@@ -80,18 +87,15 @@ export function GrpcEditor({
|
|||||||
<InlineCode>{request.service}</InlineCode> in schema
|
<InlineCode>{request.service}</InlineCode> in schema
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
});
|
log: ["Failed to find method", { method: request.method, methods: s.methods }],
|
||||||
return;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
if (schema == null) {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
updateSchema(editorView, JSON.parse(schema));
|
return { type: "schema", schema: JSON.parse(schema) as JsonSchema };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showAlert({
|
return {
|
||||||
|
type: "error",
|
||||||
id: "grpc-parse-schema-error",
|
id: "grpc-parse-schema-error",
|
||||||
title: "Failed to Parse Schema",
|
title: "Failed to Parse Schema",
|
||||||
body: (
|
body: (
|
||||||
@@ -103,9 +107,22 @@ export function GrpcEditor({
|
|||||||
<FormattedError>{String(err)}</FormattedError>
|
<FormattedError>{String(err)}</FormattedError>
|
||||||
</VStack>
|
</VStack>
|
||||||
),
|
),
|
||||||
});
|
log: ["Failed to parse schema", err],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}, [editorView, services, request.method, request.service]);
|
}, [services, request.method, request.service]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (methodSchema.type !== "error") return;
|
||||||
|
console.log(...methodSchema.log);
|
||||||
|
showAlert({ id: methodSchema.id, title: methodSchema.title, body: methodSchema.body });
|
||||||
|
}, [methodSchema]);
|
||||||
|
|
||||||
|
// Update the editor whenever the schema changes
|
||||||
|
useEffect(() => {
|
||||||
|
if (editorView == null || methodSchema.type !== "schema") return;
|
||||||
|
updateSchema(editorView, methodSchema.schema as JSONSchema7);
|
||||||
|
}, [editorView, methodSchema]);
|
||||||
|
|
||||||
const extraExtensions = useMemo(
|
const extraExtensions = useMemo(
|
||||||
() => [
|
() => [
|
||||||
@@ -124,45 +141,145 @@ export function GrpcEditor({
|
|||||||
const reflectionUnavailable = reflectionError?.match(/unimplemented/i);
|
const reflectionUnavailable = reflectionError?.match(/unimplemented/i);
|
||||||
reflectionError = reflectionUnavailable ? undefined : reflectionError;
|
reflectionError = reflectionUnavailable ? undefined : reflectionError;
|
||||||
|
|
||||||
|
const handleGenerateExample = useCallback(async () => {
|
||||||
|
if (methodSchema.type !== "schema") return;
|
||||||
|
|
||||||
|
if (request.message.trim() !== "") {
|
||||||
|
const confirmed = await showConfirm({
|
||||||
|
id: "grpc-generate-example",
|
||||||
|
title: "Generate Example",
|
||||||
|
description: "The current message will be replaced with an example.",
|
||||||
|
confirmText: "Generate",
|
||||||
|
});
|
||||||
|
if (!confirmed) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const message = JSON.stringify(buildExampleFromSchema(methodSchema.schema), null, 2);
|
||||||
|
await patchModel(request, { message });
|
||||||
|
|
||||||
|
// Force the editor to pick up the new message
|
||||||
|
wasUpdatedExternally(request.id);
|
||||||
|
}, [methodSchema, request]);
|
||||||
|
|
||||||
|
// The reflect query is keyed by request, url and proto files, so a prefix invalidate
|
||||||
|
// reaches it without threading a refetch down from the connection layout.
|
||||||
|
const handleReloadSchema = useCallback(
|
||||||
|
() => queryClient.invalidateQueries({ queryKey: ["grpc_reflect", request.id] }),
|
||||||
|
[request.id],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleShowReflectionError = useCallback(() => {
|
||||||
|
showDialog({
|
||||||
|
id: "grpc-reflection-error",
|
||||||
|
title: "Reflection Failed",
|
||||||
|
size: "sm",
|
||||||
|
render: ({ hide }) => (
|
||||||
|
<>
|
||||||
|
<FormattedError>{reflectionError ?? "unknown"}</FormattedError>
|
||||||
|
<div className="w-full my-4">
|
||||||
|
<Button
|
||||||
|
className="ml-auto"
|
||||||
|
color="primary"
|
||||||
|
size="sm"
|
||||||
|
onClick={async () => {
|
||||||
|
hide();
|
||||||
|
await handleReloadSchema();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}, [handleReloadSchema, reflectionError]);
|
||||||
|
|
||||||
const actions = useMemo(
|
const actions = useMemo(
|
||||||
() => [
|
() => [
|
||||||
<div key="reflection" className={classNames(services == null && "opacity-100!")}>
|
// Matches the GraphQL editor: one always-visible control labelled by schema state,
|
||||||
<Button
|
// with everything schema-related behind it.
|
||||||
size="xs"
|
<div key="schema" className="opacity-100!">
|
||||||
color={
|
<Dropdown
|
||||||
reflectionLoading
|
items={[
|
||||||
? "secondary"
|
{
|
||||||
: reflectionUnavailable
|
// Hidden for servers without reflection, which isn't an error
|
||||||
? "info"
|
hidden: !reflectionError,
|
||||||
: reflectionError
|
type: "content",
|
||||||
? "danger"
|
label: (
|
||||||
: "secondary"
|
<Banner color="danger">
|
||||||
}
|
<p className="mb-1">Reflection failed</p>
|
||||||
isLoading={reflectionLoading}
|
<Button
|
||||||
onClick={() => {
|
size="xs"
|
||||||
showDialog({
|
color="danger"
|
||||||
title: "Configure Schema",
|
variant="border"
|
||||||
size: "md",
|
onClick={handleShowReflectionError}
|
||||||
id: "reflection-failed",
|
>
|
||||||
render: ({ hide }) => <GrpcProtoSelectionDialog onDone={hide} />,
|
View Error
|
||||||
});
|
</Button>
|
||||||
}}
|
</Banner>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Generate Example Message",
|
||||||
|
leftSlot: <Icon icon="magic_wand" />,
|
||||||
|
disabled: methodSchema.type !== "schema",
|
||||||
|
onSelect: handleGenerateExample,
|
||||||
|
},
|
||||||
|
{ type: "separator" },
|
||||||
|
{
|
||||||
|
label: "Reload Schema",
|
||||||
|
leftSlot: <Icon icon="refresh" spin={reflectionLoading} />,
|
||||||
|
keepOpenOnSelect: true,
|
||||||
|
onSelect: handleReloadSchema,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: protoFiles.length > 0 ? "Select Proto Files\u2026" : "Configure Schema\u2026",
|
||||||
|
leftSlot: <Icon icon="settings" />,
|
||||||
|
onSelect: () => {
|
||||||
|
showDialog({
|
||||||
|
title: "Configure Schema",
|
||||||
|
size: "md",
|
||||||
|
id: "grpc-configure-schema",
|
||||||
|
render: ({ hide }) => <GrpcProtoSelectionDialog onDone={hide} />,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
>
|
>
|
||||||
{reflectionLoading
|
<Button
|
||||||
? "Inspecting Schema"
|
size="sm"
|
||||||
: reflectionUnavailable
|
variant="border"
|
||||||
? "Select Proto Files"
|
title="Schema"
|
||||||
: reflectionError
|
forDropdown
|
||||||
? "Server Error"
|
isLoading={reflectionLoading}
|
||||||
: protoFiles.length > 0
|
color={reflectionUnavailable ? "info" : reflectionError ? "danger" : "default"}
|
||||||
? pluralizeCount("File", protoFiles.length)
|
>
|
||||||
: services != null && protoFiles.length === 0
|
{reflectionLoading
|
||||||
? "Schema Detected"
|
? "Inspecting Schema"
|
||||||
: "Select Schema"}
|
: reflectionUnavailable
|
||||||
</Button>
|
? "Select Proto Files"
|
||||||
|
: reflectionError
|
||||||
|
? "Server Error"
|
||||||
|
: protoFiles.length > 0
|
||||||
|
? pluralizeCount("File", protoFiles.length)
|
||||||
|
: services != null
|
||||||
|
? "Schema Detected"
|
||||||
|
: "Select Schema"}
|
||||||
|
</Button>
|
||||||
|
</Dropdown>
|
||||||
</div>,
|
</div>,
|
||||||
],
|
],
|
||||||
[protoFiles.length, reflectionError, reflectionLoading, reflectionUnavailable, services],
|
[
|
||||||
|
handleGenerateExample,
|
||||||
|
handleReloadSchema,
|
||||||
|
handleShowReflectionError,
|
||||||
|
methodSchema.type,
|
||||||
|
protoFiles.length,
|
||||||
|
reflectionError,
|
||||||
|
reflectionLoading,
|
||||||
|
reflectionUnavailable,
|
||||||
|
services,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { open } from "@tauri-apps/plugin-dialog";
|
|
||||||
import type { GrpcRequest } from "@yaakapp-internal/models";
|
import type { GrpcRequest } from "@yaakapp-internal/models";
|
||||||
import { Banner, HStack, Icon, InlineCode, VStack } from "@yaakapp-internal/ui";
|
import { Banner, HStack, Icon, InlineCode, VStack } from "@yaakapp-internal/ui";
|
||||||
import { useActiveRequest } from "../hooks/useActiveRequest";
|
import { useActiveRequest } from "../hooks/useActiveRequest";
|
||||||
@@ -8,6 +7,7 @@ import { pluralizeCount } from "../lib/pluralize";
|
|||||||
import { Button } from "./core/Button";
|
import { Button } from "./core/Button";
|
||||||
import { IconButton } from "./core/IconButton";
|
import { IconButton } from "./core/IconButton";
|
||||||
import { Link } from "./core/Link";
|
import { Link } from "./core/Link";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onDone: () => void;
|
onDone: () => void;
|
||||||
@@ -45,7 +45,7 @@ function GrpcProtoSelectionDialogWithRequest({ request }: Props & { request: Grp
|
|||||||
color="primary"
|
color="primary"
|
||||||
variant="border"
|
variant="border"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const selected = await open({
|
const selected = await platform.dialog.open({
|
||||||
title: "Select Proto Files",
|
title: "Select Proto Files",
|
||||||
multiple: true,
|
multiple: true,
|
||||||
filters: [{ name: "Proto Files", extensions: ["proto"] }],
|
filters: [{ name: "Proto Files", extensions: ["proto"] }],
|
||||||
@@ -63,7 +63,7 @@ function GrpcProtoSelectionDialogWithRequest({ request }: Props & { request: Grp
|
|||||||
variant="border"
|
variant="border"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const selected = await open({
|
const selected = await platform.dialog.open({
|
||||||
title: "Select Proto Directory",
|
title: "Select Proto Directory",
|
||||||
directory: true,
|
directory: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -194,13 +194,6 @@ export function GrpcRequestPane({
|
|||||||
type: "default",
|
type: "default",
|
||||||
shortLabel: o.label,
|
shortLabel: o.label,
|
||||||
}))}
|
}))}
|
||||||
itemsAfter={[
|
|
||||||
{
|
|
||||||
label: "Refresh",
|
|
||||||
type: "default",
|
|
||||||
leftSlot: <Icon size="sm" icon="refresh" />,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
size="sm"
|
size="sm"
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import classNames from "classnames";
|
|||||||
import { atom, useAtomValue } from "jotai";
|
import { atom, useAtomValue } from "jotai";
|
||||||
import type { CSSProperties } from "react";
|
import type { CSSProperties } from "react";
|
||||||
import { lazy, Suspense, useCallback, useMemo, useRef, useState } from "react";
|
import { lazy, Suspense, useCallback, useMemo, useRef, useState } from "react";
|
||||||
|
import { importCurl, looksLikeCurl } from "../commands/importCurl";
|
||||||
import { allRequestUrlsAtom } from "../hooks/useAllRequests";
|
import { allRequestUrlsAtom } from "../hooks/useAllRequests";
|
||||||
import { useAuthTab } from "../hooks/useAuthTab";
|
import { useAuthTab } from "../hooks/useAuthTab";
|
||||||
import { useCancelHttpResponse } from "../hooks/useCancelHttpResponse";
|
import { useCancelHttpResponse } from "../hooks/useCancelHttpResponse";
|
||||||
import { useHeadersTab } from "../hooks/useHeadersTab";
|
import { useHeadersTab } from "../hooks/useHeadersTab";
|
||||||
import { useImportCurl } from "../hooks/useImportCurl";
|
|
||||||
import { useInheritedHeaders } from "../hooks/useInheritedHeaders";
|
import { useInheritedHeaders } from "../hooks/useInheritedHeaders";
|
||||||
import { usePinnedHttpResponse } from "../hooks/usePinnedHttpResponse";
|
import { usePinnedHttpResponse } from "../hooks/usePinnedHttpResponse";
|
||||||
import { useRequestEditor, useRequestEditorEvent } from "../hooks/useRequestEditor";
|
import { useRequestEditor, useRequestEditorEvent } from "../hooks/useRequestEditor";
|
||||||
@@ -278,7 +278,6 @@ export function HttpRequestPane({ style, fullHeight, className, activeRequest }:
|
|||||||
const { activeResponse } = usePinnedHttpResponse(activeRequestId);
|
const { activeResponse } = usePinnedHttpResponse(activeRequestId);
|
||||||
const { mutate: cancelResponse } = useCancelHttpResponse(activeResponse?.id ?? null);
|
const { mutate: cancelResponse } = useCancelHttpResponse(activeResponse?.id ?? null);
|
||||||
const updateKey = useRequestUpdateKey(activeRequestId);
|
const updateKey = useRequestUpdateKey(activeRequestId);
|
||||||
const { mutate: importCurl } = useImportCurl();
|
|
||||||
|
|
||||||
const handleBodyChange = useCallback(
|
const handleBodyChange = useCallback(
|
||||||
(body: HttpRequest["body"]) => patchModelDebounced(activeRequest, { body }),
|
(body: HttpRequest["body"]) => patchModelDebounced(activeRequest, { body }),
|
||||||
@@ -299,8 +298,8 @@ export function HttpRequestPane({ style, fullHeight, className, activeRequest }:
|
|||||||
|
|
||||||
const handlePaste = useCallback(
|
const handlePaste = useCallback(
|
||||||
async (e: ClipboardEvent, text: string) => {
|
async (e: ClipboardEvent, text: string) => {
|
||||||
if (text.startsWith("curl ")) {
|
if (looksLikeCurl(text)) {
|
||||||
importCurl({ overwriteRequestId: activeRequestId, command: text });
|
importCurl.mutate({ overwriteRequestId: activeRequestId, command: text });
|
||||||
} else {
|
} else {
|
||||||
const patch = prepareImportQuerystring(text);
|
const patch = prepareImportQuerystring(text);
|
||||||
if (patch != null) {
|
if (patch != null) {
|
||||||
@@ -322,7 +321,7 @@ export function HttpRequestPane({ style, fullHeight, className, activeRequest }:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[activeRequest, activeRequestId, forceParamsRefresh, forceUrlRefresh, importCurl],
|
[activeRequest, activeRequestId, forceParamsRefresh, forceUrlRefresh],
|
||||||
);
|
);
|
||||||
const handleSend = useCallback(
|
const handleSend = useCallback(
|
||||||
() => sendRequest(activeRequest.id ?? null),
|
() => sendRequest(activeRequest.id ?? null),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { useCopyHttpResponse } from "../hooks/useCopyHttpResponse";
|
|||||||
import { useHttpResponseEvents } from "../hooks/useHttpResponseEvents";
|
import { useHttpResponseEvents } from "../hooks/useHttpResponseEvents";
|
||||||
import { usePinnedHttpResponse } from "../hooks/usePinnedHttpResponse";
|
import { usePinnedHttpResponse } from "../hooks/usePinnedHttpResponse";
|
||||||
import { useResponseBodyBytes, useResponseBodyText } from "../hooks/useResponseBodyText";
|
import { useResponseBodyBytes, useResponseBodyText } from "../hooks/useResponseBodyText";
|
||||||
|
import { useResponseBodyUrl } from "../hooks/useResponseBodyUrl";
|
||||||
import { useResponseViewMode } from "../hooks/useResponseViewMode";
|
import { useResponseViewMode } from "../hooks/useResponseViewMode";
|
||||||
import { useSaveResponse } from "../hooks/useSaveResponse";
|
import { useSaveResponse } from "../hooks/useSaveResponse";
|
||||||
import { useTimelineViewMode } from "../hooks/useTimelineViewMode";
|
import { useTimelineViewMode } from "../hooks/useTimelineViewMode";
|
||||||
@@ -29,6 +30,7 @@ import { EmptyStateText } from "./EmptyStateText";
|
|||||||
import { ErrorBoundary } from "./ErrorBoundary";
|
import { ErrorBoundary } from "./ErrorBoundary";
|
||||||
import { HttpResponseTimeline } from "./HttpResponseTimeline";
|
import { HttpResponseTimeline } from "./HttpResponseTimeline";
|
||||||
import { RecentHttpResponsesDropdown } from "./RecentHttpResponsesDropdown";
|
import { RecentHttpResponsesDropdown } from "./RecentHttpResponsesDropdown";
|
||||||
|
import { RequestVersionDropdown } from "./RequestVersionDropdown";
|
||||||
import { RequestBodyViewer } from "./RequestBodyViewer";
|
import { RequestBodyViewer } from "./RequestBodyViewer";
|
||||||
import { ResponseCookies } from "./ResponseCookies";
|
import { ResponseCookies } from "./ResponseCookies";
|
||||||
import { ResponseHeaders } from "./ResponseHeaders";
|
import { ResponseHeaders } from "./ResponseHeaders";
|
||||||
@@ -262,13 +264,14 @@ export function HttpResponsePane({ style, className, activeRequestId }: Props) {
|
|||||||
) : (
|
) : (
|
||||||
<span />
|
<span />
|
||||||
)}
|
)}
|
||||||
<div className="justify-self-end shrink-0">
|
<HStack space={1} className="justify-self-end shrink-0">
|
||||||
|
<RequestVersionDropdown response={activeResponse} />
|
||||||
<RecentHttpResponsesDropdown
|
<RecentHttpResponsesDropdown
|
||||||
responses={responses}
|
responses={responses}
|
||||||
activeResponse={activeResponse}
|
activeResponse={activeResponse}
|
||||||
onPinnedResponseId={setPinnedResponseId}
|
onPinnedResponseId={setPinnedResponseId}
|
||||||
/>
|
/>
|
||||||
</div>
|
</HStack>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</HStack>
|
</HStack>
|
||||||
@@ -409,14 +412,13 @@ function EnsureCompleteResponse({
|
|||||||
Component,
|
Component,
|
||||||
}: {
|
}: {
|
||||||
response: HttpResponse;
|
response: HttpResponse;
|
||||||
Component: ComponentType<{ bodyPath: string }>;
|
Component: ComponentType<{ bodyUrl: string }>;
|
||||||
}) {
|
}) {
|
||||||
if (response.bodyPath === null) {
|
// Wait until the response has been fully-downloaded before asking for it
|
||||||
return <div>Empty response body</div>;
|
const complete = response.state === "closed";
|
||||||
}
|
const bodyUrl = useResponseBodyUrl(complete ? response : null);
|
||||||
|
|
||||||
// Wait until the response has been fully-downloaded
|
if (!complete || bodyUrl.isPending) {
|
||||||
if (response.state !== "closed") {
|
|
||||||
return (
|
return (
|
||||||
<EmptyStateText>
|
<EmptyStateText>
|
||||||
<LoadingIcon />
|
<LoadingIcon />
|
||||||
@@ -424,7 +426,15 @@ function EnsureCompleteResponse({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Component bodyPath={response.bodyPath} />;
|
if (bodyUrl.error) {
|
||||||
|
return <Banner color="danger">{String(bodyUrl.error)}</Banner>;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bodyUrl.data == null) {
|
||||||
|
return <div>Empty response body</div>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Component bodyUrl={bodyUrl.data} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
function HttpSvgViewer({ response }: { response: HttpResponse }) {
|
function HttpSvgViewer({ response }: { response: HttpResponse }) {
|
||||||
|
|||||||
@@ -0,0 +1,112 @@
|
|||||||
|
import { platform, useCapability } from "@yaakapp-internal/platform";
|
||||||
|
import { Icon } from "@yaakapp-internal/ui";
|
||||||
|
import * as m from "motion/react-m";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { importCurl, looksLikeCurl } from "../commands/importCurl";
|
||||||
|
import { useWindowFocus } from "../hooks/useWindowFocus";
|
||||||
|
import { showToast } from "../lib/toast";
|
||||||
|
import { Button } from "./core/Button";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offers to create a request from a Curl command on the clipboard. A host that can read
|
||||||
|
* the clipboard on its own offers it whenever the window is focused; one that would have
|
||||||
|
* to prompt for permission first waits for the user to paste instead.
|
||||||
|
*/
|
||||||
|
export function ImportCurl() {
|
||||||
|
return useCapability("clipboardRead") ? <ImportCurlButton /> : <ImportCurlOnPaste />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function ImportCurlButton() {
|
||||||
|
const focused = useWindowFocus();
|
||||||
|
const [clipboardText, setClipboardText] = useState("");
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
// oxlint-disable-next-line react-hooks/exhaustive-deps -- none
|
||||||
|
useEffect(() => {
|
||||||
|
void platform.clipboard.readText().then(setClipboardText);
|
||||||
|
}, [focused]);
|
||||||
|
|
||||||
|
if (!looksLikeCurl(clipboardText)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<m.div
|
||||||
|
initial={{ opacity: 0, scale: 0 }}
|
||||||
|
animate={{ opacity: 1, scale: 1 }}
|
||||||
|
transition={{ delay: 0.5 }}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
size="2xs"
|
||||||
|
variant="border"
|
||||||
|
color="success"
|
||||||
|
className="rounded-full"
|
||||||
|
rightSlot={<Icon icon="import" size="sm" />}
|
||||||
|
isLoading={isLoading}
|
||||||
|
title="Import Curl command from clipboard"
|
||||||
|
onClick={async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
await importCurl.mutateAsync({ command: clipboardText });
|
||||||
|
setClipboardText(""); // Hide the button until the clipboard changes
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Failed to import curl", e);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Import Curl
|
||||||
|
</Button>
|
||||||
|
</m.div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ImportCurlOnPaste() {
|
||||||
|
useEffect(() => {
|
||||||
|
const handlePaste = (e: ClipboardEvent) => {
|
||||||
|
const command = e.clipboardData?.getData("text/plain") ?? "";
|
||||||
|
if (!looksLikeCurl(command)) return;
|
||||||
|
|
||||||
|
// Editable targets keep the text as text. The URL editor imports it itself.
|
||||||
|
if (isEditable(e.target)) return;
|
||||||
|
|
||||||
|
showToast({
|
||||||
|
id: "curl-paste",
|
||||||
|
color: "success",
|
||||||
|
message: (
|
||||||
|
<div>
|
||||||
|
<h2 className="font-semibold">Curl command detected</h2>
|
||||||
|
<p className="text-text-subtle text-sm">Create a request from the pasted command?</p>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
action: ({ hide }) => (
|
||||||
|
<Button
|
||||||
|
size="xs"
|
||||||
|
color="success"
|
||||||
|
className="mr-auto min-w-20"
|
||||||
|
rightSlot={<Icon icon="import" size="sm" />}
|
||||||
|
onClick={() => {
|
||||||
|
hide();
|
||||||
|
importCurl.mutate({ command });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Create Request
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
document.addEventListener("paste", handlePaste);
|
||||||
|
return () => document.removeEventListener("paste", handlePaste);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEditable(target: EventTarget | null) {
|
||||||
|
if (!(target instanceof HTMLElement)) return false;
|
||||||
|
if (target.isContentEditable) return true;
|
||||||
|
if (target.closest(".cm-editor") != null) return true;
|
||||||
|
return ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName);
|
||||||
|
}
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
import { clear, readText } from "@tauri-apps/plugin-clipboard-manager";
|
|
||||||
import * as m from "motion/react-m";
|
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import { useImportCurl } from "../hooks/useImportCurl";
|
|
||||||
import { useWindowFocus } from "../hooks/useWindowFocus";
|
|
||||||
import { Button } from "./core/Button";
|
|
||||||
import { Icon } from "@yaakapp-internal/ui";
|
|
||||||
|
|
||||||
export function ImportCurlButton() {
|
|
||||||
const focused = useWindowFocus();
|
|
||||||
const [clipboardText, setClipboardText] = useState("");
|
|
||||||
|
|
||||||
const importCurl = useImportCurl();
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
|
||||||
|
|
||||||
// oxlint-disable-next-line react-hooks/exhaustive-deps -- none
|
|
||||||
useEffect(() => {
|
|
||||||
void readText().then(setClipboardText);
|
|
||||||
}, [focused]);
|
|
||||||
|
|
||||||
if (!clipboardText?.trim().startsWith("curl ")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<m.div
|
|
||||||
initial={{ opacity: 0, scale: 0 }}
|
|
||||||
animate={{ opacity: 1, scale: 1 }}
|
|
||||||
transition={{ delay: 0.5 }}
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
size="2xs"
|
|
||||||
variant="border"
|
|
||||||
color="success"
|
|
||||||
className="rounded-full"
|
|
||||||
rightSlot={<Icon icon="import" size="sm" />}
|
|
||||||
isLoading={isLoading}
|
|
||||||
title="Import Curl command from clipboard"
|
|
||||||
onClick={async () => {
|
|
||||||
setIsLoading(true);
|
|
||||||
try {
|
|
||||||
await importCurl.mutateAsync({ command: clipboardText });
|
|
||||||
await clear(); // Clear the clipboard so the button goes away
|
|
||||||
setClipboardText("");
|
|
||||||
} catch (e) {
|
|
||||||
console.log("Failed to import curl", e);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Import Curl
|
|
||||||
</Button>
|
|
||||||
</m.div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,57 +1,702 @@
|
|||||||
import { VStack } from "@yaakapp-internal/ui";
|
import {
|
||||||
import { useState } from "react";
|
type Folder,
|
||||||
import { useLocalStorage } from "react-use";
|
type ImportDestination,
|
||||||
|
type ImportPlan,
|
||||||
|
type ImportPlanItem,
|
||||||
|
type ImportSource,
|
||||||
|
type Workspace,
|
||||||
|
} from "@yaakapp-internal/models";
|
||||||
|
import { HStack, Icon, InlineCode, VStack } from "@yaakapp-internal/ui";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
import classNames from "classnames";
|
||||||
|
import { formatDistanceToNowStrict } from "date-fns";
|
||||||
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
import { pluralize } from "../lib/pluralize";
|
||||||
import { CommercialUseBanner } from "./CommercialUseBanner";
|
import { CommercialUseBanner } from "./CommercialUseBanner";
|
||||||
import { Button } from "./core/Button";
|
import { Button } from "./core/Button";
|
||||||
import { SelectFile } from "./SelectFile";
|
import { Checkbox } from "./core/Checkbox";
|
||||||
|
import type { CheckboxTreeNode } from "./core/CheckboxTree";
|
||||||
|
import { CheckboxTree } from "./core/CheckboxTree";
|
||||||
|
import { IconTooltip } from "./core/IconTooltip";
|
||||||
|
import { PlainInput } from "./core/PlainInput";
|
||||||
|
import { Select } from "./core/Select";
|
||||||
|
import { SegmentedControl } from "./core/SegmentedControl";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
importData: (filePath: string) => Promise<void>;
|
currentWorkspace: Workspace | null;
|
||||||
|
workspaces: Workspace[];
|
||||||
|
selectedFolder: Folder | null;
|
||||||
|
planFile: (filePath: string, destination: ImportDestination) => Promise<ImportPlan>;
|
||||||
|
planUrl: (url: string, destination: ImportDestination) => Promise<ImportPlan>;
|
||||||
|
listSources: (workspaceId: string) => Promise<ImportSource[]>;
|
||||||
|
findSourcesForOrigin: (args: { filePath?: string; url?: string }) => Promise<ImportSource[]>;
|
||||||
|
commit: (plan: ImportPlan) => Promise<void>;
|
||||||
|
cancel: () => void;
|
||||||
|
onError: (err: unknown) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ImportDataDialog({ importData }: Props) {
|
/**
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
* An absolute or relative path is unambiguously a file. Everything else is treated as a URL, so a
|
||||||
const [filePath, setFilePath] = useLocalStorage<string | null>("importFilePath", null);
|
* bare host like `example.com/openapi.json` still works (the backend defaults it to https).
|
||||||
|
*/
|
||||||
|
function isFilePath(value: string): boolean {
|
||||||
return (
|
return (
|
||||||
<VStack space={5} className="pb-4">
|
value.startsWith("/") ||
|
||||||
<CommercialUseBanner source="data-import" title="Importing work data?" />
|
value.startsWith("./") ||
|
||||||
|
value.startsWith("../") ||
|
||||||
|
value.startsWith("~/") ||
|
||||||
|
value.startsWith("\\\\") ||
|
||||||
|
/^[a-zA-Z]:[\\/]/.test(value)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
<VStack space={1}>
|
function fileName(path: string): string {
|
||||||
<ul className="list-disc pl-5">
|
return path.split(/[/\\]/).at(-1) || path;
|
||||||
<li>OpenAPI 3.0, 3.1</li>
|
}
|
||||||
<li>Postman Collection v2, v2.1</li>
|
|
||||||
<li>Insomnia v4+</li>
|
/**
|
||||||
<li>Swagger 2.0</li>
|
* Loads the current workspace's linked sources before rendering the dialog, so the inner
|
||||||
<li>
|
* component can construct its initial state (prefilled path, destination) in one pass instead of
|
||||||
Curl commands <em className="text-text-subtle">(or paste into URL)</em>
|
* patching it in with effects after the first paint.
|
||||||
</li>
|
*/
|
||||||
</ul>
|
export function ImportDataDialog(props: Props) {
|
||||||
</VStack>
|
const [initialSources, setInitialSources] = useState<ImportSource[] | null>(null);
|
||||||
<VStack space={2}>
|
const { currentWorkspace, listSources } = props;
|
||||||
<SelectFile
|
|
||||||
filePath={filePath ?? null}
|
useEffect(() => {
|
||||||
onChange={({ filePath }) => setFilePath(filePath)}
|
let cancelled = false;
|
||||||
/>
|
const load = currentWorkspace == null ? Promise.resolve([]) : listSources(currentWorkspace.id);
|
||||||
{filePath && (
|
load
|
||||||
|
.then((sources) => {
|
||||||
|
if (!cancelled) setInitialSources(sources);
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
if (!cancelled) setInitialSources([]);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [currentWorkspace, listSources]);
|
||||||
|
|
||||||
|
if (initialSources == null) return null;
|
||||||
|
return <LoadedImportDataDialog {...props} initialSources={initialSources} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function latestSource(sources: ImportSource[]): ImportSource | null {
|
||||||
|
return sources.reduce<ImportSource | null>(
|
||||||
|
(latest, s) => (latest == null || s.lastImportedAt > latest.lastImportedAt ? s : latest),
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function LoadedImportDataDialog({
|
||||||
|
currentWorkspace,
|
||||||
|
workspaces,
|
||||||
|
selectedFolder,
|
||||||
|
planFile,
|
||||||
|
planUrl,
|
||||||
|
listSources,
|
||||||
|
findSourcesForOrigin,
|
||||||
|
commit,
|
||||||
|
cancel,
|
||||||
|
onError,
|
||||||
|
initialSources,
|
||||||
|
}: Props & { initialSources: ImportSource[] }) {
|
||||||
|
// A workspace with a linked source is probably being re-imported, so start from that source
|
||||||
|
const prefill = latestSource(initialSources);
|
||||||
|
|
||||||
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
|
const [plan, setPlan] = useState<ImportPlan | null>(null);
|
||||||
|
const [items, setItems] = useState<ImportPlanItem[]>([]);
|
||||||
|
// null means no explicit choice yet, so the default below applies
|
||||||
|
const [destinationChoice, setDestinationChoice] = useState<"new" | "current" | "other" | null>(
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
const [otherWorkspaceId, setOtherWorkspaceId] = useState<string | null>(null);
|
||||||
|
const [targetSelectedFolder, setTargetSelectedFolder] = useState(selectedFolder != null);
|
||||||
|
const [linkedSources, setLinkedSources] = useState<ImportSource[]>(
|
||||||
|
prefill != null ? initialSources : [],
|
||||||
|
);
|
||||||
|
const [originSources, setOriginSources] = useState<ImportSource[]>(
|
||||||
|
prefill != null ? [prefill] : [],
|
||||||
|
);
|
||||||
|
// A file path or a URL. Both inputs write here, so there is only ever one thing to import
|
||||||
|
const [source, setSource] = useState<string | null>(prefill?.origin ?? null);
|
||||||
|
const [forceUpdateKey, setForceUpdateKey] = useState<number>(0);
|
||||||
|
const [isHovering, setIsHovering] = useState<boolean>(false);
|
||||||
|
const ref = useRef<HTMLDivElement>(null);
|
||||||
|
const trimmedSource = source?.trim() ?? "";
|
||||||
|
const filePath = isFilePath(trimmedSource) ? trimmedSource : null;
|
||||||
|
|
||||||
|
const selectSource = (value: string) => {
|
||||||
|
setSource(value);
|
||||||
|
// Remount the input so it shows the path of the newly-picked file
|
||||||
|
setForceUpdateKey((k) => k + 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Accept a file dropped anywhere on the dialog, the way SelectFile does for its button
|
||||||
|
useEffect(() => {
|
||||||
|
return platform.window.onDragDrop((event) => {
|
||||||
|
if (event.type === "over") {
|
||||||
|
const p = event.position;
|
||||||
|
const r = ref.current?.getBoundingClientRect();
|
||||||
|
if (r == null) return;
|
||||||
|
setIsHovering(p.x >= r.left && p.x <= r.right && p.y >= r.top && p.y <= r.bottom);
|
||||||
|
} else if (event.type === "drop" && isHovering) {
|
||||||
|
const p = event.paths[0];
|
||||||
|
if (p) selectSource(p);
|
||||||
|
setIsHovering(false);
|
||||||
|
} else {
|
||||||
|
setIsHovering(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, [isHovering, setSource]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (trimmedSource === "") {
|
||||||
|
setOriginSources([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let cancelled = false;
|
||||||
|
const timeout = setTimeout(() => {
|
||||||
|
findSourcesForOrigin(filePath != null ? { filePath } : { url: trimmedSource })
|
||||||
|
.then((sources) => {
|
||||||
|
if (!cancelled) setOriginSources(sources);
|
||||||
|
})
|
||||||
|
.catch(() => setOriginSources([]));
|
||||||
|
}, 300);
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
clearTimeout(timeout);
|
||||||
|
};
|
||||||
|
}, [trimmedSource, filePath, findSourcesForOrigin]);
|
||||||
|
|
||||||
|
// The one workspace this file is linked to, if there is exactly one.
|
||||||
|
const linkedWorkspace = useMemo(() => {
|
||||||
|
const ids = [...new Set(originSources.map((s) => s.workspaceId))];
|
||||||
|
if (ids.length !== 1) return null;
|
||||||
|
return workspaces.find((w) => w.id === ids[0]) ?? null;
|
||||||
|
}, [originSources, workspaces]);
|
||||||
|
|
||||||
|
// A file linked to the current workspace defaults back into it, so re-importing doesn't
|
||||||
|
// accidentally create a duplicate workspace. A file linked elsewhere only gets a suggestion —
|
||||||
|
// silently targeting a workspace that is neither new nor current is too surprising. An
|
||||||
|
// explicit choice always wins.
|
||||||
|
const destinationKind =
|
||||||
|
destinationChoice ??
|
||||||
|
(linkedWorkspace != null && linkedWorkspace.id === currentWorkspace?.id ? "current" : "new");
|
||||||
|
|
||||||
|
const destinationWorkspaceId =
|
||||||
|
destinationKind === "current"
|
||||||
|
? (currentWorkspace?.id ?? null)
|
||||||
|
: destinationKind === "other"
|
||||||
|
? otherWorkspaceId
|
||||||
|
: null;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (destinationWorkspaceId == null) {
|
||||||
|
setLinkedSources([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let cancelled = false;
|
||||||
|
listSources(destinationWorkspaceId)
|
||||||
|
.then((sources) => {
|
||||||
|
if (!cancelled) setLinkedSources(sources);
|
||||||
|
})
|
||||||
|
.catch(() => setLinkedSources([]));
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, [destinationWorkspaceId, listSources]);
|
||||||
|
|
||||||
|
const handleSelectFile = async () => {
|
||||||
|
const selected = await platform.dialog.open({ title: "Select File", multiple: false });
|
||||||
|
if (selected == null) return;
|
||||||
|
selectSource(selected);
|
||||||
|
};
|
||||||
|
|
||||||
|
// The selected folder belongs to the workspace being viewed, so it is only offerable when that
|
||||||
|
// is also the destination.
|
||||||
|
const canTargetSelectedFolder = selectedFolder != null && destinationKind === "current";
|
||||||
|
|
||||||
|
const destination = (): ImportDestination => {
|
||||||
|
if (destinationWorkspaceId == null) {
|
||||||
|
return { type: "new_workspace" };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
type: "existing_workspace",
|
||||||
|
workspaceId: destinationWorkspaceId,
|
||||||
|
folderId: canTargetSelectedFolder && targetSelectedFolder ? selectedFolder.id : undefined,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const handlePreview = async () => {
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
const nextPlan =
|
||||||
|
filePath != null
|
||||||
|
? await planFile(filePath, destination())
|
||||||
|
: await planUrl(trimmedSource, destination());
|
||||||
|
setPlan(nextPlan);
|
||||||
|
setItems(nextPlan.items);
|
||||||
|
} catch (err) {
|
||||||
|
onError(err);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCommit = async () => {
|
||||||
|
if (plan == null) return;
|
||||||
|
setIsLoading(true);
|
||||||
|
try {
|
||||||
|
await commit({ ...plan, items });
|
||||||
|
} catch (err) {
|
||||||
|
onError(err);
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const itemTree = useMemo(() => buildItemTree(items), [items]);
|
||||||
|
|
||||||
|
// A folder row's checkbox aggregates its subtree the way the git commit tree does: creates and
|
||||||
|
// updates toggle together, while removals only ever cascade beneath a removed folder.
|
||||||
|
const toggleNode = (node: CheckboxTreeNode<ImportPlanItem>, checked: boolean) => {
|
||||||
|
const targets = new Set(
|
||||||
|
collectItems(node)
|
||||||
|
.filter((i) => togglesWith(node.data, i))
|
||||||
|
.map((i) => i.modelId),
|
||||||
|
);
|
||||||
|
setItems((prev) => prev.map((i) => (targets.has(i.modelId) ? { ...i, selected: checked } : i)));
|
||||||
|
};
|
||||||
|
|
||||||
|
const resolveConflict = (modelId: string, resolution: "keep_mine" | "take_source") => {
|
||||||
|
setItems((prev) =>
|
||||||
|
prev.map((item) => (item.modelId === modelId ? { ...item, resolution } : item)),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// A row the user can't meaningfully toggle on its own: a planned resource inside a deselected
|
||||||
|
// new folder can't exist, and a removed folder takes its contents with it.
|
||||||
|
const disabledIds = useMemo(() => {
|
||||||
|
const disabled = new Set<string>();
|
||||||
|
const byId = new Map(items.map((i) => [i.modelId, i]));
|
||||||
|
for (const item of items) {
|
||||||
|
const seen = new Set<string>();
|
||||||
|
let parentId = item.parentId;
|
||||||
|
while (parentId != null && !seen.has(parentId)) {
|
||||||
|
seen.add(parentId);
|
||||||
|
const parent = byId.get(parentId);
|
||||||
|
if (parent == null || parent.model !== "folder") break;
|
||||||
|
if (parent.action === "create" && !parent.selected && item.action !== "delete") {
|
||||||
|
disabled.add(item.modelId);
|
||||||
|
}
|
||||||
|
if (parent.action === "delete" && parent.selected && item.action === "delete") {
|
||||||
|
disabled.add(item.modelId);
|
||||||
|
}
|
||||||
|
parentId = parent.parentId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return disabled;
|
||||||
|
}, [items]);
|
||||||
|
|
||||||
|
if (plan != null) {
|
||||||
|
const unchanged = items.filter((i) => i.action === "unchanged");
|
||||||
|
const footerNote =
|
||||||
|
unchanged.length > 0
|
||||||
|
? `${unchanged.length} ${pluralize("resource", unchanged.length)} unchanged`
|
||||||
|
: "";
|
||||||
|
const changeCount = items.filter((item) => {
|
||||||
|
if (disabledIds.has(item.modelId)) return false;
|
||||||
|
if (item.action === "conflict") return item.resolution === "take_source";
|
||||||
|
if (item.action === "unchanged") return false;
|
||||||
|
return item.selected;
|
||||||
|
}).length;
|
||||||
|
|
||||||
|
const destinationLabel = (() => {
|
||||||
|
if (plan.destination.type === "new_workspace") return "New workspace";
|
||||||
|
const { workspaceId, folderId } = plan.destination;
|
||||||
|
const name = workspaces.find((w) => w.id === workspaceId)?.name ?? "Unknown workspace";
|
||||||
|
return folderId != null && folderId === selectedFolder?.id
|
||||||
|
? `${name} / ${selectedFolder.name}`
|
||||||
|
: name;
|
||||||
|
})();
|
||||||
|
|
||||||
|
// The destination workspace roots the tree. It is not a plan item — commit always applies
|
||||||
|
// it — so its checkbox only aggregates the subtree.
|
||||||
|
const workspaceRoot: CheckboxTreeNode<ImportPlanItem> = (() => {
|
||||||
|
const planned = plan.resources.workspaces[0];
|
||||||
|
const planDestination = plan.destination;
|
||||||
|
const existing =
|
||||||
|
planDestination.type === "existing_workspace"
|
||||||
|
? workspaces.find((w) => w.id === planDestination.workspaceId)
|
||||||
|
: null;
|
||||||
|
return {
|
||||||
|
key: existing?.id ?? planned?.id ?? "workspace",
|
||||||
|
data: {
|
||||||
|
action: plan.destination.type === "new_workspace" ? "create" : "unchanged",
|
||||||
|
model: "workspace",
|
||||||
|
modelId: existing?.id ?? planned?.id ?? "workspace",
|
||||||
|
name: existing?.name ?? planned?.name ?? "New workspace",
|
||||||
|
selected: true,
|
||||||
|
},
|
||||||
|
children: itemTree,
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<VStack space={4} className="pb-4">
|
||||||
|
<div className="rounded-lg border border-border-subtle divide-y divide-border-subtle">
|
||||||
|
<PreviewRow label="Detected format" value={plan.importer} />
|
||||||
|
<PreviewRow label="Destination" value={destinationLabel} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="rounded-lg border border-border-subtle px-3 py-2 overflow-y-auto max-h-[40vh]">
|
||||||
|
<CheckboxTree
|
||||||
|
node={workspaceRoot}
|
||||||
|
checked={nodeCheckedStatus}
|
||||||
|
onCheck={toggleNode}
|
||||||
|
isCheckboxDisabled={(n) => disabledIds.has(n.key)}
|
||||||
|
isRelevant={(n) => n.data.model === "workspace" || n.data.action !== "unchanged"}
|
||||||
|
renderRow={(n) => <ImportTreeRow item={n.data} onResolveConflict={resolveConflict} />}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{plan.warnings.length > 0 && (
|
||||||
|
<div>
|
||||||
|
<div className="text-sm font-semibold mb-1">Import details</div>
|
||||||
|
<div className="rounded-lg border border-border-subtle divide-y divide-border-subtle">
|
||||||
|
{plan.warnings.map((warning) => (
|
||||||
|
<div
|
||||||
|
key={`${warning.title}:${warning.detail}`}
|
||||||
|
className="flex items-start gap-2.5 px-3 py-2.5"
|
||||||
|
>
|
||||||
|
<Icon icon="info" color="info" size="sm" className="mt-0.5" />
|
||||||
|
<div className="min-w-0">
|
||||||
|
<div className="text-sm font-medium">{warning.title}</div>
|
||||||
|
<div className="text-xs text-text-subtle mt-0.5">{warning.detail}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<HStack space={2} alignItems="center" className="mt-3">
|
||||||
|
{footerNote !== "" && <div className="text-xs text-text-subtle">{footerNote}</div>}
|
||||||
<Button
|
<Button
|
||||||
color="primary"
|
className="ml-auto"
|
||||||
disabled={!filePath || isLoading}
|
color="secondary"
|
||||||
isLoading={isLoading}
|
variant="border"
|
||||||
size="sm"
|
disabled={isLoading}
|
||||||
onClick={async () => {
|
onClick={() => {
|
||||||
setIsLoading(true);
|
setPlan(null);
|
||||||
try {
|
setItems([]);
|
||||||
await importData(filePath);
|
|
||||||
} finally {
|
|
||||||
setIsLoading(false);
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{isLoading ? "Importing" : "Import"}
|
Back
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button color="primary" isLoading={isLoading} onClick={handleCommit}>
|
||||||
|
{isLoading
|
||||||
|
? "Importing"
|
||||||
|
: changeCount > 0
|
||||||
|
? `Apply ${changeCount} ${changeCount === 1 ? "Change" : "Changes"}`
|
||||||
|
: "Apply"}
|
||||||
|
</Button>
|
||||||
|
</HStack>
|
||||||
|
</VStack>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const lastImported =
|
||||||
|
originSources.find((s) => s.workspaceId === destinationWorkspaceId) ??
|
||||||
|
linkedSources.reduce<ImportSource | null>(
|
||||||
|
(latest, s) => (latest == null || s.lastImportedAt > latest.lastImportedAt ? s : latest),
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<VStack ref={ref} space={4} className="pb-4">
|
||||||
|
<CommercialUseBanner source="data-import" title="Importing work data?" />
|
||||||
|
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleSelectFile}
|
||||||
|
className={classNames(
|
||||||
|
"w-full rounded-lg border border-dashed px-4 py-6",
|
||||||
|
"flex flex-col items-center gap-1 text-center",
|
||||||
|
isHovering
|
||||||
|
? "border-notice bg-surface-highlight"
|
||||||
|
: "border-border hover:border-text-subtle",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Icon icon="folder_input" className="text-text-subtlest w-8! h-8! mb-2" />
|
||||||
|
{/* Fixed height so the region doesn't resize between the empty and selected states */}
|
||||||
|
<div className="h-6 w-full flex items-center justify-center">
|
||||||
|
{filePath == null ? (
|
||||||
|
<div className="text-text">
|
||||||
|
<strong className="font-semibold">Choose a file</strong> or drag it here
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="text-text font-mono text-xs max-w-full truncate" title={filePath}>
|
||||||
|
{fileName(filePath)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="text-xs text-text-subtlest">
|
||||||
|
Supports OpenAPI, Swagger, Postman, Insomnia, and curl
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<PlainInput
|
||||||
|
label="Or enter a file path or URL"
|
||||||
|
size="sm"
|
||||||
|
placeholder="https://example.com/openapi.json"
|
||||||
|
defaultValue={source ?? ""}
|
||||||
|
forceUpdateKey={String(forceUpdateKey)}
|
||||||
|
onChange={setSource}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<VStack space={2}>
|
||||||
|
<Select
|
||||||
|
name="import-destination-kind"
|
||||||
|
label="Import location"
|
||||||
|
size="sm"
|
||||||
|
value={destinationKind}
|
||||||
|
onChange={setDestinationChoice}
|
||||||
|
options={[
|
||||||
|
{ value: "new", label: "New Workspace" },
|
||||||
|
...(currentWorkspace != null
|
||||||
|
? [{ value: "current" as const, label: "Current Workspace" }]
|
||||||
|
: []),
|
||||||
|
{ value: "other", label: "Other Workspace" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
{destinationKind === "other" && (
|
||||||
|
<Select
|
||||||
|
name="import-destination-workspace"
|
||||||
|
label="Workspace"
|
||||||
|
hideLabel
|
||||||
|
size="sm"
|
||||||
|
value={otherWorkspaceId ?? ""}
|
||||||
|
onChange={(id) => setOtherWorkspaceId(id === "" ? null : id)}
|
||||||
|
filterable
|
||||||
|
options={[
|
||||||
|
{ value: "", label: "Select a workspace" },
|
||||||
|
...workspaces
|
||||||
|
.filter((w) => w.id !== currentWorkspace?.id)
|
||||||
|
.map((w) => ({ value: w.id, label: w.name })),
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{lastImported != null && destinationWorkspaceId != null ? (
|
||||||
|
<div className="text-xs text-text-subtle">
|
||||||
|
Last imported from {lastImported.originLabel} ·{" "}
|
||||||
|
{formatDistanceToNowStrict(`${lastImported.lastImportedAt}Z`, { addSuffix: true })}
|
||||||
|
</div>
|
||||||
|
) : linkedWorkspace != null && linkedWorkspace.id !== destinationWorkspaceId ? (
|
||||||
|
<div className="text-xs text-text-subtle">
|
||||||
|
This file was last imported into{" "}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="underline hocus:text-text"
|
||||||
|
onClick={() => {
|
||||||
|
if (linkedWorkspace.id === currentWorkspace?.id) {
|
||||||
|
setDestinationChoice("current");
|
||||||
|
} else {
|
||||||
|
setDestinationChoice("other");
|
||||||
|
setOtherWorkspaceId(linkedWorkspace.id);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{linkedWorkspace.name}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{canTargetSelectedFolder && (
|
||||||
|
<Checkbox
|
||||||
|
checked={targetSelectedFolder}
|
||||||
|
title={`Place root resources in selected folder “${selectedFolder.name}”`}
|
||||||
|
onChange={setTargetSelectedFolder}
|
||||||
|
/>
|
||||||
)}
|
)}
|
||||||
</VStack>
|
</VStack>
|
||||||
|
|
||||||
|
<HStack space={2} justifyContent="end">
|
||||||
|
<Button color="secondary" variant="border" disabled={isLoading} onClick={cancel}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="primary"
|
||||||
|
disabled={
|
||||||
|
trimmedSource === "" ||
|
||||||
|
isLoading ||
|
||||||
|
(destinationKind === "other" && otherWorkspaceId == null)
|
||||||
|
}
|
||||||
|
isLoading={isLoading}
|
||||||
|
onClick={handlePreview}
|
||||||
|
>
|
||||||
|
{isLoading ? "Analyzing" : "Preview Import"}
|
||||||
|
</Button>
|
||||||
|
</HStack>
|
||||||
</VStack>
|
</VStack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ImportTreeRow({
|
||||||
|
item,
|
||||||
|
onResolveConflict,
|
||||||
|
}: {
|
||||||
|
item: ImportPlanItem;
|
||||||
|
onResolveConflict: (modelId: string, resolution: "keep_mine" | "take_source") => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{item.model === "workspace" || item.model === "folder" || item.model === "environment" ? (
|
||||||
|
<Icon
|
||||||
|
color="secondary"
|
||||||
|
icon={
|
||||||
|
item.model === "workspace" ? "house" : item.model === "folder" ? "folder" : "variable"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<span aria-hidden className="w-4" />
|
||||||
|
)}
|
||||||
|
<div className="truncate flex-1">{item.name}</div>
|
||||||
|
{item.action === "conflict" ? (
|
||||||
|
<div className="shrink-0 flex items-center gap-1.5">
|
||||||
|
<SegmentedControl
|
||||||
|
name={`conflict-${item.modelId}`}
|
||||||
|
label={`Resolve conflict for ${item.name}`}
|
||||||
|
hideLabel
|
||||||
|
value={item.resolution ?? "keep_mine"}
|
||||||
|
onChange={(v) => onResolveConflict(item.modelId, v)}
|
||||||
|
options={[
|
||||||
|
{ value: "keep_mine", label: "Keep mine" },
|
||||||
|
{ value: "take_source", label: "Take source" },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<IconTooltip content={actionHelp(item)} iconSize="sm" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
actionLabel(item) && (
|
||||||
|
<InlineCode
|
||||||
|
className={classNames(
|
||||||
|
"py-0 bg-transparent w-32 shrink-0 whitespace-nowrap text-xs",
|
||||||
|
"inline-flex items-center justify-center gap-1.5",
|
||||||
|
item.action === "create" && "text-success",
|
||||||
|
item.action === "update" && "text-info",
|
||||||
|
item.action === "delete" && "text-danger",
|
||||||
|
item.action === "keep_local" && item.selected && "text-warning",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{actionLabel(item)}
|
||||||
|
<IconTooltip content={actionHelp(item)} iconSize="xs" />
|
||||||
|
</InlineCode>
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function actionLabel(item: ImportPlanItem): string | null {
|
||||||
|
switch (item.action) {
|
||||||
|
case "create":
|
||||||
|
return "new";
|
||||||
|
case "update":
|
||||||
|
return "updated";
|
||||||
|
case "delete":
|
||||||
|
return "removed";
|
||||||
|
case "keep_local":
|
||||||
|
return "edited";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function actionHelp(item: ImportPlanItem): string | null {
|
||||||
|
switch (item.action) {
|
||||||
|
case "create":
|
||||||
|
return "Added since the last import";
|
||||||
|
case "update":
|
||||||
|
return "Changed since the last import";
|
||||||
|
case "delete":
|
||||||
|
return "Deleted since the last import";
|
||||||
|
case "keep_local":
|
||||||
|
return "Local edits made since the last import. Importing will revert them if checked";
|
||||||
|
case "conflict":
|
||||||
|
return "Changed both here and in the file since the last import";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildItemTree(items: ImportPlanItem[]): CheckboxTreeNode<ImportPlanItem>[] {
|
||||||
|
const byId = new Map(items.map((i) => [i.modelId, i]));
|
||||||
|
const childrenOf = new Map<string, ImportPlanItem[]>();
|
||||||
|
const roots: ImportPlanItem[] = [];
|
||||||
|
for (const item of items) {
|
||||||
|
if (item.parentId != null && byId.has(item.parentId)) {
|
||||||
|
const siblings = childrenOf.get(item.parentId) ?? [];
|
||||||
|
siblings.push(item);
|
||||||
|
childrenOf.set(item.parentId, siblings);
|
||||||
|
} else {
|
||||||
|
roots.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const foldersFirst = (list: ImportPlanItem[]) => [
|
||||||
|
...list.filter((i) => i.model === "folder"),
|
||||||
|
...list.filter((i) => i.model !== "folder"),
|
||||||
|
];
|
||||||
|
|
||||||
|
const toNode = (item: ImportPlanItem, seen: Set<string>): CheckboxTreeNode<ImportPlanItem> => ({
|
||||||
|
key: item.modelId,
|
||||||
|
data: item,
|
||||||
|
children: seen.has(item.modelId)
|
||||||
|
? []
|
||||||
|
: foldersFirst(childrenOf.get(item.modelId) ?? []).map((c) =>
|
||||||
|
toNode(c, new Set([...seen, item.modelId])),
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
return foldersFirst(roots).map((r) => toNode(r, new Set()));
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectItems(node: CheckboxTreeNode<ImportPlanItem>): ImportPlanItem[] {
|
||||||
|
return [node.data, ...node.children.flatMap(collectItems)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether toggling `root`'s checkbox also toggles `item` in its subtree. Destructive decisions
|
||||||
|
* (deletions, reverting local edits) never ride along with a parent toggle.
|
||||||
|
*/
|
||||||
|
function togglesWith(root: ImportPlanItem, item: ImportPlanItem): boolean {
|
||||||
|
if (item.model === "workspace") return false;
|
||||||
|
if (root.action === "delete") return item.action === "delete";
|
||||||
|
if (item.action === "keep_local") {
|
||||||
|
return root.modelId === item.modelId && item.model !== "folder";
|
||||||
|
}
|
||||||
|
return item.action === "create" || item.action === "update";
|
||||||
|
}
|
||||||
|
|
||||||
|
function nodeCheckedStatus(
|
||||||
|
node: CheckboxTreeNode<ImportPlanItem>,
|
||||||
|
): boolean | "indeterminate" | "hidden" {
|
||||||
|
const covered = collectItems(node).filter((i) => togglesWith(node.data, i));
|
||||||
|
if (covered.length === 0) return "hidden";
|
||||||
|
const selected = covered.filter((i) => i.selected).length;
|
||||||
|
if (selected === covered.length) return true;
|
||||||
|
if (selected === 0) return false;
|
||||||
|
return "indeterminate";
|
||||||
|
}
|
||||||
|
|
||||||
|
function PreviewRow({ label, value }: { label: string; value: string }) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-start justify-between gap-4 px-3 py-2 text-sm">
|
||||||
|
<span className="text-text-subtle">{label}</span>
|
||||||
|
<span className="text-right font-medium">{value}</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
|
||||||
import type { LicenseCheckStatus } from "@yaakapp-internal/license";
|
import type { LicenseCheckStatus } from "@yaakapp-internal/license";
|
||||||
import { useLicense } from "@yaakapp-internal/license";
|
import { useLicense } from "@yaakapp-internal/license";
|
||||||
import { settingsAtom } from "@yaakapp-internal/models";
|
import { settingsAtom } from "@yaakapp-internal/models";
|
||||||
@@ -14,6 +13,7 @@ import type { ButtonProps } from "./core/Button";
|
|||||||
import { Dropdown, type DropdownItem } from "./core/Dropdown";
|
import { Dropdown, type DropdownItem } from "./core/Dropdown";
|
||||||
import { Icon } from "@yaakapp-internal/ui";
|
import { Icon } from "@yaakapp-internal/ui";
|
||||||
import { PillButton } from "./core/PillButton";
|
import { PillButton } from "./core/PillButton";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
const dismissedAtom = atomWithKVStorage<string | null>("dismissed_license_expired", null);
|
const dismissedAtom = atomWithKVStorage<string | null>("dismissed_license_expired", null);
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ function getDetail(
|
|||||||
leftSlot: <Icon icon="gift" />,
|
leftSlot: <Icon icon="gift" />,
|
||||||
rightSlot: <Icon icon="external_link" size="sm" className="opacity-disabled" />,
|
rightSlot: <Icon icon="external_link" size="sm" className="opacity-disabled" />,
|
||||||
hidden: data.data.changes === 0 || data.data.changesUrl == null,
|
hidden: data.data.changes === 0 || data.data.changesUrl == null,
|
||||||
onSelect: () => openUrl(data.data.changesUrl ?? ""),
|
onSelect: () => platform.openUrl(data.data.changesUrl ?? ""),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: "separator",
|
type: "separator",
|
||||||
@@ -63,7 +63,7 @@ function getDetail(
|
|||||||
leftSlot: <Icon icon="refresh" />,
|
leftSlot: <Icon icon="refresh" />,
|
||||||
rightSlot: <Icon icon="external_link" size="sm" className="opacity-disabled" />,
|
rightSlot: <Icon icon="external_link" size="sm" className="opacity-disabled" />,
|
||||||
hidden: data.data.changesUrl == null,
|
hidden: data.data.changesUrl == null,
|
||||||
onSelect: () => openUrl(data.data.billingUrl),
|
onSelect: () => platform.openUrl(data.data.billingUrl),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Enter License Key",
|
label: "Enter License Key",
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { convertFileSrc } from "@tauri-apps/api/core";
|
|
||||||
import { resolveResource } from "@tauri-apps/api/path";
|
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
src: string;
|
src: string;
|
||||||
@@ -12,8 +11,8 @@ export function LocalImage({ src: srcPath, className }: Props) {
|
|||||||
const src = useQuery({
|
const src = useQuery({
|
||||||
queryKey: ["local-image", srcPath],
|
queryKey: ["local-image", srcPath],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const p = await resolveResource(srcPath);
|
const p = await platform.files.resolveResource(srcPath);
|
||||||
return convertFileSrc(p);
|
return platform.files.url(p);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ import type {
|
|||||||
Folder,
|
Folder,
|
||||||
GrpcRequest,
|
GrpcRequest,
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
|
HttpVersion,
|
||||||
InheritedBoolSetting,
|
InheritedBoolSetting,
|
||||||
|
InheritedHttpVersionSetting,
|
||||||
InheritedIntSetting,
|
InheritedIntSetting,
|
||||||
WebsocketRequest,
|
WebsocketRequest,
|
||||||
Workspace,
|
Workspace,
|
||||||
@@ -13,6 +15,7 @@ import {
|
|||||||
modelSupportsSetting,
|
modelSupportsSetting,
|
||||||
type RequestSettingDefinition,
|
type RequestSettingDefinition,
|
||||||
SETTING_FOLLOW_REDIRECTS,
|
SETTING_FOLLOW_REDIRECTS,
|
||||||
|
SETTING_HTTP_VERSION,
|
||||||
SETTING_REQUEST_MESSAGE_SIZE,
|
SETTING_REQUEST_MESSAGE_SIZE,
|
||||||
SETTING_REQUEST_TIMEOUT,
|
SETTING_REQUEST_TIMEOUT,
|
||||||
SETTING_SEND_COOKIES,
|
SETTING_SEND_COOKIES,
|
||||||
@@ -21,6 +24,7 @@ import {
|
|||||||
} from "../lib/requestSettings";
|
} from "../lib/requestSettings";
|
||||||
import { Checkbox } from "./core/Checkbox";
|
import { Checkbox } from "./core/Checkbox";
|
||||||
import { PlainInput } from "./core/PlainInput";
|
import { PlainInput } from "./core/PlainInput";
|
||||||
|
import { Select } from "./core/Select";
|
||||||
import {
|
import {
|
||||||
SettingOverrideRow,
|
SettingOverrideRow,
|
||||||
SettingRow,
|
SettingRow,
|
||||||
@@ -38,37 +42,21 @@ interface Props {
|
|||||||
model: ModelWithSettings;
|
model: ModelWithSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ModelWithSettings =
|
type ModelWithSettings = Workspace | Folder | HttpRequest | WebsocketRequest | GrpcRequest;
|
||||||
| Workspace
|
|
||||||
| Folder
|
|
||||||
| HttpRequest
|
|
||||||
| WebsocketRequest
|
|
||||||
| GrpcRequest;
|
|
||||||
type ModelWithHttpSettings = Workspace | Folder | HttpRequest;
|
type ModelWithHttpSettings = Workspace | Folder | HttpRequest;
|
||||||
type ModelWithTlsSettings =
|
type ModelWithTlsSettings = Workspace | Folder | HttpRequest | WebsocketRequest | GrpcRequest;
|
||||||
| Workspace
|
type ModelWithCookieSettings = Workspace | Folder | HttpRequest | WebsocketRequest;
|
||||||
| Folder
|
type ModelWithMessageSizeSettings = Workspace | Folder | WebsocketRequest | GrpcRequest;
|
||||||
| HttpRequest
|
|
||||||
| WebsocketRequest
|
|
||||||
| GrpcRequest;
|
|
||||||
type ModelWithCookieSettings =
|
|
||||||
| Workspace
|
|
||||||
| Folder
|
|
||||||
| HttpRequest
|
|
||||||
| WebsocketRequest;
|
|
||||||
type ModelWithMessageSizeSettings =
|
|
||||||
| Workspace
|
|
||||||
| Folder
|
|
||||||
| WebsocketRequest
|
|
||||||
| GrpcRequest;
|
|
||||||
type BooleanSetting = boolean | InheritedBoolSetting;
|
type BooleanSetting = boolean | InheritedBoolSetting;
|
||||||
type IntegerSetting = number | InheritedIntSetting;
|
type IntegerSetting = number | InheritedIntSetting;
|
||||||
|
type HttpVersionSetting = HttpVersion | InheritedHttpVersionSetting;
|
||||||
type CookieSettingsPatch = {
|
type CookieSettingsPatch = {
|
||||||
settingSendCookies?: ModelWithCookieSettings["settingSendCookies"];
|
settingSendCookies?: ModelWithCookieSettings["settingSendCookies"];
|
||||||
settingStoreCookies?: ModelWithCookieSettings["settingStoreCookies"];
|
settingStoreCookies?: ModelWithCookieSettings["settingStoreCookies"];
|
||||||
};
|
};
|
||||||
type HttpSettingsPatch = {
|
type HttpSettingsPatch = {
|
||||||
settingFollowRedirects?: ModelWithHttpSettings["settingFollowRedirects"];
|
settingFollowRedirects?: ModelWithHttpSettings["settingFollowRedirects"];
|
||||||
|
settingHttpVersion?: ModelWithHttpSettings["settingHttpVersion"];
|
||||||
settingRequestTimeout?: ModelWithHttpSettings["settingRequestTimeout"];
|
settingRequestTimeout?: ModelWithHttpSettings["settingRequestTimeout"];
|
||||||
};
|
};
|
||||||
type TlsSettingsPatch = {
|
type TlsSettingsPatch = {
|
||||||
@@ -78,10 +66,7 @@ type MessageSizeSettingsPatch = {
|
|||||||
settingRequestMessageSize?: ModelWithMessageSizeSettings["settingRequestMessageSize"];
|
settingRequestMessageSize?: ModelWithMessageSizeSettings["settingRequestMessageSize"];
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ModelSettingsEditor({
|
export function ModelSettingsEditor({ model, showSectionTitles = false }: Props) {
|
||||||
model,
|
|
||||||
showSectionTitles = false,
|
|
||||||
}: Props) {
|
|
||||||
const ancestors = useModelAncestors(model);
|
const ancestors = useModelAncestors(model);
|
||||||
const supportsHttpSettings = modelSupportsHttpSettings(model);
|
const supportsHttpSettings = modelSupportsHttpSettings(model);
|
||||||
const supportsCookieSettings = modelSupportsCookieSettings(model);
|
const supportsCookieSettings = modelSupportsCookieSettings(model);
|
||||||
@@ -154,12 +139,26 @@ export function ModelSettingsEditor({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{supportsHttpSettings && (
|
||||||
|
<HttpVersionSettingRow
|
||||||
|
settingDefinition={SETTING_HTTP_VERSION}
|
||||||
|
setting={model.settingHttpVersion}
|
||||||
|
inheritedValue={resolveInheritedValue(
|
||||||
|
ancestors,
|
||||||
|
SETTING_HTTP_VERSION.modelKey,
|
||||||
|
model.settingHttpVersion,
|
||||||
|
)}
|
||||||
|
onChange={(settingHttpVersion) =>
|
||||||
|
patchHttpSettings(model, {
|
||||||
|
settingHttpVersion,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</SettingsSection>
|
</SettingsSection>
|
||||||
)}
|
)}
|
||||||
{supportsCookieSettings && (
|
{supportsCookieSettings && (
|
||||||
<SettingsSection
|
<SettingsSection title={supportsTlsSettings || showSectionTitles ? "Cookies" : null}>
|
||||||
title={supportsTlsSettings || showSectionTitles ? "Cookies" : null}
|
|
||||||
>
|
|
||||||
<BooleanSettingRow
|
<BooleanSettingRow
|
||||||
settingDefinition={SETTING_SEND_COOKIES}
|
settingDefinition={SETTING_SEND_COOKIES}
|
||||||
setting={model.settingSendCookies}
|
setting={model.settingSendCookies}
|
||||||
@@ -195,7 +194,7 @@ export function ModelSettingsEditor({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function countOverriddenSettings(model: ModelWithSettings) {
|
export function countOverriddenSettings(model: ModelWithSettings) {
|
||||||
const settings: (BooleanSetting | IntegerSetting)[] = [];
|
const settings: (BooleanSetting | IntegerSetting | HttpVersionSetting)[] = [];
|
||||||
|
|
||||||
if (modelSupportsCookieSettings(model)) {
|
if (modelSupportsCookieSettings(model)) {
|
||||||
settings.push(model.settingSendCookies, model.settingStoreCookies);
|
settings.push(model.settingSendCookies, model.settingStoreCookies);
|
||||||
@@ -204,22 +203,22 @@ export function countOverriddenSettings(model: ModelWithSettings) {
|
|||||||
settings.push(model.settingValidateCertificates);
|
settings.push(model.settingValidateCertificates);
|
||||||
|
|
||||||
if (modelSupportsHttpSettings(model)) {
|
if (modelSupportsHttpSettings(model)) {
|
||||||
settings.push(model.settingFollowRedirects, model.settingRequestTimeout);
|
settings.push(
|
||||||
|
model.settingFollowRedirects,
|
||||||
|
model.settingRequestTimeout,
|
||||||
|
model.settingHttpVersion,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modelSupportsMessageSizeSettings(model)) {
|
if (modelSupportsMessageSizeSettings(model)) {
|
||||||
settings.push(model.settingRequestMessageSize);
|
settings.push(model.settingRequestMessageSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return settings.filter(
|
return settings.filter((setting) => isInheritedSetting(setting) && setting.enabled === true)
|
||||||
(setting) => isInheritedSetting(setting) && setting.enabled === true,
|
.length;
|
||||||
).length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function patchCookieSettings(
|
function patchCookieSettings(model: ModelWithCookieSettings, patch: Partial<CookieSettingsPatch>) {
|
||||||
model: ModelWithCookieSettings,
|
|
||||||
patch: Partial<CookieSettingsPatch>,
|
|
||||||
) {
|
|
||||||
switch (model.model) {
|
switch (model.model) {
|
||||||
case "workspace":
|
case "workspace":
|
||||||
return patchModel(model, patch as Partial<Workspace>);
|
return patchModel(model, patch as Partial<Workspace>);
|
||||||
@@ -232,10 +231,7 @@ function patchCookieSettings(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function patchHttpSettings(
|
function patchHttpSettings(model: ModelWithHttpSettings, patch: Partial<HttpSettingsPatch>) {
|
||||||
model: ModelWithHttpSettings,
|
|
||||||
patch: Partial<HttpSettingsPatch>,
|
|
||||||
) {
|
|
||||||
switch (model.model) {
|
switch (model.model) {
|
||||||
case "workspace":
|
case "workspace":
|
||||||
return patchModel(model, patch as Partial<Workspace>);
|
return patchModel(model, patch as Partial<Workspace>);
|
||||||
@@ -246,10 +242,7 @@ function patchHttpSettings(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function patchTlsSettings(
|
function patchTlsSettings(model: ModelWithTlsSettings, patch: Partial<TlsSettingsPatch>) {
|
||||||
model: ModelWithTlsSettings,
|
|
||||||
patch: Partial<TlsSettingsPatch>,
|
|
||||||
) {
|
|
||||||
switch (model.model) {
|
switch (model.model) {
|
||||||
case "workspace":
|
case "workspace":
|
||||||
return patchModel(model, patch as Partial<Workspace>);
|
return patchModel(model, patch as Partial<Workspace>);
|
||||||
@@ -280,21 +273,15 @@ function patchMessageSizeSettings(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function modelSupportsHttpSettings(
|
function modelSupportsHttpSettings(model: ModelWithSettings): model is ModelWithHttpSettings {
|
||||||
model: ModelWithSettings,
|
|
||||||
): model is ModelWithHttpSettings {
|
|
||||||
return modelSupportsSetting(model, SETTING_REQUEST_TIMEOUT);
|
return modelSupportsSetting(model, SETTING_REQUEST_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
function modelSupportsCookieSettings(
|
function modelSupportsCookieSettings(model: ModelWithSettings): model is ModelWithCookieSettings {
|
||||||
model: ModelWithSettings,
|
|
||||||
): model is ModelWithCookieSettings {
|
|
||||||
return modelSupportsSetting(model, SETTING_SEND_COOKIES);
|
return modelSupportsSetting(model, SETTING_SEND_COOKIES);
|
||||||
}
|
}
|
||||||
|
|
||||||
function modelSupportsTlsSettings(
|
function modelSupportsTlsSettings(model: ModelWithSettings): model is ModelWithTlsSettings {
|
||||||
model: ModelWithSettings,
|
|
||||||
): model is ModelWithTlsSettings {
|
|
||||||
return modelSupportsSetting(model, SETTING_VALIDATE_CERTIFICATES);
|
return modelSupportsSetting(model, SETTING_VALIDATE_CERTIFICATES);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,11 +304,7 @@ function BooleanSettingRow({
|
|||||||
}) {
|
}) {
|
||||||
const inherited = isInheritedSetting(setting);
|
const inherited = isInheritedSetting(setting);
|
||||||
const overridden = inherited ? setting.enabled === true : false;
|
const overridden = inherited ? setting.enabled === true : false;
|
||||||
const value = inherited
|
const value = inherited ? (overridden ? setting.value : inheritedValue) : setting;
|
||||||
? overridden
|
|
||||||
? setting.value
|
|
||||||
: inheritedValue
|
|
||||||
: setting;
|
|
||||||
|
|
||||||
if (!inherited) {
|
if (!inherited) {
|
||||||
return (
|
return (
|
||||||
@@ -352,6 +335,63 @@ function BooleanSettingRow({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const HTTP_VERSION_OPTIONS: { label: string; value: HttpVersion }[] = [
|
||||||
|
{ label: "Automatic", value: "auto" },
|
||||||
|
{ label: "HTTP/1.1", value: "http1" },
|
||||||
|
{ label: "HTTP/2", value: "http2" },
|
||||||
|
];
|
||||||
|
|
||||||
|
function HttpVersionSettingRow({
|
||||||
|
inheritedValue,
|
||||||
|
setting,
|
||||||
|
settingDefinition,
|
||||||
|
onChange,
|
||||||
|
}: {
|
||||||
|
inheritedValue: HttpVersion;
|
||||||
|
setting: HttpVersionSetting;
|
||||||
|
settingDefinition: RequestSettingDefinition<"settingHttpVersion">;
|
||||||
|
onChange: (setting: HttpVersionSetting) => void;
|
||||||
|
}) {
|
||||||
|
const inherited = isInheritedSetting(setting);
|
||||||
|
const overridden = inherited ? setting.enabled === true : false;
|
||||||
|
const value = inherited ? (overridden ? setting.value : inheritedValue) : setting;
|
||||||
|
|
||||||
|
if (!inherited) {
|
||||||
|
return (
|
||||||
|
<SettingRow title={settingDefinition.title} description={settingDefinition.description}>
|
||||||
|
<Select
|
||||||
|
hideLabel
|
||||||
|
name={settingDefinition.modelKey}
|
||||||
|
label={settingDefinition.title}
|
||||||
|
size="sm"
|
||||||
|
value={value}
|
||||||
|
options={HTTP_VERSION_OPTIONS}
|
||||||
|
onChange={(value) => onChange(value)}
|
||||||
|
/>
|
||||||
|
</SettingRow>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SettingOverrideRow
|
||||||
|
title={settingDefinition.title}
|
||||||
|
description={settingDefinition.description}
|
||||||
|
overridden={overridden}
|
||||||
|
onResetOverride={() => onChange({ ...setting, enabled: false })}
|
||||||
|
>
|
||||||
|
<Select
|
||||||
|
hideLabel
|
||||||
|
name={settingDefinition.modelKey}
|
||||||
|
label={settingDefinition.title}
|
||||||
|
size="sm"
|
||||||
|
value={value}
|
||||||
|
options={HTTP_VERSION_OPTIONS}
|
||||||
|
onChange={(value) => onChange({ ...setting, enabled: true, value })}
|
||||||
|
/>
|
||||||
|
</SettingOverrideRow>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function IntegerSettingRow({
|
function IntegerSettingRow({
|
||||||
inheritedValue,
|
inheritedValue,
|
||||||
setting,
|
setting,
|
||||||
@@ -365,18 +405,11 @@ function IntegerSettingRow({
|
|||||||
}) {
|
}) {
|
||||||
const inherited = isInheritedSetting(setting);
|
const inherited = isInheritedSetting(setting);
|
||||||
const overridden = inherited ? setting.enabled === true : false;
|
const overridden = inherited ? setting.enabled === true : false;
|
||||||
const value = inherited
|
const value = inherited ? (overridden ? setting.value : inheritedValue) : setting;
|
||||||
? overridden
|
|
||||||
? setting.value
|
|
||||||
: inheritedValue
|
|
||||||
: setting;
|
|
||||||
|
|
||||||
if (!inherited) {
|
if (!inherited) {
|
||||||
return (
|
return (
|
||||||
<SettingRow
|
<SettingRow title={settingDefinition.title} description={settingDefinition.description}>
|
||||||
title={settingDefinition.title}
|
|
||||||
description={settingDefinition.description}
|
|
||||||
>
|
|
||||||
<NumberUnitInput
|
<NumberUnitInput
|
||||||
name={settingDefinition.modelKey}
|
name={settingDefinition.modelKey}
|
||||||
label={settingDefinition.title}
|
label={settingDefinition.title}
|
||||||
@@ -429,20 +462,13 @@ function MessageSizeSettingRow({
|
|||||||
}) {
|
}) {
|
||||||
const inherited = isInheritedSetting(setting);
|
const inherited = isInheritedSetting(setting);
|
||||||
const overridden = inherited ? setting.enabled === true : false;
|
const overridden = inherited ? setting.enabled === true : false;
|
||||||
const value = inherited
|
const value = inherited ? (overridden ? setting.value : inheritedValue) : setting;
|
||||||
? overridden
|
|
||||||
? setting.value
|
|
||||||
: inheritedValue
|
|
||||||
: setting;
|
|
||||||
const displayValue = formatMegabytes(value);
|
const displayValue = formatMegabytes(value);
|
||||||
const placeholder = "0";
|
const placeholder = "0";
|
||||||
|
|
||||||
if (!inherited) {
|
if (!inherited) {
|
||||||
return (
|
return (
|
||||||
<SettingRow
|
<SettingRow title={settingDefinition.title} description={settingDefinition.description}>
|
||||||
title={settingDefinition.title}
|
|
||||||
description={settingDefinition.description}
|
|
||||||
>
|
|
||||||
<MessageSizeInput
|
<MessageSizeInput
|
||||||
name={settingDefinition.modelKey}
|
name={settingDefinition.modelKey}
|
||||||
label={settingDefinition.title}
|
label={settingDefinition.title}
|
||||||
@@ -567,13 +593,18 @@ function resolveInheritedValue(
|
|||||||
key: BooleanWorkspaceSettingKey,
|
key: BooleanWorkspaceSettingKey,
|
||||||
fallback: BooleanSetting,
|
fallback: BooleanSetting,
|
||||||
): boolean;
|
): boolean;
|
||||||
|
function resolveInheritedValue(
|
||||||
|
ancestors: (Folder | Workspace)[],
|
||||||
|
key: "settingHttpVersion",
|
||||||
|
fallback: HttpVersionSetting,
|
||||||
|
): HttpVersion;
|
||||||
function resolveInheritedValue(
|
function resolveInheritedValue(
|
||||||
ancestors: (Folder | Workspace)[],
|
ancestors: (Folder | Workspace)[],
|
||||||
key: keyof WorkspaceSettings,
|
key: keyof WorkspaceSettings,
|
||||||
fallback: BooleanSetting | IntegerSetting,
|
fallback: BooleanSetting | IntegerSetting | HttpVersionSetting,
|
||||||
) {
|
) {
|
||||||
for (const ancestor of ancestors) {
|
for (const ancestor of ancestors) {
|
||||||
const setting = ancestor[key] as BooleanSetting | IntegerSetting;
|
const setting = ancestor[key] as BooleanSetting | IntegerSetting | HttpVersionSetting;
|
||||||
if (isInheritedSetting(setting)) {
|
if (isInheritedSetting(setting)) {
|
||||||
if (setting.enabled === true) {
|
if (setting.enabled === true) {
|
||||||
return setting.value;
|
return setting.value;
|
||||||
@@ -589,6 +620,7 @@ function resolveInheritedValue(
|
|||||||
type WorkspaceSettings = Pick<
|
type WorkspaceSettings = Pick<
|
||||||
Workspace,
|
Workspace,
|
||||||
| "settingFollowRedirects"
|
| "settingFollowRedirects"
|
||||||
|
| "settingHttpVersion"
|
||||||
| "settingRequestMessageSize"
|
| "settingRequestMessageSize"
|
||||||
| "settingRequestTimeout"
|
| "settingRequestTimeout"
|
||||||
| "settingSendCookies"
|
| "settingSendCookies"
|
||||||
@@ -598,14 +630,12 @@ type WorkspaceSettings = Pick<
|
|||||||
|
|
||||||
type BooleanWorkspaceSettingKey = Exclude<
|
type BooleanWorkspaceSettingKey = Exclude<
|
||||||
keyof WorkspaceSettings,
|
keyof WorkspaceSettings,
|
||||||
"settingRequestTimeout" | "settingRequestMessageSize"
|
"settingRequestTimeout" | "settingRequestMessageSize" | "settingHttpVersion"
|
||||||
>;
|
>;
|
||||||
|
|
||||||
function formatMegabytes(bytes: number) {
|
function formatMegabytes(bytes: number) {
|
||||||
const megabytes = bytes / BYTES_PER_MB;
|
const megabytes = bytes / BYTES_PER_MB;
|
||||||
return Number.isInteger(megabytes)
|
return Number.isInteger(megabytes) ? `${megabytes}` : megabytes.toFixed(3).replace(/\.?0+$/, "");
|
||||||
? `${megabytes}`
|
|
||||||
: megabytes.toFixed(3).replace(/\.?0+$/, "");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseMegabytes(value: string) {
|
function parseMegabytes(value: string) {
|
||||||
@@ -626,9 +656,5 @@ function isValidInteger(value: string) {
|
|||||||
function isValidMegabytes(value: string) {
|
function isValidMegabytes(value: string) {
|
||||||
if (value === "") return true;
|
if (value === "") return true;
|
||||||
const megabytes = Number(value);
|
const megabytes = Number(value);
|
||||||
return (
|
return Number.isFinite(megabytes) && megabytes >= 0 && megabytes <= MAX_MESSAGE_SIZE_MB;
|
||||||
Number.isFinite(megabytes) &&
|
|
||||||
megabytes >= 0 &&
|
|
||||||
megabytes <= MAX_MESSAGE_SIZE_MB
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import type { HttpResponse, RequestVersionComparison } from "@yaakapp-internal/models";
|
||||||
|
import { Icon } from "@yaakapp-internal/ui";
|
||||||
|
import { stringify } from "yaml";
|
||||||
|
import { useRequestVersion } from "../hooks/useRequestVersion";
|
||||||
|
import { showDialog } from "../lib/dialog";
|
||||||
|
import { restoreRequestVersion } from "../lib/restoreRequestVersion";
|
||||||
|
import { Button } from "./core/Button";
|
||||||
|
import { DiffViewer } from "./core/Editor/DiffViewer";
|
||||||
|
import { Dropdown } from "./core/Dropdown";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
response: Pick<HttpResponse, "requestId" | "versionId">;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Offers the request a response was sent from, when that is no longer the
|
||||||
|
* request you have.
|
||||||
|
*
|
||||||
|
* Hidden while the two agree, which is the overwhelmingly common case and the
|
||||||
|
* one where there is nothing to say. Responses recorded before versioning
|
||||||
|
* existed have no version and stay quiet forever.
|
||||||
|
*/
|
||||||
|
export function RequestVersionDropdown({ response }: Props) {
|
||||||
|
const { data: comparison } = useRequestVersion(response.versionId, response.requestId);
|
||||||
|
if (comparison == null || !comparison.differs) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dropdown
|
||||||
|
items={[
|
||||||
|
{
|
||||||
|
label: "View Diff",
|
||||||
|
leftSlot: <Icon icon="git_branch" />,
|
||||||
|
onSelect: () => showRequestVersionDiff(comparison),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Restore This Version",
|
||||||
|
leftSlot: <Icon icon="history" />,
|
||||||
|
onSelect: () => restoreRequestVersion(comparison.version),
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
size="2xs"
|
||||||
|
variant="border"
|
||||||
|
color="notice"
|
||||||
|
className="font-sans"
|
||||||
|
title="This request has changed since this response was sent"
|
||||||
|
forDropdown
|
||||||
|
>
|
||||||
|
Request Changed
|
||||||
|
</Button>
|
||||||
|
</Dropdown>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showRequestVersionDiff(comparison: RequestVersionComparison) {
|
||||||
|
showDialog({
|
||||||
|
id: "request-version-diff",
|
||||||
|
title: "Request Changes Since This Response",
|
||||||
|
size: "full",
|
||||||
|
noPadding: true,
|
||||||
|
render: () => (
|
||||||
|
<div className="h-full flex flex-col px-4 pb-4">
|
||||||
|
<DiffViewer
|
||||||
|
original={toYaml(comparison.version.document)}
|
||||||
|
modified={toYaml(comparison.currentDocument)}
|
||||||
|
className="flex-1 min-h-0"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Matches how the Git dialog renders a model for diffing. */
|
||||||
|
function toYaml(document: unknown): string {
|
||||||
|
return stringify(document, { indent: 2, lineWidth: 0 });
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
|
||||||
import type { HttpResponse } from "@yaakapp-internal/models";
|
import type { HttpResponse } from "@yaakapp-internal/models";
|
||||||
import { format, formatDistanceToNowStrict } from "date-fns";
|
import { format, formatDistanceToNowStrict } from "date-fns";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
@@ -6,6 +5,7 @@ import { CountBadge } from "./core/CountBadge";
|
|||||||
import { DetailsBanner } from "./core/DetailsBanner";
|
import { DetailsBanner } from "./core/DetailsBanner";
|
||||||
import { IconButton } from "./core/IconButton";
|
import { IconButton } from "./core/IconButton";
|
||||||
import { KeyValueRow, KeyValueRows } from "./core/KeyValueRow";
|
import { KeyValueRow, KeyValueRows } from "./core/KeyValueRow";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
response: HttpResponse;
|
response: HttpResponse;
|
||||||
@@ -45,7 +45,7 @@ export function ResponseHeaders({ response }: Props) {
|
|||||||
iconSize="sm"
|
iconSize="sm"
|
||||||
className="inline-block w-auto h-auto! opacity-50 hover:opacity-100"
|
className="inline-block w-auto h-auto! opacity-50 hover:opacity-100"
|
||||||
icon="external_link"
|
icon="external_link"
|
||||||
onClick={() => openUrl(response.url)}
|
onClick={() => platform.openUrl(response.url)}
|
||||||
title="Open in browser"
|
title="Open in browser"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
|
||||||
import type { HttpResponse } from "@yaakapp-internal/models";
|
import type { HttpResponse } from "@yaakapp-internal/models";
|
||||||
import { IconButton } from "./core/IconButton";
|
import { IconButton } from "./core/IconButton";
|
||||||
import { KeyValueRow, KeyValueRows } from "./core/KeyValueRow";
|
import { KeyValueRow, KeyValueRows } from "./core/KeyValueRow";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
response: HttpResponse;
|
response: HttpResponse;
|
||||||
@@ -26,7 +26,7 @@ export function ResponseInfo({ response }: Props) {
|
|||||||
iconSize="sm"
|
iconSize="sm"
|
||||||
className="inline-block w-auto ml-1 h-auto! opacity-50 hover:opacity-100"
|
className="inline-block w-auto ml-1 h-auto! opacity-50 hover:opacity-100"
|
||||||
icon="external_link"
|
icon="external_link"
|
||||||
onClick={() => openUrl(response.url)}
|
onClick={() => platform.openUrl(response.url)}
|
||||||
title="Open in browser"
|
title="Open in browser"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import { open } from "@tauri-apps/plugin-dialog";
|
|
||||||
import { HStack } from "@yaakapp-internal/ui";
|
import { HStack } from "@yaakapp-internal/ui";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import mime from "mime";
|
import mime from "mime";
|
||||||
@@ -41,7 +40,7 @@ export function SelectFile({
|
|||||||
...props
|
...props
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const handleClick = async () => {
|
const handleClick = async () => {
|
||||||
const filePath = await open({
|
const filePath = await platform.dialog.open({
|
||||||
title: directory ? "Select Folder" : "Select File",
|
title: directory ? "Select Folder" : "Select File",
|
||||||
multiple: false,
|
multiple: false,
|
||||||
directory,
|
directory,
|
||||||
@@ -64,32 +63,21 @@ export function SelectFile({
|
|||||||
// NOTE: This doesn't work for Windows since native drag-n-drop can't work at the same tmie
|
// NOTE: This doesn't work for Windows since native drag-n-drop can't work at the same tmie
|
||||||
// as browser drag-n-drop.
|
// as browser drag-n-drop.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let unlisten: (() => void) | undefined;
|
return platform.window.onDragDrop((event) => {
|
||||||
const setup = async () => {
|
if (event.type === "over") {
|
||||||
const webview = getCurrentWebviewWindow();
|
const p = event.position;
|
||||||
unlisten = await webview.onDragDropEvent((event) => {
|
const r = ref.current?.getBoundingClientRect();
|
||||||
if (event.payload.type === "over") {
|
if (r == null) return;
|
||||||
const p = event.payload.position;
|
const isOver = p.x >= r.left && p.x <= r.right && p.y >= r.top && p.y <= r.bottom;
|
||||||
const r = ref.current?.getBoundingClientRect();
|
setIsHovering(isOver);
|
||||||
if (r == null) return;
|
} else if (event.type === "drop" && isHovering) {
|
||||||
const isOver = p.x >= r.left && p.x <= r.right && p.y >= r.top && p.y <= r.bottom;
|
const p = event.paths[0];
|
||||||
console.log("IS OVER", isOver);
|
if (p) onChange({ filePath: p, contentType: null });
|
||||||
setIsHovering(isOver);
|
setIsHovering(false);
|
||||||
} else if (event.payload.type === "drop" && isHovering) {
|
} else {
|
||||||
console.log("User dropped", event.payload.paths);
|
setIsHovering(false);
|
||||||
const p = event.payload.paths[0];
|
}
|
||||||
if (p) onChange({ filePath: p, contentType: null });
|
});
|
||||||
setIsHovering(false);
|
|
||||||
} else {
|
|
||||||
console.log("File drop cancelled");
|
|
||||||
setIsHovering(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
setup().catch(console.error);
|
|
||||||
return () => {
|
|
||||||
if (unlisten) unlisten();
|
|
||||||
};
|
|
||||||
}, [isHovering, onChange]);
|
}, [isHovering, onChange]);
|
||||||
|
|
||||||
const filePathWithNameOverride = nameOverride ? `${filePath} (${nameOverride})` : filePath;
|
const filePathWithNameOverride = nameOverride ? `${filePath} (${nameOverride})` : filePath;
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { useSearch } from "@tanstack/react-router";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
|
||||||
import { type } from "@tauri-apps/plugin-os";
|
|
||||||
import { useLicense } from "@yaakapp-internal/license";
|
import { useLicense } from "@yaakapp-internal/license";
|
||||||
import { pluginsAtom, settingsAtom } from "@yaakapp-internal/models";
|
import { pluginsAtom, settingsAtom } from "@yaakapp-internal/models";
|
||||||
import { HeaderSize, HStack, Icon } from "@yaakapp-internal/ui";
|
import { HeaderSize, HStack, Icon } from "@yaakapp-internal/ui";
|
||||||
@@ -21,6 +19,8 @@ import { SettingsProxy } from "./SettingsProxy";
|
|||||||
import { SettingsTheme } from "./SettingsTheme";
|
import { SettingsTheme } from "./SettingsTheme";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
tab?: SettingsTabWithSubtab | null;
|
||||||
|
/** Set when Settings is in a dialog rather than owning a window. */
|
||||||
hide?: () => void;
|
hide?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,25 +43,19 @@ const tabs = [
|
|||||||
TAB_LICENSE,
|
TAB_LICENSE,
|
||||||
] as const;
|
] as const;
|
||||||
export type SettingsTab = (typeof tabs)[number];
|
export type SettingsTab = (typeof tabs)[number];
|
||||||
|
export type SettingsTabWithSubtab = SettingsTab | `${SettingsTab}:${string}`;
|
||||||
|
|
||||||
export default function Settings({ hide }: Props) {
|
export default function Settings({ tab, hide }: Props) {
|
||||||
const { tab: tabFromQuery } = useSearch({ from: "/workspaces/$workspaceId/settings" });
|
|
||||||
// Parse tab and subtab (e.g., "plugins:installed")
|
// Parse tab and subtab (e.g., "plugins:installed")
|
||||||
const [mainTab, subtab] = tabFromQuery?.split(":") ?? [];
|
const [mainTab, subtab] = tab?.split(":") ?? [];
|
||||||
const settings = useAtomValue(settingsAtom);
|
const settings = useAtomValue(settingsAtom);
|
||||||
const plugins = useAtomValue(pluginsAtom);
|
const plugins = useAtomValue(pluginsAtom);
|
||||||
const licenseCheck = useLicense();
|
const licenseCheck = useLicense();
|
||||||
|
|
||||||
// Close settings window on escape
|
// Close settings window on escape. In a dialog, the dialog handles Escape itself.
|
||||||
// TODO: Could this be put in a better place? Eg. in Rust key listener when creating the window
|
// TODO: Could this be put in a better place? Eg. in Rust key listener when creating the window
|
||||||
useKeyPressEvent("Escape", async () => {
|
useKeyPressEvent("Escape", async () => {
|
||||||
if (hide != null) {
|
if (hide == null) await platform.window.close();
|
||||||
// It's being shown in a dialog, so close the dialog
|
|
||||||
hide();
|
|
||||||
} else {
|
|
||||||
// It's being shown in a window, so close the window
|
|
||||||
await getCurrentWebviewWindow().close();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -75,7 +69,7 @@ export default function Settings({ hide }: Props) {
|
|||||||
onlyXWindowControl
|
onlyXWindowControl
|
||||||
size="md"
|
size="md"
|
||||||
className="x-theme-appHeader bg-surface text-text-subtle flex items-center justify-center border-b border-border-subtle text-sm font-semibold"
|
className="x-theme-appHeader bg-surface text-text-subtle flex items-center justify-center border-b border-border-subtle text-sm font-semibold"
|
||||||
osType={type()}
|
osType={platform.osType()}
|
||||||
hideWindowControls={settings.hideWindowControls}
|
hideWindowControls={settings.hideWindowControls}
|
||||||
useNativeTitlebar={settings.useNativeTitlebar}
|
useNativeTitlebar={settings.useNativeTitlebar}
|
||||||
interfaceScale={settings.interfaceScale}
|
interfaceScale={settings.interfaceScale}
|
||||||
@@ -85,13 +79,13 @@ export default function Settings({ hide }: Props) {
|
|||||||
justifyContent="center"
|
justifyContent="center"
|
||||||
className="w-full h-full grid grid-cols-[1fr_auto] pointer-events-none"
|
className="w-full h-full grid grid-cols-[1fr_auto] pointer-events-none"
|
||||||
>
|
>
|
||||||
<div className={classNames(type() === "macos" ? "text-center" : "pl-2")}>Settings</div>
|
<div className={classNames(platform.osType() === "macos" ? "text-center" : "pl-2")}>Settings</div>
|
||||||
</HStack>
|
</HStack>
|
||||||
</HeaderSize>
|
</HeaderSize>
|
||||||
)}
|
)}
|
||||||
<Tabs
|
<Tabs
|
||||||
layout="horizontal"
|
layout="horizontal"
|
||||||
defaultValue={mainTab || tabFromQuery}
|
defaultValue={mainTab}
|
||||||
addBorders
|
addBorders
|
||||||
tabListClassName="min-w-40 bg-surface x-theme-sidebar border-r border-border pl-3"
|
tabListClassName="min-w-40 bg-surface x-theme-sidebar border-r border-border pl-3"
|
||||||
label="Settings"
|
label="Settings"
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { revealItemInDir } from "@tauri-apps/plugin-opener";
|
|
||||||
import { patchModel, settingsAtom } from "@yaakapp-internal/models";
|
import { patchModel, settingsAtom } from "@yaakapp-internal/models";
|
||||||
import { Heading, VStack } from "@yaakapp-internal/ui";
|
import { Heading, VStack } from "@yaakapp-internal/ui";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
@@ -9,6 +8,7 @@ import { CargoFeature } from "../CargoFeature";
|
|||||||
import { CommercialUseBanner } from "../CommercialUseBanner";
|
import { CommercialUseBanner } from "../CommercialUseBanner";
|
||||||
import { DismissibleBanner } from "../core/DismissibleBanner";
|
import { DismissibleBanner } from "../core/DismissibleBanner";
|
||||||
import { IconButton } from "../core/IconButton";
|
import { IconButton } from "../core/IconButton";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import {
|
import {
|
||||||
ModelSettingRowBoolean,
|
ModelSettingRowBoolean,
|
||||||
ModelSettingSelectControl,
|
ModelSettingSelectControl,
|
||||||
@@ -152,7 +152,7 @@ export function SettingsGeneral() {
|
|||||||
{
|
{
|
||||||
title: revealInFinderText,
|
title: revealInFinderText,
|
||||||
icon: "folder_open",
|
icon: "folder_open",
|
||||||
onClick: () => revealItemInDir(appInfo.appDataDir),
|
onClick: () => platform.revealItemInDir(appInfo.appDataDir),
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
@@ -168,7 +168,7 @@ export function SettingsGeneral() {
|
|||||||
{
|
{
|
||||||
title: revealInFinderText,
|
title: revealInFinderText,
|
||||||
icon: "folder_open",
|
icon: "folder_open",
|
||||||
onClick: () => revealItemInDir(appInfo.appLogDir),
|
onClick: () => platform.revealItemInDir(appInfo.appLogDir),
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ export function SettingsHotkeys() {
|
|||||||
<HotkeyRow
|
<HotkeyRow
|
||||||
key={action}
|
key={action}
|
||||||
action={action}
|
action={action}
|
||||||
currentKeys={hotkeys[action]}
|
currentKeys={hotkeys[action] ?? []}
|
||||||
defaultKeys={defaultHotkeys[action]}
|
defaultKeys={defaultHotkeys[action]}
|
||||||
onSave={async (keys) => {
|
onSave={async (keys) => {
|
||||||
const newHotkeys = { ...settings.hotkeys };
|
const newHotkeys = { ...settings.hotkeys };
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type } from "@tauri-apps/plugin-os";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import { useFonts } from "@yaakapp-internal/fonts";
|
import { useFonts } from "@yaakapp-internal/fonts";
|
||||||
import { useLicense } from "@yaakapp-internal/license";
|
import { useLicense } from "@yaakapp-internal/license";
|
||||||
import type { EditorKeymap, Settings } from "@yaakapp-internal/models";
|
import type { EditorKeymap, Settings } from "@yaakapp-internal/models";
|
||||||
@@ -9,7 +9,7 @@ import { useState } from "react";
|
|||||||
import { activeWorkspaceAtom } from "../../hooks/useActiveWorkspace";
|
import { activeWorkspaceAtom } from "../../hooks/useActiveWorkspace";
|
||||||
import { showConfirm } from "../../lib/confirm";
|
import { showConfirm } from "../../lib/confirm";
|
||||||
import { pricingUrl } from "../../lib/pricingUrl";
|
import { pricingUrl } from "../../lib/pricingUrl";
|
||||||
import { invokeCmd } from "../../lib/tauri";
|
import { rpc } from "../../lib/rpc";
|
||||||
import { CargoFeature } from "../CargoFeature";
|
import { CargoFeature } from "../CargoFeature";
|
||||||
import { Button } from "../core/Button";
|
import { Button } from "../core/Button";
|
||||||
import { Checkbox } from "../core/Checkbox";
|
import { Checkbox } from "../core/Checkbox";
|
||||||
@@ -176,7 +176,7 @@ export function SettingsInterface() {
|
|||||||
|
|
||||||
<SettingsSection title="Window">
|
<SettingsSection title="Window">
|
||||||
<NativeTitlebarSetting settings={settings} />
|
<NativeTitlebarSetting settings={settings} />
|
||||||
{type() !== "macos" && (
|
{platform.osType() !== "macos" && (
|
||||||
<ModelSettingRowBoolean
|
<ModelSettingRowBoolean
|
||||||
model={settings}
|
model={settings}
|
||||||
modelKey="hideWindowControls"
|
modelKey="hideWindowControls"
|
||||||
@@ -216,7 +216,7 @@ function NativeTitlebarSetting({ settings }: { settings: Settings }) {
|
|||||||
size="xs"
|
size="xs"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await patchModel(settings, { useNativeTitlebar: nativeTitlebar });
|
await patchModel(settings, { useNativeTitlebar: nativeTitlebar });
|
||||||
await invokeCmd("cmd_restart");
|
await rpc("cmd_restart");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Apply and Restart
|
Apply and Restart
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
|
||||||
import { useLicense } from "@yaakapp-internal/license";
|
import { useLicense } from "@yaakapp-internal/license";
|
||||||
import { Banner, HStack, Icon, VStack } from "@yaakapp-internal/ui";
|
import { Banner, HStack, Icon, VStack } from "@yaakapp-internal/ui";
|
||||||
import { differenceInDays } from "date-fns";
|
import { differenceInDays } from "date-fns";
|
||||||
@@ -12,6 +11,7 @@ import { Button } from "../core/Button";
|
|||||||
import { Link } from "../core/Link";
|
import { Link } from "../core/Link";
|
||||||
import { PlainInput } from "../core/PlainInput";
|
import { PlainInput } from "../core/PlainInput";
|
||||||
import { Separator } from "../core/Separator";
|
import { Separator } from "../core/Separator";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
export function SettingsLicense() {
|
export function SettingsLicense() {
|
||||||
return (
|
return (
|
||||||
@@ -135,7 +135,7 @@ function SettingsLicenseCmp() {
|
|||||||
<Button
|
<Button
|
||||||
color="secondary"
|
color="secondary"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => openUrl("https://yaak.app/dashboard?intent=app.license.support")}
|
onClick={() => platform.openUrl("https://yaak.app/dashboard?intent=app.license.support")}
|
||||||
rightSlot={<Icon icon="external_link" />}
|
rightSlot={<Icon icon="external_link" />}
|
||||||
>
|
>
|
||||||
Direct Support
|
Direct Support
|
||||||
@@ -151,7 +151,7 @@ function SettingsLicenseCmp() {
|
|||||||
color="primary"
|
color="primary"
|
||||||
rightSlot={<Icon icon="external_link" />}
|
rightSlot={<Icon icon="external_link" />}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openUrl(pricingUrl(`app.license.purchase.${check.data?.status ?? "unknown"}`))
|
platform.openUrl(pricingUrl(`app.license.purchase.${check.data?.status ?? "unknown"}`))
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
Purchase License
|
Purchase License
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
|
||||||
import type { Plugin } from "@yaakapp-internal/models";
|
import type { Plugin } from "@yaakapp-internal/models";
|
||||||
import { patchModel, pluginsAtom } from "@yaakapp-internal/models";
|
import { patchModel, pluginsAtom } from "@yaakapp-internal/models";
|
||||||
import type { PluginVersion } from "@yaakapp-internal/plugins";
|
import type { PluginVersion } from "@yaakapp-internal/plugins";
|
||||||
@@ -39,6 +38,7 @@ import { PlainInput } from "../core/PlainInput";
|
|||||||
import { TabContent, Tabs } from "../core/Tabs/Tabs";
|
import { TabContent, Tabs } from "../core/Tabs/Tabs";
|
||||||
import { EmptyStateText } from "../EmptyStateText";
|
import { EmptyStateText } from "../EmptyStateText";
|
||||||
import { SelectFile } from "../SelectFile";
|
import { SelectFile } from "../SelectFile";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
interface SettingsPluginsProps {
|
interface SettingsPluginsProps {
|
||||||
defaultSubtab?: string;
|
defaultSubtab?: string;
|
||||||
@@ -113,7 +113,7 @@ export function SettingsPlugins({ defaultSubtab }: SettingsPluginsProps) {
|
|||||||
icon="help"
|
icon="help"
|
||||||
title="View documentation"
|
title="View documentation"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
openUrl("https://yaak.app/docs/plugin-development/plugins-quick-start")
|
platform.openUrl("https://yaak.app/docs/plugin-development/plugins-quick-start")
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</HStack>
|
</HStack>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { openUrl } from "@tauri-apps/plugin-opener";
|
|
||||||
import { useLicense } from "@yaakapp-internal/license";
|
import { useLicense } from "@yaakapp-internal/license";
|
||||||
import { useRef } from "react";
|
import { useRef } from "react";
|
||||||
import { openSettings } from "../commands/openSettings";
|
import { openSettings } from "../commands/openSettings";
|
||||||
@@ -13,6 +12,7 @@ import { Dropdown } from "./core/Dropdown";
|
|||||||
import { Icon } from "@yaakapp-internal/ui";
|
import { Icon } from "@yaakapp-internal/ui";
|
||||||
import { IconButton } from "./core/IconButton";
|
import { IconButton } from "./core/IconButton";
|
||||||
import { KeyboardShortcutsDialog } from "./KeyboardShortcutsDialog";
|
import { KeyboardShortcutsDialog } from "./KeyboardShortcutsDialog";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
export function SettingsDropdown() {
|
export function SettingsDropdown() {
|
||||||
const exportData = useExportData();
|
const exportData = useExportData();
|
||||||
@@ -62,7 +62,7 @@ export function SettingsDropdown() {
|
|||||||
{
|
{
|
||||||
label: "Create Run Button",
|
label: "Create Run Button",
|
||||||
leftSlot: <Icon icon="rocket" />,
|
leftSlot: <Icon icon="rocket" />,
|
||||||
onSelect: () => openUrl("https://yaak.app/button/new"),
|
onSelect: () => platform.openUrl("https://yaak.app/button/new"),
|
||||||
},
|
},
|
||||||
{ type: "separator", label: `Yaak v${appInfo.version}` },
|
{ type: "separator", label: `Yaak v${appInfo.version}` },
|
||||||
{
|
{
|
||||||
@@ -78,26 +78,26 @@ export function SettingsDropdown() {
|
|||||||
leftSlot: <Icon icon="circle_dollar_sign" />,
|
leftSlot: <Icon icon="circle_dollar_sign" />,
|
||||||
rightSlot: <Icon icon="external_link" color="success" className="opacity-60" />,
|
rightSlot: <Icon icon="external_link" color="success" className="opacity-60" />,
|
||||||
onSelect: () =>
|
onSelect: () =>
|
||||||
openUrl(pricingUrl(`app.menu.purchase.${check.data?.status ?? "unknown"}`)),
|
platform.openUrl(pricingUrl(`app.menu.purchase.${check.data?.status ?? "unknown"}`)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Install CLI",
|
label: "Install CLI",
|
||||||
hidden: appInfo.cliVersion != null,
|
hidden: appInfo.cliVersion != null,
|
||||||
leftSlot: <Icon icon="square_terminal" />,
|
leftSlot: <Icon icon="square_terminal" />,
|
||||||
rightSlot: <Icon icon="external_link" color="secondary" />,
|
rightSlot: <Icon icon="external_link" color="secondary" />,
|
||||||
onSelect: () => openUrl("https://yaak.app/docs/cli"),
|
onSelect: () => platform.openUrl("https://yaak.app/docs/cli"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Feedback",
|
label: "Feedback",
|
||||||
leftSlot: <Icon icon="chat" />,
|
leftSlot: <Icon icon="chat" />,
|
||||||
rightSlot: <Icon icon="external_link" color="secondary" />,
|
rightSlot: <Icon icon="external_link" color="secondary" />,
|
||||||
onSelect: () => openUrl("https://yaak.app/feedback"),
|
onSelect: () => platform.openUrl("https://yaak.app/feedback"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Changelog",
|
label: "Changelog",
|
||||||
leftSlot: <Icon icon="cake" />,
|
leftSlot: <Icon icon="cake" />,
|
||||||
rightSlot: <Icon icon="external_link" color="secondary" />,
|
rightSlot: <Icon icon="external_link" color="secondary" />,
|
||||||
onSelect: () => openUrl(`https://yaak.app/changelog/${appInfo.version}`),
|
onSelect: () => platform.openUrl(`https://yaak.app/changelog/${appInfo.version}`),
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { Extension } from "@codemirror/state";
|
import type { Extension } from "@codemirror/state";
|
||||||
import { Compartment } from "@codemirror/state";
|
import { Compartment } from "@codemirror/state";
|
||||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
|
||||||
import { debounce } from "@yaakapp-internal/lib";
|
import { debounce } from "@yaakapp-internal/lib";
|
||||||
import { gitMutations } from "@yaakapp-internal/git";
|
import { gitMutations } from "@yaakapp-internal/git";
|
||||||
import type { GitStatus } from "@yaakapp-internal/git";
|
import type { GitStatus } from "@yaakapp-internal/git";
|
||||||
@@ -44,7 +43,8 @@ import { getFolderActions } from "../hooks/useFolderActions";
|
|||||||
import { getGrpcRequestActions } from "../hooks/useGrpcRequestActions";
|
import { getGrpcRequestActions } from "../hooks/useGrpcRequestActions";
|
||||||
import { useHotKey } from "../hooks/useHotKey";
|
import { useHotKey } from "../hooks/useHotKey";
|
||||||
import { getHttpRequestActions } from "../hooks/useHttpRequestActions";
|
import { getHttpRequestActions } from "../hooks/useHttpRequestActions";
|
||||||
import { useListenToTauriEvent } from "../hooks/useListenToTauriEvent";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
import { usePlatformEvent } from "../hooks/usePlatformEvent";
|
||||||
import { getModelAncestors } from "../hooks/useModelAncestors";
|
import { getModelAncestors } from "../hooks/useModelAncestors";
|
||||||
import { sendAnyHttpRequest } from "../hooks/useSendAnyHttpRequest";
|
import { sendAnyHttpRequest } from "../hooks/useSendAnyHttpRequest";
|
||||||
import { useSidebarHidden } from "../hooks/useSidebarHidden";
|
import { useSidebarHidden } from "../hooks/useSidebarHidden";
|
||||||
@@ -135,10 +135,10 @@ function Sidebar({ className }: { className?: string }) {
|
|||||||
// Focus new sidebar models created by the user in this window. Writes from other
|
// Focus new sidebar models created by the user in this window. Writes from other
|
||||||
// sources (import, sync, CLI) can carry thousands of models and shouldn't move
|
// sources (import, sync, CLI) can carry thousands of models and shouldn't move
|
||||||
// the selection.
|
// the selection.
|
||||||
useListenToTauriEvent<ModelPayload[]>("model_writes", ({ payload: payloads }) => {
|
usePlatformEvent<ModelPayload[]>("model_writes", (payloads) => {
|
||||||
for (const payload of payloads) {
|
for (const payload of payloads) {
|
||||||
if (payload.updateSource.type !== "window") continue;
|
if (payload.updateSource.type !== "window") continue;
|
||||||
if (payload.updateSource.label !== getCurrentWebviewWindow().label) continue;
|
if (payload.updateSource.label !== platform.window.label) continue;
|
||||||
if (!isSidebarLeafModel(payload.model)) continue;
|
if (!isSidebarLeafModel(payload.model)) continue;
|
||||||
if (!(payload.change.type === "upsert" && payload.change.created)) continue;
|
if (!(payload.change.type === "upsert" && payload.change.created)) continue;
|
||||||
treeRef.current?.selectItem(payload.model.id, true);
|
treeRef.current?.selectItem(payload.model.id, true);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { readDir } from "@tauri-apps/plugin-fs";
|
|
||||||
import { Banner, VStack } from "@yaakapp-internal/ui";
|
import { Banner, VStack } from "@yaakapp-internal/ui";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { openWorkspaceFromSyncDir } from "../commands/openWorkspaceFromSyncDir";
|
import { openWorkspaceFromSyncDir } from "../commands/openWorkspaceFromSyncDir";
|
||||||
@@ -6,6 +5,7 @@ import { Button } from "./core/Button";
|
|||||||
import { Checkbox } from "./core/Checkbox";
|
import { Checkbox } from "./core/Checkbox";
|
||||||
import { SettingRowBoolean, SettingRowDirectory } from "./core/SettingRow";
|
import { SettingRowBoolean, SettingRowDirectory } from "./core/SettingRow";
|
||||||
import { SelectFile } from "./SelectFile";
|
import { SelectFile } from "./SelectFile";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
export interface SyncToFilesystemSettingProps {
|
export interface SyncToFilesystemSettingProps {
|
||||||
layout?: "form" | "settings";
|
layout?: "form" | "settings";
|
||||||
@@ -24,7 +24,7 @@ export function SyncToFilesystemSetting({
|
|||||||
|
|
||||||
const handleFilePathChange = async (filePath: string | null) => {
|
const handleFilePathChange = async (filePath: string | null) => {
|
||||||
if (filePath != null) {
|
if (filePath != null) {
|
||||||
const files = await readDir(filePath);
|
const files = await platform.files.readDir(filePath);
|
||||||
if (files.length > 0) {
|
if (files.length > 0) {
|
||||||
setSyncDir(filePath);
|
setSyncDir(filePath);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type } from "@tauri-apps/plugin-os";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import { settingsAtom, workspacesAtom } from "@yaakapp-internal/models";
|
import { settingsAtom, workspacesAtom } from "@yaakapp-internal/models";
|
||||||
import { Banner, HeaderSize, HStack, SidebarLayout } from "@yaakapp-internal/ui";
|
import { Banner, HeaderSize, HStack, SidebarLayout } from "@yaakapp-internal/ui";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
@@ -53,7 +53,7 @@ export function Workspace() {
|
|||||||
|
|
||||||
const workspaces = useAtomValue(workspacesAtom);
|
const workspaces = useAtomValue(workspacesAtom);
|
||||||
const settings = useAtomValue(settingsAtom);
|
const settings = useAtomValue(settingsAtom);
|
||||||
const osType = type();
|
const osType = platform.osType();
|
||||||
const [width, setWidth] = useSidebarWidth();
|
const [width, setWidth] = useSidebarWidth();
|
||||||
const [sidebarHidden, setSidebarHidden] = useSidebarHidden();
|
const [sidebarHidden, setSidebarHidden] = useSidebarHidden();
|
||||||
const [floatingSidebarHidden, setFloatingSidebarHidden] = useFloatingSidebarHidden();
|
const [floatingSidebarHidden, setFloatingSidebarHidden] = useFloatingSidebarHidden();
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
import { open } from "@tauri-apps/plugin-dialog";
|
|
||||||
import { revealItemInDir } from "@tauri-apps/plugin-opener";
|
|
||||||
import { getModel, settingsAtom, workspacesAtom } from "@yaakapp-internal/models";
|
import { getModel, settingsAtom, workspacesAtom } from "@yaakapp-internal/models";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
@@ -27,6 +25,7 @@ import { Icon } from "@yaakapp-internal/ui";
|
|||||||
import type { RadioDropdownItem } from "./core/RadioDropdown";
|
import type { RadioDropdownItem } from "./core/RadioDropdown";
|
||||||
import { RadioDropdown } from "./core/RadioDropdown";
|
import { RadioDropdown } from "./core/RadioDropdown";
|
||||||
import { SwitchWorkspaceDialog } from "./SwitchWorkspaceDialog";
|
import { SwitchWorkspaceDialog } from "./SwitchWorkspaceDialog";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
type Props = Pick<ButtonProps, "className" | "justify" | "forDropdown" | "leftSlot">;
|
type Props = Pick<ButtonProps, "className" | "justify" | "forDropdown" | "leftSlot">;
|
||||||
|
|
||||||
@@ -76,7 +75,7 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
|
|||||||
label: "Open Folder",
|
label: "Open Folder",
|
||||||
leftSlot: <Icon icon="folder_open" />,
|
leftSlot: <Icon icon="folder_open" />,
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
const dir = await open({
|
const dir = await platform.dialog.open({
|
||||||
title: "Select Workspace Directory",
|
title: "Select Workspace Directory",
|
||||||
directory: true,
|
directory: true,
|
||||||
multiple: false,
|
multiple: false,
|
||||||
@@ -120,7 +119,7 @@ export const WorkspaceActionsDropdown = memo(function WorkspaceActionsDropdown({
|
|||||||
leftSlot: <Icon icon="folder_symlink" />,
|
leftSlot: <Icon icon="folder_symlink" />,
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
if (workspaceMeta?.settingSyncDir == null) return;
|
if (workspaceMeta?.settingSyncDir == null) return;
|
||||||
await revealItemInDir(workspaceMeta.settingSyncDir);
|
await platform.revealItemInDir(workspaceMeta.settingSyncDir);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { CookieDropdown } from "./CookieDropdown";
|
|||||||
import { IconButton } from "./core/IconButton";
|
import { IconButton } from "./core/IconButton";
|
||||||
import { PillButton } from "./core/PillButton";
|
import { PillButton } from "./core/PillButton";
|
||||||
import { EnvironmentActionsDropdown } from "./EnvironmentActionsDropdown";
|
import { EnvironmentActionsDropdown } from "./EnvironmentActionsDropdown";
|
||||||
import { ImportCurlButton } from "./ImportCurlButton";
|
import { ImportCurl } from "./ImportCurl";
|
||||||
import { LicenseBadge } from "./LicenseBadge";
|
import { LicenseBadge } from "./LicenseBadge";
|
||||||
import { RecentRequestsDropdown } from "./RecentRequestsDropdown";
|
import { RecentRequestsDropdown } from "./RecentRequestsDropdown";
|
||||||
import { SettingsDropdown } from "./SettingsDropdown";
|
import { SettingsDropdown } from "./SettingsDropdown";
|
||||||
@@ -56,7 +56,7 @@ export const WorkspaceHeader = memo(function WorkspaceHeader({
|
|||||||
<RecentRequestsDropdown />
|
<RecentRequestsDropdown />
|
||||||
</div>
|
</div>
|
||||||
<div className="flex-1 flex gap-1 items-center h-full justify-end pointer-events-none pr-1">
|
<div className="flex-1 flex gap-1 items-center h-full justify-end pointer-events-none pr-1">
|
||||||
<ImportCurlButton />
|
<ImportCurl />
|
||||||
{showEncryptionSetup ? (
|
{showEncryptionSetup ? (
|
||||||
<PillButton color="danger" onClick={setupOrConfigureEncryption}>
|
<PillButton color="danger" onClick={setupOrConfigureEncryption}>
|
||||||
Enter Encryption Key
|
Enter Encryption Key
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
import { Icon } from "@yaakapp-internal/ui";
|
||||||
|
import classNames from "classnames";
|
||||||
|
import type { ReactNode } from "react";
|
||||||
|
import { useState } from "react";
|
||||||
|
import type { CheckboxProps } from "./Checkbox";
|
||||||
|
import { Checkbox } from "./Checkbox";
|
||||||
|
|
||||||
|
export interface CheckboxTreeNode<T> {
|
||||||
|
key: string;
|
||||||
|
data: T;
|
||||||
|
children: CheckboxTreeNode<T>[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Props<T> {
|
||||||
|
node: CheckboxTreeNode<T>;
|
||||||
|
depth?: number;
|
||||||
|
/** Return "hidden" to render row alignment space instead of a checkbox */
|
||||||
|
checked: (node: CheckboxTreeNode<T>) => CheckboxProps["checked"] | "hidden";
|
||||||
|
onCheck: (node: CheckboxTreeNode<T>, checked: boolean) => void;
|
||||||
|
checkboxTitle?: (node: CheckboxTreeNode<T>) => string;
|
||||||
|
isCheckboxDisabled?: (node: CheckboxTreeNode<T>) => boolean;
|
||||||
|
/** An irrelevant row is hidden unless one of its descendants is relevant */
|
||||||
|
isRelevant: (node: CheckboxTreeNode<T>) => boolean;
|
||||||
|
renderRow: (node: CheckboxTreeNode<T>) => ReactNode;
|
||||||
|
onSelectRow?: (node: CheckboxTreeNode<T>) => void;
|
||||||
|
canSelectRow?: (node: CheckboxTreeNode<T>) => boolean;
|
||||||
|
isRowSelected?: (node: CheckboxTreeNode<T>) => boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function CheckboxTree<T>(props: Props<T>) {
|
||||||
|
const { node, depth = 0 } = props;
|
||||||
|
const [collapsed, setCollapsed] = useState<boolean>(false);
|
||||||
|
if (!hasRelevantNode(node, props.isRelevant)) return null;
|
||||||
|
|
||||||
|
const checked = props.checked(node);
|
||||||
|
const selected = props.isRowSelected?.(node) ?? false;
|
||||||
|
const selectable = props.onSelectRow != null && (props.canSelectRow?.(node) ?? true);
|
||||||
|
const hasVisibleChildren = node.children.some((c) => hasRelevantNode(c, props.isRelevant));
|
||||||
|
const rowContent = (
|
||||||
|
<div className="flex-1 min-w-0 flex items-center gap-1 px-1 py-0.5 text-left">
|
||||||
|
{props.renderRow(node)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={classNames(
|
||||||
|
depth > 0 && "pl-4 ml-2 border-l border-dashed border-border-subtle relative",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={classNames(
|
||||||
|
"relative flex gap-1 w-full h-xs items-center",
|
||||||
|
selected ? "text-text" : "text-text-subtle",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{selected && (
|
||||||
|
<div className="absolute left-[-100vw] right-0 top-0 bottom-0 bg-surface-active opacity-30 -z-10" />
|
||||||
|
)}
|
||||||
|
{hasVisibleChildren ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={collapsed ? "Expand" : "Collapse"}
|
||||||
|
aria-expanded={!collapsed}
|
||||||
|
className="shrink-0 text-text-subtlest hocus:text-text"
|
||||||
|
onClick={() => setCollapsed((v) => !v)}
|
||||||
|
>
|
||||||
|
<Icon size="sm" icon={collapsed ? "chevron_right" : "chevron_down"} />
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
<span aria-hidden className="w-4 shrink-0" />
|
||||||
|
)}
|
||||||
|
{checked === "hidden" ? (
|
||||||
|
<span aria-hidden className="w-4 mr-0.5 shrink-0" />
|
||||||
|
) : (
|
||||||
|
<Checkbox
|
||||||
|
checked={checked}
|
||||||
|
title={props.checkboxTitle?.(node) ?? "Toggle"}
|
||||||
|
hideLabel
|
||||||
|
disabled={props.isCheckboxDisabled?.(node)}
|
||||||
|
onChange={(checked) => props.onCheck(node, checked)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{selectable ? (
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="flex-1 min-w-0 flex text-left"
|
||||||
|
onClick={() => props.onSelectRow?.(node)}
|
||||||
|
>
|
||||||
|
{rowContent}
|
||||||
|
</button>
|
||||||
|
) : (
|
||||||
|
rowContent
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!collapsed &&
|
||||||
|
node.children.map((child) => (
|
||||||
|
<CheckboxTree key={child.key} {...props} node={child} depth={depth + 1} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasRelevantNode<T>(
|
||||||
|
node: CheckboxTreeNode<T>,
|
||||||
|
isRelevant: (node: CheckboxTreeNode<T>) => boolean,
|
||||||
|
): boolean {
|
||||||
|
return isRelevant(node) || node.children.some((c) => hasRelevantNode(c, isRelevant));
|
||||||
|
}
|
||||||
@@ -10,11 +10,13 @@ export interface DialogProps {
|
|||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
disableBackdropClose?: boolean;
|
/** Block dismissal from the backdrop, Escape key, and built-in close button. */
|
||||||
|
disableClose?: boolean;
|
||||||
title?: ReactNode;
|
title?: ReactNode;
|
||||||
description?: ReactNode;
|
description?: ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
size?: DialogSize;
|
size?: DialogSize;
|
||||||
|
/** Hide the built-in close button without changing backdrop or Escape behavior. */
|
||||||
hideX?: boolean;
|
hideX?: boolean;
|
||||||
noPadding?: boolean;
|
noPadding?: boolean;
|
||||||
noScroll?: boolean;
|
noScroll?: boolean;
|
||||||
@@ -27,7 +29,7 @@ export function Dialog({
|
|||||||
size = "full",
|
size = "full",
|
||||||
open,
|
open,
|
||||||
onClose,
|
onClose,
|
||||||
disableBackdropClose,
|
disableClose,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
hideX,
|
hideX,
|
||||||
@@ -42,7 +44,7 @@ export function Dialog({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Overlay open={open} onClose={disableBackdropClose ? undefined : onClose} portalName="dialog">
|
<Overlay open={open} onClose={disableClose ? undefined : onClose} portalName="dialog">
|
||||||
<div
|
<div
|
||||||
role="dialog"
|
role="dialog"
|
||||||
className={classNames(
|
className={classNames(
|
||||||
@@ -58,7 +60,7 @@ export function Dialog({
|
|||||||
// NOTE: We handle Escape on the element itself so that it doesn't close multiple
|
// NOTE: We handle Escape on the element itself so that it doesn't close multiple
|
||||||
// dialogs and can be intercepted by children if needed.
|
// dialogs and can be intercepted by children if needed.
|
||||||
if (e.key === "Escape") {
|
if (e.key === "Escape") {
|
||||||
onClose?.();
|
if (!disableClose) onClose?.();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
@@ -110,7 +112,7 @@ export function Dialog({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/*Put close at the end so that it's the last thing to be tabbed to*/}
|
{/*Put close at the end so that it's the last thing to be tabbed to*/}
|
||||||
{!hideX && (
|
{!disableClose && !hideX && (
|
||||||
<div className="ml-auto absolute right-1 top-1">
|
<div className="ml-auto absolute right-1 top-1">
|
||||||
<IconButton
|
<IconButton
|
||||||
className="opacity-70 hover:opacity-100"
|
className="opacity-70 hover:opacity-100"
|
||||||
|
|||||||
@@ -36,12 +36,16 @@ import { fireAndForget } from "../../lib/fireAndForget";
|
|||||||
import { ErrorBoundary } from "../ErrorBoundary";
|
import { ErrorBoundary } from "../ErrorBoundary";
|
||||||
import { Button } from "./Button";
|
import { Button } from "./Button";
|
||||||
import { Hotkey } from "./Hotkey";
|
import { Hotkey } from "./Hotkey";
|
||||||
|
import { IconButton } from "./IconButton";
|
||||||
|
import type { SeparatorAction } from "./Separator";
|
||||||
import { Separator } from "./Separator";
|
import { Separator } from "./Separator";
|
||||||
|
|
||||||
export type DropdownItemSeparator = {
|
export type DropdownItemSeparator = {
|
||||||
type: "separator";
|
type: "separator";
|
||||||
label?: ReactNode;
|
label?: ReactNode;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
|
/** A control shown beside the label, eg. revealing the labelled file on disk. */
|
||||||
|
action?: SeparatorAction;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DropdownItemContent = {
|
export type DropdownItemContent = {
|
||||||
@@ -66,6 +70,12 @@ export type DropdownItemDefault = {
|
|||||||
submenu?: DropdownItem[];
|
submenu?: DropdownItem[];
|
||||||
/** If true, submenu opens on click instead of hover */
|
/** If true, submenu opens on click instead of hover */
|
||||||
submenuOpenOnClick?: boolean;
|
submenuOpenOnClick?: boolean;
|
||||||
|
/**
|
||||||
|
* How the submenu opens. "row" (default) opens it from the row itself (hover, or click
|
||||||
|
* with submenuOpenOnClick). "button" keeps the row selectable via onSelect and renders
|
||||||
|
* a dedicated button on the right that opens the submenu.
|
||||||
|
*/
|
||||||
|
submenuTrigger?: "row" | "button";
|
||||||
icon?: IconProps["icon"];
|
icon?: IconProps["icon"];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -502,9 +512,15 @@ const Menu = forwardRef<Omit<DropdownRef, "open" | "isOpen" | "toggle" | "items"
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item.keepOpenOnSelect) handleCloseAll();
|
if (!item.keepOpenOnSelect) {
|
||||||
|
handleCloseAll();
|
||||||
|
} else if (isSubmenu) {
|
||||||
|
// Keep the parent menu open, but close this submenu — its items may no
|
||||||
|
// longer describe the row after the action (e.g. Pin → Unpin, Remove)
|
||||||
|
handleClose();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[handleCloseAll, setSelectedIndex],
|
[handleCloseAll, handleClose, isSubmenu, setSelectedIndex],
|
||||||
);
|
);
|
||||||
|
|
||||||
useImperativeHandle(ref, () => {
|
useImperativeHandle(ref, () => {
|
||||||
@@ -629,7 +645,7 @@ const Menu = forwardRef<Omit<DropdownRef, "open" | "isOpen" | "toggle" | "items"
|
|||||||
const item = filteredItems[selectedIndex ?? -1];
|
const item = filteredItems[selectedIndex ?? -1];
|
||||||
if (!item || item.type === "separator" || item.type === "content") return;
|
if (!item || item.type === "separator" || item.type === "content") return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (item.submenu) {
|
if (item.submenu && item.submenuTrigger !== "button") {
|
||||||
const parent = document.activeElement as HTMLButtonElement;
|
const parent = document.activeElement as HTMLButtonElement;
|
||||||
if (parent) {
|
if (parent) {
|
||||||
setActiveSubmenu({ item, parent, viaKeyboard: true });
|
setActiveSubmenu({ item, parent, viaKeyboard: true });
|
||||||
@@ -648,9 +664,11 @@ const Menu = forwardRef<Omit<DropdownRef, "open" | "isOpen" | "toggle" | "items"
|
|||||||
clearTimeout(submenuTimeoutRef.current);
|
clearTimeout(submenuTimeoutRef.current);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.submenu && !item.submenuOpenOnClick) {
|
if (item.submenu && !item.submenuOpenOnClick && item.submenuTrigger !== "button") {
|
||||||
setActiveSubmenu({ item, parent });
|
setActiveSubmenu({ item, parent });
|
||||||
} else if (activeSubmenu) {
|
} else if (activeSubmenu && activeSubmenu.item !== item) {
|
||||||
|
// Hovering the row that owns the open submenu must not dismiss it — the
|
||||||
|
// pointer travels across the row on its way to a button-triggered submenu
|
||||||
submenuTimeoutRef.current = window.setTimeout(() => {
|
submenuTimeoutRef.current = window.setTimeout(() => {
|
||||||
const submenuEl = submenuRef.current;
|
const submenuEl = submenuRef.current;
|
||||||
if (!submenuEl || !activeSubmenu) {
|
if (!submenuEl || !activeSubmenu) {
|
||||||
@@ -776,6 +794,7 @@ const Menu = forwardRef<Omit<DropdownRef, "open" | "isOpen" | "toggle" | "items"
|
|||||||
// oxlint-disable-next-line no-array-index-key -- Nothing else available
|
// oxlint-disable-next-line no-array-index-key -- Nothing else available
|
||||||
key={i}
|
key={i}
|
||||||
className={classNames("my-1.5", item.label ? "ml-2" : null)}
|
className={classNames("my-1.5", item.label ? "ml-2" : null)}
|
||||||
|
action={item.action}
|
||||||
>
|
>
|
||||||
{item.label}
|
{item.label}
|
||||||
</Separator>
|
</Separator>
|
||||||
@@ -797,6 +816,7 @@ const Menu = forwardRef<Omit<DropdownRef, "open" | "isOpen" | "toggle" | "items"
|
|||||||
onFocus={handleFocus}
|
onFocus={handleFocus}
|
||||||
onSelect={handleSelect}
|
onSelect={handleSelect}
|
||||||
onHover={handleItemHover}
|
onHover={handleItemHover}
|
||||||
|
onOpenSubmenu={(item, el) => setActiveSubmenu({ item, parent: el })}
|
||||||
// oxlint-disable-next-line no-array-index-key -- It's fine
|
// oxlint-disable-next-line no-array-index-key -- It's fine
|
||||||
key={i}
|
key={i}
|
||||||
item={item}
|
item={item}
|
||||||
@@ -868,6 +888,7 @@ interface MenuItemProps {
|
|||||||
onSelect: (item: DropdownItemDefault, el?: HTMLButtonElement) => Promise<void>;
|
onSelect: (item: DropdownItemDefault, el?: HTMLButtonElement) => Promise<void>;
|
||||||
onFocus: (item: DropdownItemDefault) => void;
|
onFocus: (item: DropdownItemDefault) => void;
|
||||||
onHover: (item: DropdownItemDefault, el: HTMLButtonElement) => void;
|
onHover: (item: DropdownItemDefault, el: HTMLButtonElement) => void;
|
||||||
|
onOpenSubmenu: (item: DropdownItemDefault, el: HTMLButtonElement) => void;
|
||||||
focused: boolean;
|
focused: boolean;
|
||||||
isParentOfActiveSubmenu?: boolean;
|
isParentOfActiveSubmenu?: boolean;
|
||||||
}
|
}
|
||||||
@@ -879,6 +900,7 @@ function MenuItem({
|
|||||||
onHover,
|
onHover,
|
||||||
item,
|
item,
|
||||||
onSelect,
|
onSelect,
|
||||||
|
onOpenSubmenu,
|
||||||
isParentOfActiveSubmenu,
|
isParentOfActiveSubmenu,
|
||||||
...props
|
...props
|
||||||
}: MenuItemProps) {
|
}: MenuItemProps) {
|
||||||
@@ -914,19 +936,22 @@ function MenuItem({
|
|||||||
e.currentTarget.focus();
|
e.currentTarget.focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
const rightSlot = item.submenu ? (
|
const hasButtonSubmenu = item.submenu != null && item.submenuTrigger === "button";
|
||||||
<Icon icon="chevron_right" color="secondary" />
|
|
||||||
) : (
|
|
||||||
(item.rightSlot ?? <Hotkey variant="text" action={item.hotKeyAction ?? null} />)
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
const rightSlot =
|
||||||
|
item.submenu && !hasButtonSubmenu ? (
|
||||||
|
<Icon icon="chevron_right" color="secondary" />
|
||||||
|
) : (
|
||||||
|
(item.rightSlot ?? <Hotkey variant="text" action={item.hotKeyAction ?? null} />)
|
||||||
|
);
|
||||||
|
|
||||||
|
const button = (
|
||||||
<Button
|
<Button
|
||||||
ref={initRef}
|
ref={initRef}
|
||||||
size="sm"
|
size="sm"
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
onMouseEnter={handleMouseEnter}
|
onMouseEnter={hasButtonSubmenu ? undefined : handleMouseEnter}
|
||||||
onMouseLeave={(e) => e.currentTarget.blur()}
|
onMouseLeave={hasButtonSubmenu ? undefined : (e) => e.currentTarget.blur()}
|
||||||
disabled={item.disabled}
|
disabled={item.disabled}
|
||||||
onFocus={handleFocus}
|
onFocus={handleFocus}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
@@ -947,6 +972,7 @@ function MenuItem({
|
|||||||
"min-w-32 outline-hidden px-2 mx-1.5 flex whitespace-nowrap",
|
"min-w-32 outline-hidden px-2 mx-1.5 flex whitespace-nowrap",
|
||||||
"focus:bg-surface-highlight focus:text rounded-sm focus:outline-hidden focus-visible:outline-1",
|
"focus:bg-surface-highlight focus:text rounded-sm focus:outline-hidden focus-visible:outline-1",
|
||||||
isParentOfActiveSubmenu && "bg-surface-highlight text rounded-sm",
|
isParentOfActiveSubmenu && "bg-surface-highlight text rounded-sm",
|
||||||
|
hasButtonSubmenu && "pr-8",
|
||||||
item.color === "danger" && "text-danger!",
|
item.color === "danger" && "text-danger!",
|
||||||
item.color === "primary" && "text-primary!",
|
item.color === "primary" && "text-primary!",
|
||||||
item.color === "success" && "text-success!",
|
item.color === "success" && "text-success!",
|
||||||
@@ -959,6 +985,52 @@ function MenuItem({
|
|||||||
<div className={classNames("truncate min-w-20")}>{item.label}</div>
|
<div className={classNames("truncate min-w-20")}>{item.label}</div>
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!hasButtonSubmenu) {
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The submenu trigger overlays the row as a sibling (not a child) because the row is
|
||||||
|
// itself a button and buttons cannot nest. Hover handling lives on this wrapper so the
|
||||||
|
// row keeps its focus highlight while the mouse is over the trigger.
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="relative grid group/menuitem"
|
||||||
|
onMouseEnter={() => {
|
||||||
|
const el = buttonRef.current;
|
||||||
|
if (el == null) return;
|
||||||
|
onHover(item, el);
|
||||||
|
el.focus();
|
||||||
|
}}
|
||||||
|
onMouseLeave={() => buttonRef.current?.blur()}
|
||||||
|
>
|
||||||
|
{button}
|
||||||
|
<div
|
||||||
|
className={classNames(
|
||||||
|
"absolute right-1.5 inset-y-0 flex items-center",
|
||||||
|
"opacity-0 group-hover/menuitem:opacity-100 group-focus-within/menuitem:opacity-100",
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<IconButton
|
||||||
|
color="custom"
|
||||||
|
size="2xs"
|
||||||
|
tabIndex={-1}
|
||||||
|
icon="ellipsis_vertical"
|
||||||
|
iconColor="secondary"
|
||||||
|
title="More actions"
|
||||||
|
className="h-full! w-7!"
|
||||||
|
onMouseDown={(e) => {
|
||||||
|
// Prevent the trigger from stealing focus, which would unhighlight the row
|
||||||
|
e.preventDefault();
|
||||||
|
}}
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
onOpenSubmenu(item, e.currentTarget);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MenuItemHotKeyProps {
|
interface MenuItemHotKeyProps {
|
||||||
|
|||||||
@@ -601,6 +601,8 @@ function getExtensions({
|
|||||||
EditorView.contentAttributes.of({
|
EditorView.contentAttributes.of({
|
||||||
autocapitalize: "off",
|
autocapitalize: "off",
|
||||||
autocorrect: "off",
|
autocorrect: "off",
|
||||||
|
// Keeps macOS Writing Tools from offering to write code for us
|
||||||
|
writingsuggestions: "false",
|
||||||
}),
|
}),
|
||||||
EditorView.domEventHandlers({
|
EditorView.domEventHandlers({
|
||||||
focus: () => {
|
focus: () => {
|
||||||
|
|||||||
@@ -1,9 +1,29 @@
|
|||||||
import type { Diagnostic } from "@codemirror/lint";
|
import type { Diagnostic } from "@codemirror/lint";
|
||||||
import type { EditorView } from "@codemirror/view";
|
import type { EditorView } from "@codemirror/view";
|
||||||
import { parse as jsonLintParse } from "@prantlf/jsonlint";
|
import { type ParseError, parse, printParseErrorCode } from "jsonc-parser";
|
||||||
|
|
||||||
const TEMPLATE_SYNTAX_REGEX = /\$\{\[[\s\S]*?]}/g;
|
const TEMPLATE_SYNTAX_REGEX = /\$\{\[[\s\S]*?]}/g;
|
||||||
|
|
||||||
|
// jsonc-parser reports error codes, so these are the words the editor shows for them
|
||||||
|
const MESSAGES: Record<string, string> = {
|
||||||
|
InvalidSymbol: "Invalid symbol",
|
||||||
|
InvalidNumberFormat: "Invalid number format",
|
||||||
|
PropertyNameExpected: "Property name expected",
|
||||||
|
ValueExpected: "Value expected",
|
||||||
|
ColonExpected: "Colon expected",
|
||||||
|
CommaExpected: "Comma expected",
|
||||||
|
CloseBraceExpected: "Closing brace expected",
|
||||||
|
CloseBracketExpected: "Closing bracket expected",
|
||||||
|
EndOfFileExpected: "End of file expected",
|
||||||
|
InvalidCommentToken: "Comments are not allowed",
|
||||||
|
UnexpectedEndOfComment: "Unexpected end of comment",
|
||||||
|
UnexpectedEndOfString: "Unexpected end of string",
|
||||||
|
UnexpectedEndOfNumber: "Unexpected end of number",
|
||||||
|
InvalidUnicode: "Invalid unicode sequence",
|
||||||
|
InvalidEscapeCharacter: "Invalid escape character",
|
||||||
|
InvalidCharacter: "Invalid character",
|
||||||
|
};
|
||||||
|
|
||||||
interface JsonLintOptions {
|
interface JsonLintOptions {
|
||||||
allowComments?: boolean;
|
allowComments?: boolean;
|
||||||
allowTrailingCommas?: boolean;
|
allowTrailingCommas?: boolean;
|
||||||
@@ -11,34 +31,28 @@ interface JsonLintOptions {
|
|||||||
|
|
||||||
export function jsonParseLinter(options?: JsonLintOptions) {
|
export function jsonParseLinter(options?: JsonLintOptions) {
|
||||||
return (view: EditorView): Diagnostic[] => {
|
return (view: EditorView): Diagnostic[] => {
|
||||||
try {
|
const doc = view.state.doc.toString();
|
||||||
const doc = view.state.doc.toString();
|
// We need lint to not break on stuff like {"foo:" ${[ ... ]}} so we'll replace all template
|
||||||
// We need lint to not break on stuff like {"foo:" ${[ ... ]}} so we'll replace all template
|
// syntax with repeating `1` characters, so it's valid JSON and the position is still correct.
|
||||||
// syntax with repeating `1` characters, so it's valid JSON and the position is still correct.
|
const escapedDoc = doc.replace(TEMPLATE_SYNTAX_REGEX, (m) => "1".repeat(m.length));
|
||||||
const escapedDoc = doc.replace(TEMPLATE_SYNTAX_REGEX, (m) => "1".repeat(m.length));
|
|
||||||
jsonLintParse(escapedDoc, {
|
|
||||||
mode: (options?.allowComments ?? true) ? "cjson" : "json",
|
|
||||||
ignoreTrailingCommas: options?.allowTrailingCommas ?? false,
|
|
||||||
});
|
|
||||||
// oxlint-disable-next-line no-explicit-any
|
|
||||||
} catch (err: any) {
|
|
||||||
if (!("location" in err)) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// const line = location?.start?.line;
|
const errors: ParseError[] = [];
|
||||||
// const column = location?.start?.column;
|
parse(escapedDoc, errors, {
|
||||||
if (err.location.start.offset) {
|
allowTrailingComma: options?.allowTrailingCommas ?? false,
|
||||||
return [
|
disallowComments: !(options?.allowComments ?? true),
|
||||||
{
|
});
|
||||||
from: err.location.start.offset,
|
|
||||||
to: err.location.start.offset,
|
// Later errors are mostly consequences of the first one, so only that one is shown
|
||||||
severity: "error",
|
const error = errors[0];
|
||||||
message: err.message,
|
if (error == null) return [];
|
||||||
},
|
|
||||||
];
|
return [
|
||||||
}
|
{
|
||||||
}
|
from: error.offset,
|
||||||
return [];
|
to: error.offset + error.length,
|
||||||
|
severity: "error",
|
||||||
|
message: MESSAGES[printParseErrorCode(error.error)] ?? "Invalid JSON",
|
||||||
|
},
|
||||||
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,202 @@
|
|||||||
|
import { SearchQuery } from "@codemirror/search";
|
||||||
|
import { EditorState } from "@codemirror/state";
|
||||||
|
import { describe, expect, test } from "vite-plus/test";
|
||||||
|
import {
|
||||||
|
currentMatch,
|
||||||
|
literalSearch,
|
||||||
|
MAX_COUNT,
|
||||||
|
MatchCounter,
|
||||||
|
normalizeDoc,
|
||||||
|
normalizeSearch,
|
||||||
|
scanNormalized,
|
||||||
|
scanQuery,
|
||||||
|
} from "./searchMatchCount";
|
||||||
|
|
||||||
|
type QueryConfig = ConstructorParameters<typeof SearchQuery>[0];
|
||||||
|
|
||||||
|
const stateOf = (doc: string) => EditorState.create({ doc });
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The matches the counter finds, having checked them against the search panel's own cursor.
|
||||||
|
*
|
||||||
|
* The cursor decides which ranges the editor highlights and which one `find next` lands on, so
|
||||||
|
* a count that doesn't agree with it is a wrong count, however fast it was to produce.
|
||||||
|
*/
|
||||||
|
function matchesOf(doc: string, config: QueryConfig) {
|
||||||
|
const state = stateOf(doc);
|
||||||
|
const query = new SearchQuery(config);
|
||||||
|
const matches = new MatchCounter().matches(state, query);
|
||||||
|
expect(matches).toEqual(scanQuery(state, query));
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
const countOf = (doc: string, config: QueryConfig) => matchesOf(doc, config).length;
|
||||||
|
|
||||||
|
describe("counting", () => {
|
||||||
|
test("counts every match, whatever the case", () => {
|
||||||
|
expect(countOf("one Two three two", { search: "two" })).toBe(2);
|
||||||
|
expect(countOf("one Two three two", { search: "two", caseSensitive: true })).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("skips matches overlapping an earlier one", () => {
|
||||||
|
expect(countOf("aaaaa", { search: "aa" })).toBe(2);
|
||||||
|
expect(countOf("ababa", { search: "aba" })).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("treats a query as text, not as a pattern", () => {
|
||||||
|
expect(countOf("a.b axb", { search: "a.b" })).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("unquotes escapes unless the query is literal", () => {
|
||||||
|
expect(countOf("one\ntwo\nthree", { search: "\\n" })).toBe(2);
|
||||||
|
expect(countOf("one\\ntwo", { search: "\\n", literal: true })).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("counts regexp and whole word queries through the cursor", () => {
|
||||||
|
expect(literalSearch(new SearchQuery({ search: "a", regexp: true }))).toBe(null);
|
||||||
|
expect(literalSearch(new SearchQuery({ search: "a", wholeWord: true }))).toBe(null);
|
||||||
|
expect(countOf("a1 b2 c3", { search: "[a-z]\\d", regexp: true })).toBe(3);
|
||||||
|
expect(countOf("cat cats cat", { search: "cat", wholeWord: true })).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("stops counting at the cap", () => {
|
||||||
|
expect(countOf("x".repeat(MAX_COUNT + 100), { search: "x" })).toBe(MAX_COUNT + 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("reports where the matches are", () => {
|
||||||
|
expect(matchesOf("ab..ab", { search: "ab" })).toEqual([
|
||||||
|
{ from: 0, to: 2 },
|
||||||
|
{ from: 4, to: 6 },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("finds nothing to match with an empty needle", () => {
|
||||||
|
expect(scanNormalized(normalizeDoc("abc", false), "")).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("normalization", () => {
|
||||||
|
test("finds what a character decomposes into", () => {
|
||||||
|
// The é is one character holding an `e`, and the match covers the whole of it
|
||||||
|
expect(matchesOf("café", { search: "e" })).toEqual([{ from: 3, to: 4 }]);
|
||||||
|
expect(matchesOf("file", { search: "fi" })).toEqual([{ from: 0, to: 1 }]);
|
||||||
|
expect(matchesOf("a…b", { search: "..." })).toEqual([{ from: 1, to: 2 }]);
|
||||||
|
expect(countOf("one two", { search: "one two" })).toBe(1);
|
||||||
|
expect(countOf("full width", { search: "full" })).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("matches a decomposed query against composed text, and the reverse", () => {
|
||||||
|
expect(countOf("café", { search: "café" })).toBe(1);
|
||||||
|
expect(countOf("café", { search: "café" })).toBe(1);
|
||||||
|
expect(countOf("café", { search: "café" })).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("keeps offsets straight after an expansion", () => {
|
||||||
|
expect(matchesOf("é.é.end", { search: "end" })).toEqual([{ from: 4, to: 7 }]);
|
||||||
|
expect(matchesOf("fififi stop", { search: "stop" })).toEqual([{ from: 4, to: 8 }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("normalizes the query whole, the document by character", () => {
|
||||||
|
expect(normalizeSearch("CAFÉ", false)).toBe("café");
|
||||||
|
expect(normalizeSearch("CAFÉ", true)).toBe("CAFÉ");
|
||||||
|
// Whole-string NFKD would fold this to a final sigma, which the cursor never does
|
||||||
|
expect(normalizeDoc("ΟΔΟΣ", false).text).toBe("οδοσ");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("leaves a document that normalizes to itself untouched", () => {
|
||||||
|
const { text, expansions } = normalizeDoc("plain 日本 🎉 text", false);
|
||||||
|
expect(text).toBe("plain 日本 🎉 text");
|
||||||
|
expect(expansions).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("current match", () => {
|
||||||
|
const matches = [
|
||||||
|
{ from: 0, to: 2 },
|
||||||
|
{ from: 4, to: 6 },
|
||||||
|
{ from: 8, to: 10 },
|
||||||
|
];
|
||||||
|
|
||||||
|
test("counts from one, and reports 0 off a match", () => {
|
||||||
|
expect(currentMatch(matches, { from: 4, to: 6 })).toBe(2);
|
||||||
|
expect(currentMatch(matches, { from: 8, to: 10 })).toBe(3);
|
||||||
|
expect(currentMatch(matches, { from: 5, to: 5 })).toBe(2);
|
||||||
|
expect(currentMatch(matches, { from: 2, to: 3 })).toBe(0);
|
||||||
|
expect(currentMatch(matches, { from: 4, to: 7 })).toBe(0);
|
||||||
|
expect(currentMatch([], { from: 0, to: 0 })).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("moving the selection doesn't scan again", () => {
|
||||||
|
const state = stateOf("a1 b2 c3");
|
||||||
|
const query = new SearchQuery({ search: "\\d", regexp: true });
|
||||||
|
const counter = new MatchCounter();
|
||||||
|
const found = counter.matches(state, query);
|
||||||
|
|
||||||
|
// The document a selection-only transaction leaves behind is the one already scanned
|
||||||
|
const moved = state.update({ selection: { anchor: 4, head: 5 } }).state;
|
||||||
|
expect(counter.matches(moved, query)).toBe(found);
|
||||||
|
expect(currentMatch(found, moved.selection.main)).toBe(2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mapping from normalized offsets back to document offsets is the part of this that can go
|
||||||
|
* quietly wrong, and only on input nobody thinks to write a case for. So generate the input.
|
||||||
|
*/
|
||||||
|
describe("against the cursor, on awkward text", () => {
|
||||||
|
const ALPHABET = [
|
||||||
|
..."abcABC .\\\n".split(""),
|
||||||
|
"é",
|
||||||
|
"é",
|
||||||
|
"fi",
|
||||||
|
"…",
|
||||||
|
" ",
|
||||||
|
"İ",
|
||||||
|
"Σ",
|
||||||
|
"ς",
|
||||||
|
"日",
|
||||||
|
"🎉",
|
||||||
|
"Ⅻ",
|
||||||
|
"f",
|
||||||
|
"①",
|
||||||
|
"́",
|
||||||
|
];
|
||||||
|
|
||||||
|
/** Seeded, so a failure is the same failure next run */
|
||||||
|
function random(seed: number) {
|
||||||
|
let state = seed;
|
||||||
|
return () => {
|
||||||
|
state = (state * 1664525 + 1013904223) >>> 0;
|
||||||
|
return state / 2 ** 32;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const caseSensitive of [false, true]) {
|
||||||
|
test(`agrees on every generated document (caseSensitive: ${caseSensitive})`, () => {
|
||||||
|
const next = random(caseSensitive ? 20260831 : 7);
|
||||||
|
|
||||||
|
for (let round = 0; round < 400; round++) {
|
||||||
|
const doc = Array.from(
|
||||||
|
{ length: 2 + Math.floor(next() * 60) },
|
||||||
|
() => ALPHABET[Math.floor(next() * ALPHABET.length)]!,
|
||||||
|
).join("");
|
||||||
|
|
||||||
|
// Half the queries are lifted out of the document, so matches are actually found
|
||||||
|
const start = Math.floor(next() * doc.length);
|
||||||
|
const search =
|
||||||
|
next() < 0.5
|
||||||
|
? doc.slice(start, start + 1 + Math.floor(next() * 3))
|
||||||
|
: Array.from(
|
||||||
|
{ length: 1 + Math.floor(next() * 2) },
|
||||||
|
() => ALPHABET[Math.floor(next() * ALPHABET.length)]!,
|
||||||
|
).join("");
|
||||||
|
if (search === "") continue;
|
||||||
|
|
||||||
|
const state = stateOf(doc);
|
||||||
|
const query = new SearchQuery({ search, caseSensitive });
|
||||||
|
const where = `doc=${JSON.stringify(doc)} search=${JSON.stringify(search)}`;
|
||||||
|
expect(new MatchCounter().matches(state, query), where).toEqual(scanQuery(state, query));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,7 +1,232 @@
|
|||||||
import { getSearchQuery, searchPanelOpen } from "@codemirror/search";
|
import { getSearchQuery, type SearchQuery, searchPanelOpen } from "@codemirror/search";
|
||||||
import type { Extension } from "@codemirror/state";
|
import type { EditorState, Extension, Text } from "@codemirror/state";
|
||||||
import { type EditorView, ViewPlugin, type ViewUpdate } from "@codemirror/view";
|
import { type EditorView, ViewPlugin, type ViewUpdate } from "@codemirror/view";
|
||||||
|
|
||||||
|
/** Matches are counted no further than this, since an exact total stops being useful long before */
|
||||||
|
export const MAX_COUNT = 9999;
|
||||||
|
|
||||||
|
/** What normalizing rewrites: anything outside ASCII, plus the case it folds */
|
||||||
|
const REWRITTEN = /\P{ASCII}|[A-Z]+/gu;
|
||||||
|
const REWRITTEN_CASE_SENSITIVE = /\P{ASCII}/gu;
|
||||||
|
|
||||||
|
export interface Match {
|
||||||
|
from: number;
|
||||||
|
to: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A character whose normalized form is a different length, shifting every offset past it */
|
||||||
|
interface Expansion {
|
||||||
|
normFrom: number;
|
||||||
|
normTo: number;
|
||||||
|
docFrom: number;
|
||||||
|
docTo: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A document as SearchCursor compares it, with what's needed to get back to real offsets */
|
||||||
|
export interface NormalizedDoc {
|
||||||
|
text: string;
|
||||||
|
expansions: Expansion[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rewrites a document the way SearchCursor does — NFKD, then a case fold unless the search is
|
||||||
|
* case-sensitive — in a single pass rather than one call per code point.
|
||||||
|
*
|
||||||
|
* The cursor spends 90% of its time asking ICU about one character at a time, which is what
|
||||||
|
* makes counting matches in a large response slow. Doing it a character at a time still matters
|
||||||
|
* for the result, since it keeps NFKD from reordering marks across characters, so the
|
||||||
|
* granularity stays and only the repeated work goes: each distinct character is normalized once
|
||||||
|
* and the answer reused, and ASCII runs never reach ICU at all.
|
||||||
|
*/
|
||||||
|
export function normalizeDoc(text: string, caseSensitive: boolean): NormalizedDoc {
|
||||||
|
const rewritten = new Map<string, string>();
|
||||||
|
const expansions: Expansion[] = [];
|
||||||
|
let shift = 0;
|
||||||
|
|
||||||
|
const normalized = text.replace(
|
||||||
|
caseSensitive ? REWRITTEN_CASE_SENSITIVE : REWRITTEN,
|
||||||
|
(chunk: string, at: number) => {
|
||||||
|
// An ASCII run only ever folds case, which can't change its length
|
||||||
|
if (chunk.charCodeAt(0) < 0x80) return chunk.toLowerCase();
|
||||||
|
|
||||||
|
let out = rewritten.get(chunk);
|
||||||
|
if (out === undefined) {
|
||||||
|
out = chunk.normalize("NFKD");
|
||||||
|
if (!caseSensitive) out = out.toLowerCase();
|
||||||
|
rewritten.set(chunk, out);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out.length !== chunk.length) {
|
||||||
|
expansions.push({
|
||||||
|
normFrom: at + shift,
|
||||||
|
normTo: at + shift + out.length,
|
||||||
|
docFrom: at,
|
||||||
|
docTo: at + chunk.length,
|
||||||
|
});
|
||||||
|
shift += out.length - chunk.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
return out;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return { text: normalized, expansions };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The query as SearchCursor compares it, which it normalizes whole rather than by character */
|
||||||
|
export function normalizeSearch(search: string, caseSensitive: boolean): string {
|
||||||
|
const normalized = search.normalize("NFKD");
|
||||||
|
return caseSensitive ? normalized : normalized.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Every occurrence of `needle`, skipping matches that overlap an earlier one */
|
||||||
|
export function scanNormalized(doc: NormalizedDoc, needle: string): Match[] {
|
||||||
|
const matches: Match[] = [];
|
||||||
|
if (needle === "") return matches;
|
||||||
|
|
||||||
|
const { text } = doc;
|
||||||
|
let pos = text.indexOf(needle);
|
||||||
|
while (pos >= 0) {
|
||||||
|
let end = pos + needle.length;
|
||||||
|
// However the query was cut, a match ends on a whole code point, as the cursor's do
|
||||||
|
if (isLowSurrogate(text.charCodeAt(end))) end++;
|
||||||
|
|
||||||
|
matches.push({ from: docStart(doc, pos), to: docEnd(doc, end) });
|
||||||
|
if (matches.length > MAX_COUNT) break;
|
||||||
|
|
||||||
|
pos = text.indexOf(needle, resumeAfter(doc, end));
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The same through the query's own cursor, which handles regexps and whole words */
|
||||||
|
export function scanQuery(state: EditorState, query: SearchQuery): Match[] {
|
||||||
|
const matches: Match[] = [];
|
||||||
|
const cursor = query.getCursor(state);
|
||||||
|
|
||||||
|
for (let result = cursor.next(); !result.done; result = cursor.next()) {
|
||||||
|
matches.push({ from: result.value.from, to: result.value.to });
|
||||||
|
if (matches.length > MAX_COUNT) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isLowSurrogate = (code: number) => code >= 0xdc00 && code <= 0xdfff;
|
||||||
|
|
||||||
|
/** The last character expansion beginning at or before `offset`, if there is one */
|
||||||
|
function expansionAt({ expansions }: NormalizedDoc, offset: number): Expansion | null {
|
||||||
|
let low = 0;
|
||||||
|
let high = expansions.length - 1;
|
||||||
|
let found: Expansion | null = null;
|
||||||
|
|
||||||
|
while (low <= high) {
|
||||||
|
const mid = (low + high) >> 1;
|
||||||
|
if (expansions[mid]!.normFrom <= offset) {
|
||||||
|
found = expansions[mid]!;
|
||||||
|
low = mid + 1;
|
||||||
|
} else {
|
||||||
|
high = mid - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
|
||||||
|
function docStart(doc: NormalizedDoc, offset: number): number {
|
||||||
|
const expansion = expansionAt(doc, offset);
|
||||||
|
if (expansion == null) return offset;
|
||||||
|
// A match starting inside a character's expansion starts at the character
|
||||||
|
return offset < expansion.normTo
|
||||||
|
? expansion.docFrom
|
||||||
|
: offset - (expansion.normTo - expansion.docTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Where scanning picks up after a match ending at `offset`.
|
||||||
|
*
|
||||||
|
* The cursor moves through the document a character at a time, so once a match ends inside a
|
||||||
|
* character's expansion the rest of that expansion is behind it — "…" holds three dots but only
|
||||||
|
* ever counts as one match of ".".
|
||||||
|
*/
|
||||||
|
function resumeAfter(doc: NormalizedDoc, offset: number): number {
|
||||||
|
const expansion = expansionAt(doc, offset);
|
||||||
|
return expansion != null && offset > expansion.normFrom && offset < expansion.normTo
|
||||||
|
? expansion.normTo
|
||||||
|
: offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
function docEnd(doc: NormalizedDoc, offset: number): number {
|
||||||
|
const expansion = expansionAt(doc, offset);
|
||||||
|
if (expansion == null) return offset;
|
||||||
|
if (offset <= expansion.normFrom) return expansion.docFrom;
|
||||||
|
// A match ending inside a character's expansion covers the whole character
|
||||||
|
return offset < expansion.normTo
|
||||||
|
? expansion.docTo
|
||||||
|
: offset - (expansion.normTo - expansion.docTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Position of the match holding the selection, counting from one, or 0 when it isn't on one */
|
||||||
|
export function currentMatch(matches: Match[], selection: { from: number; to: number }): number {
|
||||||
|
let index = 0;
|
||||||
|
for (const match of matches) {
|
||||||
|
index++;
|
||||||
|
if (match.from <= selection.from && match.to >= selection.to) return index;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The text a plain query looks for, or null when only the cursor can answer it */
|
||||||
|
export function literalSearch(query: SearchQuery): string | null {
|
||||||
|
if (query.regexp || query.wholeWord || query.test != null) return null;
|
||||||
|
// Mirrors SearchQuery's own unquoting, which the published type doesn't expose
|
||||||
|
return query.literal
|
||||||
|
? query.search
|
||||||
|
: query.search.replace(/\\([nrt\\])/g, (_, ch) =>
|
||||||
|
ch === "n" ? "\n" : ch === "r" ? "\r" : ch === "t" ? "\t" : "\\",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds the matches for the search panel, keeping the normalized document and the matches it
|
||||||
|
* last found, so neither moving the selection nor typing another character starts over.
|
||||||
|
*/
|
||||||
|
export class MatchCounter {
|
||||||
|
private doc: { doc: Text; caseSensitive: boolean; normalized: NormalizedDoc } | null = null;
|
||||||
|
private last: { doc: Text; query: SearchQuery; matches: Match[] } | null = null;
|
||||||
|
|
||||||
|
matches(state: EditorState, query: SearchQuery): Match[] {
|
||||||
|
const last = this.last;
|
||||||
|
if (last != null && last.doc === state.doc && last.query.eq(query)) {
|
||||||
|
return last.matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
const matches = this.scan(state, query);
|
||||||
|
this.last = { doc: state.doc, query, matches };
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
private scan(state: EditorState, query: SearchQuery): Match[] {
|
||||||
|
const search = literalSearch(query);
|
||||||
|
if (search == null) return scanQuery(state, query);
|
||||||
|
|
||||||
|
const doc = this.normalizedDoc(state.doc, query.caseSensitive);
|
||||||
|
return scanNormalized(doc, normalizeSearch(search, query.caseSensitive));
|
||||||
|
}
|
||||||
|
|
||||||
|
private normalizedDoc(doc: Text, caseSensitive: boolean): NormalizedDoc {
|
||||||
|
const cached = this.doc;
|
||||||
|
if (cached != null && cached.doc === doc && cached.caseSensitive === caseSensitive) {
|
||||||
|
return cached.normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
const normalized = normalizeDoc(doc.toString(), caseSensitive);
|
||||||
|
this.doc = { doc, caseSensitive, normalized };
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A CodeMirror extension that displays the total number of search matches
|
* A CodeMirror extension that displays the total number of search matches
|
||||||
* inside the built-in search panel.
|
* inside the built-in search panel.
|
||||||
@@ -10,6 +235,7 @@ export function searchMatchCount(): Extension {
|
|||||||
return ViewPlugin.fromClass(
|
return ViewPlugin.fromClass(
|
||||||
class {
|
class {
|
||||||
private countEl: HTMLElement | null = null;
|
private countEl: HTMLElement | null = null;
|
||||||
|
private counter = new MatchCounter();
|
||||||
|
|
||||||
constructor(private view: EditorView) {
|
constructor(private view: EditorView) {
|
||||||
this.updateCount();
|
this.updateCount();
|
||||||
@@ -38,38 +264,21 @@ export function searchMatchCount(): Extension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.ensureCountEl();
|
this.ensureCountEl();
|
||||||
|
if (this.countEl == null) return;
|
||||||
|
|
||||||
if (!query.search) {
|
if (!query.search) {
|
||||||
if (this.countEl) {
|
this.countEl.textContent = "0/0";
|
||||||
this.countEl.textContent = "0/0";
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const selection = state.selection.main;
|
const matches = this.counter.matches(state, query);
|
||||||
let count = 0;
|
if (matches.length > MAX_COUNT) {
|
||||||
let currentIndex = 0;
|
this.countEl.textContent = `${MAX_COUNT}+`;
|
||||||
const MAX_COUNT = 9999;
|
} else if (matches.length === 0) {
|
||||||
const cursor = query.getCursor(state);
|
this.countEl.textContent = "0/0";
|
||||||
for (let result = cursor.next(); !result.done; result = cursor.next()) {
|
} else {
|
||||||
count++;
|
const current = currentMatch(matches, state.selection.main);
|
||||||
const match = result.value;
|
this.countEl.textContent = `${current}/${matches.length}`;
|
||||||
if (match.from <= selection.from && match.to >= selection.to) {
|
|
||||||
currentIndex = count;
|
|
||||||
}
|
|
||||||
if (count > MAX_COUNT) break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.countEl) {
|
|
||||||
if (count > MAX_COUNT) {
|
|
||||||
this.countEl.textContent = `${MAX_COUNT}+`;
|
|
||||||
} else if (count === 0) {
|
|
||||||
this.countEl.textContent = "0/0";
|
|
||||||
} else if (currentIndex > 0) {
|
|
||||||
this.countEl.textContent = `${currentIndex}/${count}`;
|
|
||||||
} else {
|
|
||||||
this.countEl.textContent = `0/${count}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {
|
|||||||
useSensor,
|
useSensor,
|
||||||
useSensors,
|
useSensors,
|
||||||
} from "@dnd-kit/core";
|
} from "@dnd-kit/core";
|
||||||
import { basename } from "@tauri-apps/api/path";
|
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import { Fragment, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import type { WrappedEnvironmentVariable } from "../../hooks/useEnvironmentVariables";
|
import type { WrappedEnvironmentVariable } from "../../hooks/useEnvironmentVariables";
|
||||||
@@ -34,6 +33,7 @@ import { Input } from "./Input";
|
|||||||
import { ensurePairId } from "./PairEditor.util";
|
import { ensurePairId } from "./PairEditor.util";
|
||||||
import type { RadioDropdownItem } from "./RadioDropdown";
|
import type { RadioDropdownItem } from "./RadioDropdown";
|
||||||
import { RadioDropdown } from "./RadioDropdown";
|
import { RadioDropdown } from "./RadioDropdown";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
export interface PairEditorHandle {
|
export interface PairEditorHandle {
|
||||||
/**
|
/**
|
||||||
@@ -113,7 +113,15 @@ function toPairData({ commitName: _commitName, ...pair }: EditablePairWithId): P
|
|||||||
/** Max number of pairs to show before prompting the user to reveal the rest */
|
/** Max number of pairs to show before prompting the user to reveal the rest */
|
||||||
const MAX_INITIAL_PAIRS = 30;
|
const MAX_INITIAL_PAIRS = 30;
|
||||||
|
|
||||||
export function PairEditor({
|
// Keyed on `stateKey` so no state survives a change of owner. Row ids alone can't tell owners
|
||||||
|
// apart — two pair sets can share ids (eg. one duplicated from the other), and the same-rows
|
||||||
|
// fast path below would swap in the new data without rebuilding the row editors, leaving any
|
||||||
|
// still-focused input showing the old owner's text.
|
||||||
|
export function PairEditor(props: PairEditorProps) {
|
||||||
|
return <PairEditorInner key={props.stateKey} {...props} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function PairEditorInner({
|
||||||
allowFileValues,
|
allowFileValues,
|
||||||
allowMultilineValues,
|
allowMultilineValues,
|
||||||
className,
|
className,
|
||||||
@@ -851,7 +859,7 @@ function FileActionsDropdown({
|
|||||||
leftSlot: <Icon icon="file_code" />,
|
leftSlot: <Icon icon="file_code" />,
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
console.log("PAIR", pair);
|
console.log("PAIR", pair);
|
||||||
const defaultFilename = await basename(pair.value ?? "");
|
const defaultFilename = await platform.files.basename(pair.value ?? "");
|
||||||
const filename = await showPrompt({
|
const filename = await showPrompt({
|
||||||
id: "filename",
|
id: "filename",
|
||||||
title: "Override Filename",
|
title: "Override Filename",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type } from "@tauri-apps/plugin-os";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import { HStack } from "@yaakapp-internal/ui";
|
import { HStack } from "@yaakapp-internal/ui";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import type { CSSProperties, ReactNode } from "react";
|
import type { CSSProperties, ReactNode } from "react";
|
||||||
@@ -66,7 +66,7 @@ export function Select<T extends string>({
|
|||||||
<Label htmlFor={id} visuallyHidden={hideLabel} className={labelClassName} help={help}>
|
<Label htmlFor={id} visuallyHidden={hideLabel} className={labelClassName} help={help}>
|
||||||
{label}
|
{label}
|
||||||
</Label>
|
</Label>
|
||||||
{type() === "macos" && !filterable ? (
|
{platform.osType() === "macos" && !filterable ? (
|
||||||
<HStack
|
<HStack
|
||||||
space={2}
|
space={2}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
@@ -119,9 +119,13 @@ export function Select<T extends string>({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
className="w-full text-sm font-mono"
|
className={classNames(
|
||||||
|
"w-full text-sm font-mono",
|
||||||
|
disabled && "border-dotted",
|
||||||
|
isInvalidSelection && "border-danger",
|
||||||
|
)}
|
||||||
justify="start"
|
justify="start"
|
||||||
variant="border"
|
variant="input"
|
||||||
size={size}
|
size={size}
|
||||||
leftSlot={leftSlot}
|
leftSlot={leftSlot}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
|
|||||||
@@ -1,13 +1,31 @@
|
|||||||
import type { Color } from "@yaakapp-internal/plugins";
|
import type { Color } from "@yaakapp-internal/plugins";
|
||||||
|
import type { IconProps } from "@yaakapp-internal/ui";
|
||||||
|
import { IconButton } from "@yaakapp-internal/ui";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A single control attached to a labelled separator, rendered between the label
|
||||||
|
* and the rule.
|
||||||
|
*
|
||||||
|
* Declared rather than passed as a node so the separator keeps ownership of the
|
||||||
|
* things that are easy to get wrong by hand: matching the label's colour, and
|
||||||
|
* staying out of the rule's way when the label is long.
|
||||||
|
*/
|
||||||
|
export interface SeparatorAction {
|
||||||
|
icon: IconProps["icon"];
|
||||||
|
/** Tooltip and accessible name. Required — the control is icon-only. */
|
||||||
|
title: string;
|
||||||
|
onClick: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
orientation?: "horizontal" | "vertical";
|
orientation?: "horizontal" | "vertical";
|
||||||
dashed?: boolean;
|
dashed?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
color?: Color;
|
color?: Color;
|
||||||
|
action?: SeparatorAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Separator({
|
export function Separator({
|
||||||
@@ -16,15 +34,31 @@ export function Separator({
|
|||||||
dashed,
|
dashed,
|
||||||
orientation = "horizontal",
|
orientation = "horizontal",
|
||||||
children,
|
children,
|
||||||
|
action,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
return (
|
return (
|
||||||
<div role="presentation" className={classNames(className, "flex items-center w-full")}>
|
<div role="presentation" className={classNames(className, "flex items-center w-full")}>
|
||||||
{children && (
|
{children && (
|
||||||
<div className="text-sm text-text-subtlest mr-2 whitespace-nowrap">{children}</div>
|
<div className="text-sm text-text-subtlest mr-2 whitespace-nowrap">{children}</div>
|
||||||
)}
|
)}
|
||||||
|
{action && (
|
||||||
|
<IconButton
|
||||||
|
size="2xs"
|
||||||
|
iconSize="xs"
|
||||||
|
className="shrink-0 mr-2 -ml-1"
|
||||||
|
// Forced, because the button itself sets `text-text` at full strength.
|
||||||
|
iconClassName="text-text-subtlest!"
|
||||||
|
icon={action.icon}
|
||||||
|
title={action.title}
|
||||||
|
onClick={action.onClick}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<div
|
<div
|
||||||
className={classNames(
|
className={classNames(
|
||||||
"opacity-60",
|
"opacity-60",
|
||||||
|
// Keep a stub of the line visible no matter how long the label is —
|
||||||
|
// `w-full` alone gets squeezed to nothing by a wide label.
|
||||||
|
orientation === "horizontal" && "min-w-8",
|
||||||
color == null && "border-border",
|
color == null && "border-border",
|
||||||
color === "primary" && "border-primary",
|
color === "primary" && "border-primary",
|
||||||
color === "secondary" && "border-secondary",
|
color === "secondary" && "border-secondary",
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import { CommercialUseBanner } from "../CommercialUseBanner";
|
|||||||
import { Button } from "../core/Button";
|
import { Button } from "../core/Button";
|
||||||
import type { CheckboxProps } from "../core/Checkbox";
|
import type { CheckboxProps } from "../core/Checkbox";
|
||||||
import { Checkbox } from "../core/Checkbox";
|
import { Checkbox } from "../core/Checkbox";
|
||||||
|
import type { CheckboxTreeNode } from "../core/CheckboxTree";
|
||||||
|
import { CheckboxTree } from "../core/CheckboxTree";
|
||||||
import { DiffViewer } from "../core/Editor/DiffViewer";
|
import { DiffViewer } from "../core/Editor/DiffViewer";
|
||||||
import { Input } from "../core/Input";
|
import { Input } from "../core/Input";
|
||||||
import { Separator } from "../core/Separator";
|
import { Separator } from "../core/Separator";
|
||||||
@@ -43,10 +45,7 @@ interface CommitTreeNode {
|
|||||||
|
|
||||||
export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
|
export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
|
||||||
const callbacks = useGitCallbacks(syncDir);
|
const callbacks = useGitCallbacks(syncDir);
|
||||||
const [{ status }, { commit, commitAndPush, add, unstage, restore }] = useGit(
|
const [{ status }, { commit, commitAndPush, add, unstage, restore }] = useGit(syncDir, callbacks);
|
||||||
syncDir,
|
|
||||||
callbacks,
|
|
||||||
);
|
|
||||||
const [isPushing, setIsPushing] = useState(false);
|
const [isPushing, setIsPushing] = useState(false);
|
||||||
const [commitError, setCommitError] = useState<string | null>(null);
|
const [commitError, setCommitError] = useState<string | null>(null);
|
||||||
const [message, setMessage] = useState<string>("");
|
const [message, setMessage] = useState<string>("");
|
||||||
@@ -143,6 +142,15 @@ export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
|
|||||||
return next(workspace, []);
|
return next(workspace, []);
|
||||||
}, [workspace, internalEntries]);
|
}, [workspace, internalEntries]);
|
||||||
|
|
||||||
|
const treeNode: CheckboxTreeNode<CommitTreeNode> | null = useMemo(() => {
|
||||||
|
const toTreeNode = (n: CommitTreeNode): CheckboxTreeNode<CommitTreeNode> => ({
|
||||||
|
key: n.status.relaPath + n.status.status + n.status.staged,
|
||||||
|
data: n,
|
||||||
|
children: n.children.map(toTreeNode),
|
||||||
|
});
|
||||||
|
return tree == null ? null : toTreeNode(tree);
|
||||||
|
}, [tree]);
|
||||||
|
|
||||||
const checkNode = useCallback(
|
const checkNode = useCallback(
|
||||||
(treeNode: CommitTreeNode) => {
|
(treeNode: CommitTreeNode) => {
|
||||||
const checked = nodeCheckedStatus(treeNode);
|
const checked = nodeCheckedStatus(treeNode);
|
||||||
@@ -190,7 +198,7 @@ export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
|
|||||||
[restore],
|
[restore],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (tree == null) {
|
if (tree == null || treeNode == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,12 +229,18 @@ export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
|
|||||||
style={innerStyle}
|
style={innerStyle}
|
||||||
className="h-full overflow-y-auto pb-3 pr-0.5 transform-cpu"
|
className="h-full overflow-y-auto pb-3 pr-0.5 transform-cpu"
|
||||||
>
|
>
|
||||||
<TreeNodeChildren
|
<CheckboxTree
|
||||||
node={tree}
|
node={treeNode}
|
||||||
depth={0}
|
checked={(n) => nodeCheckedStatus(n.data)}
|
||||||
onCheck={checkNode}
|
onCheck={(n) => checkNode(n.data)}
|
||||||
onSelect={handleSelectChild}
|
checkboxTitle={(n) =>
|
||||||
selectedPath={selectedEntry?.relaPath ?? null}
|
nodeCheckedStatus(n.data) ? "Unstage change" : "Stage change"
|
||||||
|
}
|
||||||
|
isRelevant={(n) => n.data.status.status !== "current"}
|
||||||
|
canSelectRow={(n) => n.data.status.status !== "current"}
|
||||||
|
onSelectRow={(n) => handleSelectChild(n.data.status)}
|
||||||
|
isRowSelected={(n) => selectedEntry?.relaPath === n.data.status.relaPath}
|
||||||
|
renderRow={(n) => <CommitTreeRow node={n.data} />}
|
||||||
/>
|
/>
|
||||||
{externalEntries.find((e) => e.status !== "current") && (
|
{externalEntries.find((e) => e.status !== "current") && (
|
||||||
<>
|
<>
|
||||||
@@ -244,10 +258,7 @@ export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
secondSlot={({ style: innerStyle }) => (
|
secondSlot={({ style: innerStyle }) => (
|
||||||
<div
|
<div style={innerStyle} className="grid grid-rows-[minmax(0,1fr)_auto] gap-3 pb-2">
|
||||||
style={innerStyle}
|
|
||||||
className="grid grid-rows-[minmax(0,1fr)_auto] gap-3 pb-2"
|
|
||||||
>
|
|
||||||
<Input
|
<Input
|
||||||
className="text-base! font-sans rounded-md"
|
className="text-base! font-sans rounded-md"
|
||||||
placeholder="Commit message..."
|
placeholder="Commit message..."
|
||||||
@@ -301,96 +312,39 @@ export function GitCommitDialog({ syncDir, onDone, workspace }: Props) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TreeNodeChildren({
|
function CommitTreeRow({ node }: { node: CommitTreeNode }) {
|
||||||
node,
|
|
||||||
depth,
|
|
||||||
onCheck,
|
|
||||||
onSelect,
|
|
||||||
selectedPath,
|
|
||||||
}: {
|
|
||||||
node: CommitTreeNode | null;
|
|
||||||
depth: number;
|
|
||||||
onCheck: (node: CommitTreeNode, checked: boolean) => void;
|
|
||||||
onSelect: (entry: GitStatusEntry) => void;
|
|
||||||
selectedPath: string | null;
|
|
||||||
}) {
|
|
||||||
if (node === null) return null;
|
|
||||||
if (!isNodeRelevant(node)) return null;
|
|
||||||
|
|
||||||
const checked = nodeCheckedStatus(node);
|
|
||||||
const isSelected = selectedPath === node.status.relaPath;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<>
|
||||||
className={classNames(
|
{node.model.model !== "http_request" &&
|
||||||
depth > 0 && "pl-4 ml-2 border-l border-dashed border-border-subtle relative",
|
node.model.model !== "grpc_request" &&
|
||||||
)}
|
node.model.model !== "websocket_request" ? (
|
||||||
>
|
<Icon
|
||||||
<div
|
color="secondary"
|
||||||
className={classNames(
|
icon={
|
||||||
"relative flex gap-1 w-full h-xs items-center",
|
node.model.model === "folder"
|
||||||
isSelected ? "text-text" : "text-text-subtle",
|
? "folder"
|
||||||
)}
|
: node.model.model === "environment"
|
||||||
>
|
? "variable"
|
||||||
{isSelected && (
|
: "house"
|
||||||
<div className="absolute left-[-100vw] right-0 top-0 bottom-0 bg-surface-active opacity-30 -z-10" />
|
}
|
||||||
)}
|
|
||||||
<Checkbox
|
|
||||||
checked={checked}
|
|
||||||
title={checked ? "Unstage change" : "Stage change"}
|
|
||||||
hideLabel
|
|
||||||
onChange={(checked) => onCheck(node, checked)}
|
|
||||||
/>
|
/>
|
||||||
<button
|
) : (
|
||||||
type="button"
|
<span aria-hidden className="w-4" />
|
||||||
className={classNames("flex-1 min-w-0 flex items-center gap-1 px-1 py-0.5 text-left")}
|
)}
|
||||||
onClick={() => node.status.status !== "current" && onSelect(node.status)}
|
<div className="truncate flex-1">{resolvedModelName(node.model)}</div>
|
||||||
|
{node.status.status !== "current" && (
|
||||||
|
<InlineCode
|
||||||
|
className={classNames(
|
||||||
|
"py-0 bg-transparent w-24 text-center shrink-0",
|
||||||
|
node.status.status === "modified" && "text-info",
|
||||||
|
node.status.status === "untracked" && "text-success",
|
||||||
|
node.status.status === "removed" && "text-danger",
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{node.model.model !== "http_request" &&
|
{node.status.status}
|
||||||
node.model.model !== "grpc_request" &&
|
</InlineCode>
|
||||||
node.model.model !== "websocket_request" ? (
|
)}
|
||||||
<Icon
|
</>
|
||||||
color="secondary"
|
|
||||||
icon={
|
|
||||||
node.model.model === "folder"
|
|
||||||
? "folder"
|
|
||||||
: node.model.model === "environment"
|
|
||||||
? "variable"
|
|
||||||
: "house"
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<span aria-hidden className="w-4" />
|
|
||||||
)}
|
|
||||||
<div className="truncate flex-1">{resolvedModelName(node.model)}</div>
|
|
||||||
{node.status.status !== "current" && (
|
|
||||||
<InlineCode
|
|
||||||
className={classNames(
|
|
||||||
"py-0 bg-transparent w-24 text-center shrink-0",
|
|
||||||
node.status.status === "modified" && "text-info",
|
|
||||||
node.status.status === "untracked" && "text-success",
|
|
||||||
node.status.status === "removed" && "text-danger",
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{node.status.status}
|
|
||||||
</InlineCode>
|
|
||||||
)}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{node.children.map((childNode) => {
|
|
||||||
return (
|
|
||||||
<TreeNodeChildren
|
|
||||||
key={childNode.status.relaPath + childNode.status.status + childNode.status.staged}
|
|
||||||
node={childNode}
|
|
||||||
depth={depth + 1}
|
|
||||||
onCheck={onCheck}
|
|
||||||
onSelect={onSelect}
|
|
||||||
selectedPath={selectedPath}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,15 +449,6 @@ function setCheckedAndChildren(
|
|||||||
if (toUnstage.length > 0) unstage({ relaPaths: toUnstage });
|
if (toUnstage.length > 0) unstage({ relaPaths: toUnstage });
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNodeRelevant(node: CommitTreeNode): boolean {
|
|
||||||
if (node.status.status !== "current") {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recursively check children
|
|
||||||
return node.children.some((c) => isNodeRelevant(c));
|
|
||||||
}
|
|
||||||
|
|
||||||
function DiffPanel({
|
function DiffPanel({
|
||||||
entry,
|
entry,
|
||||||
onDiscardChanges,
|
onDiscardChanges,
|
||||||
@@ -526,13 +471,11 @@ function DiffPanel({
|
|||||||
size="2xs"
|
size="2xs"
|
||||||
variant="border"
|
variant="border"
|
||||||
onClick={() => onDiscardChanges(entry)}
|
onClick={() => onDiscardChanges(entry)}
|
||||||
>Discard Changes</Button>
|
>
|
||||||
|
Discard Changes
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<DiffViewer
|
<DiffViewer original={prevYaml ?? ""} modified={nextYaml ?? ""} className="flex-1 min-h-0" />
|
||||||
original={prevYaml ?? ""}
|
|
||||||
modified={nextYaml ?? ""}
|
|
||||||
className="flex-1 min-h-0"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,10 +86,8 @@ export async function promptDivergedStrategy({
|
|||||||
showDialog({
|
showDialog({
|
||||||
id: "git-diverged",
|
id: "git-diverged",
|
||||||
title: "Branches Diverged",
|
title: "Branches Diverged",
|
||||||
hideX: true,
|
|
||||||
size: "sm",
|
size: "sm",
|
||||||
disableBackdropClose: true,
|
disableClose: true,
|
||||||
onClose: () => resolve("cancel"),
|
|
||||||
render: ({ hide }) =>
|
render: ({ hide }) =>
|
||||||
DivergedDialog({
|
DivergedDialog({
|
||||||
remote,
|
remote,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { HttpRequest } from "@yaakapp-internal/models";
|
import type { HttpRequest } from "@yaakapp-internal/models";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import { useCallback, useEffect, useMemo } from "react";
|
import { useCallback, useEffect, useMemo } from "react";
|
||||||
@@ -11,6 +12,7 @@ import type { DropdownItem } from "../core/Dropdown";
|
|||||||
import { Dropdown } from "../core/Dropdown";
|
import { Dropdown } from "../core/Dropdown";
|
||||||
import type { EditorProps } from "../core/Editor/Editor";
|
import type { EditorProps } from "../core/Editor/Editor";
|
||||||
import { Editor } from "../core/Editor/LazyEditor";
|
import { Editor } from "../core/Editor/LazyEditor";
|
||||||
|
import { IconButton } from "../core/IconButton";
|
||||||
import type { RadioDropdownItem } from "../core/RadioDropdown";
|
import type { RadioDropdownItem } from "../core/RadioDropdown";
|
||||||
import { RadioDropdown } from "../core/RadioDropdown";
|
import { RadioDropdown } from "../core/RadioDropdown";
|
||||||
import { Banner, FormattedError, Icon } from "@yaakapp-internal/ui";
|
import { Banner, FormattedError, Icon } from "@yaakapp-internal/ui";
|
||||||
@@ -18,6 +20,7 @@ import { Separator } from "../core/Separator";
|
|||||||
import { tryFormatGraphql } from "../../lib/formatters";
|
import { tryFormatGraphql } from "../../lib/formatters";
|
||||||
import { parseGraphQLOperationNames } from "../../lib/graphqlOperationNames";
|
import { parseGraphQLOperationNames } from "../../lib/graphqlOperationNames";
|
||||||
import { normalizeGraphQLBody } from "../../lib/requestBodyConversion";
|
import { normalizeGraphQLBody } from "../../lib/requestBodyConversion";
|
||||||
|
import { revealInFinderText } from "../../lib/reveal";
|
||||||
import { showGraphQLDocExplorerAtom } from "./graphqlAtoms";
|
import { showGraphQLDocExplorerAtom } from "./graphqlAtoms";
|
||||||
|
|
||||||
type Props = Pick<EditorProps, "heightMode" | "className" | "forceUpdateKey"> & {
|
type Props = Pick<EditorProps, "heightMode" | "className" | "forceUpdateKey"> & {
|
||||||
@@ -28,6 +31,10 @@ type Props = Pick<EditorProps, "heightMode" | "className" | "forceUpdateKey"> &
|
|||||||
|
|
||||||
const OPERATION_NAME_NOT_SPECIFIED = "";
|
const OPERATION_NAME_NOT_SPECIFIED = "";
|
||||||
|
|
||||||
|
// How much of the end of a schema filename is pinned when middle-truncating it.
|
||||||
|
// Enough to keep the extension and a little of the name before it.
|
||||||
|
const FILE_NAME_TAIL_CHARS = 12;
|
||||||
|
|
||||||
export function GraphQLEditor(props: Props) {
|
export function GraphQLEditor(props: Props) {
|
||||||
// There's some weirdness with stale onChange being called when switching requests, so we'll
|
// There's some weirdness with stale onChange being called when switching requests, so we'll
|
||||||
// key on the request ID as a workaround for now.
|
// key on the request ID as a workaround for now.
|
||||||
@@ -38,9 +45,41 @@ function GraphQLEditorInner({ request, onChange, baseRequest, ...extraEditorProp
|
|||||||
const [autoIntrospectDisabled, setAutoIntrospectDisabled] = useLocalStorage<
|
const [autoIntrospectDisabled, setAutoIntrospectDisabled] = useLocalStorage<
|
||||||
Record<string, boolean>
|
Record<string, boolean>
|
||||||
>("graphQLAutoIntrospectDisabled", {});
|
>("graphQLAutoIntrospectDisabled", {});
|
||||||
const { schema, isLoading, error, refetch, clear } = useIntrospectGraphQL(baseRequest, {
|
const {
|
||||||
|
schema,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
refetch,
|
||||||
|
clear,
|
||||||
|
loadFromFile,
|
||||||
|
reloadFromFile,
|
||||||
|
removeSchemaFile,
|
||||||
|
filePath,
|
||||||
|
} = useIntrospectGraphQL(baseRequest, {
|
||||||
disabled: autoIntrospectDisabled?.[baseRequest.id],
|
disabled: autoIntrospectDisabled?.[baseRequest.id],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Last path segment, for display only. The host owns real path semantics; this
|
||||||
|
// just needs something short enough to label the divider with.
|
||||||
|
const fileName = useMemo(() => filePath?.split(/[/\\]/).pop() || filePath, [filePath]);
|
||||||
|
|
||||||
|
// Selecting a file is all it takes — the request's source becomes that file,
|
||||||
|
// which is what keeps automatic introspection from overwriting it.
|
||||||
|
const handleLoadFromFile = useCallback(async () => {
|
||||||
|
const selected = await platform.dialog.open({
|
||||||
|
title: "Load GraphQL Schema",
|
||||||
|
multiple: false,
|
||||||
|
filters: [
|
||||||
|
{
|
||||||
|
name: "GraphQL Schema",
|
||||||
|
extensions: ["graphql", "graphqls", "gql", "json"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
if (selected == null) return;
|
||||||
|
|
||||||
|
await loadFromFile(selected);
|
||||||
|
}, [loadFromFile]);
|
||||||
const [currentBody, setCurrentBody] = useStateWithDeps<{
|
const [currentBody, setCurrentBody] = useStateWithDeps<{
|
||||||
query: string;
|
query: string;
|
||||||
variables: string | undefined;
|
variables: string | undefined;
|
||||||
@@ -160,14 +199,37 @@ function GraphQLEditorInner({ request, onChange, baseRequest, ...extraEditorProp
|
|||||||
...((schema != null
|
...((schema != null
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
label: "Clear",
|
label: "Clear Schema",
|
||||||
onSelect: clear,
|
onSelect: clear,
|
||||||
color: "danger",
|
color: "danger",
|
||||||
leftSlot: <Icon icon="trash" />,
|
leftSlot: <Icon icon="trash" />,
|
||||||
},
|
},
|
||||||
{ type: "separator" },
|
|
||||||
]
|
]
|
||||||
: []) satisfies DropdownItem[]),
|
: []) satisfies DropdownItem[]),
|
||||||
|
{
|
||||||
|
// Labels the source actions below it, so the menu says where the
|
||||||
|
// schema came from without spending a row on it.
|
||||||
|
type: "separator",
|
||||||
|
hidden: schema == null && filePath == null,
|
||||||
|
label:
|
||||||
|
fileName == null || filePath == null ? undefined : (
|
||||||
|
// Middle truncation: the head shrinks and ellipsizes while the
|
||||||
|
// tail is pinned, so the extension always survives. Full path
|
||||||
|
// on hover.
|
||||||
|
<div className="flex min-w-0 max-w-[16rem] font-mono text-xs" title={filePath}>
|
||||||
|
<span className="truncate">{fileName.slice(0, -FILE_NAME_TAIL_CHARS)}</span>
|
||||||
|
<span className="shrink-0">{fileName.slice(-FILE_NAME_TAIL_CHARS)}</span>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
action:
|
||||||
|
filePath == null
|
||||||
|
? undefined
|
||||||
|
: {
|
||||||
|
icon: "folder_symlink",
|
||||||
|
title: revealInFinderText,
|
||||||
|
onClick: () => platform.revealItemInDir(filePath),
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
hidden: !error,
|
hidden: !error,
|
||||||
label: (
|
label: (
|
||||||
@@ -210,25 +272,33 @@ function GraphQLEditorInner({ request, onChange, baseRequest, ...extraEditorProp
|
|||||||
type: "content",
|
type: "content",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
hidden: schema == null,
|
// One refresh action for either source: re-read the file, or
|
||||||
label: `${isDocOpen ? "Hide" : "Show"} Documentation`,
|
// re-introspect the server.
|
||||||
leftSlot: <Icon icon="book_open_text" />,
|
label: "Reload Schema",
|
||||||
onSelect: () => {
|
leftSlot: <Icon icon="refresh" spin={isLoading} />,
|
||||||
setGraphqlDocStateAtomValue((v) => ({
|
keepOpenOnSelect: true,
|
||||||
...v,
|
// Failures surface through the hook's error state either way.
|
||||||
[request.id]: isDocOpen ? undefined : null,
|
onSelect: async () => {
|
||||||
}));
|
if (filePath != null) await reloadFromFile();
|
||||||
|
else await refetch();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: "Introspect Schema",
|
label: filePath == null ? "Load Schema from File…" : "Load a Different File…",
|
||||||
leftSlot: <Icon icon="refresh" spin={isLoading} />,
|
leftSlot: <Icon icon="import" />,
|
||||||
keepOpenOnSelect: true,
|
onSelect: handleLoadFromFile,
|
||||||
onSelect: refetch,
|
|
||||||
},
|
},
|
||||||
{ type: "separator", label: "Setting" },
|
|
||||||
{
|
{
|
||||||
label: "Automatic Introspection",
|
hidden: filePath == null,
|
||||||
|
label: "Stop Using File",
|
||||||
|
leftSlot: <Icon icon="x" />,
|
||||||
|
onSelect: removeSchemaFile,
|
||||||
|
},
|
||||||
|
{ type: "separator", label: "Settings" },
|
||||||
|
{
|
||||||
|
// Governs both sources: re-introspecting the server, and
|
||||||
|
// re-reading the file when the request is opened.
|
||||||
|
label: filePath == null ? "Automatic Introspection" : "Automatic Reload",
|
||||||
keepOpenOnSelect: true,
|
keepOpenOnSelect: true,
|
||||||
onSelect: () => {
|
onSelect: () => {
|
||||||
setAutoIntrospectDisabled({
|
setAutoIntrospectDisabled({
|
||||||
@@ -261,6 +331,29 @@ function GraphQLEditorInner({ request, onChange, baseRequest, ...extraEditorProp
|
|||||||
</Dropdown>
|
</Dropdown>
|
||||||
)}
|
)}
|
||||||
</div>,
|
</div>,
|
||||||
|
// Sits after the schema control it depends on. Always rendered, disabled
|
||||||
|
// without a schema, so the row never changes shape.
|
||||||
|
<div key="documentation" className="opacity-100!">
|
||||||
|
<IconButton
|
||||||
|
size="sm"
|
||||||
|
variant="border"
|
||||||
|
icon="book_open_text"
|
||||||
|
disabled={schema == null}
|
||||||
|
title={
|
||||||
|
schema == null
|
||||||
|
? "Documentation unavailable without a schema"
|
||||||
|
: isDocOpen
|
||||||
|
? "Hide Documentation"
|
||||||
|
: "Show Documentation"
|
||||||
|
}
|
||||||
|
onClick={() => {
|
||||||
|
setGraphqlDocStateAtomValue((v) => ({
|
||||||
|
...v,
|
||||||
|
[request.id]: isDocOpen ? undefined : null,
|
||||||
|
}));
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
schema,
|
schema,
|
||||||
@@ -272,6 +365,11 @@ function GraphQLEditorInner({ request, onChange, baseRequest, ...extraEditorProp
|
|||||||
isLoading,
|
isLoading,
|
||||||
operationNames,
|
operationNames,
|
||||||
refetch,
|
refetch,
|
||||||
|
handleLoadFromFile,
|
||||||
|
reloadFromFile,
|
||||||
|
removeSchemaFile,
|
||||||
|
filePath,
|
||||||
|
fileName,
|
||||||
autoIntrospectDisabled,
|
autoIntrospectDisabled,
|
||||||
baseRequest.id,
|
baseRequest.id,
|
||||||
setGraphqlDocStateAtomValue,
|
setGraphqlDocStateAtomValue,
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
import { convertFileSrc } from "@tauri-apps/api/core";
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
bodyPath?: string;
|
/** A URL for the body the host already stored. */
|
||||||
|
bodyUrl?: string;
|
||||||
data?: Uint8Array;
|
data?: Uint8Array;
|
||||||
mimeType?: string;
|
mimeType?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function AudioViewer({ bodyPath, data, mimeType }: Props) {
|
export function AudioViewer({ bodyUrl, data, mimeType }: Props) {
|
||||||
const [src, setSrc] = useState<string>();
|
const [src, setSrc] = useState<string>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (bodyPath) {
|
if (bodyUrl) {
|
||||||
setSrc(convertFileSrc(bodyPath));
|
setSrc(bodyUrl);
|
||||||
} else if (data) {
|
} else if (data) {
|
||||||
// The type matters here in a way it doesn't for an image: a media element goes by what
|
// The type matters here in a way it doesn't for an image: a media element goes by what
|
||||||
// the blob declares rather than sniffing it, so an Ogg labelled as MP3 won't play
|
// the blob declares rather than sniffing it, so an Ogg labelled as MP3 won't play
|
||||||
const blob = new Blob([new Uint8Array(data)], { type: mimeType ?? "audio/mpeg" });
|
const blob = new Blob([new Uint8Array(data)], { type: mimeType ?? "audio/mpeg" });
|
||||||
const url = URL.createObjectURL(blob);
|
const objectUrl = URL.createObjectURL(blob);
|
||||||
setSrc(url);
|
setSrc(objectUrl);
|
||||||
return () => URL.revokeObjectURL(url);
|
return () => URL.revokeObjectURL(objectUrl);
|
||||||
} else {
|
} else {
|
||||||
setSrc(undefined);
|
setSrc(undefined);
|
||||||
}
|
}
|
||||||
}, [bodyPath, data, mimeType]);
|
}, [bodyUrl, data, mimeType]);
|
||||||
|
|
||||||
// oxlint-disable-next-line jsx-a11y/media-has-caption
|
// oxlint-disable-next-line jsx-a11y/media-has-caption
|
||||||
return <audio className="w-full" controls src={src} />;
|
return <audio className="w-full" controls src={src} />;
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import type { ReactNode } from "react";
|
||||||
|
import { renderToStaticMarkup } from "react-dom/server";
|
||||||
|
import { describe, expect, test, vi } from "vite-plus/test";
|
||||||
|
import { CsvViewerInner } from "./CsvViewer";
|
||||||
|
|
||||||
|
vi.mock("@yaakapp-internal/ui", () => ({
|
||||||
|
Table: ({ children }: { children: ReactNode }) => <table>{children}</table>,
|
||||||
|
TableBody: ({ children }: { children: ReactNode }) => <tbody>{children}</tbody>,
|
||||||
|
TableCell: ({ children }: { children: ReactNode }) => <td>{children}</td>,
|
||||||
|
TableHead: ({ children }: { children: ReactNode }) => <thead>{children}</thead>,
|
||||||
|
TableHeaderCell: ({ children }: { children: ReactNode }) => <th>{children}</th>,
|
||||||
|
TableRow: ({ children }: { children: ReactNode }) => <tr>{children}</tr>,
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe("CsvViewer", () => {
|
||||||
|
test("renders columns that extend beyond the first row", () => {
|
||||||
|
const markup = renderToStaticMarkup(
|
||||||
|
<CsvViewerInner
|
||||||
|
text={[
|
||||||
|
"startDate,2026-02-03T00:00-03:00",
|
||||||
|
"endDate,2026-02-03T23:59:59-03:00",
|
||||||
|
"id,Fecha de inicio,Nombre,Estado,Perfil de puesto,ID de sucursal,Sucursal,Fecha de fin,ID de usuario",
|
||||||
|
"391118210,2026-02-03 12:58:55,atencion1,Disponible,ATD,3549,sucursal,2026-02-03 12:59:08,42041",
|
||||||
|
].join("\n")}
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(markup).toContain("ID de usuario");
|
||||||
|
expect(markup).toContain("42041");
|
||||||
|
expect(markup.match(/<td>/g)).toHaveLength(20);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -26,27 +26,33 @@ export function CsvViewer({ text, className }: Props) {
|
|||||||
export function CsvViewerInner({ text, className }: { text: string | null; className?: string }) {
|
export function CsvViewerInner({ text, className }: { text: string | null; className?: string }) {
|
||||||
const parsed = useMemo(() => {
|
const parsed = useMemo(() => {
|
||||||
if (text == null) return null;
|
if (text == null) return null;
|
||||||
return Papa.parse<Record<string, string>>(text, { header: true, skipEmptyLines: true });
|
return Papa.parse<string[]>(text, { skipEmptyLines: true });
|
||||||
}, [text]);
|
}, [text]);
|
||||||
|
|
||||||
if (parsed === null) return null;
|
if (parsed === null) return null;
|
||||||
|
|
||||||
|
const header = parsed.data[0] ?? [];
|
||||||
|
const rows = parsed.data.slice(1);
|
||||||
|
const columnCount = parsed.data.reduce((count, row) => Math.max(count, row.length), 0);
|
||||||
|
const columnIndexes = Array.from({ length: columnCount }, (_, index) => index);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="overflow-auto h-full">
|
<div className="overflow-auto h-full">
|
||||||
<Table className={classNames(className, "text-sm")}>
|
<Table className={classNames(className, "text-sm")}>
|
||||||
<TableHead>
|
<TableHead>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
{parsed.meta.fields?.map((field) => (
|
{columnIndexes.map((columnIndex) => (
|
||||||
<TableHeaderCell key={field}>{field}</TableHeaderCell>
|
<TableHeaderCell key={columnIndex}>{header[columnIndex] ?? ""}</TableHeaderCell>
|
||||||
))}
|
))}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{parsed.data.map((row, i) => (
|
{rows.map((row, i) => (
|
||||||
// oxlint-disable-next-line react/no-array-index-key
|
// oxlint-disable-next-line react/no-array-index-key
|
||||||
<TableRow key={i}>
|
<TableRow key={i}>
|
||||||
{parsed.meta.fields?.map((key) => (
|
{row.map((cell, columnIndex) => (
|
||||||
<TableCell key={key}>{row[key] ?? ""}</TableCell>
|
// oxlint-disable-next-line react/no-array-index-key
|
||||||
|
<TableCell key={columnIndex}>{cell}</TableCell>
|
||||||
))}
|
))}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import type { HttpResponse } from "@yaakapp-internal/models";
|
import type { HttpResponse } from "@yaakapp-internal/models";
|
||||||
import { useMemo, useState } from "react";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { useCallback } from "react";
|
||||||
import { useCopyHttpResponse } from "../../hooks/useCopyHttpResponse";
|
import { useCopyHttpResponse } from "../../hooks/useCopyHttpResponse";
|
||||||
import { useResponseBodyText } from "../../hooks/useResponseBodyText";
|
import { responseBodyTextQuery, useResponseBodyText } from "../../hooks/useResponseBodyText";
|
||||||
|
import { useResponseFilter } from "../../hooks/useResponseFilter";
|
||||||
import { useSaveResponse } from "../../hooks/useSaveResponse";
|
import { useSaveResponse } from "../../hooks/useSaveResponse";
|
||||||
import { languageFromContentType } from "../../lib/contentType";
|
import { languageFromContentType } from "../../lib/contentType";
|
||||||
import { getContentTypeFromHeaders } from "../../lib/model_util";
|
import { getContentTypeFromHeaders } from "../../lib/model_util";
|
||||||
@@ -52,30 +54,25 @@ interface HttpTextViewerProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function HttpTextViewer({ response, text, language, pretty, className }: HttpTextViewerProps) {
|
function HttpTextViewer({ response, text, language, pretty, className }: HttpTextViewerProps) {
|
||||||
const [currentFilter, setCurrentFilter] = useState<string | null>(null);
|
const queryClient = useQueryClient();
|
||||||
const filteredBody = useResponseBodyText({ response, filter: currentFilter });
|
const filter = useResponseFilter({
|
||||||
|
stateKey: `response.body.${response.requestId}`,
|
||||||
|
// Shares the display query's cache entry, so the verdict costs no extra RPC
|
||||||
|
runFilter: useCallback(
|
||||||
|
(f: string) => queryClient.fetchQuery(responseBodyTextQuery({ response, filter: f })),
|
||||||
|
[queryClient, response],
|
||||||
|
),
|
||||||
|
});
|
||||||
|
const filteredBody = useResponseBodyText({ response, filter: filter.appliedFilter });
|
||||||
const saveResponse = useSaveResponse(response);
|
const saveResponse = useSaveResponse(response);
|
||||||
const copyResponse = useCopyHttpResponse(response);
|
const copyResponse = useCopyHttpResponse(response);
|
||||||
const actionsDisabled = response.state !== "closed" && response.status >= 100;
|
const actionsDisabled = response.state !== "closed" && response.status >= 100;
|
||||||
|
|
||||||
const filterCallback = useMemo(
|
|
||||||
() => (filter: string) => {
|
|
||||||
setCurrentFilter(filter);
|
|
||||||
return {
|
|
||||||
data: filteredBody.data,
|
|
||||||
isPending: filteredBody.isPending,
|
|
||||||
error: !!filteredBody.error,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
[filteredBody],
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TextViewer
|
<TextViewer
|
||||||
text={text}
|
text={text}
|
||||||
language={language}
|
language={language}
|
||||||
stateKey={`response.body.${response.id}`}
|
stateKey={`response.body.${response.id}`}
|
||||||
filterStateKey={`response.body.${response.requestId}`}
|
|
||||||
pretty={pretty}
|
pretty={pretty}
|
||||||
className={className}
|
className={className}
|
||||||
footerActions={[
|
footerActions={[
|
||||||
@@ -98,7 +95,12 @@ function HttpTextViewer({ response, text, language, pretty, className }: HttpTex
|
|||||||
className="border !border-border-subtle"
|
className="border !border-border-subtle"
|
||||||
/>,
|
/>,
|
||||||
]}
|
]}
|
||||||
onFilter={filterCallback}
|
filter={filter}
|
||||||
|
filterResult={{
|
||||||
|
data: filteredBody.data,
|
||||||
|
isPending: filteredBody.isPending,
|
||||||
|
error: !!filteredBody.error,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { convertFileSrc } from "@tauri-apps/api/core";
|
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
type Props = { className?: string; mimeType?: string } & (
|
type Props = { className?: string; mimeType?: string } & (
|
||||||
| {
|
| {
|
||||||
bodyPath: string;
|
/** A URL for the body the host already stored. */
|
||||||
|
bodyUrl: string;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
data: ArrayBuffer;
|
data: ArrayBuffer;
|
||||||
@@ -13,21 +13,21 @@ type Props = { className?: string; mimeType?: string } & (
|
|||||||
|
|
||||||
export function ImageViewer({ className, mimeType, ...props }: Props) {
|
export function ImageViewer({ className, mimeType, ...props }: Props) {
|
||||||
const [src, setSrc] = useState<string>();
|
const [src, setSrc] = useState<string>();
|
||||||
const bodyPath = "bodyPath" in props ? props.bodyPath : null;
|
const bodyUrl = "bodyUrl" in props ? props.bodyUrl : null;
|
||||||
const data = "data" in props ? props.data : null;
|
const data = "data" in props ? props.data : null;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (bodyPath != null) {
|
if (bodyUrl != null) {
|
||||||
setSrc(convertFileSrc(bodyPath));
|
setSrc(bodyUrl);
|
||||||
} else if (data != null) {
|
} else if (data != null) {
|
||||||
const blob = new Blob([data], { type: mimeType ?? "image/png" });
|
const blob = new Blob([data], { type: mimeType ?? "image/png" });
|
||||||
const url = URL.createObjectURL(blob);
|
const objectUrl = URL.createObjectURL(blob);
|
||||||
setSrc(url);
|
setSrc(objectUrl);
|
||||||
return () => URL.revokeObjectURL(url);
|
return () => URL.revokeObjectURL(objectUrl);
|
||||||
} else {
|
} else {
|
||||||
setSrc(undefined);
|
setSrc(undefined);
|
||||||
}
|
}
|
||||||
}, [bodyPath, data, mimeType]);
|
}, [bodyUrl, data, mimeType]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<img
|
<img
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import "react-pdf/dist/Page/TextLayer.css";
|
import "react-pdf/dist/Page/TextLayer.css";
|
||||||
import "react-pdf/dist/Page/AnnotationLayer.css";
|
import "react-pdf/dist/Page/AnnotationLayer.css";
|
||||||
import { convertFileSrc } from "@tauri-apps/api/core";
|
|
||||||
import "./PdfViewer.css";
|
import "./PdfViewer.css";
|
||||||
import type { PDFDocumentProxy } from "pdfjs-dist";
|
import type { PDFDocumentProxy } from "pdfjs-dist";
|
||||||
import { useMemo, useRef, useState } from "react";
|
import { useMemo, useRef, useState } from "react";
|
||||||
@@ -18,7 +17,8 @@ fireAndForget(
|
|||||||
);
|
);
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
bodyPath?: string;
|
/** A URL for the body the host already stored. */
|
||||||
|
bodyUrl?: string;
|
||||||
data?: Uint8Array;
|
data?: Uint8Array;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,7 +27,7 @@ const options = {
|
|||||||
standardFontDataUrl: "/standard_fonts/",
|
standardFontDataUrl: "/standard_fonts/",
|
||||||
};
|
};
|
||||||
|
|
||||||
export function PdfViewer({ bodyPath, data }: Props) {
|
export function PdfViewer({ bodyUrl, data }: Props) {
|
||||||
const containerRef = useRef<HTMLDivElement>(null);
|
const containerRef = useRef<HTMLDivElement>(null);
|
||||||
const [numPages, setNumPages] = useState<number>();
|
const [numPages, setNumPages] = useState<number>();
|
||||||
|
|
||||||
@@ -36,8 +36,8 @@ export function PdfViewer({ bodyPath, data }: Props) {
|
|||||||
// During render, not in an effect: an effect leaves the first paint with no file, and
|
// During render, not in an effect: an effect leaves the first paint with no file, and
|
||||||
// `Document` renders its "Failed to load PDF file" state for that frame before recovering
|
// `Document` renders its "Failed to load PDF file" state for that frame before recovering
|
||||||
const src = useMemo(() => {
|
const src = useMemo(() => {
|
||||||
if (bodyPath) {
|
if (bodyUrl) {
|
||||||
return convertFileSrc(bodyPath);
|
return bodyUrl;
|
||||||
}
|
}
|
||||||
if (data) {
|
if (data) {
|
||||||
// Create a copy to avoid "Buffer is already detached" errors
|
// Create a copy to avoid "Buffer is already detached" errors
|
||||||
@@ -45,7 +45,7 @@ export function PdfViewer({ bodyPath, data }: Props) {
|
|||||||
return { data: new Uint8Array(data) };
|
return { data: new Uint8Array(data) };
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}, [bodyPath, data]);
|
}, [bodyUrl, data]);
|
||||||
|
|
||||||
const onDocumentLoadSuccess = ({ numPages: nextNumPages }: PDFDocumentProxy): void => {
|
const onDocumentLoadSuccess = ({ numPages: nextNumPages }: PDFDocumentProxy): void => {
|
||||||
setNumPages(nextNumPages);
|
setNumPages(nextNumPages);
|
||||||
|
|||||||
@@ -0,0 +1,96 @@
|
|||||||
|
import { Icon } from "@yaakapp-internal/ui";
|
||||||
|
import type { RecentFilter } from "../../hooks/useRecentFilters";
|
||||||
|
import { Dropdown, type DropdownItem } from "../core/Dropdown";
|
||||||
|
import { IconButton } from "../core/IconButton";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
recentFilters: RecentFilter[];
|
||||||
|
activeFilter: string | null;
|
||||||
|
onSelect: (value: string) => void;
|
||||||
|
onRemove: (value: string) => void;
|
||||||
|
onTogglePin: (value: string) => void;
|
||||||
|
onClear: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RecentFiltersDropdown({
|
||||||
|
recentFilters,
|
||||||
|
activeFilter,
|
||||||
|
onSelect,
|
||||||
|
onRemove,
|
||||||
|
onTogglePin,
|
||||||
|
onClear,
|
||||||
|
}: Props) {
|
||||||
|
const pinned = recentFilters.filter((f) => f.pinned);
|
||||||
|
const unpinned = recentFilters.filter((f) => !f.pinned);
|
||||||
|
|
||||||
|
const toItem = (filter: RecentFilter): DropdownItem => ({
|
||||||
|
label: (
|
||||||
|
<div className="font-mono text-sm truncate max-w-sm" title={filter.value}>
|
||||||
|
{filter.value}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
leftSlot: <Icon icon={filter.value === activeFilter ? "check" : "empty"} />,
|
||||||
|
onSelect: () => onSelect(filter.value),
|
||||||
|
submenuTrigger: "button",
|
||||||
|
submenu: [
|
||||||
|
{
|
||||||
|
label: filter.pinned ? "Unpin" : "Pin",
|
||||||
|
icon: filter.pinned ? "unpin" : "pin",
|
||||||
|
keepOpenOnSelect: true,
|
||||||
|
onSelect: () => onTogglePin(filter.value),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Remove",
|
||||||
|
icon: "trash",
|
||||||
|
color: "danger",
|
||||||
|
keepOpenOnSelect: true,
|
||||||
|
onSelect: () => onRemove(filter.value),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const items: DropdownItem[] = [];
|
||||||
|
|
||||||
|
if (recentFilters.length === 0) {
|
||||||
|
items.push({
|
||||||
|
type: "content",
|
||||||
|
label: (
|
||||||
|
<span className="block px-4 py-1 text-sm text-text-subtle">
|
||||||
|
Filters you use are remembered here
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pinned.length > 0) {
|
||||||
|
items.push({ type: "separator", label: "Pinned" }, ...pinned.map(toItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unpinned.length > 0) {
|
||||||
|
items.push({ type: "separator", label: "Recent" }, ...unpinned.map(toItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (recentFilters.length > 0) {
|
||||||
|
items.push(
|
||||||
|
{ type: "separator" },
|
||||||
|
{
|
||||||
|
label: "Clear All",
|
||||||
|
leftSlot: <Icon icon="trash" />,
|
||||||
|
color: "danger",
|
||||||
|
onSelect: onClear,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dropdown items={items}>
|
||||||
|
<IconButton
|
||||||
|
size="xs"
|
||||||
|
icon="filter"
|
||||||
|
title="Recent filters"
|
||||||
|
iconColor="secondary"
|
||||||
|
className="w-8 ml-0.5 mr-1 h-auto!"
|
||||||
|
/>
|
||||||
|
</Dropdown>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,14 +1,15 @@
|
|||||||
import classNames from "classnames";
|
|
||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { Children, useCallback, useMemo } from "react";
|
import { Children, useCallback, useMemo } from "react";
|
||||||
import { createGlobalState } from "react-use";
|
import { Banner, HStack, Icon, InlineCode } from "@yaakapp-internal/ui";
|
||||||
import { useDebouncedValue } from "@yaakapp-internal/ui";
|
|
||||||
import { useFormatText } from "../../hooks/useFormatText";
|
import { useFormatText } from "../../hooks/useFormatText";
|
||||||
|
import type { ResponseFilterApi } from "../../hooks/useResponseFilter";
|
||||||
|
import { Button } from "../core/Button";
|
||||||
import type { EditorProps } from "../core/Editor/Editor";
|
import type { EditorProps } from "../core/Editor/Editor";
|
||||||
import { hyperlink } from "../core/Editor/hyperlink/extension";
|
import { hyperlink } from "../core/Editor/hyperlink/extension";
|
||||||
import { Editor } from "../core/Editor/LazyEditor";
|
import { Editor } from "../core/Editor/LazyEditor";
|
||||||
import { IconButton } from "../core/IconButton";
|
import { IconButton } from "../core/IconButton";
|
||||||
import { Input } from "../core/Input";
|
import { Input } from "../core/Input";
|
||||||
|
import { RecentFiltersDropdown } from "./RecentFiltersDropdown";
|
||||||
|
|
||||||
const extraExtensions = [hyperlink];
|
const extraExtensions = [hyperlink];
|
||||||
|
|
||||||
@@ -16,57 +17,45 @@ interface Props {
|
|||||||
text: string;
|
text: string;
|
||||||
language: EditorProps["language"];
|
language: EditorProps["language"];
|
||||||
stateKey: string | null;
|
stateKey: string | null;
|
||||||
filterStateKey?: string | null;
|
|
||||||
pretty?: boolean;
|
pretty?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
footerActions?: ReactNode;
|
footerActions?: ReactNode;
|
||||||
onFilter?: (filter: string) => {
|
filter?: ResponseFilterApi;
|
||||||
|
filterResult?: {
|
||||||
data: string | null | undefined;
|
data: string | null | undefined;
|
||||||
isPending: boolean;
|
isPending: boolean;
|
||||||
error: boolean;
|
error: boolean;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const useFilterText = createGlobalState<Record<string, string | null>>({});
|
|
||||||
|
|
||||||
export function TextViewer({
|
export function TextViewer({
|
||||||
language,
|
language,
|
||||||
text,
|
text,
|
||||||
stateKey,
|
stateKey,
|
||||||
filterStateKey,
|
|
||||||
pretty,
|
pretty,
|
||||||
className,
|
className,
|
||||||
footerActions,
|
footerActions,
|
||||||
onFilter,
|
filter,
|
||||||
|
filterResult,
|
||||||
}: Props) {
|
}: Props) {
|
||||||
const filterKey = filterStateKey ?? stateKey;
|
const canFilter =
|
||||||
const [filterTextMap, setFilterTextMap] = useFilterText();
|
filter != null && (language === "json" || language === "xml" || language === "html");
|
||||||
const filterText = filterKey ? (filterTextMap[filterKey] ?? null) : null;
|
const isSearching = filter?.isSearching ?? false;
|
||||||
const debouncedFilterText = useDebouncedValue(filterText);
|
const appliedFilter = filter?.appliedFilter ?? null;
|
||||||
const setFilterText = useCallback(
|
const resultError = filterResult?.error ?? false;
|
||||||
(v: string | null) => {
|
|
||||||
if (!filterKey) return;
|
const handleFilterKeyDown = useCallback(
|
||||||
setFilterTextMap((m) => ({ ...m, [filterKey]: v }));
|
(e: KeyboardEvent) => {
|
||||||
|
if (filter == null) return;
|
||||||
|
if (e.key === "Escape") {
|
||||||
|
filter.toggleSearch();
|
||||||
|
} else if (e.key === "Enter" && filter.filterText != null) {
|
||||||
|
filter.applyFilter(filter.filterText);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[filterKey, setFilterTextMap],
|
[filter],
|
||||||
);
|
);
|
||||||
|
|
||||||
const isSearching = filterText != null;
|
|
||||||
const filteredResponse =
|
|
||||||
onFilter && debouncedFilterText
|
|
||||||
? onFilter(debouncedFilterText)
|
|
||||||
: { data: null, isPending: false, error: false };
|
|
||||||
|
|
||||||
const toggleSearch = useCallback(() => {
|
|
||||||
if (isSearching) {
|
|
||||||
setFilterText(null);
|
|
||||||
} else {
|
|
||||||
setFilterText("");
|
|
||||||
}
|
|
||||||
}, [isSearching, setFilterText]);
|
|
||||||
|
|
||||||
const canFilter = onFilter && (language === "json" || language === "xml" || language === "html");
|
|
||||||
|
|
||||||
const actions = useMemo<ReactNode[]>(() => {
|
const actions = useMemo<ReactNode[]>(() => {
|
||||||
const nodes: ReactNode[] = isSearching ? [] : Children.toArray(footerActions);
|
const nodes: ReactNode[] = isSearching ? [] : Children.toArray(footerActions);
|
||||||
|
|
||||||
@@ -76,8 +65,8 @@ export function TextViewer({
|
|||||||
nodes.push(
|
nodes.push(
|
||||||
<div key="input" className="w-full opacity-100!">
|
<div key="input" className="w-full opacity-100!">
|
||||||
<Input
|
<Input
|
||||||
key={filterKey ?? "filter"}
|
key={filter.stateKey ?? "filter"}
|
||||||
validate={!filteredResponse.error}
|
validate={!resultError}
|
||||||
hideLabel
|
hideLabel
|
||||||
autoFocus
|
autoFocus
|
||||||
containerClassName="bg-surface"
|
containerClassName="bg-surface"
|
||||||
@@ -85,39 +74,62 @@ export function TextViewer({
|
|||||||
placeholder={language === "json" ? "JSONPath expression" : "XPath expression"}
|
placeholder={language === "json" ? "JSONPath expression" : "XPath expression"}
|
||||||
label="Filter expression"
|
label="Filter expression"
|
||||||
name="filter"
|
name="filter"
|
||||||
defaultValue={filterText}
|
defaultValue={filter.filterText}
|
||||||
onKeyDown={(e) => e.key === "Escape" && toggleSearch()}
|
forceUpdateKey={filter.filterUpdateKey}
|
||||||
onChange={setFilterText}
|
onKeyDown={handleFilterKeyDown}
|
||||||
stateKey={filterKey ? `filter.${filterKey}` : null}
|
onChange={filter.setFilterText}
|
||||||
|
stateKey={filter.stateKey ? `filter.${filter.stateKey}` : null}
|
||||||
|
leftSlot={
|
||||||
|
<div className="py-0.5 flex">
|
||||||
|
<RecentFiltersDropdown
|
||||||
|
recentFilters={filter.recentFilters}
|
||||||
|
activeFilter={filter.appliedFilter}
|
||||||
|
onSelect={filter.replaceFilter}
|
||||||
|
onRemove={filter.removeRecentFilter}
|
||||||
|
onTogglePin={filter.togglePinRecentFilter}
|
||||||
|
onClear={filter.clearRecentFilters}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
rightSlot={
|
||||||
|
<div className="py-0.5 flex">
|
||||||
|
<IconButton
|
||||||
|
size="xs"
|
||||||
|
icon="x"
|
||||||
|
title="Close filter"
|
||||||
|
iconColor="secondary"
|
||||||
|
onClick={filter.toggleSearch}
|
||||||
|
className="w-8 mr-0.5 h-auto!"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
</div>,
|
</div>,
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
nodes.push(
|
||||||
|
<IconButton
|
||||||
|
key="icon"
|
||||||
|
size="sm"
|
||||||
|
isLoading={filterResult?.isPending ?? false}
|
||||||
|
icon="filter"
|
||||||
|
title="Filter response"
|
||||||
|
onClick={filter.toggleSearch}
|
||||||
|
className="border border-border-subtle!"
|
||||||
|
/>,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes.push(
|
|
||||||
<IconButton
|
|
||||||
key="icon"
|
|
||||||
size="sm"
|
|
||||||
isLoading={filteredResponse.isPending}
|
|
||||||
icon={isSearching ? "x" : "filter"}
|
|
||||||
title={isSearching ? "Close filter" : "Filter response"}
|
|
||||||
onClick={toggleSearch}
|
|
||||||
className={classNames("border border-border-subtle!", isSearching && "opacity-100!")}
|
|
||||||
/>,
|
|
||||||
);
|
|
||||||
|
|
||||||
return nodes;
|
return nodes;
|
||||||
}, [
|
}, [
|
||||||
canFilter,
|
canFilter,
|
||||||
footerActions,
|
footerActions,
|
||||||
filterKey,
|
filter,
|
||||||
filterText,
|
filterResult?.isPending,
|
||||||
filteredResponse.error,
|
resultError,
|
||||||
filteredResponse.isPending,
|
|
||||||
isSearching,
|
isSearching,
|
||||||
language,
|
language,
|
||||||
setFilterText,
|
handleFilterKeyDown,
|
||||||
toggleSearch,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const formattedBody = useFormatText({ text, language, pretty: pretty ?? false });
|
const formattedBody = useFormatText({ text, language, pretty: pretty ?? false });
|
||||||
@@ -126,11 +138,11 @@ export function TextViewer({
|
|||||||
}
|
}
|
||||||
|
|
||||||
let body: string;
|
let body: string;
|
||||||
if (isSearching && filterText?.length > 0) {
|
if (appliedFilter) {
|
||||||
if (filteredResponse.error) {
|
if (resultError) {
|
||||||
body = "";
|
body = "";
|
||||||
} else {
|
} else {
|
||||||
body = filteredResponse.data != null ? filteredResponse.data : "";
|
body = filterResult?.data != null ? filterResult.data : "";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
body = formattedBody;
|
body = formattedBody;
|
||||||
@@ -143,15 +155,61 @@ export function TextViewer({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Editor
|
<div className="grid grid-rows-[auto_minmax(0,1fr)] h-full w-full">
|
||||||
readOnly
|
{appliedFilter && filter != null ? (
|
||||||
className={className}
|
<AppliedFilterBar
|
||||||
defaultValue={body}
|
filter={appliedFilter}
|
||||||
language={language}
|
error={resultError}
|
||||||
actions={actions}
|
onClear={() => filter.replaceFilter("")}
|
||||||
extraExtensions={extraExtensions}
|
/>
|
||||||
stateKey={stateKey}
|
) : (
|
||||||
/>
|
<span />
|
||||||
|
)}
|
||||||
|
<Editor
|
||||||
|
readOnly
|
||||||
|
className={className}
|
||||||
|
defaultValue={body}
|
||||||
|
language={language}
|
||||||
|
actions={actions}
|
||||||
|
extraExtensions={extraExtensions}
|
||||||
|
stateKey={stateKey}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows what's actually filtering the body, which the filter box below can't convey
|
||||||
|
* once it holds an edited expression that hasn't been applied yet.
|
||||||
|
*/
|
||||||
|
function AppliedFilterBar({
|
||||||
|
filter,
|
||||||
|
error,
|
||||||
|
onClear,
|
||||||
|
}: {
|
||||||
|
filter: string;
|
||||||
|
error: boolean;
|
||||||
|
onClear: () => void;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Banner color={error ? "danger" : "info"} className="py-1! mb-2! text-sm">
|
||||||
|
<HStack space={2} className="min-w-0">
|
||||||
|
<Icon icon="filter" size="xs" className="shrink-0 opacity-70" />
|
||||||
|
<span className="truncate min-w-0" title={filter}>
|
||||||
|
Response filtered by <InlineCode>{filter}</InlineCode>
|
||||||
|
{error && " (invalid expression)"}
|
||||||
|
</span>
|
||||||
|
<Button
|
||||||
|
size="2xs"
|
||||||
|
variant="border"
|
||||||
|
color={error ? "danger" : "info"}
|
||||||
|
className="ml-auto shrink-0"
|
||||||
|
onClick={onClear}
|
||||||
|
>
|
||||||
|
Clear
|
||||||
|
</Button>
|
||||||
|
</HStack>
|
||||||
|
</Banner>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
import { convertFileSrc } from "@tauri-apps/api/core";
|
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
bodyPath?: string;
|
/** A URL for the body the host already stored. */
|
||||||
|
bodyUrl?: string;
|
||||||
data?: Uint8Array;
|
data?: Uint8Array;
|
||||||
mimeType?: string;
|
mimeType?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function VideoViewer({ bodyPath, data, mimeType }: Props) {
|
export function VideoViewer({ bodyUrl, data, mimeType }: Props) {
|
||||||
const [src, setSrc] = useState<string>();
|
const [src, setSrc] = useState<string>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (bodyPath) {
|
if (bodyUrl) {
|
||||||
setSrc(convertFileSrc(bodyPath));
|
setSrc(bodyUrl);
|
||||||
} else if (data) {
|
} else if (data) {
|
||||||
// As in AudioViewer: a media element trusts the declared type instead of sniffing
|
// As in AudioViewer: a media element trusts the declared type instead of sniffing
|
||||||
const blob = new Blob([new Uint8Array(data)], { type: mimeType ?? "video/mp4" });
|
const blob = new Blob([new Uint8Array(data)], { type: mimeType ?? "video/mp4" });
|
||||||
const url = URL.createObjectURL(blob);
|
const objectUrl = URL.createObjectURL(blob);
|
||||||
setSrc(url);
|
setSrc(objectUrl);
|
||||||
return () => URL.revokeObjectURL(url);
|
return () => URL.revokeObjectURL(objectUrl);
|
||||||
} else {
|
} else {
|
||||||
setSrc(undefined);
|
setSrc(undefined);
|
||||||
}
|
}
|
||||||
}, [bodyPath, data, mimeType]);
|
}, [bodyUrl, data, mimeType]);
|
||||||
|
|
||||||
// oxlint-disable-next-line jsx-a11y/media-has-caption
|
// oxlint-disable-next-line jsx-a11y/media-has-caption
|
||||||
return <video className="w-full" controls src={src} />;
|
return <video className="w-full" controls src={src} />;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Listen for settings changes, the re-compute theme
|
// Listen for settings changes, the re-compute theme
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import type { ModelPayload } from "@yaakapp-internal/models";
|
import type { ModelPayload } from "@yaakapp-internal/models";
|
||||||
import { fireAndForget } from "./lib/fireAndForget";
|
import { fireAndForget } from "./lib/fireAndForget";
|
||||||
import { getSettings } from "./lib/settings";
|
import { getSettings } from "./lib/settings";
|
||||||
@@ -8,12 +8,12 @@ function setFontSizeOnDocument(fontSize: number) {
|
|||||||
document.documentElement.style.fontSize = `${fontSize}px`;
|
document.documentElement.style.fontSize = `${fontSize}px`;
|
||||||
}
|
}
|
||||||
|
|
||||||
listen<ModelPayload[]>("model_writes", async (event) => {
|
platform.listen<ModelPayload[]>("model_writes", (payloads) => {
|
||||||
for (const payload of event.payload) {
|
for (const payload of payloads) {
|
||||||
if (payload.change.type !== "upsert") continue;
|
if (payload.change.type !== "upsert") continue;
|
||||||
if (payload.model.model !== "settings") continue;
|
if (payload.model.model !== "settings") continue;
|
||||||
setFontSizeOnDocument(payload.model.interfaceFontSize);
|
setFontSizeOnDocument(payload.model.interfaceFontSize);
|
||||||
}
|
}
|
||||||
}).catch(console.error);
|
});
|
||||||
|
|
||||||
fireAndForget(getSettings().then((settings) => setFontSizeOnDocument(settings.interfaceFontSize)));
|
fireAndForget(getSettings().then((settings) => setFontSizeOnDocument(settings.interfaceFontSize)));
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Listen for settings changes, the re-compute theme
|
// Listen for settings changes, the re-compute theme
|
||||||
import { listen } from "@tauri-apps/api/event";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import type { ModelPayload, Settings } from "@yaakapp-internal/models";
|
import type { ModelPayload, Settings } from "@yaakapp-internal/models";
|
||||||
import { fireAndForget } from "./lib/fireAndForget";
|
import { fireAndForget } from "./lib/fireAndForget";
|
||||||
import { getSettings } from "./lib/settings";
|
import { getSettings } from "./lib/settings";
|
||||||
@@ -12,12 +12,12 @@ function setFonts(settings: Settings) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
listen<ModelPayload[]>("model_writes", async (event) => {
|
platform.listen<ModelPayload[]>("model_writes", (payloads) => {
|
||||||
for (const payload of event.payload) {
|
for (const payload of payloads) {
|
||||||
if (payload.change.type !== "upsert") continue;
|
if (payload.change.type !== "upsert") continue;
|
||||||
if (payload.model.model !== "settings") continue;
|
if (payload.model.model !== "settings") continue;
|
||||||
setFonts(payload.model);
|
setFonts(payload.model);
|
||||||
}
|
}
|
||||||
}).catch(console.error);
|
});
|
||||||
|
|
||||||
fireAndForget(getSettings().then((settings) => setFonts(settings)));
|
fireAndForget(getSettings().then((settings) => setFonts(settings)));
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { event } from "@tauri-apps/api";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import { useFastMutation } from "./useFastMutation";
|
import { useFastMutation } from "./useFastMutation";
|
||||||
|
|
||||||
export function useCancelHttpResponse(id: string | null) {
|
export function useCancelHttpResponse(id: string | null) {
|
||||||
return useFastMutation<void>({
|
return useFastMutation<void>({
|
||||||
mutationKey: ["cancel_http_response", id],
|
mutationKey: ["cancel_http_response", id],
|
||||||
mutationFn: () => event.emit(`cancel_http_response_${id}`),
|
mutationFn: () => platform.emit(`cancel_http_response_${id}`),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ import { InlineCode } from "@yaakapp-internal/ui";
|
|||||||
import { showAlert } from "../lib/alert";
|
import { showAlert } from "../lib/alert";
|
||||||
import { appInfo } from "../lib/appInfo";
|
import { appInfo } from "../lib/appInfo";
|
||||||
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
|
|
||||||
export function useCheckForUpdates() {
|
export function useCheckForUpdates() {
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationKey: ["check_for_updates"],
|
mutationKey: ["check_for_updates"],
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
const hasUpdate: boolean = await minPromiseMillis(invokeCmd("cmd_check_for_updates"), 500);
|
const hasUpdate: boolean = await minPromiseMillis(rpc("cmd_check_for_updates"), 500);
|
||||||
if (!hasUpdate) {
|
if (!hasUpdate) {
|
||||||
showAlert({
|
showAlert({
|
||||||
id: "no-updates",
|
id: "no-updates",
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { useFastMutation } from "./useFastMutation";
|
import { useFastMutation } from "./useFastMutation";
|
||||||
|
|
||||||
export function useDeleteGrpcConnections(requestId?: string) {
|
export function useDeleteGrpcConnections(requestId?: string) {
|
||||||
@@ -6,7 +6,7 @@ export function useDeleteGrpcConnections(requestId?: string) {
|
|||||||
mutationKey: ["delete_grpc_connections", requestId],
|
mutationKey: ["delete_grpc_connections", requestId],
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
if (requestId === undefined) return;
|
if (requestId === undefined) return;
|
||||||
await invokeCmd("cmd_delete_all_grpc_connections", { requestId });
|
await rpc("cmd_delete_all_grpc_connections", { requestId });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { useFastMutation } from "./useFastMutation";
|
import { useFastMutation } from "./useFastMutation";
|
||||||
|
|
||||||
export function useDeleteHttpResponses(requestId?: string) {
|
export function useDeleteHttpResponses(requestId?: string) {
|
||||||
@@ -6,7 +6,7 @@ export function useDeleteHttpResponses(requestId?: string) {
|
|||||||
mutationKey: ["delete_http_responses", requestId],
|
mutationKey: ["delete_http_responses", requestId],
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
if (requestId === undefined) return;
|
if (requestId === undefined) return;
|
||||||
await invokeCmd("cmd_delete_all_http_responses", { requestId });
|
await rpc("cmd_delete_all_http_responses", { requestId });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { showAlert } from "../lib/alert";
|
|||||||
import { showConfirmDelete } from "../lib/confirm";
|
import { showConfirmDelete } from "../lib/confirm";
|
||||||
import { jotaiStore } from "../lib/jotai";
|
import { jotaiStore } from "../lib/jotai";
|
||||||
import { pluralizeCount } from "../lib/pluralize";
|
import { pluralizeCount } from "../lib/pluralize";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { activeWorkspaceIdAtom } from "./useActiveWorkspace";
|
import { activeWorkspaceIdAtom } from "./useActiveWorkspace";
|
||||||
import { useFastMutation } from "./useFastMutation";
|
import { useFastMutation } from "./useFastMutation";
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ export function useDeleteSendHistory() {
|
|||||||
if (!confirmed) return false;
|
if (!confirmed) return false;
|
||||||
|
|
||||||
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
||||||
await invokeCmd("cmd_delete_send_history", { workspaceId });
|
await rpc("cmd_delete_send_history", { workspaceId });
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type {
|
|||||||
GetFolderActionsResponse,
|
GetFolderActionsResponse,
|
||||||
} from "@yaakapp-internal/plugins";
|
} from "@yaakapp-internal/plugins";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { usePluginsKey } from "./usePlugins";
|
import { usePluginsKey } from "./usePlugins";
|
||||||
|
|
||||||
export type CallableFolderAction = Pick<FolderAction, "label" | "icon"> & {
|
export type CallableFolderAction = Pick<FolderAction, "label" | "icon"> & {
|
||||||
@@ -30,7 +30,7 @@ export function useFolderActions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getFolderActions() {
|
export async function getFolderActions() {
|
||||||
const responses = await invokeCmd<GetFolderActionsResponse[]>("cmd_folder_actions");
|
const responses = await rpc<GetFolderActionsResponse[]>("cmd_folder_actions");
|
||||||
const actions = responses.flatMap((r) =>
|
const actions = responses.flatMap((r) =>
|
||||||
r.actions.map((a, i) => ({
|
r.actions.map((a, i) => ({
|
||||||
label: a.label,
|
label: a.label,
|
||||||
@@ -41,7 +41,7 @@ export async function getFolderActions() {
|
|||||||
pluginRefId: r.pluginRefId,
|
pluginRefId: r.pluginRefId,
|
||||||
args: { folder },
|
args: { folder },
|
||||||
};
|
};
|
||||||
await invokeCmd("cmd_call_folder_action", { req: payload });
|
await rpc("cmd_call_folder_action", { req: payload });
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { useKeyValue } from "./useKeyValue";
|
||||||
|
|
||||||
|
// The file a request's GraphQL schema is loaded from, or null when the schema
|
||||||
|
// comes from an introspection request.
|
||||||
|
//
|
||||||
|
// This is the *source*, not the schema. The introspection row it produces is a
|
||||||
|
// cache that expires on its own; this outlives it and regenerates it, the same
|
||||||
|
// way gRPC keeps its proto file list separate from a reflection result.
|
||||||
|
export function graphqlSchemaFileArgs(requestId: string | null) {
|
||||||
|
return {
|
||||||
|
namespace: "global" as const,
|
||||||
|
key: ["graphql_schema_file", requestId ?? "n/a"],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useGraphQLSchemaFile(requestId: string | null) {
|
||||||
|
return useKeyValue<string | null>({ ...graphqlSchemaFileArgs(requestId), fallback: null });
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { useMutation, useQuery } from "@tanstack/react-query";
|
import { useMutation, useQuery } from "@tanstack/react-query";
|
||||||
import { emit } from "@tauri-apps/api/event";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import type { GrpcConnection, GrpcRequest } from "@yaakapp-internal/models";
|
import type { GrpcConnection, GrpcRequest } from "@yaakapp-internal/models";
|
||||||
import { flushAllModelWrites } from "@yaakapp-internal/models";
|
import { flushAllModelWrites } from "@yaakapp-internal/models";
|
||||||
import { jotaiStore } from "../lib/jotai";
|
import { jotaiStore } from "../lib/jotai";
|
||||||
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { activeEnvironmentIdAtom, useActiveEnvironment } from "./useActiveEnvironment";
|
import { activeEnvironmentIdAtom, useActiveEnvironment } from "./useActiveEnvironment";
|
||||||
import { useDebouncedValue } from "@yaakapp-internal/ui";
|
import { useDebouncedValue } from "@yaakapp-internal/ui";
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export function useGrpc(
|
|||||||
mutationKey: ["grpc_go", conn?.id],
|
mutationKey: ["grpc_go", conn?.id],
|
||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await flushAllModelWrites(); // The backend reads the request from the DB
|
await flushAllModelWrites(); // The backend reads the request from the DB
|
||||||
return invokeCmd<void>("cmd_grpc_go", {
|
return rpc<void>("cmd_grpc_go", {
|
||||||
requestId,
|
requestId,
|
||||||
environmentId: environment?.id,
|
environmentId: environment?.id,
|
||||||
protoFiles,
|
protoFiles,
|
||||||
@@ -36,17 +36,17 @@ export function useGrpc(
|
|||||||
const send = useMutation({
|
const send = useMutation({
|
||||||
mutationKey: ["grpc_send", conn?.id],
|
mutationKey: ["grpc_send", conn?.id],
|
||||||
mutationFn: ({ message }: { message: string }) =>
|
mutationFn: ({ message }: { message: string }) =>
|
||||||
emit(`grpc_client_msg_${conn?.id ?? "none"}`, { Message: message }),
|
platform.emit(`grpc_client_msg_${conn?.id ?? "none"}`, { Message: message }),
|
||||||
});
|
});
|
||||||
|
|
||||||
const cancel = useMutation({
|
const cancel = useMutation({
|
||||||
mutationKey: ["grpc_cancel", conn?.id ?? "n/a"],
|
mutationKey: ["grpc_cancel", conn?.id ?? "n/a"],
|
||||||
mutationFn: () => emit(`grpc_client_msg_${conn?.id ?? "none"}`, "Cancel"),
|
mutationFn: () => platform.emit(`grpc_client_msg_${conn?.id ?? "none"}`, "Cancel"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const commit = useMutation({
|
const commit = useMutation({
|
||||||
mutationKey: ["grpc_commit", conn?.id ?? "n/a"],
|
mutationKey: ["grpc_commit", conn?.id ?? "n/a"],
|
||||||
mutationFn: () => emit(`grpc_client_msg_${conn?.id ?? "none"}`, "Commit"),
|
mutationFn: () => platform.emit(`grpc_client_msg_${conn?.id ?? "none"}`, "Commit"),
|
||||||
});
|
});
|
||||||
|
|
||||||
const debouncedUrl = useDebouncedValue<string>(req?.url ?? "", 1000);
|
const debouncedUrl = useDebouncedValue<string>(req?.url ?? "", 1000);
|
||||||
@@ -61,7 +61,7 @@ export function useGrpc(
|
|||||||
queryFn: () => {
|
queryFn: () => {
|
||||||
const environmentId = jotaiStore.get(activeEnvironmentIdAtom);
|
const environmentId = jotaiStore.get(activeEnvironmentIdAtom);
|
||||||
return minPromiseMillis<ReflectResponseService[]>(
|
return minPromiseMillis<ReflectResponseService[]>(
|
||||||
invokeCmd("cmd_grpc_reflect", { requestId, protoFiles, environmentId }),
|
rpc("cmd_grpc_reflect", { requestId, protoFiles, environmentId }),
|
||||||
300,
|
300,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type {
|
|||||||
GrpcRequestAction,
|
GrpcRequestAction,
|
||||||
} from "@yaakapp-internal/plugins";
|
} from "@yaakapp-internal/plugins";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { getGrpcProtoFiles } from "./useGrpcProtoFiles";
|
import { getGrpcProtoFiles } from "./useGrpcProtoFiles";
|
||||||
import { usePluginsKey } from "./usePlugins";
|
import { usePluginsKey } from "./usePlugins";
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ export function useGrpcRequestActions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getGrpcRequestActions() {
|
export async function getGrpcRequestActions() {
|
||||||
const responses = await invokeCmd<GetGrpcRequestActionsResponse[]>("cmd_grpc_request_actions");
|
const responses = await rpc<GetGrpcRequestActionsResponse[]>("cmd_grpc_request_actions");
|
||||||
|
|
||||||
return responses.flatMap((r) =>
|
return responses.flatMap((r) =>
|
||||||
r.actions.map((a, i) => ({
|
r.actions.map((a, i) => ({
|
||||||
@@ -46,7 +46,7 @@ export async function getGrpcRequestActions() {
|
|||||||
pluginRefId: r.pluginRefId,
|
pluginRefId: r.pluginRefId,
|
||||||
args: { grpcRequest, protoFiles },
|
args: { grpcRequest, protoFiles },
|
||||||
};
|
};
|
||||||
await invokeCmd("cmd_call_grpc_request_action", { req: payload });
|
await rpc("cmd_call_grpc_request_action", { req: payload });
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { type } from "@tauri-apps/plugin-os";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import { debounce } from "@yaakapp-internal/lib";
|
import { debounce } from "@yaakapp-internal/lib";
|
||||||
import { settingsAtom } from "@yaakapp-internal/models";
|
import { settingsAtom } from "@yaakapp-internal/models";
|
||||||
import { atom, useAtomValue } from "jotai";
|
import { atom, useAtomValue } from "jotai";
|
||||||
@@ -102,7 +102,7 @@ const defaultHotkeysOther: Record<HotkeyAction, string[]> = {
|
|||||||
|
|
||||||
/** Get the default hotkeys for the current platform */
|
/** Get the default hotkeys for the current platform */
|
||||||
export const defaultHotkeys: Record<HotkeyAction, string[]> =
|
export const defaultHotkeys: Record<HotkeyAction, string[]> =
|
||||||
type() === "macos" ? defaultHotkeysMac : defaultHotkeysOther;
|
platform.osType() === "macos" ? defaultHotkeysMac : defaultHotkeysOther;
|
||||||
|
|
||||||
/** Atom that provides the effective hotkeys by merging defaults with user settings */
|
/** Atom that provides the effective hotkeys by merging defaults with user settings */
|
||||||
export const hotkeysAtom = atom((get) => {
|
export const hotkeysAtom = atom((get) => {
|
||||||
@@ -112,9 +112,12 @@ export const hotkeysAtom = atom((get) => {
|
|||||||
// Merge default hotkeys with custom hotkeys from settings
|
// Merge default hotkeys with custom hotkeys from settings
|
||||||
// Custom hotkeys override defaults for the same action
|
// Custom hotkeys override defaults for the same action
|
||||||
// An empty array means the hotkey is intentionally disabled
|
// An empty array means the hotkey is intentionally disabled
|
||||||
const merged: Record<HotkeyAction, string[]> = { ...defaultHotkeys };
|
const merged: Partial<Record<HotkeyAction, string[]>> = {};
|
||||||
|
for (const action of hotkeyActions) {
|
||||||
|
merged[action] = defaultHotkeys[action];
|
||||||
|
}
|
||||||
for (const [action, keys] of Object.entries(customHotkeys)) {
|
for (const [action, keys] of Object.entries(customHotkeys)) {
|
||||||
if (action in defaultHotkeys && Array.isArray(keys)) {
|
if (action in merged && Array.isArray(keys)) {
|
||||||
merged[action as HotkeyAction] = keys;
|
merged[action as HotkeyAction] = keys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -122,7 +125,7 @@ export const hotkeysAtom = atom((get) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/** Helper function to get current hotkeys from the store */
|
/** Helper function to get current hotkeys from the store */
|
||||||
function getHotkeys(): Record<HotkeyAction, string[]> {
|
function getHotkeys(): Partial<Record<HotkeyAction, string[]>> {
|
||||||
return jotaiStore.get(hotkeysAtom);
|
return jotaiStore.get(hotkeysAtom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,16 +168,25 @@ const layoutInsensitiveKeys = [
|
|||||||
"Space",
|
"Space",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** Zoom is the browser's own on these keys, so the app has no such action there. */
|
||||||
|
const ZOOM_ACTIONS: HotkeyAction[] = ["app.zoom_in", "app.zoom_out", "app.zoom_reset"];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The actions this host actually has. An action left out of here has no keys in
|
||||||
|
* `hotkeysAtom`, so it never matches and never claims the keystroke.
|
||||||
|
*/
|
||||||
export const hotkeyActions: HotkeyAction[] = (
|
export const hotkeyActions: HotkeyAction[] = (
|
||||||
Object.keys(defaultHotkeys) as (keyof typeof defaultHotkeys)[]
|
Object.keys(defaultHotkeys) as (keyof typeof defaultHotkeys)[]
|
||||||
).sort((a, b) => {
|
)
|
||||||
const scopeA = a.split(".")[0] || "";
|
.filter((a) => platform.capabilities.interfaceZoom || !ZOOM_ACTIONS.includes(a))
|
||||||
const scopeB = b.split(".")[0] || "";
|
.sort((a, b) => {
|
||||||
if (scopeA !== scopeB) {
|
const scopeA = a.split(".")[0] || "";
|
||||||
return scopeA.localeCompare(scopeB);
|
const scopeB = b.split(".")[0] || "";
|
||||||
}
|
if (scopeA !== scopeB) {
|
||||||
return hotkeyLabels[a].localeCompare(hotkeyLabels[b]);
|
return scopeA.localeCompare(scopeB);
|
||||||
});
|
}
|
||||||
|
return hotkeyLabels[a].localeCompare(hotkeyLabels[b]);
|
||||||
|
});
|
||||||
|
|
||||||
export type HotKeyOptions = {
|
export type HotKeyOptions = {
|
||||||
enable?: boolean | (() => boolean);
|
enable?: boolean | (() => boolean);
|
||||||
@@ -318,7 +330,7 @@ export function getHotkeyScope(action: HotkeyAction): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function formatHotkeyString(trigger: string): string[] {
|
export function formatHotkeyString(trigger: string): string[] {
|
||||||
const os = type();
|
const os = platform.osType();
|
||||||
const parts = trigger.split("+");
|
const parts = trigger.split("+");
|
||||||
const labelParts: string[] = [];
|
const labelParts: string[] = [];
|
||||||
|
|
||||||
@@ -333,7 +345,9 @@ export function formatHotkeyString(trigger: string): string[] {
|
|||||||
} else if (p === "Alt") {
|
} else if (p === "Alt") {
|
||||||
labelParts.push("⌥");
|
labelParts.push("⌥");
|
||||||
} else if (p === "Enter") {
|
} else if (p === "Enter") {
|
||||||
labelParts.push("↩");
|
// U+21A9 has an emoji presentation, which Chromium's font fallback picks
|
||||||
|
// (a blue glyph among monochrome ones). U+FE0E forces the text form.
|
||||||
|
labelParts.push("↩︎");
|
||||||
} else if (p === "Tab") {
|
} else if (p === "Tab") {
|
||||||
labelParts.push("⇥");
|
labelParts.push("⇥");
|
||||||
} else if (p === "Backspace") {
|
} else if (p === "Backspace") {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { GetHttpAuthenticationSummaryResponse } from "@yaakapp-internal/plu
|
|||||||
import { atom, useAtomValue } from "jotai";
|
import { atom, useAtomValue } from "jotai";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { jotaiStore } from "../lib/jotai";
|
import { jotaiStore } from "../lib/jotai";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { showErrorToast } from "../lib/toast";
|
import { showErrorToast } from "../lib/toast";
|
||||||
import { usePluginsKey } from "./usePlugins";
|
import { usePluginsKey } from "./usePlugins";
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ export function useSubscribeHttpAuthentication() {
|
|||||||
placeholderData: (prev) => prev, // Keep previous data on refetch
|
placeholderData: (prev) => prev, // Keep previous data on refetch
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
try {
|
try {
|
||||||
const result = await invokeCmd<GetHttpAuthenticationSummaryResponse[]>(
|
const result = await rpc<GetHttpAuthenticationSummaryResponse[]>(
|
||||||
"cmd_get_http_authentication_summaries",
|
"cmd_get_http_authentication_summaries",
|
||||||
);
|
);
|
||||||
setNumResults(result.length);
|
setNumResults(result.length);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import type { GetHttpAuthenticationConfigResponse, JsonPrimitive } from "@yaakap
|
|||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import { md5 } from "js-md5";
|
import { md5 } from "js-md5";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { activeEnvironmentIdAtom } from "./useActiveEnvironment";
|
import { activeEnvironmentIdAtom } from "./useActiveEnvironment";
|
||||||
import { activeWorkspaceIdAtom } from "./useActiveWorkspace";
|
import { activeWorkspaceIdAtom } from "./useActiveWorkspace";
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ export function useHttpAuthenticationConfig(
|
|||||||
placeholderData: (prev) => prev, // Keep previous data on refetch
|
placeholderData: (prev) => prev, // Keep previous data on refetch
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (authName == null || authName === "inherit") return null;
|
if (authName == null || authName === "inherit") return null;
|
||||||
const config = await invokeCmd<GetHttpAuthenticationConfigResponse>(
|
const config = await rpc<GetHttpAuthenticationConfigResponse>(
|
||||||
"cmd_get_http_authentication_config",
|
"cmd_get_http_authentication_config",
|
||||||
{
|
{
|
||||||
authName,
|
authName,
|
||||||
@@ -65,7 +65,7 @@ export function useHttpAuthenticationConfig(
|
|||||||
call: async (
|
call: async (
|
||||||
model: HttpRequest | GrpcRequest | WebsocketRequest | Folder | Workspace,
|
model: HttpRequest | GrpcRequest | WebsocketRequest | Folder | Workspace,
|
||||||
) => {
|
) => {
|
||||||
await invokeCmd("cmd_call_http_authentication_action", {
|
await rpc("cmd_call_http_authentication_action", {
|
||||||
pluginRefId: config.pluginRefId,
|
pluginRefId: config.pluginRefId,
|
||||||
actionIndex: i,
|
actionIndex: i,
|
||||||
authName,
|
authName,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type {
|
|||||||
HttpRequestAction,
|
HttpRequestAction,
|
||||||
} from "@yaakapp-internal/plugins";
|
} from "@yaakapp-internal/plugins";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { usePluginsKey } from "./usePlugins";
|
import { usePluginsKey } from "./usePlugins";
|
||||||
|
|
||||||
export type CallableHttpRequestAction = Pick<HttpRequestAction, "label" | "icon"> & {
|
export type CallableHttpRequestAction = Pick<HttpRequestAction, "label" | "icon"> & {
|
||||||
@@ -30,7 +30,7 @@ export function useHttpRequestActions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getHttpRequestActions() {
|
export async function getHttpRequestActions() {
|
||||||
const responses = await invokeCmd<GetHttpRequestActionsResponse[]>("cmd_http_request_actions");
|
const responses = await rpc<GetHttpRequestActionsResponse[]>("cmd_http_request_actions");
|
||||||
const actions = responses.flatMap((r) =>
|
const actions = responses.flatMap((r) =>
|
||||||
r.actions.map((a, i) => ({
|
r.actions.map((a, i) => ({
|
||||||
label: a.label,
|
label: a.label,
|
||||||
@@ -41,7 +41,7 @@ export async function getHttpRequestActions() {
|
|||||||
pluginRefId: r.pluginRefId,
|
pluginRefId: r.pluginRefId,
|
||||||
args: { httpRequest },
|
args: { httpRequest },
|
||||||
};
|
};
|
||||||
await invokeCmd("cmd_call_http_request_action", { req: payload });
|
await rpc("cmd_call_http_request_action", { req: payload });
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import type { HttpResponse } from "@yaakapp-internal/models";
|
import type { HttpResponse } from "@yaakapp-internal/models";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
|
|
||||||
export function useHttpRequestBody(response: HttpResponse | null) {
|
export function useHttpRequestBody(response: HttpResponse | null) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
@@ -18,7 +18,7 @@ export async function getRequestBodyText(response: HttpResponse | null) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await invokeCmd<number[] | null>("cmd_http_request_body", {
|
const data = await rpc<number[] | null>("cmd_http_request_body", {
|
||||||
responseId: response.id,
|
responseId: response.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
import type { HttpResponse, HttpResponseEvent } from "@yaakapp-internal/models";
|
import type { HttpResponse, HttpResponseEvent } from "@yaakapp-internal/models";
|
||||||
import {
|
import {
|
||||||
httpResponseEventsAtom,
|
httpResponseEventsAtom,
|
||||||
@@ -8,6 +7,7 @@ import {
|
|||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { fireAndForget } from "../lib/fireAndForget";
|
import { fireAndForget } from "../lib/fireAndForget";
|
||||||
|
import { rpc } from "../lib/rpc";
|
||||||
|
|
||||||
export function useHttpResponseEvents(response: HttpResponse | null) {
|
export function useHttpResponseEvents(response: HttpResponse | null) {
|
||||||
const allEvents = useAtomValue(httpResponseEventsAtom);
|
const allEvents = useAtomValue(httpResponseEventsAtom);
|
||||||
@@ -20,7 +20,7 @@ export function useHttpResponseEvents(response: HttpResponse | null) {
|
|||||||
|
|
||||||
// Fetch events from database, filtering out events from other responses and merging atomically
|
// Fetch events from database, filtering out events from other responses and merging atomically
|
||||||
fireAndForget(
|
fireAndForget(
|
||||||
invoke<HttpResponseEvent[]>("cmd_get_http_response_events", { responseId: response.id }).then(
|
rpc<HttpResponseEvent[]>("cmd_get_http_response_events", { responseId: response.id }).then(
|
||||||
(events) =>
|
(events) =>
|
||||||
mergeModelsInStore("http_response_event", events, (e) => e.responseId === response.id),
|
mergeModelsInStore("http_response_event", events, (e) => e.responseId === response.id),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
import type { HttpRequest } from "@yaakapp-internal/models";
|
|
||||||
import { patchModelById } from "@yaakapp-internal/models";
|
|
||||||
import { createRequestAndNavigate } from "../lib/createRequestAndNavigate";
|
|
||||||
import { jotaiStore } from "../lib/jotai";
|
|
||||||
import { invokeCmd } from "../lib/tauri";
|
|
||||||
import { showToast } from "../lib/toast";
|
|
||||||
import { activeWorkspaceIdAtom } from "./useActiveWorkspace";
|
|
||||||
import { useFastMutation } from "./useFastMutation";
|
|
||||||
import { wasUpdatedExternally } from "./useRequestUpdateKey";
|
|
||||||
|
|
||||||
export function useImportCurl() {
|
|
||||||
return useFastMutation({
|
|
||||||
mutationKey: ["import_curl"],
|
|
||||||
mutationFn: async ({
|
|
||||||
overwriteRequestId,
|
|
||||||
command,
|
|
||||||
}: {
|
|
||||||
overwriteRequestId?: string;
|
|
||||||
command: string;
|
|
||||||
}) => {
|
|
||||||
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
|
||||||
const importedRequest: HttpRequest = await invokeCmd("cmd_curl_to_request", {
|
|
||||||
command,
|
|
||||||
workspaceId,
|
|
||||||
});
|
|
||||||
|
|
||||||
let verb: string;
|
|
||||||
if (overwriteRequestId == null) {
|
|
||||||
verb = "Created";
|
|
||||||
await createRequestAndNavigate(importedRequest);
|
|
||||||
} else {
|
|
||||||
verb = "Updated";
|
|
||||||
await patchModelById(importedRequest.model, overwriteRequestId, (r: HttpRequest) => ({
|
|
||||||
...importedRequest,
|
|
||||||
id: r.id,
|
|
||||||
createdAt: r.createdAt,
|
|
||||||
workspaceId: r.workspaceId,
|
|
||||||
folderId: r.folderId,
|
|
||||||
name: r.name,
|
|
||||||
sortPriority: r.sortPriority,
|
|
||||||
}));
|
|
||||||
|
|
||||||
setTimeout(() => wasUpdatedExternally(overwriteRequestId), 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
showToast({
|
|
||||||
color: "success",
|
|
||||||
message: `${verb} request from Curl`,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
import type { GraphQlIntrospection, HttpRequest } from "@yaakapp-internal/models";
|
import type { GraphQlIntrospection, HttpRequest } from "@yaakapp-internal/models";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import type { GraphQLSchema, IntrospectionQuery } from "graphql";
|
import type { GraphQLSchema, IntrospectionQuery } from "graphql";
|
||||||
import { buildClientSchema, getIntrospectionQuery } from "graphql";
|
import { buildClientSchema, getIntrospectionQuery } from "graphql";
|
||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
|
import { tryBuildIntrospectionFromFile } from "../lib/graphqlSchema";
|
||||||
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
||||||
import { getResponseBodyText } from "../lib/responseBody";
|
|
||||||
import { sendEphemeralRequest } from "../lib/sendEphemeralRequest";
|
import { sendEphemeralRequest } from "../lib/sendEphemeralRequest";
|
||||||
import { useActiveEnvironment } from "./useActiveEnvironment";
|
import { useActiveEnvironment } from "./useActiveEnvironment";
|
||||||
|
import { useGraphQLSchemaFile } from "./useGraphQLSchemaFile";
|
||||||
import { useDebouncedValue } from "@yaakapp-internal/ui";
|
import { useDebouncedValue } from "@yaakapp-internal/ui";
|
||||||
|
import { rpc } from "../lib/rpc";
|
||||||
|
|
||||||
const introspectionRequestBody = JSON.stringify({
|
const introspectionRequestBody = JSON.stringify({
|
||||||
query: getIntrospectionQuery(),
|
query: getIntrospectionQuery(),
|
||||||
@@ -30,9 +32,14 @@ export function useIntrospectGraphQL(
|
|||||||
|
|
||||||
const introspection = useIntrospectionResult(baseRequest);
|
const introspection = useIntrospectionResult(baseRequest);
|
||||||
|
|
||||||
|
// The schema's source. Outlives the introspection row it produces, so a
|
||||||
|
// request configured with a file keeps working after the row is swept.
|
||||||
|
const schemaFile = useGraphQLSchemaFile(baseRequest.id);
|
||||||
|
const filePath = schemaFile.value ?? null;
|
||||||
|
|
||||||
const upsertIntrospection = useCallback(
|
const upsertIntrospection = useCallback(
|
||||||
async (content: string | null) => {
|
async (content: string | null) => {
|
||||||
const v = await invoke<GraphQlIntrospection>("models_upsert_graphql_introspection", {
|
const v = await rpc<GraphQlIntrospection>("models_upsert_graphql_introspection", {
|
||||||
requestId: baseRequest.id,
|
requestId: baseRequest.id,
|
||||||
workspaceId: baseRequest.workspaceId,
|
workspaceId: baseRequest.workspaceId,
|
||||||
content: content ?? "",
|
content: content ?? "",
|
||||||
@@ -54,7 +61,7 @@ export function useIntrospectGraphQL(
|
|||||||
bodyType: "application/json",
|
bodyType: "application/json",
|
||||||
body: { text: introspectionRequestBody },
|
body: { text: introspectionRequestBody },
|
||||||
};
|
};
|
||||||
const response = await minPromiseMillis(
|
const { response, body } = await minPromiseMillis(
|
||||||
sendEphemeralRequest(args, activeEnvironment?.id ?? null),
|
sendEphemeralRequest(args, activeEnvironment?.id ?? null),
|
||||||
700,
|
700,
|
||||||
);
|
);
|
||||||
@@ -63,14 +70,16 @@ export function useIntrospectGraphQL(
|
|||||||
return setError(response.error);
|
return setError(response.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const bodyText = await getResponseBodyText({ response, filter: null });
|
// The send hands back the only copy of the body — an unsaved response has
|
||||||
|
// nothing on disk and no row to read it back from
|
||||||
|
const bodyText = new TextDecoder("utf-8").decode(new Uint8Array(body));
|
||||||
if (response.status < 200 || response.status >= 300) {
|
if (response.status < 200 || response.status >= 300) {
|
||||||
return setError(
|
return setError(
|
||||||
`Request failed with status ${response.status}.\nThe response text is:\n\n${bodyText}`,
|
`Request failed with status ${response.status}.\nThe response text is:\n\n${bodyText}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bodyText === null) {
|
if (bodyText === "") {
|
||||||
return setError("Empty body returned in response");
|
return setError("Empty body returned in response");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,15 +99,109 @@ export function useIntrospectGraphQL(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
refetch().catch(console.error);
|
// A request pointed at a file gets its schema from that file. Introspecting
|
||||||
}, [baseRequest.id, debouncedRequest.url, debouncedRequest.method, activeEnvironment?.id]);
|
// here would overwrite it on the next URL edit.
|
||||||
|
if (filePath != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
refetch().catch(console.error);
|
||||||
|
}, [
|
||||||
|
baseRequest.id,
|
||||||
|
debouncedRequest.url,
|
||||||
|
debouncedRequest.method,
|
||||||
|
activeEnvironment?.id,
|
||||||
|
filePath,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Clears the schema, not the source. Removing a file source is a separate
|
||||||
|
// action, because the source is what would rebuild this a moment later.
|
||||||
const clear = useCallback(async () => {
|
const clear = useCallback(async () => {
|
||||||
setError("");
|
setError("");
|
||||||
setSchema(null);
|
setSchema(null);
|
||||||
await upsertIntrospection(null);
|
await upsertIntrospection(null);
|
||||||
}, [upsertIntrospection]);
|
}, [upsertIntrospection]);
|
||||||
|
|
||||||
|
// Reads a schema file and produces an introspection row from it, the same way
|
||||||
|
// `refetch` produces one from a server. Does not touch the stored source.
|
||||||
|
const introspectFromFile = useCallback(
|
||||||
|
async (path: string): Promise<{ ok: true } | { ok: false; error: string }> => {
|
||||||
|
try {
|
||||||
|
setIsLoading(true);
|
||||||
|
setError(undefined);
|
||||||
|
|
||||||
|
const fileContent = await platform.files.readText(path);
|
||||||
|
const result = tryBuildIntrospectionFromFile(fileContent);
|
||||||
|
|
||||||
|
if ("error" in result) {
|
||||||
|
setError(result.error);
|
||||||
|
return { ok: false, error: result.error };
|
||||||
|
}
|
||||||
|
|
||||||
|
await upsertIntrospection(result.content);
|
||||||
|
return { ok: true };
|
||||||
|
} catch (err) {
|
||||||
|
// The host rejects with a bare string for a missing or unreadable path,
|
||||||
|
// so this can't assume an Error.
|
||||||
|
const message = err instanceof Error ? err.message : String(err);
|
||||||
|
setError(message);
|
||||||
|
return { ok: false, error: message };
|
||||||
|
} finally {
|
||||||
|
setIsLoading(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[upsertIntrospection],
|
||||||
|
);
|
||||||
|
|
||||||
|
// Points the request at a file and immediately builds its schema from it.
|
||||||
|
const loadFromFile = useCallback(
|
||||||
|
async (path: string) => {
|
||||||
|
const result = await introspectFromFile(path);
|
||||||
|
if (result.ok) await schemaFile.set(path);
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
[introspectFromFile, schemaFile],
|
||||||
|
);
|
||||||
|
|
||||||
|
const reloadFromFile = useCallback(async () => {
|
||||||
|
if (filePath == null) return { ok: false as const, error: "No schema file to reload" };
|
||||||
|
return introspectFromFile(filePath);
|
||||||
|
}, [filePath, introspectFromFile]);
|
||||||
|
|
||||||
|
// The file-source counterpart of automatic introspection: re-read the file
|
||||||
|
// when the request is opened, so an edited schema is picked up without asking.
|
||||||
|
//
|
||||||
|
// A missing row is repaired even with the setting off — that is recovering
|
||||||
|
// from the 7-day sweep, not keeping the schema fresh, and skipping it would
|
||||||
|
// make the schema disappear with no visible cause.
|
||||||
|
const reloadedFor = useRef<string | null>(null);
|
||||||
|
useEffect(() => {
|
||||||
|
if (filePath == null || introspection.isLoading) return;
|
||||||
|
// Only attempt once per path, so an unreadable file doesn't spin.
|
||||||
|
if (reloadedFor.current === filePath) return;
|
||||||
|
|
||||||
|
const hasContent = (introspection.data?.content ?? "") !== "";
|
||||||
|
if (hasContent && options.disabled) return;
|
||||||
|
|
||||||
|
reloadedFor.current = filePath;
|
||||||
|
introspectFromFile(filePath).catch(console.error);
|
||||||
|
}, [
|
||||||
|
filePath,
|
||||||
|
introspection.data?.content,
|
||||||
|
introspection.isLoading,
|
||||||
|
introspectFromFile,
|
||||||
|
options.disabled,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Stops using the file. The schema goes with it, since the file is what
|
||||||
|
// produced it; introspection repopulates if it's set to run automatically.
|
||||||
|
const removeSchemaFile = useCallback(async () => {
|
||||||
|
setError("");
|
||||||
|
setSchema(null);
|
||||||
|
await schemaFile.set(null);
|
||||||
|
await upsertIntrospection(null);
|
||||||
|
}, [schemaFile, upsertIntrospection]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (introspection.data?.content == null || introspection.data.content === "") {
|
if (introspection.data?.content == null || introspection.data.content === "") {
|
||||||
return;
|
return;
|
||||||
@@ -112,14 +215,24 @@ export function useIntrospectGraphQL(
|
|||||||
}
|
}
|
||||||
}, [introspection.data?.content]);
|
}, [introspection.data?.content]);
|
||||||
|
|
||||||
return { schema, isLoading, error, refetch, clear };
|
return {
|
||||||
|
schema,
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
refetch,
|
||||||
|
clear,
|
||||||
|
loadFromFile,
|
||||||
|
reloadFromFile,
|
||||||
|
removeSchemaFile,
|
||||||
|
filePath,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function useIntrospectionResult(request: HttpRequest) {
|
function useIntrospectionResult(request: HttpRequest) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["introspection", request.id],
|
queryKey: ["introspection", request.id],
|
||||||
queryFn: async () =>
|
queryFn: async () =>
|
||||||
invoke<GraphQlIntrospection | null>("models_get_graphql_introspection", {
|
rpc<GraphQlIntrospection | null>("models_get_graphql_introspection", {
|
||||||
requestId: request.id,
|
requestId: request.id,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
import type { EventCallback, EventName } from "@tauri-apps/api/event";
|
|
||||||
import { listen } from "@tauri-apps/api/event";
|
|
||||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
|
||||||
import { useEffect, useRef } from "react";
|
|
||||||
|
|
||||||
export function useListenToTauriEvent<T>(event: EventName, fn: EventCallback<T>) {
|
|
||||||
const handlerRef = useRef(fn);
|
|
||||||
useEffect(() => {
|
|
||||||
handlerRef.current = fn;
|
|
||||||
}, [fn]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
return listenToTauriEvent<T>(event, (p) => handlerRef.current(p));
|
|
||||||
}, [event]);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function listenToTauriEvent<T>(event: EventName, fn: EventCallback<T>) {
|
|
||||||
const unsubPromise = listen<T>(
|
|
||||||
event,
|
|
||||||
fn,
|
|
||||||
// Listen to `emit_all()` events or events specific to the current window
|
|
||||||
{ target: { label: getCurrentWebviewWindow().label, kind: "Window" } },
|
|
||||||
);
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
unsubPromise.then((unsub) => unsub()).catch(console.error);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
import type { GrpcConnection, GrpcEvent } from "@yaakapp-internal/models";
|
import type { GrpcConnection, GrpcEvent } from "@yaakapp-internal/models";
|
||||||
import {
|
import {
|
||||||
grpcConnectionsAtom,
|
grpcConnectionsAtom,
|
||||||
@@ -11,6 +10,7 @@ import { useEffect, useMemo } from "react";
|
|||||||
import { fireAndForget } from "../lib/fireAndForget";
|
import { fireAndForget } from "../lib/fireAndForget";
|
||||||
import { atomWithKVStorage } from "../lib/atoms/atomWithKVStorage";
|
import { atomWithKVStorage } from "../lib/atoms/atomWithKVStorage";
|
||||||
import { activeRequestIdAtom } from "./useActiveRequestId";
|
import { activeRequestIdAtom } from "./useActiveRequestId";
|
||||||
|
import { rpc } from "../lib/rpc";
|
||||||
|
|
||||||
const pinnedGrpcConnectionIdsAtom = atomWithKVStorage<Record<string, string | null>>(
|
const pinnedGrpcConnectionIdsAtom = atomWithKVStorage<Record<string, string | null>>(
|
||||||
"pinned-grpc-connection-ids",
|
"pinned-grpc-connection-ids",
|
||||||
@@ -71,7 +71,7 @@ export function useGrpcEvents(connectionId: string | null) {
|
|||||||
|
|
||||||
// Fetch events from database, filtering out events from other connections and merging atomically
|
// Fetch events from database, filtering out events from other connections and merging atomically
|
||||||
fireAndForget(
|
fireAndForget(
|
||||||
invoke<GrpcEvent[]>("models_grpc_events", { connectionId }).then((events) =>
|
rpc<GrpcEvent[]>("models_grpc_events", { connectionId }).then((events) =>
|
||||||
mergeModelsInStore("grpc_event", events, (e) => e.connectionId === connectionId),
|
mergeModelsInStore("grpc_event", events, (e) => e.connectionId === connectionId),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import { invoke } from "@tauri-apps/api/core";
|
|
||||||
import type { WebsocketConnection, WebsocketEvent } from "@yaakapp-internal/models";
|
import type { WebsocketConnection, WebsocketEvent } from "@yaakapp-internal/models";
|
||||||
import {
|
import {
|
||||||
mergeModelsInStore,
|
mergeModelsInStore,
|
||||||
@@ -12,6 +11,7 @@ import { fireAndForget } from "../lib/fireAndForget";
|
|||||||
import { atomWithKVStorage } from "../lib/atoms/atomWithKVStorage";
|
import { atomWithKVStorage } from "../lib/atoms/atomWithKVStorage";
|
||||||
import { jotaiStore } from "../lib/jotai";
|
import { jotaiStore } from "../lib/jotai";
|
||||||
import { activeRequestIdAtom } from "./useActiveRequestId";
|
import { activeRequestIdAtom } from "./useActiveRequestId";
|
||||||
|
import { rpc } from "../lib/rpc";
|
||||||
|
|
||||||
const pinnedWebsocketConnectionIdAtom = atomWithKVStorage<Record<string, string | null>>(
|
const pinnedWebsocketConnectionIdAtom = atomWithKVStorage<Record<string, string | null>>(
|
||||||
"pinned-websocket-connection-ids",
|
"pinned-websocket-connection-ids",
|
||||||
@@ -58,7 +58,7 @@ export function useWebsocketEvents(connectionId: string | null) {
|
|||||||
|
|
||||||
// Fetch events from database, filtering out events from other connections and merging atomically
|
// Fetch events from database, filtering out events from other connections and merging atomically
|
||||||
fireAndForget(
|
fireAndForget(
|
||||||
invoke<WebsocketEvent[]>("models_websocket_events", { connectionId }).then((events) =>
|
rpc<WebsocketEvent[]>("models_websocket_events", { connectionId }).then((events) =>
|
||||||
mergeModelsInStore("websocket_event", events, (e) => e.connectionId === connectionId),
|
mergeModelsInStore("websocket_event", events, (e) => e.connectionId === connectionId),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
|
|
||||||
|
/** Subscribe to a backend event for the lifetime of the component. */
|
||||||
|
export function usePlatformEvent<T>(event: string, fn: (payload: T) => void) {
|
||||||
|
const handlerRef = useRef(fn);
|
||||||
|
useEffect(() => {
|
||||||
|
handlerRef.current = fn;
|
||||||
|
}, [fn]);
|
||||||
|
|
||||||
|
useEffect(() => platform.listen<T>(event, (payload) => handlerRef.current(payload)), [event]);
|
||||||
|
}
|
||||||
@@ -4,7 +4,7 @@ import { pluginsAtom } from "@yaakapp-internal/models";
|
|||||||
import type { PluginMetadata } from "@yaakapp-internal/plugins";
|
import type { PluginMetadata } from "@yaakapp-internal/plugins";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import { queryClient } from "../lib/queryClient";
|
import { queryClient } from "../lib/queryClient";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
|
|
||||||
function pluginInfoKey(id: string | null, plugin: Plugin | null) {
|
function pluginInfoKey(id: string | null, plugin: Plugin | null) {
|
||||||
return ["plugin_info", id ?? "n/a", plugin?.updatedAt ?? "n/a"];
|
return ["plugin_info", id ?? "n/a", plugin?.updatedAt ?? "n/a"];
|
||||||
@@ -19,7 +19,7 @@ export function usePluginInfo(id: string | null) {
|
|||||||
placeholderData: (prev) => prev, // Keep previous data on refetch
|
placeholderData: (prev) => prev, // Keep previous data on refetch
|
||||||
queryFn: () => {
|
queryFn: () => {
|
||||||
if (id == null) return null;
|
if (id == null) return null;
|
||||||
return invokeCmd<PluginMetadata>("cmd_plugin_info", { id });
|
return rpc<PluginMetadata>("cmd_plugin_info", { id });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { changeModelStoreWorkspace, pluginsAtom } from "@yaakapp-internal/models
|
|||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import { jotaiStore } from "../lib/jotai";
|
import { jotaiStore } from "../lib/jotai";
|
||||||
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { activeWorkspaceIdAtom } from "./useActiveWorkspace";
|
import { activeWorkspaceIdAtom } from "./useActiveWorkspace";
|
||||||
import { useDebouncedValue } from "@yaakapp-internal/ui";
|
import { useDebouncedValue } from "@yaakapp-internal/ui";
|
||||||
import { invalidateAllPluginInfo } from "./usePluginInfo";
|
import { invalidateAllPluginInfo } from "./usePluginInfo";
|
||||||
@@ -26,7 +26,7 @@ export function useRefreshPlugins() {
|
|||||||
mutationFn: async () => {
|
mutationFn: async () => {
|
||||||
await minPromiseMillis(
|
await minPromiseMillis(
|
||||||
(async () => {
|
(async () => {
|
||||||
await invokeCmd("cmd_reload_plugins");
|
await rpc("cmd_reload_plugins");
|
||||||
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
|
||||||
await changeModelStoreWorkspace(workspaceId); // Force refresh models
|
await changeModelStoreWorkspace(workspaceId); // Force refresh models
|
||||||
invalidateAllPluginInfo();
|
invalidateAllPluginInfo();
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import type { Appearance } from "@yaakapp-internal/theme";
|
import type { Appearance } from "@yaakapp-internal/theme";
|
||||||
import { getCSSAppearance, subscribeToPreferredAppearance } from "@yaakapp-internal/theme";
|
import {
|
||||||
|
getCSSAppearance,
|
||||||
|
getSystemAppearance,
|
||||||
|
subscribeToPreferredAppearance,
|
||||||
|
} from "@yaakapp-internal/theme";
|
||||||
|
|
||||||
export function usePreferredAppearance() {
|
export function usePreferredAppearance() {
|
||||||
const [preferredAppearance, setPreferredAppearance] = useState<Appearance>(getCSSAppearance());
|
const [preferredAppearance, setPreferredAppearance] = useState<Appearance>(
|
||||||
|
getSystemAppearance() ?? getCSSAppearance(),
|
||||||
|
);
|
||||||
useEffect(() => subscribeToPreferredAppearance(setPreferredAppearance), []);
|
useEffect(() => subscribeToPreferredAppearance(setPreferredAppearance), []);
|
||||||
return preferredAppearance;
|
return preferredAppearance;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,67 @@
|
|||||||
|
import { useCallback } from "react";
|
||||||
|
import { useKeyValue } from "./useKeyValue";
|
||||||
|
|
||||||
|
export interface RecentFilter {
|
||||||
|
value: string;
|
||||||
|
pinned?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAX_RECENT_FILTERS = 20;
|
||||||
|
const kvKey = (filterStateKey: string) => `recent_filters::${filterStateKey}`;
|
||||||
|
const namespace = "global";
|
||||||
|
const fallback: RecentFilter[] = [];
|
||||||
|
|
||||||
|
export function useRecentFilters(filterStateKey: string | null) {
|
||||||
|
const { value, set } = useKeyValue<RecentFilter[]>({
|
||||||
|
key: kvKey(filterStateKey ?? "n/a"),
|
||||||
|
namespace,
|
||||||
|
fallback,
|
||||||
|
});
|
||||||
|
|
||||||
|
const addFilter = useCallback(
|
||||||
|
async (rawValue: string) => {
|
||||||
|
const value = rawValue.trim();
|
||||||
|
if (filterStateKey == null || value === "") return;
|
||||||
|
await set((prev) => {
|
||||||
|
// Returning the same reference skips the write, so re-committing the
|
||||||
|
// expression already at the top (on every blur) costs nothing
|
||||||
|
if (prev[0]?.value === value) return prev;
|
||||||
|
const existing = prev.find((f) => f.value === value);
|
||||||
|
const rest = prev.filter((f) => f.value !== value);
|
||||||
|
return trim([{ value, pinned: existing?.pinned }, ...rest]);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[filterStateKey, set],
|
||||||
|
);
|
||||||
|
|
||||||
|
const removeFilter = useCallback(
|
||||||
|
async (value: string) => set((prev) => prev.filter((f) => f.value !== value)),
|
||||||
|
[set],
|
||||||
|
);
|
||||||
|
|
||||||
|
const togglePin = useCallback(
|
||||||
|
async (value: string) =>
|
||||||
|
set((prev) => prev.map((f) => (f.value === value ? { ...f, pinned: !f.pinned } : f))),
|
||||||
|
[set],
|
||||||
|
);
|
||||||
|
|
||||||
|
const clearFilters = useCallback(async () => set([]), [set]);
|
||||||
|
|
||||||
|
return { recentFilters: value ?? fallback, addFilter, removeFilter, togglePin, clearFilters };
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bound the list, evicting the oldest unpinned entries before any pinned ones */
|
||||||
|
function trim(filters: RecentFilter[]): RecentFilter[] {
|
||||||
|
const excess = filters.length - MAX_RECENT_FILTERS;
|
||||||
|
if (excess <= 0) return filters;
|
||||||
|
|
||||||
|
const evicted = new Set<number>();
|
||||||
|
for (let i = filters.length - 1; i >= 0 && evicted.size < excess; i--) {
|
||||||
|
if (!filters[i]?.pinned) evicted.add(i);
|
||||||
|
}
|
||||||
|
for (let i = filters.length - 1; i >= 0 && evicted.size < excess; i--) {
|
||||||
|
evicted.add(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return filters.filter((_, i) => !evicted.has(i));
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ import { useQuery } from "@tanstack/react-query";
|
|||||||
import type { RenderPurpose } from "@yaakapp-internal/plugins";
|
import type { RenderPurpose } from "@yaakapp-internal/plugins";
|
||||||
import { useAtomValue } from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
import { minPromiseMillis } from "../lib/minPromiseMillis";
|
||||||
import { invokeCmd } from "../lib/tauri";
|
import { rpc } from "../lib/rpc";
|
||||||
import { useActiveEnvironment } from "./useActiveEnvironment";
|
import { useActiveEnvironment } from "./useActiveEnvironment";
|
||||||
import { activeWorkspaceIdAtom } from "./useActiveWorkspace";
|
import { activeWorkspaceIdAtom } from "./useActiveWorkspace";
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ export async function renderTemplate({
|
|||||||
purpose: RenderPurpose;
|
purpose: RenderPurpose;
|
||||||
ignoreError?: boolean;
|
ignoreError?: boolean;
|
||||||
}): Promise<string> {
|
}): Promise<string> {
|
||||||
return invokeCmd("cmd_render_template", {
|
return rpc("cmd_render_template", {
|
||||||
template,
|
template,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
environmentId,
|
environmentId,
|
||||||
@@ -67,5 +67,5 @@ export async function decryptTemplate({
|
|||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
environmentId: string | null;
|
environmentId: string | null;
|
||||||
}): Promise<string> {
|
}): Promise<string> {
|
||||||
return invokeCmd("cmd_decrypt_template", { template, workspaceId, environmentId });
|
return rpc("cmd_decrypt_template", { template, workspaceId, environmentId });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
import type { ModelPayload } from "@yaakapp-internal/models";
|
import type { ModelPayload } from "@yaakapp-internal/models";
|
||||||
import { atom, useAtomValue } from "jotai";
|
import { atom, useAtomValue } from "jotai";
|
||||||
import { generateId } from "../lib/generateId";
|
import { generateId } from "../lib/generateId";
|
||||||
@@ -6,26 +6,24 @@ import { jotaiStore } from "../lib/jotai";
|
|||||||
|
|
||||||
const requestUpdateKeyAtom = atom<Record<string, string>>({});
|
const requestUpdateKeyAtom = atom<Record<string, string>>({});
|
||||||
|
|
||||||
getCurrentWebviewWindow()
|
platform.listen<ModelPayload[]>("model_writes", (payloads) => {
|
||||||
.listen<ModelPayload[]>("model_writes", ({ payload: payloads }) => {
|
const changedIds: string[] = [];
|
||||||
const changedIds: string[] = [];
|
for (const payload of payloads) {
|
||||||
for (const payload of payloads) {
|
if (payload.change.type !== "upsert") continue;
|
||||||
if (payload.change.type !== "upsert") continue;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(payload.model.model === "http_request" ||
|
(payload.model.model === "http_request" ||
|
||||||
payload.model.model === "grpc_request" ||
|
payload.model.model === "grpc_request" ||
|
||||||
payload.model.model === "websocket_request") &&
|
payload.model.model === "websocket_request") &&
|
||||||
((payload.updateSource.type === "window" &&
|
((payload.updateSource.type === "window" &&
|
||||||
payload.updateSource.label !== getCurrentWebviewWindow().label) ||
|
payload.updateSource.label !== platform.window.label) ||
|
||||||
payload.updateSource.type !== "window")
|
payload.updateSource.type !== "window")
|
||||||
) {
|
) {
|
||||||
changedIds.push(payload.model.id);
|
changedIds.push(payload.model.id);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (changedIds.length > 0) wasUpdatedExternally(changedIds);
|
}
|
||||||
})
|
if (changedIds.length > 0) wasUpdatedExternally(changedIds);
|
||||||
.catch(console.error);
|
});
|
||||||
|
|
||||||
export function wasUpdatedExternally(changedRequestIds: string | string[]) {
|
export function wasUpdatedExternally(changedRequestIds: string | string[]) {
|
||||||
const ids = Array.isArray(changedRequestIds) ? changedRequestIds : [changedRequestIds];
|
const ids = Array.isArray(changedRequestIds) ? changedRequestIds : [changedRequestIds];
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import type { RequestVersionComparison } from "@yaakapp-internal/models";
|
||||||
|
import { useAtomValue } from "jotai";
|
||||||
|
import { allRequestsAtom } from "./useAllRequests";
|
||||||
|
import { rpc } from "../lib/rpc";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The request version a response was sent from, alongside the request as it
|
||||||
|
* stands now.
|
||||||
|
*
|
||||||
|
* Refetches when the live request is written, which is what keeps the "has this
|
||||||
|
* changed?" answer honest while someone edits. The comparison itself is the
|
||||||
|
* backend's — the frontend never hashes anything.
|
||||||
|
*/
|
||||||
|
export function useRequestVersion(versionId: string | null | undefined, requestId: string | null) {
|
||||||
|
const requests = useAtomValue(allRequestsAtom);
|
||||||
|
const liveUpdatedAt = requests.find((r) => r.id === requestId)?.updatedAt;
|
||||||
|
|
||||||
|
return useQuery({
|
||||||
|
placeholderData: (prev) => prev,
|
||||||
|
queryKey: ["request_version", versionId, liveUpdatedAt],
|
||||||
|
enabled: versionId != null,
|
||||||
|
queryFn: () =>
|
||||||
|
rpc<RequestVersionComparison>("models_request_version", { versionId: versionId! }),
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -2,6 +2,25 @@ import { useQuery } from "@tanstack/react-query";
|
|||||||
import type { HttpResponse } from "@yaakapp-internal/models";
|
import type { HttpResponse } from "@yaakapp-internal/models";
|
||||||
import { getResponseBodyBytes, getResponseBodyText } from "../lib/responseBody";
|
import { getResponseBodyBytes, getResponseBodyText } from "../lib/responseBody";
|
||||||
|
|
||||||
|
export function responseBodyTextQuery({
|
||||||
|
response,
|
||||||
|
filter,
|
||||||
|
}: {
|
||||||
|
response: HttpResponse;
|
||||||
|
filter: string | null;
|
||||||
|
}) {
|
||||||
|
return {
|
||||||
|
queryKey: [
|
||||||
|
"response_body_text",
|
||||||
|
response.id,
|
||||||
|
response.updatedAt,
|
||||||
|
response.contentLength,
|
||||||
|
filter ?? "",
|
||||||
|
],
|
||||||
|
queryFn: () => getResponseBodyText({ response, filter }),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function useResponseBodyText({
|
export function useResponseBodyText({
|
||||||
response,
|
response,
|
||||||
filter,
|
filter,
|
||||||
@@ -11,14 +30,7 @@ export function useResponseBodyText({
|
|||||||
}) {
|
}) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
placeholderData: (prev) => prev, // Keep previous data on refetch
|
placeholderData: (prev) => prev, // Keep previous data on refetch
|
||||||
queryKey: [
|
...responseBodyTextQuery({ response, filter }),
|
||||||
"response_body_text",
|
|
||||||
response.id,
|
|
||||||
response.updatedAt,
|
|
||||||
response.contentLength,
|
|
||||||
filter ?? "",
|
|
||||||
],
|
|
||||||
queryFn: () => getResponseBodyText({ response, filter }),
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import { useQuery } from "@tanstack/react-query";
|
||||||
|
import type { HttpResponse } from "@yaakapp-internal/models";
|
||||||
|
import { platform } from "@yaakapp-internal/platform";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A URL for a stored response body, for the viewers that hand one to an element
|
||||||
|
* instead of reading the bytes themselves.
|
||||||
|
*
|
||||||
|
* Resolved once here rather than inside each viewer: the host may have to ask
|
||||||
|
* the backend where the body is, and a viewer that computes its source during
|
||||||
|
* render (the PDF one, deliberately) needs it settled before it mounts.
|
||||||
|
*
|
||||||
|
* Null data means the response has no stored body.
|
||||||
|
*/
|
||||||
|
export function useResponseBodyUrl(response: HttpResponse | null) {
|
||||||
|
const responseId = response?.id ?? null;
|
||||||
|
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["response_body_url", responseId, response?.updatedAt ?? ""],
|
||||||
|
enabled: responseId != null,
|
||||||
|
// A response body is stored under the response's own id
|
||||||
|
queryFn: () => (responseId == null ? null : platform.blobs.url(responseId)),
|
||||||
|
});
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user