-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Feat:-Added open in editor to appear by default #26949
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea!
I left some comments, please also consider that we support setting the placeholder for the url value from environment variable EDITOR_URL
. If this variable is set, we should display Custom
option by default.
packages/react-devtools-shared/src/devtools/views/Components/InspectedElement.js
Outdated
Show resolved
Hide resolved
if (openInEditorURLPreset === 'vscode') { | ||
setOpenInEditorURL('vscode://file/{path}:{line}'); | ||
} else { | ||
setOpenInEditorURL('custom link'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we leave it empty? Since the option label will be already "Custom"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why are you using useEffect for it? Can we update editorURL
in onChange
callback of select?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, why are you using useEffect for it? Can we update
editorURL
inonChange
callback of select?
😅 ah! i was about to refactor dropping the useEffect, something like below
const selectedValue = currentTarget.value;
setOpenInEditorURLPreset(selectedValue);
if (selectedValue === 'vscode') {
setOpenInEditorURL('vscode://file/{path}:{line}');
} else if (selectedValue === 'custom') {
setOpenInEditorURL('');
}
}}>
Co-authored-by: Ruslan Lesiutin <rdlesyutin@gmail.com>
@hoxyq will look at this tommorow , thanks for the nits! |
@hoxyq made a few changes as per your request, waiting for another set of review! i feel this UI feels more reasonable Screen.Recording.2023-06-15.at.1.43.17.PM.mov |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I thing we need two more things before merging this:
- Can you please add a small margin between select and input?
- Can you update / add new tests for this logic inside these react components? For both internal case (when EDITOR_URL env variable is set) and for public with custom url case
placeholder={ | ||
process.env.EDITOR_URL ? 'vscode://file/{path}:{line}' : '' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
placeholder={ | |
process.env.EDITOR_URL ? 'vscode://file/{path}:{line}' : '' | |
} | |
placeholder={getDefaultOpenInEditorURL()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or process.env.EDITOR_URL ? process.env.EDITOR_URL : ''
const selectedValue = currentTarget.value; | ||
setOpenInEditorURLPreset(selectedValue); | ||
if (selectedValue === 'vscode') { | ||
setOpenInEditorURL('vscode://file/{path}:{line}'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please move 'vscode://file/{path}:{line}' to a constant somewhere at the top?
@hoxyq thanks for the nits! i would try to make the changes as you requested! Could you confirm the test file location for the ones you asked me to write tests! |
No, I think you need to create a new one, something like |
@hoxyq on running the test getting this error Error $ C:\Users\bikid\react-1\node_modules.bin\jest ComponentSettings-test.js
Test Suites: 1 failed, 1 total
|
Can you try to run this test via |
@hoxyq , does not seem to work :-(
|
Are you running this command from root folder? |
yep tried from the repo root folder and also by making the cd to the test file , both did not work!
|
Try to run
|
hey @hoxyq test have started to run , am i allowed to install the react-testing-library? also what could be the reason, the test are being skipped by Jest! this is where i have created the test file, it ain't wrong i guess! |
packages/react-devtools-shared/src/__tests__/ComponentSettings-test.js
Outdated
Show resolved
Hide resolved
@hoxyq can i install react testing library to write the tests? |
Rest all work is done, the input now renders with a small amount of margin from left confused while running the test,
i think an example from you running the test might help, the test are running but i am not able to understand the error messages! |
Will this work properly with the fact that we are using React from source?
I believe you need to mock the SettingsContext. |
<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 comment
The reason will be displayed to describe this comment to others. Learn more.
{process.env.EDITOR_URL || ' ' } would be a cleaner approach.
@hoxyq tried mocking the setting context still not able to write tests properly, could you help out to write a few tests so we can progress with this PR, if you find some time! |
@Jack-Works could you help out with the test i am sort of confused on writing it, a small help would be appreciated :-) see comment |
<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 comment
The reason will be displayed to describe this comment to others. Learn more.
please add a try-catch around process.env.EDITOR_URL
, it might throw an error because process
is undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
export const LOCAL_STORAGE_OPEN_IN_EDITOR_URL_PRESET = | ||
'React::DevTools::openInEditorUrlPreset'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest removing this new config, then if the React::DevTools::openInEditorUrl
equals to 'vscode://file/{path}:{line}'
, you select the VSCode
option. That will be simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 "custom"
and then put "vscode://file/{path}:{line}"
, should we automatically switch to VSCode
option and hide input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
"custom"
and then put"vscode://file/{path}:{line}"
, should we automatically switch toVSCode
option and hide input?
yup current implementation looks right i think @hoxyq
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, if I select "custom" and then put "vscode://file/{path}:{line}", should we automatically switch to VSCode option and hide input?
Yes. I think this is good, but plz continue this PR if you don't agree with me!
const useContextMock = jest.fn().mockReturnValue({ | ||
collapseNodesByDefault: true, | ||
addListener: jest.fn(), | ||
removeListener: jest.fn(), | ||
}); | ||
|
||
render(<ComponentsSettings />, container); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please try to render ComponentsSettings
wrapper in required contexts?
Like this:
render(
<StoreContext.Provider value={...}>
<SettingsContext.Provider value={...}>
<ComponentsSettings />
</SettingsContext.Provider>
</StoreContext.Provider>,
container
);
I think this should resolve your problem with mocking contexts and you won't be required to mock useContextMock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @Biki-das, have you tried this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hoxyq let me try :-) , was busy with other stuff!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the issue here is i don't have experience testing react components without rtl 😅, so i am really struggline to make this up!
Plain jest tests are hard to come up with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no rush, thanks for working on this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hoxyq did you looked the test files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet, sorry, I am finishing something and then will take a look at this, it is still in my queue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to find a workaround for these tests, but I think we will need to find a better approach on how they should be implemented.
We can remove these tests for now:
- We don't have a good example with unit tests for custom components, some tests seem outdated and cover integration with user code
- It is quite painful atm to write tests with using
dispatchEvent
because of how SyntheticEvents work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup that's what i felt too, when i started out, so for now we would remove the test and get this merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup that's what i felt too, when i started out, so for now we would remove the test and get this merged?
Yes, I will review the PR after your changes and hope we can ship this soon :)
container = null; | ||
}); | ||
|
||
// @reactVersion >= 17 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove these annotations, my change has landed on main
, so these tests should be included in tests runs now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup i was going to remove it eventually!
@hoxyq Now the PR is at the stage of how it was working and doing as it was expected to do, if you have any changes to request please review back and direct me the same! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, one small nit is to move constant outside of component.
Please address it, I will also poke it tomorrow and if everything is good, will merge it, thanks!
const [openInEditorURL, setOpenInEditorURL] = useLocalStorage<string>( | ||
LOCAL_STORAGE_OPEN_IN_EDITOR_URL, | ||
getDefaultOpenInEditorURL(), | ||
); | ||
|
||
const vscodeFilepath = 'vscode://file/{path}:{line}'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move it outside of function? Same file, but outside of the component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the review! let me do the same :-)
Updated React from 9377e1010 to cb3404a0c. ### React upstream changes - facebook/react#27190 - facebook/react#27189 - facebook/react#27201 - facebook/react#27147 - facebook/react#26949 - facebook/react#27058 - facebook/react#27142 - facebook/react#27133 - facebook/react#27130 - facebook/react#27105 - facebook/react#27117 - facebook/react#27057
List of changes: * refactor: refactored devtools browser extension scripts to improve port management and service worker lifetime ([hoxyq](https://github.com/hoxyq) in [#27215](#27215)) * refactor[devtools/extension]: minify production builds to strip comments ([hoxyq](https://github.com/hoxyq) in [#27304](#27304)) * fix[devtools]: allow element updates polling only if bridge is alive ([hoxyq](https://github.com/hoxyq) in [#27067](#27067)) * refactor: resolve browser via env variables based on build rather than user agent ([hoxyq](https://github.com/hoxyq) in [#27179](#27179)) * fix[devtools/updateFiberRecursively]: mount suspense fallback set in timed out case ([hoxyq](https://github.com/hoxyq) in [#27147](#27147)) * Feat:-Added open in editor to appear by default ([Biki-das](https://github.com/Biki-das) in [#26949](#26949)) * fix[devtools/inspect]: null check memoized props before trying to call hasOwnProperty ([hoxyq](https://github.com/hoxyq) in [#27057](#27057)) * rename SuspenseList export to unstable_SuspenseList ([noahlemen](https://github.com/noahlemen) in [#27061](#27061))
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>
List of changes: * refactor: refactored devtools browser extension scripts to improve port management and service worker lifetime ([hoxyq](https://github.com/hoxyq) in [facebook#27215](facebook#27215)) * refactor[devtools/extension]: minify production builds to strip comments ([hoxyq](https://github.com/hoxyq) in [facebook#27304](facebook#27304)) * fix[devtools]: allow element updates polling only if bridge is alive ([hoxyq](https://github.com/hoxyq) in [facebook#27067](facebook#27067)) * refactor: resolve browser via env variables based on build rather than user agent ([hoxyq](https://github.com/hoxyq) in [facebook#27179](facebook#27179)) * fix[devtools/updateFiberRecursively]: mount suspense fallback set in timed out case ([hoxyq](https://github.com/hoxyq) in [facebook#27147](facebook#27147)) * Feat:-Added open in editor to appear by default ([Biki-das](https://github.com/Biki-das) in [facebook#26949](facebook#26949)) * fix[devtools/inspect]: null check memoized props before trying to call hasOwnProperty ([hoxyq](https://github.com/hoxyq) in [facebook#27057](facebook#27057)) * rename SuspenseList export to unstable_SuspenseList ([noahlemen](https://github.com/noahlemen) in [facebook#27061](facebook#27061))
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> DiffTrain build for commit 493f72b.
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 .
Screen.Recording.2023-06-14.at.8.03.28.PM.mov
Earlier it used to be a placeholder describing the URL
cc @hoxyq