@@ -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
1717import { 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+
6475const 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 ) ;
0 commit comments