mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-21 08:11:24 +02:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -17,8 +17,8 @@ import type {
|
|||||||
SendHttpRequestResponse,
|
SendHttpRequestResponse,
|
||||||
ShowToastRequest,
|
ShowToastRequest,
|
||||||
TemplateRenderRequest,
|
TemplateRenderRequest,
|
||||||
TemplateRenderResponse,
|
|
||||||
} from '../bindings/gen_events.ts';
|
} from '../bindings/gen_events.ts';
|
||||||
|
import { JsonValue } from '../bindings/serde_json/JsonValue';
|
||||||
|
|
||||||
export interface Context {
|
export interface Context {
|
||||||
clipboard: {
|
clipboard: {
|
||||||
@@ -59,6 +59,6 @@ export interface Context {
|
|||||||
find(args: FindHttpResponsesRequest): Promise<FindHttpResponsesResponse['httpResponses']>;
|
find(args: FindHttpResponsesRequest): Promise<FindHttpResponsesResponse['httpResponses']>;
|
||||||
};
|
};
|
||||||
templates: {
|
templates: {
|
||||||
render(args: TemplateRenderRequest): Promise<TemplateRenderResponse['data']>;
|
render<T extends JsonValue>(args: TemplateRenderRequest & { data: T }): Promise<T>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { HttpUrlParameter } from '@yaakapp-internal/models';
|
||||||
import type { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
|
import type { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
|
||||||
|
|
||||||
export const plugin: PluginDefinition = {
|
export const plugin: PluginDefinition = {
|
||||||
@@ -53,5 +54,47 @@ export const plugin: PluginDefinition = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'request.param',
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
name: 'requestId',
|
||||||
|
label: 'Http Request',
|
||||||
|
type: 'http_request',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'param',
|
||||||
|
label: 'Param Name',
|
||||||
|
type: 'text',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
async onRender(ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
|
||||||
|
const paramName = String(args.values.param ?? '');
|
||||||
|
const requestId = String(args.values.requestId ?? 'n/a');
|
||||||
|
const httpRequest = await ctx.httpRequest.getById({ id: requestId });
|
||||||
|
if (httpRequest == null) return null;
|
||||||
|
|
||||||
|
const renderedUrl = await ctx.templates.render({
|
||||||
|
data: httpRequest.url,
|
||||||
|
purpose: args.purpose,
|
||||||
|
});
|
||||||
|
|
||||||
|
const querystring = renderedUrl.split('?')[1] ?? '';
|
||||||
|
const paramsFromUrl: HttpUrlParameter[] = new URLSearchParams(querystring)
|
||||||
|
.entries()
|
||||||
|
.map(([name, value]): HttpUrlParameter => ({ name, value }))
|
||||||
|
.toArray();
|
||||||
|
|
||||||
|
const allParams = [...paramsFromUrl, ...httpRequest.urlParameters];
|
||||||
|
const allEnabledParams = allParams.filter((p) => p.enabled !== false);
|
||||||
|
const foundParam = allEnabledParams.find((p) => p.name === paramName);
|
||||||
|
|
||||||
|
const renderedValue = await ctx.templates.render({
|
||||||
|
data: foundParam?.value ?? '',
|
||||||
|
purpose: args.purpose,
|
||||||
|
});
|
||||||
|
return renderedValue;
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export function openWorkspaceSettings(tab?: WorkspaceSettingsTab) {
|
|||||||
id: 'workspace-settings',
|
id: 'workspace-settings',
|
||||||
title: 'Workspace Settings',
|
title: 'Workspace Settings',
|
||||||
size: 'md',
|
size: 'md',
|
||||||
className: 'h-[calc(100vh-5rem)] max-h-[40rem]',
|
className: 'h-[calc(100vh-5rem)] !max-h-[40rem]',
|
||||||
noPadding: true,
|
noPadding: true,
|
||||||
render: ({ hide }) => (
|
render: ({ hide }) => (
|
||||||
<WorkspaceSettingsDialog workspaceId={workspaceId} hide={hide} tab={tab} />
|
<WorkspaceSettingsDialog workspaceId={workspaceId} hide={hide} tab={tab} />
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import type {
|
|||||||
} from '@yaakapp-internal/plugins';
|
} from '@yaakapp-internal/plugins';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { useAtomValue } from 'jotai';
|
import { useAtomValue } from 'jotai';
|
||||||
import { useCallback } from 'react';
|
import { useCallback, useEffect } from 'react';
|
||||||
import { useActiveRequest } from '../hooks/useActiveRequest';
|
import { useActiveRequest } from '../hooks/useActiveRequest';
|
||||||
import { useRandomKey } from '../hooks/useRandomKey';
|
import { useRandomKey } from '../hooks/useRandomKey';
|
||||||
import { capitalize } from '../lib/capitalize';
|
import { capitalize } from '../lib/capitalize';
|
||||||
@@ -415,7 +415,7 @@ function FileArg({
|
|||||||
disabled={arg.disabled}
|
disabled={arg.disabled}
|
||||||
help={arg.description}
|
help={arg.description}
|
||||||
onChange={({ filePath }) => onChange(filePath)}
|
onChange={({ filePath }) => onChange(filePath)}
|
||||||
filePath={filePath === '__NULL__' ? null : filePath}
|
filePath={filePath === DYNAMIC_FORM_NULL_ARG ? null : filePath}
|
||||||
directory={!!arg.directory}
|
directory={!!arg.directory}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@@ -432,7 +432,14 @@ function HttpRequestArg({
|
|||||||
}) {
|
}) {
|
||||||
const folders = useAtomValue(foldersAtom);
|
const folders = useAtomValue(foldersAtom);
|
||||||
const httpRequests = useAtomValue(httpRequestsAtom);
|
const httpRequests = useAtomValue(httpRequestsAtom);
|
||||||
const activeRequest = useActiveRequest();
|
const activeHttpRequest = useActiveRequest('http_request');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (value === DYNAMIC_FORM_NULL_ARG && activeHttpRequest) {
|
||||||
|
onChange(activeHttpRequest.id);
|
||||||
|
}
|
||||||
|
}, [activeHttpRequest, onChange, value]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
label={arg.label ?? arg.name}
|
label={arg.label ?? arg.name}
|
||||||
@@ -446,7 +453,7 @@ function HttpRequestArg({
|
|||||||
return {
|
return {
|
||||||
label:
|
label:
|
||||||
buildRequestBreadcrumbs(r, folders).join(' / ') +
|
buildRequestBreadcrumbs(r, folders).join(' / ') +
|
||||||
(r.id == activeRequest?.id ? ' (current)' : ''),
|
(r.id == activeHttpRequest?.id ? ' (current)' : ''),
|
||||||
value: r.id,
|
value: r.id,
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -74,22 +74,22 @@ export default function Settings({ hide }: Props) {
|
|||||||
onChangeValue={setTab}
|
onChangeValue={setTab}
|
||||||
tabs={tabs.map((value) => ({ value, label: capitalize(value) }))}
|
tabs={tabs.map((value) => ({ value, label: capitalize(value) }))}
|
||||||
>
|
>
|
||||||
<TabContent value={TAB_GENERAL} className="pt-3 overflow-y-auto h-full px-4">
|
<TabContent value={TAB_GENERAL} className="overflow-y-auto h-full px-4">
|
||||||
<SettingsGeneral />
|
<SettingsGeneral />
|
||||||
</TabContent>
|
</TabContent>
|
||||||
<TabContent value={TAB_INTERFACE} className="pt-3 overflow-y-auto h-full px-4">
|
<TabContent value={TAB_INTERFACE} className="overflow-y-auto h-full px-4">
|
||||||
<SettingsInterface />
|
<SettingsInterface />
|
||||||
</TabContent>
|
</TabContent>
|
||||||
<TabContent value={TAB_THEME} className="pt-3 overflow-y-auto h-full px-4">
|
<TabContent value={TAB_THEME} className="overflow-y-auto h-full px-4">
|
||||||
<SettingsTheme />
|
<SettingsTheme />
|
||||||
</TabContent>
|
</TabContent>
|
||||||
<TabContent value={TAB_PLUGINS} className="pt-3 h-full px-4 grid grid-rows-1">
|
<TabContent value={TAB_PLUGINS} className="h-full px-4 grid grid-rows-1">
|
||||||
<SettingsPlugins />
|
<SettingsPlugins />
|
||||||
</TabContent>
|
</TabContent>
|
||||||
<TabContent value={TAB_PROXY} className="pt-3 overflow-y-auto h-full px-4">
|
<TabContent value={TAB_PROXY} className="overflow-y-auto h-full px-4">
|
||||||
<SettingsProxy />
|
<SettingsProxy />
|
||||||
</TabContent>
|
</TabContent>
|
||||||
<TabContent value={TAB_LICENSE} className="pt-3 overflow-y-auto h-full px-4">
|
<TabContent value={TAB_LICENSE} className="overflow-y-auto h-full px-4">
|
||||||
<SettingsLicense />
|
<SettingsLicense />
|
||||||
</TabContent>
|
</TabContent>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ export function Tabs({
|
|||||||
tabListClassName,
|
tabListClassName,
|
||||||
addBorders && '!-ml-1',
|
addBorders && '!-ml-1',
|
||||||
'flex items-center hide-scrollbars mb-2',
|
'flex items-center hide-scrollbars mb-2',
|
||||||
layout === 'horizontal' && 'h-full overflow-auto px-2',
|
layout === 'horizontal' && 'h-full overflow-auto p-2',
|
||||||
layout === 'vertical' && 'overflow-x-auto overflow-y-visible ',
|
layout === 'vertical' && 'overflow-x-auto overflow-y-visible ',
|
||||||
// Give space for button focus states within overflow boundary.
|
// Give space for button focus states within overflow boundary.
|
||||||
layout === 'vertical' && 'py-1 -ml-5 pl-3 pr-1',
|
layout === 'vertical' && 'py-1 -ml-5 pl-3 pr-1',
|
||||||
@@ -100,9 +100,9 @@ export function Tabs({
|
|||||||
const isActive = t.value === value;
|
const isActive = t.value === value;
|
||||||
const btnClassName = classNames(
|
const btnClassName = classNames(
|
||||||
'h-sm flex items-center rounded whitespace-nowrap',
|
'h-sm flex items-center rounded whitespace-nowrap',
|
||||||
'!px-2 ml-[1px]',
|
'!px-2 ml-[1px] hocus:text-text',
|
||||||
addBorders && 'border',
|
addBorders && 'border hocus:bg-surface-highlight',
|
||||||
isActive ? 'text-text' : 'text-text-subtle hover:text-text',
|
isActive ? 'text-text' : 'text-text-subtle',
|
||||||
isActive && addBorders
|
isActive && addBorders
|
||||||
? 'border-surface-active bg-surface-active'
|
? 'border-surface-active bg-surface-active'
|
||||||
: layout === 'vertical'
|
: layout === 'vertical'
|
||||||
@@ -177,7 +177,7 @@ export const TabContent = memo(function TabContent({
|
|||||||
<div
|
<div
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
data-tab={value}
|
data-tab={value}
|
||||||
className={classNames(className, 'tab-content', 'hidden w-full h-full')}
|
className={classNames(className, 'tab-content', 'hidden w-full h-full py-2')}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user