mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 11:51:13 +01:00
Placeholder CM tags working
This commit is contained in:
@@ -1,37 +1,14 @@
|
||||
import type { HttpRequest } from '@yaakapp/api';
|
||||
import { useMemo } from 'react';
|
||||
import type { Pair } from './core/PairEditor';
|
||||
import { PairOrBulkEditor } from './core/PairOrBulkEditor';
|
||||
import { VStack } from './core/Stacks';
|
||||
|
||||
type Props = {
|
||||
forceUpdateKey: string;
|
||||
urlParameters: HttpRequest['headers'];
|
||||
pairs: HttpRequest['headers'];
|
||||
onChange: (headers: HttpRequest['urlParameters']) => void;
|
||||
url: string;
|
||||
};
|
||||
|
||||
export function UrlParametersEditor({ urlParameters, forceUpdateKey, onChange, url }: Props) {
|
||||
const placeholderNames = Array.from(url.matchAll(/\/(:[^/]+)/g)).map((m) => m[1] ?? '');
|
||||
|
||||
const pairs = useMemo(() => {
|
||||
const items: Pair[] = [...urlParameters];
|
||||
for (const name of placeholderNames) {
|
||||
const index = items.findIndex((p) => p.name === name);
|
||||
if (index >= 0) {
|
||||
items[index]!.readOnlyName = true;
|
||||
} else {
|
||||
items.push({
|
||||
name,
|
||||
value: '',
|
||||
enabled: true,
|
||||
readOnlyName: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}, [placeholderNames, urlParameters]);
|
||||
|
||||
export function UrlParametersEditor({ pairs, forceUpdateKey, onChange }: Props) {
|
||||
return (
|
||||
<VStack className="h-full">
|
||||
<PairOrBulkEditor
|
||||
@@ -42,7 +19,7 @@ export function UrlParametersEditor({ urlParameters, forceUpdateKey, onChange, u
|
||||
valuePlaceholder="Value"
|
||||
pairs={pairs}
|
||||
onChange={onChange}
|
||||
forceUpdateKey={forceUpdateKey + placeholderNames.join(':')}
|
||||
forceUpdateKey={forceUpdateKey}
|
||||
/>
|
||||
</VStack>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user