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 enum and env var to conditionally render MUI theme #564

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

jenny-s51
Copy link
Contributor

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

Description

Adds env var to support toggling 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?

Verify that the MUI theme is toggled on / off based on the value of STYLE_THEME.

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.

@jenny-s51 jenny-s51 force-pushed the conditionalThemeFlag branch 5 times, most recently from d15ef8c to ee1c21c Compare November 15, 2024 19:05
@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 3 times, most recently from ec4cff7 to ccd6543 Compare November 18, 2024 20:45
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.

@jenny-s51 jenny-s51 changed the title Add flag to conditionally render MUI theme Add enum / env var to conditionally render MUI theme Nov 20, 2024
@jenny-s51 jenny-s51 changed the title Add enum / env var to conditionally render MUI theme Add enum and env var to conditionally render MUI theme Nov 20, 2024
@jenny-s51 jenny-s51 requested a review from lucferbux November 20, 2024 16:13
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, just a couple of nits, everything else working as expected!

@jenny-s51 jenny-s51 force-pushed the conditionalThemeFlag branch 2 times, most recently from 95eaae9 to e1f97d0 Compare November 21, 2024 15:31
Signed-off-by: Jenny <32821331+jenny-s51@users.noreply.github.com>
@jenny-s51 jenny-s51 force-pushed the conditionalThemeFlag branch from e1f97d0 to e3bb6b8 Compare November 21, 2024 15:31
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.

/lgtm

Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ederign, lucferbux

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

The pull request process is described 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

@ederign
Copy link
Member

ederign commented Nov 21, 2024

/label approved

@google-oss-prow google-oss-prow bot merged commit a12fd00 into kubeflow:main Nov 21, 2024
16 checks passed
Copy link

@ederign: The label(s) /label approved cannot be applied. These labels are supported: tide/merge-method-merge, tide/merge-method-rebase, tide/merge-method-squash, lifecycle/needs-triage. Is this label configured under labels -> additional_labels or labels -> restricted_labels in plugin.yaml?

In response to this:

/label approved

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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.

4 participants