@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) • 8.69 kB
JavaScript
"use strict";const e=require("react/jsx-runtime"),N=require("react"),l=require("semantic-ui-react"),G=require("../data/CategoriesConsumer.js"),J=require("../data/CategoriesProvider.js"),P=require("react-redux"),M=require("../reducers/data.js"),K=require("react-intl"),H=require("@devgateway/wp-react-lib"),Y="multi-select",_="single-select",Q="NO_DATA",X="DEFAULT_VALUE_INPUT",Z="LOWEST_VALUE",ee="HIGHEST_VALUE",E=n=>n instanceof Boolean?n:n=="true",te=(n,i)=>n?n.sort((s,u)=>s.position-u.position).map(s=>{const u=i&&s.labels&&s.labels[i.toUpperCase()]?s.labels[i.toUpperCase()]:s.value;return{key:s.id,value:s.id,text:u,icon:s.value.toLocaleLowerCase(),position:s.position?s.position:s.value}}):[],ne=n=>decodeURIComponent(n),W=n=>{if(!n||n=="")return null;try{return JSON.parse(ne(n))}catch(i){throw new Error("error parsing value:"+i)}},V=(n,i)=>{const{app:s,group:u,param:o}=i;return{current:n.getIn(["data","filters",s,u,o])}},$={onInit:M.setInitialFilters,onChange:M.setFilter},B=n=>{const{isRange:i,options:s,alphabeticalSort:u,ascOrder:o}=n;let f=[];E(u)?f=s.sort(function(d,r){const m=d.text?d.text.toLowerCase():"",c=r.text?r.text.toLowerCase():"";return E(o)?m<c?-1:m>c?1:0:m<c?1:m>c?-1:0}):f=s.sort(function(d,r){return E(o)?d.position-r.position:r.position-d.position});const h={...n,options:f};return i?e.jsx(le,{...h}):e.jsx(re,{...h})},re=P.connect(V,$)(n=>{const{allLabel:i,noneLabel:s,placeholder:u,options:o,app:f,group:h,param:d,current:r,onChange:m,onInit:c,useSingleColumn:F,enableTextSearch:C,filterType:w,defaultValues:T,showNoDataOption:I,defaultValueCriteria:x,allNoneSameBehaviour:g,closeOnSelect:v,hiddenFilters:L,autoApply:D}=n,[O,y]=N.useState(""),A=t=>{let a=[];w!=_&&!v&&r&&r.indexOf(t)>-1?a=r.filter(p=>p!==t):w!=_&&r&&!v?a=[...r,t]:a=[t],m({app:f,group:h,param:d,value:a,autoApply:D}),v&&S.current&&S.current.close()},R=t=>{const a=o.filter(p=>C&&j&&j.trim().length>0&&p.text?p.text.toLowerCase().includes(j.toLowerCase()):!0);m({app:f,group:h,param:d,value:a.map(p=>p.value),autoApply:D}),v&&S.current&&S.current.close()},k=()=>{const t=o.filter(a=>C&&j&&j.trim().length>0&&a.text?a.text.toLowerCase().includes(j.toLowerCase()):!0);m({app:f,group:h,param:d,value:g?t.map(a=>a.value):[],autoApply:D}),v&&S.current&&S.current.close()},q=t=>{U(t);const a=o.filter(p=>C&&t&&t.trim().length>0&&p.text?p.text.toLowerCase().includes(t.toLowerCase()):!0);m({app:f,group:h,param:d,value:a.map(p=>p.value),autoApply:D})};N.useEffect(()=>{if(!r){const t=o.map(a=>a.value);if(w==Y||w=="")c({app:f,group:h,param:d,value:t});else if(f=="csv"){let a=[];x===X?a=T?T.split(","):[]:x==Z?a=t.length>0?[t[0]]:[]:x==ee&&(a=t.length>0?[t[t.length-1]]:[]),c({app:f,group:h,param:d,value:a})}else c({app:f,group:h,param:d,value:[t[0]]})}},[]);const b=()=>{if(w==_){const t=r&&r[0]?o.filter(a=>a.value==r[0])[0]:null;return`${u} ${t?t.text:""}`}else return`${u} (${r?r.filter(t=>t==Number.MIN_SAFE_INTEGER?!1:L&&L.length>0?L.indexOf(t)==-1:!0).length:0}/${o.filter(t=>L&&L.length>0?L.indexOf(t.id)==-1:!0).length}) `},S=N.useRef(null),[j,U]=N.useState("");return e.jsx(l.Dropdown,{ref:S,fluid:!0,text:b(),scrolling:!1,button:!0,icon:"angle down",multiple:!0,search:!0,floating:!1,className:`${r&&r.length>0?"applied ":""}`,children:e.jsxs(l.Dropdown.Menu,{children:[w!=_&&e.jsxs(e.Fragment,{children:[e.jsx(l.Segment,{children:e.jsxs(l.Dropdown.Item,{children:[e.jsx(l.Label,{basic:!0,onClick:R,children:i})," ","|"," ",e.jsx(l.Label,{basic:!0,onClick:k,children:s})]})}),C&&e.jsxs(e.Fragment,{children:[e.jsx(l.Container,{children:e.jsx(l.Dropdown.Item,{children:e.jsx("div",{className:"ui action input",children:e.jsxs(l.Input,{placeholder:"Search...",children:[e.jsx("input",{className:"filter-search",value:j,onChange:t=>{q(t.target.value)}}),e.jsx(l.Icon,{name:"remove",link:!0,className:"clear-icon ignore",onClick:t=>{q("")}})]})})})}),e.jsx(l.Divider,{})]})]}),e.jsx("br",{}),e.jsx(l.Container,{className:F?"dropdown-single-column":"",children:o.filter(t=>C&&j&&j.trim().length>0&&t.text?t.text.toLowerCase().includes(j.toLowerCase()):!0).map(({value:t,text:a},p)=>e.jsxs(l.Dropdown.Item,{className:F?"dropdown-item-single-column":"",children:[w==_&&e.jsx(l.Radio,{checked:!!(r&&r.indexOf(t)>-1),onChange:z=>A(t),label:a}),w==Y&&e.jsx(l.Checkbox,{checked:!!(r&&r.indexOf(t)>-1&&!(o.length==r.length&&g)),onChange:z=>A(t),label:a})]},p))})]})})}),le=P.connect(V,$)(({placeholder:n,startLabel:i,endLabel:s,options:u,onChange:o,app:f,group:h,param:d,current:r,autoApply:m})=>{const[c,F]=N.useState(u[0].position),[C,w]=N.useState(u[u.length-1].position);N.useEffect(()=>{const I=u.filter(x=>(x.position>c||x.position===c)&&(x.position<C||x.position===C)).map(x=>x.value);o({app:f,group:h,param:d,value:I,autoApply:m})},[c,C]);const T=N.useRef(null);return e.jsx(l.Dropdown,{ref:T,fluid:!0,text:`${n} (${r?r.filter(I=>I!=Number.MIN_SAFE_INTEGER).length:0}/${u.length})`,scrolling:!1,button:!0,multiple:!0,search:!0,floating:!1,icon:"angle down",className:`${r&&r.length>0?"applied ":""} range`,children:e.jsxs(l.Dropdown.Menu,{children:[e.jsx(l.Segment,{children:e.jsxs(l.Dropdown.Item,{children:[" ",e.jsx(l.Label,{basic:!0,children:i})]})}),e.jsx(l.Container,{children:u.map(({value:I,text:x,position:g})=>e.jsx(l.Dropdown.Item,{children:e.jsx(l.Radio,{disabled:g>C,checked:c===g,onChange:v=>F(g),label:x})}))}),e.jsx(l.Segment,{children:e.jsxs(l.Dropdown.Item,{children:[" ",e.jsx(l.Label,{basic:!0,children:s})]})}),e.jsx(l.Container,{children:u.map(({value:I,text:x,position:g})=>e.jsx(l.Dropdown.Item,{children:e.jsx(l.Radio,{disabled:g<c,checked:C===g,onChange:v=>w(g),label:x})}))})]})})}),se=n=>{const{data:i,type:s,showNoDataOption:u}=n,o=i.filter(c=>c.type===s)[0],f=o?o.items.filter(c=>!u&&c.code==Q?!1:n.hiddenFilters&&n.hiddenFilters.length>0?n.hiddenFilters.indexOf(c.id)==-1:!0):[],h=f?te(f,n.locale):[],d=i.find(c=>c.type="FilterDefinition"),r=d?d.items.find(c=>c.fieldType==s):null,m=r?r.value:"Filter";return e.jsx(l.Container,{fluid:!0,className:"filter",children:e.jsx(B,{...n,options:h,placeholder:n.placeholder?n.placeholder:m})})},ae=P.connect(V,$)(n=>{let i=0;const s=[{key:"Yes",value:!0,text:"Yes",position:i++},{key:"No",value:!1,text:"No",position:i++}];return e.jsx(l.Container,{fluid:!0,className:"filter",children:e.jsx(B,{options:s,...n})})}),ie=n=>{const{csvValue:i}=n;let s=0;const u=i.split(",").map(o=>({key:o,value:o,text:o,icon:o.toLocaleLowerCase(),position:s++}));return e.jsx(l.Container,{fluid:!0,className:"filter",children:e.jsx(B,{options:u,...n,children:" "})})},oe=n=>e.jsx(H.SettingProvider,{locale:n.intl.locale,changeUUID:n.unique,children:e.jsx(H.SettingsConsumer,{children:e.jsx(ce,{...n})})}),ce=({"data-group":n,"data-app":i,"data-dvz-proxy-dataset-id":s,"data-param":u,"data-icon":o,"data-type":f,"data-place-holder":h,"data-is-range":d="false","data-all-label":r,"data-none-label":m,"data-start-label":c,"data-end-label":F,"data-csv-value":C,"data-filters":w="[]","data-use-single-column":T="false","data-enable-text-search":I="false","data-filter-type":x,"data-default-values":g,"data-show-no-data-option":v="true","data-default-value-criteria":L="DEFAULT_VALUE_INPUT","data-hidden-filters":D="[]","data-all-none-same-behaviour":O="false","data-close-on-select":y="false","data-alphabetical-sort":A="true","data-asc-order":R="true","data-auto-apply":k="true",settings:q,intl:b})=>{const S={},j=w?W(w):{};j&&j.forEach&&j.forEach(a=>{a.value!=null&&a.value.filter(p=>p!=null&&p.toString().trim()!="").length>0&&(S[a.param]=a.value)}),s&&(S.dvzProxyDatasetId=s);const U=D?W(D):[];let t;return x==null||x==""?t=d==="true"?"range":"multi-select":t=x,i==="csv"?e.jsx(ie,{allLabel:r,noneLabel:m,isRange:d==="true",csvValue:C,app:i,group:n,icon:o,placeholder:h,startLabel:c,endLabel:F,param:u,useSingleColumn:T==="true",enableTextSearch:I==="true",filterType:t,defaultValues:g,defaultValueCriteria:L,allNoneSameBehaviour:O==="true",closeOnSelect:y==="true",locale:b.locale}):i?e.jsx(J,{params:S,app:i,hiddenFilters:U||[],children:e.jsx(G,{children:e.jsxs(l.Container,{fluid:!0,children:[f==="Boolean"&&e.jsx(ae,{startLabel:c,endLabel:F,allLabel:r,noneLabel:m,isRange:E(d),app:i,group:n,icon:o,placeholder:h,param:u,filterType:t,defaultValues:g,locale:b.locale}),f!=="Boolean"&&e.jsx(G,{type:f,children:e.jsx(se,{startLabel:c,endLabel:F,allLabel:r,noneLabel:m,isRange:E(d),app:i,group:n,icon:o,placeholder:h,param:u,alphabeticalSort:A,ascOrder:R,useSingleColumn:E(T),enableTextSearch:E(I),showNoDataOption:E(v),filterType:t,defaultValues:g,defaultValueCriteria:L,hiddenFilters:U||[],allNoneSameBehaviour:O=="true",autoApply:E(k),closeOnSelect:E(y),locale:b.locale})})]})})}):null},ue=K.injectIntl(oe);module.exports=ue;