Skip to content

Commit 4b9b830

Browse files
authored
Merge pull request #159 from ceifa/cleanup-messages-button
add cleanup websocket messages button
2 parents 7c9969b + ac69e11 commit 4b9b830

File tree

5 files changed

+32
-10
lines changed

5 files changed

+32
-10
lines changed

src/components/view/http/http-details-pane.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { action, computed } from 'mobx';
44
import { observer, inject } from 'mobx-react';
55
import * as portals from 'react-reverse-portal';
66

7-
import { CollectedEvent, HtkResponse, HttpExchange, HttpExchangeView } from '../../../types';
7+
import { CollectedEvent, HtkResponse, HttpExchangeView } from '../../../types';
88
import { styled } from '../../../styles';
99
import { logError } from '../../../errors';
1010

@@ -15,7 +15,7 @@ import { ApiExchange } from '../../../model/api/api-interfaces';
1515
import { buildRuleFromRequest } from '../../../model/rules/rule-creation';
1616
import { findItem } from '../../../model/rules/rules-structure';
1717
import { HtkRule, getRulePartKey } from '../../../model/rules/rules';
18-
import { WebSocketStream } from '../../../model/websockets/websocket-stream';
18+
import { WebSocketView } from '../../../model/websockets/websocket-views';
1919
import { tagsToErrorType } from '../../../model/http/error-types';
2020

2121
import { PaneScrollContainer } from '../view-details-pane';
@@ -448,7 +448,7 @@ export class HttpDetailsPane extends React.Component<{
448448
/>;
449449
}
450450

451-
private renderWebSocketMessages(exchange: WebSocketStream) {
451+
private renderWebSocketMessages(exchange: WebSocketView) {
452452
const urlParts = exchange.request.url.split('/');
453453
const domain = urlParts[2].split(':')[0];
454454
const baseName = urlParts.length >= 2 ? urlParts[urlParts.length - 1] : undefined;
@@ -469,6 +469,7 @@ export class HttpDetailsPane extends React.Component<{
469469
isPaidUser={this.props.accountStore!.isPaidUser}
470470
filenamePrefix={filenamePrefix}
471471
messages={exchange.messages}
472+
onClearMessages={this.clearMessages}
472473
/>;
473474
}
474475

@@ -538,4 +539,11 @@ export class HttpDetailsPane extends React.Component<{
538539
exchange.hideErrors = true;
539540
}
540541

542+
@action.bound
543+
private clearMessages() {
544+
const { exchange } = this.props;
545+
if (!exchange.isWebSocket()) return;
546+
exchange.downstream.clearMessages();
547+
}
548+
541549
};

src/components/view/stream-message-list-card.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ export class StreamMessageListCard extends React.Component<ExpandableCardProps &
4343
streamId: string,
4444
streamType: StreamType,
4545
streamLabel?: string,
46-
messages: Array<StreamMessage>,
46+
messages: ReadonlyArray<StreamMessage>,
4747
editorNode: portals.HtmlPortalNode<typeof SelfSizedEditor>
48+
onClearMessages?: () => void,
4849
}> {
4950

5051
@observable
@@ -67,6 +68,7 @@ export class StreamMessageListCard extends React.Component<ExpandableCardProps &
6768
expanded,
6869
onCollapseToggled,
6970
onExpandToggled,
71+
onClearMessages,
7072
ariaLabel
7173
} = this.props;
7274

@@ -92,6 +94,12 @@ export class StreamMessageListCard extends React.Component<ExpandableCardProps &
9294
disabled={!isPaidUser}
9395
onClick={this.exportMessages}
9496
/>
97+
{ onClearMessages &&
98+
<IconButton
99+
icon={['far', 'trash-alt']}
100+
title="Clear all messages"
101+
onClick={onClearMessages}
102+
/> }
95103
</CollapsingButtons>
96104
{ streamLabel && <Pill
97105
color={getSummaryColor('data')}

src/model/events/event-base.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import {
44
FailedTlsConnection,
55
TlsTunnel,
66
HttpExchangeView,
7+
WebSocketView,
78
RTCConnection,
89
RTCDataChannel,
9-
RTCMediaTrack,
10-
WebSocketStream
10+
RTCMediaTrack
1111
} from '../../types';
1212

1313
import { getEventCategory } from './categorization';
@@ -18,7 +18,7 @@ export abstract class HTKEventBase {
1818

1919
// These can be overriden by subclasses to allow easy type narrowing:
2020
isHttp(): this is HttpExchangeView { return false; }
21-
isWebSocket(): this is WebSocketStream { return false; }
21+
isWebSocket(): this is WebSocketView { return false; }
2222

2323
isTlsFailure(): this is FailedTlsConnection { return false; }
2424
isTlsTunnel(): this is TlsTunnel { return false; }

src/model/websockets/websocket-stream.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,15 @@ export class WebSocketStream extends HttpExchange implements WebSocketView {
127127
this.upstream.updateWithRequestHead(params);
128128
}
129129

130-
cleanup() {
131-
super.cleanup();
132-
130+
@action
131+
clearMessages() {
133132
// Clear all websocket message data too
134133
this.messages.forEach(msg => msg.cleanup());
135134
this.messages.length = 0;
136135
}
136+
137+
cleanup() {
138+
super.cleanup();
139+
this.clearMessages();
140+
}
137141
}

src/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import type { HttpExchange, HttpVersion } from './model/http/http-exchange';
3737
import type { HttpExchangeView } from './model/http/http-exchange-views';
3838

3939
import type { WebSocketStream } from './model/websockets/websocket-stream';
40+
import type { WebSocketView } from './model/websockets/websocket-views';
4041
import type { RTCConnection } from './model/webrtc/rtc-connection';
4142
import type { RTCDataChannel } from './model/webrtc/rtc-data-channel';
4243
import type { RTCMediaTrack } from './model/webrtc/rtc-media-track';
@@ -247,6 +248,7 @@ export type {
247248
HttpExchange,
248249
HttpExchangeView,
249250
WebSocketStream,
251+
WebSocketView,
250252
RTCConnection,
251253
RTCDataChannel,
252254
RTCMediaTrack

0 commit comments

Comments
 (0)