unleash-server 4.20.4 → 4.20.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/lib/services/feature-toggle-service.d.ts +2 -2
  2. package/dist/lib/services/feature-toggle-service.js +6 -6
  3. package/dist/lib/services/feature-toggle-service.js.map +1 -1
  4. package/dist/test/e2e/services/feature-toggle-service-v2.e2e.test.js +3 -2
  5. package/dist/test/e2e/services/feature-toggle-service-v2.e2e.test.js.map +1 -1
  6. package/frontend/build/index.html +1 -1
  7. package/frontend/build/static/{CreateProject-29a2b285.js → CreateProject-f3e27e64.js} +1 -1
  8. package/frontend/build/static/{Error-934cc570.js → Error-3a9a6e2a.js} +1 -1
  9. package/frontend/build/static/{ExpandMore-c3e13d73.js → ExpandMore-46f830cb.js} +1 -1
  10. package/frontend/build/static/{FeatureArchiveDialog-b5fc8177.js → FeatureArchiveDialog-57c6d9ed.js} +2 -2
  11. package/frontend/build/static/{FeatureMetricsChart-13ce1b57.js → FeatureMetricsChart-d491608e.js} +1 -1
  12. package/frontend/build/static/FeatureViewLazyExport-b0689708.js +9 -0
  13. package/frontend/build/static/{LazyAdminExport-2f5a25ac.js → LazyAdminExport-62d63b43.js} +2 -2
  14. package/frontend/build/static/{LazyProjectExport-dc65603b.js → LazyProjectExport-7200e7dc.js} +1 -1
  15. package/frontend/build/static/{NetworkOverview-8018cd89.js → NetworkOverview-42db0a7a.js} +75 -75
  16. package/frontend/build/static/{NetworkTraffic-84935c51.js → NetworkTraffic-7c9567ee.js} +1 -1
  17. package/frontend/build/static/{Playground-6d2eacce.js → Playground-13a05a33.js} +1 -1
  18. package/frontend/build/static/{StrategyItemContainer-93cba46f.js → StrategyItemContainer-66556bf6.js} +1 -1
  19. package/frontend/build/static/{chartjs-adapter-date-fns.esm-38d041f7.js → chartjs-adapter-date-fns.esm-4b4ea41a.js} +1 -1
  20. package/frontend/build/static/{index-c290f941.js → index-54a8dd7a.js} +73 -73
  21. package/frontend/build/static/{index-3132dba8.js → index-a4c3dd25.js} +1 -1
  22. package/frontend/build/static/{index-66dec49c.js → index-b275e721.js} +1 -1
  23. package/frontend/build/static/{unknownify-86fd295b.js → unknownify-8b8ea1ba.js} +1 -1
  24. package/frontend/build/static/{useProjectRole-b5b140d2.js → useProjectRole-f229b4e4.js} +1 -1
  25. package/frontend/build/static/v4-a960c1f4.js +1 -0
  26. package/frontend/package.json +1 -0
  27. package/package.json +1 -1
  28. package/frontend/build/static/FeatureViewLazyExport-1bee3351.js +0 -9
@@ -0,0 +1,9 @@
1
+ import{az as aa,aA as ra,s as p,r as m,aB as oa,_ as sa,$ as Vt,j as t,aC as ia,aD as la,c as qe,aE as k,aF as _,aG as ca,aH as da,aI as bt,aJ as Pe,aK as Ge,w as Be,ai as ua,aL as cn,aM as ce,a2 as K,aN as $e,aO as fe,f as c,aP as ie,C as E,a4 as j,aQ as dn,aR as at,aS as pa,aT as ga,aU as ha,H as Te,aV as ma,aW as ne,aX as se,aY as Se,aZ as ya,a_ as vt,u as Ye,a$ as pe,F as O,b0 as Dt,b1 as Ot,b2 as Ve,b3 as ge,T as H,b4 as De,ar as xe,b5 as Ct,b6 as Oe,A as he,b7 as un,b8 as fa,b9 as Sa,ba,bb as va,ap as Le,bc as Ca,bd as be,be as le,m as Ne,bf as wa,bg as Ta,bh as Ke,a8 as Je,bi as pn,bj as gn,bk as wt,bl as xa,bm as Aa,bn as Ea,a as Q,p as Ia,N as ue,B as gt,a9 as me,bo as Ra,x as Xe,an as _e,E as ka,bp as Tt,bq as ze,P as Fa,br as Pa,bs as U,bt as Ba,bu as $a,D as Va,bv as Da,bw as Oa,bx as La,by as hn,bz as Na,bA as Ma,bB as ja,bC as xt,bD as mn,bE as ve,bF as _a,bG as za,bH as Wa,bI as Ha,bJ as Ae,bK as Ce,bL as yn,af as We,bM as Ua,bN as qa,bO as Ga,bP as At,bQ as fn,bR as ye,bS as ht,bT as Ya,ac as Et,bU as Sn,a3 as Ee,bV as Ka,ad as bn,bW as Ie,bX as Ja,a5 as Xa,bY as vn,bZ as ke,b_ as Cn,b$ as mt,l as Z,c0 as He,b as wn,d as de,e as Tn,U as It,ak as Qe,al as xn,c1 as Qa,S as Rt,h as kt,i as Ft,c2 as Za,W as An,c3 as En,c4 as In,c5 as Rn,c6 as er,c7 as kn,au as tr,c8 as Re,c9 as Lt,ca as nr,cb as Fn,cc as yt,cd as Pn,R as ar,Q as rr,X as or,g as Bn,k as $n,ce as sr,cf as ir,V as Nt,I as lr,cg as cr,ch as dr,ci as Mt,cj as ur,ck as Vn,cl as pr,ae as gr,cm as jt,cn as hr,co as mr,cp as yr,cq as fr,cr as Sr,cs as br,M as vr,ct as Cr,cu as wr,cv as Tr,cw as xr,cx as Ar}from"./index-54a8dd7a.js";import{C as Me,f as Er,u as Dn,U as On,E as Ln,a as Nn,V as Ir,F as Rr,b as kr,c as Fr}from"./FeatureArchiveDialog-57c6d9ed.js";import{S as Pr}from"./StrategyItemContainer-66556bf6.js";import{E as Br}from"./ExpandMore-46f830cb.js";import{v as rt}from"./v4-a960c1f4.js";function $r(e){return aa("MuiCardContent",e)}ra("MuiCardContent",["root"]);const Vr=["className","component"],Dr=e=>{const{classes:n}=e;return la({root:["root"]},$r,n)},Or=p("div",{name:"MuiCardContent",slot:"Root",overridesResolver:(e,n)=>n.root})(()=>({padding:16,"&:last-child":{paddingBottom:24}})),Lr=m.forwardRef(function(n,a){const r=oa({props:n,name:"MuiCardContent"}),{className:o,component:l="div"}=r,s=sa(r,Vr),i=Vt({},r,{component:l}),d=Dr(i);return t(Or,Vt({as:l,className:ia(d.root,o),ownerState:i,ref:a},s))}),Nr=Lr,Mr=qe(t("path",{d:"m20.54 5.23-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5 6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z"}),"Archive"),jr=qe(t("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"}),"Assessment"),_r=qe(t("path",{d:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z"}),"Cloud"),zr=qe(t("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10 10-4.5 10-10S17.5 2 12 2zm4.2 14.2L11 13V7h1.5v5.2l4.5 2.7-.8 1.3z"}),"WatchLater"),Wr=p("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),Hr=()=>{const e=k("projectId"),n=k("featureId"),{feature:a}=_(e,n);return a.name?t(Wr,{children:t(ca,{title:"Event log",project:e,feature:n,displayInline:!0})}):null},Ze=(e,n={})=>{const a=async()=>{const u=Pe(`api/admin/features/${e}/tags`);return(await fetch(u,{method:"GET"}).then(Ge("Tags"))).json()},r=`api/admin/features/${e}/tags`,{data:o,error:l}=da(Boolean(e),{tags:[]},r,a,n),[s,i]=m.useState(!l&&!o),d=()=>{bt(r)};return m.useEffect(()=>{i(!l&&!o)},[o,l]),{tags:(o==null?void 0:o.tags)||[],error:l,loading:s,refetch:d}},Ur=p("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.primary.main,display:"flex",flexDirection:"column",marginRight:e.spacing(2),marginTop:e.spacing(2),[e.breakpoints.down(800)]:{width:"100%",maxWidth:"none"}})),qr=p(Be)(({theme:e})=>({marginRight:e.spacing(.5),marginTop:e.spacing(1),backgroundColor:e.palette.text.tertiaryContrast,fontSize:e.fontSizes.smallBody})),Gr=p(ua)(({theme:e})=>({color:e.palette.primary.light,"&:hover":{color:e.palette.primary.light}})),Yr=({projectId:e,...n})=>{const[a,r]=m.useState(!1),[o,l]=m.useState({value:"",type:""}),s=k("featureId"),{tags:i,refetch:d}=Ze(s),{tagTypes:u}=cn(),{deleteTagFromFeature:g}=ce(),{setToastData:h,setToastApiError:b}=K(),{hasAccess:y}=m.useContext($e),T=y(fe,e),w=async()=>{try{await g(s,o.type,o.value),d(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(v){b(j(v))}},S=v=>{let x=u.find($=>$.name===v);const A={width:"20px",height:"20px",marginRight:"5px"};if(x&&x.icon)switch(x.name){case"slack":return t("img",{style:A,alt:"Slack",src:at(ha)});case"jira":return t("img",{style:A,alt:"JIRA",src:at(ga)});case"webhook":return t("img",{style:A,alt:"Webhook",src:at(pa)});default:return t(dn,{})}else return t("span",{children:v[0].toUpperCase()})},f=v=>t(qr,{icon:S(v.type),"data-loading":!0,label:v.value,deleteIcon:t(Gr,{titleAccess:"Remove"}),onDelete:T?()=>{r(!0),l({type:v.type,value:v.value})}:void 0},`${v.type}:${v.value}`);return c(Ur,{...n,children:[t(ie,{open:a,onClose:()=>{r(!1),l({type:"",value:""})},onClick:()=>{r(!1),w(),l({type:"",value:""})},title:"Are you sure you want to delete this tag?"}),t("div",{children:t(E,{condition:i.length>0,show:i.map(f),elseShow:t("p",{"data-loading":!0,children:"No tags to display"})})})]})},Kr=p("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,color:e.palette.text.tertiaryContrast,backgroundColor:e.palette.featureMetaData,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:e.spacing(2),[e.breakpoints.down(1e3)]:{width:"100%",maxWidth:"none",minWidth:"auto"}})),Jr=p("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Xr=p("div")(({theme:e})=>({padding:"0 1.5rem 1.5rem 1.5rem",borderTop:`1px solid ${e.palette.divider}`})),Qr=p("div")({display:"flex",alignItems:"center"}),Zr=p("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),eo=p("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),_t=p("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize,wordBreak:"break-all"})),zt=p("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.text.tertiaryContrast})),to=()=>{const{uiConfig:e}=Te(),n=k("projectId"),a=k("featureId"),{tags:r}=Ze(a),{feature:o}=_(n,a),{project:l,description:s,type:i}=o,d=ya(i);return c(Kr,{children:[c(Jr,{children:[c(Qr,{"data-loading":!0,children:[t(d,{sx:u=>({marginRight:u.spacing(2),height:"40px",width:"40px",fill:u.palette.text.tertiaryContrast})})," ",c(Zr,{children:[ma(i||"")," toggle"]})]}),c(eo,{children:[c(_t,{"data-loading":!0,children:["Project: ",l]}),t(E,{condition:Boolean(s),show:c(_t,{"data-loading":!0,children:[t("div",{children:"Description:"}),c(zt,{children:[t("p",{children:s}),t(ne,{projectId:n,permission:fe,component:se,to:`/projects/${n}/features/${a}/settings`,tooltipProps:{title:"Edit description"},children:t(Se,{sx:u=>({color:u.palette.text.tertiaryContrast})})})]})]}),elseShow:t("span",{"data-loading":!0,children:c(zt,{children:["No description."," ",t(ne,{projectId:n,permission:fe,component:se,to:`/projects/${n}/features/${a}/settings`,tooltipProps:{title:"Edit description"},children:t(Se,{sx:u=>({color:u.palette.text.tertiaryContrast})})})]})})})]})]}),t(E,{condition:r.length>0&&!Boolean(e.flags.variantsPerEnvironment),show:t(Xr,{children:t(Yr,{projectId:n})})})]})},Wt={lastHourUsage:[],seenApplications:[]},no=(e,n,a={})=>{const r=async()=>{const g=Pe(`api/admin/client-metrics/features/${n}`),h=await fetch(g,{method:"GET"}).then(Ge("feature metrics"));return h.ok?h.json():Wt},o=`${e}_${n}_metrics`,{data:l,error:s}=vt(o,r,{...a}),[i,d]=m.useState(!s&&!l),u=()=>{bt(o)};return m.useEffect(()=>{d(!s&&!l)},[l,s]),{metrics:l||Wt,error:s,loading:i,refetch:u,FEATURE_METRICS_CACHE_KEY:o}},ao=e=>({yes:0,no:0,environment:e,timestamp:""}),ro=(e,n)=>e.map(a=>n.lastHourUsage.find(o=>o.environment===a.name)||ao(a.name)),oo=({enabled:e,className:n})=>{const a=Ye(),r=e?"Environment enabled":"Environment disabled",o={backgroundColor:e?a.palette.primary.light:a.palette.neutral.border,borderRadius:"50%",width:"28px",height:"28px",minWidth:"28px",display:"flex",alignItems:"center",justifyContent:"center",marginRight:a.spacing(1)};return t("div",{style:o,className:n,children:t(_r,{style:{fill:"#fff",width:"16px",height:"16px"},titleAccess:r})})},Mn=()=>t(he,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),so=({onRemove:e,onClose:n,isOpen:a})=>t(ie,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(Mn,{})}),io=p("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),lo=({onRemove:e,onClose:n,isOpen:a})=>c(ie,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(Mn,{}),t(io,{children:t(H,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(H,{fontWeight:"bold",children:"Remove strategy"})]}),co=({projectId:e,featureId:n,environmentId:a,strategyId:r})=>{const{deleteStrategyFromFeature:o}=De(),{setToastData:l,setToastApiError:s}=K(),i=xe(),{refetchFeature:d}=_(e,n);return async g=>{try{g.preventDefault(),await o(e,n,a,r),l({title:"Strategy deleted",type:"success"}),d(),i(un(e,n))}catch(h){s(j(h))}}},uo=({projectId:e,featureId:n,environmentId:a,strategyId:r})=>{const{addChange:o}=Ct(),{refetch:l}=Oe(e),{setToastData:s,setToastApiError:i}=K();return async u=>{try{u.preventDefault(),await o(e,a,{action:"deleteStrategy",feature:n,payload:{id:r}}),s({title:"Changes added to the draft!",type:"success"}),await l()}catch(g){i(j(g))}}},po=({projectId:e,featureId:n,environmentId:a,strategyId:r,disabled:o,icon:l})=>{const[s,i]=m.useState(!1),{isChangeRequestConfigured:d}=pe(e),u=co({featureId:n,projectId:e,strategyId:r,environmentId:a}),g=uo({featureId:n,projectId:e,strategyId:r,environmentId:a});return c(O,{children:[t(E,{condition:Boolean(l),show:t(ne,{onClick:()=>i(!0),projectId:e,environmentId:a,disabled:o,permission:Dt,"data-testid":Ot,tooltipProps:{title:"Remove strategy"},type:"button",children:t(Ve,{})}),elseShow:t(ge,{onClick:()=>i(!0),projectId:e,environmentId:a,disabled:o,permission:Dt,"data-testid":Ot,color:"secondary",variant:"text",type:"button",children:"Remove strategy"})}),t(E,{condition:d(a),show:t(lo,{isOpen:s,onClose:()=>i(!1),onRemove:async h=>{await g(h),i(!1)}}),elseShow:t(so,{isOpen:s,onClose:()=>i(!1),onRemove:u})})]})},go=e=>(n,a,r)=>(r.revalidateOnFocus=!1,r.revalidateIfStale=!1,r.revalidateOnReconnect=!1,e(n,a,r));var ho=fa(vt,go);const jn=(e,n)=>{const{refetchFeature:a}=_(e,n),r=Sa(e,n),{data:o,error:l,mutate:s}=ho(["useFeatureImmutable",r],()=>ba(r)),i=m.useCallback(async()=>{await s(),await a()},[s,a]);return{feature:(o==null?void 0:o.body)||va,refetchFeature:i,loading:!l&&!o,status:o==null?void 0:o.status,error:l}},Pt=(e,n,a)=>{const{setToastData:r,setToastApiError:o}=K(),{addChange:l}=Ct(),{refetch:s}=Oe(e),[i,d]=m.useState({isOpen:!1}),u=m.useCallback((T,w,S)=>{d({featureName:n,environment:T,fromEnvironment:S,strategy:w,isOpen:!0})},[]),g=m.useCallback((T,w,S)=>{d({featureName:n,environment:T,fromEnvironment:S,strategies:w,isOpen:!0})},[]),h=m.useCallback(()=>{d({isOpen:!1})},[]),b=m.useCallback(async()=>{try{await l(e,i.environment,{feature:i.featureName,action:a,payload:i.strategy}),s(),d({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(T){o(j(T)),d({isOpen:!1})}},[l]),y=m.useCallback(async()=>{try{await Promise.all(i.strategies.map(T=>l(e,i.environment,{feature:i.featureName,action:a,payload:T}))),s(),d({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(T){o(j(T)),d({isOpen:!1})}},[l]);return{onChangeRequestAddStrategy:u,onChangeRequestAddStrategies:g,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:b,onChangeRequestAddStrategiesConfirm:y,changeRequestDialogDetails:i}},mo=({payload:e,fromEnvironment:n,environment:a})=>c(H,{children:[c("strong",{children:["Copy ",Le((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),yo=({environmentId:e,environments:n,strategy:a})=>{const r=k("projectId"),o=k("featureId"),[l,s]=m.useState(null),i=Boolean(l),{addStrategyToFeature:d}=De(),{setToastData:u,setToastApiError:g}=K(),{refetchFeature:h}=_(r,o),{refetchFeature:b}=jn(r,o),y=()=>{s(null)},T=Ca(r),{isChangeRequestConfigured:w}=pe(r),{changeRequestDialogDetails:S,onChangeRequestAddStrategyClose:f,onChangeRequestAddStrategy:v,onChangeRequestAddStrategyConfirm:x}=Pt(r,o,"addStrategy"),A=async F=>{const{id:M,...D}={...a,targetEnvironment:F};if(w(F)){await v(F,{id:M,...D},e);return}try{await d(r,o,F,a),h(),b(),u({title:"Strategy created",text:`Successfully copied a strategy to ${F}`,type:"success"})}catch(Y){g(j(Y))}y()},$=n.some(F=>T(be,F));return c("div",{children:[t(Me,{isOpen:S.isOpen,onClose:f,environment:S==null?void 0:S.environment,onConfirm:x,messageComponent:t(mo,{fromEnvironment:S.fromEnvironment,payload:S.strategy})}),t(le,{title:`Copy to another environment${$?"":" (Access denied)"}`,children:t("div",{children:t(Ne,{size:"large",id:`copy-strategy-icon-menu-${a.id}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:F=>{s(F.currentTarget)},"data-testid":wa,disabled:!$,children:t(Ta,{})})})}),t(Ke,{id:"basic-menu",anchorEl:l,open:i,onClose:y,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(F=>{const M=T(be,F);return t(le,{title:M?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Je,{onClick:()=>A(F),disabled:!M,children:[t(E,{condition:!M,show:t(pn,{children:t(gn,{fontSize:"small"})})}),c(wt,{children:["Copy to ",F]})]})})},F)})})]})},fo=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:r,otherEnvironments:o,orderNumber:l,headerChildren:s})=>{const i=k("projectId"),d=k("featureId"),u=xa(i,d,e,n.id);return t(Pr,{strategy:n,onDragStart:a,onDragEnd:r,orderNumber:l,actions:c(O,{children:[s,t(E,{condition:Boolean(o&&(o==null?void 0:o.length)>0),show:()=>t(yo,{environmentId:e,environments:o,strategy:n})}),t(ne,{permission:Aa,environmentId:e,projectId:i,component:se,to:u,tooltipProps:{title:"Edit strategy"},children:t(Se,{})}),t(po,{projectId:i,featureId:d,environmentId:e,strategyId:n.id,icon:!0})]}),children:t(Ea,{strategy:n})})},So=(e,n,a,r)=>{const{data:o}=Oe(e),l=o==null?void 0:o.find(d=>d.environment===a),s=l==null?void 0:l.features.find(d=>d.name===n);return s==null?void 0:s.changes.find(d=>d.action==="updateStrategy"||d.action==="deleteStrategy"?d.payload.id===r:!1)},bo=({strategy:e,index:n,environmentName:a,otherEnvironments:r,isDragging:o,onDragStartRef:l,onDragOver:s,onDragEnd:i})=>{const d=k("projectId"),u=k("featureId"),g=m.useRef(null),h=So(d,u,a,e.id);return c(Q,{ref:g,onDragOver:s(g,n),sx:{opacity:o?"0.5":"1"},children:[t(E,{condition:n>0,show:t(Ia,{text:"OR"})}),t(fo,{strategy:e,environmentId:a,otherEnvironments:r,onDragStart:l(g,n),onDragEnd:i,orderNumber:n+1,headerChildren:t(vo,{change:h})})]},e.id)},vo=({change:e})=>{const n=Ye();return ue(n.breakpoints.down("sm"))?null:c(Q,{sx:{mr:1.5},children:[t(E,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(gt,{color:"warning",children:"Modified in draft"})}),t(E,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(gt,{color:"error",children:"Deleted in draft"})})]})},Co=p("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",margin:"1rem 0",position:"relative","&:before":{content:'""',position:"absolute",top:"50%",transform:"translateY(-50%)",height:2,width:"100%",backgroundColor:e.palette.dividerAlternative}})),wo=p("span")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",padding:"0 1rem",background:e.palette.secondaryContainer,position:"relative",maxWidth:"80%",color:e.palette.text.primary})),_n=({children:e})=>t(Co,{children:t(wo,{children:e})}),To=({environmentId:e,environments:n,onClick:a})=>{const r=k("projectId"),[o,l]=m.useState(null),s=Boolean(o),{hasAccess:i}=m.useContext($e),d=n.some(u=>i(be,r,u));return c("div",{children:[t(le,{title:d?"":"(Access denied)",children:t("div",{children:t(me,{id:`copy-all-strategies-${e}`,"aria-controls":s?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":s?"true":void 0,onClick:u=>{l(u.currentTarget)},disabled:!d,variant:"outlined",children:"Copy from another environment"})})}),t(Ke,{id:"basic-menu",anchorEl:o,open:s,onClose:()=>{l(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(u=>{const g=i(be,r,u);return t(le,{title:g?"":"You don't have access to add a strategy to this environment",children:t("div",{children:c(Je,{onClick:()=>a(u),disabled:!g,children:[t(E,{condition:!g,show:t(pn,{children:t(gn,{fontSize:"small"})})}),c(wt,{children:["Copy from ",u]})]})})},u)})})]})},xo=p("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),Ao=({payload:e,fromEnvironment:n,environment:a})=>c(xo,{children:[t(H,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(r=>c(H,{children:[c("strong",{children:[Le((r==null?void 0:r.name)||"")," strategy"," "]})," "]})),c(H,{children:["from ",n," to ",a]})]}),Eo=({payload:e,environment:n})=>c(O,{children:[t(H,{component:"span",children:"Add "}),c("strong",{children:[Le((e==null?void 0:e.name)||"")," strategy"]})," to ",t("strong",{children:n})]}),Io=p(Ra)(({theme:e})=>({display:"flex",flexDirection:"column",borderRadius:e.shape.borderRadiusMedium})),Ht=({title:e,children:n,featureId:a,projectId:r,environmentId:o,strategy:l,Icon:s,onAfterAddStrategy:i})=>{const{addStrategyToFeature:d}=De(),{setToastApiError:u}=K(),{isChangeRequestConfigured:g}=pe(r),{changeRequestDialogDetails:h,onChangeRequestAddStrategy:b,onChangeRequestAddStrategyConfirm:y,onChangeRequestAddStrategyClose:T}=Pt(r,a,"addStrategy");return c(O,{children:[t(Io,{variant:"outlined",children:c(Nr,{sx:{display:"flex",flexDirection:"column",flexGrow:1},children:[c(H,{variant:"body1",fontWeight:"medium",sx:{mb:.5,display:"flex",alignItems:"center"},children:[t(s,{color:"disabled",sx:{mr:1}})," ",e]}),t(H,{variant:"body2",color:"text.secondary",component:"p",children:n}),t(Q,{sx:{ml:"auto",mt:"auto",pt:1,mr:{xs:"auto",sm:0}},children:t(ge,{permission:be,projectId:r,environmentId:o,variant:"outlined",size:"small",onClick:async()=>{try{g(o)?b(o,l):(await d(r,a,o,l),i())}catch(S){u(j(S))}},children:"Use template"})})]})}),t(Me,{isOpen:h.isOpen,onClose:T,environment:h==null?void 0:h.environment,onConfirm:y,messageComponent:t(Eo,{environment:o,payload:h.strategy})})]})},Ro=p("div")(({theme:e})=>({width:e.spacing(4),height:"auto","& > svg":{fill:e.palette.primary.main},"& > div":{height:e.spacing(2),marginLeft:"-.75rem",color:e.palette.primary.main}})),ko=p("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Fo=p(Xe)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Po=p(se)(({theme:e})=>({display:"grid",gridTemplateColumns:"3rem 1fr",width:"20rem",padding:e.spacing(2),color:"inherit",textDecoration:"inherit",lineHeight:1.25,borderWidth:"1px",borderStyle:"solid",borderColor:e.palette.dividerAlternative,borderRadius:e.spacing(1),"&:hover, &:focus":{borderColor:e.palette.primary.main}})),Bo=({projectId:e,featureId:n,environmentId:a,strategy:r})=>{const o=_e(r.name),l=Le(r.name),s=Er(e,n,a,r.name);return c(Po,{to:s,children:[t(Ro,{children:t(o,{})}),c("div",{children:[t(Fo,{text:r.displayName||l,maxWidth:"200",maxLength:25}),t(ko,{children:r.description})]})]})},$o=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:r}=ka(),o=m.useMemo(()=>r.filter(l=>!l.deprecated),[r]);return t(Tt,{dense:!0,children:o.map(l=>t(ze,{children:t(Bo,{projectId:e,featureId:n,environmentId:a,strategy:l})},l.name))})},ft=({label:e,projectId:n,featureId:a,environmentId:r,variant:o,matchWidth:l})=>{const[s,i]=m.useState(),d=Boolean(s),u=d?"FeatureStrategyMenuPopover":void 0,g=()=>{i(void 0)};return c("div",{onClick:b=>b.stopPropagation(),children:[t(ge,{permission:be,projectId:n,environmentId:r,onClick:b=>{i(b.currentTarget)},"aria-labelledby":u,variant:o,sx:{minWidth:l?"282px":"auto"},children:e}),t(Fa,{id:u,open:d,anchorEl:s,onClose:g,onClick:g,children:t($o,{projectId:n,featureId:a,environmentId:r})})]})},Vo=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Do=p("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),Oo=p("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3)})),Lo=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:r}=De(),{setToastData:o,setToastApiError:l}=K(),{refetchFeature:s}=_(e,n),{refetchFeature:i}=jn(e,n),{feature:d}=_(e,n),u=d==null?void 0:d.environments.filter(v=>v.name!==a&&v.strategies&&v.strategies.length>0),{isChangeRequestConfigured:g}=pe(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:b,onChangeRequestAddStrategiesConfirm:y,onChangeRequestAddStrategyClose:T}=Pt(e,n,"addStrategy"),w=(v=!1)=>{s(),i(),o({title:v?"Strategies created":"Strategy created",text:v?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},S=async v=>{var A;const x=((A=u==null?void 0:u.find($=>$.name===v))==null?void 0:A.strategies)||[];if(g(a)){await b(a,x,v);return}try{await Promise.all(x.map($=>{const{id:F,...M}={...$,environment:a};return r(e,n,a,M)})),w(!0)}catch($){l(j($))}},f=u&&u.length>0;return c(O,{children:[t(Me,{isOpen:h.isOpen,onClose:T,environment:h==null?void 0:h.environment,onConfirm:y,messageComponent:t(Ao,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),c(Vo,{children:[t(Do,{children:"You have not defined any strategies yet."}),c(Oo,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(se,{to:"/admin/api",children:"API key configured"})," for this environment."]}),c(Q,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t(ft,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:f}),t(E,{condition:f,show:t(To,{environmentId:a,environments:u.map(v=>v.name),onClick:S})})]}),t(Q,{sx:{width:"100%",mt:3},children:t(_n,{children:"Or use a strategy template"})}),c(Q,{sx:{display:"grid",width:"100%",gap:2,gridTemplateColumns:{xs:"1fr",sm:"1fr 1fr"}},children:[t(Ht,{title:"Standard strategy",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:w,Icon:_e("default"),strategy:{name:"default",parameters:{},constraints:[]},children:"The standard strategy is strictly on/off for your entire userbase."}),t(Ht,{title:"Gradual rollout",projectId:e,featureId:n,environmentId:a,onAfterAddStrategy:w,Icon:_e("flexibleRollout"),strategy:{name:"flexibleRollout",parameters:{rollout:"50",stickiness:"default",groupId:d.name},constraints:[]},children:"Roll out to a percentage of your userbase."})]})]})]})},No=p("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Mo=p("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),jo=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const r=k("projectId"),o=k("featureId"),{setStrategiesSortOrder:l}=De(),{setToastData:s,setToastApiError:i}=K(),{refetchFeature:d}=_(r,o),[u,g]=m.useState((e==null?void 0:e.strategies)||[]),[h,b]=m.useState(null);if(m.useEffect(()=>{g((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const y=async f=>{try{await l(r,o,e.name,f),d(),s({title:"Order of strategies updated",type:"success"})}catch(v){i(j(v))}},T=(f,v)=>x=>{var A;b({id:u[v].id,index:v,height:((A=f.current)==null?void 0:A.offsetHeight)||0}),f!=null&&f.current&&(x.dataTransfer.effectAllowed="move",x.dataTransfer.setData("text/html",f.current.outerHTML),x.dataTransfer.setDragImage(f.current,20,20))},w=f=>(v,x)=>A=>{if(h===null||v.current===null||h.index===x||f===h.id)return;const{top:$,bottom:F}=v.current.getBoundingClientRect(),M=A.clientY-$<h.height,D=F-A.clientY<h.height,Y=h.index>x;if(M&&Y||D&&!Y){const q=[...u],G=q.splice(h.index,1)[0];q.splice(x,0,G),g(q),b({...h,index:x})}},S=()=>{b(null),y(u.map((f,v)=>({id:f.id,sortOrder:v})))};return t(No,{children:c(Mo,{children:[t(E,{condition:u.length>0&&n,show:()=>t(he,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(E,{condition:u.length>0,show:t(O,{children:u.map((f,v)=>t(bo,{strategy:f,index:v,environmentName:e.name,otherEnvironments:a,isDragging:(h==null?void 0:h.id)===f.id,onDragStartRef:T,onDragOver:w(f.id),onDragEnd:S},f.id))}),elseShow:t(Lo,{projectId:r,featureId:o,environmentId:e.name})})]})})},zn=(e,n)=>e===0?0:Math.round(n/e*100);var et={},tt={};Object.defineProperty(tt,"__esModule",{value:!0});tt.defaultOptions=void 0;tt.defaultOptions={decimalSeparator:".",lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var we={};Object.defineProperty(we,"__esModule",{value:!0});we.roundTo=we.parseValue=void 0;function _o(e){const n=parseFloat(e==null?void 0:e.toString());if(isNaN(n))throw new Error("Input value is not a number");if(n>Number.MAX_SAFE_INTEGER||n<Number.MIN_SAFE_INTEGER)throw new RangeError("Input value is outside of safe integer range");return n}we.parseValue=_o;function zo(e,n){if(!Number.isFinite(e))throw new Error("Input value is not a finite number");if(!Number.isInteger(n)||n<0)throw new Error("Precision is not a positive integer");return Number.isInteger(e)?e:parseFloat(e.toFixed(n))}we.roundTo=zo;Object.defineProperty(et,"__esModule",{value:!0});et.millify=void 0;const ot=tt,Ut=we,qt=1e3;function*Gt(e){let n=qt;for(;;){const a=e/n;if(a<1)return;yield a,n*=qt}}function Wn(e,n){var a;const r=n?Object.assign(Object.assign({},ot.defaultOptions),n):ot.defaultOptions;if(!Array.isArray(r.units)||!r.units.length)throw new Error("Option `units` must be a non-empty array");let o;try{o=Ut.parseValue(e)}catch(y){return y instanceof Error&&console.warn(`WARN: ${y.message} (millify)`),String(e)}const l=o<0?"-":"";o=Math.abs(o);let s=0;for(const y of Gt(o))o=y,s+=1;if(s>=r.units.length)return e.toString();let d=Ut.roundTo(o,r.precision);for(const y of Gt(d))d=y,s+=1;const u=(a=r.units[s])!==null&&a!==void 0?a:"",g=r.lowercase?u.toLowerCase():u,h=r.space?" ":"",b=d.toString().replace(ot.defaultOptions.decimalSeparator,r.decimalSeparator);return`${l}${b}${h}${g}`}et.millify=Wn;var Wo=et.default=Wn;const Ue=({value:e,threshold:n=1e6,precision:a=2})=>{let r,o=!1;e<n?r=e.toLocaleString():(r=Wo(e,{precision:a}),o=!0);const l=t("span",{"data-testid":Pa,children:r});return t(E,{condition:o,show:t(le,{title:e.toLocaleString(),arrow:!0,children:l}),elseShow:l})},st=p("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),it=p("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),lt=p("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),ct=p("p")(({theme:e})=>({margin:e.spacing(1,0,0,0),padding:e.spacing(2,0,0,0),borderTopWidth:"1px",borderTopStyle:"solid",borderTopColor:e.palette.dividerAlternative,fontSize:e.fontSizes.smallerBody,color:e.palette.text.secondary})),Hn=({totalYes:e,totalNo:n,hoursBack:a,statsSectionId:r,tableSectionId:o})=>{const l=a===1?"in the last hour":`in the last ${a} hours`;return c(U,{container:!0,spacing:2,id:r,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t(U,{item:!0,xs:12,sm:4,children:c(st,{children:[t(it,{children:"Exposure"}),t(lt,{children:t(Ue,{value:e})}),c(ct,{children:["Total exposure of the feature in the environment"," ",l,"."]})]})}),t(U,{item:!0,xs:12,sm:4,children:c(st,{children:[t(it,{children:"Exposure %"}),c(lt,{children:[zn(e+n,e),"%"]}),c(ct,{children:["% total exposure of the feature in the environment"," ",l,"."]})]})}),t(U,{item:!0,xs:12,sm:4,children:c(st,{children:[t(it,{children:"Requests"}),t(lt,{children:t(Ue,{value:e+n})}),c(ct,{children:["Total requests for the feature in the environment"," ",l,"."]})]})})]})},Ho=({environmentMetric:e})=>e?c(O,{children:[t(_n,{children:"Feature toggle exposure"}),t("div",{children:t(Hn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Yt=p("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),Kt=p("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Jt=p("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Xt=p("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),Uo=p(Ba)(({theme:e})=>({fill:e.palette.standaloneBackground,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),qo=p("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),Go=({environmentMetric:e,disabled:n=!1})=>{const a=$a();if(!e)return null;const r=e.yes+e.no,o=zn(r,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?c(Yt,{children:[c(Kt,{children:[c(Jt,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),c(Xt,{style:{color:n?a.palette.text.secondary:a.palette.text.primary},"data-loading":!0,children:["The feature has been requested ",t("b",{children:"0 times"})," and exposed",t("b",{children:" 0 times"})," in the last hour"]})]}),t(Uo,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):c(Yt,{children:[c(Kt,{children:[c(Jt,{children:[o,"%"]}),c(Xt,{children:["The feature has been requested"," ",c("b",{children:[t(Ue,{value:r})," times"]})," ","and exposed"," ",c("b",{children:[t(Ue,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(qo,{"data-loading":!0,children:t(Va,{percentage:o,size:"3rem"})})]})},Yo=({strategyName:e})=>{const n=_e(e);return t(le,{title:Le(e),arrow:!0,children:t(Ko,{children:t(n,{})})})},Ko=p("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.palette.inactiveIcon,"& svg":{width:e.spacing(2.5),height:e.spacing(2.5)}})),Jo=({strategies:e})=>e!=null&&e.length?t(Xo,{"aria-label":"Feature strategies",children:e.map(n=>t(Qo,{children:t(Yo,{strategyName:n.name})},n.id))}):null,Xo=p("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),Qo=p("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),Zo=p("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2),backgroundColor:e.palette.background.paper,background:n?e.palette.background.paper:e.palette.neutral.light})),es=p(Da)({boxShadow:"none",background:"none"}),ts=p(Oa)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),ns=p(La,{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({padding:e.spacing(3),background:e.palette.secondaryContainer,borderBottomLeftRadius:e.shape.borderRadiusLarge,borderBottomRightRadius:e.shape.borderRadiusLarge,borderBottom:`4px solid ${n?e.palette.primary.light:e.palette.neutral.border}`,[e.breakpoints.down("md")]:{padding:e.spacing(2,1)}})),as=p(jo)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),rs=p("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({display:"flex",justifyContent:"center",flexDirection:"column",color:n?e.palette.text.primary:e.palette.text.secondary})),os=p("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),ss=p(oo)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),is=p(Xe)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),ls=p("div")(({theme:e})=>({display:"flex",alignItems:"center",marginLeft:"1.8rem",[e.breakpoints.down(560)]:{flexDirection:"column",marginLeft:"0"}})),cs=({env:e})=>{var u;const n=k("projectId"),a=k("featureId"),{metrics:r}=no(n,a),{feature:o}=_(n,a),{value:l}=hn(),i=ro(o==null?void 0:o.environments,r).find(g=>g.environment===e.name),d=o==null?void 0:o.environments.find(g=>g.name===e.name);return t(E,{condition:!Boolean(new Set(l.hiddenEnvironments).has(e.name)),show:t(Zo,{enabled:e.enabled,children:c(es,{"data-testid":`${Na}_${e.name}`,children:[c(ts,{expandIcon:t(Br,{titleAccess:"Toggle"}),children:[c(rs,{"data-loading":!0,enabled:e.enabled,children:[c(os,{children:[t(ss,{enabled:e.enabled}),t("div",{children:t(is,{text:e.name,maxWidth:"100",maxLength:15})}),t(E,{condition:!e.enabled,show:t(Be,{size:"small",variant:"outlined",label:"Disabled",sx:{ml:1}})})]}),c(ls,{children:[t(ft,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"text"}),t(Jo,{strategies:d==null?void 0:d.strategies})]})]}),t(Go,{environmentMetric:i,disabled:!e.enabled})]}),c(ns,{enabled:e.enabled,children:[t(as,{featureEnvironment:d,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:g})=>g).filter(g=>g!==e.name)}),t(E,{condition:(((u=d==null?void 0:d.strategies)==null?void 0:u.length)||0)>0,show:c(O,{children:[t(Q,{sx:{display:"flex",justifyContent:"center",py:1},children:t(ft,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(Ho,{environmentMetric:i})]})})]})]})})})},ds=()=>{const e=k("projectId"),n=k("featureId"),{feature:a}=_(e,n);if(!a)return null;const{environments:r}=a;return t(O,{children:r==null?void 0:r.map(o=>t(cs,{env:o},o.name))})},us=p(Ne,{shouldForwardProp:e=>e!=="visibilityOff"})(({theme:e,visibilityOff:n})=>({marginLeft:"auto",marginRight:e.spacing(-1),color:n?e.palette.neutral.main:e.palette.tertiary.main,"&:hover":{color:e.palette.neutral.main}})),Un=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(us,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(E,{condition:n.has(e.name),show:t(Ma,{}),elseShow:t(ja,{})})}),ps=p("div")({display:"flex",alignItems:"center"}),gs=p("label")({display:"inline-flex",alignItems:"center",cursor:"pointer"}),hs=({env:e,callback:n,text:a,showInfoBox:r,hiddenEnvironments:o,setHiddenEnvironments:l})=>{const s=k("projectId"),i=k("featureId"),{toggleFeatureEnvironmentOn:d,toggleFeatureEnvironmentOff:u}=ce(),{refetchFeature:g}=_(s,i),{setToastData:h,setToastApiError:b}=K(),{isChangeRequestConfigured:y}=pe(s),{onChangeRequestToggle:T,onChangeRequestToggleClose:w,onChangeRequestToggleConfirm:S,changeRequestDialogDetails:f}=Dn(s),v=async()=>{try{await d(s,i,e.name),h({type:"success",title:`Available in ${e.name}`,text:`${i} is now available in ${e.name} based on its defined strategies.`}),g(),n&&n()}catch(F){F instanceof Error&&F.message===Ln?r():b(j(F))}},x=async()=>{try{await u(s,i,e.name),h({type:"success",title:`Unavailable in ${e.name}`,text:`${i} is unavailable in ${e.name} and its strategies will no longer have any effect.`}),g(),n&&n()}catch(F){b(j(F))}},A=async F=>{if(y(e.name)){F.preventDefault(),T(i,e.name,!e.enabled);return}if(e.enabled){await x();return}await v()};let $=a||c(O,{children:[" ",c("span",{"data-loading":!0,children:[e.enabled?"enabled":"disabled"," in"]})," ",t(Xe,{text:e.name,maxWidth:"120",maxLength:15})]});return c(ps,{children:[c(gs,{children:[t(xt,{permission:mn,projectId:s,checked:e.enabled,onChange:A,environmentId:e.name}),$]}),t(Un,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:l}),t(Me,{isOpen:f.isOpen,onClose:w,environment:f==null?void 0:f.environment,onConfirm:S,messageComponent:t(On,{enabled:f==null?void 0:f.enabled,featureName:f==null?void 0:f.featureName,environment:f.environment})})]})},ms=p("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",padding:"1.5rem",maxWidth:"350px",minWidth:"350px",marginRight:"1rem",marginTop:"1rem",[e.breakpoints.down(1e3)]:{marginBottom:"1rem",width:"100%",maxWidth:"none",minWidth:"auto"}})),ys=p("h3")(({theme:e})=>({display:"flex",gap:e.spacing(1),alignItems:"center",fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0,marginBottom:"0.5rem","& > :last-child":{position:"relative",top:1}})),fs=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=k("projectId"),r=k("featureId"),{feature:o}=_(a,r);ce();const[l,s]=m.useState(!1),[i,d]=m.useState(""),u=()=>{s(!1)};return c(ms,{"data-testid":"feature-toggle-status",children:[c(ys,{"data-loading":!0,children:["Feature toggle status",t(ve,{tooltip:"When a feature is switched off in an environment, it will always return false. When switched on, it will return true or false depending on its strategies.",placement:"top"})]}),(()=>o==null?void 0:o.environments.map(h=>t(hs,{env:h,hiddenEnvironments:e,setHiddenEnvironments:n,showInfoBox:()=>{d(h.name),s(!0)}},h.name)))(),t(Nn,{open:l,onClose:u,projectId:a,featureId:r,environmentName:i})]})},Ss=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),bs=p("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),vs=({feature:e,header:n})=>{const{locationSettings:a}=_a();return c(Ss,{children:[n,c("div",{"data-loading":!0,children:[t(bs,{children:"Created at:"}),t("span",{children:za(Wa(e.createdAt),a.locale)})]})]})},Cs=p("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),ws=p("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),Ts=({environment:e,callback:n,showInfoBox:a,children:r,hiddenEnvironments:o,setHiddenEnvironments:l})=>{const{name:s,enabled:i}=e,d=k("projectId"),u=k("featureId"),{toggleFeatureEnvironmentOn:g,toggleFeatureEnvironmentOff:h}=ce(),{refetchFeature:b}=_(d,u),{setToastData:y,setToastApiError:T}=K(),{isChangeRequestConfigured:w}=pe(d),{onChangeRequestToggle:S,onChangeRequestToggleClose:f,onChangeRequestToggleConfirm:v,changeRequestDialogDetails:x}=Dn(d),A=async()=>{try{await g(d,u,s),y({type:"success",title:`Available in ${s}`,text:`${u} is now available in ${s} based on its defined strategies.`}),b(),n&&n()}catch(D){D instanceof Error&&D.message===Ln?a():T(j(D))}},$=async()=>{try{await h(d,u,s),y({type:"success",title:`Unavailable in ${s}`,text:`${u} is unavailable in ${s} and its strategies will no longer have any effect.`}),b(),n&&n()}catch(D){T(j(D))}},F=async D=>{if(w(s)){D.preventDefault(),S(u,s,!i);return}if(i){await $();return}await A()},M=c(O,{children:[" ",c("span",{"data-loading":!0,children:[i?"enabled":"disabled"," in"]})," ",t(Xe,{text:s,maxWidth:"120",maxLength:15})]});return c(Cs,{children:[c(ws,{children:[t(xt,{tooltip:i?`Disable feature in ${s}`:`Enable feature in ${s}`,permission:mn,projectId:d,checked:i,onChange:F,environmentId:s}),r??M]}),t(Un,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:l}),t(Me,{isOpen:x.isOpen,onClose:f,environment:x==null?void 0:x.environment,onConfirm:v,messageComponent:t(On,{enabled:x==null?void 0:x.enabled,featureName:x==null?void 0:x.featureName,environment:x.environment})})]})},xs=p("div")(({theme:e})=>({padding:e.spacing(3)})),As=p("div")(()=>({display:"flex",flexDirection:"column"})),Es=p("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),Is=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Qt=p("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),Rs=p(Ha)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),ks=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:r})=>{const[o,l]=m.useState(!1),[s,i]=m.useState(""),d=e.environments.some(u=>{var g;return u.enabled&&((g=u.variants)==null?void 0:g.length)});return c(xs,{children:[n,e.environments.map(u=>{const g=u.strategies.length===1?"1 strategy":`${u.strategies.length} strategies`,h=u.variants??[],b=h.length>0&&c(O,{children:[t(Qt,{}),t(le,{title:"View variants",arrow:!0,describeChild:!0,children:t(Rs,{component:se,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:h.length===1?"1 variant":`${h.length} variants`})})]}),y=u.enabled&&h.length==0&&d;return t(Ts,{environment:u,hiddenEnvironments:a,setHiddenEnvironments:r,showInfoBox:()=>{i(u.name),l(!0)},children:c(As,{children:[t(Es,{children:u.name}),c(Is,{children:[g,b,t(E,{condition:y,show:c(O,{children:[t(Qt,{}),t(Ir,{})]})})]})]})},u.name)}),t(Nn,{open:o,onClose:()=>l(!1),projectId:e.project,featureId:e.name,environmentName:s})]})},Fs=({value:e,onChange:n,...a})=>{const{tagTypes:r}=cn(),o=r.map(l=>({key:l.name,label:l.name,title:l.name}));return t(O,{children:t(Ae,{label:"Tag type",id:"tag-select",options:o,value:e,onChange:n,...a})})},Ps=p(Ce)(()=>({width:"100%"})),Bs=p("section")(({theme:e})=>({["& > *"]:{margin:"0.5rem 0"}})),qn=({open:e,setOpen:n})=>{const a={type:"simple",value:""},r=k("featureId"),{addTagToFeature:o,loading:l}=ce(),{tags:s,refetch:i}=Ze(r),[d,u]=m.useState({tagError:""}),{setToastData:g}=K(),[h,b]=m.useState(a),y=()=>{n(!1),u({tagError:""}),b(a)},T=async A=>{A.preventDefault(),h.type||(h.type="simple");try{await o(r,h),n(!1),b(a),i(),g({type:"success",title:"Added tag to toggle",text:"We successfully added a tag to your toggle",confetti:!0})}catch($){const F=j($);u({tagError:F})}},w=A=>A.length,S=A=>!s.some(({type:$,value:F})=>$===A.type&&F===A.value),f=w(h.value)&&S(h),v=(A,$)=>{u({tagError:""});const F={...h,[A]:yn($)};S(F)||u({tagError:"Tag already exists for this feature toggle."}),b(F)},x="add-tag-form";return t(O,{children:t(ie,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Add tag",title:"Add tags to feature toggle",onClick:T,disabledPrimaryButton:l||!f,onClose:y,formId:x,children:c(O,{children:[t(H,{paragraph:!0,children:"Tags allow you to group features together"}),t("form",{id:x,onSubmit:T,children:c(Bs,{children:[t(Fs,{autoFocus:!0,name:"type",value:h.type,onChange:A=>v("type",A)}),t("br",{}),t(Ps,{label:"Value",name:"value",placeholder:"Your tag",value:h.value,error:Boolean(d.tagError),errorText:d.tagError,onChange:A=>v("value",A.target.value),required:!0})]})})]})})})},$s=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),Vs=p("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Ds=p(Be)(({theme:e})=>({fontSize:e.fontSizes.smallBody,".MuiChip-deleteIcon":{color:e.palette.neutral.main}})),Os=p(We)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),Ls=p(me)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),Ns=({feature:e,header:n})=>{const{tags:a,refetch:r}=Ze(e.name),{deleteTagFromFeature:o}=ce(),[l,s]=m.useState(!1),[i,d]=m.useState(!1),[u,g]=m.useState(),{setToastData:h,setToastApiError:b}=K(),{hasAccess:y}=m.useContext($e),T=y(fe,e.project),w=async()=>{if(u)try{await o(e.name,u.type,u.value),r(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(S){b(j(S))}};return c($s,{children:[n,t(Vs,{children:a.map(S=>{const f=`${S.type}:${S.value}`;return t(Ds,{label:f,deleteIcon:t(Ua,{titleAccess:"Remove"}),onDelete:T?()=>{d(!0),g(S)}:void 0},f)})}),t(E,{condition:T,show:c(O,{children:[t(E,{condition:a.length>0,show:t(Os,{})}),t(Ls,{"data-loading":!0,variant:"outlined",startIcon:t(qa,{}),onClick:()=>s(!0),children:"Add new tag"})]})}),t(qn,{open:l,setOpen:s}),c(ie,{open:i,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{d(!1),g(void 0)},onClick:()=>{d(!1),w(),g(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",c("strong",{children:[u==null?void 0:u.type,":",u==null?void 0:u.value]})]})]})},Ms=p("div")(({theme:e})=>({position:"sticky",top:e.spacing(2),borderRadius:e.shape.borderRadiusLarge,backgroundColor:e.palette.background.paper,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:"1rem",marginTop:"1rem",[e.breakpoints.down(1e3)]:{marginBottom:"1rem",width:"100%",maxWidth:"none",minWidth:"auto"}})),dt=p("h3")(({theme:e})=>({display:"flex",gap:e.spacing(1),alignItems:"center",fontSize:e.fontSizes.bodySize,margin:0,marginBottom:e.spacing(3),"& > :last-child":{position:"relative",top:1}})),js=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=k("projectId"),r=k("featureId"),{feature:o}=_(a,r);return c(Ms,{children:[t(ks,{header:c(dt,{"data-loading":!0,children:["Enabled in environments (",o.environments.filter(({enabled:l})=>l).length,")",t(ve,{tooltip:"When a feature is switched off in an environment, it will always return false. When switched on, it will return true or false depending on its strategies.",placement:"top"})]}),feature:o,hiddenEnvironments:e,setHiddenEnvironments:n}),t(We,{}),t(vs,{header:t(dt,{"data-loading":!0,children:"Feature toggle details"}),feature:o}),t(We,{}),t(Ns,{header:t(dt,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:o})]})},_s=()=>{const{trackEvent:e}=Ga(),{value:n,setValue:a}=hn(),[r,o]=m.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:r,setHiddenEnvironments:s=>{a(i=>{const d=new Set(i.hiddenEnvironments);return d.has(s)?(d.delete(s),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(d.add(s),e("hidden_environment",{props:{eventType:"environment hidden"}})),o(d),{...n,hiddenEnvironments:d}})}}},zs=p("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),Ws=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),Hs=()=>{const{uiConfig:e}=Te(),n=xe(),a=k("projectId"),r=k("featureId"),o=un(a,r),{hiddenEnvironments:l,setHiddenEnvironments:s}=_s(),i=()=>n(o);return At(r),c(zs,{children:[c("div",{children:[t(to,{}),t(E,{condition:Boolean(e.flags.variantsPerEnvironment),show:t(js,{hiddenEnvironments:l,setHiddenEnvironments:s}),elseShow:t(fs,{hiddenEnvironments:l,setHiddenEnvironments:s})})]}),t(Ws,{children:t(ds,{})}),c(fn,{children:[t(ye,{path:"strategies/create",element:t(ht,{label:"Create feature strategy",onClose:i,open:!0,children:t(Rr,{})})}),t(ye,{path:"strategies/edit",element:t(ht,{label:"Edit feature strategy",onClose:i,open:!0,children:t(Ya,{})})})]})]})},Gn=({values:e=[],updateValues:n,placeholder:a="",error:r,...o})=>{const l=i=>{const u=i.target.value.split(/,\s?/).map(g=>g.trim());n(u)},s=i=>{if(i.key==="Backspace"){const d=i.target.value;if(d.endsWith(", ")){i.preventDefault();const u=d.slice(0,-2);n(u.split(/,\s*/))}}};return t(Et,{...o,error:r,placeholder:a,value:e?e.join(", "):"",onKeyDown:s,onChange:l,style:{width:"100%"},variant:"outlined",size:"small"})},Us=({overrides:e,overridesDispatch:n})=>{const{classes:a}=Sn(),{context:r}=Ee(),o=r.map(({name:i})=>({key:i,label:i})),l=i=>d=>{n({type:"UPDATE_VALUES_AT",payload:[i,d]})},s=i=>(d,u)=>{d==null||d.preventDefault(),n({type:"UPDATE_VALUES_AT",payload:[i,u||[]]})};return t(O,{children:e.map((i,d)=>{var b;const u=r.find(y=>y.name===i.contextName),g=((b=u==null?void 0:u.legalValues)==null?void 0:b.map(({value:y})=>y))||[],h=i.values.filter(y=>g.includes(y));return c(U,{container:!0,alignItems:"center",children:[t(U,{item:!0,md:3,sm:3,xs:3,sx:y=>({marginRight:y.spacing(1)}),children:t(Ae,{name:"contextName",label:"Context Field",value:i.contextName,options:o,classes:{root:Ka(a.fullWidth)},onChange:y=>{n({type:"UPDATE_TYPE_AT",payload:[d,y]})}})}),t(U,{md:7,sm:7,xs:6,item:!0,children:t(E,{condition:Boolean(g&&g.length>0),show:t(bn,{multiple:!0,id:`override-select-${d}`,isOptionEqualToValue:(y,T)=>y===T,options:g,onChange:s(d),getOptionLabel:y=>y,value:h,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:y=>t(Et,{...y,variant:"outlined",label:"Legal values",style:{width:"100%"}})}),elseShow:t(Gn,{label:"Values (v1, v2, ...)",name:"values",placeholder:"",values:i.values,updateValues:l(d)})})}),t(U,{item:!0,md:1,children:t(le,{title:"Remove",arrow:!0,children:t(Ne,{onClick:y=>{y.preventDefault(),n({type:"REMOVE",payload:d})},size:"large",children:t(Ve,{})})})})]},`override=${d}`)})})},qs=(e,n)=>{switch(n.type){case"SET":return n.payload;case"CLEAR":return[];case"ADD":return[...e,n.payload];case"REMOVE":return e.filter((s,i)=>i!==n.payload);case"UPDATE_VALUES_AT":const[a,r]=n.payload;return e.map((s,i)=>i===a?{...s,values:r}:s);case"UPDATE_TYPE_AT":const[o,l]=n.payload;return e.map((s,i)=>i===o?{...s,contextName:l}:s)}},Gs=(e=[])=>m.useReducer(qs,e),Ys=[{key:"string",label:"string"},{key:"json",label:"json"},{key:"csv",label:"csv"}],ut={type:"string",value:""},Ks=p("p")(({theme:e})=>({color:e.palette.error.main,fontSize:e.fontSizes.smallBody,position:"relative"})),Js=p(Ce)({maxWidth:350,width:"100%"}),Xs=p(U)(({theme:e})=>({marginBottom:e.spacing(1)})),Zt=p("p")(({theme:e})=>({display:"flex",alignItems:"center",gap:"1ch",marginBottom:e.spacing(2)})),Qs=p(Ae)({minWidth:"100px",width:"100%"}),Zs=({showDialog:e,closeDialog:n,save:a,editVariant:r,validateName:o,validateWeight:l,title:s,editing:i})=>{const[d,u]=m.useState({}),[g,h]=m.useState(ut),[b,y]=Gs([]),[T,w]=m.useState({}),{classes:S}=Sn(),f=k("projectId"),v=k("featureId"),{feature:x}=_(f,v),[A,$]=m.useState([]),{context:F}=Ee(),M=V=>{try{return JSON.parse(V),!0}catch{return w({payload:"Invalid JSON"}),!1}},D=()=>{r?(u({name:r.name,weight:String(r.weight/10),weightType:r.weightType||Ie.VARIABLE,stickiness:r.stickiness}),r.payload?h(r.payload):h(ut),r.overrides?y({type:"SET",payload:r.overrides}):y({type:"CLEAR"})):(u({}),h(ut),y({type:"CLEAR"})),w({})},Y=V=>$(mt(V));m.useEffect(()=>{x&&Y(x.variants)},[x.variants]),m.useEffect(()=>{D()},[r]);const q=V=>{const{name:R,value:z}=V.target;u({...d,[R]:yn(z)})},G=V=>{const{checked:R,name:z}=V.target,W=R?Ie.FIX:Ie.VARIABLE;u({...d,[z]:W})},ee=async V=>{w({}),V.preventDefault();const R=o(d.name);if(R){w(R);return}const z=l(d.weight);if(z){w(z);return}if(!(g.type==="json"&&!M(g.value)))try{const re={name:d.name,weight:Number(d.weight)*10,weightType:d.weightType,stickiness:d.stickiness,payload:g.value?g:void 0,overrides:b.map(ae=>({contextName:ae.contextName,values:ae.values})).filter(ae=>ae.values&&ae.values.length>0)};await a(re),D(),n()}catch(re){const ae=j(re);ae.includes("duplicate value")?w({name:"A variant with that name already exists."}):ae.includes("must be a number")?w({weight:"Weight must be a number"}):w({general:ae||"Could not add variant"})}},te=V=>R=>{w({payload:""}),h({...g,[V]:R})},B=V=>{V.preventDefault(),D(),n()},C=()=>{F.length>0&&y({type:"ADD",payload:{contextName:F[0].name,values:[]}})},I=d.weightType===Ie.FIX,N="add-feature-variant-form";return t(ie,{open:e,style:Ja,onClose:B,onClick:ee,primaryButtonText:"Save",secondaryButtonText:"Cancel",title:s,fullWidth:!0,maxWidth:"md",formId:N,children:c("form",{id:N,onSubmit:ee,className:S.contentSpacingY,children:[t(Ks,{children:T.general}),t(Js,{label:"Variant name",autoFocus:!0,name:"name",id:"variant-name",errorText:T.name,value:d.name||"",error:Boolean(T.name),required:!0,type:"name",disabled:i,onChange:q,"data-testid":"VARIANT_NAME_INPUT"}),t("br",{}),c(Xs,{container:!0,children:[t(E,{condition:i&&A.length>1||!i&&A.length>0,show:t(U,{item:!0,md:12,children:t(Xa,{children:t(vn,{control:t(xt,{permission:ke,projectId:f,name:"weightType",checked:I,"data-testid":"VARIANT_WEIGHT_CHECK",onChange:G}),label:"Custom percentage"})})})}),t(E,{condition:d.weightType===Ie.FIX,show:t(U,{item:!0,md:4,children:t(Ce,{id:"weight",label:"Variant weight",name:"weight","data-testid":"VARIANT_WEIGHT_INPUT",InputProps:{endAdornment:t(Cn,{position:"start",children:"%"})},sx:{marginRight:"0.8rem"},value:d.weight,error:Boolean(T.weight),errorText:T.weight,type:"number",disabled:!I,onChange:V=>{q(V)},"aria-valuemin":0,"aria-valuemax":100})})})]}),c(Zt,{children:[t("strong",{children:"Payload "}),t(ve,{tooltip:"Passed along with the the variant object."})]}),c(U,{container:!0,children:[t(U,{item:!0,md:2,sm:2,xs:4,children:t(Qs,{id:"variant-payload-type",name:"type",label:"Type",value:g.type,options:Ys,onChange:te("type")})}),t(U,{item:!0,md:8,sm:8,xs:6,children:t(Ce,{error:Boolean(T.payload),errorText:T.payload,name:"variant-payload-value",id:"variant-payload-value",label:"Value",multiline:g.type!=="string",rows:g.type==="string"?1:4,className:S.fullWidth,value:g.value,onChange:V=>te("value")(V.target.value),"data-testid":"VARIANT_PAYLOAD_VALUE",placeholder:g.type==="json"?'{ "hello": "world" }':""})})]}),t(E,{condition:b.length>0,show:c(Zt,{children:[t("strong",{children:"Overrides "}),t(ve,{tooltip:"Here you can specify which users should get this variant."})]})}),t(Us,{overrides:b,overridesDispatch:y}),t(me,{onClick:C,variant:"contained",color:"primary",children:"Add override"})]})})},ei=({show:e,onClick:n,onClose:a})=>t(ie,{title:"Are you sure you want to delete this variant?",open:e,primaryButtonText:"Delete variant",secondaryButtonText:"Cancel",onClick:n,onClose:a,children:t(he,{severity:"error",children:"Deleting this variant will change which variant users receive."})}),ti=({payload:e,overrides:n})=>c(O,{children:[t(E,{condition:Boolean(e),show:t(Z,{children:"Payload"})}),t(E,{condition:n&&n.length>0,show:t(Z,{children:"Overrides"})})]}),ni=({projectId:e,setDelDialog:n,variant:a,editVariant:r})=>c(Q,{style:{display:"flex",justifyContent:"flex-end"},"data-loading":!0,children:[t(ne,{size:"large","data-testid":`VARIANT_EDIT_BUTTON_${a.name}`,permission:ke,projectId:e,onClick:()=>r(a.name),children:t(Se,{})}),t(ne,{size:"large",permission:ke,"data-testid":`VARIANT_DELETE_BUTTON_${a.name}`,projectId:e,onClick:()=>n({show:!0,name:a.name}),children:t(Ve,{})})]}),ai=()=>{const{hasAccess:e}=m.useContext($e),n=k("projectId"),a=k("featureId"),{feature:r,refetchFeature:o,loading:l}=_(n,a),[s,i]=m.useState([]),[d,u]=m.useState(!1),{context:g}=Ee(),{setToastData:h,setToastApiError:b}=K(),{patchFeatureVariants:y}=ce(),[T,w]=m.useState({}),[S,f]=m.useState(!1),[v,x]=m.useState([]),[A,$]=m.useState({name:"",show:!1}),F=ue(He.breakpoints.down("md")),M=ue(He.breakpoints.down("lg"));m.useEffect(()=>{r&&R(r.variants)},[r.variants]),m.useEffect(()=>{const P=["default",...g.filter(L=>L.stickiness).map(L=>L.name)];x(P)},[g]);const D=e(ke,n),Y=m.useMemo(()=>l?Array(5).fill({name:"Context name",description:"Context description when loading"}):r.variants,[r.variants,l]),q=m.useCallback(P=>{const L={...s.find(J=>J.name===P)};w(L),u(!0),f(!0)},[s,w,u,f]),G=m.useMemo(()=>[{Header:"Name",accessor:"name",width:"25%",Cell:({row:{original:{name:P}}})=>t(Z,{"data-loading":!0,children:P}),sortType:"alphanumeric"},{Header:"Payload/Overrides",accessor:"data",Cell:({row:{original:{overrides:P,payload:L}}})=>t(ti,{overrides:P,payload:L}),disableSortBy:!0},{Header:"Weight",accessor:"weight",width:"20%",Cell:({row:{original:{name:P,weight:L}}})=>c(Z,{"data-testid":`VARIANT_WEIGHT_${P}`,children:[wn(L)," %"]}),sortType:"number"},{Header:"Type",accessor:"weightType",width:"20%",Cell:({row:{original:{weightType:P}}})=>t(Z,{children:P}),sortType:"alphanumeric"},{Header:"Actions",id:"Actions",align:"right",Cell:({row:{original:P}})=>t(ni,{editVariant:q,setDelDialog:$,variant:P,projectId:n}),width:150,disableSortBy:!0}],[n,q]),ee=m.useMemo(()=>({sortBy:[{id:"name",desc:!1}]}),[]),{getTableProps:te,getTableBodyProps:B,headerGroups:C,rows:I,prepareRow:N,setHiddenColumns:V}=de.useTable({columns:G,data:Y,initialState:ee,sortTypes:Tn,autoResetHiddenColumns:!1,autoResetGlobalFilter:!1,autoResetSortBy:!1,disableSortRemove:!0},de.useGlobalFilter,de.useSortBy);It([{condition:F,columns:["data"]},{condition:M,columns:["weightType"]}],V,G);const R=P=>i(mt(P)),z=()=>{f(!1),u(!1),w({})},W=()=>{if(!s||s.length<2)return null;const P=s[0].stickiness||"default",L=v.map(X=>({key:X,label:X}));return v.includes(P)||L.push({key:P,label:P}),c("section",{style:{paddingTop:"16px"},children:[t(Ae,{label:"Stickiness",options:L,value:P,onChange:X=>{re(X).catch(console.warn)}}),"  ",c("small",{style:{display:"block",marginTop:"0.5rem"},children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t("a",{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})},re=async P=>{const L=[...s].map(X=>({...X,stickiness:P})),J=$t(L);if(J.length!==0)try{await y(n,a,J),o(),h({title:"Updated variant",confetti:!0,type:"success",text:"Successfully updated variant stickiness"})}catch(X){b(j(X))}},ae=async P=>{let L=s.filter(J=>J.name!==P);try{await nt(L,"Successfully removed variant")}catch(J){b(j(J))}},Bt=async P=>{const L=mt(s),J=L.findIndex(X=>X.name===P.name);L[J]=P,await nt(L,"Successfully updated variant")},Xn=async P=>{let L="default";(s==null?void 0:s.length)>0&&(L=s[0].stickiness||"default"),P.stickiness=L,await nt([...s,P],"Successfully added a variant")},nt=async(P,L)=>{const J=En(P,1e3),X=$t(J);if(X.length!==0)try{await y(n,a,X),o(),h({title:"Updated variant",type:"success",text:L})}catch(na){b(j(na))}},Qn=P=>{if(!P)return{name:"Name is required"}},Zn=P=>{const L=parseInt(P);if(L>100||L<0)return{weight:"weight must be between 0 and 100"}},ea=ei({show:A.show,onClick:()=>{ae(A.name),$({name:"",show:!1}),h({title:"Deleted variant",type:"success",text:"Successfully deleted variant"})},onClose:()=>$({show:!1,name:""})}),$t=P=>In(r.variants,P),ta=()=>{u(!1),s.length===0?w({weight:1e3}):w({weightType:"variable"}),f(!0)};return c(Qe,{isLoading:l,header:t(xn,{title:`Variants (${I.length})`,actions:t(O,{children:t(ge,{onClick:ta,"data-testid":"ADD_VARIANT_BUTTON",permission:ke,projectId:n,children:"New variant"})})}),children:[c(he,{severity:"info",sx:{marginBottom:"1rem"},children:["Variants allows you to return a variant object if the feature toggle is considered enabled for the current request. When using variants you should use the"," ",t("code",{style:{fontWeight:"bold"},children:"getVariant()"})," method in the Client SDK."]}),c(Qa,{...te(),children:[t(Rt,{headerGroups:C}),t(kt,{...B(),children:I.map(P=>(N(P),t(Ft,{hover:!0,...P.getRowProps(),style:{height:"75px"},children:P.cells.map(L=>t(Za,{...L.getCellProps(),padding:"none",children:L.render("Cell")}))})))})]}),t(E,{condition:I.length===0,show:t(An,{children:"No variants available. Get started by adding one."})}),t("br",{}),t("div",{children:t(E,{condition:D,show:W()})}),t(Zs,{showDialog:S,closeDialog:z,save:async P=>d?Bt(P):Xn(P),editing:d,validateName:Qn,validateWeight:Zn,editVariant:T,title:d?"Edit variant":"Add variant"}),ea]})},ri=p("div")(({theme:e})=>({display:"flex",alignItems:"center",rowGap:e.spacing(1.5),marginBottom:e.spacing(2),[e.breakpoints.down("sm")]:{flexDirection:"column","& > div, .MuiInputBase-root":{width:"100%",alignItems:"flex-start"}}})),oi=p(Rn)(({theme:e})=>({minWidth:e.spacing(20),marginRight:e.spacing(10)})),si=p("div")(({theme:e})=>({width:"100%",gap:e.spacing(1.5),display:"flex"})),ii=p(Gn)(()=>({width:"100%"})),li=p(Et)(()=>({width:"100%"})),ci=({overrides:e,overridesDispatch:n})=>{const{context:a}=Ee(),r=a.map(({name:s})=>({key:s,label:s})),o=s=>i=>{n({type:"UPDATE_VALUES_AT",payload:[s,i]})},l=s=>(i,d)=>{i==null||i.preventDefault(),n({type:"UPDATE_VALUES_AT",payload:[s,d||[]]})};return t(O,{children:e.map((s,i)=>{var h;const d=a.find(({name:b})=>b===s.contextName),u=((h=d==null?void 0:d.legalValues)==null?void 0:h.map(({value:b})=>b))||[],g=s.values.filter(b=>u.includes(b));return c(ri,{children:[t(oi,{id:"override-context-name",name:"contextName",label:"Context Field",value:s.contextName,options:r,onChange:b=>n({type:"UPDATE_TYPE_AT",payload:[i,b.target.value]})}),c(si,{children:[t(E,{condition:Boolean(u&&u.length>0),show:t(bn,{multiple:!0,id:`override-select-${i}`,isOptionEqualToValue:(b,y)=>b===y,options:u,onChange:l(i),getOptionLabel:b=>b,value:g,style:{width:"100%"},filterSelectedOptions:!0,size:"small",renderInput:b=>t(li,{...b,variant:"outlined",label:"Legal values"})}),elseShow:t(ii,{label:"Values (v1, v2, ...)",name:"values",placeholder:"",values:s.values,updateValues:o(i)})}),t(le,{title:"Remove",arrow:!0,children:t(Ne,{onClick:b=>{b.preventDefault(),n({type:"REMOVE",payload:i})},children:t(Ve,{})})})]})]},`override=${i}`)})})},di=(e,n)=>{switch(n.type){case"SET":return n.payload;case"CLEAR":return[];case"ADD":return[...e,n.payload];case"REMOVE":return e.filter((s,i)=>i!==n.payload);case"UPDATE_VALUES_AT":const[a,r]=n.payload;return e.map((s,i)=>i===a?{...s,values:r}:s);case"UPDATE_TYPE_AT":const[o,l]=n.payload;return e.map((s,i)=>i===o?{...s,contextName:l}:s)}},ui=(e=[])=>m.useReducer(di,e);var oe=(e=>(e.FIX="fix",e.VARIABLE="variable",e))(oe||{});const pi=p("div")(({theme:e})=>({position:"relative",backgroundColor:e.palette.neutral.light,display:"flex",flexDirection:"column",padding:e.spacing(3),marginBottom:e.spacing(3),borderRadius:e.shape.borderRadiusLarge})),gi=p(Ne)(({theme:e})=>({position:"absolute",top:e.spacing(2),right:e.spacing(2)})),Yn=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),en=p(Yn)(({theme:e})=>({display:"flex",color:e.palette.text.primary,marginTop:e.spacing(1),marginBottom:e.spacing(2)})),hi=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(2)})),mi=p(vn)(({theme:e})=>({marginBottom:e.spacing(1),"& > span":{fontSize:e.fontSizes.smallBody},[e.breakpoints.down("sm")]:{marginTop:e.spacing(1),marginBottom:e.spacing(1.5)}})),tn=p(Ce)(()=>({width:"100%"})),yi=p("div")(({theme:e})=>({marginLeft:e.spacing(3)})),fi=p(Ce)(({theme:e})=>({width:e.spacing(24),[e.breakpoints.down("sm")]:{width:"100%"}})),Si=p("div")(({theme:e})=>({marginTop:e.spacing(3),flexGrow:1})),Kn=p("div")(({theme:e})=>({display:"flex",rowGap:e.spacing(1.5),marginBottom:e.spacing(2),[e.breakpoints.down("sm")]:{flexDirection:"column","& > div, .MuiInputBase-root":{width:"100%"}}})),bi=p(Kn)({alignItems:"end",justifyContent:"space-between"}),vi=p(Rn)(({theme:e})=>({minWidth:e.spacing(20),marginRight:e.spacing(10)})),Ci=p(me)(({theme:e})=>({width:e.spacing(20),maxWidth:"100%"})),wi=[{key:"string",label:"string"},{key:"json",label:"json"},{key:"csv",label:"csv"}],Ti={type:"string",value:""},xi=({variant:e,variants:n,updateVariant:a,removeVariant:r,apiPayload:o})=>{const[l,s]=m.useState(e.name),[i,d]=m.useState(e.weightType===oe.FIX),[u,g]=m.useState(String(e.weight/10)),[h,b]=m.useState(e.payload||Ti),[y,T]=ui(e.overrides||[]),{context:w}=Ee(),[S,f]=m.useState({}),v=C=>{f(I=>({...I,[C]:void 0}))},x=(C,I)=>{f(N=>({...N,[C]:I}))};m.useEffect(()=>{var C;v("percentage"),(C=o.error)!=null&&C.includes("%")&&x("percentage","Total weight must equal 100%")},[o.error]);const A=!e.new,$=n.filter(({id:C,weightType:I})=>C!==e.id&&I===oe.VARIABLE).length>0,F=C=>{const I=C.weightType===oe.VARIABLE,N=n.some(R=>R.weightType===oe.FIX),V=n.filter(R=>R.weightType===oe.VARIABLE).length==1;return N&&V&&I},M=C=>{v("name"),ee(C,e.id)||x("name","A variant with that name already exists for this environment."),s(C)},D=C=>{(C===""||te(C))&&g(C)},Y=C=>{B(C)||x("payload","Invalid JSON.")},q=()=>{w.length>0&&T({type:"ADD",payload:{contextName:w[0].name,values:[]}})},G=C=>Boolean(C.length),ee=(C,I)=>A||!n.some(N=>N.name===C&&N.id!==I),te=C=>{if(!i)return!0;if(C===""||C.match(/\.[0-9]{2,}$/))return!1;const I=Number(C);return I>=0&&I<=100},B=C=>{try{return C.type==="json"&&JSON.parse(C.value),!0}catch{return!1}};return m.useEffect(()=>{a({...e,name:l,weight:Number(i?u:100)*10,weightType:i?oe.FIX:oe.VARIABLE,stickiness:(n==null?void 0:n.length)>0?n[0].stickiness:"default",payload:h.value?h:void 0,overrides:y.map(C=>({contextName:C.contextName,values:C.values})).filter(C=>C.values&&C.values.length>0),isValid:G(l)&&ee(l,e.id)&&te(u)&&B(h)&&!o.error})},[l,i,u,h,y]),m.useEffect(()=>{i||g(String(e.weight/10))},[e.weight]),c(pi,{children:[t(gi,{onClick:()=>r(e.id),disabled:F(e),children:t(Ve,{})}),c(bi,{children:[c(Si,{children:[t(Yn,{children:"Variant name"}),t(hi,{children:"This will be used to identify the variant in your code"}),t(tn,{autoFocus:!0,label:"Variant name",error:Boolean(S.name),errorText:S.name,value:l,onChange:C=>M(C.target.value),disabled:A,required:!0})]}),t(E,{condition:$,show:c(yi,{children:[t(mi,{label:"Custom percentage",control:t(er,{checked:i,onChange:C=>d(C.target.checked)})}),t(fi,{type:"number",label:"Variant weight",error:Boolean(S.percentage),errorText:S.percentage,value:u,onChange:C=>D(C.target.value),required:i,disabled:!i,"aria-valuemin":0,"aria-valuemax":100,InputProps:{endAdornment:t(Cn,{position:"end",children:"%"})}})]})})]}),c(en,{children:["Payload",t(ve,{tooltip:"Passed along with the the variant object."})]}),c(Kn,{children:[t(vi,{id:"variant-payload-type",name:"type",label:"Type",value:h.type,options:wi,onChange:C=>{v("payload"),b(I=>({...I,type:C.target.value}))}}),t(tn,{id:"variant-payload-value",name:"variant-payload-value",label:"Value",multiline:h.type!=="string",rows:h.type==="string"?1:4,value:h.value,onChange:C=>{v("payload"),b(I=>({...I,value:C.target.value}))},placeholder:h.type==="json"?'{ "hello": "world" }':"",onBlur:()=>Y(h),error:Boolean(S.payload),errorText:S.payload})]}),c(en,{children:["Overrides",t(ve,{tooltip:"Here you can specify which users should get this variant."})]}),t(ci,{overrides:y,overridesDispatch:T}),t(Ci,{onClick:q,variant:"outlined",color:"primary",children:"Add override"})]})},Ai=p("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"},marginTop:e.spacing(-1.5),marginBottom:e.spacing(4)})),Ei=p(kn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Ii=p("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontSize:e.fontSizes.mainHeader,fontWeight:e.fontWeight.bold})),Ri=p("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),ki=p(he)(({theme:e})=>({marginBottom:e.spacing(2)})),Fi=p(he)(({theme:e})=>({marginTop:e.spacing(4)})),Pi=p("div")(({theme:e})=>({display:"flex",flexDirection:"column-reverse"})),Bi=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),nn=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),$i=p(Ae)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),Vi=p("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),Di=p(me)(({theme:e})=>({marginLeft:e.spacing(3)})),Oi=({environment:e,open:n,setOpen:a,getApiPayload:r,getCrPayload:o,onConfirm:l})=>{var V;const s=k("projectId"),i=k("featureId"),{uiConfig:d}=Te(),{context:u}=Ee(),{isChangeRequestConfigured:g}=pe(s),{data:h}=Oe(s),{changeRequestInReviewOrApproved:b,alert:y}=nr(h),T=(e==null?void 0:e.variants)||[],[w,S]=m.useState([]);m.useEffect(()=>{S(T.length?T.map(R=>({...R,isValid:!0,new:!1,id:rt()})):[{name:"",weightType:oe.VARIABLE,weight:0,overrides:[],stickiness:(w==null?void 0:w.length)>0?w[0].stickiness:"default",new:!0,isValid:!1,id:rt()}])},[n]);const f=(R,z)=>{S(W=>Lt(W.map(re=>re.id===z?R:re),1e3))},v=w.map(({new:R,isValid:z,id:W,...re})=>re),x=r(T,v),A=o(v),$=async R=>{R.preventDefault(),l(v)},F=()=>q?`curl --location --request POST '${d.unleashUrl}/api/admin/projects/${s}/environments/${e==null?void 0:e.name}/change-requests' \\
2
+ --header 'Authorization: INSERT_API_KEY' \\
3
+ --header 'Content-Type: application/json' \\
4
+ --data-raw '${JSON.stringify(A,void 0,2)}'`:`curl --location --request PATCH '${d.unleashUrl}/api/admin/projects/${s}/features/${i}/environments/${e==null?void 0:e.name}/variants' \\
5
+ --header 'Authorization: INSERT_API_KEY' \\
6
+ --header 'Content-Type: application/json' \\
7
+ --data-raw '${JSON.stringify(x.patch,void 0,2)}'`,M=w.every(({isValid:R})=>R),D=b((e==null?void 0:e.name)||""),Y=D?"Add to existing change request":"Add change to draft",q=g((e==null?void 0:e.name)||"")&&d.flags.crOnVariants,G=((V=v[0])==null?void 0:V.stickiness)||"default",ee=m.useMemo(()=>["default",...u.filter(R=>R.stickiness).map(R=>R.name)],[u]),te=ee.map(R=>({key:R,label:R}));ee.includes(G)||te.push({key:G,label:G});const B=async R=>{S(z=>z.map(W=>({...W,stickiness:R})))},C=R=>{B(R).catch(console.warn)},[I,N]=m.useState();return m.useEffect(()=>{N(void 0),x.error&&N(x.error)},[x.error]),t(ht,{open:n,onClose:()=>{a(!1)},label:"",children:c(tr,{modal:!0,title:"",description:"Variants allows you to return a variant object if the feature toggle is considered enabled for the current request.",documentationLink:"https://docs.getunleash.io/reference/feature-toggle-variants",documentationLinkLabel:"Feature toggle variants documentation",formatApiCode:F,loading:!n,children:[c(Ai,{children:[c("div",{children:[t(Ei,{deprecated:!(e!=null&&e.enabled)}),t(Ii,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(ge,{onClick:()=>S(R=>[...R,{name:"",weightType:oe.VARIABLE,weight:0,overrides:[],stickiness:(R==null?void 0:R.length)>0?R[0].stickiness:"default",new:!0,isValid:!1,id:rt()}]),variant:"outlined",permission:Re,projectId:s,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),c(Ri,{onSubmit:$,children:[t(E,{condition:D,show:y,elseShow:t(E,{condition:Boolean(q),show:c(ki,{severity:"info",children:[t("strong",{children:"Change requests"})," are enabled",e?` for ${e.name}`:"",". Your changes need to be approved before they will be live. All the changes you do now will be added into a draft that you can submit for review."]})})}),t(Pi,{children:w.map(R=>t(xi,{variant:R,variants:w,updateVariant:z=>f(z,R.id),removeVariant:()=>S(z=>Lt(z.filter(W=>W.id!==R.id),1e3)),projectId:s,apiPayload:x},R.id))}),t(E,{condition:w.length>0,show:c(O,{children:[t(Bi,{children:t("p",{children:"Stickiness"})}),c(nn,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t("a",{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t($i,{options:te,value:G,onChange:C})})]}),elseShow:t(nn,{children:"This environment has no variants. Get started by adding a variant."})}),c(Fi,{severity:"error",hidden:!Boolean(I),children:[t("strong",{children:"Error: "}),I]}),c(Vi,{children:[t(me,{type:"submit",variant:"contained",color:"primary",disabled:!M,children:q?Y:"Save variants"}),t(Di,{onClick:()=>{a(!1)},children:"Cancel"})]})]})]})})},Li=p(H)(({theme:e})=>({fontSize:e.fontSizes.smallerBody,whiteSpace:"pre-wrap"})),Ni=({value:e})=>{const{searchQuery:n}=Fn();return e?e.type==="string"&&e.value.length<20?t(Z,{children:t(yt,{search:n,children:e.value})}):t(Z,{children:t(Pn,{tooltip:t(O,{children:t(Li,{children:t(yt,{search:n,children:e.value})})}),highlighted:n.length>0&&e.value.toLowerCase().includes(n.toLowerCase()),children:e.type})}):t(Z,{})},Mi=p(H)(({theme:e})=>({fontSize:e.fontSizes.smallerBody})),ji=({value:e})=>{const{searchQuery:n}=Fn();if(!e||e.length===0)return t(Z,{});const a=r=>`${r.contextName}:${r.values.join()}`;return t(Z,{children:t(Pn,{tooltip:t(O,{children:e.map((r,o)=>t(Mi,{children:t(yt,{search:n,children:a(r)})},r.contextName+o))}),highlighted:n.length>0&&(e==null?void 0:e.map(a).join(`
8
+ `).toLowerCase().includes(n.toLowerCase())),children:e.length===1?"1 override":`${e.length} overrides`})})},_i=p("div")(({theme:e})=>({margin:e.spacing(3,0)})),zi=({environment:e,searchValue:n})=>{const a=k("projectId"),r=Ye(),o=ue(r.breakpoints.down("md")),l=ue(r.breakpoints.down("lg")),s=e.variants??[],i=m.useMemo(()=>[{Header:"Name",accessor:"name",Cell:ar,sortType:"alphanumeric",minWidth:350,searchable:!0},{Header:"Payload",accessor:"payload",Cell:Ni,disableSortBy:!0,searchable:!0,filterParsing:f=>f==null?void 0:f.value},{Header:"Overrides",accessor:"overrides",Cell:ji,disableSortBy:!0,searchable:!0,filterParsing:f=>(f==null?void 0:f.map(({contextName:v,values:x})=>`${v}:${x.join()}`).join(`
9
+ `))||""},{Header:"Weight",accessor:"weight",Cell:({row:{original:{name:f,weight:v}}})=>c(Z,{"data-testid":`VARIANT_WEIGHT_${f}`,children:[wn(v)," %"]}),sortType:"number"},{Header:"Type",accessor:f=>f.weightType==="fix"?"Fixed":"Variable",Cell:Z,sortType:"alphanumeric"}],[a,s,e]),d=m.useMemo(()=>({sortBy:[{id:"name",desc:!1}]}),[]),{data:u,getSearchText:g}=rr(i,n,s),{getTableProps:h,getTableBodyProps:b,headerGroups:y,rows:T,prepareRow:w,setHiddenColumns:S}=de.useTable({columns:i,data:u,initialState:d,sortTypes:Tn,autoResetHiddenColumns:!1,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},de.useSortBy);return It([{condition:o,columns:["payload","overrides"]},{condition:l,columns:["weightType"]}],S,i),c(_i,{children:[t(or,{value:g(n),children:c(Bn,{...h(),children:[t(Rt,{headerGroups:y}),t(kt,{...b(),children:T.map(f=>(w(f),t(Ft,{hover:!0,...f.getRowProps(),children:f.cells.map(v=>t($n,{...v.getCellProps(),children:v.render("Cell")}))})))})]})}),t(E,{condition:T.length===0,show:t(E,{condition:(n==null?void 0:n.length)>0,show:c(An,{children:["No variants found matching “",n,"”"]})})})]})},Wi=p("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.dividerAlternative}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),Hi=p("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Ui=p(kn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),qi=p("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontWeight:e.fontWeight.bold})),Gi=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Yi=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),Ki=({environment:e,searchValue:n,children:a})=>{var l;const r=e.variants??[],o=((l=r[0])==null?void 0:l.stickiness)||"default";return c(Wi,{children:[c(Hi,{children:[c("div",{children:[t(Ui,{deprecated:!e.enabled}),t(qi,{deprecated:!e.enabled,children:e.name})]}),a]}),t(E,{condition:r.length>0,show:c(O,{children:[t(zi,{environment:e,searchValue:n}),t(E,{condition:r.length>1,show:c(O,{children:[c(Yi,{children:[t("p",{children:"Stickiness:"}),t(gt,{children:o})]}),c(Gi,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t("a",{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},Ji=p(wt)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),Xi=({environment:e,permission:n,projectId:a,environmentId:r,onCopyVariantsFrom:o,otherEnvsWithVariants:l})=>{const[s,i]=m.useState(null),d=Boolean(s),u=e.variants??[];return t(E,{condition:l.length>0&&u.length===0,show:c(O,{children:[t(ge,{onClick:g=>{i(g.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":d?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":d?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:r,children:"Copy variants from"}),t(Ke,{anchorEl:s,open:d,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:l.map(g=>t(Je,{onClick:()=>o(g,e),children:t(Ji,{children:`Copy from ${g.name}`})},g.name))})]})})},Qi=({permission:e,projectId:n,environment:a,checked:r,onClick:o,...l})=>{const s=sr(e,n,a);return c(Je,{disabled:!s,onClick:o,...l,children:[t(ir,{checked:r}),a]})},Zi=p(Ke)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),el=p("div")(({theme:e})=>({margin:e.spacing(1,2)})),tl=p(me)(({theme:e})=>({marginTop:e.spacing(2)})),nl=({current:e,environments:n,permission:a,projectId:r,onSubmit:o})=>{var w;const[l,s]=m.useState(null),i=Boolean(l),[d,u]=m.useState([]),g=S=>{u(f=>[...f,S])},h=S=>{u(f=>f.filter(({name:v})=>v!==S.name))},b=S=>{d.includes(S)?h(S):g(S)},y=()=>{u([]),s(null)},T=((w=n.find(S=>S.name===e))==null?void 0:w.variants)??[];return t(E,{condition:T.length>0&&n.length>1,show:c(O,{children:[t(me,{onClick:S=>{s(S.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,variant:"outlined",children:"Push to environment"}),c(Zi,{anchorEl:l,open:i,onClose:()=>s(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(S=>S.name!==e).map(S=>t(Qi,{projectId:r,permission:a,environment:S.name,checked:d.includes(S),onClick:()=>b(S)},S.name)),c(el,{children:[t(We,{}),c(tl,{variant:"outlined",onClick:()=>{o(d),y()},disabled:d.length===0,children:["Push to selected (",d.length,")"]})]})]})]})})},al=p(he)(({theme:e})=>({marginBottom:e.spacing(4),"& code":{fontWeight:e.fontWeight.bold}})),rl=p("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),ol=()=>{const{uiConfig:e}=Te(),{setToastData:n,setToastApiError:a}=K(),r=Ye(),o=ue(r.breakpoints.down("md")),l=k("projectId"),s=k("featureId"),{feature:i,refetchFeature:d,loading:u}=_(l,s),{patchFeatureEnvironmentVariants:g,overrideVariantsInEnvironments:h}=ce(),{refetch:b}=Oe(l),{addChange:y}=Ct(),{isChangeRequestConfigured:T}=pe(l),[w,S]=m.useState(""),[f,v]=m.useState(),[x,A]=m.useState(!1),$=m.useMemo(()=>{var B;return((B=i==null?void 0:i.environments)==null?void 0:B.map(C=>({...C,crEnabled:e.flags.crOnVariants&&T(C.name)})))||[]},[i.environments,e.flags.crOnVariants]),F=(B,C)=>In(B,C),M=(B,C)=>{try{const I=En(C,1e3);return{patch:F(B,I)}}catch(I){return{patch:[],error:j(I)}}},D=B=>({feature:s,action:"patchVariant",payload:{variants:B}}),Y=async(B,C)=>{if(B.crEnabled)await y(l,B.name,D(C)),b();else{const I=B.variants??[],{patch:N,error:V}=M(I,C);if(N.length===0)return;if(V){n({type:"error",title:V});return}await g(l,s,B.name,N)}d()},q=async(B,C)=>{try{const I=C.filter(({crEnabled:W})=>W),N=C.filter(({crEnabled:W})=>!W);I.length&&await Promise.all(I.map(W=>y(l,W.name,D(B)))),N.length&&await h(l,s,B,N.map(({name:W})=>W)),b(),d();const V=N.length?`Variants pushed to ${N.length===1?N[0].name:`${N.length} environments`}`:"",R=I.length?`Variants push added to ${I.length===1?`${I[0].name} draft`:`${I.length} drafts`}`:"",z=`${V}${V&&R?". ":""}${R}`;n({title:z,type:"success"})}catch(I){a(j(I))}},G=B=>{v(B),A(!0)},ee=async B=>{if(f)try{await Y(f,B),A(!1),n({title:f.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(C){a(j(C))}},te=async(B,C)=>{try{const I=B.variants??[];await Y(C,I),n({title:C.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(I){a(j(I))}};return c(Qe,{isLoading:u,header:t(xn,{title:"Variants",actions:t(E,{condition:!o,show:t(O,{children:t(Nt,{initialValue:w,onChange:S})})}),children:t(E,{condition:o,show:t(Nt,{initialValue:w,onChange:S})})}),children:[c(al,{severity:"info",children:["Variants allows you to return a variant object if the feature toggle is considered enabled for the current request. When using variants you should use the ",t("code",{children:"getVariant()"})," method in the Client SDK."]}),$.map(B=>{var I;const C=$.filter(({name:N,variants:V})=>N!==B.name&&(V==null?void 0:V.length));return t(Ki,{environment:B,searchValue:w,children:c(rl,{children:[t(nl,{current:B.name,environments:$,permission:Re,projectId:l,onSubmit:N=>q(B.variants??[],N)}),t(Xi,{environment:B,permission:Re,projectId:l,environmentId:B.name,onCopyVariantsFrom:te,otherEnvsWithVariants:C}),t(E,{condition:Boolean((I=B.variants)==null?void 0:I.length),show:t(ne,{onClick:()=>G(B),permission:Re,projectId:l,environmentId:B.name,children:t(Se,{})}),elseShow:t(ge,{onClick:()=>G(B),variant:"outlined",permission:Re,projectId:l,environmentId:B.name,children:"Add variant"})})]})},B.name)}),t(Oi,{environment:f,open:x,setOpen:A,getApiPayload:M,getCrPayload:D,onConfirm:ee})]})},sl=()=>{At("Variants");const{uiConfig:e}=Te();return e.flags.variantsPerEnvironment?t(ol,{}):t(ai,{})},il=Pe("api/admin/client-metrics/features"),Jn=(e,n)=>{const a=Pe(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:r,error:o}=vt(a,()=>ll(a)),l=m.useCallback(()=>{bt(il).catch(console.warn)},[]);return{featureMetrics:r==null?void 0:r.data,loading:!o&&!r,refetchFeatureMetrics:l,error:o}},ll=e=>fetch(e).then(Ge("Features")).then(n=>n.json()).then(),Fe=48,cl=({hoursBack:e,setHoursBack:n})=>{const a=r=>{n(dl(r))};return t(Ae,{label:"Period",name:"feature-metrics-period",id:"feature-metrics-period",options:ul,value:String(e),onChange:a,fullWidth:!0})},dl=e=>{switch(e){case"1":return 1;case"24":return 24;default:return Fe}},ul=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${Fe}`,label:`Last ${Fe} hours`}],pl=({metrics:e,tableSectionId:n})=>{const a=ue(He.breakpoints.down("md")),r=m.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:o,getTableBodyProps:l,headerGroups:s,rows:i,prepareRow:d,setHiddenColumns:u}=de.useTable({initialState:r,columns:an,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:Z}},de.useGlobalFilter,de.useSortBy);return It([{condition:a,columns:["appName","environment"]}],u,an),e.length===0?null:c(Bn,{...o(),rowHeight:"standard",id:n,children:[t(Rt,{headerGroups:s}),t(kt,{...l(),children:i.map(g=>(d(g),t(Ft,{hover:!0,...g.getRowProps(),children:g.cells.map(h=>t($n,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},an=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(lr,{icon:t(jr,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(cr,{value:e.row.original.timestamp})},{Header:"Application",accessor:"appName"},{Header:"Environment",accessor:"environment"},{id:"requested",Header:"Requested",accessor:e=>e.yes+e.no},{Header:"Exposed",accessor:"yes"}],gl=({metrics:e,...n})=>{const a=m.useMemo(()=>e.reduce((o,l)=>o+l.yes,0),[e]),r=m.useMemo(()=>e.reduce((o,l)=>o+l.no,0),[e]);return t(Hn,{...n,totalYes:a,totalNo:r})},hl=({metrics:e,hoursBack:n})=>{const a=Mt(),r=Mt();return e.length===0?c(Q,{mt:6,children:[t(H,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(H,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):c(m.Suspense,{fallback:null,children:[t(Q,{borderTop:1,pt:2,mt:3,borderColor:He.palette.grey[200],children:t(ml,{metrics:e,hoursBack:n,statsSectionId:a})}),t(Q,{mt:4,children:t(gl,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:r})}),t(Q,{mt:4,children:t(pl,{metrics:e,tableSectionId:r})})]})},ml=dr.lazy(()=>import("./FeatureMetricsChart-d491608e.js")),St=e=>{const{search:n}=window.location,a=xe(),r=m.useMemo(()=>new URLSearchParams(n),[n]),o=m.useCallback(l=>{const s=new URLSearchParams(n);s.set(e,l),a({search:s.toString()},{replace:!0})},[e,n,a]);return[r.get(e)||void 0,o]},yl=e=>{const[n,a]=St(e),r=m.useCallback(o=>a(String(o)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,r]},fl=p("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Sl=p("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),bl=p("li")(({theme:e})=>({"& > [aria-pressed=true]":{backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText}})),rn=({title:e,values:n,value:a,setValue:r})=>{const o=s=>()=>{n.has(s)&&r(s)},l=m.useMemo(()=>Array.from(n).sort((s,i)=>s.localeCompare(i)),[n]);return c("div",{children:[t(fl,{children:e}),t(Sl,{children:l.map(s=>t(bl,{children:t(Be,{label:s,onClick:o(s),"aria-pressed":s===a,sx:ur})},s))})]})},vl=p("div")(({theme:e})=>({[e.breakpoints.down("md")]:{marginTop:e.spacing(2)}})),Cl=()=>{const e=k("projectId"),n=k("featureId"),a=wl(e,n),r=Tl(n);At("Metrics");const[o=Fe,l]=yl("hoursBack"),{featureMetrics:s}=Jn(n,o),[i,d]=m.useState(s);m.useEffect(()=>{s&&d(s)},[s]);const u=Array.from(a)[0],g=Array.from(r)[0],[h=u,b]=St("environment"),[y=g,T]=St("application"),w=m.useMemo(()=>i==null?void 0:i.filter(S=>S.environment===h).filter(S=>S.appName===y),[i,h,y]);return w?c(Qe,{children:[c(U,{container:!0,component:"header",spacing:2,alignItems:"flex-end",children:[t(U,{item:!0,xs:12,md:5,children:t(E,{condition:a.size>0,show:t(rn,{title:"Environments",values:a,value:h,setValue:b})})}),t(U,{item:!0,xs:12,md:5,children:t(E,{condition:r.size>0,show:t(rn,{title:"Applications",values:r,value:y,setValue:T})})}),t(U,{item:!0,xs:12,md:2,children:t(vl,{children:t(cl,{hoursBack:o,setHoursBack:l})})})]}),t(hl,{metrics:w,hoursBack:o})]}):null},wl=(e,n)=>{const{feature:a}=_(e,n),r=a.environments.map(o=>o.name);return new Set(r)},Tl=e=>{const{featureMetrics:n=[]}=Jn(e,Fe),a=n.map(r=>r.appName);return new Set(a)},xl=(e,n)=>{const a=new Set(e),r=new Set(n);return a.size!==r.size?!1:[...a].every(o=>r.has(o))},on=p("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),sn=p(he)(({theme:e})=>({marginBottom:e.spacing(1)})),Al=p(Tt)({padding:0}),El=({projectId:e,open:n,onClose:a,onClick:r,feature:o,changeRequests:l})=>{const s=k("projectId"),{project:i}=Vn(e),d=m.useMemo(()=>xl(o.environments.map(g=>g.name),i.environments),[o,i]),u=l?l.length>0:!1;return t(E,{condition:d&&!u,show:t(ie,{open:n,onClose:a,onClick:r,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:c(on,{children:[t(sn,{severity:"success",children:"This feature toggle is compatible with the new project."}),t("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t(ie,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"OK",children:c(on,{children:[t(sn,{severity:"warning",children:"Incompatible project environments"}),t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."}),t(E,{condition:u,show:c(O,{children:[t("p",{children:"In addition the feature toggle must not have any pending change requests. This feature toggle is currently referenced in the following change requests:"}),t(Al,{children:l==null?void 0:l.map(g=>t(ze,{children:c(se,{to:`/projects/${s}/change-requests/${g.id}`,children:["View change request"," ",g.id]})},g.id))})]})})]})})})},Il=e=>fetch(e).then(Ge("ChangeRequest")).then(n=>n.json()),Rl=(e,n)=>{const{data:a,error:r,mutate:o}=pr([],Pe(`api/admin/projects/${e}/change-requests/pending/${n}`),Il);return{changeRequests:a,loading:!r&&!a,refetch:o,error:r}},kl=()=>{const{hasAccess:e}=m.useContext($e),n=k("projectId"),a=k("featureId"),{feature:r,refetchFeature:o}=_(n,a),[l,s]=m.useState(!1),{changeFeatureProject:i}=ce(),{setToastData:d,setToastApiError:u}=K(),[g,h]=m.useState(n),{projects:b}=gr(),y=xe(),{changeRequests:T}=Rl(n,a),w=async()=>{try{g&&(await i(n,a,g),o(),d({title:"Project changed",type:"success"}),s(!1),y(`/projects/${g}/features/${a}/settings`,{replace:!0}))}catch(f){u(j(f))}},S=m.useMemo(()=>b.map(f=>f.id).filter(f=>e(jt,f)),[b,e]);return S.length===0?null:c(O,{children:[t(hr,{value:g,onChange:h,label:"Project",filter:f=>S.includes(f),enabled:!0}),t(ge,{permission:jt,onClick:()=>s(!0),disabled:g===n,projectId:n,children:"Save"}),t(El,{changeRequests:T,projectId:g,open:l,feature:r,onClose:()=>s(!1),onClick:w})]})},Fl=p("div")({display:"flex",alignItems:"center"}),Pl=p(H)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),Bl=({projectId:e,featureId:n})=>{var l;const{feature:a}=_(e,n),r=xe();return c(O,{children:[c(Fl,{children:[t(Pl,{children:"Feature information"}),t(ne,{permission:fe,projectId:e,"data-loading":!0,onClick:()=>{r(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(Se,{})})]}),c(H,{children:["Name: ",t("strong",{children:a.name})]}),c(H,{children:["Description:"," ",t("strong",{children:(l=a.description)!=null&&l.length?a.description:"no description"})]}),c(H,{children:["Type: ",t("strong",{children:a.type})]}),c(H,{children:["Impression Data:"," ",t("strong",{children:a.impressionData?"enabled":"disabled"})]})]})},je="metadata",pt="project",$l=p("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),Vl=p("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,["& > *"]:{margin:e.spacing(1,0)}})),Dl=()=>{const e=k("projectId"),n=k("featureId"),[a,r]=m.useState(je),{uiConfig:o}=Te();return t(Qe,{header:"Settings",sx:{padding:0},children:c(Q,{sx:{display:"flex"},children:[t($l,{children:c(Tt,{children:[t(ze,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(je),selected:a===je,children:"Metadata"},0),t(ze,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(pt),selected:a===pt,hidden:!o.flags.P,children:"Project"},1)]})}),c(Vl,{children:[t(E,{condition:a===je,show:t(Bl,{projectId:e,featureId:n})}),t(E,{condition:a===pt&&o.flags.P,show:t(kl,{})})]})]})})},Ol=p(Be)(({theme:e})=>({background:"transparent",border:`1px solid ${e.palette.primary.main}`,color:e.palette.primary.main})),Ll=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(Ol,{color:"primary",variant:"outlined",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",label:e?"Stale":"Active"})}),ln=p("strong")({wordBreak:"break-all"}),Nl=()=>{const e=k("projectId"),n=k("featureId"),{archivedFeatures:a}=mr(),r=yr(e,{name:n});return a?a.some(l=>l.name===n)?c("p",{children:["The feature ",t(ln,{children:n})," has been archived. You can find it on the"," ",t(se,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):c("p",{children:["The feature ",t(ln,{children:n})," does not exist. Would you like to"," ",t(se,{to:r,children:"create it"}),"?"]}):null},Ml=p("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),jl=p("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),_l=p("div")({display:"flex",alignItems:"center"}),zl=p("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),Wl=p("div")({flexShrink:0,display:"flex"}),Hl=p("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.tertiary.light,height:"1px"})),Ul=p("div")(({theme:e})=>({padding:e.spacing(0,4)})),ql=p(fr)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),Ql=()=>{const e=k("projectId"),n=k("featureId"),{refetch:a}=Vn(e),{favorite:r,unfavorite:o}=Sr(),{refetchFeature:l}=_(e,n),[s,i]=m.useState(!1),[d,u]=m.useState(!1),[g,h]=m.useState(!1),b=ue(`(max-width:${500}px)`),{feature:y,loading:T,error:w,status:S}=_(e,n),f=xe(),{pathname:v}=br(),x=vr(T),A=`/projects/${e}/features/${n}`,$=[{title:"Overview",path:`${A}`,name:"overview"},{title:"Metrics",path:`${A}/metrics`,name:"Metrics"},{title:"Variants",path:`${A}/variants`,name:"Variants"},{title:"Settings",path:`${A}/settings`,name:"Settings"},{title:"Event log",path:`${A}/logs`,name:"Event log"}],F=$.find(D=>D.path===v)??$[0],M=async()=>{y!=null&&y.favorite?await o(e,y.name):await r(e,y.name),l()};return S===404?t(Nl,{}):w!==void 0?t("div",{ref:x}):c("div",{ref:x,children:[c(Ml,{children:[c(jl,{children:[c(_l,{children:[t(Cr,{onClick:M,isFavorite:y==null?void 0:y.favorite}),c(zl,{"data-loading":!0,children:[y.name," "]}),t(E,{condition:!b,show:t(Ll,{stale:y==null?void 0:y.stale})})]}),c(Wl,{children:[t(ne,{permission:wr,projectId:e,"data-loading":!0,component:se,to:`/projects/${e}/features/${n}/strategies/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(Tr,{})}),t(ne,{permission:xr,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>u(!0),children:t(Mr,{})}),t(ne,{onClick:()=>h(!0),permission:fe,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(zr,{})}),t(ne,{onClick:()=>i(!0),permission:fe,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(dn,{})})]})]}),t(Hl,{}),t(Ul,{children:t(Ar,{value:F.path,indicatorColor:"primary",textColor:"primary",children:$.map(D=>t(ql,{label:D.title,value:D.path,onClick:()=>f(D.path)},D.title))})})]}),c(fn,{children:[t(ye,{path:"metrics",element:t(Cl,{})}),t(ye,{path:"logs",element:t(Hr,{})}),t(ye,{path:"variants",element:t(sl,{})}),t(ye,{path:"settings",element:t(Dl,{})}),t(ye,{path:"*",element:t(Hs,{})})]}),t(kr,{isOpen:d,onConfirm:()=>{a(),f(`/projects/${e}`)},onClose:()=>u(!1),projectId:e,featureId:n}),t(Fr,{isStale:y.stale,isOpen:g,onClose:()=>{h(!1),l()},featureId:n,projectId:e}),t(qn,{open:s,setOpen:i})]})};export{Ql as default};
@@ -1,4 +1,4 @@
1
- import{s as g,r as d,aB as wo,cI as xo,_ as ko,j as e,$ as An,cJ as on,cK as Rt,cL as To,cM as Ao,cN as Eo,cO as Po,c as ze,cP as En,cQ as Ge,cR as $t,aJ as se,a_ as xe,aK as ke,H as q,f as r,A as W,ar as ae,cS as Ft,bN as bt,cT as Do,cU as Ro,a2 as Y,be as Se,m as Re,ct as Io,cV as Uo,aN as de,cW as Pn,F as z,C as x,cX as Lo,b2 as Pe,aP as oe,aX as De,c8 as Dn,l as fe,c9 as pt,N as be,c0 as Be,d as _,e as Ne,U as Ze,ak as Q,al as ne,V as ve,a as O,X as Me,c1 as zt,S as Mt,h as nt,i as je,k as Ht,W as ce,I as Rn,R as ge,ce as Fe,cY as ot,cb as St,cZ as Bo,c_ as He,bK as We,bJ as In,a9 as M,aj as Un,ae as No,bI as Ln,a5 as Ye,c$ as ft,bY as ie,d0 as tt,T as R,d1 as Oo,d2 as $o,bU as Wt,d3 as Bn,bP as Nn,au as Te,aw as _t,d4 as j,d5 as qt,a4 as V,ay as Ce,bs as b,d6 as we,a6 as Go,a7 as jo,a8 as Ve,ac as Z,Z as _e,aI as vt,d7 as Fo,af as Vt,d8 as On,a1 as zo,d9 as Mo,da as st,B as Gt,db as Ho,g as $n,dc as Wo,dd as Yt,bF as Gn,de as _o,df as jn,c2 as re,bG as Fn,dg as qo,cg as an,dh as Jt,aH as Vo,ad as Yo,di as Jo,dj as It,cd as zn,dk as Ko,dl as Zo,dm as qe,Y as at,w as Xo,dn as Qo,dp as ea,bE as ta,dq as na,dr as oa,ds as aa,aE as Ct,dt as Kt,du as Mn,ah as Hn,bS as Wn,K as ra,u as Zt,dv as ia,L as _n,Q as Xt,aW as Ee,dw as sa,aY as rt,dx as la,dy as ca,P as qn,dz as da,bi as Ut,bk as Lt,dA as ua,dB as ha,bO as Qt,dC as pa,cq as Vn,cv as Yn,co as he,bQ as Jn,bR as J,x as ma,bv as ga,bw as fa,bx as ya,c6 as ba,dD as Sa,b$ as Bt,dE as Kn,dF as yt,dG as Zn,dH as va,dI as Xn,dJ as Ca,O as wa,ca as xa,dK as ka,dL as Ta,dM as Aa,dN as Ea,dO as Pa,dP as Da,b3 as Ra,bV as Ia,dQ as Ua,dR as La,bL as Ba,dS as rn,M as Qn,bj as Na,bH as Nt,dT as Oa}from"./index-c290f941.js";import{m as $a,u as wt,B as Ga,a as sn}from"./useProjectRole-b5b140d2.js";import{E as ja}from"./ExpandMore-c3e13d73.js";import{a as Fa}from"./index-3132dba8.js";import{a as za}from"./index-66dec49c.js";const Ma=["component","direction","spacing","divider","children"];function Ha(t,n){const o=d.Children.toArray(t).filter(Boolean);return o.reduce((a,i,s)=>(a.push(i),s<o.length-1&&a.push(d.cloneElement(n,{key:`separator-${s}`})),a),[])}const Wa=t=>({row:"Left","row-reverse":"Right",column:"Top","column-reverse":"Bottom"})[t],_a=({ownerState:t,theme:n})=>{let o=An({display:"flex",flexDirection:"column"},on({theme:n},Rt({values:t.direction,breakpoints:n.breakpoints.values}),a=>({flexDirection:a})));if(t.spacing){const a=To(n),i=Object.keys(n.breakpoints.values).reduce((l,c)=>((typeof t.spacing=="object"&&t.spacing[c]!=null||typeof t.direction=="object"&&t.direction[c]!=null)&&(l[c]=!0),l),{}),s=Rt({values:t.direction,base:i}),u=Rt({values:t.spacing,base:i});typeof s=="object"&&Object.keys(s).forEach((l,c,p)=>{if(!s[l]){const y=c>0?s[p[c-1]]:"column";s[l]=y}}),o=Ao(o,on({theme:n},u,(l,c)=>({"& > :not(style) + :not(style)":{margin:0,[`margin${Wa(c?s[c]:t.direction)}`]:Po(a,l)}})))}return o=Eo(n.breakpoints,o),o},qa=g("div",{name:"MuiStack",slot:"Root",overridesResolver:(t,n)=>[n.root]})(_a),Va=d.forwardRef(function(n,o){const a=wo({props:n,name:"MuiStack"}),i=xo(a),{component:s="div",direction:u="column",spacing:h=0,divider:l,children:c}=i,p=ko(i,Ma);return e(qa,An({as:s,ownerState:{direction:u,spacing:h},ref:o},p,{children:l?Ha(c,l):c}))}),Ya=Va,Ja=ze(e("path",{d:"M5 20h14v-2H5v2zM19 9h-4V3H9v6H5l7 7 7-7z"}),"Download"),Ka=ze(e("path",{d:"M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5s-3 1.34-3 3 1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V18c0 .55.45 1 1 1h12c.55 0 1-.45 1-1v-1.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05.02.01.03.03.04.04 1.14.83 1.93 1.94 1.93 3.41V18c0 .35-.07.69-.18 1H22c.55 0 1-.45 1-1v-1.5c0-2.33-4.67-3.5-7-3.5z"}),"GroupRounded"),Za=ze(e("path",{d:"M21 10h-8.35C11.83 7.67 9.61 6 7 6c-3.31 0-6 2.69-6 6s2.69 6 6 6c2.61 0 4.83-1.67 5.65-4H13l2 2 2-2 2 2 4-4.04L21 10zM7 15c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z"}),"Key"),Xa=ze(e("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1.41 16.09V20h-2.67v-1.93c-1.71-.36-3.16-1.46-3.27-3.4h1.96c.1 1.05.82 1.87 2.65 1.87 1.96 0 2.4-.98 2.4-1.59 0-.83-.44-1.61-2.67-2.14-2.48-.6-4.18-1.62-4.18-3.67 0-1.72 1.39-2.84 3.11-3.21V4h2.67v1.95c1.86.45 2.79 1.86 2.85 3.39H14.3c-.05-1.11-.64-1.87-2.22-1.87-1.5 0-2.4.68-2.4 1.64 0 .84.65 1.39 2.67 1.91s4.18 1.39 4.18 3.91c-.01 1.83-1.38 2.83-3.12 3.16z"}),"MonetizationOn"),Qa=ze(e("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"}),"MoreVert"),er=ze(e("path",{d:"M11.99 2c-5.52 0-10 4.48-10 10s4.48 10 10 10 10-4.48 10-10-4.48-10-10-10zm3.61 6.34c1.07 0 1.93.86 1.93 1.93 0 1.07-.86 1.93-1.93 1.93-1.07 0-1.93-.86-1.93-1.93-.01-1.07.86-1.93 1.93-1.93zm-6-1.58c1.3 0 2.36 1.06 2.36 2.36 0 1.3-1.06 2.36-2.36 2.36s-2.36-1.06-2.36-2.36c0-1.31 1.05-2.36 2.36-2.36zm0 9.13v3.75c-2.4-.75-4.3-2.6-5.14-4.96 1.05-1.12 3.67-1.69 5.14-1.69.53 0 1.2.08 1.9.22-1.64.87-1.9 2.02-1.9 2.68zM11.99 20c-.27 0-.53-.01-.79-.04v-4.07c0-1.42 2.94-2.13 4.4-2.13 1.07 0 2.92.39 3.84 1.15-1.17 2.97-4.06 5.09-7.45 5.09z"}),"SupervisedUserCircle"),tr=ze(e("path",{d:"M20 6h-8l-2-2H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm-6 10H6v-2h8v2zm4-4H6v-2h12v2z"}),"Topic");function mt(t){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?mt=function(o){return typeof o}:mt=function(o){return o&&typeof Symbol=="function"&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},mt(t)}function gt(t,n){if(En(2,arguments),!n||mt(n)!=="object")return new Date(NaN);var o=n.years?Ge(n.years):0,a=n.months?Ge(n.months):0,i=n.weeks?Ge(n.weeks):0,s=n.days?Ge(n.days):0,u=n.hours?Ge(n.hours):0,h=n.minutes?Ge(n.minutes):0,l=n.seconds?Ge(n.seconds):0,c=$t(t),p=a||o?za(c,a+o*12):c,m=s||i?Fa(p,s+i*7):p,y=h+u*60,S=l+y*60,f=S*1e3,C=new Date(m.getTime()+f);return C}function ln(t,n){En(2,arguments);var o=$t(t),a=$t(n);return o.getTime()>a.getTime()}const eo=(t={})=>{const n=se("api/admin/api-tokens"),{data:o,error:a,mutate:i}=xe(n,nr,t),s=d.useMemo(()=>o??[],[o]),u=d.useCallback(()=>{i().catch(console.warn)},[i]);return{tokens:s,error:a,loading:!a&&!o,refetch:u}},nr=async t=>(await(await fetch(t).then(ke("Api tokens"))).json()).tokens,or=()=>{const{uiConfig:t}=q();return r(W,{severity:"info",children:[r("p",{children:["Read the"," ",e("a",{href:"https://docs.getunleash.io/reference/sdks",target:"_blank",rel:"noreferrer",children:"SDK overview"})," ","to connect Unleash to your application. Please note it can take up to ",e("strong",{children:"1 minute"})," before a new API key is activated."]}),e("br",{}),e("strong",{children:"API URL: "})," ",r("pre",{style:{display:"inline"},children:[t.unleashUrl,"/api/"]})]})},ar=()=>{const t=ae();return e(Ft,{Icon:bt,onClick:()=>t("/admin/api/create-token"),"data-testid":Do,permission:Ro,maxWidth:"700px",children:"New API token"})},rr=({token:t})=>{const{setToastData:n}=Y(),o=a=>{Uo(a)&&n({type:"success",title:"Token copied to clipboard"})};return e(Se,{title:"Copy token",arrow:!0,children:e(Re,{onClick:()=>o(t.secret),size:"large",children:e(Io,{})})})},ir=g("ul")({marginBottom:0}),sr=({token:t})=>{const{hasAccess:n}=d.useContext(de),{deleteToken:o}=Pn(),[a,i]=d.useState(!1),{setToastData:s}=Y(),{refetch:u}=eo(),h=async()=>{await o(t.secret),i(!1),u(),s({type:"success",title:"API token removed"})};return r(z,{children:[e(x,{condition:n(Lo),show:e(Se,{title:"Delete token",arrow:!0,children:e(Re,{onClick:()=>i(!0),size:"large",children:e(Pe,{})})})}),e(oe,{open:a,onClick:h,onClose:()=>i(!1),title:"Confirm deletion",children:r("div",{children:["Are you sure you want to delete the following API token?",e("br",{}),r(ir,{children:[r("li",{children:[e("strong",{children:"username"}),":"," ",e("code",{children:t.username})]}),r("li",{children:[e("strong",{children:"type"}),": ",e("code",{children:t.type})]})]})]})})]})},lr=g(De)(()=>({textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),cr=({projects:t,project:n})=>{const{searchQuery:o}=Dn();let a=t&&Array.isArray(t)?t:n?[n]:[];return a.length===0?e(fe,{children:e(pt,{search:o,children:"*"})}):e(fe,{children:a.map((i,s)=>r(d.Fragment,{children:[s>0&&", ",!i||i==="*"?e(pt,{search:o,children:"*"}):e(lr,{to:`/projects/${i}`,children:e(pt,{search:o,children:i})})]},i))})},dr=["Icon","createdAt"],ur=()=>{const{tokens:t,loading:n}=eo(),o=d.useMemo(()=>({sortBy:[{id:"createdAt"}]}),[]);q();const a=be(Be.breakpoints.down("md")),{getTableProps:i,getTableBodyProps:s,headerGroups:u,rows:h,prepareRow:l,state:{globalFilter:c},setGlobalFilter:p,setHiddenColumns:m}=_.useTable({columns:dn,data:t,initialState:o,sortTypes:Ne,autoResetHiddenColumns:!1,disableSortRemove:!0},_.useGlobalFilter,_.useSortBy);return Ze([{condition:a,columns:dr}],m,dn),r(Q,{header:e(ne,{title:`API access (${h.length})`,actions:r(z,{children:[e(ve,{initialValue:c,onChange:p}),e(ne.Divider,{}),e(ar,{})]})}),children:[e(x,{condition:h.length>0,show:e(O,{sx:{mb:4},children:e(or,{})})}),e(O,{sx:{overflowX:"auto"},children:e(Me,{value:c,children:r(zt,{...i(),children:[e(Mt,{headerGroups:u}),e(nt,{...s(),children:h.map(y=>(l(y),e(je,{hover:!0,...y.getRowProps(),children:y.cells.map(S=>e(Ht,{...S.getCellProps(),children:S.render("Cell")}))})))})]})})}),e(x,{condition:h.length===0&&!n,show:e(x,{condition:(c==null?void 0:c.length)>0,show:r(ce,{children:["No tokens found matching “",c,"”"]}),elseShow:e(ce,{children:r("span",{children:["No tokens available. Read ",e("a",{href:"https://docs.getunleash.io/how-to/api",target:"_blank",rel:"noreferrer",children:"API How-to guides"})," "," to learn more."]})})})})]})},cn={client:{label:"CLIENT",title:"Connect server-side SDK or Unleash Proxy"},frontend:{label:"FRONTEND",title:"Connect web and mobile SDK"},admin:{label:"ADMIN",title:"Full access for managing Unleash"}},dn=[{id:"Icon",width:"1%",Cell:()=>e(Rn,{icon:e(Za,{color:"disabled"})}),disableSortBy:!0,disableGlobalFilter:!0},{Header:"Username",accessor:"username",Cell:ge},{Header:"Type",accessor:"type",Cell:({value:t})=>e(ge,{value:cn[t].label,subtitle:cn[t].title}),minWidth:280},{Header:"Project",accessor:"project",Cell:t=>e(cr,{project:t.row.original.project,projects:t.row.original.projects}),minWidth:120},{Header:"Environment",accessor:"environment",Cell:ge,minWidth:120},{Header:"Created",accessor:"createdAt",Cell:Fe,minWidth:150,disableGlobalFilter:!0},{Header:"Last seen",accessor:"seenAt",Cell:ot,minWidth:150,disableGlobalFilter:!0},{Header:"Actions",id:"Actions",align:"center",width:"1%",disableSortBy:!0,disableGlobalFilter:!0,Cell:t=>r(St,{children:[e(rr,{token:t.row.original}),e(sr,{token:t.row.original})]})}],hr=()=>{const{hasAccess:t}=d.useContext(de);return e(x,{condition:t(Bo),show:()=>e(ur,{}),elseShow:()=>e(He,{})})},pr=()=>e("div",{children:e(hr,{})});var me=(t=>(t.ADMIN="ADMIN",t.CLIENT="CLIENT",t.FRONTEND="FRONTEND",t))(me||{});const mr=g("div")(()=>({maxWidth:"400px"})),gr=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),fr=g(We)(({theme:t})=>({width:"100%",marginBottom:t.spacing(2)})),yr=g(In)(({theme:t})=>({marginBottom:t.spacing(2),minWidth:"400px",[t.breakpoints.down("sm")]:{minWidth:"379px"}})),Ot=g("p")(({theme:t})=>({marginBottom:t.spacing(1)})),br=g("label")(({theme:t})=>({marginBottom:t.spacing(1)})),Sr=g(M)(({theme:t})=>({marginLeft:t.spacing(3)})),vr=g(O)({marginTop:"auto",display:"flex",justifyContent:"flex-end"}),Cr=({children:t,username:n,type:o,projects:a,environment:i,setUsername:s,setTokenType:u,setProjects:h,setEnvironment:l,handleSubmit:c,handleCancel:p,errors:m,clearErrors:y})=>{var B;const{uiConfig:S}=q(),{environments:f}=Un(),{projects:C}=No(),k=[{key:me.CLIENT,label:`Server-side SDK (${me.CLIENT})`,title:"Connect server-side SDK or Unleash Proxy"},{key:me.ADMIN,label:me.ADMIN,title:"Full access for managing Unleash"}];S.flags.embedProxyFrontend&&k.splice(1,0,{key:me.FRONTEND,label:`Client-side SDK (${me.FRONTEND})`,title:"Connect web and mobile SDK directly to Unleash"});const v=C.map(w=>({value:w.id,label:w.name})),T=o===me.ADMIN?[{key:"*",label:"ALL"}]:f.map(w=>({key:w.name,label:w.name,title:w.name,disabled:!w.enabled})),A=Boolean((B=S==null?void 0:S.flags)==null?void 0:B.UNLEASH_CLOUD);return r(gr,{onSubmit:c,children:[e(x,{condition:A,show:r(W,{severity:"info",sx:{mb:4},children:["Please be aware of our"," ",e(Ln,{href:"https://www.getunleash.io/fair-use-policy",children:"fair use policy"}),"."]})}),r(mr,{children:[e(Ot,{children:"What would you like to call this token?"}),e(fr,{value:n,name:"username",onChange:w=>s(w.target.value),label:"Token name",error:m.username!==void 0,errorText:m.username,onFocus:()=>y("username"),autoFocus:!0}),r(Ye,{sx:{mb:2,width:"100%"},children:[e(br,{id:"token-type",children:"What do you want to connect?"}),e(ft,{"aria-labelledby":"token-type",defaultValue:"CLIENT",name:"radio-buttons-group",value:o,onChange:(w,P)=>u(P),children:k.map(({key:w,label:P,title:L})=>e(ie,{value:w,sx:{mb:1},control:e(tt,{sx:{ml:.75,alignSelf:"flex-start"}}),label:e(O,{children:r(O,{children:[e(R,{children:P}),e(R,{variant:"body2",color:"text.secondary",children:L})]})})},w))})]}),e(Ot,{children:"Which project do you want to give access to?"}),e(Oo,{disabled:o===me.ADMIN,options:v,defaultValue:a,onChange:h,error:m==null?void 0:m.projects,onFocus:()=>y("projects")}),e(Ot,{children:"Which environment should the token have access to?"}),e(yr,{disabled:o===me.ADMIN,options:T,value:i,onChange:l,label:"Environment",id:"api_key_environment",name:"environment",IconComponent:$o,fullWidth:!0})]}),r(vr,{children:[t,e(Sr,{onClick:p,children:"Cancel"})]})]})},wr=()=>{var T;const{environments:t}=Un(),n=(T=t==null?void 0:t.find(A=>A.enabled))==null?void 0:T.name,[o,a]=d.useState(""),[i,s]=d.useState("CLIENT"),[u,h]=d.useState(["*"]),[l,c]=d.useState(u),[p,m]=d.useState(),[y,S]=d.useState({});return d.useEffect(()=>{m(i==="ADMIN"?"*":n)},[i,n]),{username:o,type:i,projects:u,environment:p,setUsername:a,setTokenType:A=>{A==="ADMIN"?(s(A),c(u),h(["*"]),m("*")):(s(A),h(l),m(n))},setProjects:h,setEnvironment:m,getApiTokenPayload:()=>({username:o,type:i,environment:p,projects:u}),isValid:()=>{const A={};return o||(A.username="Username is required"),u.length===0&&(A.projects="At least one project is required"),S(A),Object.keys(A).length===0},clearErrors:A=>{if(A){const B={...y};delete B[A],S(B)}else S({})},errors:y}},xr=({open:t,closeConfirm:n,token:o,type:a})=>(Wt(),r(oe,{open:t,onClick:n,primaryButtonText:"Close",title:"New token created",children:[e(R,{variant:"body1",children:"Your new token has been created successfully."}),e(Bn,{token:o}),e(x,{condition:a===me.FRONTEND,show:r(W,{sx:{mt:2},severity:"info",children:["By default, all ",me.FRONTEND," tokens may be used from any CORS origin. If you'd like to configure a strict set of origins, please use the"," ",e(De,{to:"/admin/cors",target:"_blank",children:"CORS origins configuration page"}),"."]})})]})),un="Create API token",kr=()=>{const{setToastApiError:t}=Y(),{uiConfig:n}=q(),o=ae(),[a,i]=d.useState(!1),[s,u]=d.useState(""),{getApiTokenPayload:h,username:l,type:c,projects:p,environment:m,setUsername:y,setTokenType:S,setProjects:f,setEnvironment:C,isValid:k,errors:v,clearErrors:T}=wr(),{createToken:A,loading:B}=Pn();return Nn(un),r(Te,{loading:B,title:un,description:"Unleash SDKs use API tokens to authenticate to the Unleash API. Client SDKs need a token with 'client privileges', which allows them to fetch feature toggle configurations and post usage metrics.",documentationLink:"https://docs.getunleash.io/reference/api-tokens-and-client-keys",documentationLinkLabel:"API tokens documentation",formatApiCode:()=>`curl --location --request POST '${n.unleashUrl}/api/admin/api-tokens' \\
1
+ import{s as g,r as d,aB as wo,cK as xo,_ as ko,j as e,$ as An,cL as on,cM as Rt,cN as To,cO as Ao,cP as Eo,cQ as Po,c as ze,cR as En,cS as Ge,cT as $t,aJ as se,a_ as xe,aK as ke,H as q,f as r,A as W,ar as ae,cU as Ft,bN as bt,cV as Do,cW as Ro,a2 as Y,be as Se,m as Re,cv as Io,cX as Uo,aN as de,cY as Pn,F as z,C as x,cZ as Lo,b2 as Pe,aP as oe,aX as De,cb as Dn,l as fe,cc as pt,N as be,c0 as Be,d as _,e as Ne,U as Ze,ak as Q,al as ne,V as ve,a as O,X as Me,c1 as zt,S as Mt,h as nt,i as je,k as Ht,W as ce,I as Rn,R as ge,cg as Fe,c_ as ot,c$ as St,d0 as Bo,d1 as He,bK as We,bJ as In,a9 as M,aj as Un,ae as No,bI as Ln,a5 as Ye,d2 as ft,bY as ie,d3 as tt,T as R,d4 as Oo,d5 as $o,bU as Wt,d6 as Bn,bP as Nn,au as Te,aw as _t,d7 as j,d8 as qt,a4 as V,ay as Ce,bs as b,c6 as we,a6 as Go,a7 as jo,a8 as Ve,ac as Z,Z as _e,aI as vt,d9 as Fo,af as Vt,da as On,a1 as zo,db as Mo,dc as st,B as Gt,dd as Ho,g as $n,de as Wo,df as Yt,bF as Gn,dg as _o,dh as jn,c2 as re,bG as Fn,di as qo,ci as an,dj as Jt,aH as Vo,ad as Yo,dk as Jo,dl as It,cf as zn,dm as Ko,dn as Zo,dp as qe,Y as at,w as Xo,dq as Qo,dr as ea,bE as ta,ds as na,dt as oa,du as aa,aE as Ct,dv as Kt,dw as Mn,ah as Hn,bS as Wn,K as ra,u as Zt,dx as ia,L as _n,Q as Xt,aW as Ee,dy as sa,aY as rt,dz as la,dA as ca,P as qn,dB as da,bi as Ut,bk as Lt,dC as ua,dD as ha,bO as Qt,dE as pa,cs as Vn,cx as Yn,cq as he,bQ as Jn,bR as J,x as ma,bv as ga,bw as fa,bx as ya,c7 as ba,dF as Sa,b$ as Bt,dG as Kn,dH as yt,dI as Zn,dJ as va,dK as Xn,dL as Ca,O as wa,cd as xa,dM as ka,dN as Ta,dO as Aa,dP as Ea,dQ as Pa,dR as Da,b3 as Ra,bV as Ia,dS as Ua,dT as La,bL as Ba,dU as rn,M as Qn,bj as Na,bH as Nt,dV as Oa}from"./index-54a8dd7a.js";import{m as $a,u as wt,B as Ga,a as sn}from"./useProjectRole-f229b4e4.js";import{E as ja}from"./ExpandMore-46f830cb.js";import{a as Fa}from"./index-a4c3dd25.js";import{a as za}from"./index-b275e721.js";const Ma=["component","direction","spacing","divider","children"];function Ha(t,n){const o=d.Children.toArray(t).filter(Boolean);return o.reduce((a,i,s)=>(a.push(i),s<o.length-1&&a.push(d.cloneElement(n,{key:`separator-${s}`})),a),[])}const Wa=t=>({row:"Left","row-reverse":"Right",column:"Top","column-reverse":"Bottom"})[t],_a=({ownerState:t,theme:n})=>{let o=An({display:"flex",flexDirection:"column"},on({theme:n},Rt({values:t.direction,breakpoints:n.breakpoints.values}),a=>({flexDirection:a})));if(t.spacing){const a=To(n),i=Object.keys(n.breakpoints.values).reduce((l,c)=>((typeof t.spacing=="object"&&t.spacing[c]!=null||typeof t.direction=="object"&&t.direction[c]!=null)&&(l[c]=!0),l),{}),s=Rt({values:t.direction,base:i}),u=Rt({values:t.spacing,base:i});typeof s=="object"&&Object.keys(s).forEach((l,c,p)=>{if(!s[l]){const y=c>0?s[p[c-1]]:"column";s[l]=y}}),o=Ao(o,on({theme:n},u,(l,c)=>({"& > :not(style) + :not(style)":{margin:0,[`margin${Wa(c?s[c]:t.direction)}`]:Po(a,l)}})))}return o=Eo(n.breakpoints,o),o},qa=g("div",{name:"MuiStack",slot:"Root",overridesResolver:(t,n)=>[n.root]})(_a),Va=d.forwardRef(function(n,o){const a=wo({props:n,name:"MuiStack"}),i=xo(a),{component:s="div",direction:u="column",spacing:h=0,divider:l,children:c}=i,p=ko(i,Ma);return e(qa,An({as:s,ownerState:{direction:u,spacing:h},ref:o},p,{children:l?Ha(c,l):c}))}),Ya=Va,Ja=ze(e("path",{d:"M5 20h14v-2H5v2zM19 9h-4V3H9v6H5l7 7 7-7z"}),"Download"),Ka=ze(e("path",{d:"M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5s-3 1.34-3 3 1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V18c0 .55.45 1 1 1h12c.55 0 1-.45 1-1v-1.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05.02.01.03.03.04.04 1.14.83 1.93 1.94 1.93 3.41V18c0 .35-.07.69-.18 1H22c.55 0 1-.45 1-1v-1.5c0-2.33-4.67-3.5-7-3.5z"}),"GroupRounded"),Za=ze(e("path",{d:"M21 10h-8.35C11.83 7.67 9.61 6 7 6c-3.31 0-6 2.69-6 6s2.69 6 6 6c2.61 0 4.83-1.67 5.65-4H13l2 2 2-2 2 2 4-4.04L21 10zM7 15c-1.65 0-3-1.35-3-3s1.35-3 3-3 3 1.35 3 3-1.35 3-3 3z"}),"Key"),Xa=ze(e("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1.41 16.09V20h-2.67v-1.93c-1.71-.36-3.16-1.46-3.27-3.4h1.96c.1 1.05.82 1.87 2.65 1.87 1.96 0 2.4-.98 2.4-1.59 0-.83-.44-1.61-2.67-2.14-2.48-.6-4.18-1.62-4.18-3.67 0-1.72 1.39-2.84 3.11-3.21V4h2.67v1.95c1.86.45 2.79 1.86 2.85 3.39H14.3c-.05-1.11-.64-1.87-2.22-1.87-1.5 0-2.4.68-2.4 1.64 0 .84.65 1.39 2.67 1.91s4.18 1.39 4.18 3.91c-.01 1.83-1.38 2.83-3.12 3.16z"}),"MonetizationOn"),Qa=ze(e("path",{d:"M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z"}),"MoreVert"),er=ze(e("path",{d:"M11.99 2c-5.52 0-10 4.48-10 10s4.48 10 10 10 10-4.48 10-10-4.48-10-10-10zm3.61 6.34c1.07 0 1.93.86 1.93 1.93 0 1.07-.86 1.93-1.93 1.93-1.07 0-1.93-.86-1.93-1.93-.01-1.07.86-1.93 1.93-1.93zm-6-1.58c1.3 0 2.36 1.06 2.36 2.36 0 1.3-1.06 2.36-2.36 2.36s-2.36-1.06-2.36-2.36c0-1.31 1.05-2.36 2.36-2.36zm0 9.13v3.75c-2.4-.75-4.3-2.6-5.14-4.96 1.05-1.12 3.67-1.69 5.14-1.69.53 0 1.2.08 1.9.22-1.64.87-1.9 2.02-1.9 2.68zM11.99 20c-.27 0-.53-.01-.79-.04v-4.07c0-1.42 2.94-2.13 4.4-2.13 1.07 0 2.92.39 3.84 1.15-1.17 2.97-4.06 5.09-7.45 5.09z"}),"SupervisedUserCircle"),tr=ze(e("path",{d:"M20 6h-8l-2-2H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm-6 10H6v-2h8v2zm4-4H6v-2h12v2z"}),"Topic");function mt(t){return typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?mt=function(o){return typeof o}:mt=function(o){return o&&typeof Symbol=="function"&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},mt(t)}function gt(t,n){if(En(2,arguments),!n||mt(n)!=="object")return new Date(NaN);var o=n.years?Ge(n.years):0,a=n.months?Ge(n.months):0,i=n.weeks?Ge(n.weeks):0,s=n.days?Ge(n.days):0,u=n.hours?Ge(n.hours):0,h=n.minutes?Ge(n.minutes):0,l=n.seconds?Ge(n.seconds):0,c=$t(t),p=a||o?za(c,a+o*12):c,m=s||i?Fa(p,s+i*7):p,y=h+u*60,S=l+y*60,f=S*1e3,C=new Date(m.getTime()+f);return C}function ln(t,n){En(2,arguments);var o=$t(t),a=$t(n);return o.getTime()>a.getTime()}const eo=(t={})=>{const n=se("api/admin/api-tokens"),{data:o,error:a,mutate:i}=xe(n,nr,t),s=d.useMemo(()=>o??[],[o]),u=d.useCallback(()=>{i().catch(console.warn)},[i]);return{tokens:s,error:a,loading:!a&&!o,refetch:u}},nr=async t=>(await(await fetch(t).then(ke("Api tokens"))).json()).tokens,or=()=>{const{uiConfig:t}=q();return r(W,{severity:"info",children:[r("p",{children:["Read the"," ",e("a",{href:"https://docs.getunleash.io/reference/sdks",target:"_blank",rel:"noreferrer",children:"SDK overview"})," ","to connect Unleash to your application. Please note it can take up to ",e("strong",{children:"1 minute"})," before a new API key is activated."]}),e("br",{}),e("strong",{children:"API URL: "})," ",r("pre",{style:{display:"inline"},children:[t.unleashUrl,"/api/"]})]})},ar=()=>{const t=ae();return e(Ft,{Icon:bt,onClick:()=>t("/admin/api/create-token"),"data-testid":Do,permission:Ro,maxWidth:"700px",children:"New API token"})},rr=({token:t})=>{const{setToastData:n}=Y(),o=a=>{Uo(a)&&n({type:"success",title:"Token copied to clipboard"})};return e(Se,{title:"Copy token",arrow:!0,children:e(Re,{onClick:()=>o(t.secret),size:"large",children:e(Io,{})})})},ir=g("ul")({marginBottom:0}),sr=({token:t})=>{const{hasAccess:n}=d.useContext(de),{deleteToken:o}=Pn(),[a,i]=d.useState(!1),{setToastData:s}=Y(),{refetch:u}=eo(),h=async()=>{await o(t.secret),i(!1),u(),s({type:"success",title:"API token removed"})};return r(z,{children:[e(x,{condition:n(Lo),show:e(Se,{title:"Delete token",arrow:!0,children:e(Re,{onClick:()=>i(!0),size:"large",children:e(Pe,{})})})}),e(oe,{open:a,onClick:h,onClose:()=>i(!1),title:"Confirm deletion",children:r("div",{children:["Are you sure you want to delete the following API token?",e("br",{}),r(ir,{children:[r("li",{children:[e("strong",{children:"username"}),":"," ",e("code",{children:t.username})]}),r("li",{children:[e("strong",{children:"type"}),": ",e("code",{children:t.type})]})]})]})})]})},lr=g(De)(()=>({textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),cr=({projects:t,project:n})=>{const{searchQuery:o}=Dn();let a=t&&Array.isArray(t)?t:n?[n]:[];return a.length===0?e(fe,{children:e(pt,{search:o,children:"*"})}):e(fe,{children:a.map((i,s)=>r(d.Fragment,{children:[s>0&&", ",!i||i==="*"?e(pt,{search:o,children:"*"}):e(lr,{to:`/projects/${i}`,children:e(pt,{search:o,children:i})})]},i))})},dr=["Icon","createdAt"],ur=()=>{const{tokens:t,loading:n}=eo(),o=d.useMemo(()=>({sortBy:[{id:"createdAt"}]}),[]);q();const a=be(Be.breakpoints.down("md")),{getTableProps:i,getTableBodyProps:s,headerGroups:u,rows:h,prepareRow:l,state:{globalFilter:c},setGlobalFilter:p,setHiddenColumns:m}=_.useTable({columns:dn,data:t,initialState:o,sortTypes:Ne,autoResetHiddenColumns:!1,disableSortRemove:!0},_.useGlobalFilter,_.useSortBy);return Ze([{condition:a,columns:dr}],m,dn),r(Q,{header:e(ne,{title:`API access (${h.length})`,actions:r(z,{children:[e(ve,{initialValue:c,onChange:p}),e(ne.Divider,{}),e(ar,{})]})}),children:[e(x,{condition:h.length>0,show:e(O,{sx:{mb:4},children:e(or,{})})}),e(O,{sx:{overflowX:"auto"},children:e(Me,{value:c,children:r(zt,{...i(),children:[e(Mt,{headerGroups:u}),e(nt,{...s(),children:h.map(y=>(l(y),e(je,{hover:!0,...y.getRowProps(),children:y.cells.map(S=>e(Ht,{...S.getCellProps(),children:S.render("Cell")}))})))})]})})}),e(x,{condition:h.length===0&&!n,show:e(x,{condition:(c==null?void 0:c.length)>0,show:r(ce,{children:["No tokens found matching “",c,"”"]}),elseShow:e(ce,{children:r("span",{children:["No tokens available. Read ",e("a",{href:"https://docs.getunleash.io/how-to/api",target:"_blank",rel:"noreferrer",children:"API How-to guides"})," "," to learn more."]})})})})]})},cn={client:{label:"CLIENT",title:"Connect server-side SDK or Unleash Proxy"},frontend:{label:"FRONTEND",title:"Connect web and mobile SDK"},admin:{label:"ADMIN",title:"Full access for managing Unleash"}},dn=[{id:"Icon",width:"1%",Cell:()=>e(Rn,{icon:e(Za,{color:"disabled"})}),disableSortBy:!0,disableGlobalFilter:!0},{Header:"Username",accessor:"username",Cell:ge},{Header:"Type",accessor:"type",Cell:({value:t})=>e(ge,{value:cn[t].label,subtitle:cn[t].title}),minWidth:280},{Header:"Project",accessor:"project",Cell:t=>e(cr,{project:t.row.original.project,projects:t.row.original.projects}),minWidth:120},{Header:"Environment",accessor:"environment",Cell:ge,minWidth:120},{Header:"Created",accessor:"createdAt",Cell:Fe,minWidth:150,disableGlobalFilter:!0},{Header:"Last seen",accessor:"seenAt",Cell:ot,minWidth:150,disableGlobalFilter:!0},{Header:"Actions",id:"Actions",align:"center",width:"1%",disableSortBy:!0,disableGlobalFilter:!0,Cell:t=>r(St,{children:[e(rr,{token:t.row.original}),e(sr,{token:t.row.original})]})}],hr=()=>{const{hasAccess:t}=d.useContext(de);return e(x,{condition:t(Bo),show:()=>e(ur,{}),elseShow:()=>e(He,{})})},pr=()=>e("div",{children:e(hr,{})});var me=(t=>(t.ADMIN="ADMIN",t.CLIENT="CLIENT",t.FRONTEND="FRONTEND",t))(me||{});const mr=g("div")(()=>({maxWidth:"400px"})),gr=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),fr=g(We)(({theme:t})=>({width:"100%",marginBottom:t.spacing(2)})),yr=g(In)(({theme:t})=>({marginBottom:t.spacing(2),minWidth:"400px",[t.breakpoints.down("sm")]:{minWidth:"379px"}})),Ot=g("p")(({theme:t})=>({marginBottom:t.spacing(1)})),br=g("label")(({theme:t})=>({marginBottom:t.spacing(1)})),Sr=g(M)(({theme:t})=>({marginLeft:t.spacing(3)})),vr=g(O)({marginTop:"auto",display:"flex",justifyContent:"flex-end"}),Cr=({children:t,username:n,type:o,projects:a,environment:i,setUsername:s,setTokenType:u,setProjects:h,setEnvironment:l,handleSubmit:c,handleCancel:p,errors:m,clearErrors:y})=>{var B;const{uiConfig:S}=q(),{environments:f}=Un(),{projects:C}=No(),k=[{key:me.CLIENT,label:`Server-side SDK (${me.CLIENT})`,title:"Connect server-side SDK or Unleash Proxy"},{key:me.ADMIN,label:me.ADMIN,title:"Full access for managing Unleash"}];S.flags.embedProxyFrontend&&k.splice(1,0,{key:me.FRONTEND,label:`Client-side SDK (${me.FRONTEND})`,title:"Connect web and mobile SDK directly to Unleash"});const v=C.map(w=>({value:w.id,label:w.name})),T=o===me.ADMIN?[{key:"*",label:"ALL"}]:f.map(w=>({key:w.name,label:w.name,title:w.name,disabled:!w.enabled})),A=Boolean((B=S==null?void 0:S.flags)==null?void 0:B.UNLEASH_CLOUD);return r(gr,{onSubmit:c,children:[e(x,{condition:A,show:r(W,{severity:"info",sx:{mb:4},children:["Please be aware of our"," ",e(Ln,{href:"https://www.getunleash.io/fair-use-policy",children:"fair use policy"}),"."]})}),r(mr,{children:[e(Ot,{children:"What would you like to call this token?"}),e(fr,{value:n,name:"username",onChange:w=>s(w.target.value),label:"Token name",error:m.username!==void 0,errorText:m.username,onFocus:()=>y("username"),autoFocus:!0}),r(Ye,{sx:{mb:2,width:"100%"},children:[e(br,{id:"token-type",children:"What do you want to connect?"}),e(ft,{"aria-labelledby":"token-type",defaultValue:"CLIENT",name:"radio-buttons-group",value:o,onChange:(w,P)=>u(P),children:k.map(({key:w,label:P,title:L})=>e(ie,{value:w,sx:{mb:1},control:e(tt,{sx:{ml:.75,alignSelf:"flex-start"}}),label:e(O,{children:r(O,{children:[e(R,{children:P}),e(R,{variant:"body2",color:"text.secondary",children:L})]})})},w))})]}),e(Ot,{children:"Which project do you want to give access to?"}),e(Oo,{disabled:o===me.ADMIN,options:v,defaultValue:a,onChange:h,error:m==null?void 0:m.projects,onFocus:()=>y("projects")}),e(Ot,{children:"Which environment should the token have access to?"}),e(yr,{disabled:o===me.ADMIN,options:T,value:i,onChange:l,label:"Environment",id:"api_key_environment",name:"environment",IconComponent:$o,fullWidth:!0})]}),r(vr,{children:[t,e(Sr,{onClick:p,children:"Cancel"})]})]})},wr=()=>{var T;const{environments:t}=Un(),n=(T=t==null?void 0:t.find(A=>A.enabled))==null?void 0:T.name,[o,a]=d.useState(""),[i,s]=d.useState("CLIENT"),[u,h]=d.useState(["*"]),[l,c]=d.useState(u),[p,m]=d.useState(),[y,S]=d.useState({});return d.useEffect(()=>{m(i==="ADMIN"?"*":n)},[i,n]),{username:o,type:i,projects:u,environment:p,setUsername:a,setTokenType:A=>{A==="ADMIN"?(s(A),c(u),h(["*"]),m("*")):(s(A),h(l),m(n))},setProjects:h,setEnvironment:m,getApiTokenPayload:()=>({username:o,type:i,environment:p,projects:u}),isValid:()=>{const A={};return o||(A.username="Username is required"),u.length===0&&(A.projects="At least one project is required"),S(A),Object.keys(A).length===0},clearErrors:A=>{if(A){const B={...y};delete B[A],S(B)}else S({})},errors:y}},xr=({open:t,closeConfirm:n,token:o,type:a})=>(Wt(),r(oe,{open:t,onClick:n,primaryButtonText:"Close",title:"New token created",children:[e(R,{variant:"body1",children:"Your new token has been created successfully."}),e(Bn,{token:o}),e(x,{condition:a===me.FRONTEND,show:r(W,{sx:{mt:2},severity:"info",children:["By default, all ",me.FRONTEND," tokens may be used from any CORS origin. If you'd like to configure a strict set of origins, please use the"," ",e(De,{to:"/admin/cors",target:"_blank",children:"CORS origins configuration page"}),"."]})})]})),un="Create API token",kr=()=>{const{setToastApiError:t}=Y(),{uiConfig:n}=q(),o=ae(),[a,i]=d.useState(!1),[s,u]=d.useState(""),{getApiTokenPayload:h,username:l,type:c,projects:p,environment:m,setUsername:y,setTokenType:S,setProjects:f,setEnvironment:C,isValid:k,errors:v,clearErrors:T}=wr(),{createToken:A,loading:B}=Pn();return Nn(un),r(Te,{loading:B,title:un,description:"Unleash SDKs use API tokens to authenticate to the Unleash API. Client SDKs need a token with 'client privileges', which allows them to fetch feature toggle configurations and post usage metrics.",documentationLink:"https://docs.getunleash.io/reference/api-tokens-and-client-keys",documentationLinkLabel:"API tokens documentation",formatApiCode:()=>`curl --location --request POST '${n.unleashUrl}/api/admin/api-tokens' \\
2
2
  --header 'Authorization: INSERT_API_KEY' \\
3
3
  --header 'Content-Type: application/json' \\
4
4
  --data-raw '${JSON.stringify(h(),void 0,2)}'`,children:[e(Cr,{username:l,type:c,projects:p,environment:m,setEnvironment:C,setTokenType:S,setUsername:y,setProjects:f,errors:v,handleSubmit:async H=>{if(H.preventDefault(),!!k())try{const U=h();await A(U).then(D=>D.json()).then(D=>{qt(),u(D.secret),i(!0)})}catch(U){t(V(U))}},handleCancel:()=>{o(Ce)},mode:"Create",clearErrors:T,children:e(_t,{name:"token",permission:j})}),e(xr,{open:a,closeConfirm:()=>{i(!1),o("/admin/api")},token:s,type:c})]})},to=({data:t={enabled:!1,autoCreate:!1},setValue:n})=>{const o=()=>{n("autoCreate",!t.autoCreate)},a=s=>{n("defaultRootRole",s.target.value)},i=s=>{n(s.target.name,s.target.value)};return r(d.Fragment,{children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Auto-create users"}),e("p",{children:"Enable automatic creation of new users when signing in."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(ie,{control:e(we,{onChange:o,name:"enabled",checked:t.autoCreate,disabled:!t.enabled}),label:"Auto-create users"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Default Root Role"}),e("p",{children:"Choose which root role the user should get when no explicit role mapping exists."})]}),e(b,{item:!0,md:6,children:r(Ye,{style:{minWidth:"200px"},children:[e(Go,{id:"defaultRootRole-label",children:"Default Role"}),r(jo,{label:"Default Role",labelId:"defaultRootRole-label",id:"defaultRootRole",name:"defaultRootRole",disabled:!t.autoCreate||!t.enabled,value:t.defaultRootRole||"Editor",onChange:a,children:[e(Ve,{value:"Viewer",children:"Viewer"}),e(Ve,{value:"Editor",children:"Editor"}),e(Ve,{value:"Admin",children:"Admin"})]})]})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Email domains"}),e("p",{children:"Comma separated list of email domains that should be allowed to sign in."})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:i,label:"Email domains",name:"emailDomains",disabled:!t.autoCreate||!t.enabled,required:Boolean(t.autoCreate),value:t.emailDomains||"",placeholder:"@company.com, @anotherCompany.com",style:{width:"400px"},rows:2,variant:"outlined",size:"small"})})]})]})},Tr=async(t,n)=>{if(t){if(n){const o=await n.json();throw t({message:o.message}),new Error(o.message)}throw new Error}},xt=t=>{const{makeRequest:n,createRequest:o,errors:a,loading:i}=_e({propagateErrors:!0,handleBadRequest:Tr});return{updateSettings:async u=>{const h=`api/admin/auth/${t}/settings`,l=o(h,{method:"POST",body:JSON.stringify(u)});try{await n(l.caller,l.id)}catch(c){throw c}},errors:a,loading:i}},Je=(t,n={})=>{const o=async()=>{const c=se(`api/admin/auth/${t}/settings`);return(await fetch(c,{method:"GET"}).then(ke("Auth settings"))).json()},a=`api/admin/auth/${t}/settings`,{data:i,error:s}=xe(a,o,n),[u,h]=d.useState(!s&&!i),l=()=>{vt(a)};return d.useEffect(()=>{h(!s&&!i)},[i,s]),{config:i||{},error:s,loading:u,refetch:l}},en=t=>{const o=Object.entries(t).filter(([,a])=>a!=="");return Object.fromEntries(o)},no=({ssoType:t,data:n={enabled:!1,enableGroupSyncing:!1,groupJsonPath:""},setValue:o})=>{const a=()=>{o("enableGroupSyncing",!n.enableGroupSyncing)},i=s=>{o(s.target.name,s.target.value)};return r(z,{children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Enable Group Syncing"}),r("p",{children:["Enables automatically syncing of users from the"," ",t,"provider when a user logs in."]})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(ie,{control:e(we,{onChange:a,value:n.enableGroupSyncing,name:"enableGroupSyncing",checked:n.enableGroupSyncing,disabled:!n.enabled}),label:n.enableGroupSyncing?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Group Field JSON Path"}),r("p",{children:["Specifies the path in the ",t," token response from which to read the groups the user belongs to."]})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:i,label:"Group JSON Path",name:"groupJsonPath",value:n.groupJsonPath,disabled:!n.enableGroupSyncing,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]})]})},Ar={enabled:!1,enableSingleSignOut:!1,enableGroupSyncing:!1,autoCreate:!1,unleashHostname:location.hostname,groupJsonPath:"",clientId:"",discoverUrl:"",secret:"",acrValues:""},Er=()=>{const{setToastData:t,setToastApiError:n}=Y(),{uiConfig:o}=q(),[a,i]=d.useState(Ar),{hasAccess:s}=d.useContext(de),{config:u}=Je("oidc"),{updateSettings:h,errors:l,loading:c}=xt("oidc");if(d.useEffect(()=>{u.discoverUrl&&i(u)},[u]),!s(j))return e(W,{severity:"error",children:"You need to be a root admin to access this section."});const p=C=>{S(C.target.name,C.target.value)},m=()=>{i({...a,enabled:!a.enabled})},y=()=>{i({...a,enableSingleSignOut:!a.enableSingleSignOut})},S=(C,k)=>{i({...a,[C]:k})},f=async C=>{C.preventDefault();try{await h(en(a)),t({title:"Settings stored",type:"success"})}catch(k){n(V(k))}};return r(Q,{children:[e(b,{container:!0,style:{marginBottom:"1rem"},children:e(b,{item:!0,md:12,children:r(W,{severity:"info",children:["Please read the"," ",e("a",{href:"https://www.unleash-hosted.com/docs/enterprise-authentication",target:"_blank",rel:"noreferrer",children:"documentation"})," ","to learn how to integrate with specific Open Id Connect providers (Okta, Keycloak, Google, etc). ",e("br",{}),"Callback URL:"," ",r("code",{children:[o.unleashUrl,"/auth/oidc/callback"]})]})})}),r("form",{onSubmit:f,children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Enable"}),e("p",{children:"Enable Open Id Connect Authentication."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(ie,{control:e(we,{onChange:m,value:a.enabled,name:"enabled",checked:a.enabled}),label:a.enabled?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Discover URL"}),e("p",{children:"(Required) Issuer discover metadata URL"})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:p,label:"Discover URL",name:"discoverUrl",value:a.discoverUrl,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Client ID"}),e("p",{children:"(Required) Client ID of your OpenID application"})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:p,label:"Client ID",name:"clientId",value:a.clientId,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:4,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Client secret"}),r("p",{children:["(Required) Client secret of your OpenID application."," "]})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:p,label:"Client Secret",name:"secret",value:a.secret,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),e("h3",{children:"Optional Configuration"}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Enable Single Sign-Out"}),e("p",{children:"If you enable Single Sign-Out Unleash will redirect the user to the IDP as part of the Sign-out process."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(ie,{control:e(we,{onChange:y,value:a.enableSingleSignOut,disabled:!a.enabled,name:"enableSingleSignOut",checked:a.enableSingleSignOut}),label:a.enableSingleSignOut?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"ACR Values"}),e("p",{children:'Requested Authentication Context Class Reference values. If multiple values are specified they should be "space" separated. Will be sent as "acr_values" as part of the authentication request. Unleash will validate the acr value in the id token claims against the list of acr values.'})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:p,label:"ACR Values",name:"acrValues",value:a.acrValues,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),e(no,{ssoType:"OIDC",data:a,setValue:S}),e(to,{data:a,setValue:S}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:12,children:[e(M,{variant:"contained",color:"primary",type:"submit",disabled:c,children:"Save"})," ",e("p",{children:e("small",{style:{color:"red"},children:l==null?void 0:l.message})})]})})]})]})},Pr={enabled:!1,autoCreate:!1,enableGroupSyncing:!1,unleashHostname:location.hostname,entityId:"",signOnUrl:"",certificate:"",signOutUrl:"",spCertificate:"",groupJsonPath:""},Dr=()=>{const{setToastData:t,setToastApiError:n}=Y(),{uiConfig:o}=q(),[a,i]=d.useState(Pr),{hasAccess:s}=d.useContext(de),{config:u}=Je("saml"),{updateSettings:h,errors:l,loading:c}=xt("saml");if(d.useEffect(()=>{u.entityId&&i(u)},[u]),!s(j))return e(W,{severity:"error",children:"You need to be a root admin to access this section."});const p=f=>{y(f.target.name,f.target.value)},m=()=>{i({...a,enabled:!a.enabled})},y=(f,C)=>{i({...a,[f]:C})},S=async f=>{f.preventDefault();try{await h(en(a)),t({title:"Settings stored",type:"success"})}catch(C){n(V(C))}};return r(Q,{children:[e(b,{container:!0,style:{marginBottom:"1rem"},children:e(b,{item:!0,md:12,children:r(W,{severity:"info",children:["Please read the"," ",e("a",{href:"https://www.unleash-hosted.com/docs/enterprise-authentication",target:"_blank",rel:"noreferrer",children:"documentation"})," ","to learn how to integrate with specific SAML 2.0 providers (Okta, Keycloak, etc). ",e("br",{}),"Callback URL:"," ",r("code",{children:[o.unleashUrl,"/auth/saml/callback"]})]})})}),r("form",{onSubmit:S,children:[r(b,{container:!0,spacing:3,children:[r(b,{item:!0,md:5,mb:2,children:[e("strong",{children:"Enable"}),e("p",{children:"Enable SAML 2.0 Authentication."})]}),e(b,{item:!0,md:6,children:e(ie,{control:e(we,{onChange:m,value:a.enabled,name:"enabled",checked:a.enabled}),label:a.enabled?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Entity ID"}),e("p",{children:"(Required) The Entity Identity provider issuer."})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:p,label:"Entity ID",name:"entityId",value:a.entityId,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Single Sign-On URL"}),e("p",{children:"(Required) The url to redirect the user to for signing in."})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:p,label:"Single Sign-On URL",name:"signOnUrl",value:a.signOnUrl,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:4,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"X.509 Certificate"}),e("p",{children:"(Required) The certificate used to sign the SAML 2.0 request."})]}),e(b,{item:!0,md:7,children:e(Z,{onChange:p,label:"X.509 Certificate",name:"certificate",value:a.certificate,disabled:!a.enabled,style:{width:"100%"},InputProps:{style:{fontSize:"0.6em",fontFamily:"monospace"}},multiline:!0,rows:14,maxRows:14,variant:"outlined",size:"small",required:!0})})]}),e("h3",{children:"Optional Configuration"}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Single Sign-out URL"}),e("p",{children:"(Optional) The url to redirect the user to for signing out of the IDP."})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:p,label:"Single Sign-out URL",name:"signOutUrl",value:a.signOutUrl,disabled:!a.enabled,style:{width:"400px"},variant:"outlined",size:"small"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Service Provider X.509 Certificate"}),e("p",{children:"(Optional) The private certificate used by the Service Provider used to sign the SAML 2.0 request towards the IDP. E.g. used to sign single logout requests (SLO)."})]}),e(b,{item:!0,md:7,children:e(Z,{onChange:p,label:"X.509 Certificate",name:"spCertificate",value:a.spCertificate,disabled:!a.enabled,style:{width:"100%"},InputProps:{style:{fontSize:"0.6em",fontFamily:"monospace"}},multiline:!0,rows:14,maxRows:14,variant:"outlined",size:"small"})})]}),e(no,{ssoType:"SAML",data:a,setValue:y}),e(to,{data:a,setValue:y}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:5,children:[e(M,{variant:"contained",color:"primary",type:"submit",disabled:c,children:"Save"})," ",e("p",{children:e("small",{style:{color:"red"},children:l==null?void 0:l.message})})]})})]})]})},Rr=()=>{const{setToastData:t,setToastApiError:n}=Y(),{config:o}=Je("simple"),[a,i]=d.useState(!1),{updateSettings:s,errors:u,loading:h}=xt("simple"),{hasAccess:l}=d.useContext(de);return d.useEffect(()=>{i(!!o.disabled)},[o.disabled]),l(j)?e(Q,{children:r("form",{onSubmit:async m=>{m.preventDefault();try{await s({disabled:a}),t({title:"Successfully saved",text:"Password authentication settings stored.",autoHideDuration:4e3,type:"success",show:!0})}catch(y){n(V(y)),i(o.disabled)}},children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Password based login"}),e("p",{children:"Allow users to login with username & password"})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(ie,{control:e(we,{onChange:()=>{i(!a)},value:!a,name:"disabled",checked:!a}),label:a?"Disabled":"Enabled"})})]}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:12,children:[e(M,{variant:"contained",color:"primary",type:"submit",disabled:h,children:"Save"})," ",e("p",{children:e("small",{style:{color:"red"},children:u==null?void 0:u.message})})]})})]})}):e(W,{severity:"error",children:"You need to be a root admin to access this section."})},Ir={enabled:!1,autoCreate:!1,unleashHostname:location.hostname,clientId:"",clientSecret:"",emailDomains:""},Ur=()=>{const{setToastData:t,setToastApiError:n}=Y(),{uiConfig:o}=q(),[a,i]=d.useState(Ir),{hasAccess:s}=d.useContext(de),{config:u}=Je("google"),{updateSettings:h,errors:l,loading:c}=xt("google");if(d.useEffect(()=>{u.clientId&&i(u)},[u]),!s(j))return e("span",{children:"You need admin privileges to access this section."});const p=f=>{i({...a,[f.target.name]:f.target.value})},m=()=>{i({...a,enabled:!a.enabled})},y=()=>{i({...a,autoCreate:!a.autoCreate})},S=async f=>{f.preventDefault();try{await h(en(a)),t({title:"Settings stored",type:"success"})}catch(C){n(V(C))}};return r(Q,{children:[r(O,{children:[r(W,{severity:"error",sx:{mb:2},children:["This integration is deprecated and will be removed in next major version. Please use ",e("strong",{children:"OpenID Connect"})," to enable Google SSO."]}),r(W,{severity:"info",sx:{mb:3},children:["Read the"," ",e("a",{href:"https://www.unleash-hosted.com/docs/enterprise-authentication/google",target:"_blank",rel:"noreferrer",children:"documentation"})," ","to learn how to integrate with Google OAuth 2.0. ",e("br",{}),"Callback URL:"," ",r("code",{children:[o.unleashUrl,"/auth/google/callback"]})]})]}),r("form",{onSubmit:S,children:[r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,xs:5,children:[e("strong",{children:"Enable"}),e("p",{children:"Enable Google users to login. Value is ignored if Client ID and Client Secret are not defined."})]}),e(b,{item:!0,xs:6,style:{padding:"20px"},children:e(ie,{control:e(we,{onChange:m,value:a.enabled,name:"enabled",checked:a.enabled}),label:a.enabled?"Enabled":"Disabled"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,xs:5,children:[e("strong",{children:"Client ID"}),e("p",{children:"(Required) The Client ID provided by Google when registering the application."})]}),e(b,{item:!0,xs:6,children:e(Z,{onChange:p,label:"Client ID",name:"clientId",placeholder:"",value:a.clientId,style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Client Secret"}),e("p",{children:"(Required) Client Secret provided by Google when registering the application."})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:p,label:"Client Secret",name:"clientSecret",value:a.clientSecret,placeholder:"",style:{width:"400px"},variant:"outlined",size:"small",required:!0})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Unleash hostname"}),r("p",{children:["(Required) The hostname you are running Unleash on that Google should send the user back to. The final callback URL will be"," ",e("small",{children:e("code",{children:"https://[unleash.hostname.com]/auth/google/callback"})})]})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:p,label:"Unleash Hostname",name:"unleashHostname",placeholder:"",value:a.unleashHostname||"",style:{width:"400px"},variant:"outlined",size:"small"})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Auto-create users"}),e("p",{children:"Enable automatic creation of new users when signing in with Google."})]}),e(b,{item:!0,md:6,style:{padding:"20px"},children:e(we,{onChange:y,name:"enabled",checked:a.autoCreate})})]}),r(b,{container:!0,spacing:3,mb:2,children:[r(b,{item:!0,md:5,children:[e("strong",{children:"Email domains"}),e("p",{children:"(Optional) Comma separated list of email domains that should be allowed to sign in."})]}),e(b,{item:!0,md:6,children:e(Z,{onChange:p,label:"Email domains",name:"emailDomains",value:a.emailDomains,placeholder:"@company.com, @anotherCompany.com",style:{width:"400px"},rows:2,multiline:!0,variant:"outlined",size:"small"})})]}),e(b,{container:!0,spacing:3,children:r(b,{item:!0,md:5,children:[e(M,{variant:"contained",color:"primary",type:"submit",disabled:c,children:"Save"})," ",e("p",{children:e("small",{style:{color:"red"},children:l==null?void 0:l.message})})]})})]})]})},Lr=()=>{const{authenticationType:t}=q().uiConfig;return e("div",{children:r(Q,{header:"Single Sign-On",children:[e(x,{condition:t==="enterprise",show:e(Fo,{tabData:[{label:"OpenID Connect",component:e(Er,{})},{label:"SAML 2.0",component:e(Dr,{})},{label:"Password",component:e(Rr,{})},{label:"Google",component:e(Ur,{})}]})}),e(x,{condition:t==="open-source",show:e(W,{severity:"warning",children:"You are running the open-source version of Unleash. You have to use the Enterprise edition in order configure Single Sign-on."})}),e(x,{condition:t==="demo",show:e(W,{severity:"warning",children:"You are running Unleash in demo mode. You have to use the Enterprise edition in order configure Single Sign-on."})}),e(x,{condition:t==="custom",show:e(W,{severity:"warning",children:"You have decided to use custom authentication type. You have to use the Enterprise edition in order configure Single Sign-on from the user interface."})}),e(x,{condition:t==="hosted",show:e(W,{severity:"info",children:"Your Unleash instance is managed by the Unleash team."})})]})})},Br=se("api/admin/invoices"),Nr=g(M)(({theme:t})=>({width:"100%",marginBottom:t.spacing(1.5)})),Or=({update:t})=>e(Nr,{href:`${Br}/${t?"portal":"checkout"}`,variant:t?"outlined":"contained",children:t?"Update billing information":"Add billing information"}),$r=g("aside")(({theme:t})=>({padding:t.spacing(4),height:"100%",borderRadius:t.shape.borderRadiusLarge,backgroundColor:t.palette.secondaryContainer})),Gr=g(R)(({theme:t})=>({marginBottom:t.spacing(4)})),jr=g(W)(({theme:t})=>({marginBottom:t.spacing(4)})),hn=g(R)(({theme:t})=>({fontSize:t.fontSizes.smallBody,color:t.palette.text.secondary})),Fr=g(Vt)(({theme:t})=>({margin:`${t.spacing(2.5)} 0`,borderColor:t.palette.dividerAlternative})),zr=({instanceStatus:t})=>{const n=t.state!==On.ACTIVE;return e(b,{item:!0,xs:12,md:5,children:r($r,{children:[e(Gr,{variant:"body1",children:"Billing information"}),e(x,{condition:n,show:r(jr,{severity:"warning",children:["In order to ",e("strong",{children:"Upgrade trial"})," you need to provide us your billing information."]})}),e(Or,{update:!n}),e(hn,{children:n?"Once we have received your billing information we will upgrade your trial within 1 business day":"Update your credit card and business information and change which email address we send invoices to"}),e(Fr,{}),r(hn,{children:[e("a",{href:"mailto:elise@getunleash.ai?subject=PRO plan clarifications",children:"Get in touch with us"})," ","for any clarification"]})]})})},Xe=()=>{const{data:t,error:n,mutate:o}=xe(se("api/admin/user-admin"),Mr);return d.useMemo(()=>({users:(t==null?void 0:t.users)??[],roles:(t==null?void 0:t.rootRoles)??[],loading:!n&&!t,refetch:()=>o(),error:n}),[t,n,o])},Mr=t=>fetch(t).then(ke("Users")).then(n=>n.json()),Hr=g(b)(({theme:t})=>({flexWrap:"nowrap",gap:t.spacing(1)})),lt=({sx:t,children:n})=>e(Hr,{container:!0,item:!0,justifyContent:"space-between",alignItems:"center",sx:t,children:n}),Le=({children:t,vertical:n=!1})=>e(b,{container:n,item:!0,display:"flex",alignItems:n?"start":"center",direction:n?"column":void 0,children:t}),Wr=g("span")(({theme:t})=>({fontSize:t.fontSizes.smallBody,marginLeft:t.spacing(1)})),pn=({children:t})=>r(Wr,{children:["(",t,")"]}),oo=!1,_r=g("aside")(({theme:t})=>({padding:t.spacing(2.5),height:"100%",borderRadius:t.shape.borderRadiusLarge,boxShadow:t.boxShadows.elevated,[t.breakpoints.up("md")]:{padding:t.spacing(6.5)}})),qr=g(R)(({theme:t})=>({fontSize:t.fontSizes.smallBody,color:t.palette.text.secondary})),Vr=g("span")(({theme:t})=>({fontSize:"3.25rem",lineHeight:1,color:t.palette.primary.main,fontWeight:800})),Yr=g("span")(({theme:t})=>({marginLeft:t.spacing(1.5),fontWeight:t.fontWeight.bold})),Jr=g("span")(({theme:t})=>({color:t.palette.primary.main,fontSize:t.fontSizes.mainHeader,fontWeight:t.fontWeight.bold})),Kr=g(W)(({theme:t})=>({fontSize:t.fontSizes.smallerBody,marginBottom:t.spacing(3),marginTop:t.spacing(-1.5),[t.breakpoints.up("md")]:{marginTop:t.spacing(-4.5)}})),Zr=g(zo)(({theme:t})=>({fontSize:"1rem",marginRight:t.spacing(1)})),Xr=g(Vt)(({theme:t})=>({margin:`${t.spacing(3)} 0`})),Qr=({instanceStatus:t})=>{const{users:n}=Xe(),o=Mo(t),a={[st.PRO]:80,[st.COMPANY]:0,[st.TEAM]:0,[st.UNKNOWN]:0,user:15},i=a[t.plan],s=t.seats??5,u=Math.min(n.length,s),h=n.length-u,l=a.user*h,c=i+l,p=t.state!==On.ACTIVE;return e(b,{item:!0,xs:12,md:7,children:r(_r,{children:[e(x,{condition:p,show:r(Kr,{severity:"info",children:["After you have sent your billing information, your instance will be upgraded - you don't have to do anything."," ",e("a",{href:"mailto:elise@getunleash.ai?subject=PRO plan clarifications",children:"Get in touch with us"})," ","for any clarification"]})}),e(Gt,{color:"success",children:"Current plan"}),e(b,{container:!0,children:r(lt,{sx:m=>({marginBottom:m.spacing(3)}),children:[r(Le,{children:[e(Vr,{children:t.plan}),e(x,{condition:Ho(t),show:e(Yr,{sx:m=>({color:o?m.palette.error.dark:m.palette.warning.dark}),children:o?"Trial expired":t.trialExtended?"Extended Trial":"Trial"})})]}),e(Le,{children:e(x,{condition:i>0,show:r(Jr,{children:["$",i.toFixed(2)]})})})]})}),e(x,{condition:oo,show:r(z,{children:[r(b,{container:!0,children:[r(lt,{sx:m=>({marginBottom:m.spacing(1.5)}),children:[e(Le,{children:r(R,{children:[e("strong",{children:s})," team members",e(pn,{children:r(De,{to:"/admin/users",children:[u," assigned"]})})]})}),r(Le,{children:[e(Zr,{}),e(R,{variant:"body2",children:"included"})]})]}),r(lt,{children:[r(Le,{vertical:!0,children:[r(R,{children:["Paid members",e(pn,{children:r(De,{to:"/admin/users",children:[h," assigned"]})})]}),r(qr,{children:["Add up to 15 extra paid members - $",a.user,"/month per member"]})]}),e(Le,{children:r(R,{sx:m=>({fontSize:m.fontSizes.mainHeader}),children:["$",l.toFixed(2)]})})]})]}),e(Xr,{}),e(b,{container:!0,children:r(lt,{children:[e(Le,{children:e(R,{sx:m=>({fontWeight:m.fontWeight.bold,fontSize:m.fontSizes.mainHeader}),children:"Total per month"})}),e(Le,{children:r(R,{sx:m=>({fontWeight:m.fontWeight.bold,fontSize:"2rem"}),children:["$",c.toFixed(2)]})})]})})]})})]})})},ei=({instanceStatus:t})=>r(b,{container:!0,spacing:4,children:[e(zr,{instanceStatus:t}),e(Qr,{instanceStatus:t})]}),ti=g(R)(({theme:t})=>({marginTop:t.spacing(6),marginBottom:t.spacing(2.5),fontSize:t.fontSizes.mainHeader})),ni=[{Header:"Amount",accessor:"amountFormatted"},{Header:"Status",accessor:"status",disableGlobalFilter:!0},{Header:"Due date",accessor:"dueDate",Cell:Fe,sortType:"date",disableGlobalFilter:!0},{Header:"Download",accessor:"invoicePDF",align:"center",Cell:({value:t})=>e(O,{sx:{display:"flex",justifyContent:"center"},"data-loading":!0,children:e(Re,{href:t,children:e(Wo,{})})}),width:100,disableGlobalFilter:!0,disableSortBy:!0}],oi=({data:t,isLoading:n=!1})=>{const o=d.useMemo(()=>({sortBy:[{id:"dueDate"}]}),[]),{getTableProps:a,getTableBodyProps:i,headerGroups:s,rows:u,prepareRow:h}=_.useTable({columns:ni,data:t,initialState:o,sortTypes:Ne,autoResetGlobalFilter:!1,disableSortRemove:!0,defaultColumn:{Cell:fe}},_.useGlobalFilter,_.useSortBy);return r(Q,{isLoading:n,disablePadding:!0,children:[e(ti,{children:"Payment history"}),r($n,{...a(),children:[e(Mt,{headerGroups:s}),e(nt,{...i(),children:u.map(l=>(h(l),e(je,{hover:!0,...l.getRowProps(),children:l.cells.map(c=>e(Ht,{...c.getCellProps(),children:c.render("Cell")}))})))})]}),e(x,{condition:u.length===0,show:e(ce,{children:"No invoices to show."})})]})},jt="api/admin/invoices",ai=se(jt),ao=(t={})=>{const n=()=>fetch(ai,{method:"GET"}).then(ke("Invoices")).then(h=>h.json()),{data:o,error:a}=xe(jt,n,t),[i,s]=d.useState(!a&&!o),u=()=>{vt(jt)};return d.useEffect(()=>{s(!a&&!o)},[o,a]),{invoices:(o==null?void 0:o.invoices)||[],error:a,loading:i,refetchInvoices:u}},ri=()=>{const{instanceStatus:t,isBilling:n,refetchInstanceStatus:o,refresh:a,loading:i}=Yt(),{invoices:s}=ao(),{hasAccess:u}=d.useContext(de);return d.useEffect(()=>{(async()=>{await a(),o()})()},[o,a]),e("div",{children:e(Q,{header:"Billing",isLoading:i,children:e(x,{condition:n,show:e(x,{condition:u(j),show:()=>r(z,{children:[e(ei,{instanceStatus:t}),e(oi,{data:s})]}),elseShow:()=>e(He,{})}),elseShow:e(W,{severity:"error",children:"Billing is not enabled for this instance."})})})})},ii=se("api/admin/invoices/portal"),si=()=>{const{refetchInvoices:t,invoices:n}=ao(),[o,a]=d.useState(!1),{locationSettings:i}=Gn();return d.useEffect(()=>{t(),a(!0)},[]),e(x,{condition:n.length>0,show:e(Q,{header:e(ne,{title:"Invoices",actions:e(M,{href:ii,rel:"noreferrer",target:"_blank",endIcon:e(_o,{}),children:"Billing portal"})}),children:e("div",{children:r(zt,{children:[e(jn,{children:r(je,{children:[e(re,{children:"Amount"}),e(re,{children:"Status"}),e(re,{children:"Due date"}),e(re,{children:"PDF"}),e(re,{children:"Link"})]})}),e(nt,{children:n.map(s=>r(je,{style:{backgroundColor:s.status==="past-due"?"#ff9194":"inherit"},children:[e(re,{style:{textAlign:"left"},children:s.amountFormatted}),e(re,{style:{textAlign:"left"},children:s.status}),e(re,{style:{textAlign:"left"},children:s.dueDate&&Fn(s.dueDate,i.locale)}),e(re,{style:{textAlign:"left"},children:e("a",{href:s.invoicePDF,children:"PDF"})}),e(re,{style:{textAlign:"left"},children:e("a",{href:s.invoiceURL,target:"_blank",rel:"noreferrer",children:"Payment link"})})]},s.invoiceURL))})]})})}),elseShow:e("div",{children:o&&"No invoices to show."})})},li=()=>{const{hasAccess:t}=d.useContext(de);return e("div",{children:e(x,{condition:t(j),show:e(si,{}),elseShow:e(W,{severity:"error",children:"You need to be instance admin to access this section."})})})},ci=()=>{const{uiConfig:t,loading:n}=q();return n?null:t.flags.UNLEASH_CLOUD?e(qo,{to:"/admin/billing",replace:!0}):e(li,{})},di=()=>r(W,{severity:"info",children:[r("p",{children:["Use this page to configure allowed CORS origins for the Frontend API (",e("code",{children:"/api/frontend"}),")."]}),r("p",{children:["This configuration will not affect the Admin API (",e("code",{children:"/api/admin"}),") nor the Client API (",e("code",{children:"/api/client"}),")."]}),r("p",{children:["An asterisk (",e("code",{children:"*"}),") may be used to allow API calls from any origin."]}),e("br",{}),e("p",{children:"Be aware that changes here will take up to two minutes to be updated. In addition, there is a maxAge on the Access-Control-Allow-Origin header that will instruct browsers to cache this header for some time. The cache period is set to the maxium that the browser allows (2h for Chrome, 24h for Firefox)."})]}),ui=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=_e({propagateErrors:!0});return{setFrontendSettings:async s=>{const h=n("api/admin/ui-config",{method:"POST",body:JSON.stringify({frontendSettings:{frontendApiOrigins:s}})},"setFrontendSettings");await t(h.caller,h.id)},loading:a,errors:o}},hi=({frontendApiOrigins:t})=>{const{setFrontendSettings:n}=ui(),{setToastData:o,setToastApiError:a}=Y(),[i,s]=d.useState(mn(t)),u=an(),h=an();return e("form",{onSubmit:async c=>{try{const p=pi(i);c.preventDefault(),await n(p),s(mn(p)),o({title:"Settings saved",type:"success"})}catch(p){a(V(p))}},children:r(O,{sx:{display:"grid",gap:1},children:[r("label",{htmlFor:u,children:["Which origins should be allowed to call the Frontend API? Add only one origin per line. The CORS specification does not support wildcard for subdomains, it needs to be a fully qualified domain, including the protocol.",e("br",{}),e("br",{}),'If you specify "*" it will be the chosen origin.',e("br",{}),e("br",{}),"Example:"]}),r("code",{style:{fontSize:"0.7em"},children:["https://www.example.com",e("br",{}),"https://www.example2.com"]}),e(Z,{id:u,"aria-describedby":h,placeholder:mi,value:i,onChange:c=>s(c.target.value),multiline:!0,rows:12,variant:"outlined",fullWidth:!0,InputProps:{style:{fontFamily:"monospace",fontSize:"0.8em"}}}),e(Jt,{permission:j})]})})},pi=t=>t.split(/[,\n\s]+/).map(n=>n.replace(/\/$/,"")).filter(Boolean),mn=t=>(t==null?void 0:t.join(`
@@ -12,7 +12,7 @@ import{s as g,r as d,aB as wo,cI as xo,_ as ko,j as e,$ as An,cJ as on,cK as Rt,
12
12
  --data-raw '${JSON.stringify(k(),void 0,2)}'`,H=()=>{h(Ce)},U=I=>I.length,D=I=>!(B!=null&&B.filter(G=>G.name===I&&G.id!==t).length),N=U(l)&&D(l);return e(Te,{loading:P,title:"Edit group",description:"Groups is the best and easiest way to organize users and then use them in projects to assign a specific role in one go to all the users in a group.",documentationLink:"https://docs.getunleash.io/advanced/groups",documentationLinkLabel:"Groups documentation",formatApiCode:E,children:e(so,{name:l,description:p,mappingsSSO:y,users:f,setName:I=>{v(),D(I)||A({name:"A group with that name already exists."}),c(I)},setDescription:m,setMappingsSSO:S,setUsers:C,errors:T,handleSubmit:L,handleCancel:H,mode:Kt,children:e(M,{type:"submit",variant:"contained",color:"primary",disabled:!N,"data-testid":Mn,children:"Save"})})})},Ni=g(Hn)(({theme:t})=>({borderRadius:t.shape.borderRadiusLarge,padding:t.spacing(2.5,4),boxShadow:"none",marginBottom:t.spacing(2),fontSize:t.fontSizes.smallBody})),Oi=g("div")(({theme:t})=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),$i=g("h1")(({theme:t})=>({fontSize:t.fontSizes.mainHeader})),Gi=g("div")(({theme:t})=>({display:"flex"})),ji=g("span")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginLeft:t.spacing(1)})),Fi=({title:t,description:n,actions:o})=>(Nn(t),r(Ni,{children:[r(Oi,{children:[e($i,{children:t}),e(Gi,{children:o})]}),e(x,{condition:Boolean(n==null?void 0:n.length),show:r(z,{children:["Description:",e(ji,{children:n})]})})]})),lo=({open:t,setOpen:n,group:o})=>{const{refetchGroups:a}=Ke(),{removeGroup:i}=it(),{setToastData:s,setToastApiError:u}=Y(),h=ae();return e(oe,{open:t,primaryButtonText:"Delete group",secondaryButtonText:"Cancel",onClick:async()=>{try{await i(o.id),a(),n(!1),h("/admin/groups"),s({title:"Group removed successfully",type:"success"})}catch(c){u(V(c))}},onClose:()=>{n(!1)},title:"Delete group?",children:r(R,{children:["Do you really want to delete ",e("strong",{children:o.name}),"? Users who are granted access to projects only via this group will lose access to those projects."]})})},zi=g("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),Mi=g("p")(({theme:t})=>({color:t.palette.text.secondary,marginBottom:t.spacing(1)})),Hi=g("div")(()=>({marginTop:"auto",display:"flex",justifyContent:"flex-end"})),Wi=g(M)(({theme:t})=>({marginLeft:t.spacing(3)})),_i=g(O)(({theme:t})=>({marginTop:t.spacing(2)})),co=({open:t,setOpen:n,group:o})=>{const{refetchGroup:a}=wt(o.id),{refetchGroups:i}=Ke(),{updateGroup:s,loading:u}=it(),{setToastData:h,setToastApiError:l}=Y(),{uiConfig:c}=q(),{users:p,setUsers:m,getGroupPayload:y}=tn(o.name,o.description,o.mappingsSSO,o.users);return d.useEffect(()=>{m(o.users)},[o.users,t,m]),e(Wn,{open:t,onClose:()=>{n(!1)},label:"Edit users",children:e(Te,{loading:u,modal:!0,title:"Edit users",description:"Groups is the best and easiest way to organize users and then use them in projects to assign a specific role in one go to all the users in a group.",documentationLink:"https://docs.getunleash.io/advanced/groups",documentationLinkLabel:"Groups documentation",formatApiCode:()=>`curl --location --request PUT '${c.unleashUrl}/api/admin/groups/${o.id}' \\
13
13
  --header 'Authorization: INSERT_API_KEY' \\
14
14
  --header 'Content-Type: application/json' \\
15
- --data-raw '${JSON.stringify(y(),void 0,2)}'`,children:r(zi,{onSubmit:async C=>{C.preventDefault();try{await s(o.id,y()),a(),i(),n(!1),h({title:"Group users saved successfully",type:"success"})}catch(k){l(V(k))}},children:[r("div",{children:[e(Mi,{children:"Edit users in this group"}),e(ro,{users:p,setUsers:m}),e(io,{users:p,setUsers:m})]}),e(Hi,{children:r(_i,{children:[e(M,{type:"submit",variant:"contained",color:"primary","data-testid":Mn,children:"Save"}),e(Wi,{onClick:()=>{n(!1)},children:"Cancel"})]})})]})})})},qi=({open:t,setOpen:n,user:o,group:a})=>{const{refetchGroup:i}=wt(a.id),{updateGroup:s}=it(),{setToastData:u,setToastApiError:h}=Y(),l=async()=>{try{const p={...a,users:a.users.filter(({id:m})=>m!==(o==null?void 0:o.id)).map(({id:m})=>({user:{id:m}}))};await s(a.id,p),i(),n(!1),u({title:"User removed from group successfully",type:"success"})}catch(p){h(V(p))}},c=(o==null?void 0:o.name)||(o==null?void 0:o.username)||(o==null?void 0:o.email);return e(oe,{open:t&&Boolean(o),primaryButtonText:"Remove user",secondaryButtonText:"Cancel",onClick:l,onClose:()=>{n(!1)},title:"Remove user from group?",children:r(R,{children:["Do you really want to remove ",e("strong",{children:c})," from"," ",e("strong",{children:a.name}),"? ",e("strong",{children:c})," will lose all access rights granted by this group."]})})},Vi=Array(15).fill({name:"Name of the user",username:"Username of the user"}),Yi={id:"joinedAt"},{value:fn,setValue:Ji}=ra("Group:v1",Yi),Ki=()=>{const t=Number(Ct("groupId")),n=Zt(),o=be(n.breakpoints.down("md")),{group:a,loading:i}=wt(t),[s,u]=d.useState(!1),[h,l]=d.useState(!1),[c,p]=d.useState(!1),[m,y]=d.useState(),S=d.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:D}})=>e(fe,{children:e(qe,{user:D})}),maxWidth:85,disableSortBy:!0},{id:"name",Header:"Name",accessor:D=>D.name||"",Cell:ge,minWidth:100,searchable:!0},{id:"username",Header:"Username",accessor:D=>D.username||D.email,Cell:ge,minWidth:100,searchable:!0},{Header:"Joined",accessor:"joinedAt",Cell:Fe,sortType:"date",maxWidth:150},{id:"createdBy",Header:"Added by",accessor:"createdBy",Cell:ge,minWidth:90,searchable:!0},{Header:"Last login",accessor:D=>D.seenAt||"",Cell:({row:{original:D}})=>e(ot,{value:D.seenAt,emptyText:"Never",title:N=>`Last login: ${N}`}),sortType:"date",maxWidth:150},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:D}})=>e(St,{children:e(Se,{title:"Remove user from group",arrow:!0,describeChild:!0,children:e("span",{children:e(Re,{"data-testid":`${ia}-${D.id}`,onClick:()=>{y(D),p(!0)},children:e(Pe,{})})})})}),maxWidth:100,disableSortBy:!0}],[y,p]),[f,C]=_n(),[k]=d.useState(()=>({sortBy:[{id:f.get("sort")||fn.id,desc:f.has("order")?f.get("order")==="desc":fn.desc}],hiddenColumns:["description"],globalFilter:f.get("search")||""})),[v,T]=d.useState(k.globalFilter),{data:A,getSearchText:B,getSearchContext:w}=Xt(S,v,(a==null?void 0:a.users)??[]),P=d.useMemo(()=>(A==null?void 0:A.length)===0&&i?Vi:A,[A,i]),{headerGroups:L,rows:E,prepareRow:H,state:{sortBy:U}}=_.useTable({columns:S,data:P,initialState:k,sortTypes:Ne,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},_.useSortBy,_.useFlexLayout);return d.useEffect(()=>{const D={};D.sort=U[0].id,U[0].desc&&(D.order="desc"),v&&(D.search=v),C(D,{replace:!0}),Ji({id:U[0].id,desc:U[0].desc||!1})},[U,v,C]),e(x,{condition:Boolean(a),show:r(z,{children:[e(Fi,{title:a==null?void 0:a.name,description:a==null?void 0:a.description,actions:r(z,{children:[e(Ee,{"data-testid":sa,to:`/admin/groups/${t}/edit`,component:De,"data-loading":!0,permission:j,tooltipProps:{title:"Edit group"},children:e(rt,{})}),e(Ee,{"data-testid":la,"data-loading":!0,onClick:()=>u(!0),permission:j,tooltipProps:{title:"Delete group"},children:e(Pe,{})})]})}),r(Q,{isLoading:i,header:e(ne,{secondary:!0,title:`Users (${E.length<P.length?`${E.length} of ${P.length}`:P.length})`,actions:r(z,{children:[e(x,{condition:!o,show:r(z,{children:[e(ve,{initialValue:v,onChange:T,hasFilters:!0,getSearchContext:w}),e(ne.Divider,{})]})}),e(Ft,{"data-testid":ca,onClick:()=>{l(!0)},maxWidth:"700px",Icon:bt,permission:j,children:"Edit users"})]}),children:e(x,{condition:o,show:e(ve,{initialValue:v,onChange:T,hasFilters:!0,getSearchContext:w})})}),children:[e(Me,{value:B(v),children:e(at,{rows:E,headerGroups:L,prepareRow:H})}),e(x,{condition:E.length===0,show:e(x,{condition:(v==null?void 0:v.length)>0,show:r(ce,{children:["No users found matching “",v,"” in this group."]}),elseShow:e(ce,{children:"This group is empty. Get started by adding a user to the group."})})}),e(lo,{open:s,setOpen:u,group:a}),e(co,{open:h,setOpen:l,group:a}),e(qi,{open:c,setOpen:p,user:m,group:a})]})]})})},Zi=g(qn)(({theme:t})=>({pointerEvents:"none",".MuiPaper-root":{padding:t.spacing(2)}})),Xi=g("div")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1)})),Qi=({user:t,open:n,anchorEl:o,onPopoverClose:a})=>r(Zi,{open:n,anchorEl:o,onClose:a,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},children:[e(Xi,{children:(t==null?void 0:t.name)||(t==null?void 0:t.username)}),e("div",{children:t==null?void 0:t.email})]}),es=g("div")(({theme:t})=>({display:"inline-flex",alignItems:"center",flexWrap:"wrap",marginLeft:t.spacing(1)})),yn=g(qe)(({theme:t})=>({outline:`${t.spacing(.25)} solid ${t.palette.background.paper}`,marginLeft:t.spacing(-1),"&:hover":{outlineColor:t.palette.primary.main}})),ts=({users:t})=>{const n=d.useMemo(()=>t.sort((c,p)=>(p==null?void 0:p.joinedAt.getTime())-(c==null?void 0:c.joinedAt.getTime())).slice(0,9),[t]),[o,a]=d.useState(null),[i,s]=d.useState(),u=c=>{a(c.currentTarget)},h=()=>{a(null)},l=Boolean(o);return r(es,{children:[n.map(c=>e(yn,{user:c,onMouseEnter:p=>{u(p),s(c)},onMouseLeave:h},c.id)),e(x,{condition:t.length>9,show:r(yn,{children:["+",t.length-n.length]})}),e(Qi,{open:l,user:i,anchorEl:o,onPopoverClose:h})]})},ns=g("div")(({theme:t})=>({display:"flex",justifyContent:"center",transform:"translate3d(8px, -6px, 0)"})),os=g(qn)(({theme:t})=>({borderRadius:t.shape.borderRadiusLarge,padding:t.spacing(1,1.5)})),as=({groupId:t,onEditUsers:n,onRemove:o})=>{const[a,i]=d.useState(null),s=Boolean(a),u=p=>{i(p.currentTarget)},h=()=>{i(null)},l=`feature-${t}-actions`,c=`${l}-menu`;return r(ns,{onClick:p=>{p.preventDefault(),p.stopPropagation()},children:[e(Se,{title:"Group actions",arrow:!0,describeChild:!0,children:e(Re,{id:l,"aria-controls":s?c:void 0,"aria-haspopup":"true","aria-expanded":s?"true":void 0,onClick:u,type:"button",children:e(Qa,{})})}),e(os,{id:c,anchorEl:a,open:s,onClose:h,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},disableScrollLock:!0,children:r(da,{"aria-labelledby":l,children:[r(Ve,{onClick:h,component:De,to:`/admin/groups/${t}/edit`,children:[e(Ut,{children:e(rt,{})}),e(Lt,{children:e(R,{variant:"body2",children:"Edit group"})})]}),r(Ve,{onClick:()=>{n(),h()},children:[e(Ut,{children:e(Ka,{})}),e(Lt,{children:e(R,{variant:"body2",children:"Edit group users"})})]}),r(Ve,{onClick:()=>{o(),h()},children:[e(Ut,{children:e(Pe,{})}),e(Lt,{children:e(R,{variant:"body2",children:"Delete group"})})]})]})})]})},rs=g(De)(({theme:t})=>({textDecoration:"none",color:t.palette.text.primary})),is=g("aside")(({theme:t})=>({padding:t.spacing(2.5),height:"100%",border:`1px solid ${t.palette.dividerAlternative}`,borderRadius:t.shape.borderRadiusLarge,boxShadow:t.boxShadows.card,display:"flex",flexDirection:"column",[t.breakpoints.up("md")]:{padding:t.spacing(4)},"&:hover":{transition:"background-color 0.2s ease-in-out",backgroundColor:t.palette.neutral.light}})),uo=g("div")(()=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),ss=g(uo)(()=>({alignItems:"flex-start"})),ls=g(uo)(()=>({marginTop:"auto"})),cs=g("h2")(({theme:t})=>({fontSize:t.fontSizes.mainHeader,fontWeight:t.fontWeight.medium})),ds=g("div")(({theme:t})=>({display:"flex",alignItems:"center",color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody})),us=g("p")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1),marginBottom:t.spacing(4)})),hs=g("span")(({theme:t})=>({color:t.palette.text.secondary,marginLeft:t.spacing(1)})),ps=g("div")(({theme:t})=>({maxWidth:"50%",display:"flex",justifyContent:"flex-end",gap:t.spacing(.5),flexWrap:"wrap"})),ms=({group:t,onEditUsers:n,onRemoveGroup:o})=>{var i;const a=ae();return e(z,{children:e(rs,{to:`/admin/groups/${t.id}`,children:r(is,{children:[r(ss,{children:[e(cs,{children:t.name}),e(ds,{children:e(as,{groupId:t.id,onEditUsers:()=>n(t),onRemove:()=>o(t)})})]}),e(us,{children:t.description}),r(ls,{children:[e(x,{condition:((i=t.users)==null?void 0:i.length)>0,show:e(ts,{users:t.users}),elseShow:e(hs,{children:"This group has no users."})}),e(ps,{children:e(x,{condition:t.projects.length>0,show:t.projects.map(s=>e(Se,{title:"View project",arrow:!0,placement:"bottom-end",describeChild:!0,children:e(Gt,{onClick:u=>{u.preventDefault(),a(`/projects/${s}/settings/access`)},color:"secondary",icon:e(ua,{}),children:s})},s)),elseShow:e(Se,{title:"This group is not used in any project",arrow:!0,describeChild:!0,children:e(Gt,{children:"Not used"})})})})]})]})},t.id)})},gs=()=>{const t=g("div")(({theme:o})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",margin:o.spacing(6),marginLeft:"auto",marginRight:"auto"})),n=g(R)(({theme:o})=>({fontSize:o.fontSizes.bodySize,marginBottom:o.spacing(2.5)}));return r(t,{children:[e(n,{children:"No groups available. Get started by adding a new group."}),e(M,{to:"/admin/groups/create-group",component:De,variant:"outlined",color:"secondary",children:"Create your first group"})]})},fs=(t,n)=>{var i,s,u,h,l,c;const o=n.toLowerCase(),a={names:(i=t.users)==null?void 0:i.map(p=>{var m;return((m=p.name)==null?void 0:m.toLowerCase())||""}),usernames:(s=t.users)==null?void 0:s.map(p=>{var m;return((m=p.username)==null?void 0:m.toLowerCase())||""}),emails:(u=t.users)==null?void 0:u.map(p=>{var m;return((m=p.email)==null?void 0:m.toLowerCase())||""})};return t.name.toLowerCase().includes(o)||t.description.toLowerCase().includes(o)||((h=a.names)==null?void 0:h.some(p=>p.includes(o)))||((l=a.usernames)==null?void 0:l.some(p=>p.includes(o)))||((c=a.emails)==null?void 0:c.some(p=>p.includes(o)))},ys=()=>{const t=ae(),[n,o]=d.useState(!1),[a,i]=d.useState(!1),[s,u]=d.useState(void 0),{groups:h=[],loading:l}=Ke(),[c,p]=_n(),[m,y]=d.useState(c.get("search")||""),S=be(Be.breakpoints.down("md"));d.useEffect(()=>{const v={};m&&(v.search=m),p(v,{replace:!0})},[m,p]);const f=d.useMemo(()=>{const v=h.sort((T,A)=>T.name.localeCompare(A.name));return m?v.filter(T=>fs(T,m)):v},[h,m]),C=v=>{u(v),o(!0)},k=v=>{u(v),i(!0)};return r(Q,{isLoading:l,header:e(ne,{title:`Groups (${f.length})`,actions:r(z,{children:[e(x,{condition:!S,show:r(z,{children:[e(ve,{initialValue:m,onChange:y}),e(ne.Divider,{})]})}),e(Ft,{onClick:()=>t("/admin/groups/create-group"),maxWidth:"700px",Icon:bt,permission:j,"data-testid":ha,children:"New group"})]}),children:e(x,{condition:S,show:e(ve,{initialValue:m,onChange:y})})}),children:[e(Me,{value:m,children:e(b,{container:!0,spacing:2,children:f.map(v=>e(b,{item:!0,xs:12,md:6,children:e(ms,{group:v,onEditUsers:C,onRemoveGroup:k})},v.id))})}),e(x,{condition:!l&&f.length===0,show:e(x,{condition:(m==null?void 0:m.length)>0,show:r(ce,{children:["No groups found matching “",m,"”"]}),elseShow:e(gs,{})})}),e(x,{condition:Boolean(s),show:e(co,{open:n,setOpen:o,group:s})}),e(x,{condition:Boolean(s),show:e(lo,{open:a,setOpen:i,group:s})})]})},bs=()=>e("div",{children:e(ys,{})}),Ss=()=>{const{data:t,error:n,mutate:o}=xe(se("api/admin/instance-admin/statistics"),vs);return d.useMemo(()=>({stats:t,loading:!n&&!t,refetchGroup:()=>o(),error:n}),[t,n,o])},vs=t=>fetch(t).then(ke("Instance Stats")).then(n=>n.json()),Cs=()=>{const{stats:t}=Ss();let n,o;t!=null&&t.versionEnterprise?(n="Unleash Enterprise version",o=t.versionEnterprise):(n="Unleash OSS version",o=t==null?void 0:t.versionOSS);const a=[{title:"Instance Id",value:t==null?void 0:t.instanceId},{title:n,value:o},{title:"Users",value:t==null?void 0:t.users},{title:"Feature toggles",value:t==null?void 0:t.featureToggles},{title:"Projects",value:t==null?void 0:t.projects},{title:"Environments",value:t==null?void 0:t.environments},{title:"Roles",value:t==null?void 0:t.roles},{title:"Groups",value:t==null?void 0:t.groups},{title:"Context fields",value:t==null?void 0:t.contextFields},{title:"Strategies",value:t==null?void 0:t.strategies}];return t!=null&&t.versionEnterprise&&a.push({title:"SAML enabled",value:t!=null&&t.SAMLenabled?"Yes":"No"},{title:"OIDC enabled",value:t!=null&&t.OIDCenabled?"Yes":"No"}),e(Q,{header:e(ne,{title:"Instance Statistics"}),children:r(Ga,{sx:{display:"grid",gap:4},children:[r(zt,{"aria-label":"Instance statistics",children:[e(jn,{children:r(je,{children:[e(re,{children:"Field"}),e(re,{align:"right",children:"Value"})]})}),e(nt,{children:a.map(i=>r(je,{children:[e(re,{component:"th",scope:"row",children:i.title}),e(re,{align:"right",children:i.value})]},i.title))})]}),e("span",{style:{textAlign:"center"},children:e(M,{startIcon:e(Ja,{}),"aria-label":"Download instance statistics",color:"primary",variant:"contained",target:"_blank",href:se("/api/admin/instance-admin/statistics/csv"),children:"Download"})})]})})},ws=()=>e("div",{children:e(Cs,{})}),xs=()=>e(W,{severity:"warning",children:r("p",{children:[e("b",{children:"Heads up!"})," If you enable maintenance mode, edit access in the entire system will be disabled for all the users (admins, editors, custom roles, etc). During this time nobody will be able to do changes or to make new configurations."]})}),ks=()=>{const{data:t,error:n,mutate:o}=xe(se("api/admin/maintenance"),Ts);return d.useMemo(()=>({enabled:Boolean(t==null?void 0:t.enabled),loading:!n&&!t,refetchMaintenance:o,error:n}),[t,n,o])},Ts=t=>fetch(t).then(ke("Maintenance")).then(n=>n.json()),As=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=_e({propagateErrors:!0});return{toggleMaintenance:async s=>{const h=n("api/admin/maintenance",{method:"POST",body:JSON.stringify(s)});try{await t(h.caller,h.id)}catch(l){throw l}},errors:o,loading:a}},Es=g("div")(({theme:t})=>({display:"flex",flexDirection:"column",padding:t.spacing(3),border:`1px solid ${t.palette.dividerAlternative}`,borderRadius:t.shape.borderRadiusLarge})),Ps=g(O)(({theme:t})=>({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"})),Ds=g(O)(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(2)})),Rs=g(R)(({theme:t})=>({fontSize:t.fontSizes.smallBody})),Is=()=>{const{enabled:t,refetchMaintenance:n}=ks(),{toggleMaintenance:o}=As(),{trackEvent:a}=Qt();return r(Es,{children:[r(Ps,{children:[e("b",{children:"Maintenance Mode"}),e(ie,{sx:{margin:0},control:e(we,{onChange:async()=>{a("maintenance",{props:{eventType:`maintenance ${t?"de":""}activated`}}),await o({enabled:!t}),n()},value:t,name:"enabled",checked:t}),label:e(Rs,{children:t?"Enabled":"Disabled"})})]}),e(Ds,{children:"Maintenance Mode is useful when you want to freeze your system so nobody can do any changes during this time. When enabled it will show a banner at the top of the applications and only an admin can enable it or disable it."})]})},Us=()=>{const{hasAccess:t}=d.useContext(de);return e("div",{children:e(x,{condition:t(j),show:e(Bs,{}),elseShow:e(He,{})})})},Ls=g(O)(({theme:t})=>({display:"grid",gap:t.spacing(4)})),Bs=()=>{const{loading:t}=q();return t?null:e(Q,{header:e(ne,{title:"Maintenance"}),children:r(Ls,{children:[e(xs,{}),e(Is,{})]})})},Ns=t=>{const n={display:"flex",justifyContent:"center",alignItems:"center",width:"100%",textDecoration:"none",color:"inherit",padding:t.theme.spacing(1.5,3)},o={fontWeight:"bold",borderRadius:"3px",padding:t.theme.spacing(1.5,3)};return t.isActive?{...n,...o}:n},pe=({to:t,children:n})=>{const o=Zt();return e(pa,{to:t,style:({isActive:a})=>Ns({isActive:a,theme:o}),children:n})},Os=g(Hn)(({theme:t})=>({marginBottom:"1rem",borderRadius:"12.5px",boxShadow:"none",padding:"0 2rem"}));function $s(){const{uiConfig:t}=q(),{pathname:n}=Vn(),{isBilling:o}=Yt(),{flags:a}=t,i=n.split("/")[2];return e(Os,{children:r(Yn,{value:i,variant:"scrollable",scrollButtons:"auto",allowScrollButtonsMobile:!0,children:[e(he,{value:"users",label:e(pe,{to:"/admin/users",children:e("span",{children:"Users"})})}),a.serviceAccounts&&e(he,{value:"service-accounts",label:e(pe,{to:"/admin/service-accounts",children:e("span",{children:"Service accounts"})})}),a.UG&&e(he,{value:"groups",label:e(pe,{to:"/admin/groups",children:e("span",{children:"Groups"})})}),a.RE&&e(he,{value:"roles",label:e(pe,{to:"/admin/roles",children:e("span",{children:"Project roles"})})}),e(he,{value:"api",label:e(pe,{to:"/admin/api",children:"API access"})}),t.flags.embedProxyFrontend&&e(he,{value:"cors",label:e(pe,{to:"/admin/cors",children:"CORS origins"})}),e(he,{value:"auth",label:e(pe,{to:"/admin/auth",children:"Single sign-on"})}),e(he,{value:"instance",label:e(pe,{to:"/admin/instance",children:"Instance stats"})}),a.networkView&&e(he,{value:"network",label:e(pe,{to:"/admin/network",children:"Network"})}),a.maintenance&&e(he,{value:"maintenance",label:e(pe,{to:"/admin/maintenance",children:"Maintenance"})}),o&&e(he,{value:"billing",label:e(pe,{to:"/admin/billing",children:"Billing"})})]})})}const Gs=d.lazy(()=>import("./NetworkOverview-8018cd89.js")),js=d.lazy(()=>import("./NetworkTraffic-84935c51.js")),Fs=g(Q)(()=>({".page-header":{padding:0}})),zs=[{label:"Overview",path:"/admin/network"},{label:"Traffic",path:"/admin/network/traffic"}],Ms=()=>{const{pathname:t}=Vn();return e("div",{children:e(Fs,{headerClass:"page-header",header:e(Yn,{value:t,indicatorColor:"primary",textColor:"primary",variant:"scrollable",allowScrollButtonsMobile:!0,children:zs.map(({label:n,path:o})=>e(he,{value:o,label:e(pe,{to:o,children:e("span",{children:n})})},n))}),children:r(Jn,{children:[e(J,{path:"traffic",element:e(js,{})}),e(J,{path:"*",element:e(Gs,{})})]})})})},Tt=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=_e({propagateErrors:!0});return{createRole:async l=>{const p=n("api/admin/roles",{method:"POST",body:JSON.stringify(l)});try{return await t(p.caller,p.id)}catch(m){throw m}},deleteRole:async l=>{const c=`api/admin/roles/${l}`,p=n(c,{method:"DELETE"});try{return await t(p.caller,p.id)}catch(m){throw m}},editRole:async(l,c)=>{const p=`api/admin/roles/${l}`,m=n(p,{method:"PUT",body:JSON.stringify(c)});try{return await t(m.caller,m.id)}catch(y){throw y}},validateRole:async l=>{const p=n("api/admin/roles/validate",{method:"POST",body:JSON.stringify(l)});try{return await t(p.caller,p.id)}catch(m){throw m}},errors:o,loading:a}},Hs=g(O)(({theme:t})=>({display:"flex",alignItems:"center",[t.breakpoints.down(500)]:{flexDirection:"column",alignItems:"flex-start"}})),Ws=g(ma)(({theme:t})=>({fontWeight:t.typography.fontWeightBold,marginRight:t.spacing(1)})),bn=({title:t,permissions:n,checkedPermissions:o,Icon:a,isInitiallyExpanded:i,context:s,onPermissionChange:u,onCheckAll:h,getRoleKey:l})=>{const[c,p]=d.useState(i),m=d.useMemo(()=>(n==null?void 0:n.reduce((f,C)=>(f[l(C)]=!0,f),{}))||{},[n]),y=d.useMemo(()=>Object.keys(o).filter(f=>m[f]).length||0,[o,m]),S=d.useMemo(()=>y===(n==null?void 0:n.length),[y,n]);return e(O,{sx:{my:2,pb:1},children:r(ga,{expanded:c,onChange:()=>p(!c),sx:{boxShadow:"none",px:3,py:1,border:f=>`1px solid ${f.palette.divider}`,borderRadius:f=>`${f.shape.borderRadiusLarge}px`},children:[e(fa,{expandIcon:e(Re,{children:e(ja,{titleAccess:"Toggle"})}),sx:{boxShadow:"none",padding:"0"},children:r(Hs,{children:[a,e(Ws,{text:t,maxWidth:"120",maxLength:25})," ",r(R,{variant:"body2",color:"text.secondary",children:["(",y," / ",n==null?void 0:n.length," ","permissions)"]})]})}),r(ya,{sx:{px:0,py:1,flexWrap:"wrap"},children:[e(Vt,{sx:{mb:1}}),r(M,{variant:"text",size:"small",onClick:h,sx:{fontWeight:f=>f.typography.fontWeightRegular},children:[S?"Unselect ":"Select ","all ",s," permissions"]}),e(O,{children:n==null?void 0:n.map(f=>e(ie,{sx:{minWidth:{sm:"300px",xs:"auto"}},control:e(zn,{checked:!!o[l(f)],onChange:()=>u(f),color:"primary"}),label:f.displayName},l(f)))})]})]})})},ho=({children:t,roleName:n,roleDesc:o,checkedPermissions:a,errors:i,permissions:s,onSubmit:u,onCancel:h,setRoleName:l,setRoleDesc:c,handlePermissionChange:p,checkAllProjectPermissions:m,checkAllEnvironmentPermissions:y,validateNameUniqueness:S,clearErrors:f,getRoleKey:C})=>{const{project:k,environments:v}=s;return r("form",{onSubmit:u,children:[r(O,{sx:{maxWidth:"400px"},children:[e(R,{sx:{mb:1},children:"What is your role name?"}),e(We,{label:"Role name",value:n,onChange:T=>l(T.target.value),error:Boolean(i.name),errorText:i.name,onFocus:()=>f(),onBlur:S,autoFocus:!0,sx:{width:"100%",marginBottom:"1rem"}}),e(R,{sx:{mb:1},children:"What is this role for?"}),e(Z,{label:"Role description",variant:"outlined",multiline:!0,maxRows:4,value:o,onChange:T=>c(T.target.value),sx:{width:"100%",marginBottom:"1rem"}})]}),e("div",{children:e(x,{condition:Boolean(i.permissions),show:e(R,{variant:"body2",color:"error.main",children:"You must select at least one permission for a role."})})}),e(bn,{isInitiallyExpanded:!0,title:"Project permissions",Icon:e(tr,{color:"disabled",sx:{mr:1}}),permissions:k,checkedPermissions:a,onPermissionChange:T=>p(T),onCheckAll:m,getRoleKey:C,context:"project"}),e("div",{children:v.map(T=>e(bn,{title:T.name,Icon:e(ba,{sx:{mr:1},color:"disabled"}),permissions:T.permissions,checkedPermissions:a,onPermissionChange:A=>p(A),onCheckAll:()=>y(T.name),getRoleKey:C,context:"environment"},T.name))}),r(O,{sx:{marginTop:"auto",display:"flex",justifyContent:"flex-end"},children:[t,e(M,{onClick:h,sx:{marginLeft:2},children:"Cancel"})]})]})},ye=t=>t.environment?`${t.id}-${t.environment}`:`${t.id}`,po=(t="",n="",o=[])=>{q();const{permissions:a}=Sa({revalidateIfStale:!1,revalidateOnReconnect:!1,revalidateOnFocus:!1}),[i,s]=d.useState(t),[u,h]=d.useState(n),[l,c]=d.useState({});d.useEffect(()=>{o.length>0&&c(o==null?void 0:o.reduce((w,P)=>(w[ye(P)]=P,w),{}))},[o==null?void 0:o.length]);const[p,m]=d.useState({}),{validateRole:y}=Tt();d.useEffect(()=>{s(t)},[t]),d.useEffect(()=>{h(n)},[n]);const S=w=>{let P=Bt(l);P[ye(w)]?delete P[ye(w)]:P[ye(w)]={...w},c(P)},f=()=>{const{project:w}=a;let P=Bt(l);w.every(E=>P[ye(E)])?w.forEach(E=>{delete P[ye(E)]}):w.forEach(E=>{P[ye(E)]={...E}}),c(P)},C=w=>{const{environments:P}=a,L=Bt(l),E=P.find(U=>U.name===w);if(!E)return;E.permissions.every(U=>L[ye(U)])?E.permissions.forEach(U=>{delete L[ye(U)]}):E.permissions.forEach(U=>{L[ye(U)]={...U}}),c(L)},k=()=>({name:i,description:u,permissions:Object.values(l)});return{roleName:i,roleDesc:u,errors:p,checkedPermissions:l,permissions:a,setRoleName:s,setRoleDesc:h,handlePermissionChange:S,onToggleAllProjectPermissions:f,onToggleAllEnvironmentPermissions:C,getProjectRolePayload:k,validatePermissions:()=>Object.keys(l).length===0?(m(w=>({...w,permissions:"You must include at least one permission."})),!1):!0,validateName:()=>i.length===0?(m(w=>({...w,name:"Name can not be empty."})),!1):!0,clearErrors:()=>{m({})},validateNameUniqueness:async()=>{const w=k();try{await y(w)}catch(P){m(L=>({...L,name:V(P)}))}},getRoleKey:ye}},_s=()=>{const{setToastData:t,setToastApiError:n}=Y(),{uiConfig:o}=q(),a=ae(),{roleName:i,roleDesc:s,permissions:u,checkedPermissions:h,errors:l,setRoleName:c,setRoleDesc:p,handlePermissionChange:m,onToggleAllProjectPermissions:y,onToggleAllEnvironmentPermissions:S,getProjectRolePayload:f,validatePermissions:C,validateName:k,validateNameUniqueness:v,clearErrors:T,getRoleKey:A}=po(),{createRole:B,loading:w}=Tt();return e(Te,{loading:w,title:"Create project role",description:`A project role can be
15
+ --data-raw '${JSON.stringify(y(),void 0,2)}'`,children:r(zi,{onSubmit:async C=>{C.preventDefault();try{await s(o.id,y()),a(),i(),n(!1),h({title:"Group users saved successfully",type:"success"})}catch(k){l(V(k))}},children:[r("div",{children:[e(Mi,{children:"Edit users in this group"}),e(ro,{users:p,setUsers:m}),e(io,{users:p,setUsers:m})]}),e(Hi,{children:r(_i,{children:[e(M,{type:"submit",variant:"contained",color:"primary","data-testid":Mn,children:"Save"}),e(Wi,{onClick:()=>{n(!1)},children:"Cancel"})]})})]})})})},qi=({open:t,setOpen:n,user:o,group:a})=>{const{refetchGroup:i}=wt(a.id),{updateGroup:s}=it(),{setToastData:u,setToastApiError:h}=Y(),l=async()=>{try{const p={...a,users:a.users.filter(({id:m})=>m!==(o==null?void 0:o.id)).map(({id:m})=>({user:{id:m}}))};await s(a.id,p),i(),n(!1),u({title:"User removed from group successfully",type:"success"})}catch(p){h(V(p))}},c=(o==null?void 0:o.name)||(o==null?void 0:o.username)||(o==null?void 0:o.email);return e(oe,{open:t&&Boolean(o),primaryButtonText:"Remove user",secondaryButtonText:"Cancel",onClick:l,onClose:()=>{n(!1)},title:"Remove user from group?",children:r(R,{children:["Do you really want to remove ",e("strong",{children:c})," from"," ",e("strong",{children:a.name}),"? ",e("strong",{children:c})," will lose all access rights granted by this group."]})})},Vi=Array(15).fill({name:"Name of the user",username:"Username of the user"}),Yi={id:"joinedAt"},{value:fn,setValue:Ji}=ra("Group:v1",Yi),Ki=()=>{const t=Number(Ct("groupId")),n=Zt(),o=be(n.breakpoints.down("md")),{group:a,loading:i}=wt(t),[s,u]=d.useState(!1),[h,l]=d.useState(!1),[c,p]=d.useState(!1),[m,y]=d.useState(),S=d.useMemo(()=>[{Header:"Avatar",accessor:"imageUrl",Cell:({row:{original:D}})=>e(fe,{children:e(qe,{user:D})}),maxWidth:85,disableSortBy:!0},{id:"name",Header:"Name",accessor:D=>D.name||"",Cell:ge,minWidth:100,searchable:!0},{id:"username",Header:"Username",accessor:D=>D.username||D.email,Cell:ge,minWidth:100,searchable:!0},{Header:"Joined",accessor:"joinedAt",Cell:Fe,sortType:"date",maxWidth:150},{id:"createdBy",Header:"Added by",accessor:"createdBy",Cell:ge,minWidth:90,searchable:!0},{Header:"Last login",accessor:D=>D.seenAt||"",Cell:({row:{original:D}})=>e(ot,{value:D.seenAt,emptyText:"Never",title:N=>`Last login: ${N}`}),sortType:"date",maxWidth:150},{Header:"Actions",id:"Actions",align:"center",Cell:({row:{original:D}})=>e(St,{children:e(Se,{title:"Remove user from group",arrow:!0,describeChild:!0,children:e("span",{children:e(Re,{"data-testid":`${ia}-${D.id}`,onClick:()=>{y(D),p(!0)},children:e(Pe,{})})})})}),maxWidth:100,disableSortBy:!0}],[y,p]),[f,C]=_n(),[k]=d.useState(()=>({sortBy:[{id:f.get("sort")||fn.id,desc:f.has("order")?f.get("order")==="desc":fn.desc}],hiddenColumns:["description"],globalFilter:f.get("search")||""})),[v,T]=d.useState(k.globalFilter),{data:A,getSearchText:B,getSearchContext:w}=Xt(S,v,(a==null?void 0:a.users)??[]),P=d.useMemo(()=>(A==null?void 0:A.length)===0&&i?Vi:A,[A,i]),{headerGroups:L,rows:E,prepareRow:H,state:{sortBy:U}}=_.useTable({columns:S,data:P,initialState:k,sortTypes:Ne,autoResetSortBy:!1,disableSortRemove:!0,disableMultiSort:!0},_.useSortBy,_.useFlexLayout);return d.useEffect(()=>{const D={};D.sort=U[0].id,U[0].desc&&(D.order="desc"),v&&(D.search=v),C(D,{replace:!0}),Ji({id:U[0].id,desc:U[0].desc||!1})},[U,v,C]),e(x,{condition:Boolean(a),show:r(z,{children:[e(Fi,{title:a==null?void 0:a.name,description:a==null?void 0:a.description,actions:r(z,{children:[e(Ee,{"data-testid":sa,to:`/admin/groups/${t}/edit`,component:De,"data-loading":!0,permission:j,tooltipProps:{title:"Edit group"},children:e(rt,{})}),e(Ee,{"data-testid":la,"data-loading":!0,onClick:()=>u(!0),permission:j,tooltipProps:{title:"Delete group"},children:e(Pe,{})})]})}),r(Q,{isLoading:i,header:e(ne,{secondary:!0,title:`Users (${E.length<P.length?`${E.length} of ${P.length}`:P.length})`,actions:r(z,{children:[e(x,{condition:!o,show:r(z,{children:[e(ve,{initialValue:v,onChange:T,hasFilters:!0,getSearchContext:w}),e(ne.Divider,{})]})}),e(Ft,{"data-testid":ca,onClick:()=>{l(!0)},maxWidth:"700px",Icon:bt,permission:j,children:"Edit users"})]}),children:e(x,{condition:o,show:e(ve,{initialValue:v,onChange:T,hasFilters:!0,getSearchContext:w})})}),children:[e(Me,{value:B(v),children:e(at,{rows:E,headerGroups:L,prepareRow:H})}),e(x,{condition:E.length===0,show:e(x,{condition:(v==null?void 0:v.length)>0,show:r(ce,{children:["No users found matching “",v,"” in this group."]}),elseShow:e(ce,{children:"This group is empty. Get started by adding a user to the group."})})}),e(lo,{open:s,setOpen:u,group:a}),e(co,{open:h,setOpen:l,group:a}),e(qi,{open:c,setOpen:p,user:m,group:a})]})]})})},Zi=g(qn)(({theme:t})=>({pointerEvents:"none",".MuiPaper-root":{padding:t.spacing(2)}})),Xi=g("div")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1)})),Qi=({user:t,open:n,anchorEl:o,onPopoverClose:a})=>r(Zi,{open:n,anchorEl:o,onClose:a,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},children:[e(Xi,{children:(t==null?void 0:t.name)||(t==null?void 0:t.username)}),e("div",{children:t==null?void 0:t.email})]}),es=g("div")(({theme:t})=>({display:"inline-flex",alignItems:"center",flexWrap:"wrap",marginLeft:t.spacing(1)})),yn=g(qe)(({theme:t})=>({outline:`${t.spacing(.25)} solid ${t.palette.background.paper}`,marginLeft:t.spacing(-1),"&:hover":{outlineColor:t.palette.primary.main}})),ts=({users:t})=>{const n=d.useMemo(()=>t.sort((c,p)=>(p==null?void 0:p.joinedAt.getTime())-(c==null?void 0:c.joinedAt.getTime())).slice(0,9),[t]),[o,a]=d.useState(null),[i,s]=d.useState(),u=c=>{a(c.currentTarget)},h=()=>{a(null)},l=Boolean(o);return r(es,{children:[n.map(c=>e(yn,{user:c,onMouseEnter:p=>{u(p),s(c)},onMouseLeave:h},c.id)),e(x,{condition:t.length>9,show:r(yn,{children:["+",t.length-n.length]})}),e(Qi,{open:l,user:i,anchorEl:o,onPopoverClose:h})]})},ns=g("div")(({theme:t})=>({display:"flex",justifyContent:"center",transform:"translate3d(8px, -6px, 0)"})),os=g(qn)(({theme:t})=>({borderRadius:t.shape.borderRadiusLarge,padding:t.spacing(1,1.5)})),as=({groupId:t,onEditUsers:n,onRemove:o})=>{const[a,i]=d.useState(null),s=Boolean(a),u=p=>{i(p.currentTarget)},h=()=>{i(null)},l=`feature-${t}-actions`,c=`${l}-menu`;return r(ns,{onClick:p=>{p.preventDefault(),p.stopPropagation()},children:[e(Se,{title:"Group actions",arrow:!0,describeChild:!0,children:e(Re,{id:l,"aria-controls":s?c:void 0,"aria-haspopup":"true","aria-expanded":s?"true":void 0,onClick:u,type:"button",children:e(Qa,{})})}),e(os,{id:c,anchorEl:a,open:s,onClose:h,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},disableScrollLock:!0,children:r(da,{"aria-labelledby":l,children:[r(Ve,{onClick:h,component:De,to:`/admin/groups/${t}/edit`,children:[e(Ut,{children:e(rt,{})}),e(Lt,{children:e(R,{variant:"body2",children:"Edit group"})})]}),r(Ve,{onClick:()=>{n(),h()},children:[e(Ut,{children:e(Ka,{})}),e(Lt,{children:e(R,{variant:"body2",children:"Edit group users"})})]}),r(Ve,{onClick:()=>{o(),h()},children:[e(Ut,{children:e(Pe,{})}),e(Lt,{children:e(R,{variant:"body2",children:"Delete group"})})]})]})})]})},rs=g(De)(({theme:t})=>({textDecoration:"none",color:t.palette.text.primary})),is=g("aside")(({theme:t})=>({padding:t.spacing(2.5),height:"100%",border:`1px solid ${t.palette.dividerAlternative}`,borderRadius:t.shape.borderRadiusLarge,boxShadow:t.boxShadows.card,display:"flex",flexDirection:"column",[t.breakpoints.up("md")]:{padding:t.spacing(4)},"&:hover":{transition:"background-color 0.2s ease-in-out",backgroundColor:t.palette.neutral.light}})),uo=g("div")(()=>({display:"flex",alignItems:"center",justifyContent:"space-between"})),ss=g(uo)(()=>({alignItems:"flex-start"})),ls=g(uo)(()=>({marginTop:"auto"})),cs=g("h2")(({theme:t})=>({fontSize:t.fontSizes.mainHeader,fontWeight:t.fontWeight.medium})),ds=g("div")(({theme:t})=>({display:"flex",alignItems:"center",color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody})),us=g("p")(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(1),marginBottom:t.spacing(4)})),hs=g("span")(({theme:t})=>({color:t.palette.text.secondary,marginLeft:t.spacing(1)})),ps=g("div")(({theme:t})=>({maxWidth:"50%",display:"flex",justifyContent:"flex-end",gap:t.spacing(.5),flexWrap:"wrap"})),ms=({group:t,onEditUsers:n,onRemoveGroup:o})=>{var i;const a=ae();return e(z,{children:e(rs,{to:`/admin/groups/${t.id}`,children:r(is,{children:[r(ss,{children:[e(cs,{children:t.name}),e(ds,{children:e(as,{groupId:t.id,onEditUsers:()=>n(t),onRemove:()=>o(t)})})]}),e(us,{children:t.description}),r(ls,{children:[e(x,{condition:((i=t.users)==null?void 0:i.length)>0,show:e(ts,{users:t.users}),elseShow:e(hs,{children:"This group has no users."})}),e(ps,{children:e(x,{condition:t.projects.length>0,show:t.projects.map(s=>e(Se,{title:"View project",arrow:!0,placement:"bottom-end",describeChild:!0,children:e(Gt,{onClick:u=>{u.preventDefault(),a(`/projects/${s}/settings/access`)},color:"secondary",icon:e(ua,{}),children:s})},s)),elseShow:e(Se,{title:"This group is not used in any project",arrow:!0,describeChild:!0,children:e(Gt,{children:"Not used"})})})})]})]})},t.id)})},gs=()=>{const t=g("div")(({theme:o})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",margin:o.spacing(6),marginLeft:"auto",marginRight:"auto"})),n=g(R)(({theme:o})=>({fontSize:o.fontSizes.bodySize,marginBottom:o.spacing(2.5)}));return r(t,{children:[e(n,{children:"No groups available. Get started by adding a new group."}),e(M,{to:"/admin/groups/create-group",component:De,variant:"outlined",color:"secondary",children:"Create your first group"})]})},fs=(t,n)=>{var i,s,u,h,l,c;const o=n.toLowerCase(),a={names:(i=t.users)==null?void 0:i.map(p=>{var m;return((m=p.name)==null?void 0:m.toLowerCase())||""}),usernames:(s=t.users)==null?void 0:s.map(p=>{var m;return((m=p.username)==null?void 0:m.toLowerCase())||""}),emails:(u=t.users)==null?void 0:u.map(p=>{var m;return((m=p.email)==null?void 0:m.toLowerCase())||""})};return t.name.toLowerCase().includes(o)||t.description.toLowerCase().includes(o)||((h=a.names)==null?void 0:h.some(p=>p.includes(o)))||((l=a.usernames)==null?void 0:l.some(p=>p.includes(o)))||((c=a.emails)==null?void 0:c.some(p=>p.includes(o)))},ys=()=>{const t=ae(),[n,o]=d.useState(!1),[a,i]=d.useState(!1),[s,u]=d.useState(void 0),{groups:h=[],loading:l}=Ke(),[c,p]=_n(),[m,y]=d.useState(c.get("search")||""),S=be(Be.breakpoints.down("md"));d.useEffect(()=>{const v={};m&&(v.search=m),p(v,{replace:!0})},[m,p]);const f=d.useMemo(()=>{const v=h.sort((T,A)=>T.name.localeCompare(A.name));return m?v.filter(T=>fs(T,m)):v},[h,m]),C=v=>{u(v),o(!0)},k=v=>{u(v),i(!0)};return r(Q,{isLoading:l,header:e(ne,{title:`Groups (${f.length})`,actions:r(z,{children:[e(x,{condition:!S,show:r(z,{children:[e(ve,{initialValue:m,onChange:y}),e(ne.Divider,{})]})}),e(Ft,{onClick:()=>t("/admin/groups/create-group"),maxWidth:"700px",Icon:bt,permission:j,"data-testid":ha,children:"New group"})]}),children:e(x,{condition:S,show:e(ve,{initialValue:m,onChange:y})})}),children:[e(Me,{value:m,children:e(b,{container:!0,spacing:2,children:f.map(v=>e(b,{item:!0,xs:12,md:6,children:e(ms,{group:v,onEditUsers:C,onRemoveGroup:k})},v.id))})}),e(x,{condition:!l&&f.length===0,show:e(x,{condition:(m==null?void 0:m.length)>0,show:r(ce,{children:["No groups found matching “",m,"”"]}),elseShow:e(gs,{})})}),e(x,{condition:Boolean(s),show:e(co,{open:n,setOpen:o,group:s})}),e(x,{condition:Boolean(s),show:e(lo,{open:a,setOpen:i,group:s})})]})},bs=()=>e("div",{children:e(ys,{})}),Ss=()=>{const{data:t,error:n,mutate:o}=xe(se("api/admin/instance-admin/statistics"),vs);return d.useMemo(()=>({stats:t,loading:!n&&!t,refetchGroup:()=>o(),error:n}),[t,n,o])},vs=t=>fetch(t).then(ke("Instance Stats")).then(n=>n.json()),Cs=()=>{const{stats:t}=Ss();let n,o;t!=null&&t.versionEnterprise?(n="Unleash Enterprise version",o=t.versionEnterprise):(n="Unleash OSS version",o=t==null?void 0:t.versionOSS);const a=[{title:"Instance Id",value:t==null?void 0:t.instanceId},{title:n,value:o},{title:"Users",value:t==null?void 0:t.users},{title:"Feature toggles",value:t==null?void 0:t.featureToggles},{title:"Projects",value:t==null?void 0:t.projects},{title:"Environments",value:t==null?void 0:t.environments},{title:"Roles",value:t==null?void 0:t.roles},{title:"Groups",value:t==null?void 0:t.groups},{title:"Context fields",value:t==null?void 0:t.contextFields},{title:"Strategies",value:t==null?void 0:t.strategies}];return t!=null&&t.versionEnterprise&&a.push({title:"SAML enabled",value:t!=null&&t.SAMLenabled?"Yes":"No"},{title:"OIDC enabled",value:t!=null&&t.OIDCenabled?"Yes":"No"}),e(Q,{header:e(ne,{title:"Instance Statistics"}),children:r(Ga,{sx:{display:"grid",gap:4},children:[r(zt,{"aria-label":"Instance statistics",children:[e(jn,{children:r(je,{children:[e(re,{children:"Field"}),e(re,{align:"right",children:"Value"})]})}),e(nt,{children:a.map(i=>r(je,{children:[e(re,{component:"th",scope:"row",children:i.title}),e(re,{align:"right",children:i.value})]},i.title))})]}),e("span",{style:{textAlign:"center"},children:e(M,{startIcon:e(Ja,{}),"aria-label":"Download instance statistics",color:"primary",variant:"contained",target:"_blank",href:se("/api/admin/instance-admin/statistics/csv"),children:"Download"})})]})})},ws=()=>e("div",{children:e(Cs,{})}),xs=()=>e(W,{severity:"warning",children:r("p",{children:[e("b",{children:"Heads up!"})," If you enable maintenance mode, edit access in the entire system will be disabled for all the users (admins, editors, custom roles, etc). During this time nobody will be able to do changes or to make new configurations."]})}),ks=()=>{const{data:t,error:n,mutate:o}=xe(se("api/admin/maintenance"),Ts);return d.useMemo(()=>({enabled:Boolean(t==null?void 0:t.enabled),loading:!n&&!t,refetchMaintenance:o,error:n}),[t,n,o])},Ts=t=>fetch(t).then(ke("Maintenance")).then(n=>n.json()),As=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=_e({propagateErrors:!0});return{toggleMaintenance:async s=>{const h=n("api/admin/maintenance",{method:"POST",body:JSON.stringify(s)});try{await t(h.caller,h.id)}catch(l){throw l}},errors:o,loading:a}},Es=g("div")(({theme:t})=>({display:"flex",flexDirection:"column",padding:t.spacing(3),border:`1px solid ${t.palette.dividerAlternative}`,borderRadius:t.shape.borderRadiusLarge})),Ps=g(O)(({theme:t})=>({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"})),Ds=g(O)(({theme:t})=>({color:t.palette.text.secondary,fontSize:t.fontSizes.smallBody,marginTop:t.spacing(2)})),Rs=g(R)(({theme:t})=>({fontSize:t.fontSizes.smallBody})),Is=()=>{const{enabled:t,refetchMaintenance:n}=ks(),{toggleMaintenance:o}=As(),{trackEvent:a}=Qt();return r(Es,{children:[r(Ps,{children:[e("b",{children:"Maintenance Mode"}),e(ie,{sx:{margin:0},control:e(we,{onChange:async()=>{a("maintenance",{props:{eventType:`maintenance ${t?"de":""}activated`}}),await o({enabled:!t}),n()},value:t,name:"enabled",checked:t}),label:e(Rs,{children:t?"Enabled":"Disabled"})})]}),e(Ds,{children:"Maintenance Mode is useful when you want to freeze your system so nobody can do any changes during this time. When enabled it will show a banner at the top of the applications and only an admin can enable it or disable it."})]})},Us=()=>{const{hasAccess:t}=d.useContext(de);return e("div",{children:e(x,{condition:t(j),show:e(Bs,{}),elseShow:e(He,{})})})},Ls=g(O)(({theme:t})=>({display:"grid",gap:t.spacing(4)})),Bs=()=>{const{loading:t}=q();return t?null:e(Q,{header:e(ne,{title:"Maintenance"}),children:r(Ls,{children:[e(xs,{}),e(Is,{})]})})},Ns=t=>{const n={display:"flex",justifyContent:"center",alignItems:"center",width:"100%",textDecoration:"none",color:"inherit",padding:t.theme.spacing(1.5,3)},o={fontWeight:"bold",borderRadius:"3px",padding:t.theme.spacing(1.5,3)};return t.isActive?{...n,...o}:n},pe=({to:t,children:n})=>{const o=Zt();return e(pa,{to:t,style:({isActive:a})=>Ns({isActive:a,theme:o}),children:n})},Os=g(Hn)(({theme:t})=>({marginBottom:"1rem",borderRadius:"12.5px",boxShadow:"none",padding:"0 2rem"}));function $s(){const{uiConfig:t}=q(),{pathname:n}=Vn(),{isBilling:o}=Yt(),{flags:a}=t,i=n.split("/")[2];return e(Os,{children:r(Yn,{value:i,variant:"scrollable",scrollButtons:"auto",allowScrollButtonsMobile:!0,children:[e(he,{value:"users",label:e(pe,{to:"/admin/users",children:e("span",{children:"Users"})})}),a.serviceAccounts&&e(he,{value:"service-accounts",label:e(pe,{to:"/admin/service-accounts",children:e("span",{children:"Service accounts"})})}),a.UG&&e(he,{value:"groups",label:e(pe,{to:"/admin/groups",children:e("span",{children:"Groups"})})}),a.RE&&e(he,{value:"roles",label:e(pe,{to:"/admin/roles",children:e("span",{children:"Project roles"})})}),e(he,{value:"api",label:e(pe,{to:"/admin/api",children:"API access"})}),t.flags.embedProxyFrontend&&e(he,{value:"cors",label:e(pe,{to:"/admin/cors",children:"CORS origins"})}),e(he,{value:"auth",label:e(pe,{to:"/admin/auth",children:"Single sign-on"})}),e(he,{value:"instance",label:e(pe,{to:"/admin/instance",children:"Instance stats"})}),a.networkView&&e(he,{value:"network",label:e(pe,{to:"/admin/network",children:"Network"})}),a.maintenance&&e(he,{value:"maintenance",label:e(pe,{to:"/admin/maintenance",children:"Maintenance"})}),o&&e(he,{value:"billing",label:e(pe,{to:"/admin/billing",children:"Billing"})})]})})}const Gs=d.lazy(()=>import("./NetworkOverview-42db0a7a.js")),js=d.lazy(()=>import("./NetworkTraffic-7c9567ee.js")),Fs=g(Q)(()=>({".page-header":{padding:0}})),zs=[{label:"Overview",path:"/admin/network"},{label:"Traffic",path:"/admin/network/traffic"}],Ms=()=>{const{pathname:t}=Vn();return e("div",{children:e(Fs,{headerClass:"page-header",header:e(Yn,{value:t,indicatorColor:"primary",textColor:"primary",variant:"scrollable",allowScrollButtonsMobile:!0,children:zs.map(({label:n,path:o})=>e(he,{value:o,label:e(pe,{to:o,children:e("span",{children:n})})},n))}),children:r(Jn,{children:[e(J,{path:"traffic",element:e(js,{})}),e(J,{path:"*",element:e(Gs,{})})]})})})},Tt=()=>{const{makeRequest:t,createRequest:n,errors:o,loading:a}=_e({propagateErrors:!0});return{createRole:async l=>{const p=n("api/admin/roles",{method:"POST",body:JSON.stringify(l)});try{return await t(p.caller,p.id)}catch(m){throw m}},deleteRole:async l=>{const c=`api/admin/roles/${l}`,p=n(c,{method:"DELETE"});try{return await t(p.caller,p.id)}catch(m){throw m}},editRole:async(l,c)=>{const p=`api/admin/roles/${l}`,m=n(p,{method:"PUT",body:JSON.stringify(c)});try{return await t(m.caller,m.id)}catch(y){throw y}},validateRole:async l=>{const p=n("api/admin/roles/validate",{method:"POST",body:JSON.stringify(l)});try{return await t(p.caller,p.id)}catch(m){throw m}},errors:o,loading:a}},Hs=g(O)(({theme:t})=>({display:"flex",alignItems:"center",[t.breakpoints.down(500)]:{flexDirection:"column",alignItems:"flex-start"}})),Ws=g(ma)(({theme:t})=>({fontWeight:t.typography.fontWeightBold,marginRight:t.spacing(1)})),bn=({title:t,permissions:n,checkedPermissions:o,Icon:a,isInitiallyExpanded:i,context:s,onPermissionChange:u,onCheckAll:h,getRoleKey:l})=>{const[c,p]=d.useState(i),m=d.useMemo(()=>(n==null?void 0:n.reduce((f,C)=>(f[l(C)]=!0,f),{}))||{},[n]),y=d.useMemo(()=>Object.keys(o).filter(f=>m[f]).length||0,[o,m]),S=d.useMemo(()=>y===(n==null?void 0:n.length),[y,n]);return e(O,{sx:{my:2,pb:1},children:r(ga,{expanded:c,onChange:()=>p(!c),sx:{boxShadow:"none",px:3,py:1,border:f=>`1px solid ${f.palette.divider}`,borderRadius:f=>`${f.shape.borderRadiusLarge}px`},children:[e(fa,{expandIcon:e(Re,{children:e(ja,{titleAccess:"Toggle"})}),sx:{boxShadow:"none",padding:"0"},children:r(Hs,{children:[a,e(Ws,{text:t,maxWidth:"120",maxLength:25})," ",r(R,{variant:"body2",color:"text.secondary",children:["(",y," / ",n==null?void 0:n.length," ","permissions)"]})]})}),r(ya,{sx:{px:0,py:1,flexWrap:"wrap"},children:[e(Vt,{sx:{mb:1}}),r(M,{variant:"text",size:"small",onClick:h,sx:{fontWeight:f=>f.typography.fontWeightRegular},children:[S?"Unselect ":"Select ","all ",s," permissions"]}),e(O,{children:n==null?void 0:n.map(f=>e(ie,{sx:{minWidth:{sm:"300px",xs:"auto"}},control:e(zn,{checked:!!o[l(f)],onChange:()=>u(f),color:"primary"}),label:f.displayName},l(f)))})]})]})})},ho=({children:t,roleName:n,roleDesc:o,checkedPermissions:a,errors:i,permissions:s,onSubmit:u,onCancel:h,setRoleName:l,setRoleDesc:c,handlePermissionChange:p,checkAllProjectPermissions:m,checkAllEnvironmentPermissions:y,validateNameUniqueness:S,clearErrors:f,getRoleKey:C})=>{const{project:k,environments:v}=s;return r("form",{onSubmit:u,children:[r(O,{sx:{maxWidth:"400px"},children:[e(R,{sx:{mb:1},children:"What is your role name?"}),e(We,{label:"Role name",value:n,onChange:T=>l(T.target.value),error:Boolean(i.name),errorText:i.name,onFocus:()=>f(),onBlur:S,autoFocus:!0,sx:{width:"100%",marginBottom:"1rem"}}),e(R,{sx:{mb:1},children:"What is this role for?"}),e(Z,{label:"Role description",variant:"outlined",multiline:!0,maxRows:4,value:o,onChange:T=>c(T.target.value),sx:{width:"100%",marginBottom:"1rem"}})]}),e("div",{children:e(x,{condition:Boolean(i.permissions),show:e(R,{variant:"body2",color:"error.main",children:"You must select at least one permission for a role."})})}),e(bn,{isInitiallyExpanded:!0,title:"Project permissions",Icon:e(tr,{color:"disabled",sx:{mr:1}}),permissions:k,checkedPermissions:a,onPermissionChange:T=>p(T),onCheckAll:m,getRoleKey:C,context:"project"}),e("div",{children:v.map(T=>e(bn,{title:T.name,Icon:e(ba,{sx:{mr:1},color:"disabled"}),permissions:T.permissions,checkedPermissions:a,onPermissionChange:A=>p(A),onCheckAll:()=>y(T.name),getRoleKey:C,context:"environment"},T.name))}),r(O,{sx:{marginTop:"auto",display:"flex",justifyContent:"flex-end"},children:[t,e(M,{onClick:h,sx:{marginLeft:2},children:"Cancel"})]})]})},ye=t=>t.environment?`${t.id}-${t.environment}`:`${t.id}`,po=(t="",n="",o=[])=>{q();const{permissions:a}=Sa({revalidateIfStale:!1,revalidateOnReconnect:!1,revalidateOnFocus:!1}),[i,s]=d.useState(t),[u,h]=d.useState(n),[l,c]=d.useState({});d.useEffect(()=>{o.length>0&&c(o==null?void 0:o.reduce((w,P)=>(w[ye(P)]=P,w),{}))},[o==null?void 0:o.length]);const[p,m]=d.useState({}),{validateRole:y}=Tt();d.useEffect(()=>{s(t)},[t]),d.useEffect(()=>{h(n)},[n]);const S=w=>{let P=Bt(l);P[ye(w)]?delete P[ye(w)]:P[ye(w)]={...w},c(P)},f=()=>{const{project:w}=a;let P=Bt(l);w.every(E=>P[ye(E)])?w.forEach(E=>{delete P[ye(E)]}):w.forEach(E=>{P[ye(E)]={...E}}),c(P)},C=w=>{const{environments:P}=a,L=Bt(l),E=P.find(U=>U.name===w);if(!E)return;E.permissions.every(U=>L[ye(U)])?E.permissions.forEach(U=>{delete L[ye(U)]}):E.permissions.forEach(U=>{L[ye(U)]={...U}}),c(L)},k=()=>({name:i,description:u,permissions:Object.values(l)});return{roleName:i,roleDesc:u,errors:p,checkedPermissions:l,permissions:a,setRoleName:s,setRoleDesc:h,handlePermissionChange:S,onToggleAllProjectPermissions:f,onToggleAllEnvironmentPermissions:C,getProjectRolePayload:k,validatePermissions:()=>Object.keys(l).length===0?(m(w=>({...w,permissions:"You must include at least one permission."})),!1):!0,validateName:()=>i.length===0?(m(w=>({...w,name:"Name can not be empty."})),!1):!0,clearErrors:()=>{m({})},validateNameUniqueness:async()=>{const w=k();try{await y(w)}catch(P){m(L=>({...L,name:V(P)}))}},getRoleKey:ye}},_s=()=>{const{setToastData:t,setToastApiError:n}=Y(),{uiConfig:o}=q(),a=ae(),{roleName:i,roleDesc:s,permissions:u,checkedPermissions:h,errors:l,setRoleName:c,setRoleDesc:p,handlePermissionChange:m,onToggleAllProjectPermissions:y,onToggleAllEnvironmentPermissions:S,getProjectRolePayload:f,validatePermissions:C,validateName:k,validateNameUniqueness:v,clearErrors:T,getRoleKey:A}=po(),{createRole:B,loading:w}=Tt();return e(Te,{loading:w,title:"Create project role",description:`A project role can be
16
16
  customised to limit access
17
17
  to resources within a project`,documentationLink:"https://docs.getunleash.io/reference/rbac#custom-project-roles",documentationLinkLabel:"Project roles documentation",formatApiCode:()=>`curl --location --request POST '${o.unleashUrl}/api/admin/roles' \\
18
18
  --header 'Authorization: INSERT_API_KEY' \\