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

[SQL Lab] Add JSON modal when clicking on cells with JSON objects #7720

Merged

Conversation

etr2460
Copy link
Member

@etr2460 etr2460 commented Jun 17, 2019

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

This was recommended in #7690 by @mistercrunch. Clicking on a JSON stringified object or array in SQL Lab now opens a modal with the formatted JSON object/array.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

image

TEST PLAN

  • Ensure only objects and arrays are clickable
  • Test with both table and grid view renders

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

@mistercrunch @graceguo-supercat @betodealmeida @elibrumbaugh

@etr2460 etr2460 force-pushed the erik-ritter--sqllab-json-format branch from bb0eb36 to aa8e806 Compare June 17, 2019 18:04
@betodealmeida
Copy link
Member

Oh, this is awesome!

Quick question to you and @mistercrunch: can you change this to double click? I'm worried people won't be able to select the cell to copy the values if we use a single click for this.

@etr2460
Copy link
Member Author

etr2460 commented Jun 17, 2019

@betodealmeida I was thinking about selecting for copy pasting too... You can still do it as is, but i could see how it might be a bit finicky. What if we added a Copy cell contents button to the modal? Do you think that would resolve the issue?

@etr2460 etr2460 force-pushed the erik-ritter--sqllab-json-format branch from aa8e806 to dc3c0f4 Compare June 17, 2019 22:50
@codecov-io
Copy link

codecov-io commented Jun 17, 2019

Codecov Report

Merging #7720 into master will decrease coverage by <.01%.
The diff coverage is 60%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #7720      +/-   ##
==========================================
- Coverage   65.77%   65.76%   -0.01%     
==========================================
  Files         459      459              
  Lines       21911    21936      +25     
  Branches     2410     2414       +4     
==========================================
+ Hits        14411    14426      +15     
- Misses       7379     7389      +10     
  Partials      121      121
Impacted Files Coverage Δ
...src/components/FilterableTable/FilterableTable.jsx 83.56% <60%> (-4.87%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5864ddc...35ef47b. Read the comment docs.

import TooltipWrapper from '../TooltipWrapper';

function getTextWidth(text, font = '12px Roboto') {
return getTextDimension({ text, style: { font } }).width;
}

function getJsonStringifiedObject(data) {
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In which scenario do you expect it to fail?
You can also use ../../../src/utils/safeStringify if the crash cases are circular json.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’ll fail if we don’t pass in valid json. Like “foo” or “{“. Let me know if there’s an easier way to determine if a string is valid json and resolves to an object/array

@etr2460 etr2460 force-pushed the erik-ritter--sqllab-json-format branch from dc3c0f4 to 41bea2a Compare June 18, 2019 15:55
@betodealmeida
Copy link
Member

@etr2460 yeah, the copy button is great!

LGTM, will defer to @mistercrunch since he requested changes.

@@ -165,6 +213,17 @@ export default class FilterableTable extends PureComponent {
this.setState({ sortBy, sortDirection });
}

addJsonModal(node, jsonObject, jsonString) {
return (
<ModalTrigger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if perf matters here as I think we're always using react-virtualized in this context (only rendering the rows in the viewport), but I think this will build all of the modals and related <JSONTree />. @betodealmeida has been working on data preview perf recently and may have more intuition as to whether this matters.

An alternate approach would be to build / render the modal on only when clicked/used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the DOM and React devtools, it doesn't seem like anything gets rendered prior to clicking on the cell. The react structure has a ModalTrigger and an empty Modal element and that's it. I think we're probably fine here.

import TooltipWrapper from '../TooltipWrapper';

function getTextWidth(text, font = '12px Roboto') {
return getTextDimension({ text, style: { font } }).width;
}

function getJsonStringifiedObject(data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT (optional): naming safeJsonParse

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make it safeJsonObjectParse since it doesn't parse all JSON, but only things that are objects.

@etr2460 etr2460 force-pushed the erik-ritter--sqllab-json-format branch from 41bea2a to 35ef47b Compare June 18, 2019 23:01
@etr2460
Copy link
Member Author

etr2460 commented Jun 21, 2019

@mistercrunch is this in good shape now?

@betodealmeida
Copy link
Member

@etr2460 I just pulled your branch and tested it, this is awesome! <3

@betodealmeida betodealmeida merged commit 0d248fe into apache:master Jun 21, 2019
@etr2460 etr2460 deleted the erik-ritter--sqllab-json-format branch June 21, 2019 16:24
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/M 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants