Skip to content

Commit

Permalink
Devtools: Display as link if value is in specified protocols (faceboo…
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr Szulc authored and zhengjitf committed Apr 15, 2022
1 parent ff99722 commit 7514c6a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Expand Up @@ -32,6 +32,14 @@
flex: 1;
}

.Link {
color: var(--color-link);
white-space: pre;
overflow: hidden;
text-overflow: ellipsis;
flex: 1;
}

.None {
color: var(--color-dimmer);
font-style: italic;
Expand Down
Expand Up @@ -24,6 +24,7 @@ import styles from './KeyValue.css';
import Button from 'react-devtools-shared/src/devtools/views/Button';
import ButtonIcon from 'react-devtools-shared/src/devtools/views/ButtonIcon';
import {InspectedElementContext} from './InspectedElementContext';
import {PROTOCOLS_SUPPORTED_AS_LINKS_IN_KEY_VALUE} from './constants';

import type {InspectedElement} from './types';
import type {Element} from 'react-devtools-shared/src/devtools/views/Components/types';
Expand Down Expand Up @@ -243,6 +244,16 @@ export default function KeyValue({
displayValue = 'undefined';
}

let shouldDisplayValueAsLink = false;
if (
dataType === 'string' &&
PROTOCOLS_SUPPORTED_AS_LINKS_IN_KEY_VALUE.some(protocolPrefix =>
value.startsWith(protocolPrefix),
)
) {
shouldDisplayValueAsLink = true;
}

children = (
<div
key="root"
Expand All @@ -259,6 +270,14 @@ export default function KeyValue({
path={path}
value={value}
/>
) : shouldDisplayValueAsLink ? (
<a
className={styles.Link}
href={value}
target="_blank"
rel="noopener noreferrer">
{displayValue}
</a>
) : (
<span className={styles.Value}>{displayValue}</span>
)}
Expand Down
@@ -0,0 +1,6 @@
export const PROTOCOLS_SUPPORTED_AS_LINKS_IN_KEY_VALUE = [
'file:///',
'http://',
'https://',
'vscode://',
];

0 comments on commit 7514c6a

Please sign in to comment.