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

Add flag to conditionally render MUI theme #564

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jenny-s51
Copy link
Contributor

@jenny-s51 jenny-s51 commented Nov 15, 2024

Description

Re-applies switch to MR UI in order to conditionally toggle MUI theme on / off.
Screenshot 2024-11-15 at 10 51 56 AM
Screenshot 2024-11-15 at 10 52 52 AM

How Has This Been Tested?

Toggle switch in page masthead and verify that the MUI theme is toggled on / off based on the value of the switch.

Tests N/A, visual updates only.

Merge criteria:

  • All the commits have been signed-off (To pass the DCO check)
  • The commits have meaningful messages; the author will squash them after approval or in case of manual merges will ask to merge with squash.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work.
  • Code changes follow the kubeflow contribution guidelines.

If you have UI changes

  • The developer has added tests or explained why testing cannot be added.
  • Included any necessary screenshots or gifs if it was a UI change.
  • Verify that UI/UX changes conform the UX guidelines for Kubeflow.

Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign alexcreasy for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Signed-off-by: Jenny <[email protected]>

format

Signed-off-by: Jenny <[email protected]>

fix tests

Signed-off-by: Jenny <[email protected]>

remove unused imports

Signed-off-by: Jenny <[email protected]>

fix plain button border radius and editable label padding
@Griffin-Sullivan
Copy link
Contributor

What a great way to show off all your work!

Comment on lines 52 to 67
const [isSwitched, setIsSwitched] = React.useState<boolean>(window.isSwitched ?? false);

// Listen for changes to `window.isSwitched`
React.useEffect(() => {
const handleSwitchChange = (event: Event) => {
if (event instanceof CustomEvent) {
setIsSwitched(event.detail); // Update state with the new value
}
};

window.addEventListener('isSwitchedChanged', handleSwitchChange);

return () => {
window.removeEventListener('isSwitchedChanged', handleSwitchChange);
};
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this gets reused a lot I would guess a custom hook like useMUI would be a good idea

Copy link
Contributor

@lucferbux lucferbux left a comment

Choose a reason for hiding this comment

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

Ok changes look reaaly great, but overall, we would wanna avoid this global declarations, apologies for not detailing too much in the description the conditional rendering, but the main goal for this is just to turn it on or off at build time, for that:

  • Instead of having a global window value, let's just control this with a constant
  • That constant could be either a boolean, but I would suggest moving this into an ENUM and then have some utility to control (we only want MUI but it's a good practice to get extensibility)
  • We might not want a switcher in the UI, upstream should stick with MUI, this is just for us to be able to contribute both upstream with MUI and downstream with regular PF6 look and feel
  • The global const should be an env variable, I'm working right now on a PR to enhance our env variable handling but so far it's gonna be similar on what we have in odh, so you can follow that pattern in the const.ts file
  • Since we don't have proper env support (I'm working on it right now) you can test that in a similar way as we have here just add the env variable you decided to use (maybe STYLE_THEME) to the Kubeflow value (if it's a boolean call it other way) and add that to the dev command, I can tweak it later in my PR

@jenny-s51 jenny-s51 force-pushed the conditionalThemeFlag branch 2 times, most recently from a14f287 to b8fef6b Compare November 18, 2024 20:41
Signed-off-by: Jenny <[email protected]>

format

fix build errors

Signed-off-by: Jenny <[email protected]>

fix import order and linting

Signed-off-by: Jenny <[email protected]>

Add process.env.STYLE_THEME
Copy link
Contributor Author

@jenny-s51 jenny-s51 left a comment

Choose a reason for hiding this comment

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

Thank you @Griffin-Sullivan @lucferbux for your feedback - updated the PR to reflect your comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants