Merge remote-tracking branch 'origin/main'

This commit is contained in:
Gregory Schier
2025-07-19 21:25:21 -07:00
6 changed files with 68 additions and 18 deletions

View File

@@ -17,8 +17,8 @@ import type {
SendHttpRequestResponse,
ShowToastRequest,
TemplateRenderRequest,
TemplateRenderResponse,
} from '../bindings/gen_events.ts';
import { JsonValue } from '../bindings/serde_json/JsonValue';
export interface Context {
clipboard: {
@@ -59,6 +59,6 @@ export interface Context {
find(args: FindHttpResponsesRequest): Promise<FindHttpResponsesResponse['httpResponses']>;
};
templates: {
render(args: TemplateRenderRequest): Promise<TemplateRenderResponse['data']>;
render<T extends JsonValue>(args: TemplateRenderRequest & { data: T }): Promise<T>;
};
}

View File

@@ -1,3 +1,4 @@
import type { HttpUrlParameter } from '@yaakapp-internal/models';
import type { CallTemplateFunctionArgs, Context, PluginDefinition } from '@yaakapp/api';
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;
},
},
],
};

View File

@@ -14,7 +14,7 @@ export function openWorkspaceSettings(tab?: WorkspaceSettingsTab) {
id: 'workspace-settings',
title: 'Workspace Settings',
size: 'md',
className: 'h-[calc(100vh-5rem)] max-h-[40rem]',
className: 'h-[calc(100vh-5rem)] !max-h-[40rem]',
noPadding: true,
render: ({ hide }) => (
<WorkspaceSettingsDialog workspaceId={workspaceId} hide={hide} tab={tab} />

View File

@@ -12,7 +12,7 @@ import type {
} from '@yaakapp-internal/plugins';
import classNames from 'classnames';
import { useAtomValue } from 'jotai';
import { useCallback } from 'react';
import { useCallback, useEffect } from 'react';
import { useActiveRequest } from '../hooks/useActiveRequest';
import { useRandomKey } from '../hooks/useRandomKey';
import { capitalize } from '../lib/capitalize';
@@ -415,7 +415,7 @@ function FileArg({
disabled={arg.disabled}
help={arg.description}
onChange={({ filePath }) => onChange(filePath)}
filePath={filePath === '__NULL__' ? null : filePath}
filePath={filePath === DYNAMIC_FORM_NULL_ARG ? null : filePath}
directory={!!arg.directory}
/>
);
@@ -432,7 +432,14 @@ function HttpRequestArg({
}) {
const folders = useAtomValue(foldersAtom);
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 (
<Select
label={arg.label ?? arg.name}
@@ -446,7 +453,7 @@ function HttpRequestArg({
return {
label:
buildRequestBreadcrumbs(r, folders).join(' / ') +
(r.id == activeRequest?.id ? ' (current)' : ''),
(r.id == activeHttpRequest?.id ? ' (current)' : ''),
value: r.id,
};
}),

View File

@@ -74,22 +74,22 @@ export default function Settings({ hide }: Props) {
onChangeValue={setTab}
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 />
</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 />
</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 />
</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 />
</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 />
</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 />
</TabContent>
</Tabs>

View File

@@ -84,7 +84,7 @@ export function Tabs({
tabListClassName,
addBorders && '!-ml-1',
'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 ',
// Give space for button focus states within overflow boundary.
layout === 'vertical' && 'py-1 -ml-5 pl-3 pr-1',
@@ -100,9 +100,9 @@ export function Tabs({
const isActive = t.value === value;
const btnClassName = classNames(
'h-sm flex items-center rounded whitespace-nowrap',
'!px-2 ml-[1px]',
addBorders && 'border',
isActive ? 'text-text' : 'text-text-subtle hover:text-text',
'!px-2 ml-[1px] hocus:text-text',
addBorders && 'border hocus:bg-surface-highlight',
isActive ? 'text-text' : 'text-text-subtle',
isActive && addBorders
? 'border-surface-active bg-surface-active'
: layout === 'vertical'
@@ -177,7 +177,7 @@ export const TabContent = memo(function TabContent({
<div
tabIndex={-1}
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}
</div>