@gisce/react-ooui 1.4.17 → 1.5.0

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.
@@ -32,7 +32,7 @@
32
32
  display: flex;
33
33
  align-items: center;
34
34
  justify-content: center;
35
- `,Oa=({numberOfVisibleSelectedRows:t,totalRecords:r,numberOfTotalRows:n,onSelectAllRecords:s,numberOfRealSelectedRows:o})=>{const[i,a]=l.useState(!1),{t:c}=l.useContext(he),h={recordsSelected:c("recordsSelected"),selectAllRecords:c("selectAllRecords"),allRecordsSelected:c("allRecordsSelected")};if(n===0||t<n&&o<=n)return null;const d=async g=>{g.preventDefault(),g.stopPropagation(),a(!0),await s(),a(!1)},u=e.jsxs("span",{children:[h.recordsSelected.replace("{numberOfSelectedRows}",t.toString())+" ",i?e.jsx(p.Spin,{}):e.jsx(ko.default,{onClick:d,style:{fontWeight:600},children:h.selectAllRecords.replace("{totalRecords}",r.toString())})]}),f=e.jsx("span",{style:{fontWeight:600},children:h.allRecordsSelected.replace("{totalRecords}",o.toString())+" "});return e.jsx(Fa,{children:o>n?f:u})},_a=t=>e.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:e.jsx(p.Checkbox,{checked:t,disabled:!0})}),Da=t=>e.jsx(va,{m2oField:t}),ka=t=>e.jsx(Kt.Interweave,{content:t==null?void 0:t.toString().replace(/(?:\r\n|\r|\n)/g,"<br>")}),Ma=t=>{if(!t||t&&t.length===0)return e.jsx(e.Fragment,{});const r=Ze(t,et.date.dateInternalFormat).format(et.date.dateDisplayFormat);return e.jsx(e.Fragment,{children:r})},Va=t=>{if(!t||t&&t.length===0)return e.jsx(e.Fragment,{});const r=Ze(t,et.time.dateInternalFormat).format(et.time.dateDisplayFormat);return e.jsx(e.Fragment,{children:r})},mn=t=>{const r=Array.isArray(t==null?void 0:t.items)?t==null?void 0:t.items.length:0;return e.jsx(e.Fragment,{children:`( ${r} )`})},Ea=t=>e.jsx(dn,{value:t}),Ia=t=>e.jsx(e.Fragment,{children:ln(t)}),yn=t=>e.jsx("div",{style:{textAlign:"right"},children:t}),Aa=t=>e.jsx("img",{src:`data:image/*;base64,${t}`,style:{maxWidth:"50px",padding:"5px"}}),$a=(t,r,n,s)=>e.jsx(Xr,{ooui:n,value:t}),La=(t,r,n,s)=>e.jsx(e.Fragment,{children:n.selectionValues.get(t)}),Na=(t,r,n,s)=>e.jsx(e.Fragment,{children:e.jsx(wa,{value:t,selectionValues:n.selectionValues,context:s})}),Pa=(t,r,n,s)=>e.jsx(Sa,{ooui:n,value:t});function Tt(t){var W;const{page:r=1,limit:n,total:s,treeView:o,results:i,onRequestPageChange:a,loading:c,onRowClicked:h,showPagination:d=!0,rowSelection:u,scrollY:f,colorsForResults:g={},statusForResults:w={},onChangeSort:y,sorter:m,onFetchChildrenForRecord:v,childField:S,rootTree:T=!1,context:V,readonly:b,onSelectAllRecords:E}=t,[D,L]=l.useState([]),[x,F]=l.useState([]),O=l.useRef(!1),C=l.useRef(null),{t:P}=l.useContext(he),I=l.useRef(n),_=l.useContext(Ue),{title:$=void 0,setTitle:A=void 0}=(T?_:{})||{};l.useEffect(()=>{C.current=at(o);const H=ci(C.current,{boolean:_a,many2one:Da,text:ka,one2many:mn,many2many:mn,progressbar:Ea,float_time:Ia,image:Aa,integer:yn,float:yn,reference:Na,tag:$a,selection:La,date:Ma,datetime:Va,avatar:Pa},V);F(H),C.current.string&&$!==C.current.string&&(A==null||A(C.current.string))},[o]),l.useEffect(()=>{O.current=!1;const H=Ur(C.current,i);L(H),I.current=n},[i]);const M=(r-1)*I.current+1,N=M-1+D.length,k=s===void 0?null:s===0?P("no_results"):P("summary").replace("{from}",M==null?void 0:M.toString()).replace("{to}",N==null?void 0:N.toString()).replace("{total}",s==null?void 0:s.toString()),Y=()=>!d||o.isExpandable||c?null:s===void 0?e.jsx(p.Spin,{className:"pb-4"}):e.jsxs(p.Row,{align:"bottom",className:"pb-4",children:[e.jsx(p.Col,{span:8,children:e.jsx(p.Pagination,{total:s,pageSize:I.current===0?s:I.current,current:r,showSizeChanger:!1,onChange:a})}),e.jsx(p.Col,{span:8,className:"text-center",children:E&&e.jsx(Oa,{numberOfVisibleSelectedRows:X,numberOfRealSelectedRows:u==null?void 0:u.selectedRowKeys.length,numberOfTotalRows:D.length,totalRecords:s||0,onSelectAllRecords:E})}),e.jsx(p.Col,{span:8,className:"text-right",children:k})]});function J(){var R;const Q=C.current.columns.filter(z=>z.sum!==void 0).map(z=>({label:z.sum,field:z.id}));if(!Q||Q.length===0)return null;let re=[],ce=((R=u==null?void 0:u.selectedRowKeys)==null?void 0:R.length)>0?D.filter(z=>u==null?void 0:u.selectedRowKeys.includes(z.id)):D;return Q.forEach(z=>{const fe=ce.reduce((me,Fe)=>Fe[z.field]&&!isNaN(Fe[z.field])?me+Fe[z.field]:me,0);re.push(`${z.label}: ${Math.round(fe*100)/100}`)}),e.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 ",children:re.join(", ")})}let j,U=f;if(C.current!==null){j=ga(x,D,600);const Q=C.current;f&&Q.columns.some(re=>re.sum!==void 0)&&(U=f-30)}const X=D.filter(H=>u==null?void 0:u.selectedRowKeys.includes(H.id)).length;return C.current===null||!j||((W=j.columns)==null?void 0:W.length)===0?e.jsx(p.Spin,{style:{padding:"2rem"}}):e.jsxs("div",{children:[Y(),c&&e.jsx(p.Spin,{className:"pb-4"}),e.jsx(vo.Table,{height:U,columns:j.columns,dataSource:D,loading:!1,loadingComponent:e.jsx(p.Spin,{}),onRowStyle:H=>{if(g[H.id])return{color:g[H.id]}},onRowStatus:di(w)?H=>{if(w[H.id])return e.jsx(p.Badge,{color:w[H.id]})}:void 0,onRowDoubleClick:h,selectionRowKeys:u==null?void 0:u.selectedRowKeys,onRowSelectionChange:u==null?void 0:u.onChange,onChangeSort:y,sorter:m,readonly:b,expandableOpts:v?{expandIcon:B.PlusSquareOutlined,collapseIcon:B.MinusSquareOutlined,loadingIcon:B.LoadingOutlined,onFetchChildrenForRecord:v,childField:S}:void 0}),J()]})}function Ba(t,r){const{model:n,formView:s,treeView:o,onRowClicked:i,nameSearch:a,treeScrollY:c,domain:h=[],visible:d=!0,rootTree:u=!1,parentContext:f={},onChangeSelectedRowKeys:g}=t,[w,y]=l.useState(!1),[m,v]=l.useState(!1),S=l.useRef(!1),[T,V]=l.useState(),[b,E]=l.useState(),[D,L]=l.useState(),[x,F]=l.useState(),[O,C]=l.useState(200),P=l.useRef(),{height:I}=Dt(),_=l.useContext(ut),{processAction:$}=_||{},A=l.useContext(Ue),{setResults:M=void 0,setCurrentItemIndex:N=void 0,currentId:k=void 0,results:Y=void 0,selectedRowItems:J=void 0,setSelectedRowItems:j=void 0,searchParams:U=[],setSearchParams:X=void 0,searchVisible:W=!0,setSearchVisible:H=void 0,sorter:Q=void 0,setSorter:re=void 0,setTotalItems:ce=void 0,setSearchTreeNameSearch:R=void 0,setTreeIsLoading:z=void 0,searchValues:fe={},setSearchValues:me=void 0,limit:Fe=bt,setLimit:Oe=void 0}=(u?A:{})||{},{submit:Ee,clear:Pe,fetchResults:we,tableRefreshing:ie,searchFilterLoading:Me,searchError:ve,page:Ve,offset:Ae,getResults:te,requestPageChange:Se,changeSort:De,fetchChildrenForRecord:Ie,colorsForResults:ae,statusForResults:ue,totalItems:Be,getAllIds:de}=nn({model:T,setSearchTreeNameSearch:R,setSelectedRowItems:ye,setSearchParams:X,setSearchValues:me,searchParams:U,setSearchVisible:H,setTreeIsLoading:z,nameSearch:a,searchNameGetDoneRef:S,context:f,formView:D,treeView:b,sorter:Q,setSorter:re,setCurrentItemIndex:N,setResultsActionView:M,resultsActionView:Y,domain:h,currentId:k,setActionViewTotalItems:ce,limit:Fe,setLimit:Oe});l.useImperativeHandle(r,()=>({refreshResults:()=>{S.current=!1,we()},getFields:()=>b==null?void 0:b.fields,getDomain:()=>h})),l.useEffect(()=>{!m||d&&(S.current=!1,we())},[Ve,Ae,m,d,a]);const ze=async()=>{v(!1),y(!0),F(void 0),z==null||z(!0);try{await $e(),v(!0)}catch(_e){F(_e),z==null||z(!1)}finally{y(!1)}},$e=async()=>{V(n);let _e=s;s||(_e=await K.getHandler().getView({model:n,type:"form",context:f}));let Le=o;o||(Le=await K.getHandler().getView({model:n,type:"tree",context:f})),L(_e),E(Le)};l.useEffect(()=>{ze()},[n]);const ee=_e=>{Oe==null||Oe(_e)},le=async _e=>{const{id:Le}=_e;P.current||(P.current=await K.getHandler().treeButOpen({id:b.view_id,model:T,context:f}));const yt=P.current[0][2];await($==null?void 0:$({actionData:yt,fields:b.fields,values:{active_id:Le,..._e},context:f}))},Ce=async _e=>{const{id:Le}=_e;if(b!=null&&b.isExpandable){try{await le(_e)}catch(yt){Ne(yt)}return}i({id:Le,model:T,formView:D,treeView:b})};function ye(_e){j==null||j(_e.map(Le=>({id:Le}))),g==null||g(_e)}async function be(){const _e=await de();j==null||j(_e.map(Le=>({id:Le}))),g==null||g(_e)}function Te(){return b!=null&&b.isExpandable?I-160:I-(O+210)}const Ge=()=>!b||!D?null:e.jsxs(e.Fragment,{children:[e.jsx(Rt,{fields:{...D.fields,...b.fields},searchFields:zr([D.search_fields,b.search_fields]),onClear:Pe,limit:Fe,offset:Ae,isSearching:Me,onSubmit:Ee,onLimitChange:ee,setSearchFilterHeight:C,searchError:ve,searchVisible:W,searchValues:fe}),e.jsx(Tt,{context:f,total:Be,limit:Fe,page:Ve,treeView:b,results:te(),onRequestPageChange:Se,loading:ie,onRowClicked:Ce,scrollY:c||Te(),colorsForResults:ae,statusForResults:ue,rowSelection:{selectedRowKeys:J==null?void 0:J.map(_e=>_e.id),onChange:ye},sorter:Q,onChangeSort:De,onFetchChildrenForRecord:b.isExpandable?Ie:void 0,childField:b.field_parent,rootTree:u,onSelectAllRecords:be})]}),He=x||ve;return He?e.jsx(p.Alert,{className:"mt-10",message:He,type:"error",banner:!0}):e.jsx("div",{style:d?{}:{display:"none"},children:w?e.jsx(p.Spin,{}):Ge()})}const tr=l.forwardRef(Ba),rr=t=>{const{visible:r,onCloseModal:n,onSelectValues:s,model:o,nameSearch:i,domain:a,context:c={}}=t,[h,d]=l.useState(!1),{modalWidth:u,modalHeight:f}=Dt(),{t:g}=l.useContext(he),[w,y]=l.useState([]),m=async()=>{await new Promise(V=>setTimeout(V,5)),n()},v=async V=>{const{id:b}=V;s([b])};function S(){if(w.length===0){m();return}s(w)}const T=()=>e.jsxs(e.Fragment,{children:[e.jsx(tr,{model:o,nameSearch:i,onRowClicked:v,treeScrollY:f*.3,domain:a,parentContext:c,onChangeSelectedRowKeys:V=>{y(V)}}),e.jsx(p.Divider,{}),e.jsx(p.Row,{justify:"end",children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(B.FileAddOutlined,{}),onClick:()=>{d(!0)},children:g("new")}),e.jsx(p.Button,{icon:e.jsx(B.CheckOutlined,{}),onClick:()=>{S()},type:"primary",children:g("ok")}),e.jsx(p.Button,{icon:e.jsx(B.CloseOutlined,{}),onClick:m,children:g("cancel")})]})})]});return e.jsxs(e.Fragment,{children:[e.jsx(p.Modal,{title:g("search"),centered:!0,width:u,open:r&&!h,closable:!0,onCancel:m,footer:null,destroyOnClose:!0,maskClosable:!1,children:T()}),e.jsx(ht,{model:o,visible:h,parentContext:c,onSubmitSucceed:V=>{d(!1),m(),s([V])},onCancel:()=>{d(!1),m()}})]})},{error:Ha}=p.Modal,Et=t=>{Ha({title:"Error",icon:e.jsx(B.ExclamationCircleOutlined,{}),centered:!0,content:t})},{defaultAlgorithm:Ka,defaultSeed:Wa}=p.theme,vn=Ka(Wa),wn=t=>{const{ooui:r}=t,{required:n}=r,s=async(o,i)=>{if(!i)throw new Error;if(!Array.isArray(i))throw new Error;if(Array.isArray(i)&&!i[0])throw new Error};return e.jsx(ge,{required:n,type:"array",validator:s,...t,children:e.jsx(Sn,{ooui:r})})},Sn=t=>{const{value:r,onChange:n,ooui:s}=t,{required:o,relation:i,readOnly:a,context:c,id:h,domain:d}=s,u=o&&!a?{backgroundColor:vn.colorPrimaryBg}:void 0,[f,g]=l.useState(!1),[w,y]=l.useState(!1),[m,v]=l.useState(!1),[S,T]=l.useState(),V=l.useRef(!1),[b,E]=l.useState(""),D=l.useRef(),L=l.useContext(ke),{domain:x,getValues:F,getFields:O,getContext:C,elementHasLostFocus:P}=L||{},I=l.useRef([]),[_,$]=l.useState([]),A=r&&r[0]||void 0,M=r&&r[1]||"";l.useEffect(()=>{!Array.isArray(r)&&r&&j(r)},[r]),l.useEffect(()=>{A&&M.length===0?j(A):A&&M.length>0?E(M):!A&&!M&&E(D.current||"")},[r]);const N=H=>{n==null||n(H),P==null||P()},k=H=>{D.current=H.target.value,N([void 0,""])},Y=async()=>{if(!m&&b!==M){if(await new Promise(H=>setTimeout(H,100)),V.current){N([void 0,""]);return}v(!0);try{if(I.current&&I.current.length>0)J(D.current);else{const H=await K.getHandler().nameSearch({model:i,payload:D.current,context:{...C==null?void 0:C(),...c}});H.length===1?(D.current=void 0,N(H[0])):J(D.current)}}catch(H){Et(H)}finally{v(!1)}}},J=async H=>{if(await U(),I.current&&I.current.length>0){const Q=await K.getHandler().searchAllIds({params:I.current,model:i,context:{...C==null?void 0:C(),...c},totalItems:2});Q.length===1?j(Q[0]):(T(H),g(!0));return}T(H),g(!0)},j=async H=>{v(!0);try{const Q=await K.getHandler().execute({action:"name_get",payload:[H],model:i,context:{...C==null?void 0:C(),...c}});N([H,Q[0][1]])}catch(Q){Et(Q)}finally{v(!1)}};async function U(){d&&(I.current=await K.getHandler().evalDomain({domain:d,values:dt({fields:O(),values:F()}),fields:O(),context:C()})),x&&x.length>0&&(I.current=I.current.concat(se.transformDomainForChildWidget({domain:x,widgetFieldName:h}))),$(I.current)}async function X(H){H.keyCode===13?(H.preventDefault(),H.stopPropagation(),await Y()):H.code==="Backspace"&&A!==void 0&&(H.preventDefault(),H.stopPropagation(),N([void 0,""]))}const W=o&&!a?Ya:p.Input;return e.jsxs(p.Row,{gutter:8,wrap:!1,children:[e.jsx(p.Col,{flex:"auto",children:e.jsx(W,{type:"text",value:b,disabled:a,onChange:k,style:u,onBlur:Y,onKeyDown:X,suffix:e.jsx(er,{id:A,model:i,context:{...C==null?void 0:C(),...c}})})}),e.jsx(p.Col,{flex:"32px",style:{paddingRight:0},children:e.jsx(p.Button,{icon:e.jsx(B.FolderOpenOutlined,{}),disabled:A===void 0||M===""||b===void 0,onClick:()=>{y(!0)},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1})}),e.jsx(p.Col,{flex:"32px",style:{paddingLeft:0},children:e.jsx(p.Button,{icon:m?e.jsx(B.LoadingOutlined,{}):e.jsx(B.SearchOutlined,{}),disabled:a||m,onClick:()=>{V.current=!0,J(M)},style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},tabIndex:-1})}),e.jsx(rr,{model:i,domain:_,context:{...C==null?void 0:C(),...c},visible:f,nameSearch:A?void 0:S,onSelectValues:H=>{g(!1),j(H[0]),V.current=!1,D.current=void 0},onCloseModal:()=>{g(!1),V.current=!1}}),e.jsx(ht,{model:i,parentContext:{...C==null?void 0:C(),...c},id:r&&r[0],visible:w,onSubmitSucceed:H=>{y(!1),j(H)},onCancel:()=>{y(!1)},mustClearAfterSave:!0,readOnly:a})]})},Ya=ot.default(p.Input)`
35
+ `,Oa=({numberOfVisibleSelectedRows:t,totalRecords:r,numberOfTotalRows:n,onSelectAllRecords:s,numberOfRealSelectedRows:o})=>{const[i,a]=l.useState(!1),{t:c}=l.useContext(he),h={recordsSelected:c("recordsSelected"),selectAllRecords:c("selectAllRecords"),allRecordsSelected:c("allRecordsSelected")};if(n===0||t<n&&o<=n||r===t)return null;const d=async g=>{g.preventDefault(),g.stopPropagation(),a(!0),await s(),a(!1)},u=e.jsxs("span",{children:[h.recordsSelected.replace("{numberOfSelectedRows}",t.toString())+" ",i?e.jsx(p.Spin,{}):e.jsx(ko.default,{onClick:d,style:{fontWeight:600},children:h.selectAllRecords.replace("{totalRecords}",r.toString())})]}),f=e.jsx("span",{style:{fontWeight:600},children:h.allRecordsSelected.replace("{totalRecords}",o.toString())+" "});return e.jsx(Fa,{children:o>n?f:u})},_a=t=>e.jsx("div",{style:{display:"flex",justifyContent:"center",alignContent:"center"},children:e.jsx(p.Checkbox,{checked:t,disabled:!0})}),Da=t=>e.jsx(va,{m2oField:t}),ka=t=>e.jsx(Kt.Interweave,{content:t==null?void 0:t.toString().replace(/(?:\r\n|\r|\n)/g,"<br>")}),Ma=t=>{if(!t||t&&t.length===0)return e.jsx(e.Fragment,{});const r=Ze(t,et.date.dateInternalFormat).format(et.date.dateDisplayFormat);return e.jsx(e.Fragment,{children:r})},Va=t=>{if(!t||t&&t.length===0)return e.jsx(e.Fragment,{});const r=Ze(t,et.time.dateInternalFormat).format(et.time.dateDisplayFormat);return e.jsx(e.Fragment,{children:r})},mn=t=>{const r=Array.isArray(t==null?void 0:t.items)?t==null?void 0:t.items.length:0;return e.jsx(e.Fragment,{children:`( ${r} )`})},Ea=t=>e.jsx(dn,{value:t}),Ia=t=>e.jsx(e.Fragment,{children:ln(t)}),yn=t=>e.jsx("div",{style:{textAlign:"right"},children:t}),Aa=t=>e.jsx("img",{src:`data:image/*;base64,${t}`,style:{maxWidth:"50px",padding:"5px"}}),$a=(t,r,n,s)=>e.jsx(Xr,{ooui:n,value:t}),La=(t,r,n,s)=>e.jsx(e.Fragment,{children:n.selectionValues.get(t)}),Na=(t,r,n,s)=>e.jsx(e.Fragment,{children:e.jsx(wa,{value:t,selectionValues:n.selectionValues,context:s})}),Pa=(t,r,n,s)=>e.jsx(Sa,{ooui:n,value:t});function Tt(t){var W;const{page:r=1,limit:n,total:s,treeView:o,results:i,onRequestPageChange:a,loading:c,onRowClicked:h,showPagination:d=!0,rowSelection:u,scrollY:f,colorsForResults:g={},statusForResults:w={},onChangeSort:y,sorter:m,onFetchChildrenForRecord:v,childField:S,rootTree:T=!1,context:V,readonly:b,onSelectAllRecords:E}=t,[D,L]=l.useState([]),[x,F]=l.useState([]),O=l.useRef(!1),C=l.useRef(null),{t:P}=l.useContext(he),I=l.useRef(n),_=l.useContext(Ue),{title:$=void 0,setTitle:A=void 0}=(T?_:{})||{};l.useEffect(()=>{C.current=at(o);const H=ci(C.current,{boolean:_a,many2one:Da,text:ka,one2many:mn,many2many:mn,progressbar:Ea,float_time:Ia,image:Aa,integer:yn,float:yn,reference:Na,tag:$a,selection:La,date:Ma,datetime:Va,avatar:Pa},V);F(H),C.current.string&&$!==C.current.string&&(A==null||A(C.current.string))},[o]),l.useEffect(()=>{O.current=!1;const H=Ur(C.current,i);L(H),I.current=n},[i]);const M=(r-1)*I.current+1,N=M-1+D.length,k=s===void 0?null:s===0?P("no_results"):P("summary").replace("{from}",M==null?void 0:M.toString()).replace("{to}",N==null?void 0:N.toString()).replace("{total}",s==null?void 0:s.toString()),Y=()=>!d||o.isExpandable||c?null:s===void 0?e.jsx(p.Spin,{className:"pb-4"}):e.jsxs(p.Row,{align:"bottom",className:"pb-4",children:[e.jsx(p.Col,{span:8,children:e.jsx(p.Pagination,{total:s,pageSize:I.current===0?s:I.current,current:r,showSizeChanger:!1,onChange:a})}),e.jsx(p.Col,{span:8,className:"text-center",children:E&&e.jsx(Oa,{numberOfVisibleSelectedRows:X,numberOfRealSelectedRows:u==null?void 0:u.selectedRowKeys.length,numberOfTotalRows:D.length,totalRecords:s||0,onSelectAllRecords:E})}),e.jsx(p.Col,{span:8,className:"text-right",children:k})]});function J(){var R;const Q=C.current.columns.filter(z=>z.sum!==void 0).map(z=>({label:z.sum,field:z.id}));if(!Q||Q.length===0)return null;let re=[],ce=((R=u==null?void 0:u.selectedRowKeys)==null?void 0:R.length)>0?D.filter(z=>u==null?void 0:u.selectedRowKeys.includes(z.id)):D;return Q.forEach(z=>{const fe=ce.reduce((me,Fe)=>Fe[z.field]&&!isNaN(Fe[z.field])?me+Fe[z.field]:me,0);re.push(`${z.label}: ${Math.round(fe*100)/100}`)}),e.jsx("div",{className:"p-1 pb-0 pl-2 mt-2 ",children:re.join(", ")})}let j,U=f;if(C.current!==null){j=ga(x,D,600);const Q=C.current;f&&Q.columns.some(re=>re.sum!==void 0)&&(U=f-30)}const X=D.filter(H=>u==null?void 0:u.selectedRowKeys.includes(H.id)).length;return C.current===null||!j||((W=j.columns)==null?void 0:W.length)===0?e.jsx(p.Spin,{style:{padding:"2rem"}}):e.jsxs("div",{children:[Y(),c&&e.jsx(p.Spin,{className:"pb-4"}),e.jsx(vo.Table,{height:U,columns:j.columns,dataSource:D,loading:!1,loadingComponent:e.jsx(p.Spin,{}),onRowStyle:H=>{if(g[H.id])return{color:g[H.id]}},onRowStatus:di(w)?H=>{if(w[H.id])return e.jsx(p.Badge,{color:w[H.id]})}:void 0,onRowDoubleClick:h,selectionRowKeys:u==null?void 0:u.selectedRowKeys,onRowSelectionChange:u==null?void 0:u.onChange,onChangeSort:y,sorter:m,readonly:b,expandableOpts:v?{expandIcon:B.PlusSquareOutlined,collapseIcon:B.MinusSquareOutlined,loadingIcon:B.LoadingOutlined,onFetchChildrenForRecord:v,childField:S}:void 0}),J()]})}function Ba(t,r){const{model:n,formView:s,treeView:o,onRowClicked:i,nameSearch:a,treeScrollY:c,domain:h=[],visible:d=!0,rootTree:u=!1,parentContext:f={},onChangeSelectedRowKeys:g}=t,[w,y]=l.useState(!1),[m,v]=l.useState(!1),S=l.useRef(!1),[T,V]=l.useState(),[b,E]=l.useState(),[D,L]=l.useState(),[x,F]=l.useState(),[O,C]=l.useState(200),P=l.useRef(),{height:I}=Dt(),_=l.useContext(ut),{processAction:$}=_||{},A=l.useContext(Ue),{setResults:M=void 0,setCurrentItemIndex:N=void 0,currentId:k=void 0,results:Y=void 0,selectedRowItems:J=void 0,setSelectedRowItems:j=void 0,searchParams:U=[],setSearchParams:X=void 0,searchVisible:W=!0,setSearchVisible:H=void 0,sorter:Q=void 0,setSorter:re=void 0,setTotalItems:ce=void 0,setSearchTreeNameSearch:R=void 0,setTreeIsLoading:z=void 0,searchValues:fe={},setSearchValues:me=void 0,limit:Fe=bt,setLimit:Oe=void 0}=(u?A:{})||{},{submit:Ee,clear:Pe,fetchResults:we,tableRefreshing:ie,searchFilterLoading:Me,searchError:ve,page:Ve,offset:Ae,getResults:te,requestPageChange:Se,changeSort:De,fetchChildrenForRecord:Ie,colorsForResults:ae,statusForResults:ue,totalItems:Be,getAllIds:de}=nn({model:T,setSearchTreeNameSearch:R,setSelectedRowItems:ye,setSearchParams:X,setSearchValues:me,searchParams:U,setSearchVisible:H,setTreeIsLoading:z,nameSearch:a,searchNameGetDoneRef:S,context:f,formView:D,treeView:b,sorter:Q,setSorter:re,setCurrentItemIndex:N,setResultsActionView:M,resultsActionView:Y,domain:h,currentId:k,setActionViewTotalItems:ce,limit:Fe,setLimit:Oe});l.useImperativeHandle(r,()=>({refreshResults:()=>{S.current=!1,we()},getFields:()=>b==null?void 0:b.fields,getDomain:()=>h})),l.useEffect(()=>{!m||d&&(S.current=!1,we())},[Ve,Ae,m,d,a]);const ze=async()=>{v(!1),y(!0),F(void 0),z==null||z(!0);try{await $e(),v(!0)}catch(_e){F(_e),z==null||z(!1)}finally{y(!1)}},$e=async()=>{V(n);let _e=s;s||(_e=await K.getHandler().getView({model:n,type:"form",context:f}));let Le=o;o||(Le=await K.getHandler().getView({model:n,type:"tree",context:f})),L(_e),E(Le)};l.useEffect(()=>{ze()},[n]);const ee=_e=>{Oe==null||Oe(_e)},le=async _e=>{const{id:Le}=_e;P.current||(P.current=await K.getHandler().treeButOpen({id:b.view_id,model:T,context:f}));const yt=P.current[0][2];await($==null?void 0:$({actionData:yt,fields:b.fields,values:{active_id:Le,..._e},context:f}))},Ce=async _e=>{const{id:Le}=_e;if(b!=null&&b.isExpandable){try{await le(_e)}catch(yt){Ne(yt)}return}i({id:Le,model:T,formView:D,treeView:b})};function ye(_e){j==null||j(_e.map(Le=>({id:Le}))),g==null||g(_e)}async function be(){const _e=await de();j==null||j(_e.map(Le=>({id:Le}))),g==null||g(_e)}function Te(){return b!=null&&b.isExpandable?I-160:I-(O+210)}const Ge=()=>!b||!D?null:e.jsxs(e.Fragment,{children:[e.jsx(Rt,{fields:{...D.fields,...b.fields},searchFields:zr([D.search_fields,b.search_fields]),onClear:Pe,limit:Fe,offset:Ae,isSearching:Me,onSubmit:Ee,onLimitChange:ee,setSearchFilterHeight:C,searchError:ve,searchVisible:W,searchValues:fe}),e.jsx(Tt,{context:f,total:Be,limit:Fe,page:Ve,treeView:b,results:te(),onRequestPageChange:Se,loading:ie,onRowClicked:Ce,scrollY:c||Te(),colorsForResults:ae,statusForResults:ue,rowSelection:{selectedRowKeys:J==null?void 0:J.map(_e=>_e.id),onChange:ye},sorter:Q,onChangeSort:De,onFetchChildrenForRecord:b.isExpandable?Ie:void 0,childField:b.field_parent,rootTree:u,onSelectAllRecords:be})]}),He=x||ve;return He?e.jsx(p.Alert,{className:"mt-10",message:He,type:"error",banner:!0}):e.jsx("div",{style:d?{}:{display:"none"},children:w?e.jsx(p.Spin,{}):Ge()})}const tr=l.forwardRef(Ba),rr=t=>{const{visible:r,onCloseModal:n,onSelectValues:s,model:o,nameSearch:i,domain:a,context:c={}}=t,[h,d]=l.useState(!1),{modalWidth:u,modalHeight:f}=Dt(),{t:g}=l.useContext(he),[w,y]=l.useState([]),m=async()=>{await new Promise(V=>setTimeout(V,5)),n()},v=async V=>{const{id:b}=V;s([b])};function S(){if(w.length===0){m();return}s(w)}const T=()=>e.jsxs(e.Fragment,{children:[e.jsx(tr,{model:o,nameSearch:i,onRowClicked:v,treeScrollY:f*.3,domain:a,parentContext:c,onChangeSelectedRowKeys:V=>{y(V)}}),e.jsx(p.Divider,{}),e.jsx(p.Row,{justify:"end",children:e.jsxs(p.Space,{children:[e.jsx(p.Button,{icon:e.jsx(B.FileAddOutlined,{}),onClick:()=>{d(!0)},children:g("new")}),e.jsx(p.Button,{icon:e.jsx(B.CheckOutlined,{}),onClick:()=>{S()},type:"primary",children:g("ok")}),e.jsx(p.Button,{icon:e.jsx(B.CloseOutlined,{}),onClick:m,children:g("cancel")})]})})]});return e.jsxs(e.Fragment,{children:[e.jsx(p.Modal,{title:g("search"),centered:!0,width:u,open:r&&!h,closable:!0,onCancel:m,footer:null,destroyOnClose:!0,maskClosable:!1,children:T()}),e.jsx(ht,{model:o,visible:h,parentContext:c,onSubmitSucceed:V=>{d(!1),m(),s([V])},onCancel:()=>{d(!1),m()}})]})},{error:Ha}=p.Modal,Et=t=>{Ha({title:"Error",icon:e.jsx(B.ExclamationCircleOutlined,{}),centered:!0,content:t})},{defaultAlgorithm:Ka,defaultSeed:Wa}=p.theme,vn=Ka(Wa),wn=t=>{const{ooui:r}=t,{required:n}=r,s=async(o,i)=>{if(!i)throw new Error;if(!Array.isArray(i))throw new Error;if(Array.isArray(i)&&!i[0])throw new Error};return e.jsx(ge,{required:n,type:"array",validator:s,...t,children:e.jsx(Sn,{ooui:r})})},Sn=t=>{const{value:r,onChange:n,ooui:s}=t,{required:o,relation:i,readOnly:a,context:c,id:h,domain:d}=s,u=o&&!a?{backgroundColor:vn.colorPrimaryBg}:void 0,[f,g]=l.useState(!1),[w,y]=l.useState(!1),[m,v]=l.useState(!1),[S,T]=l.useState(),V=l.useRef(!1),[b,E]=l.useState(""),D=l.useRef(),L=l.useContext(ke),{domain:x,getValues:F,getFields:O,getContext:C,elementHasLostFocus:P}=L||{},I=l.useRef([]),[_,$]=l.useState([]),A=r&&r[0]||void 0,M=r&&r[1]||"";l.useEffect(()=>{!Array.isArray(r)&&r&&j(r)},[r]),l.useEffect(()=>{A&&M.length===0?j(A):A&&M.length>0?E(M):!A&&!M&&E(D.current||"")},[r]);const N=H=>{n==null||n(H),P==null||P()},k=H=>{D.current=H.target.value,N([void 0,""])},Y=async()=>{if(!m&&b!==M){if(await new Promise(H=>setTimeout(H,100)),V.current){N([void 0,""]);return}v(!0);try{if(I.current&&I.current.length>0)J(D.current);else{const H=await K.getHandler().nameSearch({model:i,payload:D.current,context:{...C==null?void 0:C(),...c}});H.length===1?(D.current=void 0,N(H[0])):J(D.current)}}catch(H){Et(H)}finally{v(!1)}}},J=async H=>{if(await U(),I.current&&I.current.length>0){const Q=await K.getHandler().searchAllIds({params:I.current,model:i,context:{...C==null?void 0:C(),...c},totalItems:2});Q.length===1?j(Q[0]):(T(H),g(!0));return}T(H),g(!0)},j=async H=>{v(!0);try{const Q=await K.getHandler().execute({action:"name_get",payload:[H],model:i,context:{...C==null?void 0:C(),...c}});N([H,Q[0][1]])}catch(Q){Et(Q)}finally{v(!1)}};async function U(){d&&(I.current=await K.getHandler().evalDomain({domain:d,values:dt({fields:O(),values:F()}),fields:O(),context:C()})),x&&x.length>0&&(I.current=I.current.concat(se.transformDomainForChildWidget({domain:x,widgetFieldName:h}))),$(I.current)}async function X(H){H.keyCode===13?(H.preventDefault(),H.stopPropagation(),await Y()):H.code==="Backspace"&&A!==void 0&&(H.preventDefault(),H.stopPropagation(),N([void 0,""]))}const W=o&&!a?Ya:p.Input;return e.jsxs(p.Row,{gutter:8,wrap:!1,children:[e.jsx(p.Col,{flex:"auto",children:e.jsx(W,{type:"text",value:b,disabled:a,onChange:k,style:u,onBlur:Y,onKeyDown:X,suffix:e.jsx(er,{id:A,model:i,context:{...C==null?void 0:C(),...c}})})}),e.jsx(p.Col,{flex:"32px",style:{paddingRight:0},children:e.jsx(p.Button,{icon:e.jsx(B.FolderOpenOutlined,{}),disabled:A===void 0||M===""||b===void 0,onClick:()=>{y(!0)},style:{borderTopRightRadius:0,borderBottomRightRadius:0},tabIndex:-1})}),e.jsx(p.Col,{flex:"32px",style:{paddingLeft:0},children:e.jsx(p.Button,{icon:m?e.jsx(B.LoadingOutlined,{}):e.jsx(B.SearchOutlined,{}),disabled:a||m,onClick:()=>{V.current=!0,J(M)},style:{borderTopLeftRadius:0,borderBottomLeftRadius:0},tabIndex:-1})}),e.jsx(rr,{model:i,domain:_,context:{...C==null?void 0:C(),...c},visible:f,nameSearch:A?void 0:S,onSelectValues:H=>{g(!1),j(H[0]),V.current=!1,D.current=void 0},onCloseModal:()=>{g(!1),V.current=!1}}),e.jsx(ht,{model:i,parentContext:{...C==null?void 0:C(),...c},id:r&&r[0],visible:w,onSubmitSucceed:H=>{y(!1),j(H)},onCancel:()=>{y(!1)},mustClearAfterSave:!0,readOnly:a})]})},Ya=ot.default(p.Input)`
36
36
  .ant-input {
37
37
  background-color: ${vn.colorPrimaryBg};
38
38
  }