Closed mohitwp closed 1 month ago
- The AdSense Module Overview widget should switch to a 2 column layout below the 960px breakpoint.
@jimmymadon, i am not sure that this is the best way to solve this problem. I think it would be much better if we scale the font size for text to fit into the DataBlock
container width.
It means that if we have a wider text that the size of the container, we will need to reduce the font size to smaller values that would allow us to display the text without wrapping it. The challenge here is to ensure that the font size is updated for all 4 blocks altogether. This will require some js magic to calculate which font size lets text fit the container. Here are some thoughts how it can be done: https://stackoverflow.com/questions/66046533/scale-font-to-size-when-text-exceeds-container
cc @aaemnnosttv and @tofumatt to chime in if you have a better idea.
@eugene-manuilov Thanks for the feedback and suggestions here.
i am not sure that this is the best way to solve this problem.
https://github.com/google/site-kit-wp/assets/1721319/4210e3f0-aa27-4e7a-82b5-359dae412ac3
You may have already tested this, but just putting a video here to say that it does look ok to me and is a one character fix. Also, the 601 to 960px range is mainly some older/smaller tablets in Portrait mode - so not sure how often we hit this resolution range? Is there any particular reason why this solution isn't good? Do you think there is too much whitespace when we are closer to 960px?
I think it would be much better if we scale the font size for text to fit into the DataBlock container width.
If we do this, we should try to do this fix for all DataBlock containers in the plugin. It does look good to me too - just that it will be some more effort.
@jimmymadon
Is there any particular reason why this solution isn't good? Do you think there is too much whitespace when we are closer to 960px?
Yes, if we switch to the 2x2 layout at 960px, we will get a lot of whitespace in data blocks, but the actual graph data will fall off to below the fold area. 960px is wide enough to show four data blocks, we just need to adapt the font size.
I think it would be much better if we scale the font size for text to fit into the DataBlock container width.
If we do this, we should try to do this fix for all DataBlock containers in the plugin. It does look good to me too - just that it will be some more effort.
Yes, that is what I had in mind when I wrote my comment. We need to do it for all data block groups that we have and they should automatically shrink the font size altogether within the group.
AC ✔️
Update
assets/sass/components/global/_googlesitekit-data-block.scss
- When screen size is above the
$width-tablet
, update the font size to useclamp()
and use32px
for min value,46px
(current value) for the max, and5vw
for preferred value so it can scale with the screen. In my quick test5vw
as preferred value had the best result across the screens.- Bellow the tablet screen size, the current font size should be kept, as layout shifts to the 2 columns
- Example usage:
clamp(32px, 5vw, 46px)
@zutigrm, unfortunately, this won't be enough because it will reduce the font site only for one data block. What we need to do here is to ensure that if one data block has overflowing text, then we need to reduce the font size for all four data blocks to make it look consistent. This will require some javascript magic to calculate the proper font size and update all data blocks within the same group.
@eugene-manuilov Thanks, I updated IB
@eugene-manuilov Taking it back for an update, just remembered that container width is not changing, so we will probably need to track scroll
Thanks, @zutigrm, feels like it should do the trick, but maybe let's create a new component that will encapsulate that logic instead of creating one more hook and add it to dashboard components? For example, we can create <DataBlockGroup>
and implement that calculation logic within that component for all data blocks that are its children. What do you think?
@eugene-manuilov
For example, we can create
and implement that calculation logic within that component for all data blocks that are its children. What do you think?
Yeah I was thinking about it at first, but the thing is that we don't have standardised wrapper/loop where we would bring all DataBlock
components together. Mostly it is used individually in separate widgets, or used individually within separate Cell
wrappers. Some examples WPDashboardSessionDurationGA4.js
, WPDashboardUniqueVisitorsGA4.js
, ModuleOverviewWidget/Overview.js
, and some do have a .map
which could be wrapped, but it would be too many places to cover.
So I was looking for a way to target all of them, and main dashboards were only choice I could think of. Maybe we could use it in some other entry component, but not sure if there is any better fitting than dashboards, what do you think?
but the thing is that we don't have standardised wrapper/loop where we would bring all
DataBlock
components together. Mostly it is used individually in separate widgets, or used individually within separateCell
wrappers.
I thought about something like this:
export function DataBlockGroup( { children } ) {
const ref = useRef(0);
useEffect( () => {
// find all data blocks that are children of ref.current and calculate
// the optimal font size if at least one data block has overlapping text
...
}, [] );
return <div ref={ ref }>{ children }</div>;
}
export default function WPDashboardWidgets() {
return (
<DataBlockGroup ... >
{ analyticsModuleActiveAndConnected && canViewSharedAnalytics && (
<Fragment>
<WPDashboardUniqueVisitorsGA4Widget />
<WPDashboardSessionDurationGA4Widget />
</Fragment>
) }
...
</DataBlockGroup>
);
}
export default function Overview( props ) {
return (
<Grid>
<Row>
<Cell>
<Row>
<DataBlockGroup ... >
{ dataBlocks.map( ( dataBlock, index ) => ( ... ) ) }
</DataBlockGroup>
</Row>
</Cell>
...
</Row>
<Grid>
);
}
@eugene-manuilov Thanks. I updated IB to take that direction of the wrapper. Let me know what you think
Thanks. IB ✔️
Pass Case
@mohitwp Thanks for catching this. Yes, this will need separate issue to handle the titles, current issue is handling the values in data block. But part of the current logic for handling the resizing of font size can be probably re-used there, so you can reference this issue in the new one, so it can be considered during definition.
As per conversation on slack. Moving this to execution.
Bug Description
AdSense Module overview widget Highlighted tile content overflowing when viewport size is 601px -664px.
Steps to reproduce
Screenshots
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
Implementation Brief
assets/js/components/DataBlockGroup.js
className
ref
and assign it to thediv
wrapper that should hold allchildren
. Pass it theclassName
propadjustFontSize
for example, and handle the JS elements query on the current ref (querySelectorAll
) for the.googlesitekit-data-block
selectorgetComputedStyle
return the font size property (.fontSize
)offsetWidth
of the elements parent (you can use.parentElement
of the current element, and use awhile
loop to check if the current elementscrollWidth
is bigger than parent'soffsetWidth
, and keep decrement the font size property of the current element for1px
while condition is true. And also for all the elements within the sameref
group, so they can match. Each iteration will adjust the font size of any element overflowing the container and match it to other items within the samewrapper
.useEffect
oruseLifecycles
, so on mount invokeadjustFontSize
and addresize
listener, to calladjustFontSize
as callback, and remove it on unmount. So it can be invoked on screen rotation as wellassets/js/components/wp-dashboard/WPDashboardWidgets.js
div
wrapper withDataBlockGroup
componentassets/js/modules/adsense/components/module/ModuleOverviewWidget/Overview.js
Row
component, addDataBlockGroup
and map throughheaders
to renderCell
withDataBlock
components. You can use theindex
for the checks and extracting data, which is currently numerically hardcoded for each data block.assets/js/modules/analytics-4/components/dashboard/DashboardOverallPageMetricsWidgetGA4.js
data.map
withDataBlockGroup
Test Coverage
QA Brief
601px
to664px
.Changelog entry