Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
- replace-fork
- styling of Link; add rel noopener
- move protocols array out of render function
  • Loading branch information
kkragoth committed Jul 28, 2021
1 parent 847f967 commit 568a4e6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
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 All @@ -53,4 +61,4 @@

.HookName {
color: var(--color-component-name);
}
}
Original file line number Diff line number Diff line change
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,11 +244,14 @@ export default function KeyValue({
displayValue = 'undefined';
}

let shouldDisplayAsLink = false;
let protocolsAllowedAsLinks = ['file:///', 'http://', 'https://', 'vscode://'];

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

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

0 comments on commit 568a4e6

Please sign in to comment.