mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-07-02 02:51:40 +02:00
Show folder structure in request selection
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import type { Folder, HttpRequest } from '@yaakapp-internal/models';
|
||||||
import type {
|
import type {
|
||||||
TemplateFunction,
|
TemplateFunction,
|
||||||
TemplateFunctionArg,
|
TemplateFunctionArg,
|
||||||
@@ -12,6 +13,7 @@ import classNames from 'classnames';
|
|||||||
import { useCallback, useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
import { useActiveRequest } from '../hooks/useActiveRequest';
|
import { useActiveRequest } from '../hooks/useActiveRequest';
|
||||||
import { useDebouncedValue } from '../hooks/useDebouncedValue';
|
import { useDebouncedValue } from '../hooks/useDebouncedValue';
|
||||||
|
import { useFolders } from '../hooks/useFolders';
|
||||||
import { useHttpRequests } from '../hooks/useHttpRequests';
|
import { useHttpRequests } from '../hooks/useHttpRequests';
|
||||||
import { useRenderTemplate } from '../hooks/useRenderTemplate';
|
import { useRenderTemplate } from '../hooks/useRenderTemplate';
|
||||||
import { useTemplateTokensToString } from '../hooks/useTemplateTokensToString';
|
import { useTemplateTokensToString } from '../hooks/useTemplateTokensToString';
|
||||||
@@ -253,6 +255,7 @@ function HttpRequestArg({
|
|||||||
value: string;
|
value: string;
|
||||||
onChange: (v: string) => void;
|
onChange: (v: string) => void;
|
||||||
}) {
|
}) {
|
||||||
|
const folders = useFolders();
|
||||||
const httpRequests = useHttpRequests();
|
const httpRequests = useHttpRequests();
|
||||||
const activeRequest = useActiveRequest();
|
const activeRequest = useActiveRequest();
|
||||||
return (
|
return (
|
||||||
@@ -262,15 +265,35 @@ function HttpRequestArg({
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
value={value}
|
value={value}
|
||||||
options={[
|
options={[
|
||||||
...httpRequests.map((r) => ({
|
...httpRequests.map((r) => {
|
||||||
label: fallbackRequestName(r) + (activeRequest?.id === r.id ? ' (current)' : ''),
|
return {
|
||||||
value: r.id,
|
label: buildRequestBreadcrumbs(r, folders).join(' / ') + (r.id == activeRequest?.id ? ' (current)' : ''),
|
||||||
})),
|
value: r.id,
|
||||||
|
};
|
||||||
|
}),
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildRequestBreadcrumbs(request: HttpRequest, folders: Folder[]): string[] {
|
||||||
|
const ancestors: (HttpRequest | Folder)[] = [request];
|
||||||
|
|
||||||
|
const next = () => {
|
||||||
|
const latest = ancestors[0];
|
||||||
|
if (latest == null) return [];
|
||||||
|
|
||||||
|
const parent = folders.find((f) => f.id === latest.folderId);
|
||||||
|
if (parent == null) return;
|
||||||
|
|
||||||
|
ancestors.unshift(parent);
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
next();
|
||||||
|
|
||||||
|
return ancestors.map((a) => (a.model === 'folder' ? a.name : fallbackRequestName(a)));
|
||||||
|
}
|
||||||
|
|
||||||
function CheckboxArg({
|
function CheckboxArg({
|
||||||
arg,
|
arg,
|
||||||
onChange,
|
onChange,
|
||||||
|
|||||||
Reference in New Issue
Block a user