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

feat: SQL preview modal for Query History #11634

Merged
merged 8 commits into from
Nov 21, 2020

Conversation

nytai
Copy link
Member

@nytai nytai commented Nov 10, 2020

SUMMARY

Building off of #11574 this PR adds a preview/inspect modal to the Query History list view with a toggle for User inputted SQL and db executed SQL.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

before:
Screen Shot 2020-11-10 at 9 57 48 AM

After:
Screen Shot 2020-11-09 at 5 35 32 PM
Screen Shot 2020-11-09 at 5 35 39 PM

Screen Shot 2020-11-09 at 5 35 51 PM

Also, added copy query button to Saved Query preview modal
Screen Shot 2020-11-09 at 5 35 18 PM

TEST PLAN

  • unit tested
  • manually tested:
    • empty User SQL
    • empty Executed SQL
    • previous button
    • next button
    • open in sql lab button
    • copy query button
    • list view row highlight

ADDITIONAL INFORMATION

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

@nytai nytai force-pushed the tai/query-history-preview branch 3 times, most recently from c031e49 to 1b67dfa Compare November 10, 2020 20:25
@codecov-io
Copy link

codecov-io commented Nov 10, 2020

Codecov Report

Merging #11634 (01106e0) into master (68693c7) will increase coverage by 0.28%.
The diff coverage is 67.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #11634      +/-   ##
==========================================
+ Coverage   62.86%   63.14%   +0.28%     
==========================================
  Files         889      900      +11     
  Lines       43055    43563     +508     
  Branches     4017     4199     +182     
==========================================
+ Hits        27065    27509     +444     
- Misses      15811    15874      +63     
- Partials      179      180       +1     
Flag Coverage Δ
javascript 62.84% <67.83%> (+0.02%) ⬆️
python 63.32% <ø> (+0.44%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset-frontend/src/common/components/index.tsx 100.00% <ø> (ø)
...rontend/src/messageToasts/enhancers/withToasts.tsx 100.00% <ø> (ø)
.../src/views/CRUD/data/savedquery/SavedQueryList.tsx 61.36% <0.00%> (ø)
superset/queries/api.py 100.00% <ø> (ø)
...UD/data/components/SyntaxHighlighterCopy/index.tsx 35.55% <35.55%> (ø)
...t-frontend/src/views/CRUD/data/query/QueryList.tsx 72.38% <66.66%> (-3.18%) ⬇️
superset-frontend/src/views/CRUD/data/hooks.ts 71.42% <71.42%> (ø)
...nd/src/views/CRUD/data/query/QueryPreviewModal.tsx 97.67% <97.67%> (ø)
...ws/CRUD/data/savedquery/SavedQueryPreviewModal.tsx 100.00% <100.00%> (+14.54%) ⬆️
superset/utils/cache.py 57.57% <0.00%> (-22.43%) ⬇️
... and 53 more

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 68693c7...01106e0. Read the comment docs.

@nytai nytai force-pushed the tai/query-history-preview branch 4 times, most recently from f0a19a5 to 83b1561 Compare November 12, 2020 21:59
@nytai nytai marked this pull request as ready for review November 13, 2020 02:26
@nytai nytai force-pushed the tai/query-history-preview branch from 43a6bf7 to 1eaa405 Compare November 14, 2020 01:26
top: 40px;
left: 512px;
visibility: hidden;
margin: -4px;
Copy link
Member

Choose a reason for hiding this comment

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

small nit, but do you need the negative margin if you have the top and left relative positions?

Copy link
Member Author

Choose a reason for hiding this comment

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

That negative margin gets rid of the space that would be occupied by the element if it were not relative positioned. If we were using absolute positioning we wouldn't need it.

}
const syntaxHighlighterProps = { ...props };
delete syntaxHighlighterProps.addDangerToast;
delete syntaxHighlighterProps.addSuccessToast;
Copy link
Member

Choose a reason for hiding this comment

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

would this work for you?
const { addDangerToast, addSuccessToast, ...syntaxHighlighterProps } = props;

do you need to remove 'props.children' from the syntaxHighlighterProps as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

👏 why didn't I think of that!


function checkIndex() {
if (currentIndex === 0) {
setDisbalePrevious(true);
Copy link
Member

Choose a reason for hiding this comment

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

typo?

if (currentIndex === 0) {
setDisbalePrevious(true);
} else {
setDisbalePrevious(false);
Copy link
Member

Choose a reason for hiding this comment

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

could this be shortened to checkDisablePrevious(currentIndex === 0)

}

if (currentIndex === queries.length - 1) {
setDisbaleNext(true);
Copy link
Member

Choose a reason for hiding this comment

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

setDisableNext(currentIndex === queries.length - 1)?

Copy link
Contributor

@riahk riahk left a comment

Choose a reason for hiding this comment

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

👍 just a couple questions!

import { ToastProps } from 'src/messageToasts/enhancers/withToasts';
import Icon from 'src/components/Icon';

SyntaxHighlighter.registerLanguage('sql', sql);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to add a language prop so we can use this component with json/css/etc.?

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 added 'sql' | 'markdown' | 'html' | 'json' which is all I could find in the code base. Adding more, as needed, should be pretty simple.

data-test={`open-sql-preview-${id}`}
onClick={() => setQueryCurrentlyPreviewing(original)}
>
<StyledSyntaxHighlighter language="sql" style={github}>
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the difference between setting the language prop here and calling SyntaxHighlighter.registerLanguage above? Does the latter just load in the highlighting logic for while former explicitly sets it?

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 think the SyntaxHighlighter ships with a few languages, and probably an interface to create your own. I think the registerLanguage step is to slim down the component and not include a bunch of unnecessary code that won't be used. I'll scan the codebase for other languages we use with SyntaxHighlighter and include those too.

type BaseQueryObject = {
id: number;
};
export function useQueryPreviewState<D extends BaseQueryObject = any>({
Copy link
Contributor

Choose a reason for hiding this comment

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

nice 👌

@nytai nytai merged commit fbe4a66 into apache:master Nov 21, 2020
@nytai nytai deleted the tai/query-history-preview branch November 21, 2020 00:01
setupFilesAfterEnv: [
'<rootDir>/node_modules/jest-enzyme/lib/index.js',
'<rootDir>/spec/helpers/shim.ts',
],
Copy link
Member

Choose a reason for hiding this comment

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

@nytai any reason for this change?

Copy link
Member Author

@nytai nytai Nov 21, 2020

Choose a reason for hiding this comment

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

I was having issues with shim.ts not loading when I was running tests in vscode -- mainly type errors. I was digging through some docs and most of them were using absolute paths. Is it causing issues?

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.0.0 labels Mar 12, 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/XL 🚢 1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants