mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-25 19:01:14 +01:00
Form urlencoded bodies!
This commit is contained in:
37
src-web/components/FormUrlencodedEditor.tsx
Normal file
37
src-web/components/FormUrlencodedEditor.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import type { HttpRequest } from '../lib/models';
|
||||
import type { PairEditorProps } from './core/PairEditor';
|
||||
import { PairEditor } from './core/PairEditor';
|
||||
|
||||
type Props = {
|
||||
forceUpdateKey: string;
|
||||
body: HttpRequest['body'];
|
||||
onChange: (headers: HttpRequest['body']) => void;
|
||||
};
|
||||
|
||||
export function FormUrlencodedEditor({ body, forceUpdateKey, onChange }: Props) {
|
||||
const pairs = useMemo(
|
||||
() =>
|
||||
(Array.isArray(body.form) ? body.form : []).map((p) => ({
|
||||
enabled: p.enabled,
|
||||
name: p.name,
|
||||
value: p.value,
|
||||
})),
|
||||
[body.form],
|
||||
);
|
||||
|
||||
const handleChange = useCallback<PairEditorProps['onChange']>(
|
||||
(pairs) => onChange({ form: pairs }),
|
||||
[onChange],
|
||||
);
|
||||
|
||||
return (
|
||||
<PairEditor
|
||||
valueAutocompleteVariables
|
||||
nameAutocompleteVariables
|
||||
pairs={pairs}
|
||||
onChange={handleChange}
|
||||
forceUpdateKey={forceUpdateKey}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user