Skip to content

Commit 7514c6a

Browse files
Piotr Szulczhengjitf
authored andcommitted
Devtools: Display as link if value is in specified protocols (facebook#21964)
1 parent ff99722 commit 7514c6a

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
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;

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

Lines changed: 19 additions & 0 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,6 +244,16 @@ export default function KeyValue({
243244
displayValue = 'undefined';
244245
}
245246

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;
255+
}
256+
246257
children = (
247258
<div
248259
key="root"
@@ -259,6 +270,14 @@ export default function KeyValue({
259270
path={path}
260271
value={value}
261272
/>
273+
) : shouldDisplayValueAsLink ? (
274+
<a
275+
className={styles.Link}
276+
href={value}
277+
target="_blank"
278+
rel="noopener noreferrer">
279+
{displayValue}
280+
</a>
262281
) : (
263282
<span className={styles.Value}>{displayValue}</span>
264283
)}
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)