@instincthub/react-ui 0.1.10 → 0.1.11
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,2 +1,2 @@
|
|
|
1
|
-
import{slicedToArray as e,objectSpread2 as t,toConsumableArray as n,asyncToGenerator as r,regeneratorRuntime as a}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as o}from"react/jsx-runtime";import c,{forwardRef as s,useRef as l,useState as u,useCallback as d,useImperativeHandle as h,useEffect as p}from"react";import b from"@mui/icons-material/FileDownloadOutlined";import m from"@mui/icons-material/RefreshOutlined";import f from"@mui/icons-material/InventoryOutlined";import v from"@mui/icons-material/ExpandMoreOutlined";import g from"@mui/icons-material/ExpandLessOutlined";import"../../../../node_modules/lodash/lodash.js";import{getNestedValue as N,reqOptions as x,API_HOST_URL as P}from"../../lib/helpFunction.js";import"../../lib/utils.js";import{l as y}from"../../../../_virtual/lodash.js";var k=s((function(s,k){var w,C,S=s.token,E=s.columns,j=s.defaultData,R=s.endpointPath,O=s.initialParams,M=void 0===O?{}:O,A=s.dataAdapter,H=s.title,L=s.emptyStateMessage,F=void 0===L?"No data available":L,D=s.emptyStateIcon,I=void 0===D?i(f,{}):D,T=s.actions,U=s.showSearch,_=void 0===U||U,B=s.searchPlaceholder,G=void 0===B?"Search...":B,J=s.searchDebounceMs,V=void 0===J?1e3:J,q=s.enableSorting,z=void 0===q||q,K=s.enableExport,Q=void 0!==K&&K,W=s.exportOptions,X=void 0===W?{csv:!0}:W,Y=s.rowsPerPageOptions,Z=void 0===Y?[10,25,50,100]:Y,$=s.defaultRowsPerPage,ee=void 0===$?10:$,te=s.onRowClick,ne=s.onFetchError,re=s.expandable,ae=void 0!==re&&re,ie=s.renderExpandedRow,oe=s.keyExtractor,ce=void 0===oe?function(e){return JSON.stringify(e)}:oe,se=s.stickyHeader,le=void 0!==se&&se,ue=s.maxHeight,de=s.hideHeaderOnMobile,he=void 0!==de&&de,pe=l(!0),be=l(null),me=u(j||[]),fe=e(me,2),ve=fe[0],ge=fe[1],Ne=u(!0),xe=e(Ne,2),Pe=xe[0],ye=xe[1],ke=u(null),we=e(ke,2),Ce=we[0],Se=we[1],Ee=u({totalCount:0,currentPage:1,perPage:ee,totalPages:0}),je=e(Ee,2),Re=je[0],Oe=je[1],Me=u(t({page:1,limit:ee},M)),Ae=e(Me,2),He=Ae[0],Le=Ae[1],Fe=u([]),De=e(Fe,2),Ie=De[0],Te=De[1],Ue=u(M.search||""),_e=e(Ue,2),Be=_e[0],Ge=_e[1],Je=d(y.exports.debounce((function(e){Le((function(n){return t(t({},n),{},{search:e,page:1})}))}),V),[]),Ve={data:j||[],pagination:{totalCount:null===(w=j||[])||void 0===w?void 0:w.length,currentPage:"",perPage:10,totalPages:Math.ceil(((null===(C=j||[])||void 0===C?void 0:C.length)||10)/10)},links:{next:"",previous:""}},qe=d(function(){var e=r(a().mark((function e(t){var n,r,i,o,c,s;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(ye(!0),e.prev=1,R){e.next=4;break}return e.abrupt("return",Ve);case 4:return n=new URLSearchParams({limit:t.limit.toString(),offset:((t.page-1)*t.limit).toString()}),t.search&&n.append("search",t.search),t.sort&&(r="desc"===t.direction?"-":"",n.append("ordering","".concat(r).concat(t.sort))),i=x("GET",null,S),o="".concat(P).concat(R,"?").concat(n.toString()),e.next=11,fetch(o,i);case 11:return c=e.sent,e.next=14,c.json();case 14:return s=e.sent,e.abrupt("return",{data:s.results,pagination:{totalCount:s.count,currentPage:Math.floor(parseInt(new URLSearchParams(s.next).get("offset")||"0")/t.limit),perPage:t.limit,totalPages:Math.ceil(s.count/t.limit)},links:{next:s.next,previous:s.previous}});case 18:throw e.prev=18,e.t0=e.catch(1),console.error("Error fetching program courses:",e.t0),e.t0;case 22:return e.prev=22,ye(!1),e.finish(22);case 25:case"end":return e.stop()}}),e,null,[[1,18,22,25]])})));return function(t){return e.apply(this,arguments)}}(),[]),ze=d((function(e){var t=e.target.value;Ge(t),Je(t)}),[Je]),Ke=d((function(e){Le((function(n){return t(t({},n),{},{page:e})}))}),[]),Qe=d((function(e){Le((function(n){return t(t({},n),{},{page:1,limit:e})}))}),[]),We=d((function(e){if(z&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;Le((function(e){return e.sort===n?t(t({},e),{},{direction:"asc"===e.direction?"desc":"asc"}):t(t({},e),{},{sort:n,direction:"asc"})}))}}),[z]),Xe=d((function(){Le((function(e){return t({},e)}))}),[]);h(k,(function(){return{refresh:Xe}}),[Xe]);var Ye=d(function(){var e=r(a().mark((function e(r){var i,o,c,s,l,u,d,h,p,b;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(Q){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,ye(!0),i=t(t({},He),{},{page:1,limit:1e3,export:r}),e.next=7,qe(i);case 7:(o=e.sent)&&(c=A?A(o).data:o.data,s=X.fileName||"table-export","csv"===r&&(l=E.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})),u=c.map((function(e){return E.filter((function(e){return"string"==typeof e.accessor})).map((function(t){var n,r=t.accessor;return String(null!==(n=e[r])&&void 0!==n?n:"")})).join(",")})),d=[l.join(",")].concat(n(u)).join("\n"),h=new Blob([d],{type:"text/csv;charset=utf-8;"}),p=document.createElement("a"),b=URL.createObjectURL(h),p.setAttribute("href",b),p.setAttribute("download","".concat(s,".csv")),p.style.visibility="hidden",document.body.appendChild(p),p.click(),document.body.removeChild(p))),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(2),console.error("Export error:",e.t0),ne&&ne(e.t0);case 15:return e.prev=15,ye(!1),e.finish(15);case 18:case"end":return e.stop()}}),e,null,[[2,11,15,18]])})));return function(t){return e.apply(this,arguments)}}(),[E,He,Q,X,A,ne]),Ze=d((function(e,t){t.stopPropagation(),Te((function(t){return t.includes(e)?t.filter((function(t){return t!==e})):[].concat(n(t),[e])}))}),[]);return p((function(){var e=!0,t=function(){var t=r(a().mark((function t(){var n,r;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,ye(!0),t.next=4,qe(He);case 4:n=t.sent,e&&(A?(r=A(n),ge(r.data),r.pagination&&Oe(r.pagination)):n&&(ge(n.data),n.pagination&&Oe(n.pagination)),Se(null)),t.next=12;break;case 8:t.prev=8,t.t0=t.catch(0),console.error("Error fetching data:",t.t0),e&&(Se(t.t0),ne&&ne(t.t0));case 12:return t.prev=12,e&&(ye(!1),pe.current=!1),t.finish(12);case 15:case"end":return t.stop()}}),t,null,[[0,8,12,15]])})));return function(){return t.apply(this,arguments)}}();return t(),function(){e=!1}}),[He,A,ne]),Pe&&pe.current?o("div",{className:"ihub-data-list-container",children:[H&&i("h2",{children:H}),i("div",{className:"ihub-loading-state",children:i("p",{children:"Loading data..."})})]}):Ce&&!Pe&&0===(ve||[]).length?o("div",{className:"ihub-data-list-container",children:[H&&i("h2",{children:H}),o("div",{className:"ihub-error-state",children:[i("p",{children:"Error loading data. Please try again."}),i("button",{className:"ihub-important-btn",onClick:Xe,children:"Retry"})]})]}):o("div",{className:"ihub-data-list-container",ref:be,children:[(H||T||_||Q)&&o("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[i("div",{children:H&&i("h2",{children:H})}),o("div",{className:"ihub-table-controls",children:[_&&i("div",{className:"ihub-table-search",children:o("div",{className:"ihub-search-input-wrapper",children:[i("input",{type:"text",placeholder:G,value:Be,onChange:ze,className:"ihub-search-input"}),Pe&&i("div",{className:"ihub-search-loading-indicator",children:i("span",{className:"ihub-loading-dot"})})]})}),Q&&o("div",{className:"ihub-export-buttons",children:[X.csv&&o("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return Ye("csv")},disabled:Pe,children:[i(b,{}),"CSV"]}),X.excel&&o("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return Ye("excel")},disabled:Pe,children:[i(b,{}),"Excel"]}),X.pdf&&o("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return Ye("pdf")},disabled:Pe,children:[i(b,{}),"PDF"]})]}),o("button",{className:"ihub-refresh-button",onClick:Xe,disabled:Pe,children:[i(m,{}),"Refresh"]}),T&&i("div",{className:"ihub-data-controls ihub-mb-0",children:T})]})]}),Pe&&!pe.current&&i("div",{className:"ihub-table-loading-overlay",children:i("div",{className:"ihub-loading-spinner"})}),o("div",{className:"ihub-scroll-container ".concat(le?"ihub-sticky-header":""),style:ue?{maxHeight:ue}:void 0,children:[o("table",{className:"ihub-table ihub-scroll-container",children:[i("thead",{className:he?"ihub-hide-on-mobile":"",children:o("tr",{children:[ae&&ie&&i("th",{style:{width:"40px"}}),E.map((function(e,t){return i("th",{className:"".concat(e.sortable&&z?"ihub-sortable-column":""," ").concat(He.sort===e.accessor?"ihub-sorted-".concat(He.direction):""),style:e.width?{width:e.width}:void 0,onClick:function(){return e.sortable&&z?We(e):void 0},children:o("div",{className:"ihub-column-header",children:[i("span",{children:e.header}),e.sortable&&z&&i("span",{className:"ihub-sort-icon",children:He.sort===e.accessor&&"asc"===He.direction?"▲":He.sort===e.accessor&&"desc"===He.direction?"▼":"⇅"})]})},t)}))]})}),Pe||0!==(ve||[]).length?i("tbody",{children:ve.map((function(e,t){var n=ce(e),r=Ie.includes(n);return o(c.Fragment,{children:[o("tr",{onClick:function(){return te&&te(e)},className:te?"ihub-clickable-row":"",children:[ae&&ie&&i("td",{onClick:function(e){return Ze(n,e)},children:i(r?g:v,{})}),E.map((function(t,n){return i("td",{"data-label":he?t.header:void 0,children:t.tooltip&&"string"==typeof t.accessor?i("div",{className:"ihub-cell-tooltip","data-tooltip":String(N(e,t.accessor)),children:t.cell?t.cell(e):N(e,t.accessor)}):t.cell?t.cell(e):"function"==typeof t.accessor?t.accessor(e):N(e,t.accessor)},n)}))]}),ae&&ie&&r&&i("tr",{className:"ihub-expanded-row",children:i("td",{colSpan:(E||[]).length+1,children:i("div",{className:"ihub-row-details",children:ie(e)})})})]},n)}))}):""]}),Pe||0!==(ve||[]).length?"":o("div",{className:"ihub-data-list-container",children:[T&&i("div",{className:"ihub-data-controls ihub-mb-0",children:T}),i("div",{className:"ihub-empty-state",children:o("div",{children:[I,i("p",{children:F})]})})]})]}),Re&&Re.totalPages>1&&o("div",{className:"ihub-table-pagination",children:[o("div",{className:"ihub-pagination-info",children:["Showing ",(Re.currentPage-1)*Re.perPage+1," to"," ",Math.min(Re.currentPage*Re.perPage,Re.totalCount)," ","of ",Re.totalCount," entries"]}),o("div",{className:"ihub-pagination-controls",children:[i("button",{className:"ihub-pagination-button",disabled:1===Re.currentPage||Pe,onClick:function(){return Ke(1)},children:"«"}),i("button",{className:"ihub-pagination-button",disabled:1===Re.currentPage||Pe,onClick:function(){return Ke(Re.currentPage-1)},children:"‹"}),Array.from({length:Math.min(5,Re.totalPages)},(function(e,t){var n;return n=Re.totalPages<=5||Re.currentPage<=3?t+1:Re.currentPage>=Re.totalPages-2?Re.totalPages-4+t:Re.currentPage-2+t,i("button",{className:"ihub-pagination-button ".concat(Re.currentPage===n?"ihub-active":""),onClick:function(){return Ke(Number(n))},disabled:Pe,children:n},n)})),i("button",{className:"ihub-pagination-button",disabled:Re.currentPage===Re.totalPages||Pe,onClick:function(){return Ke(Re.currentPage+1)},children:"›"}),i("button",{className:"ihub-pagination-button",disabled:Re.currentPage===Re.totalPages||Pe,onClick:function(){return Ke(Re.totalPages)},children:"»"})]}),o("div",{className:"ihub-rows-per-page",children:[i("span",{children:"Rows per page:"}),i("select",{value:Re.perPage,onChange:function(e){return Qe(Number(e.target.value))},className:"ihub-rows-select",disabled:Pe,children:Z.map((function(e){return i("option",{value:e,children:e},e)}))})]})]})]})}));k.displayName="IHubTableServer";export{k as IHubTableServer,k as default};
|
|
1
|
+
import{slicedToArray as e,objectSpread2 as t,toConsumableArray as n,asyncToGenerator as r,regeneratorRuntime as a}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{jsx as i,jsxs as o}from"react/jsx-runtime";import c,{forwardRef as s,useRef as l,useState as u,useCallback as d,useImperativeHandle as h,useEffect as p}from"react";import b from"@mui/icons-material/FileDownloadOutlined";import m from"@mui/icons-material/RefreshOutlined";import f from"@mui/icons-material/InventoryOutlined";import v from"@mui/icons-material/ExpandMoreOutlined";import g from"@mui/icons-material/ExpandLessOutlined";import"../../../../node_modules/lodash/lodash.js";import{getNestedValue as N,reqOptions as P,API_HOST_URL as x}from"../../lib/helpFunction.js";import"../../lib/utils.js";import{l as y}from"../../../../_virtual/lodash.js";var k=s((function(s,k){var w,C,S=s.token,E=s.columns,j=s.defaultData,R=s.endpointPath,O=s.initialParams,M=void 0===O?{}:O,A=s.searchParams,H=s.dataAdapter,L=s.title,F=s.emptyStateMessage,D=void 0===F?"No data available":F,I=s.emptyStateIcon,T=void 0===I?i(f,{}):I,U=s.actions,_=s.showSearch,B=void 0===_||_,G=s.searchPlaceholder,J=void 0===G?"Search...":G,V=s.searchDebounceMs,q=void 0===V?1e3:V,z=s.enableSorting,K=void 0===z||z,Q=s.enableExport,W=void 0!==Q&&Q,X=s.exportOptions,Y=void 0===X?{csv:!0}:X,Z=s.rowsPerPageOptions,$=void 0===Z?[10,25,50,100]:Z,ee=s.defaultRowsPerPage,te=void 0===ee?10:ee,ne=s.onRowClick,re=s.onFetchError,ae=s.expandable,ie=void 0!==ae&&ae,oe=s.renderExpandedRow,ce=s.keyExtractor,se=void 0===ce?function(e){return JSON.stringify(e)}:ce,le=s.stickyHeader,ue=void 0!==le&&le,de=s.maxHeight,he=s.hideHeaderOnMobile,pe=void 0!==he&&he,be=l(!0),me=l(null),fe=u(j||[]),ve=e(fe,2),ge=ve[0],Ne=ve[1],Pe=u(!0),xe=e(Pe,2),ye=xe[0],ke=xe[1],we=u(null),Ce=e(we,2),Se=Ce[0],Ee=Ce[1],je=u({totalCount:0,currentPage:1,perPage:te,totalPages:0}),Re=e(je,2),Oe=Re[0],Me=Re[1],Ae=u(t({page:1,limit:te},M)),He=e(Ae,2),Le=He[0],Fe=He[1],De=u([]),Ie=e(De,2),Te=Ie[0],Ue=Ie[1],_e=u(M.search||""),Be=e(_e,2),Ge=Be[0],Je=Be[1],Ve=d(y.exports.debounce((function(e){Fe((function(n){return t(t({},n),{},{search:e,page:1})}))}),q),[]),qe={data:j||[],pagination:{totalCount:null===(w=j||[])||void 0===w?void 0:w.length,currentPage:"",perPage:10,totalPages:Math.ceil(((null===(C=j||[])||void 0===C?void 0:C.length)||10)/10)},links:{next:"",previous:""}},ze=d(function(){var t=r(a().mark((function t(n){var r,i,o,c,s,l;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(ke(!0),t.prev=1,R){t.next=4;break}return t.abrupt("return",qe);case 4:return r=new URLSearchParams({limit:n.limit.toString(),offset:((n.page-1)*n.limit).toString()}),n.search&&r.append("search",n.search),n.sort&&(i="desc"===n.direction?"-":"",r.append("ordering","".concat(i).concat(n.sort))),A&&Object.entries(A).forEach((function(t){var n=e(t,2),a=n[0],i=n[1];null!=i&&""!==i&&r.append(a,String(i))})),o=P("GET",null,S),c="".concat(x).concat(R,"?").concat(r.toString()),t.next=12,fetch(c,o);case 12:return s=t.sent,t.next=15,s.json();case 15:return l=t.sent,t.abrupt("return",{data:l.results,pagination:{totalCount:l.count,currentPage:Math.floor(parseInt(new URLSearchParams(l.next).get("offset")||"0")/n.limit),perPage:n.limit,totalPages:Math.ceil(l.count/n.limit)},links:{next:l.next,previous:l.previous}});case 19:throw t.prev=19,t.t0=t.catch(1),console.error("Error fetching program courses:",t.t0),t.t0;case 23:return t.prev=23,ke(!1),t.finish(23);case 26:case"end":return t.stop()}}),t,null,[[1,19,23,26]])})));return function(e){return t.apply(this,arguments)}}(),[A]),Ke=d((function(e){var t=e.target.value;Je(t),Ve(t)}),[Ve]),Qe=d((function(e){Fe((function(n){return t(t({},n),{},{page:e})}))}),[]),We=d((function(e){Fe((function(n){return t(t({},n),{},{page:1,limit:e})}))}),[]),Xe=d((function(e){if(K&&e.sortable&&"string"==typeof e.accessor){var n=e.accessor;Fe((function(e){return e.sort===n?t(t({},e),{},{direction:"asc"===e.direction?"desc":"asc"}):t(t({},e),{},{sort:n,direction:"asc"})}))}}),[K]),Ye=d((function(){Fe((function(e){return t({},e)}))}),[]);h(k,(function(){return{refresh:Ye}}),[Ye]);var Ze=d(function(){var e=r(a().mark((function e(r){var i,o,c,s,l,u,d,h,p,b;return a().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(W){e.next=2;break}return e.abrupt("return");case 2:return e.prev=2,ke(!0),i=t(t({},Le),{},{page:1,limit:1e3,export:r}),e.next=7,ze(i);case 7:(o=e.sent)&&(c=H?H(o).data:o.data,s=Y.fileName||"table-export","csv"===r&&(l=E.filter((function(e){return"string"==typeof e.accessor})).map((function(e){return e.header})),u=c.map((function(e){return E.filter((function(e){return"string"==typeof e.accessor})).map((function(t){var n,r=t.accessor;return String(null!==(n=e[r])&&void 0!==n?n:"")})).join(",")})),d=[l.join(",")].concat(n(u)).join("\n"),h=new Blob([d],{type:"text/csv;charset=utf-8;"}),p=document.createElement("a"),b=URL.createObjectURL(h),p.setAttribute("href",b),p.setAttribute("download","".concat(s,".csv")),p.style.visibility="hidden",document.body.appendChild(p),p.click(),document.body.removeChild(p))),e.next=15;break;case 11:e.prev=11,e.t0=e.catch(2),console.error("Export error:",e.t0),re&&re(e.t0);case 15:return e.prev=15,ke(!1),e.finish(15);case 18:case"end":return e.stop()}}),e,null,[[2,11,15,18]])})));return function(t){return e.apply(this,arguments)}}(),[E,Le,W,Y,H,re]),$e=d((function(e,t){t.stopPropagation(),Ue((function(t){return t.includes(e)?t.filter((function(t){return t!==e})):[].concat(n(t),[e])}))}),[]);return p((function(){var e=!0,t=function(){var t=r(a().mark((function t(){var n,r;return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,ke(!0),t.next=4,ze(Le);case 4:n=t.sent,e&&(H?(r=H(n),Ne(r.data),r.pagination&&Me(r.pagination)):n&&(Ne(n.data),n.pagination&&Me(n.pagination)),Ee(null)),t.next=12;break;case 8:t.prev=8,t.t0=t.catch(0),console.error("Error fetching data:",t.t0),e&&(Ee(t.t0),re&&re(t.t0));case 12:return t.prev=12,e&&(ke(!1),be.current=!1),t.finish(12);case 15:case"end":return t.stop()}}),t,null,[[0,8,12,15]])})));return function(){return t.apply(this,arguments)}}();return t(),function(){e=!1}}),[Le,H,re]),p((function(){A&&!be.current&&Fe((function(e){return t({},e)}))}),[A]),ye&&be.current?o("div",{className:"ihub-data-list-container",children:[L&&i("h2",{children:L}),i("div",{className:"ihub-loading-state",children:i("p",{children:"Loading data..."})})]}):Se&&!ye&&0===(ge||[]).length?o("div",{className:"ihub-data-list-container",children:[L&&i("h2",{children:L}),o("div",{className:"ihub-error-state",children:[i("p",{children:"Error loading data. Please try again."}),i("button",{className:"ihub-important-btn",onClick:Ye,children:"Retry"})]})]}):o("div",{className:"ihub-data-list-container",ref:me,children:[(L||U||B||W)&&o("div",{className:"ihub-data-list-header ihub-table-header ihub-p-0",children:[i("div",{children:L&&i("h2",{children:L})}),o("div",{className:"ihub-table-controls",children:[B&&i("div",{className:"ihub-table-search",children:o("div",{className:"ihub-search-input-wrapper",children:[i("input",{type:"text",placeholder:J,value:Ge,onChange:Ke,className:"ihub-search-input"}),ye&&i("div",{className:"ihub-search-loading-indicator",children:i("span",{className:"ihub-loading-dot"})})]})}),W&&o("div",{className:"ihub-export-buttons",children:[Y.csv&&o("button",{className:"ihub-export-button ihub-export-csv",onClick:function(){return Ze("csv")},disabled:ye,children:[i(b,{}),"CSV"]}),Y.excel&&o("button",{className:"ihub-export-button ihub-export-excel",onClick:function(){return Ze("excel")},disabled:ye,children:[i(b,{}),"Excel"]}),Y.pdf&&o("button",{className:"ihub-export-button ihub-export-pdf",onClick:function(){return Ze("pdf")},disabled:ye,children:[i(b,{}),"PDF"]})]}),o("button",{className:"ihub-refresh-button",onClick:Ye,disabled:ye,children:[i(m,{}),"Refresh"]}),U&&i("div",{className:"ihub-data-controls ihub-mb-0",children:U})]})]}),ye&&!be.current&&i("div",{className:"ihub-table-loading-overlay",children:i("div",{className:"ihub-loading-spinner"})}),o("div",{className:"ihub-scroll-container ".concat(ue?"ihub-sticky-header":""),style:de?{maxHeight:de}:void 0,children:[o("table",{className:"ihub-table ihub-scroll-container",children:[i("thead",{className:pe?"ihub-hide-on-mobile":"",children:o("tr",{children:[ie&&oe&&i("th",{style:{width:"40px"}}),E.map((function(e,t){return i("th",{className:"".concat(e.sortable&&K?"ihub-sortable-column":""," ").concat(Le.sort===e.accessor?"ihub-sorted-".concat(Le.direction):""),style:e.width?{width:e.width}:void 0,onClick:function(){return e.sortable&&K?Xe(e):void 0},children:o("div",{className:"ihub-column-header",children:[i("span",{children:e.header}),e.sortable&&K&&i("span",{className:"ihub-sort-icon",children:Le.sort===e.accessor&&"asc"===Le.direction?"▲":Le.sort===e.accessor&&"desc"===Le.direction?"▼":"⇅"})]})},t)}))]})}),ye||0!==(ge||[]).length?i("tbody",{children:ge.map((function(e,t){var n=se(e),r=Te.includes(n);return o(c.Fragment,{children:[o("tr",{onClick:function(){return ne&&ne(e)},className:ne?"ihub-clickable-row":"",children:[ie&&oe&&i("td",{onClick:function(e){return $e(n,e)},children:i(r?g:v,{})}),E.map((function(t,n){return i("td",{"data-label":pe?t.header:void 0,children:t.tooltip&&"string"==typeof t.accessor?i("div",{className:"ihub-cell-tooltip","data-tooltip":String(N(e,t.accessor)),children:t.cell?t.cell(e):N(e,t.accessor)}):t.cell?t.cell(e):"function"==typeof t.accessor?t.accessor(e):N(e,t.accessor)},n)}))]}),ie&&oe&&r&&i("tr",{className:"ihub-expanded-row",children:i("td",{colSpan:(E||[]).length+1,children:i("div",{className:"ihub-row-details",children:oe(e)})})})]},n)}))}):""]}),ye||0!==(ge||[]).length?"":o("div",{className:"ihub-data-list-container",children:[U&&i("div",{className:"ihub-data-controls ihub-mb-0",children:U}),i("div",{className:"ihub-empty-state",children:o("div",{children:[T,i("p",{children:D})]})})]})]}),Oe&&Oe.totalPages>1&&o("div",{className:"ihub-table-pagination",children:[o("div",{className:"ihub-pagination-info",children:["Showing ",(Oe.currentPage-1)*Oe.perPage+1," to"," ",Math.min(Oe.currentPage*Oe.perPage,Oe.totalCount)," ","of ",Oe.totalCount," entries"]}),o("div",{className:"ihub-pagination-controls",children:[i("button",{className:"ihub-pagination-button",disabled:1===Oe.currentPage||ye,onClick:function(){return Qe(1)},children:"«"}),i("button",{className:"ihub-pagination-button",disabled:1===Oe.currentPage||ye,onClick:function(){return Qe(Oe.currentPage-1)},children:"‹"}),Array.from({length:Math.min(5,Oe.totalPages)},(function(e,t){var n;return n=Oe.totalPages<=5||Oe.currentPage<=3?t+1:Oe.currentPage>=Oe.totalPages-2?Oe.totalPages-4+t:Oe.currentPage-2+t,i("button",{className:"ihub-pagination-button ".concat(Oe.currentPage===n?"ihub-active":""),onClick:function(){return Qe(Number(n))},disabled:ye,children:n},n)})),i("button",{className:"ihub-pagination-button",disabled:Oe.currentPage===Oe.totalPages||ye,onClick:function(){return Qe(Oe.currentPage+1)},children:"›"}),i("button",{className:"ihub-pagination-button",disabled:Oe.currentPage===Oe.totalPages||ye,onClick:function(){return Qe(Oe.totalPages)},children:"»"})]}),o("div",{className:"ihub-rows-per-page",children:[i("span",{children:"Rows per page:"}),i("select",{value:Oe.perPage,onChange:function(e){return We(Number(e.target.value))},className:"ihub-rows-select",disabled:ye,children:$.map((function(e){return i("option",{value:e,children:e},e)}))})]})]})]})}));k.displayName="IHubTableServer";export{k as IHubTableServer,k as default};
|
|
2
2
|
//# sourceMappingURL=IHubTableServer.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { ApiResponseType, TableColumnType } from "@/types";
|
|
2
|
+
import { ApiResponseType, SearchParamsType, TableColumnType } from "@/types";
|
|
3
3
|
import { FetchParamsType } from "@/types";
|
|
4
4
|
export interface IHubTableServerRef {
|
|
5
5
|
refresh: () => void;
|
|
@@ -11,6 +11,8 @@ interface IHubTableServerPropsType<T> {
|
|
|
11
11
|
defaultData?: any[];
|
|
12
12
|
endpointPath: string;
|
|
13
13
|
initialParams?: Partial<FetchParamsType>;
|
|
14
|
+
/** External search parameters that trigger table refetch when changed */
|
|
15
|
+
searchParams?: SearchParamsType;
|
|
14
16
|
dataAdapter?: (apiResponse: any) => ApiResponseType<T>;
|
|
15
17
|
title?: string;
|
|
16
18
|
emptyStateMessage?: string;
|
|
@@ -49,6 +51,7 @@ interface IHubTableServerPropsType<T> {
|
|
|
49
51
|
* columns={columns}
|
|
50
52
|
* endpointPath={"/api/program-courses"}
|
|
51
53
|
* initialParams={{ sort: "title", direction: "asc" }}
|
|
54
|
+
* searchParams={{ category: "active", status: "published" }}
|
|
52
55
|
* title="Program Courses"
|
|
53
56
|
* showSearch={true}
|
|
54
57
|
* enableSorting={true}
|
|
@@ -85,6 +88,7 @@ interface IHubTableServerPropsType<T> {
|
|
|
85
88
|
* @prop {any<T>[]} defaultData - The default data of the table
|
|
86
89
|
* @prop {string} endpointPath - The path to the API endpoint
|
|
87
90
|
* @prop {Partial<FetchParamsType>} initialParams - The initial parameters for the API request
|
|
91
|
+
* @prop {Record<string, any>} searchParams - External search parameters that trigger table refetch when changed
|
|
88
92
|
* @prop {string} title - The title of the table
|
|
89
93
|
* @prop {boolean} showSearch - Whether to show the search input
|
|
90
94
|
* @prop {boolean} enableSorting - Whether to enable sorting
|