From 6dc4943f55c762c1ad57edec15f0345b4d2dba11 Mon Sep 17 00:00:00 2001 From: jackkav Date: Thu, 2 May 2024 09:44:40 +0200 Subject: [PATCH] can navigate to folder --- packages/insomnia/src/models/grpc-request.ts | 2 +- packages/insomnia/src/models/request-group.ts | 2 +- packages/insomnia/src/models/request.ts | 2 +- .../insomnia/src/models/websocket-request.ts | 2 +- .../components/panes/request-group-pane.tsx | 12 +++++++++++ packages/insomnia/src/ui/index.tsx | 9 ++++++++ packages/insomnia/src/ui/routes/debug.tsx | 21 ++++++++++++++----- .../insomnia/src/ui/routes/request-group.tsx | 21 ++++++++++++++++++- 8 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 packages/insomnia/src/ui/components/panes/request-group-pane.tsx diff --git a/packages/insomnia/src/models/grpc-request.ts b/packages/insomnia/src/models/grpc-request.ts index 2dd8c03179b..ec34cd649ac 100644 --- a/packages/insomnia/src/models/grpc-request.ts +++ b/packages/insomnia/src/models/grpc-request.ts @@ -42,7 +42,7 @@ export const isGrpcRequest = (model: Pick): model is GrpcRequ model.type === type ); -export const isGrpcRequestId = (id: string | null) => ( +export const isGrpcRequestId = (id?: string | null) => ( id?.startsWith(`${prefix}_`) ); diff --git a/packages/insomnia/src/models/request-group.ts b/packages/insomnia/src/models/request-group.ts index ae7eab3f50e..509eb6b10cb 100644 --- a/packages/insomnia/src/models/request-group.ts +++ b/packages/insomnia/src/models/request-group.ts @@ -96,4 +96,4 @@ export async function duplicate(requestGroup: RequestGroup, patch: Partial id.startsWith(prefix); +export const isRequestGroupId = (id?: string | null) => id?.startsWith(prefix); diff --git a/packages/insomnia/src/models/request.ts b/packages/insomnia/src/models/request.ts index 3168669b18e..3c65991e12e 100644 --- a/packages/insomnia/src/models/request.ts +++ b/packages/insomnia/src/models/request.ts @@ -273,7 +273,7 @@ export const isRequest = (model: Pick): model is Request => ( model.type === type ); -export const isRequestId = (id: string | null) => ( +export const isRequestId = (id?: string | null) => ( id?.startsWith(`${prefix}_`) ); diff --git a/packages/insomnia/src/models/websocket-request.ts b/packages/insomnia/src/models/websocket-request.ts index 285c98c0359..e19862a1ca4 100644 --- a/packages/insomnia/src/models/websocket-request.ts +++ b/packages/insomnia/src/models/websocket-request.ts @@ -33,7 +33,7 @@ export const isWebSocketRequest = (model: Pick): model is Web model.type === type ); -export const isWebSocketRequestId = (id: string | null) => ( +export const isWebSocketRequestId = (id?: string | null) => ( id?.startsWith(`${prefix}_`) ); diff --git a/packages/insomnia/src/ui/components/panes/request-group-pane.tsx b/packages/insomnia/src/ui/components/panes/request-group-pane.tsx new file mode 100644 index 00000000000..35de9969c24 --- /dev/null +++ b/packages/insomnia/src/ui/components/panes/request-group-pane.tsx @@ -0,0 +1,12 @@ +import React, { FC } from 'react'; +import { useRouteLoaderData } from 'react-router-dom'; + +import { RequestGroupLoaderData } from '../../routes/request-group'; + +export const RequestGroupPane: FC = () => { + const { activeRequestGroup } = useRouteLoaderData('request-group/:requestGroupId') as RequestGroupLoaderData; + + return ( +
test{activeRequestGroup.name}
+ ); +}; diff --git a/packages/insomnia/src/ui/index.tsx b/packages/insomnia/src/ui/index.tsx index 8eff5682f7b..6c756efef39 100644 --- a/packages/insomnia/src/ui/index.tsx +++ b/packages/insomnia/src/ui/index.tsx @@ -346,6 +346,15 @@ async function renderApp() { await import('./routes/actions') ).reorderCollectionAction(...args), }, + { + path: 'request-group/:requestGroupId', + id: 'request-group/:requestGroupId', + loader: async (...args) => + (await import('./routes/request-group')).loader( + ...args, + ), + element: , + }, { path: 'request/:requestId', id: 'request/:requestId', diff --git a/packages/insomnia/src/ui/routes/debug.tsx b/packages/insomnia/src/ui/routes/debug.tsx index 02a9a74f329..a6e6d69a7b2 100644 --- a/packages/insomnia/src/ui/routes/debug.tsx +++ b/packages/insomnia/src/ui/routes/debug.tsx @@ -48,7 +48,7 @@ import { isRequestId, Request, } from '../../models/request'; -import { isRequestGroup, RequestGroup } from '../../models/request-group'; +import { isRequestGroup, isRequestGroupId, RequestGroup } from '../../models/request-group'; import { getByParentId as getRequestMetaByParentId } from '../../models/request-meta'; import { isWebSocketRequest, @@ -76,6 +76,7 @@ import { WorkspaceEnvironmentsEditModal } from '../components/modals/workspace-e import { GrpcRequestPane } from '../components/panes/grpc-request-pane'; import { GrpcResponsePane } from '../components/panes/grpc-response-pane'; import { PlaceholderRequestPane } from '../components/panes/placeholder-request-pane'; +import { RequestGroupPane } from '../components/panes/request-group-pane'; import { RequestPane } from '../components/panes/request-pane'; import { ResponsePane } from '../components/panes/response-pane'; import { getMethodShortHand } from '../components/tags/method-tag'; @@ -123,7 +124,7 @@ const INITIAL_GRPC_REQUEST_STATE = { methods: [], }; export const loader: LoaderFunction = async ({ params }) => { - if (!params.requestId) { + if (!params.requestId && !params.requestGroupId) { const { projectId, workspaceId, organizationId } = params; invariant(workspaceId, 'Workspace ID is required'); invariant(projectId, 'Project ID is required'); @@ -179,12 +180,14 @@ export const Debug: FC = () => { const [isPasteCurlModalOpen, setPasteCurlModalOpen] = useState(false); const [pastedCurl, setPastedCurl] = useState(''); - const { organizationId, projectId, workspaceId, requestId } = useParams() as { + const { organizationId, projectId, workspaceId, requestId, requestGroupId } = useParams() as { organizationId: string; projectId: string; workspaceId: string; - requestId: string; + requestId?: string; + requestGroupId?: string; }; + console.log('debug', { requestId, requestGroupId }); const [grpcStates, setGrpcStates] = useState( grpcRequests.map(r => ({ requestId: r._id, @@ -1020,6 +1023,7 @@ export const Debug: FC = () => { onSingleClick={() => { if (item && isRequestGroup(item.doc)) { groupMetaPatcher(item.doc._id, { collapsed: !item.collapsed }); + navigate(`/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/debug/request-group/${item.doc._id}?${searchParams.toString()}`); } else { navigate( `/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/debug/request/${item.doc._id}?${searchParams.toString()}` @@ -1072,6 +1076,8 @@ export const Debug: FC = () => { ); if (item && isRequestGroup(item.doc)) { groupMetaPatcher(value, { collapsed: !item.collapsed }); + navigate(`/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/debug/request-group/${item.doc._id}?${searchParams.toString()}`); + } else { navigate( `/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/debug/request/${value}?${searchParams.toString()}` @@ -1142,6 +1148,8 @@ export const Debug: FC = () => { onSingleClick={() => { if (item && isRequestGroup(item.doc)) { groupMetaPatcher(item.doc._id, { collapsed: !item.collapsed }); + navigate(`/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/debug/request-group/${item.doc._id}?${searchParams.toString()}`); + } else { navigate( `/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/debug/request/${item.doc._id}?${searchParams.toString()}` @@ -1215,6 +1223,9 @@ export const Debug: FC = () => { {workspaceId ? ( + {isRequestGroupId(requestGroupId) && ( + + )} {isGrpcRequestId(requestId) && grpcState && ( { }} /> )} - {!requestId && } + {Boolean(!requestId && !requestGroupId) && } {isRequestSettingsModalOpen && activeRequest && ( => { + const { organizationId, projectId, requestGroupId, workspaceId } = params; + invariant(requestGroupId, 'Request ID is required'); + invariant(workspaceId, 'Workspace ID is required'); + invariant(projectId, 'Project ID is required'); + const activeRequestGroup = await models.requestGroup.getById(requestGroupId); + console.log('req group loader', requestGroupId); + if (!activeRequestGroup) { + throw redirect(`/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/debug`); + } + + return { + activeRequestGroup, + }; +}; + export const createRequestGroupAction: ActionFunction = async ({ request, params }) => { const { workspaceId } = params; const formData = await request.formData();