woocommerce/packages/woocommerce-admin/dist/chunks/analytics-settings.js

1 line
17 KiB
JavaScript
Raw Normal View History

2021-12-10 12:03:04 +00:00
(window.__wcAdmin_webpackJsonp=window.__wcAdmin_webpackJsonp||[]).push([[17],{38:function(e,t){e.exports=function(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e},e.exports.default=e.exports,e.exports.__esModule=!0},546:function(e,t,a){},547:function(e,t,a){},548:function(e,t,a){},614:function(e,t,a){"use strict";a.r(t);var o=a(35),r=a.n(o),s=a(0),c=a(2),i=a(3),n=a(14),m=a(7),l=a(21),d=a(11),p=a(16),u=(a(546),a(255)),b=a(38),h=a.n(b),_=a(1),g=a.n(_),O=a(4);a(547);class j extends s.Component{constructor(e){super(e),h()(this,"renderInput",()=>{const{handleChange:e,name:t,inputText:a,inputType:o,options:c,value:n,component:m}=this.props,{disabled:l}=this.state;switch(o){case"checkboxGroup":return c.map(e=>e.options.length>0&&Object(s.createElement)("div",{className:"woocommerce-setting__options-group",key:e.key,"aria-labelledby":t+"-label"},e.label&&Object(s.createElement)("span",{className:"woocommerce-setting__options-group-label"},e.label),this.renderCheckboxOptions(e.options)));case"checkbox":return this.renderCheckboxOptions(c);case"button":return Object(s.createElement)(i.Button,{isSecondary:!0,onClick:this.handleInputCallback,disabled:l},a);case"component":const o=m;return Object(s.createElement)(o,r()({value:n,onChange:e},this.props));case"text":default:const d=Object(O.uniqueId)(t);return Object(s.createElement)("input",{id:d,type:"text",name:t,onChange:e,value:n,placeholder:a,disabled:l})}}),h()(this,"handleInputCallback",()=>{const{createNotice:e,callback:t}=this.props;if("function"==typeof t)return new Promise((a,o)=>{this.setState({disabled:!0}),t(a,o,e)}).then(()=>{this.setState({disabled:!1})}).catch(()=>{this.setState({disabled:!1})})}),this.state={disabled:!1}}renderCheckboxOptions(e){const{handleChange:t,name:a,value:o}=this.props,{disabled:r}=this.state;return e.map(e=>Object(s.createElement)(i.CheckboxControl,{key:a+"-"+e.value,label:e.label,name:a,checked:o&&o.includes(e.value),onChange:o=>t({target:{checked:o,name:a,type:"checkbox",value:e.value}}),disabled:r}))}render(){const{helpText:e,label:t,name:a}=this.props;return Object(s.createElement)("div",{className:"woocommerce-setting"},Object(s.createElement)("div",{className:"woocommerce-setting__label",id:a+"-label"},t),Object(s.createElement)("div",{className:"woocommerce-setting__input"},this.renderInput(),e&&Object(s.createElement)("span",{className:"woocommerce-setting__help"},e)))}}j.propTypes={callback:g.a.func,handleChange:g.a.func.isRequired,helpText:g.a.oneOfType([g.a.string,g.a.array]),inputText:g.a.string,inputType:g.a.oneOf(["button","checkbox","checkboxGroup","text","component"]),label:g.a.string.isRequired,name:g.a.string.isRequired,options:g.a.arrayOf(g.a.shape({value:g.a.string,label:g.a.string,description:g.a.string,key:g.a.string,options:g.a.array})),value:g.a.oneOfType([g.a.string,g.a.array])};var w=Object(n.compose)(Object(m.withDispatch)(e=>{const{createNotice:t}=e("core/notices");return{createNotice:t}}))(j),v=a(9),I=a.n(v);const S=(e,t,a)=>{const o={};if(a&&(o.skip_existing=!0),"all"!==t.label)if("custom"===t.label){const a=I()().diff(I()(t.date,e),"days",!0);o.days=Math.floor(a)}else o.days=parseInt(t.label,10);return o};var E=a(15);var k=Object(n.compose)([Object(m.withSelect)(e=>{const{getFormSettings:t}=e(d.IMPORT_STORE_NAME),{period:a,skipPrevious:o}=t();return{selectedPeriod:a,skipChecked:o}}),Object(m.withDispatch)(e=>{const{updateImportation:t,setImportStarted:a}=e(d.IMPORT_STORE_NAME),{createNotice:o}=e("core/notices");return{createNotice:o,setImportStarted:a,updateImportation:t}})])((function({clearStatusAndTotalsCache:e,createNotice:t,dateFormat:a,importDate:o,onImportStarted:r,selectedPeriod:n,stopImport:m,skipChecked:l,status:d,setImportStarted:u,updateImportation:b}){const h=()=>{const e=Object(E.addQueryArgs)("/wc-analytics/reports/import",S(a,n,l)),t=Object(c.__)("There was a problem rebuilding your report data.",'woocommerce');g(e,t,!0),r()},_=()=>{m();const e=Object(c.__)("There was a problem stopping your current import.",'woocommerce');g("/wc-analyt