"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/FirewallIcmpPage"],{1683:(e,t,a)=>{a.r(t),a.d(t,{SORT_ASC:()=>p,SORT_DESC:()=>m,default:()=>P});var r=a(241),s=a(243),o=a.n(s),l=a(242),i=a(90);const n=i.Locale.getTranslate("components.list"),c=i.Locale.getSection("components.list"),p="ASC",m="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:m,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:m}),{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)((()=>f?t.filter((e=>(Array.isArray(f)?f:[f]).some((t=>e[t]&&String(e[t]).toLowerCase().includes(D.toLowerCase()))))):t),[t,D,f]),I=(0,r.useMemo)((()=>{if(!k)return V;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[...V].sort(((e,a)=>p===F?t(e,a):t(a,e)))}),[V,k,F,a]),E=(0,r.useMemo)((()=>{if(R===g)return I;const e=R*(L-1),t=e+R;return I.slice(e,t)}),[L,I,R]),q=(0,r.useCallback)((e=>{M({searchPattern:e}),e!==D&&M({page:1})}),[D]),$=(0,r.useCallback)((e=>{M({itemsPerPage:e});(e===g?1:Math.ceil(V.length/e))<L&&M({page:1})}),[V.length,L]);return(0,r.useEffect)((()=>{if("function"==typeof C&&S.length){const e=V.map((e=>{return t=e,"function"==typeof(a=T)?a(t):t[a];var t,a})).filter((e=>S.includes(e)));C(e)}}),[V]),(0,r.jsx)(l.List,{pagination:(0,r.jsx)(l.Pagination,{current:L,total:R===g?1:Math.ceil(V.length/R),onSelect:e=>M({page:e}),itemsPerPage:R,itemsPerPageOptions:o,onItemsPerPageChange:$}),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:q})})]})]}),totalRows:V.length,sortColumn:k,sortDirection:F,onSortChange:v,columns:a,data:E,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:p,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},1873:(e,t,a)=>{a.r(t),a.d(t,{default:()=>h});var r=a(243),s=a(242),o=a(90),l=a(1683),i=a(447),n=a(748),c=a(241),p=a(717);const m=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)(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,p.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: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},1872:(e,t,a)=>{a.r(t),a.d(t,{default:()=>g});var r=a(90),s=a(288),o=a(731),l=a(1873),i=a(1869),n=a(725),c=a(858),p=a.n(c),m=a(241);const g=(0,o.withPageLayout)((0,i.withFirewallTabs)((()=>{const{data:{server:{firewall:{icmpRules:e}}}}=(0,n.useQuery)(p());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}}}))},1869:(e,t,a)=>{a.r(t),a.d(t,{default:()=>m,withFirewallTabs:()=>p});var r=a(241),s=a(719),o=a(720),l=a(242),i=a(90),n=a(761);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)))})},p=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?bd09107ea01e9f0b6f2c