Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INS-1821] - import/export websocket requests #5122

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/insomnia/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ export const WORKSPACE_ID_KEY = '__WORKSPACE_ID__';
export const BASE_ENVIRONMENT_ID_KEY = '__BASE_ENVIRONMENT_ID__';
export const EXPORT_TYPE_REQUEST = 'request';
export const EXPORT_TYPE_GRPC_REQUEST = 'grpc_request';
export const EXPORT_TYPE_WEBSOCKET_REQUEST = 'websocket_request';
export const EXPORT_TYPE_REQUEST_GROUP = 'request_group';
export const EXPORT_TYPE_UNIT_TEST_SUITE = 'unit_test_suite';
export const EXPORT_TYPE_UNIT_TEST = 'unit_test';
Expand Down
6 changes: 6 additions & 0 deletions packages/insomnia/src/common/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { isRequest } from '../models/request';
import { isRequestGroup } from '../models/request-group';
import { isUnitTest } from '../models/unit-test';
import { isUnitTestSuite } from '../models/unit-test-suite';
import { isWebSocketRequest } from '../models/websocket-request';
import { isWorkspace, Workspace } from '../models/workspace';
import { resetKeys } from '../sync/ignore-keys';
import { SegmentEvent, trackSegmentEvent } from './analytics';
Expand All @@ -28,6 +29,7 @@ import {
EXPORT_TYPE_REQUEST_GROUP,
EXPORT_TYPE_UNIT_TEST,
EXPORT_TYPE_UNIT_TEST_SUITE,
EXPORT_TYPE_WEBSOCKET_REQUEST,
EXPORT_TYPE_WORKSPACE,
getAppVersion,
} from './constants';
Expand Down Expand Up @@ -188,6 +190,7 @@ export async function exportRequestsData(
isUnitTestSuite(d) ||
isUnitTest(d) ||
isRequest(d) ||
isWebSocketRequest(d) ||
isGrpcRequest(d) ||
isRequestGroup(d) ||
isProtoFile(d) ||
Expand Down Expand Up @@ -231,6 +234,9 @@ export async function exportRequestsData(
} else if (isGrpcRequest(d)) {
// @ts-expect-error -- TSCONVERSION maybe this needs to be added to the upstream type?
d._type = EXPORT_TYPE_GRPC_REQUEST;
} else if (isWebSocketRequest(d)) {
// @ts-expect-error -- TSCONVERSION maybe this needs to be added to the upstream type?
d._type = EXPORT_TYPE_WEBSOCKET_REQUEST;
} else if (isProtoFile(d)) {
// @ts-expect-error -- TSCONVERSION maybe this needs to be added to the upstream type?
d._type = EXPORT_TYPE_PROTO_FILE;
Expand Down
1 change: 1 addition & 0 deletions packages/insomnia/src/main/network/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ async function createWebSocketConnection(
elapsedTime: performance.now() - start,
timelinePath,
bodyPath: responseBodyPath,
// NOTE: required for legacy zip workaround
bodyCompression: null,
};
const settings = await models.settings.getOrCreate();
Expand Down
2 changes: 2 additions & 0 deletions packages/insomnia/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EXPORT_TYPE_REQUEST_GROUP,
EXPORT_TYPE_UNIT_TEST,
EXPORT_TYPE_UNIT_TEST_SUITE,
EXPORT_TYPE_WEBSOCKET_REQUEST,
EXPORT_TYPE_WORKSPACE,
} from '../common/constants';
import { generateId, pluralize } from '../common/misc';
Expand Down Expand Up @@ -210,6 +211,7 @@ export async function initModel<T extends BaseModel>(type: string, ...sources: R

export const MODELS_BY_EXPORT_TYPE: Record<string, any> = {
[EXPORT_TYPE_REQUEST]: request,
[EXPORT_TYPE_WEBSOCKET_REQUEST]: websocketRequest,
[EXPORT_TYPE_GRPC_REQUEST]: grpcRequest,
[EXPORT_TYPE_REQUEST_GROUP]: requestGroup,
[EXPORT_TYPE_UNIT_TEST_SUITE]: unitTestSuite,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import React, { FC, SyntheticEvent, useCallback } from 'react';

import { GrpcRequest, isGrpcRequest } from '../../../models/grpc-request';
import type { Request } from '../../../models/request';
import { isRequest, Request } from '../../../models/request';
import { isWebSocketRequest, WebSocketRequest } from '../../../models/websocket-request';
import { GrpcTag } from '../tags/grpc-tag';
import { MethodTag } from '../tags/method-tag';
import { WebSocketTag } from '../tags/websocket-tag';

interface Props {
handleSetItemSelected: (...args: any[]) => any;
isSelected: boolean;
request: Request | GrpcRequest;
request: Request | WebSocketRequest | GrpcRequest;
}

export const RequestRow: FC<Props> = ({
Expand All @@ -27,7 +29,9 @@ export const RequestRow: FC<Props> = ({
<input type="checkbox" checked={isSelected} onChange={onChange} />
</div>
<button className="wide">
{isGrpcRequest(request) ? <GrpcTag /> : <MethodTag method={request.method} />}
{isRequest(request) ? <MethodTag method={request.method} /> : null}
{isGrpcRequest(request) ? <GrpcTag /> : null}
{isWebSocketRequest(request) ? <WebSocketTag /> : null}
<span className="inline-block">{request.name}</span>
</button>
</div>
Expand Down
3 changes: 2 additions & 1 deletion packages/insomnia/src/ui/components/export-requests/tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { FC } from 'react';

import { isGrpcRequest } from '../../../models/grpc-request';
import { isRequest } from '../../../models/request';
import { isWebSocketRequest } from '../../../models/websocket-request';
import type { Node } from '../modals/export-requests-modal';
import { RequestGroupRow } from './request-group-row';
import { RequestRow } from './request-row';
Expand All @@ -18,7 +19,7 @@ export const Tree: FC<Props> = ({ root, handleSetRequestGroupCollapsed, handleSe
return null;
}

if (isRequest(node.doc) || isGrpcRequest(node.doc)) {
if (isRequest(node.doc) || isWebSocketRequest(node.doc) || isGrpcRequest(node.doc)) {
return (
<RequestRow
key={node.doc._id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as models from '../../../models';
import { GrpcRequest, isGrpcRequest } from '../../../models/grpc-request';
import { isRequest, Request } from '../../../models/request';
import { isRequestGroup, RequestGroup } from '../../../models/request-group';
import { isWebSocketRequest, WebSocketRequest } from '../../../models/websocket-request';
import { RootState } from '../../redux/modules';
import { exportRequestsToFile } from '../../redux/modules/global';
import { selectSidebarChildren } from '../../redux/sidebar-selectors';
Expand All @@ -18,7 +19,7 @@ import { ModalHeader } from '../base/modal-header';
import { Tree } from '../export-requests/tree';

export interface Node {
doc: Request | GrpcRequest | RequestGroup;
doc: Request | WebSocketRequest | GrpcRequest | RequestGroup;
children: Node[];
collapsed: boolean;
totalRequests: number;
Expand Down Expand Up @@ -67,7 +68,7 @@ export class ExportRequestsModalClass extends PureComponent<Props, State> {
}

getSelectedRequestIds(node: Node): string[] {
const docIsRequest = isRequest(node.doc) || isGrpcRequest(node.doc);
const docIsRequest = isRequest(node.doc) || isWebSocketRequest(node.doc) || isGrpcRequest(node.doc);

if (docIsRequest && node.selectedRequests === node.totalRequests) {
return [node.doc._id];
Expand Down Expand Up @@ -117,7 +118,7 @@ export class ExportRequestsModalClass extends PureComponent<Props, State> {
let totalRequests = children
.map(child => child.totalRequests)
.reduce((acc, totalRequests) => acc + totalRequests, 0);
const docIsRequest = isRequest(item.doc) || isGrpcRequest(item.doc);
const docIsRequest = isRequest(item.doc) || isWebSocketRequest(item.doc) || isGrpcRequest(item.doc);

if (docIsRequest) {
totalRequests++;
Expand Down