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

Convert RefreshWidget to Mantine, CSS modules, and TS #42768

Merged
merged 6 commits into from
May 17, 2024

Conversation

oisincoveney
Copy link
Contributor

@oisincoveney oisincoveney commented May 16, 2024

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.

@oisincoveney oisincoveney changed the title Convert RefreshWidget to Mantine and TS Convert RefreshWidget to Mantine, CSS modules, and TS May 16, 2024
@oisincoveney oisincoveney requested a review from a team May 16, 2024 13:39
Copy link
Contributor Author

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;
Copy link
Contributor Author

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")

Copy link
Contributor

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

Suggested change
--color-summarize: #88bf4d;
--mb-color-summarize: #88bf4d;

@oisincoveney oisincoveney added the no-backport Do not backport this PR to any branch label May 16, 2024
Copy link

replay-io bot commented May 16, 2024

Status Complete ↗︎
Commit 41feff5
Results
⚠️ 4 Flaky
2523 Passed

Copy link
Contributor

@heypoom heypoom left a 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;
Copy link
Contributor

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)

Copy link
Contributor Author

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 😄

Comment on lines 38 to 47
useUpdateEffect(() => {
if (
setRefreshElapsedHook &&
prevProps?.setRefreshElapsedHook !== setRefreshElapsedHook
) {
setRefreshElapsedHook((elapsed: number | null) => {
setElapsed(elapsed);
});
}
});
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

@heypoom heypoom May 17, 2024

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!

Comment on lines 6 to 13
.RefreshWidgetTitle {
color: var(--color-text-medium);
font-weight: bold;
font-size: 0.75em;
text-transform: uppercase;
margin-bottom: 1em;
margin-left: 0.5em;
}
Copy link
Contributor

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)

Copy link
Contributor Author

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

Copy link
Contributor

@heypoom heypoom May 17, 2024

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";
Copy link
Contributor

@heypoom heypoom May 17, 2024

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😄

@heypoom heypoom requested a review from a team May 17, 2024 12:26
@oisincoveney oisincoveney enabled auto-merge (squash) May 17, 2024 13:00
@@ -4,6 +4,7 @@
:root {
--color-white: #fff;
--color-success: #84bb4c;
--color-summarize: #88bf4d;
Copy link
Contributor

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

Suggested change
--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";
Copy link
Contributor

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

Suggested change
import RefreshOptionS from "metabase/dashboard/components/RefreshWidget/RefreshOption/RefreshOption.module.css";
import RefreshOptionS from "./RefreshOption.module.css";

@oisincoveney oisincoveney merged commit 2cf2955 into master May 17, 2024
109 checks passed
@oisincoveney oisincoveney deleted the convert-refresh-widget-to-mantine-ts branch May 17, 2024 13:24
Copy link

@oisincoveney Did you forget to add a milestone to the issue for this PR? When and where should I add a milestone?

oisincoveney added a commit that referenced this pull request May 17, 2024
oisincoveney added a commit that referenced this pull request May 17, 2024
oisincoveney added a commit that referenced this pull request May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-backport Do not backport this PR to any branch .Team/Embedding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants