-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Convert RefreshWidget to Mantine, CSS modules, and TS #42768
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I converted this one to TS as well to fix the type error in RefreshWidget
, where it was asking for a className that's not necessarily needed
@@ -4,6 +4,7 @@ | |||
:root { | |||
--color-white: #fff; | |||
--color-success: #84bb4c; | |||
--color-summarize: #88bf4d; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to add this to match color("summarize")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change it to be
--color-summarize: #88bf4d; | |
--mb-color-summarize: #88bf4d; |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I haven't tried to run this locally yet, but code-wise looks good. Left some minor comments and questions.
}: { | ||
setRefreshElapsedHook?: (hook: (elapsed: number | null) => void) => void; | ||
period: number | null; | ||
onChangePeriod: (period: number | null) => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: wondering if we have a naming convention on this? (e.g. the props in the above diff is onRefreshPeriodChange
, so this could be onPeriodChange
too or vice-versa)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that I'm doing with #42777 will be to standardize this. Don't worry, it's definitely a thought I've had as well 😄
useUpdateEffect(() => { | ||
if ( | ||
setRefreshElapsedHook && | ||
prevProps?.setRefreshElapsedHook !== setRefreshElapsedHook | ||
) { | ||
setRefreshElapsedHook((elapsed: number | null) => { | ||
setElapsed(elapsed); | ||
}); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why we use usePrevious
in this case instead of using standard useEffect
to track dependency change on setRefreshElapsedHook
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I basically copied the code over from JS. Usually when I try to use something like a new useEffect
in place of the old code something breaks, but I've changed it and things seem to be working correctly still. I've made the change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, I thought this was a new logic - forgot for a moment that this is only for TS migration, my bad 🙏🏻
I'm not exactly sure if useEffect
would cover all the edge cases though (that was just me being curious), but if it works fine then ok!
.RefreshWidgetTitle { | ||
color: var(--color-text-medium); | ||
font-weight: bold; | ||
font-size: 0.75em; | ||
text-transform: uppercase; | ||
margin-bottom: 1em; | ||
margin-left: 0.5em; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious on when do we decide to write our own styles in CSS Modules, as opposed to using metabase/ui
Mantine components? (Mantine components can specify most of these props)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the main blocker is nested selectors, as you see later in the file. I've moved the independent classes to the mantine props as you suggested, but some of them will have to stay for now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! I think it makes complete sense to go with CSS modules for nested selectors, as there is no other way to handle it 😄
Mantine's style props is much more limited than, say, what tailwind and friends can do unfortunately. I'm not a big fan of their use-hover
shenanigans either
|
||
import { CountdownIcon } from "metabase/components/icons/CountdownIcon"; | ||
import { DashboardHeaderButton } from "metabase/dashboard/components/DashboardHeader/DashboardHeader.styled"; | ||
import { isNotNull } from "metabase/lib/types"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(not related to this PR, but I thought lib/types
is about types, I'm surprised to see functions here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😄
@@ -4,6 +4,7 @@ | |||
:root { | |||
--color-white: #fff; | |||
--color-success: #84bb4c; | |||
--color-summarize: #88bf4d; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please change it to be
--color-summarize: #88bf4d; | |
--mb-color-summarize: #88bf4d; |
@@ -0,0 +1,27 @@ | |||
import cx from "classnames"; | |||
|
|||
import RefreshOptionS from "metabase/dashboard/components/RefreshWidget/RefreshOption/RefreshOption.module.css"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use relative import here
import RefreshOptionS from "metabase/dashboard/components/RefreshWidget/RefreshOption/RefreshOption.module.css"; | |
import RefreshOptionS from "./RefreshOption.module.css"; |
@oisincoveney Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone? |
Refactors the RefreshWidget to use Mantine popovers, CSS modules, and typescript. I made this change since the logic in Popover was breaking when displaying the static dashboard, and the height wasn't being calculated properly. I figured that using the Mantine popover would be an easier way to go since the component wasn't that big, and I figured it would be a better use of our time than trying to figure out why the Popover is working in our dashboards but not in the SDK.
Since I was also in the area, I converted the component to TS. I also converted the emotion to CSS modules since there were some issues with styling in the Embedding SDK that I thought would be solved by using CSS modules instead of emotion. That wasn't the issue but I think it's a welcome conversion too.