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

Add support for preview when collapsed #54

Open
igo opened this issue Jul 14, 2024 · 5 comments
Open

Add support for preview when collapsed #54

igo opened this issue Jul 14, 2024 · 5 comments

Comments

@igo
Copy link

igo commented Jul 14, 2024

Instead of showing three dots when collapsed
image

would be great to set which fields are important and try to show them in preview when collapsed:
image

@jaywcjlove
Copy link
Member

@igo It looks easy to implement. How about adding a collapsedPreviewLength prop?

<JsonView
+  collapsedPreviewLength={12}
/>

@igo
Copy link
Author

igo commented Jul 14, 2024

To make this useful I need to select which fields to show. collapsedPreviewLength would be useful to limit how many of those fields would fit on the screen.

@jaywcjlove
Copy link
Member

@igo Would it be acceptable if the API is designed like this?

<JsonView
+  collapsedPreview={12}
/>
<JsonView
+  collapsedPreview="some text"
/>
<JsonView
+  collapsedPreview={(value, expandKey = '', level, keys = []) => {
+     return "some text"
+  }}
/>

@igo
Copy link
Author

igo commented Jul 14, 2024

I do not fully understand your suggested API. I was thinking about something like this:

{
"user": { "username": "tim" } // firstName intentionally omitted
"address": [{"city": "NY"}]
}
<JsonView
collapsedPreviewKeys=['user.username', 'user.firstName', 'user.address.[0].city']
collapsedPreviewKeyName={true/false} // would show "username -> tim, city -> NY" if true else "tim, NY"
/>

@jaywcjlove
Copy link
Member

@igo I think callback functions would be more flexible.

var object = {
  "user": { "username": "tim" }
  "address": [{"city": "NY"}]
}

<JsonView
  value={object}
  collapsedPreview={(value, expandKey = '', level, keys = []) => {
    if (expandKey == "user") {
      return value.username
    }
    if (expandKey == "city") {
      return value
    }
    if (keys.join(".") == "user.address.0.city") {
      return value
    }
  }}
/>

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

2 participants