Files
yaak/src-web/components/UrlParameterEditor.tsx
Gregory Schier b4a1c418bb Run oxfmt across repo, add format script and docs
Add .oxfmtignore to skip generated bindings and wasm-pack output.
Add npm format script, update DEVELOPMENT.md for Vite+ toolchain,
and format all non-generated files with oxfmt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-13 10:15:49 -07:00

56 lines
1.7 KiB
TypeScript

import type { HttpRequest } from "@yaakapp-internal/models";
import { useCallback, useRef } from "react";
import { useRequestEditor, useRequestEditorEvent } from "../hooks/useRequestEditor";
import type { PairEditorHandle, PairEditorProps } from "./core/PairEditor";
import { PairOrBulkEditor } from "./core/PairOrBulkEditor";
import { VStack } from "./core/Stacks";
type Props = {
forceUpdateKey: string;
pairs: HttpRequest["headers"];
stateKey: PairEditorProps["stateKey"];
onChange: (headers: HttpRequest["urlParameters"]) => void;
};
export function UrlParametersEditor({ pairs, forceUpdateKey, onChange, stateKey }: Props) {
const pairEditorRef = useRef<PairEditorHandle>(null);
const handleInitPairEditorRef = useCallback((ref: PairEditorHandle) => {
pairEditorRef.current = ref;
}, []);
const [{ urlParametersKey }] = useRequestEditor();
useRequestEditorEvent(
"request_params.focus_value",
(name) => {
const pair = pairs.find((p) => p.name === name);
if (pair?.id != null) {
pairEditorRef.current?.focusValue(pair.id);
} else {
console.log(`Couldn't find pair to focus`, { name, pairs });
}
},
[pairs],
);
return (
<VStack className="h-full">
<PairOrBulkEditor
setRef={handleInitPairEditorRef}
allowMultilineValues
forceUpdateKey={forceUpdateKey + urlParametersKey}
nameAutocompleteFunctions
nameAutocompleteVariables
namePlaceholder="param_name"
onChange={onChange}
pairs={pairs}
preferenceName="url_parameters"
stateKey={stateKey}
valueAutocompleteFunctions
valueAutocompleteVariables
valuePlaceholder="Value"
/>
</VStack>
);
}