Skip to content

Commit

Permalink
Feat:-Added open in editor to appear by default (#26949)
Browse files Browse the repository at this point in the history
Currently the Open in editor just is a placeholder input where the
developer would need to type the whole Vscode file path being shown as a
placeholder, we can make this process a little easier by just already
setting the URL .




https://github.com/facebook/react/assets/72331432/96f43230-6c49-45f7-907c-c99a0d3d8bf7

Earlier it used to be a placeholder describing the URL
<img width="1284" alt="Screenshot 2023-06-14 at 7 55 38 PM"
src="https://github.com/facebook/react/assets/72331432/4e8234ad-e1cd-4b55-8ef8-46dea82a9c7c">


cc @hoxyq

---------

Co-authored-by: Ruslan Lesiutin <rdlesyutin@gmail.com>
Co-authored-by: BIKI <biki@BIKIs-MacBook-Pro.local>
  • Loading branch information
3 people authored Jul 27, 2023
1 parent fdb368d commit 493f72b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 12 deletions.
3 changes: 3 additions & 0 deletions packages/react-devtools-shared/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const SESSION_STORAGE_LAST_SELECTION_KEY =
export const LOCAL_STORAGE_OPEN_IN_EDITOR_URL =
'React::DevTools::openInEditorUrl';

export const LOCAL_STORAGE_OPEN_IN_EDITOR_URL_PRESET =
'React::DevTools::openInEditorUrlPreset';

export const LOCAL_STORAGE_PARSE_HOOK_NAMES_KEY =
'React::DevTools::parseHookNames';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@ export default function InspectedElementWrapper(_: Props): React.Node {
}

const url = new URL(editorURL);
url.href = url.href.replace('{path}', source.fileName);
url.href = url.href.replace('{line}', String(source.lineNumber));
url.href = url.href
.replace('{path}', source.fileName)
.replace('{line}', String(source.lineNumber))
.replace('%7Bpath%7D', source.fileName)
.replace('%7Bline%7D', String(source.lineNumber));
window.open(url);
}, [inspectedElement, editorURL]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
useRef,
useState,
} from 'react';
import {LOCAL_STORAGE_OPEN_IN_EDITOR_URL} from '../../../constants';
import {
LOCAL_STORAGE_OPEN_IN_EDITOR_URL,
LOCAL_STORAGE_OPEN_IN_EDITOR_URL_PRESET,
} from '../../../constants';
import {useLocalStorage, useSubscription} from '../hooks';
import {StoreContext} from '../context';
import Button from '../Button';
Expand Down Expand Up @@ -51,6 +54,8 @@ import type {
RegExpComponentFilter,
} from 'react-devtools-shared/src/types';

const vscodeFilepath = 'vscode://file/{path}:{line}';

export default function ComponentsSettings(_: {}): React.Node {
const store = useContext(StoreContext);
const {parseHookNames, setParseHookNames} = useContext(SettingsContext);
Expand Down Expand Up @@ -83,6 +88,10 @@ export default function ComponentsSettings(_: {}): React.Node {
[setParseHookNames],
);

const [openInEditorURLPreset, setOpenInEditorURLPreset] = useLocalStorage<
'vscode' | 'custom',
>(LOCAL_STORAGE_OPEN_IN_EDITOR_URL_PRESET, 'custom');
const [openInEditorURL, setOpenInEditorURL] = useLocalStorage<string>(
LOCAL_STORAGE_OPEN_IN_EDITOR_URL,
getDefaultOpenInEditorURL(),
Expand Down Expand Up @@ -280,15 +289,32 @@ export default function ComponentsSettings(_: {}): React.Node {

<label className={styles.OpenInURLSetting}>
Open in Editor URL:{' '}
<input
className={styles.Input}
type="text"
placeholder={process.env.EDITOR_URL ?? 'vscode://file/{path}:{line}'}
value={openInEditorURL}
onChange={event => {
setOpenInEditorURL(event.target.value);
}}
/>
<select
className={styles.Select}
value={openInEditorURLPreset}
onChange={({currentTarget}) => {
const selectedValue = currentTarget.value;
setOpenInEditorURLPreset(selectedValue);
if (selectedValue === 'vscode') {
setOpenInEditorURL(vscodeFilepath);
} else if (selectedValue === 'custom') {
setOpenInEditorURL('');
}
}}>
<option value="vscode">VS Code</option>
<option value="custom">Custom</option>
</select>
{openInEditorURLPreset === 'custom' && (
<input
className={styles.Input}
type="text"
placeholder={process.env.EDITOR_URL ? process.env.EDITOR_URL : ''}
value={openInEditorURL}
onChange={event => {
setOpenInEditorURL(event.target.value);
}}
/>
)}
</label>

<div className={styles.Header}>Hide components where...</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
border: 1px solid var(--color-border);
border-radius: 0.125rem;
padding: 0.125rem;
margin-left: .5rem;
}

.InvalidRegExp,
Expand Down

0 comments on commit 493f72b

Please sign in to comment.