Files
yaak/src-web/components/FormMultipartEditor.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

58 lines
1.5 KiB
TypeScript

import type { HttpRequest } from "@yaakapp-internal/models";
import { useCallback, useMemo } from "react";
import type { Pair, PairEditorProps } from "./core/PairEditor";
import { PairEditor } from "./core/PairEditor";
type Props = {
forceUpdateKey: string;
request: HttpRequest;
onChange: (body: HttpRequest["body"]) => void;
};
export function FormMultipartEditor({ request, forceUpdateKey, onChange }: Props) {
const pairs = useMemo<Pair[]>(
() =>
(Array.isArray(request.body.form) ? request.body.form : []).map((p) => ({
enabled: p.enabled,
name: p.name,
value: p.file ?? p.value,
contentType: p.contentType,
filename: p.filename,
isFile: !!p.file,
id: p.id,
})),
[request.body.form],
);
const handleChange = useCallback<PairEditorProps["onChange"]>(
(pairs) =>
onChange({
form: pairs.map((p) => ({
enabled: p.enabled,
name: p.name,
contentType: p.contentType,
filename: p.filename,
file: p.isFile ? p.value : undefined,
value: p.isFile ? undefined : p.value,
id: p.id,
})),
}),
[onChange],
);
return (
<PairEditor
valueAutocompleteFunctions
valueAutocompleteVariables
nameAutocompleteVariables
nameAutocompleteFunctions
allowFileValues
allowMultilineValues
pairs={pairs}
onChange={handleChange}
forceUpdateKey={forceUpdateKey}
stateKey={`multipart.${request.id}`}
/>
);
}