Skip to content

Commit ca57c50

Browse files
refactor: use href props for Button and remove unused component
1 parent 299c02f commit ca57c50

3 files changed

Lines changed: 11 additions & 47 deletions

File tree

assets/src/dashboard/parts/components/DashboardMetricBox.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

assets/src/dashboard/parts/connected/dashboard/index.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414

1515
import { sprintf } from '@wordpress/i18n';
1616

17-
import { useSelect, select } from '@wordpress/data';
17+
import { useSelect } from '@wordpress/data';
1818
import { warning, external, help } from '@wordpress/icons';
1919

2020
import { clearCache } from '../../../utils/api';
@@ -30,7 +30,6 @@ import {
3030
} from '../../../utils/icons';
3131

3232
import ProgressBar from '../../components/ProgressBar';
33-
import DashboardMetricBox from '../../components/DashboardMetricBox';
3433

3534
import LastImages from './LastImages';
3635
import { useMemo } from 'react';
@@ -227,18 +226,13 @@ const Dashboard = () => {
227226
const getMetricButtonAction = ( metricValue ) => {
228227
switch ( metricValue ) {
229228
case 'saved_size':
230-
return () => navigate( settingsTab.advance );
229+
return { onClick: () => navigate( settingsTab.advance ) };
231230
case 'compression_percentage':
232-
return () => navigate( settingsTab.advance );
231+
return { onClick: () => navigate( settingsTab.advance ) };
233232
case 'traffic':
234-
return () => {
235-
const newWindow = window.open( 'https://dashboard.optimole.com/metrics', '_blank' );
236-
if ( newWindow ) {
237-
newWindow.focus();
238-
}
239-
};
233+
return { href: window.optimoleDashboardApp.optimoleDashMetrics, target: '_blank' };
240234
case 'offloaded_images':
241-
return () => navigate( settingsTab.offload_image );
235+
return { onClick: () => navigate( settingsTab.offload_image ) };
242236
}
243237
};
244238

@@ -326,6 +320,8 @@ const Dashboard = () => {
326320
{ metrics.map( metric => {
327321
const rawValue = userData[ metric.value ];
328322
const { formattedValue, unit } = formatMetric( metric.value, rawValue );
323+
const buttonAction = getMetricButtonAction( metric.value );
324+
const showButton = 'free' !== userData.plan && metric.hasButton;
329325

330326
return (
331327
<div
@@ -344,16 +340,16 @@ const Dashboard = () => {
344340
<span className='text-sm text-gray-500'>{unit}</span>
345341
</div>
346342

347-
<div className="font-normal text-gray-600 mb-3">
343+
<div className={ `font-normal text-gray-600 ${ showButton ? 'mb-3' : '' }` }>
348344
{ metric.description }
349345
</div>
350346

351-
{ 'free' !== userData.plan && metric.hasButton && (
347+
{ showButton && (
352348
<Button
353349
variant="secondary"
354350
size="small"
355351
className="mt-auto font-semibold rounded-md w-fit px-3 flex items-center gap-1"
356-
onClick={ getMetricButtonAction( metric.value ) }
352+
{ ...buttonAction }
357353
>
358354
{ metric.buttonText }
359355
{ ( 'traffic' === metric.value ) && (

inc/admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,7 @@ private function localize_dashboard_app() {
13681368
'optimoleHome' => tsdk_translate_link( 'https://optimole.com/' ),
13691369
'optimoleDashHome' => tsdk_translate_link( 'https://dashboard.optimole.com/', 'query' ),
13701370
'optimoleDashBilling' => tsdk_translate_link( 'https://dashboard.optimole.com/settings/billing', 'query' ),
1371+
'optimoleDashMetrics' => tsdk_translate_link( tsdk_utmify( 'https://dashboard.optimole.com/metrics', 'wp-plugin', 'shortcut' ) ),
13711372
'days_since_install' => round( ( time() - get_option( 'optimole_wp_install', 0 ) ) / DAY_IN_SECONDS ),
13721373
'is_offload_media_available' => $is_offload_media_available,
13731374
'auto_connect' => $auto_connect,

0 commit comments

Comments
 (0)