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

refactor: [migration] convert iframe chart into dashboard markdown component #10590

Merged

Conversation

graceguo-supercat
Copy link

@graceguo-supercat graceguo-supercat commented Aug 12, 2020

SUMMARY

Dashboard v2 support native markdown component, and user can also create iframe inside markdown. So that it's not necessary to have iframe/markup/separator viz_type in slices (or add them into dashboard).

This PR will do:

  • Find iframe type chart that used in dashboard.
  • Convert iframe slices into dashboard Markdown component. Slices in markup and separator viz_type already converted into dashboard component when dashboard v2 rollout.
  • Delete iframe/markup/separator slices, and remove viz_type support (python and js)

TEST PLAN

Before migration, create a iframe chart and add into dashboard.
After migration, check the dashboard, iframe chart should be converted into Markdown component with a iframe.

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

@mistercrunch @etr2460 @john-bodley @serenajiang

@graceguo-supercat graceguo-supercat force-pushed the gg-RemoveIframeVizInDash branch 3 times, most recently from ca6b05f to 78a0816 Compare August 12, 2020 23:21
Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

a couple initial comments, i need to reread the getInitialState changes again when i get more time though (I think it's mostly indentation changes, but confirmation would be helpful).

Overall, this looks awesome! I'm so happy to get rid of the iframe viz!

@@ -2040,25 +2040,6 @@ def get_data(self, df: pd.DataFrame) -> VizData:
return d


class IFrameViz(BaseViz):
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to remove markdown components from viz.py too?

Copy link
Author

@graceguo-supercat graceguo-supercat Aug 13, 2020

Choose a reason for hiding this comment

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

yes i think i need to.
Actually they were removed in another PR: #9997

@@ -0,0 +1,38 @@
# Licensed to the Apache Software Foundation (ASF) under one
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this can be removed? I assume it was a placeholder for the migration I just ran

Copy link
Author

@graceguo-supercat graceguo-supercat Aug 13, 2020

Choose a reason for hiding this comment

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

I create this migration yesterday, but today you merge a new migration script. so both of us are based from same root. this file is to resolve the sequence problem for alembic. otherwise i have to re-create the migration script.

Copy link
Member

Choose a reason for hiding this comment

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

I think you could copy paste your migration into a new migration script and then not need this blank file. Sorry for the migration conflict!

Copy link
Author

Choose a reason for hiding this comment

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

use superset db merge heads will generate migration script and fix the conflicts. no need to modify original file. There are many empty migration script in the codebase which was created for this purpose.

).delete(synchronize_session=False)

except Exception as ex:
logging.exception(f"dashboard {dashboard.id} has error: {ex}")
Copy link
Member

Choose a reason for hiding this comment

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

What state would we end in if only part of the iframes got deleted? I assume the charts would break because we're removing the backend api. Maybe it's not an issue though if the chance of an exception here is quite small



def downgrade():
pass
Copy link
Member

Choose a reason for hiding this comment

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

I agree this is nearly impossible to do a downgrade for. Maybe add a comment explaining why though?

@@ -29,9 +29,7 @@ import ForceDirectedChartPlugin from '@superset-ui/legacy-plugin-chart-force-dir
import HeatmapChartPlugin from '@superset-ui/legacy-plugin-chart-heatmap';
import HistogramChartPlugin from '@superset-ui/legacy-plugin-chart-histogram';
import HorizonChartPlugin from '@superset-ui/legacy-plugin-chart-horizon';
import IframeChartPlugin from '@superset-ui/legacy-plugin-chart-iframe';
Copy link
Member

Choose a reason for hiding this comment

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

oooo, we can delete these packages next! So much red code!

Copy link
Author

@graceguo-supercat graceguo-supercat Aug 13, 2020

Choose a reason for hiding this comment

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

correct. need another PR in superset-ui codebase (after everything looks good in superset).

# find iframe chart position in metadata
# and replace it with markdown component
position_dict = json.loads(dashboard.position_json or "{}")
for key, value in position_dict.items():
Copy link
Member

Choose a reason for hiding this comment

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

nit: replace value with chart_position (or perhaps position_value as it's more clear

Copy link
Author

Choose a reason for hiding this comment

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

i like chart_position. fixed.

dashboards = (
session.query(Dashboard).filter(Dashboard.id.in_(dashboard_ids)).all()
)
for i, dashboard in enumerate(dashboards):
Copy link
Member

Choose a reason for hiding this comment

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

we should probably add to UPDATING.md that this should be done during off hours as it could break people's charts while they're editing. They might save over the migrated dash and accidentally add an iframe chart back into it

Copy link
Author

Choose a reason for hiding this comment

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

fixed.

).all()
slices_ids = [slc.id for slc in slices_to_remove]

# remove dependencies first
Copy link
Author

@graceguo-supercat graceguo-supercat Aug 13, 2020

Choose a reason for hiding this comment

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

i tested in dev-box use production data.
It seems I have to remove dependencies first, where those table use slice_id as foreign key.

modified: slice.modified,
changed_on: new Date(slice.changed_on).getTime(),
};
const form_data = {
Copy link
Author

Choose a reason for hiding this comment

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

correct. the only change is just removed if viz_type change. I didn't touch any other code.

Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

apart from the empty migration that i think you can get rid of, this lgtm!

@codecov-commenter
Copy link

codecov-commenter commented Aug 14, 2020

Codecov Report

Merging #10590 into master will decrease coverage by 4.53%.
The diff coverage is 1.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10590      +/-   ##
==========================================
- Coverage   64.37%   59.83%   -4.54%     
==========================================
  Files         775      777       +2     
  Lines       36555    36619      +64     
  Branches     3459     3456       -3     
==========================================
- Hits        23531    21910    -1621     
- Misses      12912    14519    +1607     
- Partials      112      190      +78     
Flag Coverage Δ
#cypress ?
#javascript 60.47% <2.77%> (-0.01%) ⬇️
#python 59.45% <1.21%> (-0.49%) ⬇️

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

Impacted Files Coverage Δ
...frontend/src/dashboard/reducers/getInitialState.js 0.00% <0.00%> (-68.61%) ⬇️
...src/explore/components/controls/VizTypeControl.jsx 76.92% <ø> (-1.93%) ⬇️
superset-frontend/src/explore/constants.js 100.00% <ø> (ø)
...-frontend/src/visualizations/presets/MainPreset.js 0.00% <ø> (-100.00%) ⬇️
...ns/978245563a02_migrate_iframe_to_dash_markdown.py 0.00% <0.00%> (ø)
superset/migrations/versions/f80a3b88324b_.py 0.00% <0.00%> (ø)
superset/viz.py 57.55% <ø> (-0.10%) ⬇️
...rset-frontend/src/explore/components/SaveModal.jsx 90.76% <100.00%> (-1.88%) ⬇️
superset/tasks/slack_util.py 89.47% <100.00%> (ø)
superset-frontend/src/SqlLab/App.jsx 0.00% <0.00%> (-100.00%) ⬇️
... and 155 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 acb00f5...9de1d87. Read the comment docs.

@stevensuting
Copy link

Screen Shot 2020-09-02 at 10 50 32 AM
@graceguo-supercat
I am attempting to create a KPI card as shown above. In version 0.36 I could do this by using the markdown chart in HTML mode where I would use 3 iFrames. Each iFrame would point to a big_number_total chart

With 0.37 this is no long possible as I understand.

ERROR: Separator

ERROR:superset.views.base:'separator'
Traceback (most recent call last):
  File "/home/ubuntu/demo-superset/lib/python3.6/site-packages/superset/views/base.py", line 173, in wraps
    return f(self, *args, **kwargs)
  File "/home/ubuntu/demo-superset/lib/python3.6/site-packages/superset/utils/decorators.py", line 67, in wrapper
    check_perms(*args, **kwargs)
  File "/home/ubuntu/demo-superset/lib/python3.6/site-packages/superset/views/utils.py", line 426, in check_datasource_perms
    force=False,
  File "/home/ubuntu/demo-superset/lib/python3.6/site-packages/superset/views/utils.py", line 111, in get_viz
    viz_obj = viz.viz_types[viz_type](datasource, form_data=form_data, force=force)
KeyError: 'separator'

ERROR: markup

KeyError: 'markup'
ERROR:superset.views.base:'markup'
Traceback (most recent call last):
  File "/home/ubuntu/demo-superset/lib/python3.6/site-packages/superset/views/base.py", line 173, in wraps
    return f(self, *args, **kwargs)
  File "/home/ubuntu/demo-superset/lib/python3.6/site-packages/superset/utils/decorators.py", line 67, in wrapper
    check_perms(*args, **kwargs)
  File "/home/ubuntu/demo-superset/lib/python3.6/site-packages/superset/views/utils.py", line 426, in check_datasource_perms
    force=False,
  File "/home/ubuntu/demo-superset/lib/python3.6/site-packages/superset/views/utils.py", line 111, in get_viz
    viz_obj = viz.viz_types[viz_type](datasource, form_data=form_data, force=force)

@graceguo-supercat
Copy link
Author

graceguo-supercat commented Sep 21, 2020

@stevensuting Superset will not support markup and separator charts any more. you should use divider and Markdown components in Dashboard.

Ofeknielsen pushed a commit to ofekisr/incubator-superset that referenced this pull request Oct 5, 2020
…mponent (apache#10590)

* refactor: [migration] convert iframe chart into dashboard markdown component

* remove 3 viz_types

* fix comments
@graceguo-supercat graceguo-supercat deleted the gg-RemoveIframeVizInDash branch November 11, 2020 23:17
auxten pushed a commit to auxten/incubator-superset that referenced this pull request Nov 20, 2020
…mponent (apache#10590)

* refactor: [migration] convert iframe chart into dashboard markdown component

* remove 3 viz_types

* fix comments
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.38.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/L 🚢 0.38.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants