@corva/ui 0.27.0-12 → 0.27.0-13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@babel/runtime/helpers/defineProperty";import{debounce as t,identity as
|
|
1
|
+
import e from"@babel/runtime/helpers/defineProperty";import{debounce as t,identity as r}from"lodash";import n from"@babel/runtime/helpers/slicedToArray";import{jsxs as o,jsx as i}from"react/jsx-runtime";import{withStyles as a,List as l,FormControl as s,InputLabel as p,FormHelperText as u,Typography as c,TextField as d,InputAdornment as m,Chip as f}from"@material-ui/core";import{forwardRef as b,useState as y,useEffect as g,useMemo as h}from"react";import O from"@babel/runtime/helpers/objectWithoutProperties";import v from"prop-types";import{Search as x}from"@material-ui/icons";import T from"../TruncatedText/index.js";import{PER_PAGE as I,SCROLL_THRESHOLD as P}from"./constants.js";import{useAssetAutoCompleteSelectData as j}from"./effects/index.js";import{Autocomplete as A}from"@material-ui/lab";function C(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function S(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?C(Object(n),!0).forEach((function(r){e(t,r,n[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):C(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var M="DC_SingleAssetEditorAutocomplete",q={paddingLeft:"16px",height:36,listStyleType:"none",display:"flex",alignItems:"center"},w=function(e){var t=e.text;return i("li",{style:q,children:i(c,{variant:"body2",color:"textSecondary",children:void 0===t?"Loading...":t})},"loading")},L=b((function(e,t){var r=e.children,n=e.loading,a=e.hasMore,s=O(e,["children","loading","hasMore"]);return o(l,S(S({},s),{},{ref:t,role:"listbox",children:[r,(a||n)&&i(w,{})]}))})),D=function(e){var a=e["data-testid"],l=e.appKey,c=e.assetType,b=e.classes,O=e.companyId,v=e.currentValue,C=e.disabled,q=e.errorText,D=e.isMultiple,N=e.isNullable,R=e.label,V=e.onChange,E=e.parentAssetId,K=e.parentAssetType,_=e.queryParams,k=y(D?[]:null),z=n(k,2),H=z[0],B=z[1],W=y(""),F=n(W,2),G=F[0],J=F[1],Q=y(""),U=n(Q,2),X=U[0],Y=U[1],Z=y(!1),$=n(Z,2),ee=$[0],te=$[1],re=y(1),ne=n(re,2),oe=ne[0],ie=ne[1],ae=y(!0),le=n(ae,2),se=le[0],pe=le[1];g((function(){B(D?[]:null),ie(1),te(!1)}),[c]);var ue=j({appKey:l,assetType:c,companyId:O,currentValue:v,isMultiple:D,parentAssetId:E,parentAssetType:K,scrollPage:oe,searchText:G,setCurrentOption:B,queryParams:_}),ce=ue.assets,de=ue.loading;g((function(){var e=ce.length>=I*oe;pe(e)}),[ce,oe]);var me=h((function(){return t((function(e){ie(1),J(e)}),200)}),[]),fe=h((function(){return t((function(){return ie((function(e){return e+1}))}),250)}),[]),be={root:b.root,inputRoot:b.inputRoot,popupIndicator:b.popupIndicator,option:b.option,noOptions:b.noOptions,listbox:b.listbox};return o(s,{disabled:C,error:!!q,className:b.formControl,children:[!N&&i(p,{shrink:!0,children:R}),i(A,S({disabled:C,blurOnSelect:!0,classes:be,clearOnBlur:!0,clearOnEscape:!0,"data-testid":a,filterOptions:r,getOptionLabel:function(e){return null==e?void 0:e.name},getOptionSelected:function(e,t){return e&&t&&e.id===t.id},inputValue:ee?X:(null==H?void 0:H.name)||"",ListboxComponent:L,ListboxProps:{onScroll:function(e){if(se&&!de){var t=e.currentTarget;t.scrollTop+t.clientHeight>t.scrollHeight-P&&fe()}},loading:de,hasMore:se},options:ce,onChange:function(e,t){var r;B(t),V(D?t.map((function(e){return e.id})):null!==(r=null==t?void 0:t.id)&&void 0!==r?r:null,t)},onClose:function(){Y(""),J(""),te(!1),ie(1)},onInputChange:function(e,t,r){"input"===r?(Y(t),te(!0),me(t)):J("")},noOptionsText:i(w,{text:de?"Loading...":"No options"}),renderInput:function(e){return i(d,S(S({},e),{},{variant:"standard",placeholder:"Search for asset..."},!D&&{InputProps:S(S({},e.InputProps),{},{startAdornment:i(m,{children:i(x,{className:b.searchIcon})})})}))},renderOption:function(e){var t=e.id,r=e.name;return i(T,{"data-testid":"".concat(M,"_option_").concat(r,"MenuItem"),children:D&&v.includes(t)?"".concat(r," (already selected)"):r},t)},value:H,multiple:D},D&&{renderTags:function(e,t){return e.map((function(e,r){return i(f,S({label:null==e?void 0:e.name},t({index:r})),e.id)}))},getOptionDisabled:function(e){return v.includes(e.id)}})),i(u,{children:q})]})};D.defaultProps={label:"Choose An Asset",currentValue:void 0,isNullable:!1,parentAssetId:void 0,parentAssetType:void 0,companyId:void 0,errorText:"","data-testid":"".concat(M,"_autoComplete"),disabled:!1,isMultiple:!1,appKey:null,queryParams:{}},D.propTypes={label:v.string,currentValue:v.oneOfType([v.number,v.arrayOf(v.number)]),isNullable:v.bool,onChange:v.func.isRequired,classes:v.shape({}).isRequired,parentAssetId:v.number,parentAssetType:v.string,companyId:v.number,assetType:v.string.isRequired,errorText:v.string,"data-testid":v.string,disabled:v.bool,isMultiple:v.bool,appKey:v.string,queryParams:v.shape({})};var N=a((function(e){return{formControl:{},listbox:{maxHeight:350},root:{fontSize:16},inputRoot:{paddingTop:16,padding:"8px 0",paddingBottom:0,width:350,fontSize:16},popupIndicator:{display:"none"},option:{paddingLeft:"16px !important",height:36,"&[aria-disabled=true]":{color:e.palette.primary.text9,opacity:1,backgroundColor:"unset"}},noOptions:{padding:0},searchIcon:{fontSize:"20px !important"}}}))(D);export default N;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"@babel/runtime/helpers/defineProperty";import"@babel/runtime/helpers/toConsumableArray";import"moment";import"lodash";import
|
|
1
|
+
import e from"@babel/runtime/helpers/defineProperty";import"@babel/runtime/helpers/toConsumableArray";import"moment";import"lodash";import r from"@babel/runtime/helpers/slicedToArray";import"lodash/get";import"lodash/set";import t from"@babel/runtime/regenerator";import n from"@babel/runtime/helpers/asyncToGenerator";import{useState as a,useEffect as s,useRef as o}from"react";import"lodash/unset";import"../../../clients/api/apiCore.js";import"../../../clients/constants.js";import{mapAssetGetRequest as p}from"../../../clients/jsonApi/index.js";import"../../../clients/subscriptions.js";import"uuid";import{PER_PAGE as i}from"../constants.js";function c(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,n)}return t}function u(r){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){e(r,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(n,e))}))}return r}var f=function(e){return{sort:"name",order:"asc",fields:["".concat(e,".name"),"".concat(e,".asset_id")]}},l=function(e){return u(u({},e.attributes),{},{id:+e.id})};function m(o){var i=o.appKey,c=o.assetType,m=o.assetId,y=o.parentAssetType,b=o.parentAssetId,d=o.queryParams,h=a([]),O=r(h,2),j=O[0],g=O[1],v=a(!0),w=r(v,2),P=w[0],x=w[1];return s((function(){function r(){return(r=n(t.mark((function r(){var n;return t.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,p(c)(u(u(u({},f(c)),{},e({per_page:1e4},y,b),i&&{app_key:i}),d));case 2:n=r.sent,g(n.data.map(l)),x(!1);case 5:case"end":return r.stop()}}),r)})))).apply(this,arguments)}x(!0),function(){r.apply(this,arguments)}()}),[c,m,y,b,i]),{assets:j,loading:P}}function y(e){var c=e.appKey,m=e.assetType,y=e.companyId,b=e.currentValue,d=e.isMultiple,h=e.parentAssetId,O=e.parentAssetType,j=e.scrollPage,g=e.searchText,v=e.setCurrentOption,w=e.queryParams,P=a([]),x=r(P,2),k=x[0],A=x[1],T=a(!1),_=r(T,2),D=_[0],I=_[1],C=o(),q=o();return s((function(){function e(){return(e=n(t.mark((function e(){var r;return t.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,p(m)(u(u({},f(m)),{},{ids:d?b:[b]},w));case 2:r=e.sent,v((function(){if(d)return r.data.map(l);var e=r.data[0];return e?l(e):null}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}(d?b.length:b)&&function(){e.apply(this,arguments)}()}),[]),s((function(){function e(){return(e=n(t.mark((function e(){var r,n,a,s,o;return t.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,I(!0),r={per_page:i,page:j},O&&h&&(r[O]=h),y&&(r.company=y),g&&(r.search=g),c&&(r.app_key=c),n=p(m)(u(u(u({},f(m)),r),w)),q.current=n,e.next=11,n;case 11:if(a=e.sent,q.current===n){e.next=14;break}return e.abrupt("return");case 14:s=a.data.map(l),o=C.current!==m||1===j,A(o?s:function(e){return e.concat(s)}),C.current=m,e.next=23;break;case 20:e.prev=20,e.t0=e.catch(0),console.error(e.t0);case 23:I(!1);case 24:case"end":return e.stop()}}),e,null,[[0,20]])})))).apply(this,arguments)}!function(){e.apply(this,arguments)}()}),[m,O,h,y,g,j,c]),{assets:k,loading:D}}export{y as useAssetAutoCompleteSelectData,m as useAssetSelectData};
|