"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7129],{40473:(z,E,t)=>{t.r(E),t.d(E,{default:()=>P});var f=t(41407),e=t(39953),C=t(82803),x=t(12190),y=t(13253),p=t(79779),F=t(26286),A=t(4919),I=t(94696);const M=(n,s)=>n.original.name.localeCompare(s.original.name),N=(n,s)=>{if(!n.original.description&&!s.original.description)return 0;if(n.original.description){if(!s.original.description)return-1}else return 1;return n.original.description.localeCompare(s.original.description)},b=(n,s)=>n.original.enabled===s.original.enabled?0:n.original.enabled?1:-1;function B({featureToggles:n,onUpdateSuccess:s}){const[o,v]=(0,e.useState)(n),[T]=(0,p.f$)(),[c,r]=(0,e.useState)([]),[g,d]=(0,e.useState)(!1),h=(a,i)=>{const m={...a,enabled:i},W=o.map(l=>l.name===a.name?m:l);v(W);const S=c.find(l=>l.name===a.name);S&&S.enabled===i?r(l=>l.filter(u=>u.name!==a.name)):r(l=>{const u=l.filter(j=>j.name!==a.name);return u.push(m),u})},U=async()=>{d(!0);try{"error"in await T(c)||(s(),r([]))}finally{d(!1)}},D=()=>n.some(a=>{const i=o.find(m=>m.name===a.name);return i&&i.enabled!==a.enabled}),L=[{id:"name",header:"Name",cell:({cell:{value:a}})=>e.createElement("div",null,a),sortType:M},{id:"description",header:"Description",cell:({cell:{value:a}})=>e.createElement("div",null,a),sortType:N},{id:"enabled",header:"State",cell:({row:a})=>e.createElement("div",null,e.createElement(F.r,{value:a.original.enabled,disabled:a.original.readOnly,onChange:i=>h(a.original,i.currentTarget.checked)})),sortType:b}];return e.createElement(e.Fragment,null,e.createElement("div",{style:{display:"flex",justifyContent:"flex-end",padding:"0 0 5px 0"}},e.createElement(A.zx,{disabled:!D()||g,onClick:U},g?"Saving...":"Save Changes")),e.createElement(I.e,{columns:L,data:o,getRowId:a=>a.name}))}function P(){const{data:n,isLoading:s,isError:o}=(0,p.xW)(),{data:v}=(0,p.sF)(),[T,c]=(0,e.useState)(!1),r=(0,C.wW)(R),g=()=>"Error fetching feature toggles",d=()=>{c(!0)},h=()=>e.createElement("div",{className:r.warning},e.createElement("div",{className:r.icon},e.createElement(x.J,{name:"exclamation-triangle"})),e.createElement("span",{className:r.message},v?.restartRequired||T?"A restart is pending for your Grafana instance to apply the latest feature toggle changes":"Saving feature toggle changes will prompt a restart of the instance, which may take a few minutes"));return e.createElement(y.T,{navId:"feature-toggles"},e.createElement(y.T.Contents,null,e.createElement(e.Fragment,null,o&&g(),s&&"Fetching feature toggles",e.createElement(h,null),n&&e.createElement(B,{featureToggles:n,onUpdateSuccess:d}))))}function R(n){return{warning:(0,f.css)({display:"flex",marginTop:n.spacing(3)}),icon:(0,f.css)({color:n.colors.warning.main,paddingRight:n.spacing()}),message:(0,f.css)({color:n.colors.text.secondary,marginTop:n.spacing(.25)})}}}}]);

//# sourceMappingURL=AdminFeatureTogglesPage.4dcf409f913814f74a17.js.map