Skip to content

Commit

Permalink
can navigate to folder
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkav committed May 2, 2024
1 parent 5fb3fc6 commit 78fa6b2
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 10 deletions.
1 change: 1 addition & 0 deletions packages/insomnia/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
data:
;
connect-src
'self'
insomnia-event-source:
https:
http:
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/models/grpc-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const isGrpcRequest = (model: Pick<BaseModel, 'type'>): model is GrpcRequ
model.type === type
);

export const isGrpcRequestId = (id: string | null) => (
export const isGrpcRequestId = (id?: string | null) => (
id?.startsWith(`${prefix}_`)
);

Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/models/request-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ export async function duplicate(requestGroup: RequestGroup, patch: Partial<Reque
});
}

export const isRequestGroupId = (id: string) => id.startsWith(prefix);
export const isRequestGroupId = (id?: string | null) => id?.startsWith(prefix);
2 changes: 1 addition & 1 deletion packages/insomnia/src/models/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export const isRequest = (model: Pick<BaseModel, 'type'>): model is Request => (
model.type === type
);

export const isRequestId = (id: string | null) => (
export const isRequestId = (id?: string | null) => (
id?.startsWith(`${prefix}_`)
);

Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/models/websocket-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const isWebSocketRequest = (model: Pick<BaseModel, 'type'>): model is Web
model.type === type
);

export const isWebSocketRequestId = (id: string | null) => (
export const isWebSocketRequestId = (id?: string | null) => (
id?.startsWith(`${prefix}_`)
);

Expand Down
12 changes: 12 additions & 0 deletions packages/insomnia/src/ui/components/panes/request-group-pane.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div>test{activeRequestGroup.name}</div>
);
};
9 changes: 9 additions & 0 deletions packages/insomnia/src/ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,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: <Outlet />,
},
{
path: 'request/:requestId',
id: 'request/:requestId',
Expand Down
21 changes: 16 additions & 5 deletions packages/insomnia/src/ui/routes/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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<GrpcRequestState[]>(
grpcRequests.map(r => ({
requestId: r._id,
Expand Down Expand Up @@ -1018,6 +1021,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()}`
Expand Down Expand Up @@ -1070,6 +1074,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()}`
Expand Down Expand Up @@ -1140,6 +1146,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()}`
Expand Down Expand Up @@ -1213,6 +1221,9 @@ export const Debug: FC = () => {
<Panel id="pane-one" className='pane-one theme--pane'>
{workspaceId ? (
<ErrorBoundary showAlert>
{isRequestGroupId(requestGroupId) && (
<RequestGroupPane />
)}
{isGrpcRequestId(requestId) && grpcState && (
<GrpcRequestPane
grpcState={grpcState}
Expand All @@ -1234,7 +1245,7 @@ export const Debug: FC = () => {
}}
/>
)}
{!requestId && <PlaceholderRequestPane />}
{Boolean(!requestId && !requestGroupId) && <PlaceholderRequestPane />}
{isRequestSettingsModalOpen && activeRequest && (
<RequestSettingsModal
request={activeRequest}
Expand Down
21 changes: 20 additions & 1 deletion packages/insomnia/src/ui/routes/request-group.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import { ActionFunction } from 'react-router-dom';
import { ActionFunction, LoaderFunction, redirect } from 'react-router-dom';

import * as models from '../../models';
import { RequestGroup } from '../../models/request-group';
import { RequestGroupMeta } from '../../models/request-group-meta';
import { invariant } from '../../utils/invariant';

export interface RequestGroupLoaderData {
activeRequestGroup: RequestGroup;
}
export const loader: LoaderFunction = async ({ params }): Promise<RequestGroupLoaderData> => {
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();
Expand Down

0 comments on commit 78fa6b2

Please sign in to comment.