Skip to content

Commit 56ca614

Browse files
committed
Switch to using ... marker for long headers as expand/collapse button
Previously we used the +/- for the whole row (which shows the docs) but this gives a bit more control, and seems to be what people expect (a few reports of users confused by previous behaviour). This PR also increases the length where this kicks in and makes the gradient more obvious to try to make it clearer what's going on.
1 parent f84e3c8 commit 56ca614

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

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

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

55
import { styled } from '../../../styles';
66
import { RawHeaders } from '../../../types';
7+
import { Icon } from '../../../icons';
78

89
import { getHeaderDocs } from '../../../model/http/http-docs';
910
import { AccountStore } from '../../../model/account/account-store';
@@ -15,7 +16,7 @@ import {
1516
CollapsibleSectionSummary,
1617
CollapsibleSectionBody
1718
} from '../../common/collapsible-section';
18-
import { Pill } from '../../common/pill';
19+
import { PillButton } from '../../common/pill';
1920

2021
import { CookieHeaderDescription } from './set-cookie-header-description';
2122
import { UserAgentHeaderDescription } from './user-agent-header-description';
@@ -37,7 +38,7 @@ const HeaderKeyValueContainer = styled(CollapsibleSectionSummary)`
3738
line-height: 1.1;
3839
`;
3940

40-
const LONG_HEADER_LIMIT = 200;
41+
const LONG_HEADER_LIMIT = 500;
4142

4243
const HeaderKeyValue = (p: {
4344
headerKey: string,
@@ -48,17 +49,34 @@ const HeaderKeyValue = (p: {
4849
open?: boolean,
4950
withinGrid?: boolean
5051
}) => {
51-
const longValue = p.headerValue.length > LONG_HEADER_LIMIT;
52+
const isLongValue = p.headerValue.length > LONG_HEADER_LIMIT;
53+
const [isExpanded, setExpanded] = React.useState(false);
54+
55+
const expand = React.useCallback(() => setExpanded(true), [setExpanded]);
56+
const collapse = React.useCallback(() => setExpanded(false), [setExpanded]);
5257

5358
return <HeaderKeyValueContainer open={p.open} withinGrid={p.withinGrid}>
5459
{ p.children }
5560
<HeaderName>{ p.headerKey }: </HeaderName>
56-
{
57-
p.open || !longValue
61+
{ !isLongValue
5862
? <span>{ p.headerValue }</span>
59-
: <LongHeaderValue>
63+
: isExpanded
64+
? <span>
65+
{ p.headerValue }
66+
<LongHeaderButton
67+
title='Collapse this large header value'
68+
onClick={collapse}
69+
>
70+
<Icon icon={['fas', 'minus']} />
71+
</LongHeaderButton>
72+
</span>
73+
: // Collapsed long header:
74+
<LongHeaderValue>
6075
{ p.headerValue.slice(0, LONG_HEADER_LIMIT - 10) }
61-
<LongHeaderMarker>...</LongHeaderMarker>
76+
<LongHeaderButton
77+
title='Expand to show the full contents of this large header value'
78+
onClick={expand}
79+
>...</LongHeaderButton>
6280
</LongHeaderValue>
6381
}
6482
</HeaderKeyValueContainer>;
@@ -69,7 +87,7 @@ const LongHeaderValue = styled.span`
6987
7088
:after {
7189
content: '';
72-
background-image: linear-gradient(to bottom, transparent, transparent 75%, ${p => p.theme.mainBackground});
90+
background-image: linear-gradient(to bottom, transparent, transparent 60%, ${p => p.theme.mainBackground});
7391
position: absolute;
7492
top: 0;
7593
left: 0;
@@ -78,7 +96,7 @@ const LongHeaderValue = styled.span`
7896
}
7997
`;
8098

81-
const LongHeaderMarker = styled(Pill)`
99+
const LongHeaderButton = styled(PillButton)`
82100
position: relative;
83101
z-index: 1;
84102
@@ -88,10 +106,6 @@ const LongHeaderMarker = styled(Pill)`
88106
margin-left: 4px;
89107
`;
90108

91-
const ExpansionPlaceholder = styled.span`
92-
display: none;
93-
`;
94-
95109
const HeaderName = styled.span`
96110
margin-right: 10px;
97111
`;
@@ -198,12 +212,6 @@ export const HeaderDetails = inject('accountStore')(observer((props: {
198212
Find out more
199213
</HeaderDocsLink> }
200214
</HeaderDescriptionContainer> }
201-
202-
{ !description && value.length > LONG_HEADER_LIMIT &&
203-
// For long headers, we add a child (so that the expand button is shown) even
204-
// if there's no description, so you can expand to see everything.
205-
<ExpansionPlaceholder />
206-
}
207215
</CollapsibleSection>;
208216
}) }
209217
</HeadersGrid>;

0 commit comments

Comments
 (0)