mirror of
https://github.com/JoshiCodes/knock.git
synced 2026-12-04 15:19:41 +01:00
Skeleton, REST core, variables and JSON editor (M0–M2)
- knock-core: YAML collection format with unknown-field round trip, variable resolution across scopes with secrets and dynamic values, HTTP engine with manual redirects, cookie jar and large-body spill, basic/bearer/API key auth with debug output, assertions and extracts - Tauri app: collection commands, file watcher, SQLite history, keyring-backed secrets - Svelte UI: sidebar tree, tabs, request editor, response viewer, JSON form/code editor with schema hints, environments, settings
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<script lang="ts">
|
||||
import { plain } from '$lib/plain.svelte';
|
||||
import { toast } from '@joshicodes/cock';
|
||||
import KeyValueTable from '$lib/ui/KeyValueTable.svelte';
|
||||
import AuthPanel from '$lib/views/auth/AuthPanel.svelte';
|
||||
import { api, errorText } from '$lib/api';
|
||||
import { ws } from '$lib/state/workspace.svelte';
|
||||
import { HEADER_NAMES, headerValues } from '$lib/headers';
|
||||
import type { FolderMeta, KeyValue } from '$lib/types';
|
||||
import { dialogs } from '$lib/state/dialogs.svelte';
|
||||
|
||||
let { col, id }: { col: string; id: string } = $props();
|
||||
|
||||
let meta = $state<FolderMeta | null>(null);
|
||||
let saved = $state('');
|
||||
let varRows = $state<KeyValue[]>([]);
|
||||
|
||||
async function load() {
|
||||
const m = await api.folderGet(col, id);
|
||||
m.headers ??= [];
|
||||
m.auth ??= 'inherit';
|
||||
meta = m;
|
||||
varRows = Object.entries(m.vars ?? {}).map(([name, value]) => ({ name, value }));
|
||||
saved = JSON.stringify(m);
|
||||
}
|
||||
$effect(() => {
|
||||
load();
|
||||
});
|
||||
|
||||
let dirty = $derived(meta ? JSON.stringify(meta) !== saved : false);
|
||||
|
||||
async function save() {
|
||||
if (!meta) return;
|
||||
meta.vars = Object.fromEntries(varRows.filter((r) => r.name).map((r) => [r.name, r.value]));
|
||||
try {
|
||||
ws.upsert(await api.folderSave(col, id, plain(meta)));
|
||||
saved = JSON.stringify(meta);
|
||||
toast.success('Folder saved');
|
||||
} catch (e) {
|
||||
toast.error('Could not save', { description: errorText(e) });
|
||||
}
|
||||
}
|
||||
|
||||
function onKey(e: KeyboardEvent) {
|
||||
if ((e.ctrlKey || e.metaKey) && e.key === 's') {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
save();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onkeydowncapture={onKey} />
|
||||
|
||||
{#if meta}
|
||||
<div class="k-scroll h-full">
|
||||
<div class="mx-auto flex max-w-3xl flex-col gap-8 px-6 py-6">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="flex-1">
|
||||
<div class="k-label">Folder</div>
|
||||
<h1 class="text-[20px] font-bold text-strong">{meta.name ?? id}</h1>
|
||||
<div class="mono text-[12px] text-fg-subtle">{id}/folder.yaml</div>
|
||||
</div>
|
||||
<button class="rounded px-3 py-1.5 text-fg-muted hover:text-fg" onclick={() => dialogs.runner(col, id)}>Run folder</button>
|
||||
<button class="rounded bg-accent px-4 py-1.5 font-bold text-accent-fg disabled:opacity-40" disabled={!dirty} onclick={save}>Save</button>
|
||||
</div>
|
||||
<section>
|
||||
<h2 class="k-label mb-2">Auth</h2>
|
||||
<p class="mb-2 text-[12px] text-fg-subtle">Requests in this folder that use "inherit" get this auth.</p>
|
||||
<div class="rounded border border-line"><AuthPanel bind:auth={meta.auth!} level="folder" /></div>
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="k-label mb-2">Headers</h2>
|
||||
<KeyValueTable bind:rows={meta.headers!} nameSuggestions={HEADER_NAMES} valueSuggestions={headerValues} />
|
||||
</section>
|
||||
<section>
|
||||
<h2 class="k-label mb-2">Variables</h2>
|
||||
<KeyValueTable bind:rows={varRows} onchange={() => (meta!.vars = Object.fromEntries(varRows.filter((r) => r.name).map((r) => [r.name, r.value])))} />
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
Reference in New Issue
Block a user