UNPKG

@devgateway/dvz-ui-react

Version:

A modular, embeddable React component library for data visualization and UI, built with TypeScript. Provides reusable components for charts, maps, dashboards, and more, with built-in support for internationalization and Redux integration.

2 lines (1 loc) 4.33 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("react/jsx-runtime"),p=require("react"),A=require("@devgateway/wp-react-lib"),x=require("semantic-ui-react"),W=require("./Post.js"),E=require("./utils.js"),d=require("../../utils/data.js"),V=require("./DropDownFilter.js"),K=P=>{const{posts:o,meta:i,showPaginationOptions:j,currentPage:h,setCurrentPage:S,countryCategory:F,height:r}=P,y=d.toNumber(F),v=Array.isArray(o)?o.filter(s=>s.categories.includes(y)):[],g=Array.isArray(o)?o.filter(s=>!s.categories.includes(y)):[],n=[...v,...g],l=i&&i["x-wp-totalpages"]?i["x-wp-totalpages"]:1;return e.jsxs("div",{children:[e.jsx("div",{className:"posts-grid",children:n==null?void 0:n.map(s=>e.jsx(W.default,{post:s},s.id))}),j&&e.jsxs("div",{className:"pagination-section",children:[e.jsxs("div",{className:"pagination-info",children:["Page ",e.jsx("span",{className:"current-page",children:h})," of ",l]}),e.jsx(x.Pagination,{activePage:h,totalPages:l,onPageChange:(s,{activePage:c})=>S(c),prevItem:{content:e.jsx(x.Icon,{name:"angle left"}),icon:!0},nextItem:{content:e.jsx(x.Icon,{name:"angle right"}),icon:!0},firstItem:null,lastItem:null})]})]})},M=P=>{const{categories:o,selectedCategory:i,setSelectedCategory:j,selectedYear:h,setSelectedYear:S,onResetFilters:F,showCategoryFilter:r,categoryPlaceholder:y,showDateFilter:v,categoriesToBeShown:g,setCurrentPage:n,showCountryFilter:l,countryPlaceholder:s,countryCategory:c,selectedCountry:N,setSelectedCountry:C}=P,[I,Y]=p.useState([]);p.useEffect(()=>{const t=async()=>{const O=(await A.getYearRange()).data.map(b=>({key:b,value:b,text:`Year ${b}`}));Y(O)};return t(),()=>{t()}},[]);const f=o&&g?o.filter(t=>g.includes(t.id)):[],D=o&&c?o.filter(t=>t.parent===parseInt(c)):[];return e.jsx("div",{children:e.jsxs("div",{children:[l&&e.jsx(V.default,{options:D.map(t=>({key:t.id,value:t.id,text:t.name})),placeholder:s,value:N,onChange:(t,{value:a})=>{C(a),n(1)}}),v&&e.jsx(V.default,{options:I,placeholder:"Select Year",value:h,onChange:(t,{value:a})=>{S(a),n(1)},multiple:!1,searchable:!0,showAllNone:!1,closeOnSelect:!0}),r&&e.jsx(V.default,{options:f?f.map(t=>({key:t.id,value:t.id,text:t.name})):[],placeholder:y||"All Countries",value:i,onChange:(t,{value:a})=>{j(a),n(1)},multiple:!1,searchable:!1,showAllNone:!1,closeOnSelect:!0}),e.jsxs(x.Container,{className:`data-filters-reset ignore ${i||h||N?"":"disabled"}`,onClick:F,children:[e.jsx("span",{children:"Reset Filters"}),e.jsx("span",{children:e.jsx(x.Icon,{name:"undo alternate",className:"custom-undo-icon"})})]})]})})},U=P=>{const{"data-height":o,"data-show-pagination":i,"data-show-posts-per-page":j,"data-show-filters":h,"data-show-date-filter":S,"data-show-category-filter":F,"data-categories":r,"data-category-placeholder":y,"data-show-country-filter":v,"data-country-category":g,"data-country-placeholder":n}=P,[l,s]=p.useState(null),[c,N]=p.useState(null),[C,I]=p.useState(null),[Y,f]=p.useState(1),[D,t]=p.useState(0),a=d.toNumber(o),q=d.toBoolean(i),O=d.toNumber(j),b=d.toBoolean(h),B=d.toBoolean(S),R=d.toBoolean(F),k=d.toBoolean(v),T=()=>{s(null),N(null),I(null),f(1),t(u=>u+1)},m=c?E.getStartDateAndEndDateFromYear(c):null;let w=[];try{if(r)if(Array.isArray(r))w=r;else if(typeof r=="string"){const u=decodeURIComponent(r);u&&u!=="undefined"&&(w=JSON.parse(u))}else w=r}catch{w=[]}return console.log(a,"heightValue"),e.jsxs(x.Container,{fluid:!0,className:"container",style:{height:a+"px",minHeight:a+"px"},children:[b&&e.jsx(A.CategoriesProvider,{children:e.jsx(A.CategoriesContext.Consumer,{children:({categories:u})=>e.jsx(M,{showCategoryFilter:R,categoryPlaceholder:y,showDateFilter:B,categories:u||[],categoriesToBeShown:w,selectedCategory:l,setSelectedCategory:s,selectedYear:c,setSelectedYear:N,onResetFilters:T,setCurrentPage:f,showCountryFilter:k,countryPlaceholder:n,countryCategory:g,selectedCountry:C,setSelectedCountry:I})})}),e.jsx(A.PostProvider,{perPage:O||10,store:"posts-with-filters",categories:(C==null?void 0:C.toString())||(l==null?void 0:l.toString())||w.join(","),after:(m==null?void 0:m.startDate)||null,before:(m==null?void 0:m.endDate)||null,page:Y,children:e.jsx(A.PostConsumer,{children:e.jsx(K,{showPaginationOptions:q,currentPage:Y,setCurrentPage:f,countryCategory:g,height:a})})},D)]})};exports.default=U;