Skip to content
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

Needs a feature to copy/paste or download the current state object #60

Open
localjo opened this issue Oct 10, 2016 · 8 comments
Open

Needs a feature to copy/paste or download the current state object #60

localjo opened this issue Oct 10, 2016 · 8 comments

Comments

@localjo
Copy link

localjo commented Oct 10, 2016

I've had a few situations where it would be really convenient for me to get a copy of just the current state object either saved to a pretty-printed JSON file or copied to the clipboard. The existing download button is similar, but since it downloads actions and computed state, I have to shave a few more yaks to get a clean copy of the state object.

The current best solution I have is to use react-devtools to select my <Provider/> component and then paste JSON.stringify($r.store.getState()) into the console. This works, but requires multiple unintuitive clicks, remembering or finding that code snippet, and then formatting the output.

Since this is something I run into often, it would reduce a lot of friction to have a more streamlined solution, like a "Copy current state to Clipboard" button somewhere in the UI. Another user suggested being able to copy the contents of the log monitor panel just by clicking and dragging, which is another potential solution that would work for this use case.

I'm more than happy to open a PR for this and implement the feature, but before I spend a lot of time on it, I just wanted to check whether or not this is a feature you'd be interested in merging, and if you have any thoughts about the design of the UI/UX for this feature.

@zalmoxisus
Copy link
Collaborator

zalmoxisus commented Oct 10, 2016

I would suggest to implement this in react-json-tree, so it will work without any changes in this repo and also for other redux devtools monitors. It would be great to have a context menu to Export as a file and Copy the current state subtree. So, it will be possible to copy not only the whole state object but also a state's subtree and the action's payload.

@localjo
Copy link
Author

localjo commented Oct 10, 2016

My intuition says a solution involving text selection might not be the right solution here. Consider this screenshot;

screen shot 2016-10-10 at 4 16 26 pm

A bunch of rhetorical questions; Where does the selection begin and end? Why are some keys not selected/selectable? What should happen with the selected bits that aren't part of the JSON syntax? Should they be selectable at all? Should they indicate selection of a specific part of the state object? If so, which?

It's worth noting that you can't copy and paste the representation of a JS object in the Chrome Devtools either.

For my personal use-case a simple button or context menu item that copies the pretty-printed result of store.getState() to the clipboard would be enough. If that's the solution it wouldn't really be a part of react-json-tree because it really has nothing to do with the tree view at all. However, I could see some value in a context menu item that allows you to copy/save individual nodes from the state object, in which case implementing it in react-json-tree would make sense.

@zalmoxisus
Copy link
Collaborator

zalmoxisus commented Oct 10, 2016

Well, the screenshot isn't related to the current repo, it's from redux-devtools-inspector. For redux-devtools-log-monitor it looks like this:
screen shot 2016-10-10 at 4 48 31 pm

So, when you right click on state you'll be able to select from a menu whether to copy this object to clipboard or export in a file, moreover you can copy also todo object (substate of a specific reducer), or let's say you want to copy just text property. Even it will be possible to copy the action object, which is also rather useful. We have already these objects in react-json-tree, it's more about UI.

However, for Inspector Monitor we'll be able to export only a part of state or action object from a context menu, so adding a button there would make sense.

In case we add a menu, then those parts you pointed shouldn't be selectable at all.

@zalmoxisus
Copy link
Collaborator

If we get this context menu with the corresponding part of the object, it will be possible even to implement inline editing as suggested in zalmoxisus/remote-redux-devtools#32. Or make this part of the object available in the console as per zalmoxisus/redux-devtools-extension#132.

Though, for most use cases a button as you suggested could be enough. Related to zalmoxisus/redux-devtools-extension#157.

@StevenACoffman
Copy link

joshwcomeau/redux-vcr/issues/1 records the series of Redux actions and would like to share functionality with redux-devtools. Might be relevant.

@Startouf
Copy link

Startouf commented Jun 4, 2018

Thank you very much for the JSON.stringify($r.store.getState()) trick, previously I was copy-pasting from the raw tab, but it wasn't JSON and actually pretty tricky to convert to proper JSON

We would just need a "Copy as JSON" button in the State > raw tab.

@tnrich
Copy link

tnrich commented Jul 21, 2022

Kind of a late response.. the devtools are definitely still lacking this seemingly very important and useful feature. In the meantime I'd recommend popping the redux store onto the window itself and then doing the following:

window.myGlobalStore.getState()

Then it's as easy as finding the object you're interested in and right clicking to copy it:

image

@leixd1994
Copy link

I found the React DevTool have this function of copy props or state to JSON. see pictures below:

image
then go to console ,you will find this
image

then you can copy to JSON by right click mouse , and choose copy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants