"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[7024],{65995:(X,v,s)=>{s.r(v),s.d(v,{default:()=>O});var a=s(74848),u=s(22803),d=s(96540),b=s(16817),C=s(29675),A=s(79784),x=s(54122),R=s(11817),y=s(28082);class B{constructor(){this.baseURL="/apis/featuretoggle.grafana.app/v0alpha1"}async getFeatureToggles(){const t=await(0,y.AI)().get(this.baseURL+"/current");return{restartRequired:!!t.restartRequired,allowEditing:!!t.allowEditing,toggles:t.toggles.map(i=>({name:i.name,description:i.description,enabled:i.enabled,readOnly:!i.writeable,stage:i.stage,hidden:!1}))}}updateFeatureToggles(t){const i={kind:"ResolvedToggleState",enabled:{}};return t.forEach(r=>{i.enabled[r.name]=r.enabled}),(0,y.AI)().patch(this.baseURL+"/current",i)}}const j=()=>new B;var T=s(6736),F=s(29010),I=s(54594),w=s(65164),E=s(14123);const M=(n,t)=>n.original.name.localeCompare(t.original.name),N=(n,t)=>{if(!n.original.description&&!t.original.description)return 0;if(n.original.description){if(!t.original.description)return-1}else return 1;return n.original.description.localeCompare(t.original.description)},G=(n,t)=>n.original.enabled===t.original.enabled?0:n.original.enabled?1:-1;function L({featureToggles:n,allowEditing:t,onUpdateSuccess:i}){n.sort((e,l)=>e.name.localeCompare(l.name));const r=(0,d.useRef)(n),[o,f]=(0,d.useState)(n),[c,g]=(0,d.useState)(!1),[U,D]=(0,d.useState)(!1),K=j(),Y=(e,l)=>{const p={...e,enabled:l},Q=o.map(S=>S.name===e.name?p:S);f(Q)},z=async()=>{g(!0);try{const e=V();await K.updateFeatureToggles(e),r.current=[...o],i()}finally{g(!1)}},h=(0,d.useRef)(null),m=e=>()=>{D(e),!e&&h.current&&h.current.focus()},V=()=>o.filter((e,l)=>e.enabled!==r.current[l].enabled),W=()=>o.some((e,l)=>e.enabled!==r.current[l].enabled),$=e=>t?e?"This is a non-editable feature":"":"Feature management is not configured for editing",H=e=>{switch(e){case"GA":return(0,a.jsx)(T.m,{content:"General availability",children:(0,a.jsx)("div",{children:"GA"})});case"privatePreview":case"preview":case"experimental":return"Beta";case"deprecated":return"Deprecated";default:return e}},J=[{id:"name",header:"Name",cell:({cell:{value:e}})=>(0,a.jsx)("div",{children:e}),sortType:M},{id:"description",header:"Description",cell:({cell:{value:e}})=>(0,a.jsx)("div",{children:e}),sortType:N},{id:"stage",header:"Stage",cell:({cell:{value:e}})=>(0,a.jsx)("div",{children:H(e)})},{id:"enabled",header:"State",cell:({row:e})=>{const l=(0,a.jsx)("div",{children:(0,a.jsx)(F.d,{value:e.original.enabled,disabled:e.original.readOnly,onChange:p=>Y(e.original,p.currentTarget.checked)})});return e.original.readOnly?(0,a.jsx)(T.m,{content:$(e.original.readOnly),children:l}):l},sortType:G}];return(0,a.jsxs)(a.Fragment,{children:[t&&(0,a.jsxs)("div",{style:{display:"flex",justifyContent:"flex-end",padding:"0 0 5px 0"},children:[(0,a.jsx)(I.$n,{disabled:!W()||c,onClick:m(!0),ref:h,children:c?"Saving...":"Save Changes"}),(0,a.jsx)(w.u,{isOpen:U,title:"Apply feature toggle changes",body:(0,a.jsxs)("div",{children:[(0,a.jsx)("p",{children:"Some features are stable (GA) and enabled by default, whereas some are currently in their preliminary Beta phase, available for early adoption."}),(0,a.jsx)("p",{children:"We advise understanding the implications of each feature change before making modifications."})]}),confirmText:"Save changes",onConfirm:async()=>{m(!1)(),z()},onDismiss:m(!1)})]}),(0,a.jsx)(E.j,{columns:J,data:o,getRowId:e=>e.name})]})}function O(){const[n,t]=(0,d.useState)(1),i=j(),r=(0,b.A)(()=>i.getFeatureToggles(),[n]),o=(0,C.of)(P),f=()=>{t(n+1)},c=()=>(0,a.jsxs)("div",{className:o.warning,children:[(0,a.jsx)("div",{className:o.icon,children:(0,a.jsx)(A.I,{name:"exclamation-triangle"})}),(0,a.jsx)("span",{className:o.message,children:r.value?.restartRequired?"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"})]}),g=(0,a.jsx)("div",{children:(0,a.jsxs)(R.x6,{i18nKey:"admin.feature-toggles.sub-title",children:["View and edit feature toggles. Read more about feature toggles at"," ",(0,a.jsx)("a",{className:"external-link",target:"_new",href:"https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/feature-toggles/",children:"grafana.com"}),"."]})});return(0,a.jsx)(x.Y,{navId:"feature-toggles",subTitle:g,children:(0,a.jsx)(x.Y.Contents,{isLoading:r.loading,children:(0,a.jsxs)(a.Fragment,{children:[r.error?.message,r.loading&&"Fetching feature toggles",(0,a.jsx)(c,{}),r.value&&(0,a.jsx)(L,{featureToggles:r.value.toggles,allowEditing:r.value.allowEditing||!1,onUpdateSuccess:f})]})})})}function P(n){return{warning:(0,u.css)({display:"flex",marginTop:n.spacing(.25),marginBottom:n.spacing(.25)}),icon:(0,u.css)({color:n.colors.warning.main,paddingRight:n.spacing()}),message:(0,u.css)({color:n.colors.text.secondary,marginTop:n.spacing(.25)})}}}}]);

//# sourceMappingURL=AdminFeatureTogglesPage.af37199a268e83e6d9e5.js.map