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

fix: always pass a string as a value to ace editor #13563

Merged
merged 2 commits into from
Mar 13, 2021

Conversation

eschutho
Copy link
Member

@eschutho eschutho commented Mar 11, 2021

SUMMARY

Fixes issue with template params modal not opening when value was null.
I converted one file to tsx so that we can put a null check on the code argument in TemplateParamsEditor, but it won't help much until the rest of the files are converted. I also made the initial state undefined instead of null so that we can use default args downstream. Lastly, I put in a check at the ace editor itself to never accept a null or undefined value, but pass an empty string in that case.

fixes #13540

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

see #13540 for before state (no modal opens)

after:
Screenshot_3_10_21__7_32_PM

TEST PLAN

unit tests aren't completely reliable when it comes to passing a null value to ace editor. It was difficult to reproduce the issue in the tests. I wrote tests around the new code to ensure that we are using undefined instead of null.

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

@eschutho eschutho changed the title always pass a string as a value to ace editor fix: always pass a string as a value to ace editor Mar 11, 2021
@eschutho eschutho force-pushed the elizabeth/fix-template-params branch from 8691e63 to a5e9b72 Compare March 11, 2021 03:41
@junlincc
Copy link
Member

junlincc commented Mar 12, 2021

Tested locally and learned something new today, LGTM! Thanks for the fix! 🙏 @eschutho
With FF enabled, I can type and delete in both sql editor and para modal ✅
i can open a new tab with ctrl+t ✅
I am able to type, close, reopen the modal and the data persists ✅

Functionality ✅

Screen.Recording.2021-03-11.at.5.09.08.PM.mov

@mistercrunch is there a reason why this feature behind a FF? it's working pretty nicely now.

@eschutho eschutho force-pushed the elizabeth/fix-template-params branch from a5e9b72 to 1859027 Compare March 12, 2021 02:15
@eschutho
Copy link
Member Author

flaky test?

@eschutho eschutho closed this Mar 12, 2021
@eschutho eschutho reopened this Mar 12, 2021
@codecov
Copy link

codecov bot commented Mar 12, 2021

Codecov Report

Merging #13563 (d439da2) into master (7656b2e) will decrease coverage by 1.06%.
The diff coverage is 42.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #13563      +/-   ##
==========================================
- Coverage   77.35%   76.29%   -1.07%     
==========================================
  Files         909      910       +1     
  Lines       46118    46310     +192     
  Branches     5649     5613      -36     
==========================================
- Hits        35674    35330     -344     
- Misses      10309    10816     +507     
- Partials      135      164      +29     
Flag Coverage Δ
cypress 55.15% <7.43%> (-1.95%) ⬇️
hive 80.03% <100.00%> (+0.05%) ⬆️
javascript 63.06% <14.17%> (-0.30%) ⬇️
mysql 80.35% <100.00%> (+0.05%) ⬆️
postgres 80.39% <100.00%> (+0.05%) ⬆️
presto 80.05% <100.00%> (?)
python 80.88% <100.00%> (+0.15%) ⬆️
sqlite 80.02% <100.00%> (+0.05%) ⬆️

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

Impacted Files Coverage Δ
...controls/DndColumnSelectControl/DndSelectLabel.tsx 36.84% <0.00%> (-2.05%) ⬇️
...s/controls/MetricControl/MetricDefinitionValue.jsx 100.00% <ø> (+5.88%) ⬆️
...-frontend/src/explore/components/controls/index.js 100.00% <ø> (ø)
superset/connectors/base/models.py 90.78% <ø> (ø)
superset/constants.py 100.00% <ø> (ø)
...ontrols/DndColumnSelectControl/DndMetricSelect.tsx 10.40% <10.40%> (ø)
...ontrols/DndColumnSelectControl/DndFilterSelect.tsx 9.23% <50.00%> (ø)
...ntrols/MetricControl/AdhocMetricPopoverTrigger.tsx 93.33% <75.00%> (-1.41%) ⬇️
...omponents/controls/DndColumnSelectControl/index.ts 100.00% <100.00%> (ø)
superset/dashboards/api.py 88.68% <100.00%> (+0.56%) ⬆️
... and 62 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 7656b2e...d126550. Read the comment docs.

@@ -150,7 +151,8 @@ export default function AsyncAceEditor(
mode={mode}
theme={theme}
tabSize={tabSize}
{...props}
defaultValue={defaultValue}
{...{ ...props, value: props.value || '' }}
Copy link
Member

Choose a reason for hiding this comment

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

The syntax here looks alien. 😄

Why not:

Suggested change
{...{ ...props, value: props.value || '' }}
{...props}
value={props.value || '' }

Copy link
Member Author

Choose a reason for hiding this comment

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

ha, yeah, that was my first implementation, but often people like to see the "rest" props at the end, and so I anticipated someone changing this order in the context of "cleanup". I think I found a way around this.. lmk what you think.

}: {
code: string;
language: 'yaml' | 'json';
onChange: (...args: any) => any;
Copy link
Member

Choose a reason for hiding this comment

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

how about this?

Suggested change
onChange: (...args: any) => any;
onChange: () => void;

Copy link
Member

Choose a reason for hiding this comment

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

When we are convert SqlEditor.jsx to the typescript, we can add function parameter type again.

<TemplateParamsEditor
language="json"
onChange={params => {
this.props.actions.queryEditorSetTemplateParams(qe, params);
}}
code={qe.templateParams}
/>

Copy link
Member Author

Choose a reason for hiding this comment

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

We should be getting to it soon, and then, yes we'll be able to manage types of props better, ya!

Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

LGTM

@eschutho
Copy link
Member Author

🏷 ready-to-merge

@superset-github-bot superset-github-bot bot added the need:merge The PR is ready to be merged label Mar 13, 2021
@pkdotson pkdotson merged commit 67ffea8 into apache:master Mar 13, 2021
@eschutho eschutho deleted the elizabeth/fix-template-params branch March 13, 2021 01:22
henryyeh pushed a commit to preset-io/superset that referenced this pull request Mar 18, 2021
* always pass a string as a value to ace editor

* fix some syntax

(cherry picked from commit 67ffea8)
henryyeh pushed a commit to preset-io/superset that referenced this pull request Mar 22, 2021
* always pass a string as a value to ace editor

* fix some syntax

(cherry picked from commit 67ffea8)
allanco91 pushed a commit to allanco91/superset that referenced this pull request May 21, 2021
* always pass a string as a value to ace editor

* fix some syntax
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.2.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 need:merge The PR is ready to be merged preset-io size/L 🚢 1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SQLlab]Parameters Modal Not Appearing
6 participants