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(explore): don't respect y-axis formatting #29367

Conversation

justinpark
Copy link
Member

@justinpark justinpark commented Jun 25, 2024

SUMMARY

When StashFormData is initially loaded, the process of restoring hiddenFormData during the stash state update was missing, causing the y-axis format to not change properly after the first change.

This code fixes the process to always update hiddenFormData whenever the shouldStash state changes.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:

before--stash-form-initially.mov

After:

after--stash-form-initially.mov

TESTING INSTRUCTIONS

Create a bar chart
Set y-axis format with an option
Update the format with a different option
Y-axis format should update respectfully

ADDITIONAL INFORMATION

@dosubot dosubot bot added explore Namespace | Anything related to Explore explore:control Related to the controls panel of Explore labels Jun 25, 2024
@rusackas
Copy link
Member

@gooroodev please review

@gooroodev
Copy link

@rusackas, thank you for the ping!

🐞Mistake 🤪Typo 🚨Security 🚀Performance 💪Best Practices 📖Readability ❓Others
0 0 0 0 1 1 0

Summary of Proposed Changes:

  • ➕ Added a new test case to ensure form data is restored from hiddenFormData when shouldStash is false.
  • ➕ Added a new test case to ensure no state update occurs if the field is already updated.
  • ➖ Removed the isMounted reference and logic from StashFormDataContainer component.
  • 🛠️ Modified the exploreReducer to skip updates when the field is already updated in SET_STASH_FORM_DATA.

Identified Issues:

ID Type Details Severity Confidence
1 💪Best Practices The useRef hook and related logic is removed, but the reason is not clear. 🟠Medium 🟠Medium
2 📖Readability The ternary operator in exploreReducer can be simplified for readability. 🟡Low 🟡Low

Issue 1: The useRef hook and related logic is removed, but the reason is not clear.

Explanation:
The useRef hook and related logic for checking the isMounted status is removed from the StashFormDataContainer component. This change is not explained, and it may lead to unintended side effects if the original logic was necessary to handle some specific cases.

Suggested Fix:
Re-evaluate the necessity of the isMounted logic. If it's truly redundant, provide a comment explaining why it was removed. Otherwise, restore it to avoid potential issues.

import { useEffect, useRef, FC } from 'react';
import { useDispatch } from 'react-redux';
import { setStashFormData } from 'src/explore/actions/exploreActions';
import useEffectEvent from 'src/hooks/useEffectEvent';

type Props = {
  shouldStash: boolean;
  fieldNames: ReadonlyArray<string>;
};

const StashFormDataContainer: FC<Props> = ({
  shouldStash,
  fieldNames,
  children,
}) => {
  const dispatch = useDispatch();
  const isMounted = useRef(false); // Restored useRef hook
  const onVisibleUpdate = useEffectEvent((shouldStash: boolean) =>
    dispatch(setStashFormData(shouldStash, fieldNames)),
  );
  useEffect(() => {
    if (!isMounted.current && !shouldStash) {
      isMounted.current = true;
    } else {
      onVisibleUpdate(shouldStash);
    }
  }, [shouldStash, onVisibleUpdate]);

  return <>{children}</>;
};

export default StashFormDataContainer;

Issue 2: The ternary operator in exploreReducer can be simplified for readability.

Explanation:
The ternary operator used in the exploreReducer for checking the length of restoredField can be simplified for better readability.

Suggested Fix:
Simplify the ternary operator for better readability.

const restoredField = pick(hiddenFormData, fieldNames);
if (Object.keys(restoredField).length === 0) {
  return state;
}
return {
  ...state,
  form_data: {
    ...form_data,
    ...restoredField,
  },
  hiddenFormData: omit(hiddenFormData, fieldNames),
};

General Review:

The proposed changes enhance the functionality by adding new test cases and refining the logic in the reducer. However, the removal of the isMounted logic in the StashFormDataContainer component needs further justification. The readability of the ternary operator in the reducer can also be improved for better maintenance. Overall, the code quality and style are good, but addressing the identified issues will make it more robust and maintainable.

--
I only arrive when I am mentioned and asked to review the pull request.
React or reply to let me know your feedback!

@michael-s-molina michael-s-molina merged commit 58f33d2 into apache:master Jun 26, 2024
38 of 39 checks passed
@michael-s-molina michael-s-molina added the v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch label Jun 26, 2024
@mistercrunch mistercrunch added 🍒 4.0.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels Jul 24, 2024
irublev pushed a commit to HighviewPower/superset that referenced this pull request Oct 29, 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 explore:control Related to the controls panel of Explore explore Namespace | Anything related to Explore size/M v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch 🍒 4.0.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants