Skip to content

Commit f866c68

Browse files
committed
Allow collapsing the entire request/response header section
1 parent 9af94d1 commit f866c68

File tree

5 files changed

+67
-25
lines changed

5 files changed

+67
-25
lines changed

src/components/common/collapsible-section.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as _ from 'lodash';
22
import * as React from 'react';
3-
import { observer } from 'mobx-react';
3+
import { inject, observer } from 'mobx-react';
44
import { observable, action } from 'mobx';
55

66
import { styled, css } from "../../styles";
7+
import { CollapsibleSectionKey, UiStore } from '../../model/ui/ui-store';
8+
79
import { isReactElement } from '../../util/ui';
810
import { Icon, IconProp } from '../../icons';
911

@@ -13,6 +15,9 @@ interface CollapsibleSectionProps {
1315
withinGrid?: boolean;
1416
prefixTrigger?: boolean;
1517
contentName: string;
18+
19+
collapsePersistKey?: CollapsibleSectionKey;
20+
uiStore?: UiStore;
1621
}
1722

1823
const CollapsibleSectionWrapper = styled.section`
@@ -62,14 +67,17 @@ const SummaryAsSpacer = styled.div`
6267
* This component also works if there is no body provided - it falls back to just
6368
* showing the summary without the expand/collapse toggle.
6469
*/
70+
@inject('uiStore')
6571
@observer
6672
export class CollapsibleSection extends React.Component<CollapsibleSectionProps> {
6773

6874
static idCounter = 0;
6975
id = `collapsible-${CollapsibleSection.idCounter++}`;
7076

7177
@observable
72-
open = false;
78+
open = this.props.collapsePersistKey
79+
? !!this.props.uiStore?.collapsibleSectionStates[this.props.collapsePersistKey]
80+
: false;
7381

7482
render() {
7583
const {
@@ -150,6 +158,10 @@ export class CollapsibleSection extends React.Component<CollapsibleSectionProps>
150158
toggleOpen(e: React.SyntheticEvent) {
151159
e.preventDefault();
152160
this.open = !this.open;
161+
162+
if (this.props.collapsePersistKey) {
163+
this.props.uiStore!.collapsibleSectionStates[this.props.collapsePersistKey] = this.open;
164+
}
153165
}
154166
}
155167

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,6 @@ const HeaderDocsLink = styled(DocsLink)`
143143
margin-top: 10px;
144144
`;
145145

146-
const PseudoHeadersHiddenMessage = styled.span`
147-
grid-column: 2 / -1;
148-
font-style: italic;
149-
`;
150-
151-
const PseudoHeadersContent = styled(CollapsibleSectionBody)`
152-
line-height: 1.3;
153-
`;
154-
155146
const getHeaderDescription = (
156147
name: string,
157148
value: string,
@@ -223,3 +214,12 @@ export const HeaderDetails = inject('accountStore')(observer((props: {
223214
}) }
224215
</HeadersGrid>;
225216
}));
217+
218+
export const HeaderHeadingContainer = styled.div<{ open?: boolean }>`
219+
display: flex;
220+
align-items: baseline;
221+
justify-content: flex-start;
222+
${p => p.open !== true && `
223+
margin-bottom: -10px;
224+
`}
225+
`;

src/components/view/http/http-request-card.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
import { DocsLink } from '../../common/docs-link';
2727
import { SourceIcon } from '../../common/source-icon';
2828
import { HttpVersionPill } from '../../common/http-version-pill';
29-
import { HeaderDetails } from './header-details';
29+
import { HeaderDetails, HeaderHeadingContainer } from './header-details';
3030
import { UrlBreakdown } from '../url-breakdown';
3131
import { StepClassKey } from '../../../model/rules/rules';
3232
import { MatchedRulePill, shouldShowRuleDetails } from './matched-rule-pill';
@@ -82,12 +82,20 @@ const RawRequestDetails = (p: {
8282
}
8383
</CollapsibleSection>
8484

85-
<ContentLabelBlock>Headers</ContentLabelBlock>
86-
<HeaderDetails
87-
httpVersion={p.httpVersion}
88-
headers={p.request.rawHeaders}
89-
requestUrl={p.request.parsedUrl}
90-
/>
85+
<CollapsibleSection
86+
contentName='Headers'
87+
collapsePersistKey='httpRequestHeaders'
88+
>
89+
<HeaderHeadingContainer>
90+
<ContentLabelBlock>Headers</ContentLabelBlock>
91+
</HeaderHeadingContainer>
92+
93+
<HeaderDetails
94+
httpVersion={p.httpVersion}
95+
headers={p.request.rawHeaders}
96+
requestUrl={p.request.parsedUrl}
97+
/>
98+
</CollapsibleSection>
9199
</div>;
92100
}
93101

src/components/view/http/http-response-card.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
CollapsibleCardHeading
1717
} from '../../common/card';
1818
import { Pill } from '../../common/pill';
19-
import { HeaderDetails } from './header-details';
19+
import { HeaderDetails, HeaderHeadingContainer } from './header-details';
2020
import {
2121
} from '../../common/card';
2222
import {
@@ -86,12 +86,20 @@ export const HttpResponseCard = observer((props: HttpResponseCardProps) => {
8686
}
8787
</CollapsibleSection>
8888

89-
<ContentLabelBlock>Headers</ContentLabelBlock>
90-
<HeaderDetails
91-
httpVersion={httpVersion}
92-
headers={response.rawHeaders}
93-
requestUrl={requestUrl}
94-
/>
89+
<CollapsibleSection
90+
contentName='Headers'
91+
collapsePersistKey='httpResponseHeaders'
92+
>
93+
<HeaderHeadingContainer>
94+
<ContentLabelBlock>Headers</ContentLabelBlock>
95+
</HeaderHeadingContainer>
96+
97+
<HeaderDetails
98+
httpVersion={httpVersion}
99+
headers={response.rawHeaders}
100+
requestUrl={requestUrl}
101+
/>
102+
</CollapsibleSection>
95103
</div>
96104
</CollapsibleCard>;
97105
});

src/model/ui/ui-store.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ const EXPANDABLE_VIEW_CARD_KEYS = [
5050
] as const;
5151
export type ExpandableViewCardKey = typeof EXPANDABLE_VIEW_CARD_KEYS[number];
5252

53+
const COLLAPSIBLE_SECTION_KEYS = [
54+
'httpRequestHeaders',
55+
'httpResponseHeaders'
56+
] as const;
57+
export type CollapsibleSectionKey = typeof COLLAPSIBLE_SECTION_KEYS[number];
58+
5359
const isExpandableViewCard = (key: any): key is ExpandableViewCardKey =>
5460
EXPANDABLE_VIEW_CARD_KEYS.includes(key);
5561

@@ -256,6 +262,14 @@ export class UiStore {
256262
@observable
257263
expandedViewCard: ExpandableViewCardKey | undefined;
258264

265+
// Store the state for various persistently collapsible sections here - true
266+
// is open, false is collapsed.
267+
@observable
268+
readonly collapsibleSectionStates: { [key in CollapsibleSectionKey]: boolean } = {
269+
'httpRequestHeaders': true,
270+
'httpResponseHeaders': true
271+
};
272+
259273
@observable
260274
viewScrollPosition: number | 'end' = 'end';
261275

0 commit comments

Comments
 (0)