You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2024/06/26 11:16:45 UTC

(superset) branch master updated: fix(explore): don't respect y-axis formatting (#29367)

This is an automated email from the ASF dual-hosted git repository.

michaelsmolina pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 58f33d227a fix(explore): don't respect y-axis formatting (#29367)
58f33d227a is described below

commit 58f33d227a8779e0a02da6fa8d75ae175d232f89
Author: JUST.in DO IT <ju...@airbnb.com>
AuthorDate: Wed Jun 26 04:16:36 2024 -0700

    fix(explore): don't respect y-axis formatting (#29367)
---
 .../StashFormDataContainer.test.tsx                | 30 +++++++++++++++++++++-
 .../components/StashFormDataContainer/index.tsx    |  9 ++-----
 .../src/explore/reducers/exploreReducer.js         | 18 +++++++------
 .../src/explore/reducers/exploreReducer.test.js    | 10 ++++++++
 4 files changed, 51 insertions(+), 16 deletions(-)

diff --git a/superset-frontend/src/explore/components/StashFormDataContainer/StashFormDataContainer.test.tsx b/superset-frontend/src/explore/components/StashFormDataContainer/StashFormDataContainer.test.tsx
index bedfb8de5b..669114bff2 100644
--- a/superset-frontend/src/explore/components/StashFormDataContainer/StashFormDataContainer.test.tsx
+++ b/superset-frontend/src/explore/components/StashFormDataContainer/StashFormDataContainer.test.tsx
@@ -17,7 +17,7 @@
  * under the License.
  */
 import { defaultState } from 'src/explore/store';
-import { render } from 'spec/helpers/testing-library';
+import { render, waitFor } from 'spec/helpers/testing-library';
 import { useSelector } from 'react-redux';
 import { ExplorePageState } from 'src/explore/types';
 import StashFormDataContainer from '.';
@@ -54,3 +54,31 @@ test('should stash form data from fieldNames', () => {
     'granularity_sqla',
   );
 });
+
+test('should restore form data from fieldNames', async () => {
+  const { granularity_sqla, ...formData } = defaultState.form_data;
+  const { container } = render(
+    <StashFormDataContainer
+      shouldStash={false}
+      fieldNames={['granularity_sqla']}
+    >
+      <FormDataMock />
+    </StashFormDataContainer>,
+    {
+      useRedux: true,
+      initialState: {
+        explore: {
+          form_data: formData,
+          hiddenFormData: {
+            granularity_sqla,
+          },
+        },
+      },
+    },
+  );
+  await waitFor(() =>
+    expect(container.querySelector('div')).toHaveTextContent(
+      'granularity_sqla',
+    ),
+  );
+});
diff --git a/superset-frontend/src/explore/components/StashFormDataContainer/index.tsx b/superset-frontend/src/explore/components/StashFormDataContainer/index.tsx
index 3715140aad..5761bef0a6 100644
--- a/superset-frontend/src/explore/components/StashFormDataContainer/index.tsx
+++ b/superset-frontend/src/explore/components/StashFormDataContainer/index.tsx
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import { useEffect, useRef, FC } from 'react';
+import { useEffect, FC } from 'react';
 
 import { useDispatch } from 'react-redux';
 import { setStashFormData } from 'src/explore/actions/exploreActions';
@@ -33,16 +33,11 @@ const StashFormDataContainer: FC<Props> = ({
   children,
 }) => {
   const dispatch = useDispatch();
-  const isMounted = useRef(false);
   const onVisibleUpdate = useEffectEvent((shouldStash: boolean) =>
     dispatch(setStashFormData(shouldStash, fieldNames)),
   );
   useEffect(() => {
-    if (!isMounted.current && !shouldStash) {
-      isMounted.current = true;
-    } else {
-      onVisibleUpdate(shouldStash);
-    }
+    onVisibleUpdate(shouldStash);
   }, [shouldStash, onVisibleUpdate]);
 
   return <>{children}</>;
diff --git a/superset-frontend/src/explore/reducers/exploreReducer.js b/superset-frontend/src/explore/reducers/exploreReducer.js
index 8985f032c7..377a66d5b5 100644
--- a/superset-frontend/src/explore/reducers/exploreReducer.js
+++ b/superset-frontend/src/explore/reducers/exploreReducer.js
@@ -261,14 +261,16 @@ export default function exploreReducer(state = {}, action) {
       }
 
       const restoredField = pick(hiddenFormData, fieldNames);
-      return {
-        ...state,
-        form_data: {
-          ...form_data,
-          ...restoredField,
-        },
-        hiddenFormData: omit(hiddenFormData, fieldNames),
-      };
+      return Object.keys(restoredField).length === 0
+        ? state
+        : {
+            ...state,
+            form_data: {
+              ...form_data,
+              ...restoredField,
+            },
+            hiddenFormData: omit(hiddenFormData, fieldNames),
+          };
     },
     [actions.SLICE_UPDATED]() {
       return {
diff --git a/superset-frontend/src/explore/reducers/exploreReducer.test.js b/superset-frontend/src/explore/reducers/exploreReducer.test.js
index 37f072d9e7..bcc585630b 100644
--- a/superset-frontend/src/explore/reducers/exploreReducer.test.js
+++ b/superset-frontend/src/explore/reducers/exploreReducer.test.js
@@ -33,3 +33,13 @@ test('reset hiddenFormData on SET_STASH_FORM_DATA', () => {
   expect(newState2.form_data).toEqual({ c: 4 });
   expect(newState2.hiddenFormData).toEqual({ a: 3 });
 });
+
+test('skips updates when the field is already updated on SET_STASH_FORM_DATA', () => {
+  const initialState = {
+    form_data: { a: 3, c: 4 },
+    hiddenFormData: { b: 2 },
+  };
+  const restoreAction = setStashFormData(false, ['c', 'd']);
+  const newState = exploreReducer(initialState, restoreAction);
+  expect(newState).toBe(initialState);
+});