Skip to content

feat: redesign the metrics layout #901

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

Merged
merged 4 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const LastImages = () => {
};

return (
<div className="hidden lg:block pt-5 border-grayish-blue border-0 border-t-2 border-solid">
<div className="hidden lg:block pt-5">
<h3 className="text-base m-0">{ optimoleDashboardApp.strings.latest_images.last } { optimoleDashboardApp.strings.latest_images.optimized_images }</h3>

{ ( isInitialLoading && ! isLoaded ) && (
Expand Down
247 changes: 157 additions & 90 deletions assets/src/dashboard/parts/connected/dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import {

import { useSelect } from '@wordpress/data';

import { clearCache } from '../../../utils/api';

/**
* Internal dependencies.
*/
import {
imagesNumber,
savedSize,
compressionPercentage,
traffic,
quota,
warning
bolt,
update,
offloadImage,
settings
} from '../../../utils/icons';

import ProgressBar from '../../components/ProgressBar';
Expand All @@ -33,29 +33,67 @@ import LastImages from './LastImages';
const cardClasses = 'flex p-6 bg-light-blue border border-blue-300 rounded-md';

const metrics = [
{
label: optimoleDashboardApp.strings.metrics.metricsTitle1,
description: optimoleDashboardApp.strings.metrics.metricsSubtitle1,
value: 'images_number',
icon: imagesNumber
},
{
label: optimoleDashboardApp.strings.metrics.metricsTitle2,
description: optimoleDashboardApp.strings.metrics.metricsSubtitle2,
value: 'saved_size',
icon: savedSize
value: 'saved_size'
},
{
label: optimoleDashboardApp.strings.metrics.metricsTitle3,
description: optimoleDashboardApp.strings.metrics.metricsSubtitle3,
value: 'compression_percentage',
icon: compressionPercentage
value: 'compression_percentage'
},
{
label: optimoleDashboardApp.strings.metrics.metricsTitle4,
description: optimoleDashboardApp.strings.metrics.metricsSubtitle4,
value: 'traffic',
icon: traffic
value: 'traffic'
}
];

const settingsTab = {
offload_image: 1,
advance: 2
};

const navigate = ( tabId ) => {
const links = window.optimoleDashboardApp.submenu_links;
const settingsLink = links.find( link => '#settings' === link.hash );
if ( settingsLink ) {
const existingLink = document.querySelector( `a[href="${settingsLink.href}"]` );
existingLink.click();
setTimeout( () => {
const tabItems = document.querySelectorAll( '.optml-settings ul li' );
tabItems[tabId]?.querySelector( 'button' ).click();
window.scrollTo( 0, 0 );
}, 500 );
}
};

const quickactions = [
{
icon: <Icon icon={bolt} className="text-info"/>,
title: optimoleDashboardApp.strings.quick_actions.speed_test_title,
description: optimoleDashboardApp.strings.quick_actions.speed_test_desc,
link: optimoleDashboardApp.strings.quick_actions.speed_test_link,
value: 'speedTest'
},
{
icon: <Icon icon={update} className="text-info"/>,
title: optimoleDashboardApp.strings.quick_actions.clear_cache_images,
description: optimoleDashboardApp.strings.quick_actions.clear_cache,
value: clearCache
},
{
icon: <Icon icon={offloadImage} className="text-info" />,
title: optimoleDashboardApp.strings.quick_actions.offload_images,
description: optimoleDashboardApp.strings.quick_actions.offload_images_desc,
value: () => navigate( settingsTab.offload_image )
},
{
icon: <Icon icon={settings} className="text-info"/>,
title: optimoleDashboardApp.strings.quick_actions.advance_settings,
description: optimoleDashboardApp.strings.quick_actions.configure_settings,
value: () => navigate( settingsTab.advance )
}
];

Expand Down Expand Up @@ -109,97 +147,126 @@ const Dashboard = () => {
Math.floor( Math.random() * 40 ) + 10;
}

// Format based on metric type
if ( 'saved_size' === metric ) {
return ( metricValue / 1000 ).toFixed( 2 ) + 'MB';
}

if ( 'compression_percentage' === metric ) {
return metricValue.toFixed( 2 ) + '%';
}

if ( 'traffic' === metric ) {
return metricValue.toFixed( 2 ) + 'MB';
}

return metricValue;
};

return (
<div className="bg-white p-8 border-0 rounded-lg shadow-md">
{ ( 0 < optimoleDashboardApp.strings.notice_just_activated.length && 'active' === userStatus ) && <ActivatedNotice/> }
const formatMetricValue = metric => {
const value = getFormattedMetric( metric );
const calcValue = 'saved_size' === metric ? ( value / 1000 ).toFixed( 2 ) : value.toFixed( 2 );
return (
<div className='flex items-end gap-1'>
<span className='text-2xl text-black font-bold'>{calcValue}</span>
<span className='text-sm text-gray-500'>{ 'compression_percentage' === metric ? '%' : 'MB' }</span>
</div>
);
};

{ 'inactive' === userStatus && <InactiveWarning/> }
return (
<>
<div className="bg-white p-8 border-0 rounded-lg shadow-md">
{ ( 0 < optimoleDashboardApp.strings.notice_just_activated.length && 'active' === userStatus ) && <ActivatedNotice/> }

<div
className={ classNames(
cardClasses,
'gap-8 flex-col sm:flex-row items-start sm:items-center'
) }
>
<Icon icon={ quota } />
{ 'inactive' === userStatus && <InactiveWarning/> }

<div className="flex w-full flex-col">
<div className="flex w-full justify-between">
<div className='py-6 gap-6 flex-col sm:flex-row items-start sm:items-center'>
<div className='flex w-full justify-between sm:items-center'>
<div className="text-gray-800 text-2xl font-bold">
{ userData.visitors_pretty } / { userData.visitors_limit_pretty }

<span className="text-gray-600 text-base font-normal ml-2">
{ optimoleDashboardApp.strings.dashboard_title }
</div>
<div className="flex items-center gap-2">
<div className="text-gray-600 text-base font-normal ml-2">
{ optimoleDashboardApp.strings.quota }
</span>
<span className="pl-2 text-gray-800 font-bold">
{ userData.visitors_pretty } / { userData.visitors_limit_pretty }
</span>
</div>
<div className='w-20'>
<ProgressBar
value={ userData.visitors }
max={ userData.visitors_limit }
/>
</div>
<span>{ visitorsLimitPercent }%</span>
</div>

{ ( 70 > visitorsLimitPercent ) && (
<Button
variant="default"
className="optml__button rounded font-bold min-h-40"
href={ optimoleDashboardApp.optimoleDashBilling }
target="_blank"
>
{ optimoleDashboardApp.strings.upgrade.title }
</Button>
) }
</div>
</div>

<div
className={ classNames(
cardClasses,
'gap-8 flex-col sm:flex-row items-start sm:items-center'
) }
>
<div>
<ProgressBar
className="mt-2.5 mb-3 mx-0"
value={ userData.visitors }
max={ userData.visitors_limit }
/>
<div className="text-gray-800 text-xl font-bold">
{ optimoleDashboardApp.strings.banner_title }
</div>
<div className="text-gray-600 text-base">
{ optimoleDashboardApp.strings.banner_description }
</div>
</div>
</div>

<div className="flex py-5 gap-5 flex-col md:flex-row">
{ metrics.map( metric => {
return (
<div
key={ metric.value }
className={ classNames(
'p-3 basis-1/3 flex-col items-start border rounded-md border-solid bg-white border-light-gray border-slate-400'
) }
>
<div className="flex w-full flex-col">
<div className="not-italic font-normal text-sm text-gray-500">
{ metric.label }
</div>

<div>
{ formatMetricValue( metric.value ) }
</div>

<div className="font-normal text-sm text-gray-600">
{ metric.description }
</div>
</div>
</div>
);
}) }
</div>
</div>
<div className="my-3 bg-white p-8 border-0 rounded-lg shadow-md">
<div className="text-gray-800 font-bold text-2xl">{ optimoleDashboardApp.strings.quick_action_title }</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-5 py-5">
{quickactions.map( ( action, index ) => (
<div
className="optml__tooltip"
style={ {
left: visitorsLimitPercent + '%',
marginLeft: 15 > visitorsLimitPercent ? '-15px' : '-20px',
display: 100 < visitorsLimitPercent ? 'none' : 'block'
} }
key={index}
className="flex items-start items-center gap-3 p-4 bg-gray-100 rounded-lg hover:bg-gray-200 transition-colors"
>
<span>{ visitorsLimitPercent }%</span>
{action.icon}
<div className="flex flex-col">
<span className="font-medium text-base text-gray-800">{action.title}</span>
{ 'speedTest' === action.value ? (
<a href={action.link} target="_blank" className="text-info text-sm font-medium hover:text-info">{action.description}</a>
) : (
<Button
variant="default"
className="text-info text-sm font-medium p-0 h-5 focus:!shadow-none focus:!outline-none"
onClick={ () => action.value() }
>
{ action.description }
</Button>
) }
</div>
</div>
</div>
) )}
</div>
</div>

<div className="flex py-5 gap-5 flex-col md:flex-row">
{ metrics.map( metric => {
return (
<DashboardMetricBox
key={ metric.value }
value={ getFormattedMetric( metric.value ) }
label={ metric.label }
description={ metric.description }
icon={ metric.icon }
/>
);
})}
<div className="bg-white p-8 border-0 rounded-lg shadow-md">
{ 'yes' !== optimoleDashboardApp.remove_latest_images && (
<LastImages />
) }
</div>

{ 'yes' !== optimoleDashboardApp.remove_latest_images && (
<LastImages />
) }
</div>
</>
);
};

Expand Down
27 changes: 27 additions & 0 deletions assets/src/dashboard/utils/icons.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 22 additions & 7 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,10 @@ private function get_dashboard_strings() {
'privacy_menu' => __( 'Privacy', 'optimole-wp' ),
'testdrive_menu' => __( 'Test Optimole', 'optimole-wp' ),
'service_details' => __( 'Image optimization service', 'optimole-wp' ),
'dashboard_title' => __( 'Image Optimization Overview', 'optimole-wp' ),
'banner_title' => __( 'All images are automatically optimized!', 'optimole-wp' ),
'banner_description' => __( 'Optimole is handling all your images in real-time with our CloudFront CDN (450+ locations worldwide)', 'optimole-wp' ),
'quick_action_title' => __( 'Quick Actions' ),
'connect_btn' => __( 'Connect to Optimole', 'optimole-wp' ),
'disconnect_btn' => __( 'Disconnect', 'optimole-wp' ),
'select' => __( 'Select', 'optimole-wp' ),
Expand Down Expand Up @@ -1551,7 +1555,7 @@ private function get_dashboard_strings() {
'connecting' => __( 'CONNECTING', 'optimole-wp' ),
'not_connected' => __( 'NOT CONNECTED', 'optimole-wp' ),
'usage' => __( 'Monthly Usage', 'optimole-wp' ),
'quota' => __( 'Monthly visits quota', 'optimole-wp' ),
'quota' => __( 'Monthly visits:', 'optimole-wp' ),
'logged_in_as' => __( 'LOGGED IN AS', 'optimole-wp' ),
'private_cdn_url' => __( 'IMAGES DOMAIN', 'optimole-wp' ),
'existing_user' => __( 'Existing user?', 'optimole-wp' ),
Expand Down Expand Up @@ -1669,12 +1673,23 @@ private function get_dashboard_strings() {
'metrics' => [
'metricsTitle1' => __( 'Images optimized', 'optimole-wp' ),
'metricsSubtitle1' => __( 'Since plugin activation', 'optimole-wp' ),
'metricsTitle2' => __( 'Saved file size', 'optimole-wp' ),
'metricsSubtitle2' => __( 'For the latest 10 images', 'optimole-wp' ),
'metricsTitle3' => __( 'Average compression', 'optimole-wp' ),
'metricsSubtitle3' => __( 'During last month', 'optimole-wp' ),
'metricsTitle4' => __( 'Traffic', 'optimole-wp' ),
'metricsSubtitle4' => __( 'During last month', 'optimole-wp' ),
'metricsTitle2' => __( 'Saved File Size', 'optimole-wp' ),
'metricsSubtitle2' => __( 'Latest 10 images', 'optimole-wp' ),
'metricsTitle3' => __( 'Average Compression', 'optimole-wp' ),
'metricsSubtitle3' => __( 'Average Reduction', 'optimole-wp' ),
'metricsTitle4' => __( 'CDN Traffic', 'optimole-wp' ),
'metricsSubtitle4' => __( 'This month', 'optimole-wp' ),
],
'quick_actions' => [
'speed_test_title' => __( 'Test Your Site Speed', 'optimole-wp' ),
'speed_test_desc' => __( 'Run speed test', 'optimole-wp' ),
'speed_test_link' => add_query_arg( 'url', get_site_url(), 'https://pagespeed.web.dev/analysis' ),
'clear_cache_images' => __( 'Clear Cached Images', 'optimole-wp' ),
'clear_cache' => __( 'Clear cache', 'optimole-wp' ),
'offload_images' => __( 'Enable Offload Images', 'optimole-wp' ),
'offload_images_desc' => __( 'Free up space on your server', 'optimole-wp' ),
'advance_settings' => __( 'Advanced Settings', 'optimole-wp' ),
'configure_settings' => __( 'Configure settings', 'optimole-wp' ),
],
'options_strings' => [
'best_format_title' => __( 'Automatic Best Image Format Selection', 'optimole-wp' ),
Expand Down
Loading