Skip to content

fix(explore): don't respect y-axis formatting#29367

Merged
michael-s-molina merged 1 commit into
apache:masterfrom
justinpark:fix--explore-yaxis-format-no-updates
Jun 26, 2024
Merged

fix(explore): don't respect y-axis formatting#29367
michael-s-molina merged 1 commit into
apache:masterfrom
justinpark:fix--explore-yaxis-format-no-updates

Conversation

@justinpark
Copy link
Copy Markdown
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
@justinpark justinpark requested review from rusackas and sfirke June 25, 2024 20:07
@rusackas
Copy link
Copy Markdown
Member

@gooroodev please review

@gooroodev
Copy link
Copy Markdown

@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
@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 Cherry-picked to 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
@mistercrunch mistercrunch added the 🚢 4.1.0 First shipped in 4.1.0 label Nov 27, 2024
ratuldawar11 pushed a commit to grofers/superset that referenced this pull request Apr 14, 2026
* fix(permalink): adding anchor to dashboard permalink generation (apache#28744)

* fix: filters not updating with force update when caching is enabled (apache#29291)

(cherry picked from commit 527f1d2)

* fix(sqllab): invalid empty state on switch tab (apache#29278)

* fix(metastore-cache): prune before add (apache#29301)

(cherry picked from commit 172ddb4)

* fix: Remove recursive repr call (apache#29314)

(cherry picked from commit 9444c6b)

* fix: Cannot delete empty column inside a tab using the dashboard editor (apache#29346)

(cherry picked from commit ee52277)

* fix(explore): restored hidden field values has discarded (apache#29349)

(cherry picked from commit 160cece)

* chore: Rename Totals to Summary in table chart (apache#29360)

* fix(revert 27883): Excess padding in horizontal Bar charts (apache#29345)

(cherry picked from commit 708afb7)

* fix(explore): don't respect y-axis formatting (apache#29367)

* fix: adds the ability to disallow SQL functions per engine (apache#28639)

* chore: Adds 4.0.2 RC2 data to CHANGELOG.md

* fixes

* frontend fixes

* fix: cache api

---------

Co-authored-by: Jack <41238731+fisjac@users.noreply.github.com>
Co-authored-by: ka-weihe <k@weihe.dk>
Co-authored-by: JUST.in DO IT <justin.park@airbnb.com>
Co-authored-by: Ville Brofeldt <33317356+villebro@users.noreply.github.com>
Co-authored-by: Jessie R <j@scjr.me>
Co-authored-by: Michael S. Molina <70410625+michael-s-molina@users.noreply.github.com>
Co-authored-by: Daniel Vaz Gaspar <danielvazgaspar@gmail.com>
Co-authored-by: Michael S. Molina <michael.s.molina@gmail.com>
qfcwell pushed a commit to qfcwell/superset that referenced this pull request May 12, 2026
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 Cherry-picked to 4.0.2 🚢 4.1.0 First shipped in 4.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants