← Back
Editing: store-performance.js
"use strict";(globalThis.webpackChunk_wcAdmin_webpackJsonp=globalThis.webpackChunk_wcAdmin_webpackJsonp||[]).push([[6115],{67403:(e,r,t)=>{t.r(r),t.d(r,{default:()=>b});var o=t(27723),n=t(86087),a=t(29491),s=t(96476),i=t(47143),c=t(98846),m=t(77374),d=t(83306),l=t(94111),u=t(85186),p=t(70288),h=t(40314),f=t(39793);const g={effects:{spotlight:{interactivity:{enabled:!0,rootElementSelector:"#wpwrap"}},arrowIndicator:!0,autoScroll:{behavior:"auto",block:"center"},liveResize:{mutation:!0,resize:!0,rootElementSelector:"#wpwrap"}}},y=({hasOpenedMenu:e})=>{const{updateUserPreferences:r,isRequesting:t,dashboard_performance_tour_shown:a}=(0,h.useUserPreferences)(),s=!t&&"yes"!==a,i=s&&!e,m=(0,n.useRef)(!1),l=e=>{(0,d.recordEvent)("dash_indicators_tour_dismiss",{source:e}),r({dashboard_performance_tour_shown:"yes"})};if((0,n.useEffect)(()=>{i&&!m.current&&(m.current=!0,(0,d.recordEvent)("dash_indicators_tour_view"))},[i]),(0,n.useEffect)(()=>{e&&s&&l("menu")},[e,s]),!i)return null;const u={steps:[{referenceElements:{desktop:".woocommerce-dashboard__performance-menu .woocommerce-ellipsis-menu__toggle"},meta:{name:"performance-metrics",heading:(0,o.__)("Choose which metrics to display","woocommerce"),descriptions:{desktop:(0,o.__)("Some are hidden by default. Add or remove them from this menu.","woocommerce")},primaryButton:{text:(0,o.__)("Got it","woocommerce")}}}],closeHandler:(e,r,t)=>l(t),options:g};return(0,f.jsx)(c.TourKit,{config:u})},{performanceIndicators:_}=(0,p.Qk)("dataEndpoints",{performanceIndicators:[]});class w extends n.Component{constructor(e){super(e),this.state={hasOpenedMenu:!1},this.onToggleMenu=this.onToggleMenu.bind(this)}onToggleMenu(){this.setState({hasOpenedMenu:!0})}renderMenu(){const{hiddenBlocks:e,isFirst:r,isLast:t,onMove:a,onRemove:s,onTitleBlur:i,onTitleChange:m,onToggleHiddenBlock:l,titleInput:u,controls:p}=this.props;return(0,f.jsx)(c.EllipsisMenu,{className:"woocommerce-dashboard__performance-menu",onToggle:this.onToggleMenu,label:(0,o.__)("Choose which analytics to display and the section name","woocommerce"),placement:"bottom-end",renderContent:({onToggle:h})=>(0,f.jsxs)(n.Fragment,{children:[(0,f.jsx)(c.MenuTitle,{children:(0,o.__)("Display stats:","woocommerce")}),_.map((r,t)=>{const o=!e.includes(r.stat);return(0,f.jsx)(c.MenuItem,{checked:o,isCheckbox:!0,isClickable:!0,onInvoke:()=>{l(r.stat)(),(0,d.recordEvent)("dash_indicators_toggle",{status:o?"off":"on",key:r.stat})},children:r.label},t)}),(0,f.jsx)(p,{onToggle:h,onMove:a,onRemove:s,isFirst:r,isLast:t,onTitleBlur:i,onTitleChange:m,titleInput:u})]})})}renderList(){const{query:e,primaryRequesting:r,secondaryRequesting:t,primaryError:n,secondaryError:a,primaryData:i,secondaryData:l,userIndicators:p,defaultDateRange:h}=this.props;if(r||t)return(0,f.jsx)(c.SummaryListPlaceholder,{numberOfItems:p.length});if(n||a)return null;const g=(0,s.getPersistedQuery)(e),{compare:y}=(0,m.getDateParamsFromQuery)(e,h),_="previous_period"===y?(0,o.__)("Previous period:","woocommerce"):(0,o.__)("Previous year:","woocommerce"),{formatAmount:w,getCurrencyConfig:b}=this.context,k=b();return(0,f.jsx)(c.SummaryList,{children:()=>p.map((e,r)=>{const{primaryValue:t,secondaryValue:o,delta:n,reportUrl:a,reportUrlType:s}=(0,u.w)({indicator:e,primaryData:i,secondaryData:l,currency:k,formatAmount:w,persistedQuery:g});return(0,f.jsx)(c.SummaryNumber,{href:a,hrefType:s,label:e.label,value:t,prevLabel:_,prevValue:o,delta:n,onLinkClickCallback:()=>{(0,d.recordEvent)("dash_indicators_click",{key:e.stat})}},r)})})}render(){const{userIndicators:e,title:r}=this.props;return(0,f.jsxs)(n.Fragment,{children:[(0,f.jsx)(c.SectionHeader,{title:r||(0,o.__)("Store Performance","woocommerce"),menu:this.renderMenu()}),e.length>0&&(0,f.jsx)("div",{className:"woocommerce-dashboard__store-performance",children:this.renderList()}),(0,f.jsx)(y,{hasOpenedMenu:this.state.hasOpenedMenu})]})}}w.contextType=l.CurrencyContext;const b=(0,a.compose)((0,i.withSelect)((e,r)=>{const{hiddenBlocks:t,query:o,filters:n}=r,a=_.filter(e=>!t.includes(e.stat)),s={hiddenBlocks:t,userIndicators:a,indicators:_};if(0===a.length)return s;const i=(0,u.m)(e,a,o,n);return{...s,...i}}))(w)},85186:(e,r,t)=>{t.d(r,{m:()=>d,w:()=>m});var o=t(66087),n=t(77374),a=t(40314),s=t(96476),i=t(43577),c=t(15703);const m=({indicator:e,primaryData:r,secondaryData:t,currency:n,formatAmount:a,persistedQuery:m})=>{const d=(0,o.find)(r.data,r=>r.stat===e.stat),l=(0,o.find)(t.data,r=>r.stat===e.stat);if(!d||!l)return{};const u=d._links&&d._links.report[0]&&d._links.report[0].href||"",p=function(e,r,t){return e?"/jetpack"===e?(0,c.getAdminLink)("admin.php?page=jetpack#/dashboard"):(0,s.getNewPath)(r,e,{chart:t.chart}):""}(u,m,d),h="/jetpack"===u?"wp-admin":"wc-admin",f="currency"===d.format,g=(0,i.calculateDelta)(d.value,l.value);return{primaryValue:f?a(d.value):(0,i.formatValue)(n,d.format,d.value),secondaryValue:f?a(l.value):(0,i.formatValue)(n,l.format,l.value),delta:g,reportUrl:p,reportUrlType:h}},d=(e,r,t,o)=>{const{getReportItems:s,getReportItemsError:i,isResolving:c}=e(a.reportsStore),{woocommerce_default_date_range:m}=e(a.settingsStore).getSetting("wc_admin","wcAdminSettings"),d=(0,n.getCurrentDates)(t,m),l=d.primary.before,u=d.secondary.before,p=r.map(e=>e.stat).join(","),h=(0,a.getFilterQuery)({filters:o,query:t}),f={...h,after:(0,n.appendTimestamp)(d.primary.after,"start"),before:(0,n.appendTimestamp)(l,l.isSame((0,n.getStoreTimeZoneMoment)(),"day")?"now":"end"),stats:p},g={...h,after:(0,n.appendTimestamp)(d.secondary.after,"start"),before:(0,n.appendTimestamp)(u,u.isSame((0,n.getStoreTimeZoneMoment)(),"day")?"now":"end"),stats:p};return{primaryData:s("performance-indicators",f),primaryError:i("performance-indicators",f)||null,primaryRequesting:c("getReportItems",["performance-indicators",f]),secondaryData:s("performance-indicators",g),secondaryError:i("performance-indicators",g)||null,secondaryRequesting:c("getReportItems",["performance-indicators",g]),defaultDateRange:m}}}}]);
Save File
Cancel