mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-09-10 11:51:57 +02:00
feat(client): offer the request a response was sent from
When the selected response's version no longer matches the live request, the response header grows a "Request Changed" control with View Diff and Restore. It follows the GraphQL editor's shape — a state-labelled dropdown button rather than a new icon in the action row — because the label is the whole point: it has to say *that* something is different before it offers to do anything about it. Hidden when the two agree, and for responses recorded before versioning existed, which have no version and never will. The diff reuses the Git dialog's DiffViewer over YAML renderings of the two documents, so a request diff reads like a commit diff. Restore flushes pending edits first (the backend restores from the database, so a debounced keystroke would otherwise land on top of it) and calls wasUpdatedExternally afterwards, because the write came from this window and the store's echo suppression would leave open editors showing the old content. EditSessionTracker turns the boundaries only the frontend can see — switching requests, losing focus, closing, falling idle for 60s — into snapshot calls. It tracks no content of its own: content addressing already decides whether a boundary had anything behind it, which is what keeps this a timer and two assignments instead of a change-tracking system.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { flushAllModelWrites } from "@yaakapp-internal/models";
|
||||
import type { ModelVersion } from "@yaakapp-internal/models";
|
||||
import { wasUpdatedExternally } from "../hooks/useRequestUpdateKey";
|
||||
import { fireAndForget } from "./fireAndForget";
|
||||
import { rpc } from "./rpc";
|
||||
import { showToast } from "./toast";
|
||||
|
||||
/**
|
||||
* Put an old version's content back into the live request.
|
||||
*
|
||||
* The backend captures whatever the request currently holds before
|
||||
* overwriting it, so this is not a destructive action even when the last edit
|
||||
* was never versioned — but the request is still rewritten under the user's
|
||||
* cursor, so it is announced.
|
||||
*/
|
||||
export function restoreRequestVersion(version: ModelVersion) {
|
||||
fireAndForget(
|
||||
(async () => {
|
||||
// The backend restores from the database, so anything still sitting in a
|
||||
// debounce has to land first — otherwise it would overwrite the restore
|
||||
await flushAllModelWrites();
|
||||
const requestId = await rpc<string>("models_restore_request_version", {
|
||||
versionId: version.id,
|
||||
});
|
||||
// The write came from this window, so the store's echo suppression would
|
||||
// otherwise leave open editors showing what was there before
|
||||
wasUpdatedExternally(requestId);
|
||||
showToast({
|
||||
id: "request-version-restored",
|
||||
color: "success",
|
||||
message: "Restored the request that produced this response",
|
||||
});
|
||||
})(),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user