Skip to content

Commit 01d007d

Browse files
feat: add offload metric and pro redirect feature
1 parent 4870d3b commit 01d007d

2 files changed

Lines changed: 58 additions & 10 deletions

File tree

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

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {
1111
Icon
1212
} from '@wordpress/components';
1313

14-
import { useSelect } from '@wordpress/data';
15-
import { warning } from '@wordpress/icons';
14+
import { useSelect, select } from '@wordpress/data';
15+
import { warning, external } from '@wordpress/icons';
1616

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

@@ -37,22 +37,30 @@ const metrics = [
3737
{
3838
label: optimoleDashboardApp.strings.metrics.metricsTitle2,
3939
description: optimoleDashboardApp.strings.metrics.metricsSubtitle2,
40-
value: 'saved_size'
40+
value: 'saved_size',
41+
hasButton: true,
42+
buttonText: optimoleDashboardApp.strings.metrics.adjust_compression
4143
},
4244
{
4345
label: optimoleDashboardApp.strings.metrics.metricsTitle3,
4446
description: optimoleDashboardApp.strings.metrics.metricsSubtitle3,
45-
value: 'compression_percentage'
47+
value: 'compression_percentage',
48+
hasButton: true,
49+
buttonText: optimoleDashboardApp.strings.metrics.adjust_compression
4650
},
4751
{
4852
label: optimoleDashboardApp.strings.metrics.metricsTitle4,
4953
description: optimoleDashboardApp.strings.metrics.metricsSubtitle4,
50-
value: 'traffic'
54+
value: 'traffic',
55+
hasButton: true,
56+
buttonText: optimoleDashboardApp.strings.metrics.view_analytics
5157
},
5258
{
5359
label: optimoleDashboardApp.strings.metrics.metricsTitle5,
5460
description: optimoleDashboardApp.strings.metrics.metricsSubtitle5,
55-
value: 'offloaded_images'
61+
value: 'offloaded_images',
62+
hasButton: true,
63+
buttonText: optimoleDashboardApp.strings.metrics.manage_offloading
5664
}
5765
];
5866

@@ -61,6 +69,9 @@ const settingsTab = {
6169
advance: 2
6270
};
6371

72+
const { getUserData } = select( 'optimole' );
73+
const user = getUserData();
74+
6475
const navigate = ( tabId ) => {
6576
const links = window.optimoleDashboardApp.submenu_links;
6677
const settingsLink = links.find( link => '#settings' === link.hash );
@@ -202,6 +213,24 @@ const Dashboard = () => {
202213
return { formattedValue, unit };
203214
};
204215

216+
const getMetricButtonAction = ( metricValue ) => {
217+
switch ( metricValue ) {
218+
case 'saved_size':
219+
return () => navigate( settingsTab.advance );
220+
case 'compression_percentage':
221+
return () => navigate( settingsTab.advance );
222+
case 'traffic':
223+
return () => {
224+
const newWindow = window.open( 'https://dashboard.optimole.com/metrics', '_blank' );
225+
if ( newWindow ) {
226+
newWindow.focus();
227+
}
228+
};
229+
case 'offloaded_images':
230+
return () => navigate( settingsTab.offload_image );
231+
}
232+
};
233+
205234
return (
206235
<div className="grid gap-5">
207236
<div className="bg-white p-8 border-0 rounded-lg shadow-md">
@@ -270,9 +299,25 @@ const Dashboard = () => {
270299
<span className='text-sm text-gray-500'>{unit}</span>
271300
</div>
272301

273-
<div className="font-normal text-gray-600">
302+
<div className="font-normal text-gray-600 mb-3">
274303
{ metric.description }
275304
</div>
305+
306+
307+
{ 'free' !== user.plan && metric.hasButton && (
308+
<Button
309+
variant="secondary"
310+
size="small"
311+
className="mt-auto font-semibold rounded-md w-fit px-3 flex items-center gap-1"
312+
onClick={ getMetricButtonAction( metric.value ) }
313+
>
314+
{ metric.buttonText }
315+
{ ( 'traffic' === metric.value ) && (
316+
<Icon icon={ external } size={ 16 } />
317+
) }
318+
</Button>
319+
) }
320+
276321
</div>
277322
</div>
278323
);

inc/admin.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1697,9 +1697,12 @@ private function get_dashboard_strings() {
16971697
'metricsTitle4' => __( 'CDN Traffic', 'optimole-wp' ),
16981698
'metricsSubtitle4' => __( 'This month', 'optimole-wp' ),
16991699
'metricsTitle5' => __( 'Offloaded images', 'optimole-wp' ),
1700-
'metricsSubtitle5' => __( 'Offloaded to cloud', 'optimole-wp'),
1701-
'image' => __( 'image', 'optimole-wp' ),
1702-
'images' => __( 'images', 'optimole-wp' ),
1700+
'metricsSubtitle5' => __( 'Offloaded to cloud', 'optimole-wp' ),
1701+
'image' => __( 'image', 'optimole-wp' ),
1702+
'images' => __( 'images', 'optimole-wp' ),
1703+
'view_analytics' => __( 'View Analytics', 'optimole-wp' ),
1704+
'adjust_compression' => __( 'Adjust Compression', 'optimole-wp' ),
1705+
'manage_offloading' => __( 'Manage image offloading', 'optimole-wp' ),
17031706
],
17041707
'quick_actions' => [
17051708
'speed_test_title' => __( 'Test Your Site Speed', 'optimole-wp' ),

0 commit comments

Comments
 (0)