"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/FirewallIcmpPage"],{1096:(e,t,a)=>{a.r(t),a.d(t,{SORT_ASC:()=>m,SORT_DESC:()=>p,default:()=>P});var r=a(245),s=a(247),o=a.n(s),l=a(246),i=a(90);const n=i.Locale.getTranslate("components.list"),c=i.Locale.getSection("components.list"),m="ASC",p="DESC",g="all",u={set(e,t){localStorage.setItem(e,JSON.stringify(t))},get(e){const t=localStorage.getItem(e);return JSON.parse(t)}},d=e=>`list-sort_${e}`,h=e=>`list-page_${e}`,f=({id:e,data:t,columns:a,itemsPerPage:s,itemsPerPageOptions:o,sortColumn:i,sortDirection:p,searchField:f,locale:P,emptyView:y,emptyFilteredView:w,toolbar:b,selection:S,onSelectionChange:C,searchBarInputProps:x,rowKey:T,...j})=>{const{sortColumn:k,sortDirection:F,setSortState:v}=((e,{sortColumn:t,sortDirection:a})=>{const[{sortColumn:s,sortDirection:o},l]=(0,r.useState)({sortColumn:u.get(d(e))?.sortColumn??t,sortDirection:u.get(d(e))?.sortDirection??a});return{sortColumn:s,sortDirection:o,setSortState:t=>{l((e=>({...e,...t}))),u.set(d(e),{...u.get(d(e)),...t})}}})(e,{sortColumn:i??a.find((({sortable:e})=>e))?.key,sortDirection:p}),{page:L,itemsPerPage:R,searchPattern:D,setPageState:M}=((e,{itemsPerPage:t})=>{const[{page:a,itemsPerPage:s,searchPattern:o},l]=(0,r.useState)({page:u.get(h(e))?.page??1,itemsPerPage:u.get(h(e))?.itemsPerPage??t,searchPattern:u.get(h(e))?.searchPattern??""});return{page:a,itemsPerPage:s,searchPattern:o,setPageState:t=>{l((e=>({...e,...t}))),u.set(h(e),{...u.get(h(e)),...t})}}})(e,{itemsPerPage:o.includes(s)?s:o[0]}),O=(0,r.useMemo)((()=>D?w??(0,r.jsx)(l.ListEmptyView,{reason:"filtered",title:(0,r.jsx)(n,{content:"emptyViewFilteredTitle"}),description:(0,r.jsx)(n,{content:"emptyViewFilteredDescription"})}):y??(0,r.jsx)(l.ListEmptyView,{title:(0,r.jsx)(n,{content:"emptyViewTitle"})})),[D,y,w]),V=(0,r.useMemo)((()=>a.map((({sortDataField:e,...t})=>t))),[a]),I=(0,r.useMemo)((()=>f&&D?t.filter((e=>(Array.isArray(f)?f:[f]).some((t=>e[t]&&String(e[t]).toLowerCase().includes(D.toLowerCase()))))):t),[t,D,f]),E=(0,r.useMemo)((()=>{if(!k)return I;const e=a.find((({key:e})=>e===k))?.sortDataField??k,t=a.find((({key:e})=>e===k))?.sort??((t,a)=>t[e]<a[e]?-1:t[e]>a[e]?1:0);return[...I].sort(((e,a)=>m===F?t(e,a):t(a,e)))}),[I,k,F,a]),q=(0,r.useMemo)((()=>{if(R===g)return E;const e=R*(L-1),t=e+R;return E.slice(e,t)}),[L,E,R]),$=(0,r.useCallback)((e=>{M({searchPattern:e}),e!==D&&M({page:1})}),[D]),B=(0,r.useCallback)((e=>{M({itemsPerPage:e});(e===g?1:Math.ceil(I.length/e))<L&&M({page:1})}),[I.length,L]);return(0,r.useEffect)((()=>{if("function"==typeof C&&S.length){const e=I.map((e=>{return t=e,"function"==typeof(a=T)?a(t):t[a];var t,a})).filter((e=>S.includes(e)));C(e)}}),[I]),(0,r.jsx)(l.List,{pagination:(0,r.jsx)(l.Pagination,{current:L,total:R===g?1:Math.ceil(I.length/R),onSelect:e=>M({page:e}),itemsPerPage:R,itemsPerPageOptions:o,onItemsPerPageChange:B}),toolbar:(b||f)&&(0,r.jsxs)(l.Toolbar,{children:[b,f&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(l.ToolbarExpander,{}),(0,r.jsx)(l.ToolbarGroup,{title:"",children:(0,r.jsx)(l.SearchBar,{inputProps:{placeholder:c.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",value:D,...x??{}},onTyping:$})})]})]}),totalRows:I.length,sortColumn:k,sortDirection:F,onSortChange:v,columns:V,data:q,filtered:!!D,locale:{totalRows:({totalRows:e})=>c.formatMessage("recordsTotal",{total:e}),...P},emptyView:O,onSelectionChange:C,selection:S,rowKey:T,...j})};f.propTypes={id:o().string.isRequired,data:o().array.isRequired,columns:o().array.isRequired,itemsPerPage:o().number,itemsPerPageOptions:o().array,sortColumn:o().string,sortDirection:o().string,searchField:o().oneOfType([o().string,o().arrayOf(o().string.isRequired)]),locale:o().object,emptyView:o().node,emptyFilteredView:o().node,toolbar:o().node,onSelectionChange:o().func,selection:o().array,rowKey:o().oneOfType([o().string,o().func]),searchBarInputProps:o().object},f.defaultProps={itemsPerPage:25,itemsPerPageOptions:[10,25,100,g],sortColumn:void 0,sortDirection:m,searchField:void 0,locale:{},emptyView:void 0,emptyFilteredView:void 0,toolbar:void 0,onSelectionChange:void 0,selection:[],searchBarInputProps:void 0,rowKey:"key"};const P=f},1957:(e,t,a)=>{a.r(t),a.d(t,{default:()=>h});var r=a(247),s=a(246),o=a(90),l=a(1096),i=a(458),n=a(774),c=a(245),m=a(688);const p=o.Locale.getTranslate("admin.components.lists.firewallicmprules"),g=o.Locale.getSection("admin.components.lists.firewallicmprules"),u=i.gql`
    mutation ToggleFirewallIcmpRuleStatus($key: String!, $enable: Boolean!) {
        toggleFirewallIcmpRule(input: { key: $key, enable: $enable }) {
            query {
                server {
                    firewall {
                        icmpRules {
                            key
                            isEnabled
                        }
                    }
                }
            }
        }
    }
`,d=({rules:e})=>{const[t,a]=(0,c.useState)([]),[r,{loading:o}]=(0,n.useMutation)(u),i=(0,c.useMemo)((()=>e.map((({key:e,...t})=>({key:e,name:g.lmsg(e.toLowerCase()),...t})))),[e]);return(0,c.jsx)(l.default,{id:"firewall-icmp-rules-list",columns:[{key:"status",title:(0,c.jsx)(p,{content:"status"}),sortable:!0,sortDataField:"isEnabled",width:"1%",render:({key:e,isEnabled:l})=>(0,c.jsx)(s.Switch,{id:`toggle-${e}`,tooltip:(0,c.jsx)(p,{content:l?"on":"off"}),checked:l,loading:o&&t.includes(e),onChange:()=>(async(e,t)=>{try{a((t=>[...t,e])),await r({variables:{key:e,enable:t}})}catch(e){(0,m.addToast)({intent:"danger",message:e.message})}finally{a((t=>t.filter((t=>t!==e))))}})(e,!l)})},{key:"name",title:(0,c.jsx)(p,{content:"name"}),type:"title",sortable:!0}],data:i,searchField:"name",sortColumn:"name"})};d.propTypes={rules:r.PropTypes.arrayOf(r.PropTypes.shape({key:r.PropTypes.string.isRequired,isEnabled:r.PropTypes.bool.isRequired})).isRequired};const h=d},1956:(e,t,a)=>{a.r(t),a.d(t,{default:()=>g});var r=a(90),s=a(293),o=a(751),l=a(1957),i=a(1953),n=a(745),c=a(937),m=a.n(c),p=a(245);const g=(0,o.withPageLayout)((0,i.withFirewallTabs)((()=>{const{data:{server:{firewall:{icmpRules:e}}}}=(0,n.useQuery)(m());return(0,p.jsx)(l.default,{rules:e})})),(()=>{const{showFrames:e,pageHeader:t,pageSidebar:a}=(0,s.default)();return{showFrames:e,pageHeader:{...t,helpMenu:{...t.helpMenu,helpContext:"firewall_icmp"}},pageSidebar:a,pageContentHeader:{breadcrumbs:[a.isPowerUserPanel?null:{title:r.Locale.getSection("components.pages.home").lmsg("title"),href:"/admin/home"},{title:r.Locale.getSection("admin.controllers.server.tools").lmsg("title"),href:"/admin/server/tools"},{title:r.Locale.getSection("components.pages.firewall").lmsg("title"),href:"/cp/firewall"},{title:r.Locale.getSection("components.pages.firewall-icmp").lmsg("title"),href:"/cp/firewall/icmp"}].filter(Boolean),tabs:[],tabsHasRootPage:!0}}}))},1953:(e,t,a)=>{a.r(t),a.d(t,{default:()=>p,withFirewallTabs:()=>m});var r=a(245),s=a(739),o=a(740),l=a(246),i=a(90),n=a(787);const c=()=>{const{pathname:e}=(0,s.useLocation)(),t=(0,r.useMemo)((()=>[{title:i.Locale.getSection("components.pages.firewall-general").lmsg("title"),url:"/cp/firewall/general",id:"tabGeneral"},{title:i.Locale.getSection("components.pages.firewall-icmp").lmsg("title"),url:"/cp/firewall/icmp",id:"tabIcmp"},{title:i.Locale.getSection("components.pages.firewall-rules").lmsg("title"),url:"/cp/firewall/rules",id:"tabRules"}]),[]),a=(0,r.useMemo)((()=>t.findIndex((({url:t})=>(0,o.matchPath)(t,e)))+1),[t,e]);return(0,r.jsx)(l.Tabs,{active:a,children:t.map((({url:e,...t})=>(0,r.jsx)(l.Tab,{component:n.default,to:e,...t},e)))})},m=e=>{const t=t=>(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(c,{...t}),(0,r.jsx)(e,{...t})]});return t.displayName=`withFirewallTabs(${e.displayName||e.name||"Component"})`,t.WrappedComponent=e,t},p=c}}]);
//# sourceMappingURL=FirewallIcmpPage.js.map?41a61755bd25953fd864