Skip to content

Commit f10e134

Browse files
committed
PR fixes
- replace-fork - styling of Link; add rel noopener - move protocols array out of render function
1 parent 847f967 commit f10e134

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

packages/react-devtools-shared/src/devtools/views/Components/KeyValue.css

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
flex: 1;
3333
}
3434

35+
.Link {
36+
color: var(--color-link);
37+
white-space: pre;
38+
overflow: hidden;
39+
text-overflow: ellipsis;
40+
flex: 1;
41+
}
42+
3543
.None {
3644
color: var(--color-dimmer);
3745
font-style: italic;
@@ -53,4 +61,4 @@
5361

5462
.HookName {
5563
color: var(--color-component-name);
56-
}
64+
}

packages/react-devtools-shared/src/devtools/views/Components/KeyValue.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import styles from './KeyValue.css';
2424
import Button from 'react-devtools-shared/src/devtools/views/Button';
2525
import ButtonIcon from 'react-devtools-shared/src/devtools/views/ButtonIcon';
2626
import {InspectedElementContext} from './InspectedElementContext';
27+
import {PROTOCOLS_SUPPORTED_AS_LINKS_IN_KEY_VALUE} from './constants';
2728

2829
import type {InspectedElement} from './types';
2930
import type {Element} from 'react-devtools-shared/src/devtools/views/Components/types';
@@ -243,11 +244,14 @@ export default function KeyValue({
243244
displayValue = 'undefined';
244245
}
245246

246-
let shouldDisplayAsLink = false;
247-
let protocolsAllowedAsLinks = ['file:///', 'http://', 'https://', 'vscode://'];
248-
249-
if (dataType === 'string' && protocolsAllowedAsLinks.some((protocolPrefix) => value.startsWith(protocolPrefix))) {
250-
shouldDisplayAsLink = true;
247+
let shouldDisplayValueAsLink = false;
248+
if (
249+
dataType === 'string' &&
250+
PROTOCOLS_SUPPORTED_AS_LINKS_IN_KEY_VALUE.some(protocolPrefix =>
251+
value.startsWith(protocolPrefix),
252+
)
253+
) {
254+
shouldDisplayValueAsLink = true;
251255
}
252256

253257
children = (
@@ -266,12 +270,16 @@ export default function KeyValue({
266270
path={path}
267271
value={value}
268272
/>
273+
) : shouldDisplayValueAsLink ? (
274+
<a
275+
className={styles.Link}
276+
href={value}
277+
target="_blank"
278+
rel="noopener noreferrer">
279+
{displayValue}
280+
</a>
269281
) : (
270-
(shouldDisplayAsLink) ? (
271-
<a href={value} target="_blank">{displayValue}</a>
272-
) : (
273-
<span className={styles.Value}>{displayValue}</span>
274-
)
282+
<span className={styles.Value}>{displayValue}</span>
275283
)}
276284
</div>
277285
);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const PROTOCOLS_SUPPORTED_AS_LINKS_IN_KEY_VALUE = [
2+
'file:///',
3+
'http://',
4+
'https://',
5+
'vscode://',
6+
];

0 commit comments

Comments
 (0)