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(dashboard): Fill form with the latest values when undo in native filters #16851

Merged
merged 6 commits into from
Sep 27, 2021
Merged

fix(dashboard): Fill form with the latest values when undo in native filters #16851

merged 6 commits into from
Sep 27, 2021

Conversation

geido
Copy link
Member

@geido geido commented Sep 27, 2021

SUMMARY

This PR fixes several issues related to the undo functionality in native filters. It stores the latest form data and adds it back to the form when the user removes a filter and then undoes the removal.

BEFORE

See issue #16821

AFTER

Video.Game.Sales.mp4

TESTING INSTRUCTIONS

  1. Open a Dashboard with native filters enabled
  2. Add a filter
  3. Remove the filter
  4. Undo your action and make sure the latest data was preserved

ADDITIONAL INFORMATION

@geido
Copy link
Member Author

geido commented Sep 27, 2021

@jinghua-qa @junlincc

@geido geido requested review from michael-s-molina, kgabryje and villebro and removed request for michael-s-molina and kgabryje September 27, 2021 08:10
@codecov
Copy link

codecov bot commented Sep 27, 2021

Codecov Report

Merging #16851 (32a16a2) into master (100760c) will increase coverage by 0.00%.
The diff coverage is 90.90%.

❗ Current head 32a16a2 differs from pull request most recent head 3e9c827. Consider uploading reports for the commit 3e9c827 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##           master   #16851   +/-   ##
=======================================
  Coverage   76.93%   76.94%           
=======================================
  Files        1021     1021           
  Lines       54708    54724   +16     
  Branches     7459     7468    +9     
=======================================
+ Hits        42092    42106   +14     
- Misses      12372    12374    +2     
  Partials      244      244           
Flag Coverage Δ
javascript 71.14% <90.90%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
...onfigModal/FiltersConfigForm/FiltersConfigForm.tsx 73.87% <90.90%> (+0.60%) ⬆️

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 100760c...3e9c827. Read the comment docs.

@geido
Copy link
Member Author

geido commented Sep 27, 2021

/testenv up FEATURE_DASHBOARD_NATIVE_FILTERS=true FEATURE_DASHBOARD_CROSS_FILTERS=true FEATURE_DASHBOARD_NATIVE_FILTERS_SET=true FEATURE_DASHBOARD_FILTERS_EXPERIMENTAL=true

@github-actions
Copy link
Contributor

@geido Ephemeral environment spinning up at http://54.245.58.103:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link
Member

@villebro villebro left a comment

Choose a reason for hiding this comment

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

Nice work! LGTM with one small question/comment.

Comment on lines -559 to +526
!!filterToEdit?.adhoc_filters || !!filterToEdit?.time_range;
!!formFilter?.adhoc_filters ||
!!formFilter?.time_range ||
!!filterToEdit?.adhoc_filters?.length ||
!!filterToEdit?.time_range;
Copy link
Member

Choose a reason for hiding this comment

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

should we also change it to formFilter?.adhoc_filters?.length || like it is later for filterToEdit, just in case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your feedback! It appears that when the form doesn't have any filters it will just return undefined, reason why I am only checking for that here

@michael-s-molina
Copy link
Member

@geido If I'm not mistaken when the user removes a filter, it only marks that filter as deleted but the form values are preserved. If that's the case, why do we need the undoFormValues state? Can't we just use the original form?

@geido
Copy link
Member Author

geido commented Sep 27, 2021

@geido If I'm not mistaken when the user removes a filter, it only marks that filter as deleted but the form values are preserved. If that's the case, why do we need the undoFormValues state? Can't we just use the original form?

@michael-s-molina I checked that and it appears that when the filter is removed the form is also cleaned up. You won't have the most recent state of the form, hence I am storing it on removal and reapplying the values on undo.

@michael-s-molina
Copy link
Member

@geido If I'm not mistaken when the user removes a filter, it only marks that filter as deleted but the form values are preserved. If that's the case, why do we need the undoFormValues state? Can't we just use the original form?

@michael-s-molina I checked that and it appears that when the filter is removed the form is also cleaned up. You won't have the most recent state of the form, hence I am storing it on removal and reapplying the values on undo.

Do you know where the form is being cleared? This is the handler for the delete action and it's only marking it as removed.

export const createHandleTabEdit = (
  setRemovedFilters: (
    value:
      | ((
          prevState: Record<string, FilterRemoval>,
        ) => Record<string, FilterRemoval>)
      | Record<string, FilterRemoval>,
  ) => void,
  setSaveAlertVisible: Function,
  addFilter: Function,
) => (filterId: string, action: 'add' | 'remove') => {
  const completeFilterRemoval = (filterId: string) => {
    // the filter state will actually stick around in the form,
    // and the filterConfig/newFilterIds, but we use removedFilters
    // to mark it as removed.
    setRemovedFilters(removedFilters => ({
      ...removedFilters,
      [filterId]: { isPending: false },
    }));
  };

  if (action === 'remove') {
    // first set up the timer to completely remove it
    const timerId = window.setTimeout(
      () => completeFilterRemoval(filterId),
      REMOVAL_DELAY_SECS * 1000,
    );
    // mark the filter state as "removal in progress"
    setRemovedFilters(removedFilters => ({
      ...removedFilters,
      [filterId]: { isPending: true, timerId },
    }));
    setSaveAlertVisible(false);
  } else if (action === 'add') {
    addFilter();
  }
};

@geido
Copy link
Member Author

geido commented Sep 27, 2021

@michael-s-molina as stated above, I confirm that the form is wiped out as soon as the form rerenders after the remove action. Any data you already have about the filter (such as the one in the filterConfigMap ) might be outdated as it does not contain the most recent state of the form. Thus, the only solution that seems to solve both scenarios is to store the current state of the form. I am happy to consider a different solution but it does not appear to be obvious at the moment. Let me know if anything different comes to your mind. Thank you!

@michael-s-molina
Copy link
Member

michael-s-molina commented Sep 27, 2021

@michael-s-molina as stated above, I confirm that the form is wiped out as soon as the form rerenders after the remove action. Any data you already have about the filter (such as the one in the filterConfigMap ) might be outdated as it does not contain the most recent state of the form. Thus, the only solution that seems to solve both scenarios is to store the current state of the form. I am happy to consider a different solution but it does not appear to be obvious at the moment. Let me know if anything different comes to your mind. Thank you!

I was reviewing and found this:

Screen Shot 2021-09-27 at 9 34 12 AM

This is the code that is clearing the form. preserve={false} is forcing the values to be cleared. The default value of Ant Design is true. If we change it to true, the values are preserved after restoring. The only thing is that I don’t know why this was set to false.

@michael-s-molina
Copy link
Member

michael-s-molina commented Sep 27, 2021

@geido We can investigate this in a follow-up since this is a P1. For now, let's merge it.

@junlincc junlincc merged commit d3f6145 into apache:master Sep 27, 2021
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

@junlincc junlincc added the rush! Requires immediate attention label Sep 27, 2021
@sadpandajoe
Copy link
Member

🏷️ 2021.38

stevenuray pushed a commit to preset-io/superset that referenced this pull request Sep 27, 2021
…filters (apache#16851)

* Set undoFormValues

* Reorganize

* Revert check

* Fix and clean up

* Fix pre-filter and sort values

(cherry picked from commit d3f6145)
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
…filters (apache#16851)

* Set undoFormValues

* Reorganize

* Revert check

* Fix and clean up

* Fix pre-filter and sort values
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
…filters (apache#16851)

* Set undoFormValues

* Reorganize

* Revert check

* Fix and clean up

* Fix pre-filter and sort values
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.4.0 labels Mar 13, 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 preset:2021.38 rush! Requires immediate attention size/L 🚢 1.4.0
Projects
None yet
6 participants