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: Removes the Filter Box code #26328

Merged
merged 10 commits into from
Jan 19, 2024

Conversation

michael-s-molina
Copy link
Member

@michael-s-molina michael-s-molina commented Dec 21, 2023

SUMMARY

As part of the 4.0 approved initiatives, this PR removes the Filter Box code and it's associated dependencies react-select and array-move. It also removes the DeprecatedSelect and AsyncSelect components that were exclusively used by filter boxes. Existing filter boxes will be automatically migrated to native filters.

TESTING INSTRUCTIONS

CI should be sufficient for merging this PR. We'll do a complete testing of 4.0 after all approved proposals are merged.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@michael-s-molina michael-s-molina added risk:breaking-change Issues or PRs that will introduce breaking changes v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch labels Dec 21, 2023
@michael-s-molina michael-s-molina added the hold! On hold label Dec 21, 2023
@john-bodley
Copy link
Member

john-bodley commented Dec 21, 2023

@michael-s-molina thanks for tackling this. I think there's more dead code which could be removed, i.e., the changeFilter logic seems to be filter-box related. I also suspect that the entirety of dashboardFilters.js et al. could be removed.

Copy link

codecov bot commented Dec 21, 2023

Codecov Report

Attention: 76 lines in your changes are missing coverage. Please review.

Comparison is base (8f8c435) 69.28% compared to head (894baf5) 69.57%.
Report is 1 commits behind head on master.

Files Patch % Lines
superset/migrations/shared/native_filters.py 37.50% 70 Missing ⚠️
...t-frontend/src/dashboard/actions/dashboardState.js 0.00% 1 Missing ⚠️
...ard/components/filterscope/FilterScopeSelector.jsx 0.00% 0 Missing and 1 partial ⚠️
...d/src/dashboard/util/logging/childChartsDidLoad.js 0.00% 1 Missing ⚠️
superset/commands/chart/importers/v1/__init__.py 50.00% 1 Missing ⚠️
...perset/commands/dashboard/importers/v1/__init__.py 90.90% 1 Missing ⚠️
superset/commands/importers/v1/assets.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #26328      +/-   ##
==========================================
+ Coverage   69.28%   69.57%   +0.28%     
==========================================
  Files        1909     1893      -16     
  Lines       74875    74220     -655     
  Branches     8398     8263     -135     
==========================================
- Hits        51876    51635     -241     
+ Misses      20856    20504     -352     
+ Partials     2143     2081      -62     
Flag Coverage Δ
hive 53.77% <9.85%> (+0.20%) ⬆️
javascript 56.84% <78.57%> (+0.05%) ⬆️
mysql 78.19% <48.59%> (+0.36%) ⬆️
postgres 78.32% <48.59%> (+0.39%) ⬆️
presto 53.72% <9.85%> (+0.20%) ⬆️
python 83.20% <48.59%> (+0.41%) ⬆️
sqlite 77.90% <48.59%> (+0.39%) ⬆️
unit 56.34% <35.91%> (+0.31%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

UPDATING.md Outdated Show resolved Hide resolved
@michael-s-molina
Copy link
Member Author

@michael-s-molina thanks for tackling this. I think there's more dead code which could be removed, i.e., the changeFilter logic seems to be filter-box related. I also suspect that the entirety of dashboardFilters.js et al. could be removed.

@john-bodley I also thought this was related but in fact it's used by the feature that shows which filters are applied to a chart.

@michael-s-molina michael-s-molina requested a review from a team December 28, 2023 19:28
@john-bodley
Copy link
Member

@michael-s-molina I also thought that, however the changeFilter method doesn’t fire (confirmed by the lack of the logged event) and thus I suspect there’s some additional dead code there.

@michael-s-molina
Copy link
Member Author

@michael-s-molina I also thought that, however the changeFilter method doesn’t fire (confirmed by the lack of the logged event) and thus I suspect there’s some additional dead code there.

You're correct. The changeFilter is not being called.

I also suspect that the entirety of dashboardFilters.js et al. could be removed.

The addFilter and removeFilter are being called when you add/remove charts to/from the dashboard.

@michael-s-molina
Copy link
Member Author

@john-bodley changeFilter is called from some plugins.

Screen.Recording.2023-12-29.at.08.33.29.mov

Copy link
Member

@justinpark justinpark left a comment

Choose a reason for hiding this comment

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

LGTM

@john-bodley
Copy link
Member

@michael-s-molina both this PR and #26329 handle aspects of removing filter-box charts in favor of the native dashboard filters. These PRs seem highly coupled and per my comments in the later I wonder if there's any incentive to combine them and/or (for review purposes) make one PR are precursor (base branch) of the other?

Additionally, though necessary, I don't believe these two PRs are sufficient for the removal of the legacy filter box charts, i.e., a migration is necessary. The native filter CLI commands should provide the necessary logic which (thankfully) has no dependencies on any of the changes outlined in these two PRs.

I'm not sure where best to add this, be it in a separate PR, or including with the proposed logic if combined into a single PR, but it seems there should be an Alembic migration added where the upgrade is akin to:

from superset.cli import native_filters


def upgrade() -> None:
    native_filters.upgrade(["--all"], standalone_mode=False)
    native_filters.cleanup(["--all"], standalone_mode=False)


def downgrade() -> None:
    pass

@michael-s-molina
Copy link
Member Author

@michael-s-molina both this PR and #26329 handle aspects of removing filter-box charts in favor of the native dashboard filters. These PRs seem highly coupled and per my comments in the later I wonder if there's any incentive to combine them and/or (for review purposes) make one PR are precursor (base branch) of the other?

Although related, the features work independently of each other which allow us to have separate PRs. Having said that, pretty much any 4.0 PR will need to be rebased once another one is merged to master given the number of touched files in these types of PRs. In other words, if we merge the native filters one first, this one will need to be rebased and vice versa.

@michael-s-molina
Copy link
Member Author

michael-s-molina commented Jan 10, 2024

I'm not sure where best to add this, be it in a separate PR, or including with the proposed logic if combined into a single PR, but it seems there should be an Alembic migration added where the upgrade is akin to:

I added a migration script to forcefully migrate legacy filter boxes. I copied the logic from the CLI command into the migration file and made the adjustments such as binding the session and using pagination. This allows us to encapsulate filter box dependencies inside a migration script and remove the CLI command.

@john-bodley
Copy link
Member

@michael-s-molina regarding,

I added a migration script to forcefully migrate legacy filter boxes. I copied the logic from the CLI command into the migration file and made the adjustments such as binding the session and using pagination. This allows us to encapsulate filter box dependencies inside a migration script and remove the CLI command.

There's still the need to cleanup the dashboard metadata (the temporary fields allows one to downgrade) as well as removal of the filter box charts.

I'm not sure if it makes more sense to make this migration either:

  • Irreversible (akin to refactor: Removes the Filter Box code #26328 (comment) where I included the cleanup logic in the upgrade and made the downgrade a no-op—this was under the assumption that keeping around dangling filter-box charts would be problematic without the supporting code).
  • Reversible (akin to the logic you currently have) with a future migration in 4.1 or 5.0 which executes the cleanup logic.

If we opt for the later, the issue is that the cleanup logic no longer exists. My sense is we will need to preserve the cleanup portion of the CLI command—though delete the upgrade/downgrade logic.

@@ -192,7 +191,6 @@
"react-reverse-portal": "^2.1.1",
"react-router-dom": "^5.3.4",
"react-search-input": "^0.11.3",
"react-select": "^3.2.0",
Copy link
Member

Choose a reason for hiding this comment

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

YAAAAAAAAAAAAYYYYY!!!!

@michael-s-molina
Copy link
Member Author

Give that this test for the legacy v0 dashboard importer I was wondering whether we just skip this test for now? I've likely already committed numerous hours to this PR and (due to other work requirements) likely couldn't revisit it until towards the end of next week.

@john-bodley Given that this test is named test_import_override_dashboard_slice_reset_ownership and the previous one is test_import_new_dashboard_slice_reset_ownership, I just copied the logic from the previous test given that they should be similar tests with the only difference being a overridden dashboard instead of a new one.

@@ -542,9 +542,11 @@ def test_import_override_dashboard_slice_reset_ownership(self):
self.assertEqual(imported_slc.owners, [gamma_user])

# re-import with another user shouldn't change the permissions
g.user = admin_user
Copy link
Member

Choose a reason for hiding this comment

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

@michael-s-molina I don't believe your logic is correct, i.e., the original logic was actually correct. The intention of the test (as far as I can tell) is to import a dashboard into Superset (as the gamma user) and then reimport the same dashboard (as the admin user). Given that the dashboard existed the creator and owner should not change.

I presume the changed_by doesn't change because none of the dashboard attributes (metadata) changed, but that's simply a hunch.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me know how you want to proceed here. I assumed the tests were similar because they have the exact names with the only difference being new vs override. Given that you wanted to skip the test, I would keep it as is.

Copy link
Member

Choose a reason for hiding this comment

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

@michael-s-molina I wonder if we should leave the test as-is and just skip it. It's the legacy version of the importer as well and thus it's likely unused. Maybe @betodealmeida would have some thoughts regarding this?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, it's a common pattern, where admins will manage dashboards under source control and periodically sync them to Superset. In that case you want to preserve the original ownership.

But like John said, if this is for the v0 importer (I'm on my phone, hard to see) then I wouldn't worry about it too much, since a lot of the behavior there is not strictly defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

@john-bodley I reverted and skipped the test.

@michael-s-molina michael-s-molina removed the hold! On hold label Jan 16, 2024
@michael-s-molina michael-s-molina force-pushed the remove-filter-box branch 2 times, most recently from 7a69b1a to a098249 Compare January 18, 2024 19:24
* Formerly called "filters", which was misleading because it is actually
* initial values of the filter_box and table vis
*/
/** Initial values */
Copy link
Member

Choose a reason for hiding this comment

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

Nit: maybe we should just remove this comment?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed!

@@ -47,7 +47,7 @@ const TelemetryPixel = ({
const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel/${PIXEL_ID}/${version}/${sha}/${build}`;
return process.env.SCARF_ANALYTICS === 'false' ? null : (
<img
referrerPolicy="no-referrer-when-downgrade"
referrerPolicy="no-referrer"
Copy link
Member

Choose a reason for hiding this comment

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

Is this change related to the pr or just a rebase mistake?

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 was a rebase mistake! Reverted!

@@ -581,7 +581,7 @@ export function addSliceToDashboard(id, component) {
]).then(() => {
dispatch(addSlice(selectedSlice));

if (selectedSlice && selectedSlice.viz_type === 'filter_box') {
if (selectedSlice) {
Copy link
Member

Choose a reason for hiding this comment

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

If the code in the if block was meant to run only for filter box, shouldn’t we remove it?

Copy link
Member Author

@michael-s-molina michael-s-molina Jan 19, 2024

Choose a reason for hiding this comment

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

Great call! By removing this I was able to remove even more code!

@@ -591,7 +591,7 @@ export function addSliceToDashboard(id, component) {
export function removeSliceFromDashboard(id) {
return (dispatch, getState) => {
const sliceEntity = getState().sliceEntities.slices[id];
if (sliceEntity && sliceEntity.viz_type === 'filter_box') {
if (sliceEntity) {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed!

Copy link
Member

@kgabryje kgabryje left a comment

Choose a reason for hiding this comment

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

Amazing work! LGTM

@michael-s-molina michael-s-molina merged commit d9a3c3e into apache:master Jan 19, 2024
35 checks passed
sfirke pushed a commit to sfirke/superset that referenced this pull request Mar 22, 2024
Co-authored-by: John Bodley <john.bodley@gmail.com>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 4.0.0 labels Apr 17, 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 risk:breaking-change Issues or PRs that will introduce breaking changes size/XXL v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch 🚢 4.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants