-
Notifications
You must be signed in to change notification settings - Fork 49.9k
Feat:-Added open in editor to appear by default #26949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
81ecab9
a883d43
f9c745b
cf2b03e
fbf83da
58e2099
023c766
7c361a4
34114ca
de9e2c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import React from 'react'; | ||
| import { render, unmountComponentAtNode } from 'react-dom'; | ||
| import ComponentsSettings from '../devtools/views/Settings/ComponentsSettings'; | ||
|
|
||
| describe('ComponentsSettings', () => { | ||
| let container; | ||
|
|
||
| beforeEach(() => { | ||
| // Set up a DOM element as a render target | ||
| container = document.createElement('div'); | ||
| document.body.appendChild(container); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| // Clean up on exiting | ||
| unmountComponentAtNode(container); | ||
| container.remove(); | ||
| container = null; | ||
| }); | ||
|
|
||
| // @reactVersion >= 17 | ||
|
||
| it('should update collapseNodesByDefault setting', () => { | ||
| const useContextMock = jest.fn().mockReturnValue({ | ||
| collapseNodesByDefault: true, | ||
| addListener: jest.fn(), | ||
| removeListener: jest.fn(), | ||
| }); | ||
|
|
||
| render(<ComponentsSettings />, container); | ||
|
||
|
|
||
| const toggleElement = container.querySelector('.Settings input[type="checkbox"]'); | ||
|
|
||
| expect(toggleElement.checked).toBe(true); | ||
|
|
||
| toggleElement.click(); | ||
|
|
||
| expect(useContextMock().collapseNodesByDefault).toBe(false); | ||
| }); | ||
|
|
||
| it('should update parseHookNames setting', () => { | ||
| const setParseHookNamesMock = jest.fn(); | ||
|
|
||
| const useContextMock = jest.fn().mockReturnValue({ | ||
| parseHookNames: true, | ||
| setParseHookNames: setParseHookNamesMock, | ||
| }); | ||
|
|
||
| render(<ComponentsSettings />, container); | ||
|
|
||
| const toggleElement = container.querySelector('.Settings input[type="checkbox"]'); | ||
|
|
||
| expect(toggleElement.checked).toBe(true); | ||
|
|
||
| toggleElement.click(); | ||
|
|
||
| expect(setParseHookNamesMock).toHaveBeenCalledWith(false); | ||
| }); | ||
|
|
||
| it('should update openInEditorURLPreset setting', () => { | ||
| const setLocalStorageMock = jest.spyOn(Storage.prototype, 'setItem'); | ||
|
|
||
| const useContextMock = jest.fn().mockReturnValue({ | ||
| openInEditorURLPreset: 'custom', | ||
| setOpenInEditorURLPreset: jest.fn(), | ||
| }); | ||
|
|
||
| render(<ComponentsSettings />, container); | ||
|
|
||
| const selectElement = container.querySelector('.Settings select'); | ||
|
|
||
| expect(selectElement.value).toBe('custom'); | ||
|
|
||
| selectElement.value = 'vscode'; | ||
| selectElement.dispatchEvent(new Event('change')); | ||
|
|
||
| expect(setLocalStorageMock).toHaveBeenCalledWith('OPEN_IN_EDITOR_URL_PRESET', 'vscode'); | ||
| }); | ||
|
|
||
| it('should update openInEditorURL setting', () => { | ||
| const setLocalStorageMock = jest.spyOn(Storage.prototype, 'setItem'); | ||
|
|
||
| const useContextMock = jest.fn().mockReturnValue({ | ||
| openInEditorURLPreset: 'custom', | ||
| setOpenInEditorURL: jest.fn(), | ||
| }); | ||
|
|
||
| render(<ComponentsSettings />, container); | ||
|
|
||
| const selectElement = container.querySelector('.Settings select'); | ||
| const inputElement = container.querySelector('.Settings input[type="text"]'); | ||
|
|
||
| selectElement.value = 'custom'; | ||
| selectElement.dispatchEvent(new Event('change')); | ||
|
|
||
| inputElement.value = 'https://example.com'; | ||
| inputElement.dispatchEvent(new Event('change')); | ||
|
|
||
| expect(setLocalStorageMock).toHaveBeenCalledWith('OPEN_IN_EDITOR_URL', 'https://example.com'); | ||
| }); | ||
|
|
||
| // Add additional test cases for other functionality... | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
||
|
Comment on lines
+42
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest removing this new config, then if the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this adds kinda wrong dependency, you should select the preset first and then based on its value, you either do nothing or update the link template. For example, if I select
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
yup current implementation looks right i think @hoxyq
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. I think this is good, but plz continue this PR if you don't agree with me! |
||
| export const LOCAL_STORAGE_PARSE_HOOK_NAMES_KEY = | ||
| 'React::DevTools::parseHookNames'; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -83,11 +86,17 @@ 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(), | ||
| ); | ||
|
|
||
| const vscodeFilepath = 'vscode://file/{path}:{line}'; | ||
|
||
|
|
||
| const [componentFilters, setComponentFilters] = useState< | ||
| Array<ComponentFilter>, | ||
| >(() => [...store.componentFilters]); | ||
|
|
@@ -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 : ''} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. {process.env.EDITOR_URL || ' ' } would be a cleaner approach.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add a try-catch around
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you possibly help out with the tests, i tried to but could not wrap my head around the structure for the same! The file is already initialized could you try something up :-)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there is an old test for the settings panel and you can add things there |
||
| value={openInEditorURL} | ||
| onChange={event => { | ||
| setOpenInEditorURL(event.target.value); | ||
| }} | ||
| /> | ||
| )} | ||
| </label> | ||
|
|
||
| <div className={styles.Header}>Hide components where...</div> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.