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

//# sourceMappingURL=AdminFeatureTogglesPage.143d84dda936c0377365.js.map