@@ -13,7 +13,7 @@ import {
1313} from '@wordpress/components' ;
1414
1515import { sprintf } from '@wordpress/i18n' ;
16-
16+ import { useMemo } from '@wordpress/element' ;
1717import { useSelect } from '@wordpress/data' ;
1818import { warning , external , help } from '@wordpress/icons' ;
1919
@@ -36,50 +36,9 @@ import {
3636import ProgressBar from '../../components/ProgressBar' ;
3737
3838import LastImages from './LastImages' ;
39- import { useMemo } from 'react' ;
4039
4140const cardClasses = 'flex p-6 bg-light-blue border border-blue-300 rounded-md' ;
4241
43- const metrics = [
44- {
45- icon : arrowDownToLine ,
46- label : optimoleDashboardApp . strings . metrics . metricsTitle2 ,
47- description : optimoleDashboardApp . strings . metrics . metricsSubtitle2 ,
48- value : 'saved_size' ,
49- hasButton : true ,
50- buttonText : optimoleDashboardApp . strings . metrics . adjust_compression
51- } ,
52- {
53- icon : chartBarDecreasing ,
54- label : optimoleDashboardApp . strings . metrics . metricsTitle3 ,
55- description : optimoleDashboardApp . strings . metrics . metricsSubtitle3 ,
56- value : 'compression_percentage' ,
57- hasButton : true ,
58- buttonText : optimoleDashboardApp . strings . metrics . adjust_compression
59- } ,
60- {
61- icon : globe ,
62- label : optimoleDashboardApp . strings . metrics . metricsTitle4 ,
63- description : optimoleDashboardApp . strings . metrics . metricsSubtitle4 ,
64- value : 'traffic' ,
65- hasButton : true ,
66- buttonText : optimoleDashboardApp . strings . metrics . view_analytics
67- }
68- ] ;
69-
70- if ( optimoleDashboardApp . user_data ?. can_use_offloading ) {
71- metrics . push (
72- {
73- icon : cloudDownload ,
74- label : optimoleDashboardApp . strings . metrics . metricsTitle5 ,
75- description : optimoleDashboardApp . strings . metrics . metricsSubtitle5 ,
76- value : 'offloaded_images' ,
77- hasButton : true ,
78- buttonText : optimoleDashboardApp . strings . metrics . manage_offloading
79- }
80- ) ;
81- }
82-
8342const settingsTab = {
8443 offload_image : 1 ,
8544 advance : 2
@@ -166,6 +125,50 @@ const Dashboard = () => {
166125 } ;
167126 } ) ;
168127
128+ const availableMetrics = useMemo ( ( ) => {
129+ const metrics = [
130+ {
131+ icon : arrowDownToLine ,
132+ label : optimoleDashboardApp . strings . metrics . metricsTitle2 ,
133+ description : optimoleDashboardApp . strings . metrics . metricsSubtitle2 ,
134+ value : 'saved_size' ,
135+ hasButton : true ,
136+ buttonText : optimoleDashboardApp . strings . metrics . adjust_compression
137+ } ,
138+ {
139+ icon : chartBarDecreasing ,
140+ label : optimoleDashboardApp . strings . metrics . metricsTitle3 ,
141+ description : optimoleDashboardApp . strings . metrics . metricsSubtitle3 ,
142+ value : 'compression_percentage' ,
143+ hasButton : true ,
144+ buttonText : optimoleDashboardApp . strings . metrics . adjust_compression
145+ } ,
146+ {
147+ icon : globe ,
148+ label : optimoleDashboardApp . strings . metrics . metricsTitle4 ,
149+ description : optimoleDashboardApp . strings . metrics . metricsSubtitle4 ,
150+ value : 'traffic' ,
151+ hasButton : true ,
152+ buttonText : optimoleDashboardApp . strings . metrics . view_analytics
153+ }
154+ ] ;
155+
156+ if ( userData ?. can_use_offloading ) {
157+ metrics . push (
158+ {
159+ icon : cloudDownload ,
160+ label : optimoleDashboardApp . strings . metrics . metricsTitle5 ,
161+ description : optimoleDashboardApp . strings . metrics . metricsSubtitle5 ,
162+ value : 'offloaded_images' ,
163+ hasButton : true ,
164+ buttonText : optimoleDashboardApp . strings . metrics . manage_offloading
165+ }
166+ ) ;
167+ }
168+
169+ return metrics ;
170+ } , [ userData ] ) ;
171+
169172 const visitorsLimitPercent = ( ( userData . visitors / userData . visitors_limit ) * 100 ) . toFixed ( 0 ) ;
170173
171174 const renewalDate = useMemo ( ( ) => {
@@ -332,7 +335,7 @@ const Dashboard = () => {
332335 </ div >
333336
334337 < div className = "flex pt-5 gap-5 flex-col md:flex-row" >
335- { metrics . map ( metric => {
338+ { availableMetrics . map ( metric => {
336339 const rawValue = userData [ metric . value ] ;
337340 const { formattedValue, unit } = formatMetric ( metric . value , rawValue ) ;
338341 const buttonAction = getMetricButtonAction ( metric . value ) ;
0 commit comments