1 line
15 KiB
JavaScript
1 line
15 KiB
JavaScript
|
"use strict";(globalThis.webpackChunk_wcAdmin_webpackJsonp=globalThis.webpackChunk_wcAdmin_webpackJsonp||[]).push([[4011],{17666:(e,t,r)=>{r.d(t,{Z:()=>C});var o=r(69307),a=r(65736),s=r(94333),n=r(69771),i=r(9818),c=r(92819),l=r(7862),u=r.n(l),m=r(86020),d=r(67221),p=r(81921),y=r(17844),g=r(65994),h=r(10431);function _(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!e||0===e.length)return null;const o=e.slice(0),a=o.pop();if(a.showFilters(t,r)){const e=(0,h.flattenFilters)(a.filters),r=t[a.param]||a.defaultValue||"all";return(0,c.find)(e,{value:r})}return _(o,t,r)}function f(e){return t=>(0,n.format)(e,t)}class b extends o.Component{shouldComponentUpdate(e){return e.isRequesting!==this.props.isRequesting||e.primaryData.isRequesting!==this.props.primaryData.isRequesting||e.secondaryData.isRequesting!==this.props.secondaryData.isRequesting||!(0,c.isEqual)(e.query,this.props.query)}getItemChartData(){const{primaryData:e,selectedChart:t}=this.props;return e.data.intervals.map((function(e){const r={};return e.subtotals.segments.forEach((function(e){if(e.segment_label){const o=r[e.segment_label]?e.segment_label+" (#"+e.segment_id+")":e.segment_label;r[e.segment_id]={label:o,value:e.subtotals[t.key]||0}}})),{date:(0,n.format)("Y-m-d\\TH:i:s",e.date_start),...r}}))}getTimeChartData(){const{query:e,primaryData:t,secondaryData:r,selectedChart:o,defaultDateRange:a}=this.props,s=(0,p.getIntervalForQuery)(e,a),{primary:i,secondary:c}=(0,p.getCurrentDates)(e,a);return t.data.intervals.map((function(t,a){const l=(0,p.getPreviousDate)(t.date_start,i.after,c.after,e.compare,s),u=r.data.intervals[a];return{date:(0,n.format)("Y-m-d\\TH:i:s",t.date_start),primary:{label:`${i.label} (${i.range})`,labelDate:t.date_start,value:t.subtotals[o.key]||0},secondary:{label:`${c.label} (${c.range})`,labelDate:l.format("YYYY-MM-DD HH:mm:ss"),value:u&&u.subtotals[o.key]||0}}}))}getTimeChartTotals(){const{primaryData:e,secondaryData:t,selectedChart:r}=this.props;return{primary:(0,c.get)(e,["data","totals",r.key],null),secondary:(0,c.get)(t,["data","totals",r.key],null)}}renderChart(e,t,r,s){const{emptySearchResults:n,filterParam:i,interactiveLegend:c,itemsLabel:l,legendPosition:u,path:y,query:g,selectedChart:h,showHeaderControls:_,primaryData:b,defaultDateRange:C}=this.props,v=(0,p.getIntervalForQuery)(g,C),w=(0,p.getAllowedIntervalsForQuery)(g,C),R=(0,p.getDateFormatsForInterval)(v,b.data.intervals.length,{type:"php"}),q=n?(0,a.__)("No data for the current search","woocommerce"):(0,a.__)("No data for the selected date range","woocommerce"),{formatAmount:E,getCurrencyConfig:D}=this.context;return(0,o.createElement)(m.Chart,{allowedIntervals:w,data:r,dateParser:"%Y-%m-%dT%H:%M:%S",emptyMessage:q,filterParam:i,interactiveLegend:c,interval:v,isRequesting:t,itemsLabel:l,legendPosition:u,legendTotals:s,mode:e,path:y,query:g,screenReaderFormat:f(R.screenReaderFormat),showHeaderControls:_,title:h.label,tooltipLabelFormat:f(R.tooltipLabelFormat),tooltipTitle:"time-comparison"===e&&h.label||null,tooltipValueFormat:(0,d.getTooltipValueFormat)(h.type,E),chartType:(0,p.getChartTypeForQuery)(g),valueType:h.type,xFormat:f(R.xFormat),x2Format:f(R.x2Format),currency:D()})}renderItemComparison(){const{isRequesting:e,primaryData:t}=this.props;if(t.isError)return(0,o.createElement)(g.Z,null);const r=e||t.isRequesting,a=this.getItemChartData();return this.renderChart("item-comparison",r,a)}renderTimeComparison(){const{isRequesting:e,primaryData:t,secondaryData:r}=this.props;if(!t||t.isError||r.isError)return(0,o.createElement)(g.Z,null);const a=e||t.isRequesting||r.isRequesting,s=this.getTimeChartData(),n=this.getTimeChartTotals();return this.renderChart("time-comparison",a,s,n)}render(){const{mode:e}=this.props;return"item-comparison"===e?this.renderItemComparison():this.renderTimeComparison()}}b.contextType=y.CurrencyContext,b.propTypes={filters:u().array,isRequesting:u().bool,itemsLabel:u().string,limitProperties:u().array,mode:u().string,path:u().string.isRequired,primaryData:u().object,query:u().object.isRequired,secondaryData:u().object,selec
|