Skip to content

Commit f0e4699

Browse files
committed
added cURL option somewhere else
1 parent bf1fdf0 commit f0e4699

File tree

4 files changed

+57
-18
lines changed

4 files changed

+57
-18
lines changed

src-web/components/ImportCurlDialog.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Banner } from './core/Banner';
44
import { Button } from './core/Button';
55
import { Editor } from './core/Editor/LazyEditor';
66
import { Icon } from './core/Icon';
7+
import { PlainInput } from './core/PlainInput';
78
import { HStack, VStack } from './core/Stacks';
89

910
interface Props {
@@ -17,6 +18,7 @@ const EXAMPLE_CURL = `curl https://api.example.com/users \\
1718

1819
export function ImportCurlDialog({ hide }: Props) {
1920
const [curlCommand, setCurlCommand] = useState<string>('');
21+
const [requestName, setRequestName] = useState<string>('');
2022
const [isLoading, setIsLoading] = useState<boolean>(false);
2123
const [error, setError] = useState<string | null>(null);
2224
const { mutate: importCurl } = useImportCurl();
@@ -35,7 +37,7 @@ export function ImportCurlDialog({ hide }: Props) {
3537
setError(null);
3638
setIsLoading(true);
3739
try {
38-
await importCurl({ command: curlCommand });
40+
await importCurl({ command: curlCommand, name: requestName });
3941
hide();
4042
} catch (error) {
4143
console.error('Failed to import cURL:', error);
@@ -63,6 +65,18 @@ export function ImportCurlDialog({ hide }: Props) {
6365
</VStack>
6466
</Banner>
6567

68+
{/* Request Name (Optional) */}
69+
<VStack space={2}>
70+
<div className="text-sm font-medium text-text">Name <span className="text-text-subtle font-normal">(optional)</span></div>
71+
<PlainInput
72+
label="Request Name"
73+
hideLabel
74+
placeholder="e.g., Get Users, Create Order"
75+
defaultValue={requestName}
76+
onChange={(value) => setRequestName(value)}
77+
/>
78+
</VStack>
79+
6680
{/* Editor Section */}
6781
<VStack space={2} className="flex-1 min-h-0">
6882
<div className="text-sm font-medium text-text">cURL Command</div>

src-web/components/Sidebar.tsx

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { sendAnyHttpRequest } from '../hooks/useSendAnyHttpRequest';
4343
import { useSidebarHidden } from '../hooks/useSidebarHidden';
4444
import { deepEqualAtom } from '../lib/atoms';
4545
import { deleteModelWithConfirm } from '../lib/deleteModelWithConfirm';
46+
import { showDialog } from '../lib/dialog';
4647
import { jotaiStore } from '../lib/jotai';
4748
import { resolvedModelName } from '../lib/resolvedModelName';
4849
import { isSidebarFocused } from '../lib/scopes';
@@ -67,6 +68,7 @@ import type { TreeHandle, TreeProps } from './core/tree/Tree';
6768
import { Tree } from './core/tree/Tree';
6869
import type { TreeItemProps } from './core/tree/TreeItem';
6970
import { GitDropdown } from './git/GitDropdown';
71+
import { ImportCurlDialog } from './ImportCurlDialog';
7072

7173
type SidebarModel = Workspace | Folder | HttpRequest | GrpcRequest | WebsocketRequest;
7274
function isSidebarLeafModel(m: AnyModel): boolean {
@@ -457,6 +459,25 @@ function Sidebar({ className }: { className?: string }) {
457459
});
458460
}, [allFields]);
459461

462+
// Subscribe to activeIdAtom changes to auto-select new requests in the sidebar
463+
useEffect(() => {
464+
return jotaiStore.sub(activeIdAtom, () => {
465+
const activeId = jotaiStore.get(activeIdAtom);
466+
if (activeId != null && treeRef.current != null) {
467+
treeRef.current.selectItem(activeId);
468+
}
469+
});
470+
}, []);
471+
472+
const handleImportCurl = useCallback(() => {
473+
showDialog({
474+
id: 'import-curl',
475+
title: 'Import cURL Command',
476+
size: 'md',
477+
render: ImportCurlDialog,
478+
});
479+
}, []);
480+
460481
if (tree == null || hidden) {
461482
return null;
462483
}
@@ -467,9 +488,18 @@ function Sidebar({ className }: { className?: string }) {
467488
aria-hidden={hidden ?? undefined}
468489
className={classNames(className, 'h-full grid grid-rows-[auto_minmax(0,1fr)_auto]')}
469490
>
470-
<div className="w-full pl-3 pr-0.5 pt-3 grid grid-cols-[minmax(0,1fr)_auto] items-center">
491+
<div className="w-full px-3 pt-3 flex flex-col gap-2">
492+
<IconButton
493+
size="sm"
494+
icon="import"
495+
className="w-full justify-center"
496+
title="Import cURL command"
497+
onClick={handleImportCurl}
498+
>
499+
Import
500+
</IconButton>
471501
{(tree.children?.length ?? 0) > 0 && (
472-
<>
502+
<div className="grid grid-cols-[minmax(0,1fr)_auto] items-center">
473503
<Input
474504
hideLabel
475505
setRef={setFilterRef}
@@ -544,7 +574,7 @@ function Sidebar({ className }: { className?: string }) {
544574
title="Show sidebar actions menu"
545575
/>
546576
</Dropdown>
547-
</>
577+
</div>
548578
)}
549579
</div>
550580
{allHidden ? (

src-web/hooks/useCreateDropdownItems.tsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import { useMemo } from 'react';
55
import { createFolder } from '../commands/commands';
66
import type { DropdownItem } from '../components/core/Dropdown';
77
import { Icon } from '../components/core/Icon';
8-
import { ImportCurlDialog } from '../components/ImportCurlDialog';
98
import { createRequestAndNavigate } from '../lib/createRequestAndNavigate';
10-
import { showDialog } from '../lib/dialog';
119
import { generateId } from '../lib/generateId';
1210
import { BODY_TYPE_GRAPHQL } from '../lib/model_util';
1311
import { activeRequestAtom } from './useActiveRequest';
@@ -66,17 +64,6 @@ export function getCreateDropdownItems({
6664
onCreate?.('http_request', id);
6765
},
6866
},
69-
{
70-
label: 'cURL',
71-
leftSlot: hideIcons ? undefined : <Icon icon="plus" />,
72-
onSelect: () =>
73-
showDialog({
74-
id: 'import-curl',
75-
title: 'Import cURL Command',
76-
size: 'md',
77-
render: ImportCurlDialog,
78-
}),
79-
},
8067
{
8168
label: 'GraphQL',
8269
leftSlot: hideIcons ? undefined : <Icon icon="plus" />,

src-web/hooks/useImportCurl.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,28 @@ export function useImportCurl() {
1414
mutationFn: async ({
1515
overwriteRequestId,
1616
command,
17+
name,
1718
}: {
1819
overwriteRequestId?: string;
1920
command: string;
21+
name?: string;
2022
}) => {
2123
const workspaceId = jotaiStore.get(activeWorkspaceIdAtom);
2224
const importedRequest: HttpRequest = await invokeCmd('cmd_curl_to_request', {
2325
command,
2426
workspaceId,
2527
});
2628

29+
// Apply custom name if provided
30+
const requestToCreate = {
31+
...importedRequest,
32+
name: name?.trim() || importedRequest.name,
33+
};
34+
2735
let verb: string;
2836
if (overwriteRequestId == null) {
2937
verb = 'Created';
30-
await createRequestAndNavigate(importedRequest);
38+
await createRequestAndNavigate(requestToCreate);
3139
} else {
3240
verb = 'Updated';
3341
await patchModelById(importedRequest.model, overwriteRequestId, (r: HttpRequest) => ({

0 commit comments

Comments
 (0)