"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/FirewallIcmpPage"],{1407:(e,t,a)=>{a.r(t),a.d(t,{SORT_ASC:()=>i,SORT_DESC:()=>c,default:()=>h});var r=a(285),s=a(591),o=a.n(s),l=a(286);const n=a(89).Locale.getSection("components.list"),i="ASC",c="DESC",g="all",m={set(e,t){localStorage.setItem(e,JSON.stringify(t))},get(e){const t=localStorage.getItem(e);return JSON.parse(t)}},p=e=>`list-sort_${e}`,u=e=>`list-page_${e}`,d=({id:e,data:t,columns:a,itemsPerPage:s=25,itemsPerPageOptions:o=[10,25,100,g],sortColumn:c,sortDirection:d=i,searchField:h,locale:f={},emptyView:P,emptyFilteredView:y,toolbar:w,selection:b=[],onSelectionChange:S,searchBarInputProps:C,rowKey:k="key",useStorage:x=!0,...T})=>{const{sortColumn:j,sortDirection:F,setSortState:L}=((e,{sortColumn:t,sortDirection:a})=>{const[{sortColumn:s,sortDirection:o},l]=(0,r.useState)({sortColumn:m.get(p(e))?.sortColumn??t,sortDirection:m.get(p(e))?.sortDirection??a});return{sortColumn:s,sortDirection:o,setSortState:t=>{l((e=>({...e,...t}))),m.set(p(e),{...m.get(p(e)),...t})}}})(e,{sortColumn:c??a.find((({sortable:e})=>e))?.key,sortDirection:d}),{page:R,itemsPerPage:D,searchPattern:M,setPageState:v}=((e,{itemsPerPage:t},a=!0)=>{const s=a?{page:m.get(u(e))?.page,itemsPerPage:m.get(u(e))?.itemsPerPage,searchPattern:m.get(u(e))?.searchPattern}:{},[{page:o,itemsPerPage:l,searchPattern:n},i]=(0,r.useState)({page:s.page??1,itemsPerPage:s.itemsPerPage??t,searchPattern:s.searchPattern??""});return{page:o,itemsPerPage:l,searchPattern:n,setPageState:t=>{i((e=>({...e,...t}))),a&&m.set(u(e),{...m.get(u(e)),...t})}}})(e,{itemsPerPage:o.includes(s)?s:o[0]},x),O=(0,r.useMemo)((()=>M?y??(0,r.jsx)(l.ListEmptyView,{reason:"filtered","data-testid":"list-empty-view-filtered"}):P??(0,r.jsx)(l.ListEmptyView,{})),[M,P,y]),E=(0,r.useMemo)((()=>a.map((({sortDataField:e,...t})=>t))),[a]),I=(0,r.useMemo)((()=>h&&M?t.filter((e=>(Array.isArray(h)?h:[h]).some((t=>e[t]&&String(e[t]).toLowerCase().includes(M.toLowerCase()))))):t),[t,M,h]),q=(0,r.useMemo)((()=>{if(!j)return I;const e=a.find((({key:e})=>e===j))?.sortDataField??j,t=a.find((({key:e})=>e===j))?.sort??((t,a)=>t[e]<a[e]?-1:t[e]>a[e]?1:0);return[...I].sort(((e,a)=>i===F?t(e,a):t(a,e)))}),[I,j,F,a]),$=(0,r.useMemo)((()=>{if(D===g)return q;const e=D*(R-1),t=e+D;return q.slice(e,t)}),[R,q,D]),V=(0,r.useCallback)((e=>{v({searchPattern:e}),e!==M&&v({page:1})}),[M]),B=(0,r.useCallback)((e=>{v({itemsPerPage:e});(e===g?1:Math.ceil(I.length/e))<R&&v({page:1})}),[I.length,R]);return(0,r.useEffect)((()=>{if("function"==typeof S&&b.length){const e=I.map((e=>{return t=e,"function"==typeof(a=k)?a(t):t[a];var t,a})).filter((e=>b.includes(e)));S(e)}}),[I]),(0,r.jsx)(l.List,{pagination:(0,r.jsx)(l.Pagination,{current:R,total:D===g?1:Math.ceil(I.length/D),onSelect:e=>v({page:e}),itemsPerPage:D,itemsPerPageOptions:o,onItemsPerPageChange:B}),toolbar:(w||h)&&(0,r.jsxs)(l.Toolbar,{children:[w,h&&(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:n.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",value:M,...C??{}},onTyping:V})})]})]}),totalRows:I.length,sortColumn:j,sortDirection:F,onSortChange:L,columns:E,data:$,filtered:!!M,locale:{totalRows:({totalRows:e})=>n.formatMessage("recordsTotal",{total:e}),...f},emptyView:O,onSelectionChange:S,selection:b,rowKey:k,...T})};d.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,useStorage:o().bool};const h=d},2486:(e,t,a)=>{a.r(t),a.d(t,{default:()=>h});var r=a(591),s=a(286),o=a(89),l=a(1407),n=a(1115),i=a(623),c=a(285),g=a(536);const m=o.Locale.getTranslate("admin.components.lists.firewallicmprules"),p=o.Locale.getSection("admin.components.lists.firewallicmprules"),u=n.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,i.useMutation)(u),n=(0,c.useMemo)((()=>e.map((({key:e,...t})=>({key:e,name:p.lmsg(e.toLowerCase()),...t})))),[e]);return(0,c.jsx)(l.default,{id:"firewall-icmp-rules-list",columns:[{key:"status",title:(0,c.jsx)(m,{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)(m,{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,g.addToast)({intent:"danger",message:e.message})}finally{a((t=>t.filter((t=>t!==e))))}})(e,!l)})},{key:"name",title:(0,c.jsx)(m,{content:"name"}),type:"title",sortable:!0}],data:n,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},2485:(e,t,a)=>{a.r(t),a.d(t,{default:()=>p});var r=a(89),s=a(335),o=a(598),l=a(2486),n=a(2482),i=a(581),c=a(1260),g=a.n(c),m=a(285);const p=(0,o.withPageLayout)((0,n.withFirewallTabs)((()=>{const{data:{server:{firewall:{icmpRules:e}}}}=(0,i.useQuery)(g());return(0,m.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}}}))},2482:(e,t,a)=>{a.r(t),a.d(t,{default:()=>m,withFirewallTabs:()=>g});var r=a(285),s=a(575),o=a(576),l=a(286),n=a(89),i=a(641);const c=()=>{const{pathname:e}=(0,s.useLocation)(),t=(0,r.useMemo)((()=>[{title:n.Locale.getSection("components.pages.firewall-general").lmsg("title"),url:"/cp/firewall/general",id:"tabGeneral"},{title:n.Locale.getSection("components.pages.firewall-icmp").lmsg("title"),url:"/cp/firewall/icmp",id:"tabIcmp"},{title:n.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:i.default,to:e,...t},e)))})},g=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},m=c}}]);
//# sourceMappingURL=FirewallIcmpPage.js.map?d24db3b351947c4d2327