Skip to content

Commit 1082622

Browse files
committed
Add a 'jump to view' button on Send
1 parent e175202 commit 1082622

File tree

3 files changed

+60
-16
lines changed

3 files changed

+60
-16
lines changed

src/components/send/response-pane.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ import { SentResponseError } from './sent-response-error';
2424
export class ResponsePane extends React.Component<{
2525
uiStore?: UiStore,
2626
accountStore?: AccountStore,
27+
editorNode: portals.HtmlPortalNode<typeof ContainerSizedEditor>,
2728

2829
requestInput: RequestInput,
2930
exchange: HttpExchange | undefined,
30-
abortRequest: (() => void) | undefined,
31-
editorNode: portals.HtmlPortalNode<typeof ContainerSizedEditor>
31+
32+
abortRequest?: () => void,
33+
showRequestOnViewPage?: () => void
3234
}> {
3335

3436
get cardProps() {
@@ -53,12 +55,13 @@ export class ResponsePane extends React.Component<{
5355
}
5456

5557
renderSuccessfulResponse(exchange: SuccessfulExchange) {
56-
const { uiStore, editorNode } = this.props;
58+
const { uiStore, editorNode, showRequestOnViewPage } = this.props;
5759
const response = exchange.response;
5860

5961
return <>
6062
<ResponseStatusSection
6163
exchange={exchange}
64+
showRequestOnViewPage={showRequestOnViewPage}
6265
theme={uiStore!.theme}
6366
/>
6467
<SentResponseHeaderSection
@@ -78,7 +81,7 @@ export class ResponsePane extends React.Component<{
7881
}
7982

8083
renderFailedResponse(exchange: CompletedExchange) {
81-
const { uiStore } = this.props;
84+
const { uiStore, showRequestOnViewPage } = this.props;
8285

8386
const errorType = tagsToErrorType(exchange.tags);
8487

@@ -92,6 +95,7 @@ export class ResponsePane extends React.Component<{
9295
<FailedResponseStatusSection
9396
exchange={exchange}
9497
errorType={errorType ?? 'unknown'}
98+
showRequestOnViewPage={showRequestOnViewPage}
9599
theme={uiStore!.theme}
96100
/>
97101
<SentResponseError
@@ -112,9 +116,9 @@ export class ResponsePane extends React.Component<{
112116

113117
return <>
114118
<PendingResponseStatusSection
115-
theme={uiStore!.theme}
116119
timingEvents={exchange?.timingEvents}
117120
abortRequest={abortRequest}
121+
theme={uiStore!.theme}
118122
/>
119123
<PendingResponseHeaderSection
120124
{...this.cardProps.responseHeaders}

src/components/send/send-page.tsx

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as portals from 'react-reverse-portal';
44

55
import { styled } from '../../styles';
66
import { useHotkeys } from '../../util/ui';
7+
import { WithInjected } from '../../types';
78

89
import { SendStore } from '../../model/send/send-store';
910

@@ -47,8 +48,9 @@ const SendPageKeyboardShortcuts = (props: {
4748

4849
@inject('sendStore')
4950
@observer
50-
export class SendPage extends React.Component<{
51-
sendStore?: SendStore
51+
class SendPage extends React.Component<{
52+
sendStore: SendStore
53+
navigate: (path: string) => void
5254
}> {
5355

5456
private requestEditorNode = portals.createHtmlPortalNode<typeof ContainerSizedEditor>({
@@ -62,11 +64,20 @@ export class SendPage extends React.Component<{
6264
const {
6365
sendRequest,
6466
selectedRequest
65-
} = this.props.sendStore!;
67+
} = this.props.sendStore;
6668

6769
sendRequest(selectedRequest);
6870
};
6971

72+
private showRequestOnViewPage = () => {
73+
const { sentExchange } = this.props.sendStore.selectedRequest;
74+
if (!sentExchange) return;
75+
76+
const { navigate } = this.props;
77+
78+
navigate(`/view/${sentExchange.id}`);
79+
}
80+
7081
render() {
7182
const {
7283
sendRequests,
@@ -75,7 +86,7 @@ export class SendPage extends React.Component<{
7586
deleteRequest,
7687
selectedRequest,
7788
addRequestInput
78-
} = this.props.sendStore!;
89+
} = this.props.sendStore;
7990

8091
return <SendPageContainer>
8192
<SendTabs
@@ -114,8 +125,10 @@ export class SendPage extends React.Component<{
114125
<ResponsePane
115126
requestInput={selectedRequest.request}
116127
exchange={selectedRequest.sentExchange}
117-
abortRequest={
118-
selectedRequest.pendingSend?.abort
128+
abortRequest={selectedRequest.pendingSend?.abort}
129+
showRequestOnViewPage={selectedRequest.sentExchange
130+
? this.showRequestOnViewPage
131+
: undefined
119132
}
120133
editorNode={this.responseEditorNode}
121134
/>
@@ -131,4 +144,11 @@ export class SendPage extends React.Component<{
131144
</SendPageContainer>;
132145
}
133146

134-
}
147+
}
148+
149+
// Annoying cast required to handle the store prop nicely in our types
150+
const InjectedSendPage = SendPage as unknown as WithInjected<
151+
typeof SendPage,
152+
'sendStore' | 'navigate'
153+
>;
154+
export { InjectedSendPage as SendPage };

src/components/send/sent-response-status.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { observer } from 'mobx-react-lite';
44

55
import { TimingEvents } from '../../types';
66
import { Theme, styled } from '../../styles';
7+
import { Icon } from '../../icons';
78
import { getReadableSize } from '../../util/buffer';
89

910
import { getStatusColor } from '../../model/events/categorization';
@@ -14,7 +15,7 @@ import { ErrorType } from '../../model/http/error-types';
1415
import { SendCardSection } from './send-card-section';
1516
import { Pill, PillButton } from '../common/pill';
1617
import { DurationPill } from '../common/duration-pill';
17-
import { Icon } from '../../icons';
18+
import { IconButton } from '../common/icon-button';
1819

1920
const ResponseStatusSectionCard = styled(SendCardSection)`
2021
padding-top: 7px;
@@ -31,8 +32,19 @@ const ResponseStatusSectionCard = styled(SendCardSection)`
3132
}
3233
`;
3334

35+
const ShowRequestButton = styled(IconButton).attrs(() => ({
36+
icon: ['fas', 'search'],
37+
title: 'Jump to this request on the View page'
38+
}))`
39+
padding: 3px 10px;
40+
margin-right: -10px;
41+
42+
margin-left: auto;
43+
`;
44+
3445
export const ResponseStatusSection = (props: {
3546
exchange: SuccessfulExchange,
47+
showRequestOnViewPage?: () => void,
3648
theme: Theme
3749
}) => {
3850
const response = props.exchange.response;
@@ -53,6 +65,9 @@ export const ResponseStatusSection = (props: {
5365
<Pill title="The size of the raw encoded response body">
5466
{ getReadableSize(response.body.encoded.byteLength) }
5567
</Pill>
68+
{ props.showRequestOnViewPage &&
69+
<ShowRequestButton onClick={props.showRequestOnViewPage} />
70+
}
5671
</header>
5772
</ResponseStatusSectionCard>;
5873
}
@@ -65,9 +80,9 @@ const AbortButton = styled(PillButton)`
6580
`;
6681

6782
export const PendingResponseStatusSection = observer((props: {
68-
theme: Theme,
6983
timingEvents?: Partial<TimingEvents>,
70-
abortRequest?: () => void
84+
abortRequest?: () => void,
85+
theme: Theme,
7186
}) => {
7287
return <ResponseStatusSectionCard
7388
className='ignores-expanded' // This always shows, even if something is expanded
@@ -97,7 +112,8 @@ export const PendingResponseStatusSection = observer((props: {
97112

98113
export const FailedResponseStatusSection = (props: {
99114
exchange: CompletedExchange,
100-
errorType: ErrorType
115+
errorType: ErrorType,
116+
showRequestOnViewPage?: () => void,
101117
theme: Theme
102118
}) => {
103119
return <ResponseStatusSectionCard
@@ -113,6 +129,10 @@ export const FailedResponseStatusSection = (props: {
113129
Failed: { _.startCase(props.errorType) }
114130
</Pill>
115131
<DurationPill timingEvents={props.exchange.timingEvents} />
132+
133+
{ props.showRequestOnViewPage &&
134+
<ShowRequestButton onClick={props.showRequestOnViewPage} />
135+
}
116136
</header>
117137
</ResponseStatusSectionCard>;
118138
}

0 commit comments

Comments
 (0)