@gisce/react-ooui 1.1.0 → 1.1.1

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.
@@ -112,7 +112,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
112
112
  .ant-progress-text {
113
113
  display: none;
114
114
  }
115
- `,booleanComponentFn=e=>jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:jsxRuntime.jsx(antd.Checkbox,{checked:e,disabled:!0})}),many2OneComponentFn=e=>e?jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.value}),jsxRuntime.jsx(Many2oneSuffix,{id:e.id,model:e.model})]}):jsxRuntime.jsx(jsxRuntime.Fragment,{}),textComponentFn=e=>jsxRuntime.jsx("div",{style:{whiteSpace:"pre-line"},children:e}),one2ManyComponentFn=e=>{const n=Array.isArray(e==null?void 0:e.items)?e==null?void 0:e.items.length:0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:`( ${n} )`})},progressBarComponentFn=e=>jsxRuntime.jsx(ProgressBarInput,{value:e}),floatTimeComponent=e=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:parseFloatToString(e)}),numberComponent=e=>jsxRuntime.jsx("div",{style:{textAlign:"right"},children:e}),imageComponent=e=>jsxRuntime.jsx("img",{src:`data:image/*;base64,${e}`,style:{maxWidth:"50px",padding:"5px"}});function Tree(e){const{page:n=1,limit:t,total:o,treeView:r,results:a,onRequestPageChange:s,loading:l,onRowClicked:c,showPagination:u=!0,rowSelection:d,scrollY:f,colorsForResults:m={},onChangeSort:p,sorter:I,onFetchChildrenForRecord:v,childField:y}=e,[g,h]=React.useState([]),[x,C]=React.useState([]),O=React.useRef(!1),w=React.useRef(null),{t:S}=React.useContext(LocaleContext);React.useEffect(()=>{w.current=getTree(r);const B=getTableColumns(w.current,{boolean:booleanComponentFn,many2one:many2OneComponentFn,text:textComponentFn,one2many:one2ManyComponentFn,many2many:one2ManyComponentFn,progressbar:progressBarComponentFn,float_time:floatTimeComponent,image:imageComponent,integer:numberComponent,float:numberComponent});C(B)},[r]),React.useEffect(()=>{O.current=!1;const B=getTableItems(w.current,a);h(B)},[a]);const b=(n-1)*t+1,F=b-1+g.length,_=o===void 0?null:o===0?S("no_results"):S("summary").replace("{from}",b==null?void 0:b.toString()).replace("{to}",F==null?void 0:F.toString()).replace("{total}",o==null?void 0:o.toString()),k=()=>!u||r.isExpandable||l?null:o===void 0?jsxRuntime.jsx(antd.Spin,{}):jsxRuntime.jsxs(antd.Row,{align:"bottom",className:"pb-4",children:[jsxRuntime.jsx(antd.Col,{span:12,children:jsxRuntime.jsx(antd.Pagination,{total:o,pageSize:t,current:n,showSizeChanger:!1,onChange:s})}),jsxRuntime.jsx(antd.Col,{span:12,className:"text-right",children:_})]});function L(){var H;const N=w.current.columns.filter(Y=>Y.sum!==void 0).map(Y=>({label:Y.sum,field:Y.id}));if(!N||N.length===0)return null;let $=[],D=((H=d==null?void 0:d.selectedRowKeys)==null?void 0:H.length)>0?g.filter(Y=>d==null?void 0:d.selectedRowKeys.includes(Y.id)):g;return N.forEach(Y=>{const G=D.reduce((U,Z)=>Z[Y.field]&&!isNaN(Z[Y.field])?U+Z[Y.field]:U,0);$.push(`${Y.label}: ${Math.round(G*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:$.join(", ")})}let M,j=f;if(w.current!==null){M=calculateColumnsWidth(x,g,600);const N=w.current;f&&N.columns.some($=>$.sum!==void 0)&&(j=f-30)}return w.current===null?jsxRuntime.jsx(antd.Spin,{style:{padding:"2rem"}}):jsxRuntime.jsxs("div",{children:[k(),jsxRuntime.jsx(reactFormigaTable.Table,{height:j,columns:M.columns,dataSource:g,loading:l,loadingComponent:jsxRuntime.jsx(antd.Spin,{}),onRowStyle:B=>{if(m[B.id])return{color:m[B.id]}},onRowDoubleClick:c,onRowSelectionChange:d==null?void 0:d.onChange,onChangeSort:p,sorter:I,expandableOpts:v?{expandIcon:Icon.PlusSquareOutlined,collapseIcon:Icon.MinusSquareOutlined,loadingIcon:Icon.LoadingOutlined,onFetchChildrenForRecord:v,childField:y}:void 0}),L()]})}const DEFAULT_SEARCH_LIMIT$1=80,useSearch=e=>{const{model:n,setSearchTreeNameSearch:t,setSelectedRowItems:o,setSearchParams:r,setSearchVisible:a,setTreeIsLoading:s,nameSearch:l,searchNameGetDoneRef:c,context:u,setActionViewTotalItems:d,treeView:f,formView:m,sorter:p,setSorter:I,setCurrentItemIndex:v,setResultsActionView:y,resultsActionView:g,domain:h,currentId:x,limitFromAction:C,limit:O,setLimit:w,searchParams:S=[],setSearchValues:b}=e,[F,_]=React.useState(!1),[k,L]=React.useState(!1),[M,j]=React.useState(),[B,N]=React.useState(1),[$,D]=React.useState(0),[H,Y]=React.useState(),[G,U]=React.useState([]),[Z,V]=React.useState(void 0),z=React.useRef([]),E=React.useRef(80),A=React.useRef([]),q=React.useCallback(J=>{y==null||y([...J]),U([...J])},[]),K=React.useCallback(()=>g||G,[g,G]),Q=React.useCallback(async()=>{const J=await ConnectionProvider.getHandler().nameSearch({model:n,payload:l,limit:E.current,attrs:A.current.length>0?A.current:h,context:u});if(Y(J.length),d==null||d(J.length),J.length>0){const se=J.map(ve=>ve==null?void 0:ve[0]),{colors:ae}=getTree(f),me=await ConnectionProvider.getHandler().readEvalUiObjects({model:n,ids:se,arch:f==null?void 0:f.arch,fields:f.field_parent?{...f.fields,[f.field_parent]:{}}:f.fields,context:u,attrs:ae&&{colors:ae}}),oe=me[0];z.current=[...oe],V(getColorMap(me[1]));const pe=oe.map(ve=>ve.id),ue=p!==void 0?sortResults({resultsToSort:oe,sorter:p,fields:{...f.fields,...m.fields}}):[...z.current];q(ue),pe.length>0?v==null||v(0):v==null||v(void 0)}else q([]),v==null||v(void 0);c.current=!0},[q,c,l,n,u,h,f,m,p,v,d,E,A]),P=React.useCallback(async()=>{const J=A.current.length>0?A.current:h,se=mergeParams(S,J),{colors:ae}=getTree(f),{totalItems:me,results:oe,attrsEvaluated:pe}=await ConnectionProvider.getHandler().searchForTree({params:se,limit:O,offset:$,model:n,fields:f.field_parent?{...f.fields,[f.field_parent]:{}}:f.fields,context:u,attrs:ae&&{colors:ae}});V(getColorMap(pe)),z.current=[...oe];const ue=p!==void 0?sortResults({resultsToSort:oe,sorter:p,fields:{...f.fields,...m.fields}}):[...z.current];if(q(ue),g&&ue.length>0){const Ie=ue.findIndex(ye=>x===ye.id);Ie===-1?v==null||v(0):v==null||v(Ie)}else v==null||v(void 0);const ve=await me;Y(ve),d==null||d(ve)},[v,g,q,x,n,u,h,f,m,p,d,O,$,A,S]),T=React.useCallback(async()=>{try{_(!0),s==null||s(!0),l&&!c.current?await Q():await P()}catch(J){j(J.message)}finally{_(!1),L(!1),s==null||s(!1)}},[A,u,x,h,m,E,O,n,l,$,g,c,d,v,q,j,L,_,s,p,f]),W=React.useCallback(J=>{I==null||I(J);const se=J!==void 0?sortResults({resultsToSort:K(),sorter:J,fields:{...f.fields,...m.fields}}):[...z.current];q(se)},[I,K,f,m,q]),X=React.useCallback(({params:J,limit:se,offset:ae,searchValues:me})=>{F||(t==null||t(void 0),o==null||o([]),b==null||b(me),r==null||r(J),a==null||a(!1),L(!0),j(void 0),N(1),se&&(w==null||w(se)),ae&&D(ae),T())},[F,t,o,r,a,L,j,N,w,D,T]),ee=React.useCallback(J=>{_(!0),N(J),D((J-1)*O)},[_,O,D,N]),ne=React.useCallback(()=>{F||(t==null||t(void 0),r==null||r([]),b==null||b({}),j(void 0),D(0),N(1),w==null||w(C||DEFAULT_SEARCH_LIMIT$1))},[F,t,r,j,D,N,w,C]),ie=React.useCallback(async J=>{const se=J[(f==null?void 0:f.field_parent)||"child_id"],ae=await ConnectionProvider.getHandler().readObjects({model:n,ids:se,fields:f.field_parent?{...f.fields,[f.field_parent]:{}}:f.fields,context:u});return q([...K(),...ae]),getTableItems(getTree(f),ae)},[f,n,u,K,q]);return{submit:X,clear:ne,fetchResults:T,tableRefreshing:F,searchFilterLoading:k,searchError:M,page:B,offset:$,limit:O,getResults:K,requestPageChange:ee,changeSort:W,fetchChildrenForRecord:ie,colorsForResults:Z,totalItems:H}};function SearchTree(e,n){const{action:t,model:o,formView:r,treeView:a,onRowClicked:s,nameSearch:l,treeScrollY:c,domain:u=[],visible:d=!0,rootTree:f=!1,parentContext:m={},onChangeSelectedRowKeys:p}=e,[I,v]=React.useState(!1),[y,g]=React.useState(!1),h=React.useRef(!1),x=React.useRef(80),[C,O]=React.useState(),[w,S]=React.useState(),[b,F]=React.useState(),[_,k]=React.useState(),[L,M]=React.useState(DEFAULT_SEARCH_LIMIT$1),[j,B]=React.useState(),N=React.useRef([]),[$,D]=React.useState(200),H=React.useRef(),{height:Y}=useWindowDimensions(),G=React.useContext(ContentRootContext),{processAction:U}=G||{},Z=React.useContext(ActionViewContext),{setResults:V=void 0,setCurrentItemIndex:z=void 0,currentId:E=void 0,results:A=void 0,selectedRowItems:q=void 0,setSelectedRowItems:K=void 0,searchParams:Q=[],setSearchParams:P=void 0,searchVisible:T=!0,setSearchVisible:W=void 0,sorter:X=void 0,setSorter:ee=void 0,setTotalItems:ne=void 0,setSearchTreeNameSearch:ie=void 0,setTreeIsLoading:J=void 0,searchValues:se={},setSearchValues:ae=void 0}=(f?Z:{})||{},{submit:me,clear:oe,fetchResults:pe,tableRefreshing:ue,searchFilterLoading:ve,searchError:Ie,page:ye,offset:xe,getResults:Se,requestPageChange:ce,changeSort:fe,fetchChildrenForRecord:ge,colorsForResults:he,totalItems:Re}=useSearch({model:C,setSearchTreeNameSearch:ie,setSelectedRowItems:K,setSearchParams:P,setSearchValues:ae,searchParams:Q,setSearchVisible:W,setTreeIsLoading:J,nameSearch:l,searchNameGetDoneRef:h,context:m,formView:b,treeView:w,sorter:X,setSorter:ee,setCurrentItemIndex:z,setResultsActionView:V,resultsActionView:A,domain:u,currentId:E,setActionViewTotalItems:ne,limitFromAction:_,setLimit:M,limit:L});React.useImperativeHandle(n,()=>({refreshResults:()=>{h.current=!1,pe()}})),React.useEffect(()=>{!y||d&&(h.current=!1,pe())},[ye,L,xe,y,d,l]);const we=async Oe=>{g(!1),v(!0),B(void 0),J==null||J(!0);try{Oe==="action"?await Te():await Ae(),g(!0)}catch(be){B(be)}finally{v(!1),J==null||J(!1)}},Te=async()=>{const Oe=await ConnectionProvider.getHandler().getViewsForAction({action:t,context:m});N.current=Oe.domain,F(Oe.views.get("form")),S(Oe.views.get("tree")),O(Oe.model),k(Oe.limit),M(Oe.limit)},Ae=async()=>{O(o);let Oe=r;r||(Oe=await ConnectionProvider.getHandler().getView({model:o,type:"form",context:m}));let be=a;a||(be=await ConnectionProvider.getHandler().getView({model:o,type:"tree",context:m})),F(Oe),S(be),k(void 0),M(DEFAULT_SEARCH_LIMIT$1)};React.useEffect(()=>{t?we("action"):o&&we("model")},[t,o]);const _e=Oe=>{x.current=Oe},Ee=async Oe=>{const{id:be}=Oe;H.current||(H.current=await ConnectionProvider.getHandler().treeButOpen({id:w.view_id,model:C,context:m}));const Fe=H.current[0][2];await(U==null?void 0:U({actionData:Fe,fields:w.fields,values:{active_id:be,...Oe},context:m}))},je=async Oe=>{const{id:be}=Oe;if(w!=null&&w.isExpandable){try{await Ee(Oe)}catch(Fe){showDialog$8(Fe)}return}s({id:be,model:C,formView:b,treeView:w})};function De(Oe){const be=Se().filter(Fe=>Oe.includes(Fe.id));K==null||K(be),p==null||p(Oe)}function ke(){return w!=null&&w.isExpandable?Y-160:Y-($+210)}const Be=()=>!w||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchFilter,{fields:{...w.fields,...b.fields},searchFields:mergeSearchFields([b.search_fields,w.search_fields]),onClear:oe,limit:L,offset:xe,isSearching:ve,onSubmit:me,onLimitChange:_e,setSearchFilterHeight:D,searchError:Ie,searchVisible:T,searchValues:se}),jsxRuntime.jsx(Tree,{total:Re,limit:L,page:ye,treeView:w,results:Se(),onRequestPageChange:ce,loading:ue,onRowClicked:je,scrollY:c||ke(),colorsForResults:he,rowSelection:{selectedRowKeys:q==null?void 0:q.map(Oe=>Oe.id),onChange:De},sorter:X,onChangeSort:fe,onFetchChildrenForRecord:w.isExpandable?ge:void 0,childField:w.field_parent})]}),Me=j||Ie;return Me?jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:Me,type:"error",banner:!0}):jsxRuntime.jsx("div",{style:d?{}:{display:"none"},children:I?jsxRuntime.jsx(antd.Spin,{}):Be()})}const SearchTree$1=React.forwardRef(SearchTree),SearchModal=e=>{const{visible:n,onCloseModal:t,onSelectValues:o,model:r,nameSearch:a,domain:s,context:l={}}=e,[c,u]=React.useState(!1),{modalWidth:d,modalHeight:f}=useWindowDimensions(),{t:m}=React.useContext(LocaleContext),[p,I]=React.useState([]),v=async()=>{await new Promise(x=>setTimeout(x,5)),t()},y=async x=>{const{id:C}=x;o([C])};function g(){if(p.length===0){v();return}o(p)}const h=()=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchTree$1,{model:r,nameSearch:a,onRowClicked:y,treeScrollY:f*.3,domain:s,parentContext:l,onChangeSelectedRowKeys:x=>{I(x)}}),jsxRuntime.jsx(antd.Divider,{}),jsxRuntime.jsx(antd.Row,{justify:"end",children:jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FileAddOutlined,{}),onClick:()=>{u(!0)},children:m("new")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CheckOutlined,{}),onClick:()=>{g()},type:"primary",children:m("ok")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CloseOutlined,{}),onClick:v,children:m("cancel")})]})})]});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(antd.Modal,{title:m("search"),centered:!0,width:d,visible:n&&!c,closable:!0,onCancel:v,footer:null,destroyOnClose:!0,maskClosable:!1,children:h()}),jsxRuntime.jsx(FormModal,{model:r,visible:c,parentContext:l,onSubmitSucceed:x=>{u(!1),v(),o([x])},onCancel:()=>{u(!1),v()}})]})},{error}=antd.Modal,showDialog$3=e=>{error({title:"Error",icon:jsxRuntime.jsx(Icon.ExclamationCircleOutlined,{}),centered:!0,content:e})},Many2one=e=>{const{ooui:n}=e,{required:t}=n,o=async(r,a)=>{if(!a)throw new Error;if(!Array.isArray(a))throw new Error;if(Array.isArray(a)&&!a[0])throw new Error};return jsxRuntime.jsx(Field$1,{required:t,type:"array",validator:o,...e,children:jsxRuntime.jsx(Many2oneInput,{ooui:n})})},Many2oneInput=e=>{const{value:n,onChange:t,ooui:o}=e,{required:r,relation:a,readOnly:s,context:l,id:c,domain:u}=o,d=r&&!s?Config.requiredClass:void 0,[f,m]=React.useState(!1),[p,I]=React.useState(!1),[v,y]=React.useState(!1),[g,h]=React.useState(),x=React.useRef(!1),[C,O]=React.useState(""),w=React.useRef(),S=React.useContext(FormContext$1),{domain:b,getValues:F,getFields:_,getContext:k,setOriginalValue:L,elementHasLostFocus:M}=S||{},j=React.useRef([]),[B,N]=React.useState([]),$=n&&n[0],D=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&!isNaN(n)&&Z(n)},[n]),React.useEffect(()=>{$&&D.length===0?Z($):$&&D.length>0?O(D):!$&&!D&&O(w.current||"")},[n]);const H=A=>{t==null||t(A),M==null||M()},Y=A=>{w.current=A.target.value,H([void 0,""])},G=async()=>{if(!v&&C!==D){if(await new Promise(A=>setTimeout(A,100)),x.current){H([void 0,""]);return}y(!0);try{if(j.current&&j.current.length>0)U(w.current);else{const A=await ConnectionProvider.getHandler().nameSearch({model:a,payload:w.current,context:{...k==null?void 0:k(),...l}});A.length===1?(w.current=void 0,H(A[0])):U(w.current)}}catch(A){showDialog$3(A)}finally{y(!1)}}},U=async A=>{if(await V(),j.current&&j.current.length>0){const q=await ConnectionProvider.getHandler().searchAllIds({params:j.current,model:a,context:{...k==null?void 0:k(),...l},totalItems:2});q.length===1?Z(q[0],!0):(h(A),m(!0));return}h(A),m(!0)},Z=async(A,q)=>{y(!0);try{const K=await ConnectionProvider.getHandler().execute({action:"name_get",payload:[A],model:a,context:{...k==null?void 0:k(),...l}});H([A,K[0][1]]),q&&L(o.id,[A,K[0][1]])}catch(K){showDialog$3(K)}finally{y(!1)}};async function V(){u&&(j.current=await ConnectionProvider.getHandler().evalDomain({domain:u,values:transformPlainMany2Ones({fields:_(),values:F()}),context:k()})),b&&b.length>0&&(j.current=j.current.concat(ooui.transformDomainForChildWidget({domain:b,widgetFieldName:c}))),N(j.current)}async function z(A){A.code==="Enter"?(A.preventDefault(),A.stopPropagation(),await G()):A.code==="Backspace"&&$!==void 0&&(A.preventDefault(),A.stopPropagation(),H([void 0,""]))}const E=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(E,{type:"text",value:C,disabled:s,onChange:Y,className:d,onBlur:G,onKeyDown:z,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:$,model:a,context:{...k==null?void 0:k(),...l}})})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FolderOpenOutlined,{}),disabled:$===void 0||D===""||C===void 0,onClick:()=>{I(!0)},tabIndex:-1})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:v?jsxRuntime.jsx(Icon.LoadingOutlined,{}):jsxRuntime.jsx(Icon.SearchOutlined,{}),disabled:s||v,onClick:()=>{x.current=!0,U(D)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:B,context:{...k==null?void 0:k(),...l},visible:f,nameSearch:$?void 0:g,onSelectValues:A=>{m(!1),Z(A[0]),x.current=!1,w.current=void 0},onCloseModal:()=>{m(!1),x.current=!1}}),jsxRuntime.jsx(FormModal,{model:a,parentContext:{...k==null?void 0:k(),...l},id:n&&n[0],visible:p,onSubmitSucceed:A=>{I(!1),Z(A)},onCancel:()=>{I(!1)},mustClearAfterSave:!0,readOnly:s})]})},RequiredInput=styled__default.default(antd.Input)`
115
+ `,booleanComponentFn=e=>jsxRuntime.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:jsxRuntime.jsx(antd.Checkbox,{checked:e,disabled:!0})}),many2OneComponentFn=e=>e?jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(jsxRuntime.Fragment,{children:e.value}),jsxRuntime.jsx(Many2oneSuffix,{id:e.id,model:e.model})]}):jsxRuntime.jsx(jsxRuntime.Fragment,{}),textComponentFn=e=>jsxRuntime.jsx("div",{style:{whiteSpace:"pre-line"},children:e}),one2ManyComponentFn=e=>{const n=Array.isArray(e==null?void 0:e.items)?e==null?void 0:e.items.length:0;return jsxRuntime.jsx(jsxRuntime.Fragment,{children:`( ${n} )`})},progressBarComponentFn=e=>jsxRuntime.jsx(ProgressBarInput,{value:e}),floatTimeComponent=e=>jsxRuntime.jsx(jsxRuntime.Fragment,{children:parseFloatToString(e)}),numberComponent=e=>jsxRuntime.jsx("div",{style:{textAlign:"right"},children:e}),imageComponent=e=>jsxRuntime.jsx("img",{src:`data:image/*;base64,${e}`,style:{maxWidth:"50px",padding:"5px"}});function Tree(e){const{page:n=1,limit:t,total:o,treeView:r,results:a,onRequestPageChange:s,loading:l,onRowClicked:c,showPagination:u=!0,rowSelection:d,scrollY:f,colorsForResults:m={},onChangeSort:p,sorter:I,onFetchChildrenForRecord:v,childField:y}=e,[g,h]=React.useState([]),[x,C]=React.useState([]),O=React.useRef(!1),w=React.useRef(null),{t:S}=React.useContext(LocaleContext);React.useEffect(()=>{w.current=getTree(r);const B=getTableColumns(w.current,{boolean:booleanComponentFn,many2one:many2OneComponentFn,text:textComponentFn,one2many:one2ManyComponentFn,many2many:one2ManyComponentFn,progressbar:progressBarComponentFn,float_time:floatTimeComponent,image:imageComponent,integer:numberComponent,float:numberComponent});C(B)},[r]),React.useEffect(()=>{O.current=!1;const B=getTableItems(w.current,a);h(B)},[a]);const b=(n-1)*t+1,F=b-1+g.length,_=o===void 0?null:o===0?S("no_results"):S("summary").replace("{from}",b==null?void 0:b.toString()).replace("{to}",F==null?void 0:F.toString()).replace("{total}",o==null?void 0:o.toString()),k=()=>!u||r.isExpandable||l?null:o===void 0?jsxRuntime.jsx(antd.Spin,{}):jsxRuntime.jsxs(antd.Row,{align:"bottom",className:"pb-4",children:[jsxRuntime.jsx(antd.Col,{span:12,children:jsxRuntime.jsx(antd.Pagination,{total:o,pageSize:t,current:n,showSizeChanger:!1,onChange:s})}),jsxRuntime.jsx(antd.Col,{span:12,className:"text-right",children:_})]});function L(){var H;const N=w.current.columns.filter(Y=>Y.sum!==void 0).map(Y=>({label:Y.sum,field:Y.id}));if(!N||N.length===0)return null;let $=[],D=((H=d==null?void 0:d.selectedRowKeys)==null?void 0:H.length)>0?g.filter(Y=>d==null?void 0:d.selectedRowKeys.includes(Y.id)):g;return N.forEach(Y=>{const G=D.reduce((U,Z)=>Z[Y.field]&&!isNaN(Z[Y.field])?U+Z[Y.field]:U,0);$.push(`${Y.label}: ${Math.round(G*100)/100}`)}),jsxRuntime.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 bg-gray-50",children:$.join(", ")})}let M,j=f;if(w.current!==null){M=calculateColumnsWidth(x,g,600);const N=w.current;f&&N.columns.some($=>$.sum!==void 0)&&(j=f-30)}return w.current===null?jsxRuntime.jsx(antd.Spin,{style:{padding:"2rem"}}):jsxRuntime.jsxs("div",{children:[k(),jsxRuntime.jsx(reactFormigaTable.Table,{height:j,columns:M.columns,dataSource:g,loading:l,loadingComponent:jsxRuntime.jsx(antd.Spin,{}),onRowStyle:B=>{if(m[B.id])return{color:m[B.id]}},onRowDoubleClick:c,onRowSelectionChange:d==null?void 0:d.onChange,onChangeSort:p,sorter:I,expandableOpts:v?{expandIcon:Icon.PlusSquareOutlined,collapseIcon:Icon.MinusSquareOutlined,loadingIcon:Icon.LoadingOutlined,onFetchChildrenForRecord:v,childField:y}:void 0}),L()]})}const DEFAULT_SEARCH_LIMIT$1=80,useSearch=e=>{const{model:n,setSearchTreeNameSearch:t,setSelectedRowItems:o,setSearchParams:r,setSearchVisible:a,setTreeIsLoading:s,nameSearch:l,searchNameGetDoneRef:c,context:u,setActionViewTotalItems:d,treeView:f,formView:m,sorter:p,setSorter:I,setCurrentItemIndex:v,setResultsActionView:y,resultsActionView:g,domain:h,currentId:x,limitFromAction:C,limit:O,setLimit:w,searchParams:S=[],setSearchValues:b}=e,[F,_]=React.useState(!1),[k,L]=React.useState(!1),[M,j]=React.useState(),[B,N]=React.useState(1),[$,D]=React.useState(0),[H,Y]=React.useState(),[G,U]=React.useState([]),[Z,V]=React.useState(void 0),z=React.useRef([]),E=React.useRef(80),A=React.useRef([]),q=React.useCallback(J=>{y==null||y([...J]),U([...J])},[]),K=React.useCallback(()=>g||G,[g,G]),Q=React.useCallback(async()=>{const J=await ConnectionProvider.getHandler().nameSearch({model:n,payload:l,limit:E.current,attrs:A.current.length>0?A.current:h,context:u});if(Y(J.length),d==null||d(J.length),J.length>0){const se=J.map(ve=>ve==null?void 0:ve[0]),{colors:ae}=getTree(f),me=await ConnectionProvider.getHandler().readEvalUiObjects({model:n,ids:se,arch:f==null?void 0:f.arch,fields:f.field_parent?{...f.fields,[f.field_parent]:{}}:f.fields,context:u,attrs:ae&&{colors:ae}}),oe=me[0];z.current=[...oe],V(getColorMap(me[1]));const pe=oe.map(ve=>ve.id),ue=p!==void 0?sortResults({resultsToSort:oe,sorter:p,fields:{...f.fields,...m.fields}}):[...z.current];q(ue),pe.length>0?v==null||v(0):v==null||v(void 0)}else q([]),v==null||v(void 0);c.current=!0},[q,c,l,n,u,h,f,m,p,v,d,E,A]),P=React.useCallback(async()=>{const J=A.current.length>0?A.current:h,se=mergeParams(S,J),{colors:ae}=getTree(f),{totalItems:me,results:oe,attrsEvaluated:pe}=await ConnectionProvider.getHandler().searchForTree({params:se,limit:O,offset:$,model:n,fields:f.field_parent?{...f.fields,[f.field_parent]:{}}:f.fields,context:u,attrs:ae&&{colors:ae}});V(getColorMap(pe)),z.current=[...oe];const ue=p!==void 0?sortResults({resultsToSort:oe,sorter:p,fields:{...f.fields,...m.fields}}):[...z.current];if(q(ue),g&&ue.length>0){const Ie=ue.findIndex(ye=>x===ye.id);Ie===-1?v==null||v(0):v==null||v(Ie)}else v==null||v(void 0);const ve=await me;Y(ve),d==null||d(ve)},[v,g,q,x,n,u,h,f,m,p,d,O,$,A,S]),T=React.useCallback(async()=>{try{_(!0),s==null||s(!0),l&&!c.current?await Q():await P()}catch(J){j(J.message)}finally{_(!1),L(!1),s==null||s(!1)}},[A,u,x,h,m,E,O,n,l,$,g,c,d,v,q,j,L,_,s,p,f]),W=React.useCallback(J=>{I==null||I(J);const se=J!==void 0?sortResults({resultsToSort:K(),sorter:J,fields:{...f.fields,...m.fields}}):[...z.current];q(se)},[I,K,f,m,q]),X=React.useCallback(({params:J,limit:se,offset:ae,searchValues:me})=>{F||(t==null||t(void 0),o==null||o([]),b==null||b(me),r==null||r(J),a==null||a(!1),L(!0),j(void 0),N(1),se&&(w==null||w(se)),ae&&D(ae),T())},[F,t,o,r,a,L,j,N,w,D,T]),ee=React.useCallback(J=>{_(!0),N(J),D((J-1)*O)},[_,O,D,N]),ne=React.useCallback(()=>{F||(t==null||t(void 0),r==null||r([]),b==null||b({}),j(void 0),D(0),N(1),w==null||w(C||DEFAULT_SEARCH_LIMIT$1))},[F,t,r,j,D,N,w,C]),ie=React.useCallback(async J=>{const se=J[(f==null?void 0:f.field_parent)||"child_id"],ae=await ConnectionProvider.getHandler().readObjects({model:n,ids:se,fields:f.field_parent?{...f.fields,[f.field_parent]:{}}:f.fields,context:u});return q([...K(),...ae]),getTableItems(getTree(f),ae)},[f,n,u,K,q]);return{submit:X,clear:ne,fetchResults:T,tableRefreshing:F,searchFilterLoading:k,searchError:M,page:B,offset:$,limit:O,getResults:K,requestPageChange:ee,changeSort:W,fetchChildrenForRecord:ie,colorsForResults:Z,totalItems:H}};function SearchTree(e,n){const{action:t,model:o,formView:r,treeView:a,onRowClicked:s,nameSearch:l,treeScrollY:c,domain:u=[],visible:d=!0,rootTree:f=!1,parentContext:m={},onChangeSelectedRowKeys:p}=e,[I,v]=React.useState(!1),[y,g]=React.useState(!1),h=React.useRef(!1),x=React.useRef(80),[C,O]=React.useState(),[w,S]=React.useState(),[b,F]=React.useState(),[_,k]=React.useState(),[L,M]=React.useState(DEFAULT_SEARCH_LIMIT$1),[j,B]=React.useState(),N=React.useRef([]),[$,D]=React.useState(200),H=React.useRef(),{height:Y}=useWindowDimensions(),G=React.useContext(ContentRootContext),{processAction:U}=G||{},Z=React.useContext(ActionViewContext),{setResults:V=void 0,setCurrentItemIndex:z=void 0,currentId:E=void 0,results:A=void 0,selectedRowItems:q=void 0,setSelectedRowItems:K=void 0,searchParams:Q=[],setSearchParams:P=void 0,searchVisible:T=!0,setSearchVisible:W=void 0,sorter:X=void 0,setSorter:ee=void 0,setTotalItems:ne=void 0,setSearchTreeNameSearch:ie=void 0,setTreeIsLoading:J=void 0,searchValues:se={},setSearchValues:ae=void 0}=(f?Z:{})||{},{submit:me,clear:oe,fetchResults:pe,tableRefreshing:ue,searchFilterLoading:ve,searchError:Ie,page:ye,offset:xe,getResults:Se,requestPageChange:ce,changeSort:fe,fetchChildrenForRecord:ge,colorsForResults:he,totalItems:Re}=useSearch({model:C,setSearchTreeNameSearch:ie,setSelectedRowItems:K,setSearchParams:P,setSearchValues:ae,searchParams:Q,setSearchVisible:W,setTreeIsLoading:J,nameSearch:l,searchNameGetDoneRef:h,context:m,formView:b,treeView:w,sorter:X,setSorter:ee,setCurrentItemIndex:z,setResultsActionView:V,resultsActionView:A,domain:u,currentId:E,setActionViewTotalItems:ne,limitFromAction:_,setLimit:M,limit:L});React.useImperativeHandle(n,()=>({refreshResults:()=>{h.current=!1,pe()}})),React.useEffect(()=>{!y||d&&(h.current=!1,pe())},[ye,L,xe,y,d,l]);const we=async Oe=>{g(!1),v(!0),B(void 0),J==null||J(!0);try{Oe==="action"?await Te():await Ae(),g(!0)}catch(be){B(be)}finally{v(!1),J==null||J(!1)}},Te=async()=>{const Oe=await ConnectionProvider.getHandler().getViewsForAction({action:t,context:m});N.current=Oe.domain,F(Oe.views.get("form")),S(Oe.views.get("tree")),O(Oe.model),k(Oe.limit),M(Oe.limit)},Ae=async()=>{O(o);let Oe=r;r||(Oe=await ConnectionProvider.getHandler().getView({model:o,type:"form",context:m}));let be=a;a||(be=await ConnectionProvider.getHandler().getView({model:o,type:"tree",context:m})),F(Oe),S(be),k(void 0),M(DEFAULT_SEARCH_LIMIT$1)};React.useEffect(()=>{t?we("action"):o&&we("model")},[t,o]);const _e=Oe=>{x.current=Oe},Ee=async Oe=>{const{id:be}=Oe;H.current||(H.current=await ConnectionProvider.getHandler().treeButOpen({id:w.view_id,model:C,context:m}));const Fe=H.current[0][2];await(U==null?void 0:U({actionData:Fe,fields:w.fields,values:{active_id:be,...Oe},context:m}))},je=async Oe=>{const{id:be}=Oe;if(w!=null&&w.isExpandable){try{await Ee(Oe)}catch(Fe){showDialog$8(Fe)}return}s({id:be,model:C,formView:b,treeView:w})};function De(Oe){const be=Se().filter(Fe=>Oe.includes(Fe.id));K==null||K(be),p==null||p(Oe)}function ke(){return w!=null&&w.isExpandable?Y-160:Y-($+210)}const Be=()=>!w||!b?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchFilter,{fields:{...w.fields,...b.fields},searchFields:mergeSearchFields([b.search_fields,w.search_fields]),onClear:oe,limit:L,offset:xe,isSearching:ve,onSubmit:me,onLimitChange:_e,setSearchFilterHeight:D,searchError:Ie,searchVisible:T,searchValues:se}),jsxRuntime.jsx(Tree,{total:Re,limit:L,page:ye,treeView:w,results:Se(),onRequestPageChange:ce,loading:ue,onRowClicked:je,scrollY:c||ke(),colorsForResults:he,rowSelection:{selectedRowKeys:q==null?void 0:q.map(Oe=>Oe.id),onChange:De},sorter:X,onChangeSort:fe,onFetchChildrenForRecord:w.isExpandable?ge:void 0,childField:w.field_parent})]}),Me=j||Ie;return Me?jsxRuntime.jsx(antd.Alert,{className:"mt-10",message:Me,type:"error",banner:!0}):jsxRuntime.jsx("div",{style:d?{}:{display:"none"},children:I?jsxRuntime.jsx(antd.Spin,{}):Be()})}const SearchTree$1=React.forwardRef(SearchTree),SearchModal=e=>{const{visible:n,onCloseModal:t,onSelectValues:o,model:r,nameSearch:a,domain:s,context:l={}}=e,[c,u]=React.useState(!1),{modalWidth:d,modalHeight:f}=useWindowDimensions(),{t:m}=React.useContext(LocaleContext),[p,I]=React.useState([]),v=async()=>{await new Promise(x=>setTimeout(x,5)),t()},y=async x=>{const{id:C}=x;o([C])};function g(){if(p.length===0){v();return}o(p)}const h=()=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(SearchTree$1,{model:r,nameSearch:a,onRowClicked:y,treeScrollY:f*.3,domain:s,parentContext:l,onChangeSelectedRowKeys:x=>{I(x)}}),jsxRuntime.jsx(antd.Divider,{}),jsxRuntime.jsx(antd.Row,{justify:"end",children:jsxRuntime.jsxs(antd.Space,{children:[jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FileAddOutlined,{}),onClick:()=>{u(!0)},children:m("new")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CheckOutlined,{}),onClick:()=>{g()},type:"primary",children:m("ok")}),jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.CloseOutlined,{}),onClick:v,children:m("cancel")})]})})]});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(antd.Modal,{title:m("search"),centered:!0,width:d,visible:n&&!c,closable:!0,onCancel:v,footer:null,destroyOnClose:!0,maskClosable:!1,children:h()}),jsxRuntime.jsx(FormModal,{model:r,visible:c,parentContext:l,onSubmitSucceed:x=>{u(!1),v(),o([x])},onCancel:()=>{u(!1),v()}})]})},{error}=antd.Modal,showDialog$3=e=>{error({title:"Error",icon:jsxRuntime.jsx(Icon.ExclamationCircleOutlined,{}),centered:!0,content:e})},Many2one=e=>{const{ooui:n}=e,{required:t}=n,o=async(r,a)=>{if(!a)throw new Error;if(!Array.isArray(a))throw new Error;if(Array.isArray(a)&&!a[0])throw new Error};return jsxRuntime.jsx(Field$1,{required:t,type:"array",validator:o,...e,children:jsxRuntime.jsx(Many2oneInput,{ooui:n})})},Many2oneInput=e=>{const{value:n,onChange:t,ooui:o}=e,{required:r,relation:a,readOnly:s,context:l,id:c,domain:u}=o,d=r&&!s?Config.requiredClass:void 0,[f,m]=React.useState(!1),[p,I]=React.useState(!1),[v,y]=React.useState(!1),[g,h]=React.useState(),x=React.useRef(!1),[C,O]=React.useState(""),w=React.useRef(),S=React.useContext(FormContext$1),{domain:b,getValues:F,getFields:_,getContext:k,setOriginalValue:L,elementHasLostFocus:M}=S||{},j=React.useRef([]),[B,N]=React.useState([]),$=n&&n[0]||void 0,D=n&&n[1]||"";React.useEffect(()=>{!Array.isArray(n)&&n&&Z(n)},[n]),React.useEffect(()=>{$&&D.length===0?Z($):$&&D.length>0?O(D):!$&&!D&&O(w.current||"")},[n]);const H=A=>{t==null||t(A),M==null||M()},Y=A=>{w.current=A.target.value,H([void 0,""])},G=async()=>{if(!v&&C!==D){if(await new Promise(A=>setTimeout(A,100)),x.current){H([void 0,""]);return}y(!0);try{if(j.current&&j.current.length>0)U(w.current);else{const A=await ConnectionProvider.getHandler().nameSearch({model:a,payload:w.current,context:{...k==null?void 0:k(),...l}});A.length===1?(w.current=void 0,H(A[0])):U(w.current)}}catch(A){showDialog$3(A)}finally{y(!1)}}},U=async A=>{if(await V(),j.current&&j.current.length>0){const q=await ConnectionProvider.getHandler().searchAllIds({params:j.current,model:a,context:{...k==null?void 0:k(),...l},totalItems:2});q.length===1?Z(q[0],!0):(h(A),m(!0));return}h(A),m(!0)},Z=async(A,q)=>{y(!0);try{const K=await ConnectionProvider.getHandler().execute({action:"name_get",payload:[A],model:a,context:{...k==null?void 0:k(),...l}});H([A,K[0][1]]),q&&L(o.id,[A,K[0][1]])}catch(K){showDialog$3(K)}finally{y(!1)}};async function V(){u&&(j.current=await ConnectionProvider.getHandler().evalDomain({domain:u,values:transformPlainMany2Ones({fields:_(),values:F()}),context:k()})),b&&b.length>0&&(j.current=j.current.concat(ooui.transformDomainForChildWidget({domain:b,widgetFieldName:c}))),N(j.current)}async function z(A){A.code==="Enter"?(A.preventDefault(),A.stopPropagation(),await G()):A.code==="Backspace"&&$!==void 0&&(A.preventDefault(),A.stopPropagation(),H([void 0,""]))}const E=r&&!s?RequiredInput:antd.Input;return jsxRuntime.jsxs(antd.Row,{gutter:8,wrap:!1,children:[jsxRuntime.jsx(antd.Col,{flex:"auto",children:jsxRuntime.jsx(E,{type:"text",value:C,disabled:s,onChange:Y,className:d,onBlur:G,onKeyDown:z,suffix:jsxRuntime.jsx(Many2oneSuffix,{id:$,model:a,context:{...k==null?void 0:k(),...l}})})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:jsxRuntime.jsx(Icon.FolderOpenOutlined,{}),disabled:$===void 0||D===""||C===void 0,onClick:()=>{I(!0)},tabIndex:-1})}),jsxRuntime.jsx(antd.Col,{flex:"32px",children:jsxRuntime.jsx(antd.Button,{icon:v?jsxRuntime.jsx(Icon.LoadingOutlined,{}):jsxRuntime.jsx(Icon.SearchOutlined,{}),disabled:s||v,onClick:()=>{x.current=!0,U(D)},tabIndex:-1})}),jsxRuntime.jsx(SearchModal,{model:a,domain:B,context:{...k==null?void 0:k(),...l},visible:f,nameSearch:$?void 0:g,onSelectValues:A=>{m(!1),Z(A[0]),x.current=!1,w.current=void 0},onCloseModal:()=>{m(!1),x.current=!1}}),jsxRuntime.jsx(FormModal,{model:a,parentContext:{...k==null?void 0:k(),...l},id:n&&n[0],visible:p,onSubmitSucceed:A=>{I(!1),Z(A)},onCancel:()=>{I(!1)},mustClearAfterSave:!0,readOnly:s})]})},RequiredInput=styled__default.default(antd.Input)`
116
116
  .ant-input {
117
117
  background-color: ${Config.requiredColor};
118
118
  }