unleash-server 5.9.1 → 5.9.2

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 (47) hide show
  1. package/dist/lib/db/feature-tag-store.js +1 -1
  2. package/dist/lib/db/feature-tag-store.js.map +1 -1
  3. package/dist/lib/features/client-feature-toggles/client-feature-toggle-store.js +2 -2
  4. package/dist/lib/features/client-feature-toggles/client-feature-toggle-store.js.map +1 -1
  5. package/dist/lib/features/instance-stats/instance-stats-service.js +1 -1
  6. package/dist/lib/features/instance-stats/instance-stats-service.js.map +1 -1
  7. package/dist/lib/features/maintenance/maintenance-service.d.ts +1 -0
  8. package/dist/lib/features/maintenance/maintenance-service.d.ts.map +1 -1
  9. package/dist/lib/features/maintenance/maintenance-service.js +21 -3
  10. package/dist/lib/features/maintenance/maintenance-service.js.map +1 -1
  11. package/dist/lib/features/scheduler/scheduler-service.d.ts.map +1 -1
  12. package/dist/lib/features/scheduler/scheduler-service.js +2 -3
  13. package/dist/lib/features/scheduler/scheduler-service.js.map +1 -1
  14. package/dist/lib/routes/admin-api/config.js +1 -1
  15. package/dist/lib/routes/admin-api/config.js.map +1 -1
  16. package/dist/lib/services/version-service.d.ts +2 -3
  17. package/dist/lib/services/version-service.d.ts.map +1 -1
  18. package/dist/lib/services/version-service.js +13 -14
  19. package/dist/lib/services/version-service.js.map +1 -1
  20. package/dist/lib/services/version-service.test.js +3 -3
  21. package/dist/lib/services/version-service.test.js.map +1 -1
  22. package/dist/server-dev.js +1 -0
  23. package/dist/server-dev.js.map +1 -1
  24. package/frontend/build/index.html +1 -1
  25. package/frontend/build/static/{AdvancedPlayground-cPIA-RbQ.js → AdvancedPlayground-FbP1gTKc.js} +1 -1
  26. package/frontend/build/static/{CreateProject-FzmjYLWO.js → CreateProject-vjn1sh4D.js} +1 -1
  27. package/frontend/build/static/{FeatureArchiveDialog-L5h4zxtD.js → FeatureArchiveDialog-ctoNJoqg.js} +1 -1
  28. package/frontend/build/static/{FeatureMetricsChart-Tbwq6Bt5.js → FeatureMetricsChart-ig6HN-Ms.js} +1 -1
  29. package/frontend/build/static/{FeatureViewLazyExport-X9dI4_aw.js → FeatureViewLazyExport-G75iq0Uc.js} +2 -2
  30. package/frontend/build/static/{LazyAdminExport-W54b3FeV.js → LazyAdminExport-oCRFK_R5.js} +2 -2
  31. package/frontend/build/static/{LazyProjectExport-9ef603BO.js → LazyProjectExport-Ul0xAhZq.js} +1 -1
  32. package/frontend/build/static/{LineChartComponent-PCNgvsmw.js → LineChartComponent-3-eT314R.js} +1 -1
  33. package/frontend/build/static/{NetworkOverview-yxVETTui.js → NetworkOverview-d20eBsIq.js} +2 -2
  34. package/frontend/build/static/{NetworkTraffic-Ae9jjvvN.js → NetworkTraffic-_52gjNiG.js} +1 -1
  35. package/frontend/build/static/{ReactJSONEditor-KLSEOFGt.js → ReactJSONEditor-0HyqnatD.js} +1 -1
  36. package/frontend/build/static/{RoleCell-FnaeVDyq.js → RoleCell--QIy8Oj_.js} +1 -1
  37. package/frontend/build/static/{StrategyItemContainer-O6ztV307.js → StrategyItemContainer-X6EIzBwJ.js} +1 -1
  38. package/frontend/build/static/{flowchart-elk-definition-170a3958-foNi5z6K.js → flowchart-elk-definition-170a3958-XjUu-j5x.js} +1 -1
  39. package/frontend/build/static/{index---XID7Lq.js → index-UE-HeGu0.js} +1 -1
  40. package/frontend/build/static/{index-YWzEwhTB.js → index-uUGk-gee.js} +104 -104
  41. package/frontend/build/static/{is_dark-KV2K-Bzj.js → is_dark-8v9B-WN0.js} +1 -1
  42. package/frontend/build/static/{mindmap-definition-44684416-69gw4Hm2.js → mindmap-definition-44684416-5sTvrm1Q.js} +1 -1
  43. package/frontend/build/static/{timeline-definition-8e5a9bc6-T_duJNYl.js → timeline-definition-8e5a9bc6-MtFefIHV.js} +1 -1
  44. package/frontend/build/static/{unknownify-PsUzaxDF.js → unknownify-joALjS6W.js} +1 -1
  45. package/frontend/build/static/{useApiTokens-8m2kE6D5.js → useApiTokens-gCm2i_7X.js} +1 -1
  46. package/frontend/build/static/{useProjectForm-QDdhfGm4.js → useProjectForm-oXjjbjX3.js} +1 -1
  47. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import{c as ht,j as t,s as p,aE as A,aF as M,aG as Qn,aH as Zn,C as b,aI as re,aJ as Ce,aK as Q,aL as we,aM as Xn,aN as We,r as g,aO as ge,aP as ye,aQ as ft,aR as es,aS as ts,aT as ns,aU as ss,b as U,aV as se,aW as te,f as V,T as W,aX as Fe,aY as he,aZ as on,a_ as Z,a$ as de,t as ee,x as $e,b0 as as,b1 as rs,b2 as ke,M as ue,b3 as Te,b4 as cn,b5 as me,b6 as ln,b7 as oe,ay as ce,b8 as Ue,J as ie,b9 as os,ba as is,bb as cs,bc as ut,bd as ls,be as ds,B as K,bf as us,bg as ps,bh as gs,bi as hs,bj as fs,bk as xs,bl as ms,bm as dn,bn as ys,bo as Rt,bp as un,aw as js,bq as Ss,a as xt,ac as Ie,br as Ye,G as Ee,K as bs,bs as mt,h as je,bt as Ae,bu as pn,bv as yt,bw as jt,bx as St,ax as fe,aj as ae,by as bt,bz as gn,aA as Ge,bA as hn,bB as fn,bC as xn,bD as vs,bE as vt,R as Ct,bF as mn,Y as Cs,bG as wt,bH as ve,bI as pe,bJ as yn,a1 as jn,bK as ws,bL as le,bM as Ts,bN as Es,X as As,ai as Ds,bO as Fs,bP as Rs,bQ as $s,bR as ks,bS as Is,bT as Ps,u as Os,bU as Sn,bV as Tt,bW as Bs,bX as Ls,bY as $t,bZ as bn,b_ as vn,b$ as _s,c0 as Cn,c1 as Ms,c2 as qs,c3 as zs,c4 as Et,c5 as Ns,c6 as Ke,c7 as Vs,Q as wn,D as Re,c8 as Hs,c9 as Ws,ca as Us,cb as Ys,cc as Tn,cd as En,ce as Gs,cf as Ks,cg as _e,ch as An,ci as Dn,cj as Fn,ck as xe,cl as pt,cm as Js,cn as Rn,co as Qs,cp as Zs,e as Xs,cq as ea,cr as kt,av as ta,cs as be,ct as It,cu as na,cv as sa,cw as aa,l as ra,at as At,au as oa,ao as Pt,cx as ia,cy as ca,cz as la,cA as Ot,ab as Ne,cB as da,a3 as Ze,af as ua,a5 as pa,a6 as ga,a7 as ha,a8 as fa,a9 as xa,aa as ma,cC as ya,cD as ja,cE as Bt,cF as Sa,cG as ba,cH as Xe,cI as va,cJ as Ca,cK as wa,cL as $n,q as Ta,cM as Lt,cN as Ea,cO as Aa,cP as Da,cQ as Fa,cR as Ra,cS as $a,al as ka,cT as Ia,cU as Pa,cV as Oa,cW as Ba,cX as La,cY as _a,cZ as Ma,c_ as qa}from"./index-YWzEwhTB.js";import{C as kn,u as In,a as za,F as Na,V as Va,b as Ha,c as Wa,T as Ua,d as Ya,W as Ga,e as Ka,f as Ja}from"./FeatureArchiveDialog-L5h4zxtD.js";import{S as Qa}from"./StrategyItemContainer-O6ztV307.js";const Za=ht(t.jsx("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"),Xa=ht(t.jsx("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"),er=ht(t.jsx("path",{d:"M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z"}),"LibraryAdd"),tr=p("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),nr=()=>{const e=A("projectId"),n=A("featureId"),{feature:s}=M(e,n);return s.name?t.jsx(tr,{children:t.jsx(Qn,{title:"Event log",feature:n,displayInline:!0})}):null},sr=p("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,color:e.palette.primary.contrastText,backgroundColor:e.palette.background.alternative,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:e.spacing(2),[e.breakpoints.down(1e3)]:{width:"100%",maxWidth:"none",minWidth:"auto"}})),ar=p("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),rr=p("div")({display:"flex",alignItems:"center"}),or=p("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),ir=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})),Mt=p("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),cr=()=>{const e=A("projectId"),n=A("featureId"),{feature:s}=M(e,n),{project:r,description:a,type:o}=s,i=Xn(o);return t.jsx(sr,{children:t.jsxs(ar,{children:[t.jsxs(rr,{"data-loading":!0,children:[t.jsx(i,{sx:c=>({marginRight:c.spacing(2),height:"40px",width:"40px",fill:c.palette.primary.contrastText})})," ",t.jsxs(or,{children:[Zn(o||"")," toggle"]})]}),t.jsxs(ir,{children:[t.jsxs(_t,{"data-loading":!0,children:["Project: ",r]}),t.jsx(b,{condition:!!a,show:t.jsxs(_t,{"data-loading":!0,children:[t.jsx("div",{children:"Description:"}),t.jsxs(Mt,{children:[t.jsx("p",{children:a}),t.jsx(re,{projectId:e,permission:Ce,component:Q,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t.jsx(we,{sx:c=>({color:c.palette.primary.contrastText})})})]})]}),elseShow:t.jsx("span",{"data-loading":!0,children:t.jsxs(Mt,{children:["No description."," ",t.jsx(re,{projectId:e,permission:Ce,component:Q,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t.jsx(we,{sx:c=>({color:c.palette.primary.contrastText})})})]})})})]})]})})},qt={lastHourUsage:[],seenApplications:[]},lr=(e,n,s={})=>{const r=async()=>{const u=ge(`api/admin/client-metrics/features/${n}`),h=await fetch(u,{method:"GET"}).then(ye("feature metrics"));return h.ok?h.json():qt},a=`${e}_${n}_metrics`,{data:o,error:i}=We(a,r,{...s}),[c,l]=g.useState(!i&&!o),d=()=>{ft(a)};return g.useEffect(()=>{l(!i&&!o)},[o,i]),{metrics:o||qt,error:i,loading:c,refetch:d,FEATURE_METRICS_CACHE_KEY:a}},dr=e=>({yes:0,no:0,environment:e,timestamp:""}),ur=(e,n)=>e.map(s=>n.lastHourUsage.find(a=>a.environment===s.name)||dr(s.name)),pr=e=>(n,s,r)=>(r.revalidateOnFocus=!1,r.revalidateIfStale=!1,r.revalidateOnReconnect=!1,e(n,s,r)),gr=es(We,pr),Pn=(e,n)=>{const{refetchFeature:s}=M(e,n),r=ts(e,n),{data:a,error:o,mutate:i}=gr(["useFeatureImmutable",r],()=>ns(r)),c=g.useCallback(async()=>{await i(),await s()},[i,s]);return{feature:(a==null?void 0:a.body)||ss,refetchFeature:c,loading:!o&&!a,status:a==null?void 0:a.status,error:o}},On=(e,n,s)=>{const{setToastData:r,setToastApiError:a}=U(),{addChange:o}=se(),{refetch:i}=te(e),[c,l]=g.useState({isOpen:!1}),d=g.useCallback((y,T,f)=>{l({featureName:n,environment:y,fromEnvironment:f,strategy:T,isOpen:!0})},[]),u=g.useCallback((y,T,f)=>{l({featureName:n,environment:y,fromEnvironment:f,strategies:T,isOpen:!0})},[]),h=g.useCallback(()=>{l({isOpen:!1})},[]),m=g.useCallback(async()=>{try{await o(e,c.environment,{feature:c.featureName,action:s,payload:c.strategy}),i(),l({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(y){a(V(y)),l({isOpen:!1})}},[o]),j=g.useCallback(async()=>{try{await Promise.all(c.strategies.map(y=>o(e,c.environment,{feature:c.featureName,action:s,payload:y}))),i(),l({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(y){a(V(y)),l({isOpen:!1})}},[o]);return{onChangeRequestAddStrategy:d,onChangeRequestAddStrategies:u,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:m,onChangeRequestAddStrategiesConfirm:j,changeRequestDialogDetails:c}},hr=({payload:e,fromEnvironment:n,environment:s})=>t.jsxs(W,{children:[t.jsxs("strong",{children:["Copy ",Fe((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",s]}),fr=({environmentId:e,environments:n,strategy:s})=>{const r=A("projectId"),a=A("featureId"),[o,i]=g.useState(null),c=!!o,{addStrategyToFeature:l}=he(),{setToastData:d,setToastApiError:u}=U(),{refetchFeature:h}=M(r,a),{refetchFeature:m}=Pn(r,a),j=()=>{i(null)},y=on(r),{isChangeRequestConfigured:T}=Z(r),{changeRequestDialogDetails:f,onChangeRequestAddStrategyClose:x,onChangeRequestAddStrategy:R,onChangeRequestAddStrategyConfirm:L}=On(r,a,"addStrategy"),q=async v=>{const{id:C,...$}={...s,targetEnvironment:v};if(T(v)){await R(v,{id:C,...$},e);return}try{await l(r,a,v,s),h(),m(),d({title:"Strategy created",text:`Successfully copied a strategy to ${v}`,type:"success"})}catch(O){u(V(O))}j()},z=n.some(v=>y(de,v));return t.jsxs("div",{children:[t.jsx(kn,{isOpen:f.isOpen,onClose:x,environment:f==null?void 0:f.environment,onConfirm:L,messageComponent:t.jsx(hr,{fromEnvironment:f.fromEnvironment,payload:f.strategy})}),t.jsx(ee,{title:`Copy to another environment${z?"":" (Access denied)"}`,children:t.jsx("div",{children:t.jsx($e,{size:"large",id:`copy-strategy-icon-menu-${s.id}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:v=>{i(v.currentTarget)},"data-testid":as,disabled:!z,children:t.jsx(rs,{})})})}),t.jsx(ke,{id:"basic-menu",anchorEl:o,open:c,onClose:j,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${s.id}`},children:n.map(v=>{const C=y(de,v);return t.jsx(ee,{title:C?"":"You don't have access to add a strategy to this environment",children:t.jsx("div",{children:t.jsxs(ue,{onClick:()=>q(v),disabled:!C,children:[t.jsx(b,{condition:!C,show:t.jsx(Te,{children:t.jsx(cn,{fontSize:"small"})})}),t.jsxs(me,{children:["Copy to ",v]})]})})},v)})})]})},xr=()=>t.jsx(ie,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),mr=p("div")(({theme:e})=>({"> * + *":{marginTop:e.spacing(1)}})),yr=({changeRequests:e,projectId:n})=>e&&e.length>0?t.jsxs(ie,{severity:"warning",children:[t.jsx("p",{children:"This strategy is in use by at least one scheduled change request. If you remove it, those change requests can no longer be applied."}),t.jsx("p",{children:"The following scheduled change requests use this strategy:"}),t.jsx("ul",{children:e.map(({id:s,title:r})=>{const a=r?`#${s} (${r})`:`#${s}`;return t.jsx("li",{children:t.jsx(Q,{to:`/projects/${n}/change-requests/${s}`,target:"_blank",rel:"noopener noreferrer",title:`Change request ${s}`,children:a})},s)})})]}):e===void 0?t.jsx(ie,{severity:"warning",children:t.jsx("p",{children:"This strategy may be in use by one or more scheduled change requests. If you remove it, those change requests can no longer be applied."})}):null,Bn=({scheduledChangeRequestsForStrategy:e})=>t.jsxs(mr,{children:[t.jsx(xr,{}),t.jsx(yr,{projectId:e.projectId,changeRequests:e.changeRequests})]}),jr=({onRemove:e,onClose:n,isOpen:s,scheduledChangeRequestsForStrategy:r})=>t.jsx(oe,{title:"Are you sure you want to delete this strategy?",open:s,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t.jsx(Bn,{scheduledChangeRequestsForStrategy:r})}),Sr=p("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),br=({onRemove:e,onClose:n,isOpen:s,scheduledChangeRequestsForStrategy:r})=>t.jsxs(oe,{title:"Suggest changes",open:s,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t.jsx(Bn,{scheduledChangeRequestsForStrategy:r}),t.jsx(Sr,{children:t.jsx(W,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t.jsx(W,{fontWeight:"bold",children:"Remove strategy"})]}),vr=({projectId:e,featureId:n,environmentId:s,strategyId:r})=>{const{deleteStrategyFromFeature:a}=he(),{setToastData:o,setToastApiError:i}=U(),c=ce(),{refetchFeature:l}=M(e,n);return async u=>{try{u.preventDefault(),await a(e,n,s,r),o({title:"Strategy deleted",type:"success"}),l(),c(Ue(e,n))}catch(h){i(V(h))}}},Cr=({projectId:e,featureId:n,environmentId:s,strategyId:r})=>{const{addChange:a}=se(),{refetch:o}=te(e),{setToastData:i,setToastApiError:c}=U();return async d=>{try{d.preventDefault(),await a(e,s,{action:"deleteStrategy",feature:n,payload:{id:r}}),i({title:"Changes added to the draft!",type:"success"}),await o()}catch(u){c(V(u))}}},wr=({projectId:e,featureId:n,environmentId:s,strategyId:r,isOpen:a,onClose:o})=>{const{isChangeRequestConfigured:i}=Z(e),{changeRequests:c}=ln(e,r),l={changeRequests:c,projectId:e},d=vr({featureId:n,projectId:e,strategyId:r,environmentId:s}),u=Cr({featureId:n,projectId:e,strategyId:r,environmentId:s});return i(s)?t.jsx(br,{isOpen:a,onClose:()=>o(),onRemove:async h=>{await u(h),o()},scheduledChangeRequestsForStrategy:l}):t.jsx(jr,{isOpen:a,onClose:()=>o(),onRemove:d,scheduledChangeRequestsForStrategy:l})},Tr=({projectId:e,environmentId:n,featureId:s,strategy:r})=>{const{refetchFeature:a}=M(e,s),{setStrategyDisabledState:o}=he(),{setToastData:i,setToastApiError:c}=U(),l=d=>async()=>{try{await o(e,s,n,r.id,!d),i({title:`Strategy ${d?"enabled":"disabled"}`,type:"success"}),a()}catch(u){c(V(u))}};return{onDisable:l(!1),onEnable:l(!0)}},Er=({projectId:e,environmentId:n,featureId:s,strategy:r})=>{const{addChange:a}=se(),{refetch:o}=te(e),{setToastData:i,setToastApiError:c}=U(),l=d=>async()=>{try{await a(e,n,{action:"updateStrategy",feature:s,payload:{...r,disabled:!d}}),i({title:"Changes added to the draft!",type:"success"}),await o()}catch(u){c(V(u))}};return{onSuggestDisable:l(!1),onSuggestEnable:l(!0)}},Ar=({isOpen:e,onClose:n,...s})=>{var j;const{projectId:r,environmentId:a}=s,{isChangeRequestConfigured:o}=Z(r),i=o(a),{onSuggestEnable:c,onSuggestDisable:l}=Er({...s}),{onEnable:d,onDisable:u}=Tr({...s}),h=!!((j=s.strategy)!=null&&j.disabled),m=y=>{y.preventDefault(),i?h?c():l():h?d():u(),n()};return t.jsx(oe,{title:i?`Add ${h?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${h?"enable":"disable"} this strategy?`,open:e,primaryButtonText:i?"Add to draft":`${h?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:m,onClose:()=>n(),children:t.jsx(b,{condition:i,show:t.jsx(os,{environment:a}),elseShow:t.jsxs(ie,{severity:"error",children:[h?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})};var Dt={},Dr=cs;Object.defineProperty(Dt,"__esModule",{value:!0});var Ln=Dt.default=void 0,Fr=Dr(is()),Rr=t,$r=(0,Fr.default)((0,Rr.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"}),"Delete");Ln=Dt.default=$r;const kr=({projectId:e,strategy:n,featureId:s,environmentId:r})=>{const[a,o]=g.useState(null),[i,c]=g.useState(!1),[l,d]=g.useState(!1),u=!!a,h=T=>{o(T.currentTarget)},m=T=>{o(null),T.stopPropagation()},j=ut(ls,e,r),y=ut(ds,e,r);return t.jsxs(t.Fragment,{children:[t.jsx(K,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t.jsx(ee,{title:"More actions",children:t.jsx($e,{onClick:h,size:"small","aria-controls":u?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":u?"true":void 0,"data-testid":us,children:t.jsx(ps,{sx:{width:32,height:32}})})})}),t.jsxs(ke,{anchorEl:a,id:"actions-menu",open:u,onClose:m,onClick:m,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":gs,children:[t.jsx(ee,{title:n.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:t.jsxs(ue,{disabled:!j,onClick:()=>c(!0),children:[t.jsx(Te,{children:n.disabled?t.jsx(hs,{}):t.jsx(fs,{})}),t.jsx(me,{children:n.disabled?"Enable":"Disable"})]})}),t.jsx(ee,{title:"Remove strategy",arrow:!0,placement:"left",children:t.jsxs(ue,{disabled:!y,onClick:()=>d(!0),"data-testid":xs,children:[t.jsx(Te,{children:t.jsx(Ln,{})}),t.jsx(me,{children:"Remove"})]})})]}),t.jsx(Ar,{isOpen:i,onClose:()=>c(!1),projectId:e,featureId:s,environmentId:r,strategy:n}),t.jsx(wr,{isOpen:l,onClose:()=>d(!1),projectId:e,featureId:s,environmentId:r,strategyId:n.id})]})},Ir=({environmentId:e,strategy:n,onDragStart:s,onDragEnd:r,otherEnvironments:a,orderNumber:o,headerChildren:i})=>{const c=A("projectId"),l=A("featureId"),d=ms(c,l,e,n.id);return t.jsxs(Qa,{strategy:n,onDragStart:s,onDragEnd:r,orderNumber:o,actions:t.jsxs(t.Fragment,{children:[i,t.jsx(b,{condition:!!(a&&(a==null?void 0:a.length)>0),show:()=>t.jsx(fr,{environmentId:e,environments:a,strategy:n})}),t.jsx(re,{permission:dn,environmentId:e,projectId:c,component:Q,to:d,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t.jsx(we,{})}),t.jsx(kr,{projectId:c,featureId:l,environmentId:e,strategy:n})]}),children:[t.jsx(ys,{strategy:n}),n.variants&&n.variants.length>0&&(n.disabled?t.jsx(K,{sx:{opacity:"0.5"},children:t.jsx(Rt,{variants:n.variants})}):t.jsx(Rt,{variants:n.variants}))]})},Pr=e=>fetch(e).then(ye("ChangeRequest")).then(n=>n.json()),_n=(e,n)=>{const{data:s,error:r,mutate:a}=un([],ge(`api/admin/projects/${e}/change-requests/pending/${n}`),Pr);return{changeRequests:s,loading:!r&&!s,refetch:a,error:r}},Or=(e,n,s,r)=>{const{user:a}=js(),{changeRequests:o}=_n(e,n),i=[],c=o==null?void 0:o.filter(l=>l.environment===s);return c==null||c.forEach(l=>{const d=l==null?void 0:l.features.find(h=>h.name===n),u=d==null?void 0:d.changes.find(h=>h.action==="updateStrategy"||h.action==="deleteStrategy"?h.payload.id===r:!1);if(u){const h=l.state==="Scheduled",m=!h&&l.createdBy.id===(a==null?void 0:a.id);h&&i.push({changeRequestId:l.id,change:u,isScheduledChange:h}),m&&i.push({changeRequestId:l.id,change:u,isScheduledChange:h})}}),i},Me=p("div")({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}),qe=p("div")(({theme:e})=>({justifyContent:"center",paddingTop:e.spacing(.75),...Ss})),ze=p("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Ft=p(Q)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),Mn=({scheduledChangeRequestIds:e})=>{const n=xt(),s=Ie(n.breakpoints.down("sm")),r=A("projectId");return s?null:t.jsx(K,{sx:{mr:1.5},children:t.jsx(Ye,{tooltip:t.jsx(t.Fragment,{children:e==null?void 0:e.map((a,o)=>t.jsxs(Ft,{to:`/projects/${r}/change-requests/${a}`,children:["Change request #",a]},`${r}-${o}`))}),children:t.jsx(Ee,{color:"warning",children:"Changes Scheduled"})})})},Br=({strategy:e,index:n,environmentName:s,otherEnvironments:r,isDragging:a,onDragStartRef:o,onDragOver:i,onDragEnd:c})=>{const l=A("projectId"),d=A("featureId"),u=g.useRef(null),h=Or(l,d,s,e.id),{changeRequests:m}=ln(l,e.id);return t.jsxs(K,{ref:u,onDragOver:i(u,n),sx:{opacity:a?"0.5":"1"},children:[t.jsx(b,{condition:n>0,show:t.jsx(bs,{text:"OR"})}),t.jsx(Ir,{strategy:e,environmentId:s,otherEnvironments:r,onDragStart:o(u,n),onDragEnd:c,orderNumber:n+1,headerChildren:_r(h,m)})]},e.id)},Lr=({change:e})=>{const n=xt();return Ie(n.breakpoints.down("sm"))?null:t.jsxs(K,{sx:{mr:1.5},children:[t.jsx(b,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t.jsx(Ee,{color:"warning",children:"Modified in draft"})}),t.jsx(b,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t.jsx(Ee,{color:"error",children:"Deleted in draft"})})]})},_r=(e,n)=>{const s=[];if((e==null?void 0:e.length)===0&&(n==null?void 0:n.length)===0)return[];const r=e==null?void 0:e.find(({isScheduledChange:a})=>!a);return r&&s.push(t.jsx(Lr,{change:r.change},`draft-change#${r.change.id}`)),n&&n.length>0&&s.push(t.jsx(Mn,{scheduledChangeRequestIds:n.map(a=>a.id)},"scheduled-changes")),s},Mr=({environmentId:e,environments:n,onClick:s})=>{const r=A("projectId"),[a,o]=g.useState(null),i=!!a,{hasAccess:c}=g.useContext(mt),l=n.some(d=>c(de,r,d));return t.jsxs("div",{children:[t.jsx(ee,{title:l?"":"(Access denied)",children:t.jsx("div",{children:t.jsx(je,{id:`copy-all-strategies-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:d=>{o(d.currentTarget)},disabled:!l,variant:"outlined",children:"Copy from another environment"})})}),t.jsx(ke,{id:"basic-menu",anchorEl:a,open:i,onClose:()=>{o(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(d=>{const u=c(de,r,d);return t.jsx(ee,{title:u?"":"You don't have access to add a strategy to this environment",children:t.jsx("div",{children:t.jsxs(ue,{onClick:()=>s(d),disabled:!u,children:[t.jsx(b,{condition:!u,show:t.jsx(Te,{children:t.jsx(cn,{fontSize:"small"})})}),t.jsxs(me,{children:["Copy from ",d]})]})})},d)})})]})},qr=p("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),zr=({payload:e,fromEnvironment:n,environment:s})=>t.jsxs(qr,{children:[t.jsx(W,{children:t.jsx("strong",{children:"Copy: "})}),e==null?void 0:e.map(r=>t.jsxs(W,{children:[t.jsxs("strong",{children:[Fe((r==null?void 0:r.name)||"")," strategy"," "]})," "]})),t.jsxs(W,{children:["from ",n," to ",s]})]}),qn=(e,n)=>{const s={};return n.parameters.forEach(r=>{s[r.name]=Nr(e,r)}),{name:n.name,constraints:[],parameters:s}},Nr=(e,n)=>n.name==="rollout"||n.name==="percentage"||n.type==="percentage"?"50":n.name==="stickiness"?"":n.name==="groupId"?e:n.type==="boolean"?"false":"",Vr=()=>{const e=A("projectId"),n=A("featureId"),s=Ae("environmentId"),r=Ae("strategyName"),{strategy:a,defaultStrategyFallback:o}=In(e,s),i=JSON.parse(pn().get("defaultStrategy")||"false"),{segments:c}=yt(),l=(c||[]).filter(P=>{var H;return(H=a==null?void 0:a.segments)==null?void 0:H.includes(P.id)}),[d,u]=g.useState({}),[h,m]=g.useState(i?l:[]),{strategyDefinition:j}=jt(r),y=St(),{addStrategyToFeature:T,loading:f}=he(),{addChange:x}=se(),{setToastData:R,setToastApiError:L}=U(),{uiConfig:q}=fe(),{unleashUrl:z}=q,v=ce(),{feature:C,refetchFeature:$}=M(e,n),O=g.useRef(C),{isChangeRequestConfigured:N}=Z(e),{refetch:G}=te(e),{trackEvent:Y}=ae(),{data:S,staleDataNotification:k,forceRefreshCache:w}=bt({unleashGetter:M,params:[e,n],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},C,{afterSubmitAction:$},vt);g.useEffect(()=>{O.current.name===""&&C.name&&(w(C),O.current=C)},[C.name]),g.useEffect(()=>{var P;if(i){const H=a||o;((P=H.parameters)==null?void 0:P.groupId)===""&&n?u({...H,parameters:{...H.parameters,groupId:n}}):u(H)}else j&&u(qn(n,j))},[n,JSON.stringify(j),i]);const E=async P=>{await T(e,n,s,P),R({title:"Strategy created",type:"success",confetti:!0})},F=async P=>{await x(e,s,{action:"addStrategy",feature:n,payload:P}),R({title:"Strategy added to draft",type:"success",confetti:!0}),G()},B=gn(d,h),I=async()=>{Y("strategyTitle",{props:{hasTitle:!!d.title,on:"create"}});try{N(s)?await F(B):await E(B),$(),v(Ue(e,n))}catch(P){L(V(P))}};return!S||!S.project?null:t.jsxs(Ge,{modal:!0,title:Fe(r),description:hn,documentationLink:fn,documentationLinkLabel:xn,formatApiCode:()=>Hr(e,n,s,B,z),children:[t.jsx(vs,{projectId:e,feature:S,strategy:d,setStrategy:u,segments:h,setSegments:m,environmentId:s,onSubmit:I,loading:f,permission:de,errors:y,isChangeRequest:N(s)}),k]})},zn=(e,n,s,r,a=!1)=>{const o=new URLSearchParams({environmentId:s,strategyName:r,defaultStrategy:String(a)});return`/projects/${e}/features/${n}/strategies/create?${o}`},Hr=(e,n,s,r,a)=>{if(!a)return"";const o=`${a}/api/admin/projects/${e}/features/${n}/environments/${s}/strategies`,i=JSON.stringify(r,void 0,2);return`curl --location --request POST '${o}' \\
1
+ import{c as ht,j as t,s as p,aE as A,aF as M,aG as Qn,aH as Zn,C as b,aI as re,aJ as Ce,aK as Q,aL as we,aM as Xn,aN as We,r as g,aO as ge,aP as ye,aQ as ft,aR as es,aS as ts,aT as ns,aU as ss,b as U,aV as se,aW as te,f as V,T as W,aX as Fe,aY as he,aZ as on,a_ as Z,a$ as de,t as ee,x as $e,b0 as as,b1 as rs,b2 as ke,M as ue,b3 as Te,b4 as cn,b5 as me,b6 as ln,b7 as oe,ay as ce,b8 as Ue,J as ie,b9 as os,ba as is,bb as cs,bc as ut,bd as ls,be as ds,B as K,bf as us,bg as ps,bh as gs,bi as hs,bj as fs,bk as xs,bl as ms,bm as dn,bn as ys,bo as Rt,bp as un,aw as js,bq as Ss,a as xt,ac as Ie,br as Ye,G as Ee,K as bs,bs as mt,h as je,bt as Ae,bu as pn,bv as yt,bw as jt,bx as St,ax as fe,aj as ae,by as bt,bz as gn,aA as Ge,bA as hn,bB as fn,bC as xn,bD as vs,bE as vt,R as Ct,bF as mn,Y as Cs,bG as wt,bH as ve,bI as pe,bJ as yn,a1 as jn,bK as ws,bL as le,bM as Ts,bN as Es,X as As,ai as Ds,bO as Fs,bP as Rs,bQ as $s,bR as ks,bS as Is,bT as Ps,u as Os,bU as Sn,bV as Tt,bW as Bs,bX as Ls,bY as $t,bZ as bn,b_ as vn,b$ as _s,c0 as Cn,c1 as Ms,c2 as qs,c3 as zs,c4 as Et,c5 as Ns,c6 as Ke,c7 as Vs,Q as wn,D as Re,c8 as Hs,c9 as Ws,ca as Us,cb as Ys,cc as Tn,cd as En,ce as Gs,cf as Ks,cg as _e,ch as An,ci as Dn,cj as Fn,ck as xe,cl as pt,cm as Js,cn as Rn,co as Qs,cp as Zs,e as Xs,cq as ea,cr as kt,av as ta,cs as be,ct as It,cu as na,cv as sa,cw as aa,l as ra,at as At,au as oa,ao as Pt,cx as ia,cy as ca,cz as la,cA as Ot,ab as Ne,cB as da,a3 as Ze,af as ua,a5 as pa,a6 as ga,a7 as ha,a8 as fa,a9 as xa,aa as ma,cC as ya,cD as ja,cE as Bt,cF as Sa,cG as ba,cH as Xe,cI as va,cJ as Ca,cK as wa,cL as $n,q as Ta,cM as Lt,cN as Ea,cO as Aa,cP as Da,cQ as Fa,cR as Ra,cS as $a,al as ka,cT as Ia,cU as Pa,cV as Oa,cW as Ba,cX as La,cY as _a,cZ as Ma,c_ as qa}from"./index-uUGk-gee.js";import{C as kn,u as In,a as za,F as Na,V as Va,b as Ha,c as Wa,T as Ua,d as Ya,W as Ga,e as Ka,f as Ja}from"./FeatureArchiveDialog-ctoNJoqg.js";import{S as Qa}from"./StrategyItemContainer-X6EIzBwJ.js";const Za=ht(t.jsx("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"),Xa=ht(t.jsx("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"),er=ht(t.jsx("path",{d:"M4 6H2v14c0 1.1.9 2 2 2h14v-2H4V6zm16-4H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-1 9h-4v4h-2v-4H9V9h4V5h2v4h4v2z"}),"LibraryAdd"),tr=p("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),nr=()=>{const e=A("projectId"),n=A("featureId"),{feature:s}=M(e,n);return s.name?t.jsx(tr,{children:t.jsx(Qn,{title:"Event log",feature:n,displayInline:!0})}):null},sr=p("div")(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,color:e.palette.primary.contrastText,backgroundColor:e.palette.background.alternative,display:"flex",flexDirection:"column",maxWidth:"350px",minWidth:"350px",marginRight:e.spacing(2),[e.breakpoints.down(1e3)]:{width:"100%",maxWidth:"none",minWidth:"auto"}})),ar=p("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),rr=p("div")({display:"flex",alignItems:"center"}),or=p("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),ir=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})),Mt=p("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),cr=()=>{const e=A("projectId"),n=A("featureId"),{feature:s}=M(e,n),{project:r,description:a,type:o}=s,i=Xn(o);return t.jsx(sr,{children:t.jsxs(ar,{children:[t.jsxs(rr,{"data-loading":!0,children:[t.jsx(i,{sx:c=>({marginRight:c.spacing(2),height:"40px",width:"40px",fill:c.palette.primary.contrastText})})," ",t.jsxs(or,{children:[Zn(o||"")," toggle"]})]}),t.jsxs(ir,{children:[t.jsxs(_t,{"data-loading":!0,children:["Project: ",r]}),t.jsx(b,{condition:!!a,show:t.jsxs(_t,{"data-loading":!0,children:[t.jsx("div",{children:"Description:"}),t.jsxs(Mt,{children:[t.jsx("p",{children:a}),t.jsx(re,{projectId:e,permission:Ce,component:Q,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t.jsx(we,{sx:c=>({color:c.palette.primary.contrastText})})})]})]}),elseShow:t.jsx("span",{"data-loading":!0,children:t.jsxs(Mt,{children:["No description."," ",t.jsx(re,{projectId:e,permission:Ce,component:Q,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t.jsx(we,{sx:c=>({color:c.palette.primary.contrastText})})})]})})})]})]})})},qt={lastHourUsage:[],seenApplications:[]},lr=(e,n,s={})=>{const r=async()=>{const u=ge(`api/admin/client-metrics/features/${n}`),h=await fetch(u,{method:"GET"}).then(ye("feature metrics"));return h.ok?h.json():qt},a=`${e}_${n}_metrics`,{data:o,error:i}=We(a,r,{...s}),[c,l]=g.useState(!i&&!o),d=()=>{ft(a)};return g.useEffect(()=>{l(!i&&!o)},[o,i]),{metrics:o||qt,error:i,loading:c,refetch:d,FEATURE_METRICS_CACHE_KEY:a}},dr=e=>({yes:0,no:0,environment:e,timestamp:""}),ur=(e,n)=>e.map(s=>n.lastHourUsage.find(a=>a.environment===s.name)||dr(s.name)),pr=e=>(n,s,r)=>(r.revalidateOnFocus=!1,r.revalidateIfStale=!1,r.revalidateOnReconnect=!1,e(n,s,r)),gr=es(We,pr),Pn=(e,n)=>{const{refetchFeature:s}=M(e,n),r=ts(e,n),{data:a,error:o,mutate:i}=gr(["useFeatureImmutable",r],()=>ns(r)),c=g.useCallback(async()=>{await i(),await s()},[i,s]);return{feature:(a==null?void 0:a.body)||ss,refetchFeature:c,loading:!o&&!a,status:a==null?void 0:a.status,error:o}},On=(e,n,s)=>{const{setToastData:r,setToastApiError:a}=U(),{addChange:o}=se(),{refetch:i}=te(e),[c,l]=g.useState({isOpen:!1}),d=g.useCallback((y,T,f)=>{l({featureName:n,environment:y,fromEnvironment:f,strategy:T,isOpen:!0})},[]),u=g.useCallback((y,T,f)=>{l({featureName:n,environment:y,fromEnvironment:f,strategies:T,isOpen:!0})},[]),h=g.useCallback(()=>{l({isOpen:!1})},[]),m=g.useCallback(async()=>{try{await o(e,c.environment,{feature:c.featureName,action:s,payload:c.strategy}),i(),l({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(y){a(V(y)),l({isOpen:!1})}},[o]),j=g.useCallback(async()=>{try{await Promise.all(c.strategies.map(y=>o(e,c.environment,{feature:c.featureName,action:s,payload:y}))),i(),l({isOpen:!1}),r({type:"success",title:"Changes added to the draft!"})}catch(y){a(V(y)),l({isOpen:!1})}},[o]);return{onChangeRequestAddStrategy:d,onChangeRequestAddStrategies:u,onChangeRequestAddStrategyClose:h,onChangeRequestAddStrategyConfirm:m,onChangeRequestAddStrategiesConfirm:j,changeRequestDialogDetails:c}},hr=({payload:e,fromEnvironment:n,environment:s})=>t.jsxs(W,{children:[t.jsxs("strong",{children:["Copy ",Fe((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",s]}),fr=({environmentId:e,environments:n,strategy:s})=>{const r=A("projectId"),a=A("featureId"),[o,i]=g.useState(null),c=!!o,{addStrategyToFeature:l}=he(),{setToastData:d,setToastApiError:u}=U(),{refetchFeature:h}=M(r,a),{refetchFeature:m}=Pn(r,a),j=()=>{i(null)},y=on(r),{isChangeRequestConfigured:T}=Z(r),{changeRequestDialogDetails:f,onChangeRequestAddStrategyClose:x,onChangeRequestAddStrategy:R,onChangeRequestAddStrategyConfirm:L}=On(r,a,"addStrategy"),q=async v=>{const{id:C,...$}={...s,targetEnvironment:v};if(T(v)){await R(v,{id:C,...$},e);return}try{await l(r,a,v,s),h(),m(),d({title:"Strategy created",text:`Successfully copied a strategy to ${v}`,type:"success"})}catch(O){u(V(O))}j()},z=n.some(v=>y(de,v));return t.jsxs("div",{children:[t.jsx(kn,{isOpen:f.isOpen,onClose:x,environment:f==null?void 0:f.environment,onConfirm:L,messageComponent:t.jsx(hr,{fromEnvironment:f.fromEnvironment,payload:f.strategy})}),t.jsx(ee,{title:`Copy to another environment${z?"":" (Access denied)"}`,children:t.jsx("div",{children:t.jsx($e,{size:"large",id:`copy-strategy-icon-menu-${s.id}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:v=>{i(v.currentTarget)},"data-testid":as,disabled:!z,children:t.jsx(rs,{})})})}),t.jsx(ke,{id:"basic-menu",anchorEl:o,open:c,onClose:j,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${s.id}`},children:n.map(v=>{const C=y(de,v);return t.jsx(ee,{title:C?"":"You don't have access to add a strategy to this environment",children:t.jsx("div",{children:t.jsxs(ue,{onClick:()=>q(v),disabled:!C,children:[t.jsx(b,{condition:!C,show:t.jsx(Te,{children:t.jsx(cn,{fontSize:"small"})})}),t.jsxs(me,{children:["Copy to ",v]})]})})},v)})})]})},xr=()=>t.jsx(ie,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),mr=p("div")(({theme:e})=>({"> * + *":{marginTop:e.spacing(1)}})),yr=({changeRequests:e,projectId:n})=>e&&e.length>0?t.jsxs(ie,{severity:"warning",children:[t.jsx("p",{children:"This strategy is in use by at least one scheduled change request. If you remove it, those change requests can no longer be applied."}),t.jsx("p",{children:"The following scheduled change requests use this strategy:"}),t.jsx("ul",{children:e.map(({id:s,title:r})=>{const a=r?`#${s} (${r})`:`#${s}`;return t.jsx("li",{children:t.jsx(Q,{to:`/projects/${n}/change-requests/${s}`,target:"_blank",rel:"noopener noreferrer",title:`Change request ${s}`,children:a})},s)})})]}):e===void 0?t.jsx(ie,{severity:"warning",children:t.jsx("p",{children:"This strategy may be in use by one or more scheduled change requests. If you remove it, those change requests can no longer be applied."})}):null,Bn=({scheduledChangeRequestsForStrategy:e})=>t.jsxs(mr,{children:[t.jsx(xr,{}),t.jsx(yr,{projectId:e.projectId,changeRequests:e.changeRequests})]}),jr=({onRemove:e,onClose:n,isOpen:s,scheduledChangeRequestsForStrategy:r})=>t.jsx(oe,{title:"Are you sure you want to delete this strategy?",open:s,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t.jsx(Bn,{scheduledChangeRequestsForStrategy:r})}),Sr=p("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),br=({onRemove:e,onClose:n,isOpen:s,scheduledChangeRequestsForStrategy:r})=>t.jsxs(oe,{title:"Suggest changes",open:s,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t.jsx(Bn,{scheduledChangeRequestsForStrategy:r}),t.jsx(Sr,{children:t.jsx(W,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t.jsx(W,{fontWeight:"bold",children:"Remove strategy"})]}),vr=({projectId:e,featureId:n,environmentId:s,strategyId:r})=>{const{deleteStrategyFromFeature:a}=he(),{setToastData:o,setToastApiError:i}=U(),c=ce(),{refetchFeature:l}=M(e,n);return async u=>{try{u.preventDefault(),await a(e,n,s,r),o({title:"Strategy deleted",type:"success"}),l(),c(Ue(e,n))}catch(h){i(V(h))}}},Cr=({projectId:e,featureId:n,environmentId:s,strategyId:r})=>{const{addChange:a}=se(),{refetch:o}=te(e),{setToastData:i,setToastApiError:c}=U();return async d=>{try{d.preventDefault(),await a(e,s,{action:"deleteStrategy",feature:n,payload:{id:r}}),i({title:"Changes added to the draft!",type:"success"}),await o()}catch(u){c(V(u))}}},wr=({projectId:e,featureId:n,environmentId:s,strategyId:r,isOpen:a,onClose:o})=>{const{isChangeRequestConfigured:i}=Z(e),{changeRequests:c}=ln(e,r),l={changeRequests:c,projectId:e},d=vr({featureId:n,projectId:e,strategyId:r,environmentId:s}),u=Cr({featureId:n,projectId:e,strategyId:r,environmentId:s});return i(s)?t.jsx(br,{isOpen:a,onClose:()=>o(),onRemove:async h=>{await u(h),o()},scheduledChangeRequestsForStrategy:l}):t.jsx(jr,{isOpen:a,onClose:()=>o(),onRemove:d,scheduledChangeRequestsForStrategy:l})},Tr=({projectId:e,environmentId:n,featureId:s,strategy:r})=>{const{refetchFeature:a}=M(e,s),{setStrategyDisabledState:o}=he(),{setToastData:i,setToastApiError:c}=U(),l=d=>async()=>{try{await o(e,s,n,r.id,!d),i({title:`Strategy ${d?"enabled":"disabled"}`,type:"success"}),a()}catch(u){c(V(u))}};return{onDisable:l(!1),onEnable:l(!0)}},Er=({projectId:e,environmentId:n,featureId:s,strategy:r})=>{const{addChange:a}=se(),{refetch:o}=te(e),{setToastData:i,setToastApiError:c}=U(),l=d=>async()=>{try{await a(e,n,{action:"updateStrategy",feature:s,payload:{...r,disabled:!d}}),i({title:"Changes added to the draft!",type:"success"}),await o()}catch(u){c(V(u))}};return{onSuggestDisable:l(!1),onSuggestEnable:l(!0)}},Ar=({isOpen:e,onClose:n,...s})=>{var j;const{projectId:r,environmentId:a}=s,{isChangeRequestConfigured:o}=Z(r),i=o(a),{onSuggestEnable:c,onSuggestDisable:l}=Er({...s}),{onEnable:d,onDisable:u}=Tr({...s}),h=!!((j=s.strategy)!=null&&j.disabled),m=y=>{y.preventDefault(),i?h?c():l():h?d():u(),n()};return t.jsx(oe,{title:i?`Add ${h?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${h?"enable":"disable"} this strategy?`,open:e,primaryButtonText:i?"Add to draft":`${h?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:m,onClose:()=>n(),children:t.jsx(b,{condition:i,show:t.jsx(os,{environment:a}),elseShow:t.jsxs(ie,{severity:"error",children:[h?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})};var Dt={},Dr=cs;Object.defineProperty(Dt,"__esModule",{value:!0});var Ln=Dt.default=void 0,Fr=Dr(is()),Rr=t,$r=(0,Fr.default)((0,Rr.jsx)("path",{d:"M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"}),"Delete");Ln=Dt.default=$r;const kr=({projectId:e,strategy:n,featureId:s,environmentId:r})=>{const[a,o]=g.useState(null),[i,c]=g.useState(!1),[l,d]=g.useState(!1),u=!!a,h=T=>{o(T.currentTarget)},m=T=>{o(null),T.stopPropagation()},j=ut(ls,e,r),y=ut(ds,e,r);return t.jsxs(t.Fragment,{children:[t.jsx(K,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t.jsx(ee,{title:"More actions",children:t.jsx($e,{onClick:h,size:"small","aria-controls":u?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":u?"true":void 0,"data-testid":us,children:t.jsx(ps,{sx:{width:32,height:32}})})})}),t.jsxs(ke,{anchorEl:a,id:"actions-menu",open:u,onClose:m,onClick:m,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":gs,children:[t.jsx(ee,{title:n.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:t.jsxs(ue,{disabled:!j,onClick:()=>c(!0),children:[t.jsx(Te,{children:n.disabled?t.jsx(hs,{}):t.jsx(fs,{})}),t.jsx(me,{children:n.disabled?"Enable":"Disable"})]})}),t.jsx(ee,{title:"Remove strategy",arrow:!0,placement:"left",children:t.jsxs(ue,{disabled:!y,onClick:()=>d(!0),"data-testid":xs,children:[t.jsx(Te,{children:t.jsx(Ln,{})}),t.jsx(me,{children:"Remove"})]})})]}),t.jsx(Ar,{isOpen:i,onClose:()=>c(!1),projectId:e,featureId:s,environmentId:r,strategy:n}),t.jsx(wr,{isOpen:l,onClose:()=>d(!1),projectId:e,featureId:s,environmentId:r,strategyId:n.id})]})},Ir=({environmentId:e,strategy:n,onDragStart:s,onDragEnd:r,otherEnvironments:a,orderNumber:o,headerChildren:i})=>{const c=A("projectId"),l=A("featureId"),d=ms(c,l,e,n.id);return t.jsxs(Qa,{strategy:n,onDragStart:s,onDragEnd:r,orderNumber:o,actions:t.jsxs(t.Fragment,{children:[i,t.jsx(b,{condition:!!(a&&(a==null?void 0:a.length)>0),show:()=>t.jsx(fr,{environmentId:e,environments:a,strategy:n})}),t.jsx(re,{permission:dn,environmentId:e,projectId:c,component:Q,to:d,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t.jsx(we,{})}),t.jsx(kr,{projectId:c,featureId:l,environmentId:e,strategy:n})]}),children:[t.jsx(ys,{strategy:n}),n.variants&&n.variants.length>0&&(n.disabled?t.jsx(K,{sx:{opacity:"0.5"},children:t.jsx(Rt,{variants:n.variants})}):t.jsx(Rt,{variants:n.variants}))]})},Pr=e=>fetch(e).then(ye("ChangeRequest")).then(n=>n.json()),_n=(e,n)=>{const{data:s,error:r,mutate:a}=un([],ge(`api/admin/projects/${e}/change-requests/pending/${n}`),Pr);return{changeRequests:s,loading:!r&&!s,refetch:a,error:r}},Or=(e,n,s,r)=>{const{user:a}=js(),{changeRequests:o}=_n(e,n),i=[],c=o==null?void 0:o.filter(l=>l.environment===s);return c==null||c.forEach(l=>{const d=l==null?void 0:l.features.find(h=>h.name===n),u=d==null?void 0:d.changes.find(h=>h.action==="updateStrategy"||h.action==="deleteStrategy"?h.payload.id===r:!1);if(u){const h=l.state==="Scheduled",m=!h&&l.createdBy.id===(a==null?void 0:a.id);h&&i.push({changeRequestId:l.id,change:u,isScheduledChange:h}),m&&i.push({changeRequestId:l.id,change:u,isScheduledChange:h})}}),i},Me=p("div")({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}),qe=p("div")(({theme:e})=>({justifyContent:"center",paddingTop:e.spacing(.75),...Ss})),ze=p("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),Ft=p(Q)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),Mn=({scheduledChangeRequestIds:e})=>{const n=xt(),s=Ie(n.breakpoints.down("sm")),r=A("projectId");return s?null:t.jsx(K,{sx:{mr:1.5},children:t.jsx(Ye,{tooltip:t.jsx(t.Fragment,{children:e==null?void 0:e.map((a,o)=>t.jsxs(Ft,{to:`/projects/${r}/change-requests/${a}`,children:["Change request #",a]},`${r}-${o}`))}),children:t.jsx(Ee,{color:"warning",children:"Changes Scheduled"})})})},Br=({strategy:e,index:n,environmentName:s,otherEnvironments:r,isDragging:a,onDragStartRef:o,onDragOver:i,onDragEnd:c})=>{const l=A("projectId"),d=A("featureId"),u=g.useRef(null),h=Or(l,d,s,e.id),{changeRequests:m}=ln(l,e.id);return t.jsxs(K,{ref:u,onDragOver:i(u,n),sx:{opacity:a?"0.5":"1"},children:[t.jsx(b,{condition:n>0,show:t.jsx(bs,{text:"OR"})}),t.jsx(Ir,{strategy:e,environmentId:s,otherEnvironments:r,onDragStart:o(u,n),onDragEnd:c,orderNumber:n+1,headerChildren:_r(h,m)})]},e.id)},Lr=({change:e})=>{const n=xt();return Ie(n.breakpoints.down("sm"))?null:t.jsxs(K,{sx:{mr:1.5},children:[t.jsx(b,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t.jsx(Ee,{color:"warning",children:"Modified in draft"})}),t.jsx(b,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t.jsx(Ee,{color:"error",children:"Deleted in draft"})})]})},_r=(e,n)=>{const s=[];if((e==null?void 0:e.length)===0&&(n==null?void 0:n.length)===0)return[];const r=e==null?void 0:e.find(({isScheduledChange:a})=>!a);return r&&s.push(t.jsx(Lr,{change:r.change},`draft-change#${r.change.id}`)),n&&n.length>0&&s.push(t.jsx(Mn,{scheduledChangeRequestIds:n.map(a=>a.id)},"scheduled-changes")),s},Mr=({environmentId:e,environments:n,onClick:s})=>{const r=A("projectId"),[a,o]=g.useState(null),i=!!a,{hasAccess:c}=g.useContext(mt),l=n.some(d=>c(de,r,d));return t.jsxs("div",{children:[t.jsx(ee,{title:l?"":"(Access denied)",children:t.jsx("div",{children:t.jsx(je,{id:`copy-all-strategies-${e}`,"aria-controls":i?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":i?"true":void 0,onClick:d=>{o(d.currentTarget)},disabled:!l,variant:"outlined",children:"Copy from another environment"})})}),t.jsx(ke,{id:"basic-menu",anchorEl:a,open:i,onClose:()=>{o(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(d=>{const u=c(de,r,d);return t.jsx(ee,{title:u?"":"You don't have access to add a strategy to this environment",children:t.jsx("div",{children:t.jsxs(ue,{onClick:()=>s(d),disabled:!u,children:[t.jsx(b,{condition:!u,show:t.jsx(Te,{children:t.jsx(cn,{fontSize:"small"})})}),t.jsxs(me,{children:["Copy from ",d]})]})})},d)})})]})},qr=p("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),zr=({payload:e,fromEnvironment:n,environment:s})=>t.jsxs(qr,{children:[t.jsx(W,{children:t.jsx("strong",{children:"Copy: "})}),e==null?void 0:e.map(r=>t.jsxs(W,{children:[t.jsxs("strong",{children:[Fe((r==null?void 0:r.name)||"")," strategy"," "]})," "]})),t.jsxs(W,{children:["from ",n," to ",s]})]}),qn=(e,n)=>{const s={};return n.parameters.forEach(r=>{s[r.name]=Nr(e,r)}),{name:n.name,constraints:[],parameters:s}},Nr=(e,n)=>n.name==="rollout"||n.name==="percentage"||n.type==="percentage"?"50":n.name==="stickiness"?"":n.name==="groupId"?e:n.type==="boolean"?"false":"",Vr=()=>{const e=A("projectId"),n=A("featureId"),s=Ae("environmentId"),r=Ae("strategyName"),{strategy:a,defaultStrategyFallback:o}=In(e,s),i=JSON.parse(pn().get("defaultStrategy")||"false"),{segments:c}=yt(),l=(c||[]).filter(P=>{var H;return(H=a==null?void 0:a.segments)==null?void 0:H.includes(P.id)}),[d,u]=g.useState({}),[h,m]=g.useState(i?l:[]),{strategyDefinition:j}=jt(r),y=St(),{addStrategyToFeature:T,loading:f}=he(),{addChange:x}=se(),{setToastData:R,setToastApiError:L}=U(),{uiConfig:q}=fe(),{unleashUrl:z}=q,v=ce(),{feature:C,refetchFeature:$}=M(e,n),O=g.useRef(C),{isChangeRequestConfigured:N}=Z(e),{refetch:G}=te(e),{trackEvent:Y}=ae(),{data:S,staleDataNotification:k,forceRefreshCache:w}=bt({unleashGetter:M,params:[e,n],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},C,{afterSubmitAction:$},vt);g.useEffect(()=>{O.current.name===""&&C.name&&(w(C),O.current=C)},[C.name]),g.useEffect(()=>{var P;if(i){const H=a||o;((P=H.parameters)==null?void 0:P.groupId)===""&&n?u({...H,parameters:{...H.parameters,groupId:n}}):u(H)}else j&&u(qn(n,j))},[n,JSON.stringify(j),i]);const E=async P=>{await T(e,n,s,P),R({title:"Strategy created",type:"success",confetti:!0})},F=async P=>{await x(e,s,{action:"addStrategy",feature:n,payload:P}),R({title:"Strategy added to draft",type:"success",confetti:!0}),G()},B=gn(d,h),I=async()=>{Y("strategyTitle",{props:{hasTitle:!!d.title,on:"create"}});try{N(s)?await F(B):await E(B),$(),v(Ue(e,n))}catch(P){L(V(P))}};return!S||!S.project?null:t.jsxs(Ge,{modal:!0,title:Fe(r),description:hn,documentationLink:fn,documentationLinkLabel:xn,formatApiCode:()=>Hr(e,n,s,B,z),children:[t.jsx(vs,{projectId:e,feature:S,strategy:d,setStrategy:u,segments:h,setSegments:m,environmentId:s,onSubmit:I,loading:f,permission:de,errors:y,isChangeRequest:N(s)}),k]})},zn=(e,n,s,r,a=!1)=>{const o=new URLSearchParams({environmentId:s,strategyName:r,defaultStrategy:String(a)});return`/projects/${e}/features/${n}/strategies/create?${o}`},Hr=(e,n,s,r,a)=>{if(!a)return"";const o=`${a}/api/admin/projects/${e}/features/${n}/environments/${s}/strategies`,i=JSON.stringify(r,void 0,2);return`curl --location --request POST '${o}' \\
2
2
  --header 'Authorization: INSERT_API_KEY' \\
3
3
  --header 'Content-Type: application/json' \\
4
4
  --data-raw '${i}'`},Wr=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}})),Ur=p("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),Yr=p(Ct)(({theme:e})=>({fontWeight:e.fontWeight.bold})),Gr=p(Q)(({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.divider,borderRadius:e.spacing(1),"&:hover, &:focus":{borderColor:e.palette.primary.main}})),et=({projectId:e,featureId:n,environmentId:s,strategy:r,defaultStrategy:a})=>{const o=mn(r.name),i=Fe(r.name),{trackEvent:c}=ae(),l=zn(e,n,s,r.name,a),d=()=>{c("strategy-add",{props:{buttonTitle:r.displayName||i}})};return t.jsxs(Gr,{to:l,onClick:d,children:[t.jsx(Wr,{children:t.jsx(o,{})}),t.jsxs("div",{children:[t.jsx(Yr,{text:r.displayName||i,maxWidth:"200",maxLength:25}),t.jsx(Ur,{children:r.description})]})]})},tt=p(W)(({theme:e})=>({fontSize:e.fontSizes.smallBody,padding:e.spacing(1,2)})),Kr=({projectId:e,featureId:n,environmentId:s})=>{const{strategies:r}=Cs(),a=r.filter(c=>!c.deprecated&&!c.editable),o=r.filter(c=>!c.deprecated&&c.editable),i={name:"flexibleRollout",displayName:"Default strategy",description:"This is the default strategy defined for this environment in the project"};return t.jsxs(wt,{dense:!0,children:[t.jsxs(t.Fragment,{children:[t.jsxs(tt,{color:"textSecondary",children:[s," environment default strategy"]}),t.jsx(ve,{children:t.jsx(et,{projectId:e,featureId:n,environmentId:s,strategy:i,defaultStrategy:!0})},i.name)]}),t.jsx(tt,{color:"textSecondary",children:"Predefined strategy types"}),a.map(c=>t.jsx(ve,{children:t.jsx(et,{projectId:e,featureId:n,environmentId:s,strategy:c})},c.name)),t.jsx(b,{condition:o.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(tt,{color:"textSecondary",children:"Custom strategies"}),o.map(c=>t.jsx(ve,{children:t.jsx(et,{projectId:e,featureId:n,environmentId:s,strategy:c})},c.name))]})})]})},Jr=p("div")({flexShrink:0}),Qr=p(pe)(({theme:e})=>({minWidth:0,width:e.spacing(4.5),alignItems:"center",justifyContent:"center",align:"center",flexDirection:"column",marginLeft:e.spacing(1)})),gt=({label:e,projectId:n,featureId:s,environmentId:r,variant:a,size:o,matchWidth:i})=>{const[c,l]=g.useState(),d=ce(),{trackEvent:u}=ae(),h=!!c,m=h?"FeatureStrategyMenuPopover":void 0,j=()=>{l(void 0)},y=x=>{u("strategy-add",{props:{buttonTitle:e}}),d(f)},T=x=>{l(x.currentTarget)},f=zn(n,s,r,"flexibleRollout",!0);return t.jsxs(Jr,{onClick:x=>x.stopPropagation(),children:[t.jsx(pe,{permission:de,projectId:n,environmentId:r,onClick:y,"aria-labelledby":m,variant:a,size:o,sx:{minWidth:i?"282px":"auto"},children:e}),t.jsx(Qr,{permission:de,projectId:n,environmentId:r,onClick:T,"aria-labelledby":m,variant:"outlined",size:o,hideLockIcon:!0,tooltipProps:{title:"More strategies"},children:t.jsx(yn,{sx:x=>({margin:x.spacing(.25,0)})})}),t.jsx(jn,{id:m,open:h,anchorEl:c,onClose:j,onClick:j,PaperProps:{sx:x=>({paddingBottom:x.spacing(1)})},children:t.jsx(Kr,{projectId:n,featureId:s,environmentId:r})})]})},Zr=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Xr=p("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),eo=p("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),to=({projectId:e,featureId:n,environmentId:s})=>{const{addStrategyToFeature:r}=he(),{setToastData:a,setToastApiError:o}=U(),{refetchFeature:i}=M(e,n),{refetchFeature:c}=Pn(e,n),{feature:l}=M(e,n),d=l==null?void 0:l.environments.filter(R=>R.name!==s&&R.strategies&&R.strategies.length>0),{isChangeRequestConfigured:u}=Z(e),{changeRequestDialogDetails:h,onChangeRequestAddStrategies:m,onChangeRequestAddStrategiesConfirm:j,onChangeRequestAddStrategyClose:y}=On(e,n,"addStrategy"),T=(R=!1)=>{i(),c(),a({title:R?"Strategies created":"Strategy created",text:R?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},f=async R=>{var q;const L=((q=d==null?void 0:d.find(z=>z.name===R))==null?void 0:q.strategies)||[];if(u(s)){await m(s,L,R);return}try{await Promise.all(L.map(z=>{const{id:v,...C}={...z,environment:s};return r(e,n,s,C)})),T(!0)}catch(z){o(V(z))}},x=d&&d.length>0;return t.jsxs(t.Fragment,{children:[t.jsx(kn,{isOpen:h.isOpen,onClose:y,environment:h==null?void 0:h.environment,onConfirm:j,messageComponent:t.jsx(zr,{fromEnvironment:h.fromEnvironment,payload:h.strategies})}),t.jsxs(Zr,{children:[t.jsx(Xr,{children:"You have not defined any strategies yet."}),t.jsxs(eo,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t.jsx(Q,{to:"/admin/api",children:"API key configured"})," for this environment."]}),t.jsxs(K,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t.jsx(gt,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:s,matchWidth:x}),t.jsx(b,{condition:x,show:t.jsx(Mr,{environmentId:s,environments:d.map(R=>R.name),onClick:f})})]})]})]})},no=p("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),so=p("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),ao=({featureEnvironment:e,isDisabled:n,otherEnvironments:s})=>{const r=A("projectId"),a=A("featureId"),{setStrategiesSortOrder:o}=he(),{addChange:i}=se(),{isChangeRequestConfigured:c}=Z(r),{refetch:l}=te(r),{setToastData:d,setToastApiError:u}=U(),{refetchFeature:h}=M(r,a),[m,j]=g.useState((e==null?void 0:e.strategies)||[]),[y,T]=g.useState(null);if(g.useEffect(()=>{j((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const f=async v=>{try{await o(r,a,e.name,v),h(),d({title:"Order of strategies updated",type:"success"})}catch(C){u(V(C))}},x=async v=>{await i(r,e.name,{action:"reorderStrategy",feature:a,payload:v}),d({title:"Strategy execution order added to draft",type:"success",confetti:!0}),l()},R=async v=>{try{c(e.name)?await x(v):await f(v)}catch(C){u(V(C))}},L=(v,C)=>$=>{var O;T({id:m[C].id,index:C,height:((O=v.current)==null?void 0:O.offsetHeight)||0}),v!=null&&v.current&&($.dataTransfer.effectAllowed="move",$.dataTransfer.setData("text/html",v.current.outerHTML),$.dataTransfer.setDragImage(v.current,20,20))},q=v=>(C,$)=>O=>{if(y===null||C.current===null||y.index===$||v===y.id)return;const{top:N,bottom:G}=C.current.getBoundingClientRect(),Y=O.clientY-N<y.height,S=G-O.clientY<y.height,k=y.index>$;if(Y&&k||S&&!k){const w=[...m],E=w.splice(y.index,1)[0];w.splice($,0,E),j(w),T({...y,index:$})}},z=()=>{T(null),R(m.map((v,C)=>({id:v.id,sortOrder:C})))};return t.jsx(no,{children:t.jsxs(so,{children:[t.jsx(b,{condition:m.length>0&&n,show:()=>t.jsx(ie,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t.jsx(b,{condition:m.length>0,show:t.jsx(t.Fragment,{children:m.map((v,C)=>t.jsx(Br,{strategy:v,index:C,environmentName:e.name,otherEnvironments:s,isDragging:(y==null?void 0:y.id)===v.id,onDragStartRef:L,onDragOver:q(v.id),onDragEnd:z},v.id))}),elseShow:t.jsx(to,{projectId:r,featureId:a,environmentId:e.name})})]})})},Nn=(e,n)=>e===0?0:Math.round(n/e*100);var Je={},Qe={};Object.defineProperty(Qe,"__esModule",{value:!0});Qe.defaultOptions=void 0;Qe.defaultOptions={lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var ne={};Object.defineProperty(ne,"__esModule",{value:!0});ne.getLocales=ne.getFractionDigits=ne.roundTo=ne.parseValue=void 0;function ro(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}ne.parseValue=ro;function oo(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))}ne.roundTo=oo;function io(e){var n;if(Number.isInteger(e))return 0;const s=e.toString().split(".")[1];return(n=s==null?void 0:s.length)!==null&&n!==void 0?n:0}ne.getFractionDigits=io;function co(){var e;return typeof navigator>"u"?[]:Array.from((e=navigator.languages)!==null&&e!==void 0?e:[])}ne.getLocales=co;Object.defineProperty(Je,"__esModule",{value:!0});Je.millify=void 0;const zt=Qe,Oe=ne,Nt=1e3;function*Vt(e){let n=Nt;for(;;){const s=e/n;if(s<1)return;yield s,n*=Nt}}function Vn(e,n){var s,r;const a=n?{...zt.defaultOptions,...n}:zt.defaultOptions;if(!Array.isArray(a.units)||!a.units.length)throw new Error("Option `units` must be a non-empty array");let o;try{o=Oe.parseValue(e)}catch(y){return y instanceof Error&&console.warn(`WARN: ${y.message} (millify)`),String(e)}const i=o<0?"-":"";o=Math.abs(o);let c=0;for(const y of Vt(o))o=y,c+=1;if(c>=a.units.length)return e.toString();let d=Oe.roundTo(o,a.precision);for(const y of Vt(d))d=y,c+=1;const u=(s=a.units[c])!==null&&s!==void 0?s:"",h=a.lowercase?u.toLowerCase():u,m=a.space?" ":"",j=d.toLocaleString((r=a.locales)!==null&&r!==void 0?r:Oe.getLocales(),{minimumFractionDigits:Oe.getFractionDigits(d)});return`${i}${j}${m}${h}`}Je.millify=Vn;var lo=Je.default=Vn;const Ve=({value:e,threshold:n=1e6,precision:s=2})=>{let r,a=!1;e<n?r=e.toLocaleString():(r=lo(e,{precision:s}),a=!0);const o=t.jsx("span",{"data-testid":ws,children:r});return t.jsx(b,{condition:a,show:t.jsx(ee,{title:e.toLocaleString(),arrow:!0,children:o}),elseShow:o})},uo=e=>e>48?`${Math.floor(e/24)} days (UTC)`:`${e} hours (local time)`,nt=p("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),st=p("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),at=p("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),rt=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.divider,fontSize:e.fontSizes.smallerBody,color:e.palette.text.secondary})),Hn=({totalYes:e,totalNo:n,hoursBack:s,statsSectionId:r,tableSectionId:a})=>{const o=s===1?"in the last hour":`in the last ${uo(s)}`;return t.jsxs(le,{container:!0,spacing:2,id:r,"aria-describedby":a,"aria-label":"Feature metrics summary",component:"section",children:[t.jsx(le,{item:!0,xs:12,sm:4,children:t.jsxs(nt,{children:[t.jsx(st,{children:"Exposure"}),t.jsx(at,{children:t.jsx(Ve,{value:e})}),t.jsxs(rt,{children:["Total exposure of the feature in the environment"," ",o,"."]})]})}),t.jsx(le,{item:!0,xs:12,sm:4,children:t.jsxs(nt,{children:[t.jsx(st,{children:"Exposure %"}),t.jsxs(at,{children:[Nn(e+n,e),"%"]}),t.jsxs(rt,{children:["% total exposure of the feature in the environment"," ",o,"."]})]})}),t.jsx(le,{item:!0,xs:12,sm:4,children:t.jsxs(nt,{children:[t.jsx(st,{children:"Requests"}),t.jsx(at,{children:t.jsx(Ve,{value:e+n})}),t.jsxs(rt,{children:["Total requests for the feature in the environment"," ",o,"."]})]})})]})},po=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.divider}})),go=p("span")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",padding:"0 1rem",background:e.palette.envAccordion.expanded,position:"relative",maxWidth:"80%",color:e.palette.text.primary})),ho=({children:e})=>t.jsx(po,{children:t.jsx(go,{children:e})}),fo=({environmentMetric:e})=>e?t.jsxs(t.Fragment,{children:[t.jsx(ho,{children:"Feature toggle exposure"}),t.jsx("div",{children:t.jsx(Hn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Ht=p("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),Wt=p("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Ut=p("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Yt=p("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),xo=p(Ts)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),mo=p("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),yo=({environmentMetric:e,disabled:n=!1})=>{const s=Es();if(!e)return null;const r=e.yes+e.no,a=Nn(r,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?t.jsxs(Ht,{children:[t.jsxs(Wt,{children:[t.jsxs(Ut,{style:{color:n?s.palette.text.secondary:void 0},"data-loading":!0,children:[a,"%"]}),t.jsxs(Yt,{style:{color:n?s.palette.text.secondary:s.palette.text.primary},"data-loading":!0,children:["The feature has been requested ",t.jsx("b",{children:"0 times"})," and exposed",t.jsx("b",{children:" 0 times"})," in the last hour"]})]}),t.jsx(xo,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):t.jsxs(Ht,{children:[t.jsxs(Wt,{children:[t.jsxs(Ut,{children:[a,"%"]}),t.jsxs(Yt,{children:["The feature has been requested"," ",t.jsxs("b",{children:[t.jsx(Ve,{value:r})," times"]})," ","and exposed"," ",t.jsxs("b",{children:[t.jsx(Ve,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t.jsx(mo,{"data-loading":!0,children:t.jsx(As,{percentage:a,size:"3rem"})})]})},ot=({strategy:e})=>{const n=mn(e.name);return t.jsx(ee,{title:Fe(e.name)+(e.title?` - ${e.title}`:""),arrow:!0,children:t.jsx(jo,{children:t.jsx(n,{})})})},jo=p("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"center",color:e.palette.action.disabled,"& svg":{width:e.spacing(2.5),height:e.spacing(2.5)}})),Gt=p("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),it=p("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),So=p("div")(({theme:e})=>({display:"flex",flexDirection:"row",alignItems:"center",gap:e.spacing(1)})),Be=5,bo=({strategies:e})=>e!=null&&e.length?e.length>Be+1?t.jsxs(Gt,{"aria-label":"Feature strategies",children:[e.slice(0,Be).map(n=>t.jsx(it,{children:t.jsx(ot,{strategy:n})},n.id)),t.jsxs(Ye,{tooltip:e.slice(Be).map(n=>t.jsx(it,{children:t.jsxs(So,{children:[t.jsx(ot,{strategy:n})," ",Fe(n.name)+(n.title?` - ${n.title}`:"")]})},n.id)),children:["(+",e.length-Be,")"]})]}):t.jsx(Gt,{"aria-label":"Feature strategies",children:e.map(n=>t.jsx(it,{children:t.jsx(ot,{strategy:n})},n.id))}):null,Wn=()=>{const{value:e,setValue:n}=Ds("global:v1",{});return{value:{...e,hiddenEnvironments:Array.from(e.hiddenEnvironments||[])},setValue:n}},vo=p("div",{shouldForwardProp:e=>e!=="enabled"})(({theme:e,enabled:n})=>({borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2),backgroundColor:n?e.palette.background.paper:e.palette.envAccordion.disabled})),Co=p(Fs)({boxShadow:"none",background:"none"}),wo=p(Rs)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),To=p($s,{shouldForwardProp:e=>e!=="enabled"})(({theme:e})=>({padding:e.spacing(3),background:e.palette.envAccordion.expanded,borderBottomLeftRadius:e.shape.borderRadiusLarge,borderBottomRightRadius:e.shape.borderRadiusLarge,boxShadow:"inset 0px 2px 4px rgba(32, 32, 33, 0.05)",[e.breakpoints.down("md")]:{padding:e.spacing(2,1)}})),Eo=p(ao)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Ao=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})),Do=p("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Fo=p(ks)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Ro=p(Ct)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),$o=p("div")(({theme:e})=>({display:"flex",alignItems:"center",marginTop:e.spacing(2),gap:e.spacing(2),flexWrap:"wrap",[e.breakpoints.down(560)]:{flexDirection:"column"}})),ko=({env:e})=>{var d;const n=A("projectId"),s=A("featureId"),{metrics:r}=lr(n,s),{feature:a}=M(n,s),{value:o}=Wn(),c=ur(a==null?void 0:a.environments,r).find(u=>u.environment===e.name),l=a==null?void 0:a.environments.find(u=>u.name===e.name);return t.jsx(b,{condition:!new Set(o.hiddenEnvironments).has(e.name),show:t.jsx(vo,{enabled:e.enabled,children:t.jsxs(Co,{TransitionProps:{mountOnEnter:!0},"data-testid":`${Is}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[t.jsxs(wo,{expandIcon:t.jsx(Ps,{titleAccess:"Toggle"}),children:[t.jsxs(Ao,{"data-loading":!0,enabled:e.enabled,children:[t.jsxs(Do,{children:[t.jsx(Fo,{enabled:e.enabled}),t.jsx("div",{children:t.jsx(Ro,{text:e.name,maxWidth:"100",maxLength:15})}),t.jsx(b,{condition:!e.enabled,show:t.jsx(Ee,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),t.jsxs($o,{children:[t.jsx(gt,{label:"Add strategy",projectId:n,featureId:s,environmentId:e.name,variant:"outlined",size:"small"}),t.jsx(bo,{strategies:l==null?void 0:l.strategies})]})]}),t.jsx(yo,{environmentMetric:c,disabled:!e.enabled})]}),t.jsxs(To,{enabled:e.enabled,children:[t.jsx(Eo,{featureEnvironment:l,isDisabled:!e.enabled,otherEnvironments:a==null?void 0:a.environments.map(({name:u})=>u).filter(u=>u!==e.name)}),t.jsx(b,{condition:(((d=l==null?void 0:l.strategies)==null?void 0:d.length)||0)>0,show:t.jsxs(t.Fragment,{children:[t.jsx(K,{sx:{display:"flex",justifyContent:"center",py:1},children:t.jsx(gt,{label:"Add strategy",projectId:n,featureId:s,environmentId:e.name})}),t.jsx(fo,{environmentMetric:c})]})})]})]})})})},Io=()=>{const e=A("projectId"),n=A("featureId"),{feature:s}=M(e,n);if(!s)return null;const{environments:r}=s;return t.jsx(t.Fragment,{children:r==null?void 0:r.map(a=>t.jsx(ko,{env:a},a.name))})},Un=e=>{const{makeRequest:n,createRequest:s,errors:r,loading:a}=Os({propagateErrors:!0}),o=async(d,u)=>{const h=s(`/api/admin/projects/${e}/features/${d}/dependencies`,{method:"POST",body:JSON.stringify(u)});await n(h.caller,h.id)},i=async(d,u)=>{const h=s(`/api/admin/projects/${e}/features/${d}/dependencies/${u}`,{method:"DELETE"});await n(h.caller,h.id)},c=async d=>{const u=s(`/api/admin/projects/${e}/features/${d}/dependencies`,{method:"DELETE"});await n(u.caller,u.id)},l=[s,n,V,e];return{addDependency:g.useCallback(o,l),removeDependency:g.useCallback(i,l),removeDependencies:g.useCallback(c,l),errors:r,loading:a}},Po=(e,n,s={})=>{const r=ge(`/api/admin/projects/${e}/features/${n}/parents`),{data:a,error:o,mutate:i}=We(r,Oo,s);return{parentOptions:a,error:o,loading:!o&&!a}},Oo=async e=>await(await fetch(e).then(ye("Parent Options"))).json(),Bo=()=>t.jsxs(ie,{severity:"warning",children:["Remember to update your Unleash client! Feature dependencies require new SDK versions. Read more about ",t.jsx(Lo,{}),"."]}),Lo=()=>t.jsx("a",{href:"https://docs.getunleash.io/reference/dependent-features#client-sdk-support",target:"_blank",rel:"noreferrer",children:"Client SDK support for feature dependencies"}),_o=p(Sn)(({theme:e})=>({marginTop:e.spacing(2),marginBottom:e.spacing(1.5)})),De={key:"none (remove dependency)",label:"none (remove dependency)"},Mo=({project:e,featureId:n,parent:s,onSelect:r})=>{const{parentOptions:a,loading:o}=Po(e,n),i=a?[De,...a.map(c=>({key:c,label:c}))]:[De];return t.jsx(_o,{fullWidth:!0,options:i,value:s,onChange:r})},qo=(e,n,s,r)=>{const{trackEvent:a}=ae(),{addChange:o}=se(),{refetch:i}=te(e),{setToastData:c,setToastApiError:l}=U(),{refetchFeature:d}=M(e,n),u=Tt(e)(),{isChangeRequestConfiguredInAnyEnv:h}=Z(e),{addDependency:m,removeDependencies:j}=Un(e),y=async f=>{if(!u){console.error("No change request environment");return}f==="addDependency"&&(await o(e,u,[{action:f,feature:n,payload:{feature:s}}]),a("dependent_features",{props:{eventType:"dependency added"}})),f==="deleteDependency"&&await o(e,u,[{action:f,feature:n,payload:void 0}]),i(),c({text:f==="addDependency"?`${n} will depend on ${s}`:`${n} dependency will be removed`,type:"success",title:"Change added to a draft"})};return async()=>{try{if(h()){const f=s===De.key?"deleteDependency":"addDependency";await y(f),a("dependent_features",{props:{eventType:f==="addDependency"?"add dependency added to change request":"delete dependency added to change request"}})}else s===De.key?(await j(n),a("dependent_features",{props:{eventType:"dependency removed"}}),c({title:"Dependency removed",type:"success"})):(await m(n,{feature:s}),a("dependent_features",{props:{eventType:"dependency added"}}),c({title:"Dependency added",type:"success"}))}catch(f){l(V(f))}await d(),r()}},zo=({project:e,featureId:n,showDependencyDialogue:s,onClose:r})=>{const[a,o]=g.useState(De.key),i=qo(e,n,a,r),{isChangeRequestConfiguredInAnyEnv:c}=Z(e);return t.jsx(oe,{open:s,title:"Add parent feature dependency",onClose:r,onClick:i,primaryButtonText:c()?"Add change to draft":a===De.key?"Remove":"Add",secondaryButtonText:"Cancel",children:t.jsxs(K,{children:[t.jsx(Bo,{}),t.jsx(K,{sx:{mt:2,mb:4},children:"Your feature will be evaluated only when the selected parent feature is enabled in the same environment."}),t.jsx(W,{children:"What feature do you want to depend on?"}),t.jsx(b,{condition:s,show:t.jsx(Mo,{project:e,featureId:n,parent:a,onSelect:o})})]})})},No=p(jn)(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,padding:e.spacing(1,1.5)})),Vo=({feature:e,onEdit:n,onDelete:s})=>{const r=`dependency-${e}-actions`,a=`${r}-menu`,[o,i]=g.useState(null),c=!!o,l=u=>{i(u.currentTarget)},d=()=>{i(null)};return t.jsxs("span",{children:[t.jsx(ee,{title:"Dependency actions",arrow:!0,describeChild:!0,children:t.jsx($e,{id:r,"aria-controls":c?a:void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:l,type:"button",children:t.jsx(yn,{})})}),t.jsx(No,{id:a,anchorEl:o,open:c,onClose:d,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},disableScrollLock:!0,children:t.jsxs(Bs,{"aria-labelledby":r,children:[t.jsx(b,{condition:!0,show:t.jsxs(ue,{onClick:()=>{n(),d()},children:[t.jsx(Te,{children:t.jsx(we,{})}),t.jsx(me,{children:t.jsx(W,{variant:"body2",children:"Edit"})})]})}),t.jsx(b,{condition:!0,show:t.jsxs(ue,{onClick:()=>{s(),d()},children:[t.jsx(Te,{children:t.jsx(Ls,{})}),t.jsx(me,{children:t.jsx(W,{variant:"body2",children:"Delete"})})]})})]})})]})},Yn=({childFeatures:e,project:n})=>t.jsx(Ye,{tooltip:t.jsx(t.Fragment,{children:e.map(s=>t.jsx(Ft,{to:`/projects/${n}/features/${s}`,children:t.jsx("div",{children:s})},`${n}-${s}`))}),children:e.length===1?"1 feature":`${e.length} features`}),Ho=(e,n)=>{const{trackEvent:s}=ae(),{addChange:r}=se(),{refetch:a}=te(e),{setToastData:o,setToastApiError:i}=U(),{refetchFeature:c}=M(e,n),l=Tt(e)(),{isChangeRequestConfiguredInAnyEnv:d}=Z(e),{removeDependencies:u}=Un(e),h=async()=>{if(!l){console.error("No change request environment");return}await r(e,l,[{action:"deleteDependency",feature:n,payload:void 0}])};return async()=>{try{d()?(await h(),s("dependent_features",{props:{eventType:"delete dependency added to change request"}}),o({text:`${n} dependency will be removed`,type:"success",title:"Change added to a draft"}),await a()):(await u(n),s("dependent_features",{props:{eventType:"dependency removed"}}),o({title:"Dependency removed",type:"success"}),await c())}catch(j){i(V(j))}}},Wo=({feature:e})=>{var d,u;const[n,s]=g.useState(!1),r=!!e.project&&e.dependencies.length===0&&e.children.length===0,a=!!e.project&&e.dependencies.length>0,o=!!e.project&&e.children.length>0,i=Tt(e.project)(),c=on(e.project),l=Ho(e.project,e.name);return t.jsxs(t.Fragment,{children:[t.jsx(b,{condition:r,show:t.jsx(Me,{children:t.jsxs(qe,{children:[t.jsx(ze,{children:"Dependency:"}),t.jsx(pe,{permission:$t,projectId:e.project,variant:"text",onClick:()=>{s(!0)},children:"Add parent feature"})]})})}),t.jsx(b,{condition:a,show:t.jsxs(Me,{children:[t.jsxs(qe,{children:[t.jsx(ze,{children:"Dependency:"}),t.jsx(Ft,{to:`/projects/${e.project}/features/${(d=e.dependencies[0])==null?void 0:d.feature}`,children:(u=e.dependencies[0])==null?void 0:u.feature})]}),t.jsx(b,{condition:c($t,i),show:t.jsx(Vo,{feature:e.name,onEdit:()=>s(!0),onDelete:l})})]})}),t.jsx(b,{condition:o,show:t.jsx(Me,{children:t.jsxs(qe,{children:[t.jsx(ze,{children:"Children:"}),t.jsx(Yn,{childFeatures:e.children,project:e.project})]})})}),t.jsx(b,{condition:!!e.project,show:t.jsx(zo,{project:e.project,featureId:e.name,onClose:()=>s(!1),showDependencyDialogue:n})})]})},Uo=(e,n={})=>{const s=ge(`/api/admin/projects/${e}/dependencies`),{data:r,error:a}=bn(e,!1,s,Yo,n);return{dependenciesExist:r,error:a,loading:!a&&!r}},Yo=async e=>await(await fetch(e).then(ye("Dependencies exist check"))).json(),Go=e=>{const{dependenciesExist:n}=Uo(e),{isOss:s}=fe();return!!(!s()||n)},Ko=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",justifyItems:"center",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),Jo=({feature:e,header:n})=>{var o;const{locationSettings:s}=vn();fe();const r=Go(e.project),a=(o=e.environments)==null?void 0:o.map(i=>({name:i.name,lastSeenAt:i.lastSeenAt,enabled:i.enabled}));return t.jsxs(Ko,{children:[n,t.jsxs(Me,{children:[t.jsxs(qe,{children:[t.jsx(ze,{children:"Created at:"}),t.jsx("span",{children:_s(Cn(e.createdAt),s.locale)})]}),t.jsx(Ms,{featureLastSeen:e.lastSeenAt,environments:a,sx:{p:0}})]}),t.jsx(b,{condition:r,show:t.jsx(Wo,{feature:e})})]})},Qo=p($e,{shouldForwardProp:e=>e!=="visibilityOff"})(({theme:e,visibilityOff:n})=>({marginLeft:"auto",marginRight:e.spacing(-1),color:n?e.palette.action.active:e.palette.action.focus,"&:hover":{color:e.palette.action.active}})),Zo=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:s})=>{const r=()=>{s(e.name)};return t.jsx(Qo,{onClick:r,visibilityOff:n.has(e.name),children:t.jsx(b,{condition:n.has(e.name),show:t.jsx(qs,{}),elseShow:t.jsx(zs,{})})})},Xo=p("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),ei=p("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),ti=({environment:e,callback:n,children:s,hiddenEnvironments:r,setHiddenEnvironments:a})=>{const o=A("projectId"),i=A("featureId"),{feature:c,refetchFeature:l}=M(o,i),{isChangeRequestConfigured:d}=Z(o),u=t.jsxs(t.Fragment,{children:[" ",t.jsxs("span",{"data-loading":!0,children:[e.enabled?"enabled":"disabled"," in"]})," ",t.jsx(Ct,{text:e.name,maxWidth:"120",maxLength:15})]}),{onToggle:h,modals:m}=za(o),j=(y,T)=>h(y,{projectId:o,featureId:i,environmentName:e.name,environmentType:e.type,hasStrategies:e.strategies.length>0,hasEnabledStrategies:e.strategies.some(f=>!f.disabled),isChangeRequestEnabled:d(e.name),onRollback:T,onSuccess:()=>{n&&n(),l()}});return t.jsxs(Xo,{children:[t.jsxs(ei,{children:[t.jsx(Na,{featureId:c.name,projectId:o,environmentName:e.name,onToggle:j,value:e.enabled}),s??u]}),t.jsx(Zo,{environment:e,hiddenEnvironments:r,setHiddenEnvironments:a}),m]})},ni=p("div")(({theme:e})=>({padding:e.spacing(3)})),si=p("div")(()=>({display:"flex",flexDirection:"column"})),ai=p("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),ri=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Kt=p("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),oi=p(Et)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),ii=({feature:e,header:n,hiddenEnvironments:s,setHiddenEnvironments:r})=>{const a=e.environments.some(o=>{var i;return o.enabled&&((i=o.variants)==null?void 0:i.length)});return t.jsxs(ni,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(o=>{const i=o.strategies.length===1?"1 strategy":`${o.strategies.length} strategies`,c=o.variants??[],l=c.length>0&&t.jsxs(t.Fragment,{children:[t.jsx(Kt,{}),t.jsx(ee,{title:"View variants",arrow:!0,describeChild:!0,children:t.jsx(oi,{component:Q,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:c.length===1?"1 variant":`${c.length} variants`})})]}),d=o.enabled&&c.length===0&&a;return t.jsx(ti,{environment:o,hiddenEnvironments:s,setHiddenEnvironments:r,children:t.jsxs(si,{children:[t.jsx(ai,{children:o.name}),t.jsxs(ri,{children:[i,l,t.jsx(b,{condition:d,show:t.jsxs(t.Fragment,{children:[t.jsx(Kt,{}),t.jsx(Va,{})]})})]})]})},o.name)})]})},Gn=(e,n={})=>{const s=async()=>{const d=ge(`api/admin/features/${e}/tags`);return(await fetch(d,{method:"GET"}).then(ye("Tags"))).json()},r=`api/admin/features/${e}/tags`,{data:a,error:o}=bn(!!e,{tags:[]},r,s,n),[i,c]=g.useState(!o&&!a),l=()=>{ft(r)};return g.useEffect(()=>{c(!o&&!a)},[a,o]),{tags:(a==null?void 0:a.tags)||[],error:o,loading:i,refetch:l}},ci=p("section")(({theme:e})=>({"& > *":{margin:e.spacing(1,0)}})),ct=e=>e.map(n=>({title:n.value})),Jt=(e,n)=>e.map(s=>({value:s.title,type:n})),Kn=({open:e,setOpen:n})=>{const{tagTypes:s}=Ns(),r=A("featureId"),{createTag:a}=Ha(),{updateFeatureTags:o,loading:i}=Ke(),{tags:c,refetch:l,loading:d}=Gn(r),{setToastData:u}=U(),h=s&&s.length>0?s[0]:{name:"simple",description:"Simple tag to get you started",icon:""},[m,j]=g.useState(h),y=i||d,[T,f]=g.useState(0),{trackEvent:x}=ae(),[R,L]=g.useState(ct(c.filter(E=>E.type===m.name))),{tags:q,refetch:z}=Wa(m.name),v=g.useMemo(()=>ct(q),[q]);g.useEffect(()=>{c&&m&&L(ct(c.filter(E=>E.type===m.name)))},[JSON.stringify(c),m]);const C=()=>{n(!1),L([])};function $(E,F){const B=E.filter(_=>_.type===m.name).filter(_=>!F.find(P=>_.value===P.value&&_.type===P.type)),I=F.filter(_=>_.type===m.name).filter(_=>!E.find(P=>_.value===P.value&&_.type===P.type));return f(B.length+I.length),{added:B,removed:I}}const O=E=>E.filter(F=>!F.title.startsWith("Create")),N=async(E,F)=>{try{await o(r,{addedTags:E,removedTags:F}),await l()}catch(B){const I=V(B);u({type:"error",title:"Failed to add tag",text:I,confetti:!1})}},G=(E,F)=>{let B="We successfully";return E>0&&(B=B.concat(` added ${E} new tag${E>1?"s":""}`)),E>0&&F>0&&(B=B.concat(" and ")),F>0&&(B=B.concat(` removed ${F} tag${F>1?"s":""}`)),B},Y=async E=>{E.preventDefault();const F=Jt(O(R),m.name),{added:B,removed:I}=$(F,c);T>0&&(await N(B,I),T>1&&x("suggest_tags",{props:{eventType:"multiple_tags_added"}}),T>0&&u({type:"success",title:`Updated tag${B.length>1?"s":""} to toggle`,text:G(B.length,I.length),confetti:!0})),f(0),L([]),n(!1)},S=(E,F)=>{F!=null&&typeof F!="string"&&(E.preventDefault(),j(F),L([]),f(0))},k=(E,F,B)=>{const I=Vs(F);B==="selectOption"&&F.forEach((P,H)=>{if(typeof P!="string"&&P.inputValue&&P.inputValue!==""){const J={value:P.inputValue,type:m.name};a(J).then(()=>{x("suggest_tags",{props:{eventType:"tag_created"}}),z()}),P.title=P.inputValue,P.inputValue="",I[H]=P}});const _=Jt(O(I),m.name);$(_,c),L(I)},w="add-tag-form";return t.jsx(oe,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update feature toggle tags",onClick:Y,disabledPrimaryButton:y||T===0,onClose:C,formId:w,children:t.jsxs(t.Fragment,{children:[t.jsx(W,{paragraph:!0,sx:{marginBottom:E=>E.spacing(2.5)},children:"Tags allow you to group features together"}),t.jsx("form",{id:w,onSubmit:Y,children:t.jsxs(ci,{children:[t.jsx(Ua,{options:s,value:m,onChange:S}),t.jsx(Ya,{options:v,existingTags:c,tagType:m,selectedOptions:R,onChange:k})]})})]})})},li=p("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),di=p("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),ui=p(wn)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),pi=p(Re)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),gi=p(je)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),hi=({feature:e,header:n})=>{const{tags:s,refetch:r}=Gn(e.name),{deleteTagFromFeature:a}=Ke(),[o,i]=g.useState(!1),[c,l]=g.useState(!1),[d,u]=g.useState(),{setToastData:h,setToastApiError:m}=U(),{hasAccess:j}=g.useContext(mt),y=j(Ce,e.project),T=async()=>{if(d)try{await a(e.name,d.type,d.value),r(),h({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(f){m(V(f))}};return t.jsxs(li,{children:[n,t.jsx(di,{children:s.map(f=>{const x=`${f.type}:${f.value}`;return t.jsx(ui,{label:x,deleteIcon:t.jsx(Hs,{titleAccess:"Remove"}),onDelete:y?()=>{l(!0),u(f)}:void 0},x)})}),t.jsx(b,{condition:y,show:t.jsxs(t.Fragment,{children:[t.jsx(b,{condition:s.length>0,show:t.jsx(pi,{})}),t.jsx(gi,{"data-loading":!0,variant:"outlined",startIcon:t.jsx(Ws,{}),onClick:()=>i(!0),children:"Add new tag"})]})}),t.jsx(Kn,{open:o,setOpen:i}),t.jsxs(oe,{open:c,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{l(!1),u(void 0)},onClick:()=>{l(!1),T(),u(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",t.jsxs("strong",{children:[d==null?void 0:d.type,":",d==null?void 0:d.value]})]})]})},fi=p(K)(({theme:e})=>({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"}})),lt=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}})),xi=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{var i;const s=A("projectId"),r=A("featureId"),{feature:a}=M(s,r),o=((i=a.environments)==null?void 0:i.length)<=3;return t.jsxs(fi,{as:o?Us:K,children:[t.jsx(ii,{header:t.jsxs(lt,{"data-loading":!0,children:["Enabled in environments (",a.environments.filter(({enabled:c})=>c).length,")",t.jsx(Ys,{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:a,hiddenEnvironments:e,setHiddenEnvironments:n}),t.jsx(Re,{}),t.jsx(Jo,{header:t.jsx(lt,{"data-loading":!0,children:"Feature toggle details"}),feature:a}),t.jsx(Re,{}),t.jsx(hi,{header:t.jsx(lt,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:a})]})},mi=()=>{const{trackEvent:e}=ae(),{value:n,setValue:s}=Wn(),[r,a]=g.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:r,setHiddenEnvironments:i=>{s(c=>{const l=new Set(Array.from(c.hiddenEnvironments||[]));return l.has(i)?(l.delete(i),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(l.add(i),e("hidden_environment",{props:{eventType:"environment hidden"}})),a(l),{...n,hiddenEnvironments:[...l]}})}}},yi=()=>{const[e,n]=g.useState(0),s=A("projectId"),r=A("featureId"),a=Ae("environmentId"),o=Ae("strategyName"),{strategy:i,defaultStrategyFallback:c}=In(s,a),l=JSON.parse(pn().get("defaultStrategy")||"false"),{segments:d}=yt(),u=(d||[]).filter(J=>{var D;return(D=i==null?void 0:i.segments)==null?void 0:D.includes(J.id)}),[h,m]=g.useState({}),[j,y]=g.useState(l?u:[]),{strategyDefinition:T}=jt(o),f=St(),{addStrategyToFeature:x,loading:R}=he(),{addChange:L}=se(),{setToastData:q,setToastApiError:z}=U(),{uiConfig:v}=fe(),{unleashUrl:C}=v,$=ce(),{feature:O,refetchFeature:N}=M(s,r),G=g.useRef(O),{isChangeRequestConfigured:Y}=Z(s),{refetch:S}=te(s),{trackEvent:k}=ae(),{data:w,staleDataNotification:E,forceRefreshCache:F}=bt({unleashGetter:M,params:[s,r],dataKey:"feature",refetchFunctionKey:"refetchFeature",options:{}},O,{afterSubmitAction:N},vt);g.useEffect(()=>{G.current.name===""&&O.name&&(F(O),G.current=O)},[O.name]),g.useEffect(()=>{var J;if(l){const D=i||c;((J=D.parameters)==null?void 0:J.groupId)===""&&r?m({...D,parameters:{...D.parameters,groupId:r}}):m(D)}else T&&m(qn(r,T))},[r,JSON.stringify(T),l]);const B=async J=>{await x(s,r,a,J),q({title:"Strategy created",type:"success",confetti:!0})},I=async J=>{await L(s,a,{action:"addStrategy",feature:r,payload:J}),q({title:"Strategy added to draft",type:"success",confetti:!0}),S()},_=gn(h,j),P=async()=>{k("strategyTitle",{props:{hasTitle:!!h.title,on:"create"}});try{Y(a)?await I(_):await B(_),N(),$(Ue(s,r))}catch(J){z(V(J))}};return!w||!w.project?null:t.jsxs(Ge,{modal:!0,description:hn,documentationLink:fn,documentationLinkLabel:xn,disablePadding:!0,formatApiCode:()=>ji(s,r,a,_,C),children:[t.jsx(Tn,{projectId:s,feature:w,strategy:h,setStrategy:m,segments:j,setSegments:y,environmentId:a,onSubmit:P,loading:R,permission:de,errors:f,isChangeRequest:Y(a),tab:e,setTab:n,StrategyVariants:t.jsx(En,{strategy:h,setStrategy:m,environment:a,projectId:s,editable:!0})}),E]})},ji=(e,n,s,r,a)=>{if(!a)return"";const o=`${a}/api/admin/projects/${e}/features/${n}/environments/${s}/strategies`,i=JSON.stringify(r,void 0,2);return`curl --location --request POST '${o}' \\
@@ -16,7 +16,7 @@ import{c as ht,j as t,s as p,aE as A,aF as M,aG as Qn,aH as Zn,C as b,aI as re,a
16
16
  --data-raw '${JSON.stringify(O,void 0,2)}'`:`curl --location --request PATCH '${l.unleashUrl}/api/admin/projects/${i}/features/${c}/environments/${e==null?void 0:e.name}/variants' \\
17
17
  --header 'Authorization: INSERT_API_KEY' \\
18
18
  --header 'Content-Type: application/json' \\
19
- --data-raw '${JSON.stringify($.patch,void 0,2)}'`,Y=x.every(({isValid:D})=>D),S=y((e==null?void 0:e.name)||""),k=S?"Add to existing change request":"Add change to draft",w=m((e==null?void 0:e.name)||""),E=g.useMemo(()=>{var D;return h?"":((D=C[0])==null?void 0:D.stickiness)||u},[h,u,JSON.stringify(C[0]??{})]),F=g.useMemo(()=>["default",...d.filter(D=>D.stickiness).map(D=>D.name)],[d]),B=F.map(D=>({key:D,label:D}));F.includes(E)||B.push({key:E,label:E});const I=async D=>{R(X=>X.map(Se=>({...Se,stickiness:D})))},_=D=>{I(D)},[P,H]=g.useState();g.useEffect(()=>{H(void 0),$.error&&H($.error)},[$.error]);const J=()=>{I(u),s(!1)};return h||E===""?t.jsx(ta,{}):t.jsx(pt,{open:n,onClose:J,label:"",children:t.jsxs(Ge,{modal:!0,title:"",description:"Variants allow 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:G,loading:!n,children:[t.jsxs(ki,{children:[t.jsxs("div",{children:[t.jsx(Ii,{deprecated:!(e!=null&&e.enabled)}),t.jsx(Pi,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t.jsx(pe,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:v,variant:"outlined",permission:be,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),t.jsxs(Oi,{onSubmit:N,children:[t.jsx(b,{condition:S,show:T,elseShow:t.jsx(b,{condition:!!w,show:t.jsxs(Bi,{severity:"info",children:[t.jsx("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.jsx(_i,{children:x.map(D=>t.jsx(Hi,{variant:D,variants:x,updateVariant:X=>z(X,D.id),removeVariant:()=>R(X=>It(X.filter(Se=>Se.id!==D.id),1e3)),error:$.error},D.id))}),t.jsx(pe,{onClick:v,variant:"outlined",permission:be,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"}),t.jsx(qi,{}),t.jsx(b,{condition:x.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(Mi,{children:t.jsx("p",{children:"Stickiness"})}),t.jsxs(Qt,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t.jsx(Et,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t.jsx("div",{children:t.jsx(zi,{value:E,label:"",editable:!0,onChange:D=>_(D.target.value)})})]}),elseShow:t.jsx(Qt,{children:"This environment has no variants. Get started by adding a variant."})}),t.jsxs(Li,{severity:"error",hidden:!P,children:[t.jsx("strong",{children:"Error: "}),P]}),t.jsxs(Ni,{children:[t.jsx(je,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!Y,children:w?k:"Save variants"}),t.jsx(Vi,{onClick:J,children:"Cancel"})]})]})]})})},Ui=e=>fetch(e).then(ye("ChangeRequest")).then(n=>n.json()),Yi=(e,n)=>{const{data:s,error:r,mutate:a}=un([],ge(`api/admin/projects/${e}/change-requests/scheduled?variantForFlag=${n}`),Ui);return{changeRequests:s,loading:!r&&!s,refetch:a,error:r}},Gi=(e,n,s)=>{const{changeRequests:r}=Yi(e,n),a=r==null?void 0:r.filter(o=>o.environment===s);return a?a.map(o=>o.id):[]},Ki=p("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.divider}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),Ji=p("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Qi=p(Rn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Zi=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})),Xi=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),ec=p("div")(({theme:e})=>({margin:e.spacing(3,0)})),tc=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),nc=({environment:e,searchValue:n,children:s})=>{var l;const r=A("projectId"),a=A("featureId"),o=Gi(r,a,e.name),i=e.variants??[],c=((l=i[0])==null?void 0:l.stickiness)||"default";return t.jsxs(Ki,{children:[t.jsxs(Ji,{children:[t.jsxs("div",{children:[t.jsx(Qi,{deprecated:!e.enabled}),t.jsx(Zi,{deprecated:!e.enabled,children:e.name}),t.jsx(b,{condition:o.length>0,show:t.jsx(sa,{sx:{ml:2},children:t.jsx(Mn,{scheduledChangeRequestIds:o})})})]}),s]}),t.jsx(b,{condition:i.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(ec,{children:t.jsx(aa,{variants:i,searchValue:n})}),t.jsx(b,{condition:i.length>1,show:t.jsxs(t.Fragment,{children:[t.jsxs(tc,{children:[t.jsx("p",{children:"Stickiness:"}),t.jsx(Ee,{children:c})]}),t.jsxs(Xi,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t.jsx(Et,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},sc=p(me)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),ac=({environment:e,permission:n,projectId:s,environmentId:r,onCopyVariantsFrom:a,otherEnvsWithVariants:o})=>{const[i,c]=g.useState(null),l=!!i,d=e.variants??[];return t.jsx(b,{condition:o.length>0&&d.length===0,show:t.jsxs(t.Fragment,{children:[t.jsx(pe,{onClick:u=>{c(u.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,variant:"outlined",permission:n,projectId:s,environmentId:r,children:"Copy variants from"}),t.jsx(ke,{anchorEl:i,open:l,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:o.map(u=>t.jsx(ue,{onClick:()=>a(u,e),children:t.jsx(sc,{children:`Copy from ${u.name}`})},u.name))})]})})},rc=({permission:e,projectId:n,environment:s,checked:r,onClick:a,...o})=>{const i=ut(e,n,s);return t.jsxs(ue,{disabled:!i,onClick:a,...o,children:[t.jsx(ra,{checked:r}),s]})},oc=p(ke)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),ic=p("div")(({theme:e})=>({margin:e.spacing(1,2)})),cc=p(je)(({theme:e})=>({marginTop:e.spacing(2)})),lc=({current:e,environments:n,permission:s,projectId:r,onSubmit:a})=>{var T;const[o,i]=g.useState(null),c=!!o,[l,d]=g.useState([]),u=f=>{d(x=>[...x,f])},h=f=>{d(x=>x.filter(({name:R})=>R!==f.name))},m=f=>{l.includes(f)?h(f):u(f)},j=()=>{d([]),i(null)},y=((T=n.find(f=>f.name===e))==null?void 0:T.variants)??[];return t.jsx(b,{condition:y.length>0&&n.length>1,show:t.jsxs(t.Fragment,{children:[t.jsx(je,{onClick:f=>{i(f.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,variant:"outlined",children:"Copy to environment"}),t.jsxs(oc,{anchorEl:o,open:c,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(f=>f.name!==e).map(f=>t.jsx(rc,{projectId:r,permission:s,environment:f.name,checked:l.includes(f),onClick:()=>m(f)},f.name)),t.jsxs(ic,{children:[t.jsx(Re,{}),t.jsxs(cc,{variant:"outlined",onClick:()=>{a(l),j()},disabled:l.length===0,children:["Push to selected (",l.length,")"]})]})]})]})})},dc=p("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),uc=()=>{const{setToastData:e,setToastApiError:n}=U(),s=xt(),r=Ie(s.breakpoints.down("md")),a=A("projectId"),o=A("featureId"),{feature:i,refetchFeature:c,loading:l}=M(a,o),{patchFeatureEnvironmentVariants:d,overrideVariantsInEnvironments:u}=Ke(),{refetch:h}=te(a),{addChange:m}=se(),{isChangeRequestConfigured:j}=Z(a),[y,T]=g.useState(""),[f,x]=g.useState(),[R,L]=g.useState(!1),q=g.useMemo(()=>{var S;return((S=i==null?void 0:i.environments)==null?void 0:S.map(k=>({...k,crEnabled:j(k.name)})))||[]},[i.environments]),z=(S,k)=>la(S,k),v=(S,k)=>{try{const w=ca(k,1e3);return{patch:z(S,w)}}catch(w){return{patch:[],error:V(w)}}},C=S=>({feature:o,action:"patchVariant",payload:{variants:S}}),$=async(S,k)=>{if(S.crEnabled)await m(a,S.name,C(k)),h();else{const w=S.variants??[],{patch:E,error:F}=v(w,k);if(E.length===0)return;if(F){e({type:"error",title:F});return}await d(a,o,S.name,E)}c()},O=async(S,k)=>{try{const w=k.filter(({crEnabled:_})=>_),E=k.filter(({crEnabled:_})=>!_);w.length&&await Promise.all(w.map(_=>m(a,_.name,C(S)))),E.length&&await u(a,o,S,E.map(({name:_})=>_)),h(),c();const F=E.length?`Variants pushed to ${E.length===1?E[0].name:`${E.length} environments`}`:"",B=w.length?`Variants push added to ${w.length===1?`${w[0].name} draft`:`${w.length} drafts`}`:"",I=`${F}${F&&B?". ":""}${B}`;e({title:I,type:"success"})}catch(w){n(V(w))}},N=S=>{x(S),L(!0)},G=async S=>{if(f)try{await $(f,S),L(!1),e({title:f.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(k){n(V(k))}},Y=async(S,k)=>{try{const w=S.variants??[];await $(k,w),e({title:k.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(w){n(V(w))}};return t.jsxs(At,{isLoading:l,header:t.jsx(oa,{title:"Variants",actions:t.jsx(b,{condition:!r,show:t.jsx(t.Fragment,{children:t.jsx(Pt,{initialValue:y,onChange:T})})}),children:t.jsx(b,{condition:r,show:t.jsx(Pt,{initialValue:y,onChange:T})})}),children:[t.jsx(ia,{}),q.map(S=>{var w;const k=q.filter(({name:E,variants:F})=>E!==S.name&&(F==null?void 0:F.length));return t.jsx(nc,{environment:S,searchValue:y,children:t.jsxs(dc,{children:[t.jsx(lc,{current:S.name,environments:q,permission:be,projectId:a,onSubmit:E=>O(S.variants??[],E)}),t.jsx(ac,{environment:S,permission:be,projectId:a,environmentId:S.name,onCopyVariantsFrom:Y,otherEnvsWithVariants:k}),t.jsx(b,{condition:!!((w=S.variants)!=null&&w.length),show:t.jsx(re,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>N(S),permission:be,projectId:a,environmentId:S.name,tooltipProps:{title:"Edit variants"},children:t.jsx(we,{})}),elseShow:t.jsx(pe,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>N(S),variant:"outlined",permission:be,projectId:a,environmentId:S.name,children:"Add variant"})})]})},S.name)}),t.jsx(Wi,{environment:f,open:R,setOpen:L,getApiPayload:v,getCrPayload:C,onConfirm:G})]})},pc=ge("api/admin/client-metrics/features"),Jn=(e,n)=>{const s=ge(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:r,error:a}=We(s,()=>gc(s)),o=g.useCallback(()=>{ft(pc).catch(console.warn)},[]);return{featureMetrics:r==null?void 0:r.data,loading:!a&&!r,refetchFeatureMetrics:o,error:a}},gc=e=>fetch(e).then(ye("Features")).then(n=>n.json()).then(),hc=()=>{const{isEnterprise:e}=fe(),n=Dn("extendedUsageMetricsUI");return e()&&n},fc=p("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),He=48,xc=({hoursBack:e,setHoursBack:n})=>{const{trackEvent:s}=ae(),r=c=>{n(parseInt(c)),s("feature-metrics",{props:{eventType:"change-period",hoursBack:c}})},o=hc()?[...Zt,...mc]:Zt,i=o.map(c=>Number(c.key)).includes(e)?e:He;return g.useEffect(()=>{e!==i&&n(i)},[e]),t.jsxs("div",{children:[t.jsx(fc,{children:"Period"}),t.jsx(Sn,{name:"feature-metrics-period",id:"feature-metrics-period",options:o,value:String(i),onChange:r,fullWidth:!0})]})},Zt=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:"48",label:"Last 48 hours"}],mc=[{key:`${7*24}`,label:"Last 7 days"},{key:`${30*24}`,label:"Last 30 days"},{key:`${90*24}`,label:"Last 90 days"}],yc=({value:e,timeZone:n})=>{const{locationSettings:s}=vn(),r=e?e instanceof Date?Ot(e,s.locale,n):Ot(Cn(e),s.locale,n):void 0;return t.jsx(Ne,{lineClamp:1,children:r})},jc=p(W)(({theme:e})=>({fontSize:e.fontSizes.smallerBody})),Sc=({row:e})=>e.original.selectedApplications&&e.original.selectedApplications.length>1?t.jsx(Ne,{children:t.jsx(Ye,{tooltip:t.jsx(t.Fragment,{children:e.original.selectedApplications.map(n=>t.jsx(jc,{children:n},n))}),children:e.original.appName})}):t.jsx(Ne,{children:e.original.appName}),bc=({metrics:e,tableSectionId:n})=>{const s=Ie(da.breakpoints.down("md")),r=g.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:a,getTableBodyProps:o,headerGroups:i,rows:c,prepareRow:l,setHiddenColumns:d}=Ze.useTable({initialState:r,columns:Xt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:Ne}},Ze.useGlobalFilter,Ze.useSortBy);return ua([{condition:s,columns:["appName","environment"]}],d,Xt),e.length===0?null:t.jsxs(pa,{...a(),rowHeight:"standard",id:n,children:[t.jsx(ga,{headerGroups:i}),t.jsx(ha,{...o(),children:c.map(u=>(l(u),t.jsx(fa,{hover:!0,...u.getRowProps(),children:u.cells.map(h=>t.jsx(xa,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},Xt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t.jsx(ma,{icon:t.jsx(Xa,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t.jsx(yc,{value:e.row.original.timestamp,timeZone:e.row.original.timestamp.includes("23:59")?"UTC":void 0})},{Header:"Application",accessor:"appName",Cell:Sc},{Header:"Environment",accessor:"environment"},{id:"requested",Header:"Requested",accessor:e=>e.yes+e.no},{Header:"Exposed",accessor:"yes"}],vc=({metrics:e,...n})=>{const s=g.useMemo(()=>e.reduce((a,o)=>a+o.yes,0),[e]),r=g.useMemo(()=>e.reduce((a,o)=>a+o.no,0),[e]);return t.jsx(Hn,{...n,totalYes:s,totalNo:r})},Cc=({metrics:e,hoursBack:n})=>{const s=Bt(),r=Bt();return e.length===0?t.jsxs(K,{mt:6,children:[t.jsx(W,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t.jsx(W,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):t.jsxs(g.Suspense,{fallback:null,children:[t.jsx(K,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t.jsx(wc,{metrics:e,hoursBack:n,statsSectionId:s})}),t.jsx(K,{mt:4,children:t.jsx(vc,{metrics:e,hoursBack:n,statsSectionId:s,tableSectionId:r})}),t.jsx(K,{mt:4,children:t.jsx(bc,{metrics:e,tableSectionId:r})})]})},wc=ya.lazy(()=>ja(()=>import("./FeatureMetricsChart-Tbwq6Bt5.js"),__vite__mapDeps([]))),Tc=p("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ec=p("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%",alignItems:"center",maxHeight:"200px",overflowY:"auto"})),Ac=p("li")(({theme:e})=>({"& > [aria-pressed=true]":{backgroundColor:e.palette.background.alternative,color:e.palette.primary.contrastText},"& > [aria-pressed=true]:hover":{backgroundColor:e.palette.primary.light}})),en=({title:e,values:n,selectedValues:s,toggleValue:r,toggleValues:a})=>{const o=l=>()=>{r(l)},i=[...n].every(l=>s.includes(l)),c=g.useMemo(()=>Array.from(n).sort((l,d)=>l.localeCompare(d)),[n]);return t.jsxs("div",{children:[t.jsx(Tc,{children:e}),t.jsxs(Ec,{children:[c.map(l=>t.jsx(Ac,{children:t.jsx(wn,{label:l,onClick:o(l),"aria-pressed":s==null?void 0:s.includes(l),sx:Sa})},l)),a&&n.size>1&&t.jsx(je,{size:"small",onClick:a,"aria-pressed":i,children:i?"Unselect":"Select all"})]})]})},Dc=e=>{const n=new Map;return e.forEach(s=>{let r=n.get(s.timestamp);if(r||(r={...s,yes:0,no:0,variants:{}},n.set(s.timestamp,r)),r.yes+=s.yes,r.no+=s.no,s.variants){r.variants=r.variants||{};for(const[a,o]of Object.entries(s.variants))r.variants[a]=(r.variants[a]||0)+o}}),Array.from(n.values()).map(s=>({...s,variants:s.variants&&Object.keys(s.variants).length===0?void 0:s.variants}))},Fc=()=>{const e=A("projectId"),n=A("featureId"),s=Rc(e,n);An("Metrics");const r=Array.from(s)[0],[a,o]=ba({environment:Xe(va,r),applications:Xe(Ca,[]),hoursBack:Xe(wa,He)}),i=$c(n,a.hoursBack||He),c=Array.from(i)[0],{environment:l,hoursBack:d}=a,u=a.applications.filter(f=>f!==null);g.useEffect(()=>{a.applications&&a.applications.length===0&&c&&o({applications:[c]})},[JSON.stringify(Array.from(i))]);const h=[...i].every(f=>u.includes(f)),{featureMetrics:m}=Jn(n,d),[j,y]=g.useState(m);g.useEffect(()=>{m&&y(m)},[m]);const T=g.useMemo(()=>Dc((j==null?void 0:j.filter(f=>l===f.environment).filter(f=>u.includes(f.appName)))||[]).map(f=>({...f,appName:u.length>1?"all selected":f.appName,selectedApplications:u})),[j,l,JSON.stringify(u)]);return T?t.jsxs(At,{children:[t.jsxs(le,{container:!0,component:"header",spacing:2,children:[t.jsx(le,{item:!0,xs:12,md:5,children:t.jsx(b,{condition:s.size>0,show:t.jsx(en,{title:"Environments",values:s,selectedValues:[l],toggleValue:f=>{o({environment:f})}})})}),t.jsx(le,{item:!0,xs:12,md:5,children:t.jsx(b,{condition:i.size>0,show:t.jsx(en,{title:"Applications",values:i,selectedValues:u,toggleValues:()=>{o(h?{applications:[c]}:{applications:[...i]})},toggleValue:f=>{u.includes(f)?o({applications:u.filter(x=>x!==f)}):o({applications:[...u,f]})}})})}),t.jsx(le,{item:!0,xs:12,md:2,children:t.jsx(xc,{hoursBack:d,setHoursBack:f=>o({hoursBack:f})})})]}),t.jsx(Cc,{metrics:T,hoursBack:d})]}):null},Rc=(e,n)=>{const{feature:s}=M(e,n),r=s.environments.map(a=>a.name);return new Set(r)},$c=(e,n=He)=>{const{featureMetrics:s=[]}=Jn(e,n),r=s.map(a=>a.appName);return new Set(r)},kc=(e,n)=>{const s=new Set(e),r=new Set(n);return s.size!==r.size?!1:[...s].every(a=>r.has(a))},tn=p("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),nn=p(ie)(({theme:e})=>({marginBottom:e.spacing(1)})),Ic=p(wt)({padding:0}),Pc=({projectId:e,open:n,onClose:s,onClick:r,feature:a,changeRequests:o})=>{const i=A("projectId"),{project:c}=$n(e),{isChangeRequestConfiguredInAnyEnv:l}=Z(e),d=l(),u=g.useMemo(()=>kc(a.environments.map(j=>j.name),c.environments.map(j=>j.environment)),[a,c]),h=o?o.length>0:!1,m=a.dependencies.length>0||a.children.length>0;return t.jsx(b,{condition:u&&!m&&!h&&!d,show:t.jsx(oe,{open:n,onClose:s,onClick:r,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:t.jsxs(tn,{children:[t.jsx(nn,{severity:"success",children:"This feature toggle is compatible with the new project."}),t.jsx("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t.jsx(oe,{open:n,onClick:s,title:"Confirm change project",primaryButtonText:"Close",children:t.jsxs(tn,{children:[t.jsx(nn,{severity:"warning",children:"Cannot proceed with the move"}),t.jsx(b,{condition:m,show:t.jsxs("p",{children:[t.jsx("span",{children:"The feature toggle must not have any dependencies."})," ",t.jsx("br",{}),t.jsx("span",{children:"Please remove feature dependencies first."})]})}),t.jsx(b,{condition:!u,show:t.jsx("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t.jsx(b,{condition:h,show:t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"The feature toggle must not have any pending change requests. This feature toggle is currently referenced in the following change requests:"}),t.jsx(Ic,{children:o==null?void 0:o.map(j=>t.jsx(ve,{children:t.jsxs(Q,{to:`/projects/${i}/change-requests/${j.id}`,children:["View change request"," ",j.id]})},j.id))})]})}),t.jsx(b,{condition:d,show:t.jsxs("p",{children:["You're not allowed to move the feature to project"," ",t.jsx(Q,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},Oc=()=>{const{hasAccess:e}=g.useContext(mt),n=A("projectId"),s=A("featureId"),{feature:r,refetchFeature:a}=M(n,s),[o,i]=g.useState(!1),{changeFeatureProject:c}=Ke(),{setToastData:l,setToastApiError:d}=U(),[u,h]=g.useState(n),{projects:m}=Ta(),j=ce(),{changeRequests:y}=_n(n,s),T=async()=>{try{u&&(await c(n,s,u),a(),l({title:"Project changed",type:"success"}),i(!1),j(`/projects/${u}/features/${s}/settings`,{replace:!0}))}catch(x){d(V(x))}},f=g.useMemo(()=>m.map(x=>x.id).filter(x=>e(Lt,x)),[m,e]);return f.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx(Ea,{value:u,onChange:h,label:"Project",filter:x=>f.includes(x),enabled:!0}),t.jsx(pe,{permission:Lt,onClick:()=>i(!0),disabled:u===n,projectId:n,children:"Save"}),t.jsx(Pc,{changeRequests:y,projectId:u,open:o,feature:r,onClose:()=>i(!1),onClick:T})]})},Bc=p("div")({display:"flex",alignItems:"center"}),Lc=p(W)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),_c=({projectId:e,featureId:n})=>{var o;const{feature:s}=M(e,n),r=ce(),a=()=>{r(`/projects/${e}/features/${n}/edit`)};return t.jsxs(t.Fragment,{children:[t.jsxs(Bc,{children:[t.jsx(Lc,{children:"Feature information"}),t.jsx(re,{permission:Ce,projectId:e,"data-loading":!0,onClick:a,tooltipProps:{title:"Edit"},children:t.jsx(we,{})})]}),t.jsxs(W,{children:["Name: ",t.jsx("strong",{children:s.name})]}),t.jsxs(W,{children:["Description:"," ",t.jsx("strong",{children:(o=s.description)!=null&&o.length?s.description:"no description"})]}),t.jsxs(W,{children:["Type: ",t.jsx("strong",{children:s.type})]}),t.jsxs(W,{children:["Impression Data:"," ",t.jsx("strong",{children:s.impressionData?"enabled":"disabled"})]})]})},Le="metadata",dt="project",Mc=p("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),qc=p("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,"& > *":{margin:e.spacing(1,0)}})),zc=()=>{const e=A("projectId"),n=A("featureId"),[s,r]=g.useState(Le),{uiConfig:a}=fe();return t.jsx(At,{header:"Settings",sx:{padding:0},children:t.jsxs(K,{sx:{display:"flex"},children:[t.jsx(Mc,{children:t.jsxs(wt,{children:[t.jsx(ve,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(Le),selected:s===Le,children:"Metadata"},0),t.jsx(ve,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(dt),selected:s===dt,hidden:!a.flags.P,children:"Project"},1)]})}),t.jsxs(qc,{children:[t.jsx(b,{condition:s===Le,show:t.jsx(_c,{projectId:e,featureId:n})}),t.jsx(b,{condition:s===dt&&a.flags.P,show:t.jsx(Oc,{})})]})]})})},Nc=({stale:e,showActive:n=!0})=>{if(!e&&!n)return null;const s=e?"Feature toggle is deprecated.":"Feature toggle is active.",r=e?"Stale":"Active";return t.jsx("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t.jsx(Ee,{color:e?"error":"success",title:s,children:r})})},sn=p("strong")({wordBreak:"break-all"}),Vc=()=>{const e=A("projectId"),n=A("featureId"),{archivedFeatures:s}=Aa(),r=Da(e,{name:n});return s?s.some(o=>o.name===n)?t.jsxs("p",{children:["The feature ",t.jsx(sn,{children:n})," has been archived. You can find it on the"," ",t.jsx(Q,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):t.jsxs("p",{children:["The feature ",t.jsx(sn,{children:n})," does not exist. Would you like to"," ",t.jsx(Q,{to:r,children:"create it"}),"?"]}):null},Hc=p(Q)(({theme:e})=>({textDecoration:"none",color:e.palette.primary.main,fontWeight:e.fontWeight.bold})),Wc=({isOpen:e,onClose:n,features:s,project:r})=>t.jsxs(oe,{title:"You can't archive a feature that other features depend on",open:e,primaryButtonText:"OK",onClick:n,children:[t.jsx("p",{children:"The following features depend on your feature:"}),t.jsx("ul",{children:s.map(a=>t.jsx("li",{children:t.jsx(Hc,{to:`/projects/${r}/features/${a}`,target:"_blank",rel:"noopener noreferrer",children:a})},a))})]}),Uc=e=>g.createElement("svg",{fill:"none",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},g.createElement("path",{d:"M1 12a5 5 0 0 1 5-5h4a5 5 0 0 1 4.584 7H14a1.993 1.993 0 0 1-1.375-.547A3 3 0 0 0 10 9H6a3 3 0 1 0 0 6h2.803a6.03 6.03 0 0 0 1.822 1.961A5.033 5.033 0 0 1 10 17H6a5 5 0 0 1-5-5Z",fill:"#202021"}),g.createElement("path",{d:"M9 12c0-.711.148-1.387.416-2H10c.532 0 1.016.208 1.375.547A3 3 0 0 0 14 15h4a3 3 0 1 0 0-6h-2.803a6.03 6.03 0 0 0-1.822-1.961C13.58 7.013 13.788 7 14 7h4a5 5 0 0 1 0 10h-4a5 5 0 0 1-5-5Z",fill:"#202021"})),Yc=e=>g.createElement("svg",{fill:"none",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},g.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1 8a5 5 0 0 1 5-5h4a5 5 0 0 1 4.584 7H14a1.993 1.993 0 0 1-1.375-.547A3 3 0 0 0 10 5H6a3 3 0 0 0 0 6h2.803a6.03 6.03 0 0 0 1.822 1.961A5.033 5.033 0 0 1 10 13H8v3a1 1 0 0 0 1 1h1.17A3.001 3.001 0 0 1 13 15h7a3 3 0 1 1 0 6h-7a3.001 3.001 0 0 1-2.83-2H9a3 3 0 0 1-3-3v-3a5 5 0 0 1-5-5Zm8 0c0-.711.148-1.388.416-2H10c.532 0 1.016.208 1.375.547A3 3 0 0 0 14 11h4a3 3 0 1 0 0-6h-2.803a6.03 6.03 0 0 0-1.822-1.961C13.58 3.013 13.788 3 14 3h4a5 5 0 0 1 0 10h-4a5 5 0 0 1-5-5Z",fill:"#202021"})),Gc=p("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),Kc=p("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),an=p("div")({display:"flex",alignItems:"center"}),rn=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1),marginTop:e.spacing(1),fontSize:e.fontSizes.smallBody,padding:e.spacing(.75,1.5),backgroundColor:e.palette.background.elevation2,borderRadius:`${e.shape.borderRadiusMedium}px`,width:"max-content"}));p(Uc)(({theme:e})=>({width:e.fontSizes.smallBody,height:e.fontSizes.smallBody}));p(Yc)(({theme:e})=>({width:e.fontSizes.smallBody,height:e.fontSizes.smallBody}));const Jc=p("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),Qc=p("div")({flexShrink:0,display:"flex"}),Zc=p("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),Xc=p("div")(({theme:e})=>({padding:e.spacing(0,4)})),el=p(Fa)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),tl=p(Q)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),nl=()=>{var S,k;const e=A("projectId"),n=A("featureId"),{refetch:s}=$n(e),{favorite:r,unfavorite:a}=Ra(),{refetchFeature:o}=M(e,n),{setToastData:i,setToastApiError:c}=U(),[l,d]=g.useState(!1),[u,h]=g.useState(!1),[m,j]=g.useState(!1),[y,T]=g.useState(!1),f=Ie("(max-width:500px)"),{feature:x,loading:R,error:L,status:q}=M(e,n),z=ce(),{pathname:v}=$a(),C=ka(R),$=`/projects/${e}/features/${n}`,O=[{title:"Overview",path:`${$}`,name:"overview"},{title:"Metrics",path:`${$}/metrics`,name:"Metrics"},{title:"Variants",path:`${$}/variants`,name:"Variants"},{title:"Settings",path:`${$}/settings`,name:"Settings"},{title:"Event log",path:`${$}/logs`,name:"Event log"}],N=O.find(w=>w.path===v)??O[0],G=async()=>{try{x!=null&&x.favorite?await a(e,x.name):await r(e,x.name),o()}catch{c("Something went wrong, could not update favorite")}};if(q===404)return t.jsx(Vc,{});if(L!==void 0)return t.jsx("div",{ref:C});const Y=()=>{try{qa(x.name),T(!0),setTimeout(()=>{T(!1)},3e3)}catch{i({type:"error",title:"Could not copy feature name"})}};return t.jsxs("div",{ref:C,children:[t.jsxs(Gc,{children:[t.jsxs(Kc,{children:[t.jsxs(an,{children:[t.jsx(Ia,{onClick:G,isFavorite:x==null?void 0:x.favorite}),t.jsxs("div",{children:[t.jsxs(an,{children:[t.jsxs(Jc,{"data-loading":!0,children:[x.name," "]}),t.jsx(ee,{title:y?"Copied!":"Copy name",arrow:!0,children:t.jsx($e,{onClick:Y,style:{marginLeft:8},children:y?t.jsx(Pa,{style:{fontSize:16}}):t.jsx(Oa,{style:{fontSize:16}})})}),t.jsx(b,{condition:!f,show:t.jsx(Nc,{stale:x==null?void 0:x.stale})})]}),t.jsx(b,{condition:x.dependencies.length>0,show:t.jsxs(rn,{children:[t.jsx("b",{children:"Has parent: "}),t.jsx(tl,{to:`/projects/${x.project}/features/${(S=x==null?void 0:x.dependencies[0])==null?void 0:S.feature}`,children:(k=x==null?void 0:x.dependencies[0])==null?void 0:k.feature})]})}),t.jsx(b,{condition:x.children.length>0,show:t.jsxs(rn,{children:[t.jsx("b",{children:"Has children:"}),t.jsx(Yn,{childFeatures:x.children,project:x.project})]})})]})]}),t.jsxs(Qc,{children:[t.jsx(re,{permission:Ba,projectId:e,"data-loading":!0,component:Q,to:`/projects/${e}/features/${n}/copy`,tooltipProps:{title:"Clone"},children:t.jsx(er,{})}),t.jsx(re,{permission:La,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>h(!0),children:t.jsx(Za,{})}),t.jsx(re,{onClick:()=>j(!0),permission:Ce,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t.jsx(Ga,{})}),t.jsx(re,{onClick:()=>d(!0),permission:Ce,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t.jsx(_a,{})})]})]}),t.jsx(Zc,{}),t.jsx(Xc,{children:t.jsx(Ma,{value:N.path,indicatorColor:"primary",textColor:"primary",children:O.map(w=>t.jsx(el,{label:w.title,value:w.path,onClick:()=>z(w.path),"data-testid":`TAB-${w.title}`},w.title))})})]}),t.jsxs(Fn,{children:[t.jsx(xe,{path:"metrics",element:t.jsx(Fc,{})}),t.jsx(xe,{path:"logs",element:t.jsx(nr,{})}),t.jsx(xe,{path:"variants",element:t.jsx(uc,{})}),t.jsx(xe,{path:"settings",element:t.jsx(zc,{})}),t.jsx(xe,{path:"*",element:t.jsx($i,{})})]}),t.jsx(b,{condition:x.children.length>0,show:t.jsx(Wc,{features:x.children,project:e,isOpen:u,onClose:()=>h(!1)}),elseShow:t.jsx(Ka,{isOpen:u,onConfirm:()=>{s(),z(`/projects/${e}`)},onClose:()=>h(!1),projectId:e,featureIds:[n]})}),t.jsx(Ja,{isStale:x.stale,isOpen:m,onClose:()=>{j(!1),o()},featureId:n,projectId:e}),t.jsx(Kn,{open:l,setOpen:d})]})},ol=Object.freeze(Object.defineProperty({__proto__:null,default:nl},Symbol.toStringTag,{value:"Module"}));export{ol as F,uo as d};
19
+ --data-raw '${JSON.stringify($.patch,void 0,2)}'`,Y=x.every(({isValid:D})=>D),S=y((e==null?void 0:e.name)||""),k=S?"Add to existing change request":"Add change to draft",w=m((e==null?void 0:e.name)||""),E=g.useMemo(()=>{var D;return h?"":((D=C[0])==null?void 0:D.stickiness)||u},[h,u,JSON.stringify(C[0]??{})]),F=g.useMemo(()=>["default",...d.filter(D=>D.stickiness).map(D=>D.name)],[d]),B=F.map(D=>({key:D,label:D}));F.includes(E)||B.push({key:E,label:E});const I=async D=>{R(X=>X.map(Se=>({...Se,stickiness:D})))},_=D=>{I(D)},[P,H]=g.useState();g.useEffect(()=>{H(void 0),$.error&&H($.error)},[$.error]);const J=()=>{I(u),s(!1)};return h||E===""?t.jsx(ta,{}):t.jsx(pt,{open:n,onClose:J,label:"",children:t.jsxs(Ge,{modal:!0,title:"",description:"Variants allow 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:G,loading:!n,children:[t.jsxs(ki,{children:[t.jsxs("div",{children:[t.jsx(Ii,{deprecated:!(e!=null&&e.enabled)}),t.jsx(Pi,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t.jsx(pe,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:v,variant:"outlined",permission:be,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),t.jsxs(Oi,{onSubmit:N,children:[t.jsx(b,{condition:S,show:T,elseShow:t.jsx(b,{condition:!!w,show:t.jsxs(Bi,{severity:"info",children:[t.jsx("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.jsx(_i,{children:x.map(D=>t.jsx(Hi,{variant:D,variants:x,updateVariant:X=>z(X,D.id),removeVariant:()=>R(X=>It(X.filter(Se=>Se.id!==D.id),1e3)),error:$.error},D.id))}),t.jsx(pe,{onClick:v,variant:"outlined",permission:be,projectId:i,environmentId:e==null?void 0:e.name,children:"Add variant"}),t.jsx(qi,{}),t.jsx(b,{condition:x.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(Mi,{children:t.jsx("p",{children:"Stickiness"})}),t.jsxs(Qt,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t.jsx(Et,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t.jsx("div",{children:t.jsx(zi,{value:E,label:"",editable:!0,onChange:D=>_(D.target.value)})})]}),elseShow:t.jsx(Qt,{children:"This environment has no variants. Get started by adding a variant."})}),t.jsxs(Li,{severity:"error",hidden:!P,children:[t.jsx("strong",{children:"Error: "}),P]}),t.jsxs(Ni,{children:[t.jsx(je,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!Y,children:w?k:"Save variants"}),t.jsx(Vi,{onClick:J,children:"Cancel"})]})]})]})})},Ui=e=>fetch(e).then(ye("ChangeRequest")).then(n=>n.json()),Yi=(e,n)=>{const{data:s,error:r,mutate:a}=un([],ge(`api/admin/projects/${e}/change-requests/scheduled?variantForFlag=${n}`),Ui);return{changeRequests:s,loading:!r&&!s,refetch:a,error:r}},Gi=(e,n,s)=>{const{changeRequests:r}=Yi(e,n),a=r==null?void 0:r.filter(o=>o.environment===s);return a?a.map(o=>o.id):[]},Ki=p("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.divider}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),Ji=p("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),Qi=p(Rn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),Zi=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})),Xi=p("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),ec=p("div")(({theme:e})=>({margin:e.spacing(3,0)})),tc=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),nc=({environment:e,searchValue:n,children:s})=>{var l;const r=A("projectId"),a=A("featureId"),o=Gi(r,a,e.name),i=e.variants??[],c=((l=i[0])==null?void 0:l.stickiness)||"default";return t.jsxs(Ki,{children:[t.jsxs(Ji,{children:[t.jsxs("div",{children:[t.jsx(Qi,{deprecated:!e.enabled}),t.jsx(Zi,{deprecated:!e.enabled,children:e.name}),t.jsx(b,{condition:o.length>0,show:t.jsx(sa,{sx:{ml:2},children:t.jsx(Mn,{scheduledChangeRequestIds:o})})})]}),s]}),t.jsx(b,{condition:i.length>0,show:t.jsxs(t.Fragment,{children:[t.jsx(ec,{children:t.jsx(aa,{variants:i,searchValue:n})}),t.jsx(b,{condition:i.length>1,show:t.jsxs(t.Fragment,{children:[t.jsxs(tc,{children:[t.jsx("p",{children:"Stickiness:"}),t.jsx(Ee,{children:c})]}),t.jsxs(Xi,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t.jsx(Et,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},sc=p(me)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),ac=({environment:e,permission:n,projectId:s,environmentId:r,onCopyVariantsFrom:a,otherEnvsWithVariants:o})=>{const[i,c]=g.useState(null),l=!!i,d=e.variants??[];return t.jsx(b,{condition:o.length>0&&d.length===0,show:t.jsxs(t.Fragment,{children:[t.jsx(pe,{onClick:u=>{c(u.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,variant:"outlined",permission:n,projectId:s,environmentId:r,children:"Copy variants from"}),t.jsx(ke,{anchorEl:i,open:l,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:o.map(u=>t.jsx(ue,{onClick:()=>a(u,e),children:t.jsx(sc,{children:`Copy from ${u.name}`})},u.name))})]})})},rc=({permission:e,projectId:n,environment:s,checked:r,onClick:a,...o})=>{const i=ut(e,n,s);return t.jsxs(ue,{disabled:!i,onClick:a,...o,children:[t.jsx(ra,{checked:r}),s]})},oc=p(ke)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),ic=p("div")(({theme:e})=>({margin:e.spacing(1,2)})),cc=p(je)(({theme:e})=>({marginTop:e.spacing(2)})),lc=({current:e,environments:n,permission:s,projectId:r,onSubmit:a})=>{var T;const[o,i]=g.useState(null),c=!!o,[l,d]=g.useState([]),u=f=>{d(x=>[...x,f])},h=f=>{d(x=>x.filter(({name:R})=>R!==f.name))},m=f=>{l.includes(f)?h(f):u(f)},j=()=>{d([]),i(null)},y=((T=n.find(f=>f.name===e))==null?void 0:T.variants)??[];return t.jsx(b,{condition:y.length>0&&n.length>1,show:t.jsxs(t.Fragment,{children:[t.jsx(je,{onClick:f=>{i(f.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,variant:"outlined",children:"Copy to environment"}),t.jsxs(oc,{anchorEl:o,open:c,onClose:()=>i(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(f=>f.name!==e).map(f=>t.jsx(rc,{projectId:r,permission:s,environment:f.name,checked:l.includes(f),onClick:()=>m(f)},f.name)),t.jsxs(ic,{children:[t.jsx(Re,{}),t.jsxs(cc,{variant:"outlined",onClick:()=>{a(l),j()},disabled:l.length===0,children:["Push to selected (",l.length,")"]})]})]})]})})},dc=p("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),uc=()=>{const{setToastData:e,setToastApiError:n}=U(),s=xt(),r=Ie(s.breakpoints.down("md")),a=A("projectId"),o=A("featureId"),{feature:i,refetchFeature:c,loading:l}=M(a,o),{patchFeatureEnvironmentVariants:d,overrideVariantsInEnvironments:u}=Ke(),{refetch:h}=te(a),{addChange:m}=se(),{isChangeRequestConfigured:j}=Z(a),[y,T]=g.useState(""),[f,x]=g.useState(),[R,L]=g.useState(!1),q=g.useMemo(()=>{var S;return((S=i==null?void 0:i.environments)==null?void 0:S.map(k=>({...k,crEnabled:j(k.name)})))||[]},[i.environments]),z=(S,k)=>la(S,k),v=(S,k)=>{try{const w=ca(k,1e3);return{patch:z(S,w)}}catch(w){return{patch:[],error:V(w)}}},C=S=>({feature:o,action:"patchVariant",payload:{variants:S}}),$=async(S,k)=>{if(S.crEnabled)await m(a,S.name,C(k)),h();else{const w=S.variants??[],{patch:E,error:F}=v(w,k);if(E.length===0)return;if(F){e({type:"error",title:F});return}await d(a,o,S.name,E)}c()},O=async(S,k)=>{try{const w=k.filter(({crEnabled:_})=>_),E=k.filter(({crEnabled:_})=>!_);w.length&&await Promise.all(w.map(_=>m(a,_.name,C(S)))),E.length&&await u(a,o,S,E.map(({name:_})=>_)),h(),c();const F=E.length?`Variants pushed to ${E.length===1?E[0].name:`${E.length} environments`}`:"",B=w.length?`Variants push added to ${w.length===1?`${w[0].name} draft`:`${w.length} drafts`}`:"",I=`${F}${F&&B?". ":""}${B}`;e({title:I,type:"success"})}catch(w){n(V(w))}},N=S=>{x(S),L(!0)},G=async S=>{if(f)try{await $(f,S),L(!1),e({title:f.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(k){n(V(k))}},Y=async(S,k)=>{try{const w=S.variants??[];await $(k,w),e({title:k.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(w){n(V(w))}};return t.jsxs(At,{isLoading:l,header:t.jsx(oa,{title:"Variants",actions:t.jsx(b,{condition:!r,show:t.jsx(t.Fragment,{children:t.jsx(Pt,{initialValue:y,onChange:T})})}),children:t.jsx(b,{condition:r,show:t.jsx(Pt,{initialValue:y,onChange:T})})}),children:[t.jsx(ia,{}),q.map(S=>{var w;const k=q.filter(({name:E,variants:F})=>E!==S.name&&(F==null?void 0:F.length));return t.jsx(nc,{environment:S,searchValue:y,children:t.jsxs(dc,{children:[t.jsx(lc,{current:S.name,environments:q,permission:be,projectId:a,onSubmit:E=>O(S.variants??[],E)}),t.jsx(ac,{environment:S,permission:be,projectId:a,environmentId:S.name,onCopyVariantsFrom:Y,otherEnvsWithVariants:k}),t.jsx(b,{condition:!!((w=S.variants)!=null&&w.length),show:t.jsx(re,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>N(S),permission:be,projectId:a,environmentId:S.name,tooltipProps:{title:"Edit variants"},children:t.jsx(we,{})}),elseShow:t.jsx(pe,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>N(S),variant:"outlined",permission:be,projectId:a,environmentId:S.name,children:"Add variant"})})]})},S.name)}),t.jsx(Wi,{environment:f,open:R,setOpen:L,getApiPayload:v,getCrPayload:C,onConfirm:G})]})},pc=ge("api/admin/client-metrics/features"),Jn=(e,n)=>{const s=ge(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:r,error:a}=We(s,()=>gc(s)),o=g.useCallback(()=>{ft(pc).catch(console.warn)},[]);return{featureMetrics:r==null?void 0:r.data,loading:!a&&!r,refetchFeatureMetrics:o,error:a}},gc=e=>fetch(e).then(ye("Features")).then(n=>n.json()).then(),hc=()=>{const{isEnterprise:e}=fe(),n=Dn("extendedUsageMetricsUI");return e()&&n},fc=p("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),He=48,xc=({hoursBack:e,setHoursBack:n})=>{const{trackEvent:s}=ae(),r=c=>{n(parseInt(c)),s("feature-metrics",{props:{eventType:"change-period",hoursBack:c}})},o=hc()?[...Zt,...mc]:Zt,i=o.map(c=>Number(c.key)).includes(e)?e:He;return g.useEffect(()=>{e!==i&&n(i)},[e]),t.jsxs("div",{children:[t.jsx(fc,{children:"Period"}),t.jsx(Sn,{name:"feature-metrics-period",id:"feature-metrics-period",options:o,value:String(i),onChange:r,fullWidth:!0})]})},Zt=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:"48",label:"Last 48 hours"}],mc=[{key:`${7*24}`,label:"Last 7 days"},{key:`${30*24}`,label:"Last 30 days"},{key:`${90*24}`,label:"Last 90 days"}],yc=({value:e,timeZone:n})=>{const{locationSettings:s}=vn(),r=e?e instanceof Date?Ot(e,s.locale,n):Ot(Cn(e),s.locale,n):void 0;return t.jsx(Ne,{lineClamp:1,children:r})},jc=p(W)(({theme:e})=>({fontSize:e.fontSizes.smallerBody})),Sc=({row:e})=>e.original.selectedApplications&&e.original.selectedApplications.length>1?t.jsx(Ne,{children:t.jsx(Ye,{tooltip:t.jsx(t.Fragment,{children:e.original.selectedApplications.map(n=>t.jsx(jc,{children:n},n))}),children:e.original.appName})}):t.jsx(Ne,{children:e.original.appName}),bc=({metrics:e,tableSectionId:n})=>{const s=Ie(da.breakpoints.down("md")),r=g.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:a,getTableBodyProps:o,headerGroups:i,rows:c,prepareRow:l,setHiddenColumns:d}=Ze.useTable({initialState:r,columns:Xt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:Ne}},Ze.useGlobalFilter,Ze.useSortBy);return ua([{condition:s,columns:["appName","environment"]}],d,Xt),e.length===0?null:t.jsxs(pa,{...a(),rowHeight:"standard",id:n,children:[t.jsx(ga,{headerGroups:i}),t.jsx(ha,{...o(),children:c.map(u=>(l(u),t.jsx(fa,{hover:!0,...u.getRowProps(),children:u.cells.map(h=>t.jsx(xa,{...h.getCellProps(),children:h.render("Cell")}))})))})]})},Xt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t.jsx(ma,{icon:t.jsx(Xa,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t.jsx(yc,{value:e.row.original.timestamp,timeZone:e.row.original.timestamp.includes("23:59")?"UTC":void 0})},{Header:"Application",accessor:"appName",Cell:Sc},{Header:"Environment",accessor:"environment"},{id:"requested",Header:"Requested",accessor:e=>e.yes+e.no},{Header:"Exposed",accessor:"yes"}],vc=({metrics:e,...n})=>{const s=g.useMemo(()=>e.reduce((a,o)=>a+o.yes,0),[e]),r=g.useMemo(()=>e.reduce((a,o)=>a+o.no,0),[e]);return t.jsx(Hn,{...n,totalYes:s,totalNo:r})},Cc=({metrics:e,hoursBack:n})=>{const s=Bt(),r=Bt();return e.length===0?t.jsxs(K,{mt:6,children:[t.jsx(W,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t.jsx(W,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):t.jsxs(g.Suspense,{fallback:null,children:[t.jsx(K,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t.jsx(wc,{metrics:e,hoursBack:n,statsSectionId:s})}),t.jsx(K,{mt:4,children:t.jsx(vc,{metrics:e,hoursBack:n,statsSectionId:s,tableSectionId:r})}),t.jsx(K,{mt:4,children:t.jsx(bc,{metrics:e,tableSectionId:r})})]})},wc=ya.lazy(()=>ja(()=>import("./FeatureMetricsChart-ig6HN-Ms.js"),__vite__mapDeps([]))),Tc=p("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ec=p("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%",alignItems:"center",maxHeight:"200px",overflowY:"auto"})),Ac=p("li")(({theme:e})=>({"& > [aria-pressed=true]":{backgroundColor:e.palette.background.alternative,color:e.palette.primary.contrastText},"& > [aria-pressed=true]:hover":{backgroundColor:e.palette.primary.light}})),en=({title:e,values:n,selectedValues:s,toggleValue:r,toggleValues:a})=>{const o=l=>()=>{r(l)},i=[...n].every(l=>s.includes(l)),c=g.useMemo(()=>Array.from(n).sort((l,d)=>l.localeCompare(d)),[n]);return t.jsxs("div",{children:[t.jsx(Tc,{children:e}),t.jsxs(Ec,{children:[c.map(l=>t.jsx(Ac,{children:t.jsx(wn,{label:l,onClick:o(l),"aria-pressed":s==null?void 0:s.includes(l),sx:Sa})},l)),a&&n.size>1&&t.jsx(je,{size:"small",onClick:a,"aria-pressed":i,children:i?"Unselect":"Select all"})]})]})},Dc=e=>{const n=new Map;return e.forEach(s=>{let r=n.get(s.timestamp);if(r||(r={...s,yes:0,no:0,variants:{}},n.set(s.timestamp,r)),r.yes+=s.yes,r.no+=s.no,s.variants){r.variants=r.variants||{};for(const[a,o]of Object.entries(s.variants))r.variants[a]=(r.variants[a]||0)+o}}),Array.from(n.values()).map(s=>({...s,variants:s.variants&&Object.keys(s.variants).length===0?void 0:s.variants}))},Fc=()=>{const e=A("projectId"),n=A("featureId"),s=Rc(e,n);An("Metrics");const r=Array.from(s)[0],[a,o]=ba({environment:Xe(va,r),applications:Xe(Ca,[]),hoursBack:Xe(wa,He)}),i=$c(n,a.hoursBack||He),c=Array.from(i)[0],{environment:l,hoursBack:d}=a,u=a.applications.filter(f=>f!==null);g.useEffect(()=>{a.applications&&a.applications.length===0&&c&&o({applications:[c]})},[JSON.stringify(Array.from(i))]);const h=[...i].every(f=>u.includes(f)),{featureMetrics:m}=Jn(n,d),[j,y]=g.useState(m);g.useEffect(()=>{m&&y(m)},[m]);const T=g.useMemo(()=>Dc((j==null?void 0:j.filter(f=>l===f.environment).filter(f=>u.includes(f.appName)))||[]).map(f=>({...f,appName:u.length>1?"all selected":f.appName,selectedApplications:u})),[j,l,JSON.stringify(u)]);return T?t.jsxs(At,{children:[t.jsxs(le,{container:!0,component:"header",spacing:2,children:[t.jsx(le,{item:!0,xs:12,md:5,children:t.jsx(b,{condition:s.size>0,show:t.jsx(en,{title:"Environments",values:s,selectedValues:[l],toggleValue:f=>{o({environment:f})}})})}),t.jsx(le,{item:!0,xs:12,md:5,children:t.jsx(b,{condition:i.size>0,show:t.jsx(en,{title:"Applications",values:i,selectedValues:u,toggleValues:()=>{o(h?{applications:[c]}:{applications:[...i]})},toggleValue:f=>{u.includes(f)?o({applications:u.filter(x=>x!==f)}):o({applications:[...u,f]})}})})}),t.jsx(le,{item:!0,xs:12,md:2,children:t.jsx(xc,{hoursBack:d,setHoursBack:f=>o({hoursBack:f})})})]}),t.jsx(Cc,{metrics:T,hoursBack:d})]}):null},Rc=(e,n)=>{const{feature:s}=M(e,n),r=s.environments.map(a=>a.name);return new Set(r)},$c=(e,n=He)=>{const{featureMetrics:s=[]}=Jn(e,n),r=s.map(a=>a.appName);return new Set(r)},kc=(e,n)=>{const s=new Set(e),r=new Set(n);return s.size!==r.size?!1:[...s].every(a=>r.has(a))},tn=p("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),nn=p(ie)(({theme:e})=>({marginBottom:e.spacing(1)})),Ic=p(wt)({padding:0}),Pc=({projectId:e,open:n,onClose:s,onClick:r,feature:a,changeRequests:o})=>{const i=A("projectId"),{project:c}=$n(e),{isChangeRequestConfiguredInAnyEnv:l}=Z(e),d=l(),u=g.useMemo(()=>kc(a.environments.map(j=>j.name),c.environments.map(j=>j.environment)),[a,c]),h=o?o.length>0:!1,m=a.dependencies.length>0||a.children.length>0;return t.jsx(b,{condition:u&&!m&&!h&&!d,show:t.jsx(oe,{open:n,onClose:s,onClick:r,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:t.jsxs(tn,{children:[t.jsx(nn,{severity:"success",children:"This feature toggle is compatible with the new project."}),t.jsx("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t.jsx(oe,{open:n,onClick:s,title:"Confirm change project",primaryButtonText:"Close",children:t.jsxs(tn,{children:[t.jsx(nn,{severity:"warning",children:"Cannot proceed with the move"}),t.jsx(b,{condition:m,show:t.jsxs("p",{children:[t.jsx("span",{children:"The feature toggle must not have any dependencies."})," ",t.jsx("br",{}),t.jsx("span",{children:"Please remove feature dependencies first."})]})}),t.jsx(b,{condition:!u,show:t.jsx("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t.jsx(b,{condition:h,show:t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"The feature toggle must not have any pending change requests. This feature toggle is currently referenced in the following change requests:"}),t.jsx(Ic,{children:o==null?void 0:o.map(j=>t.jsx(ve,{children:t.jsxs(Q,{to:`/projects/${i}/change-requests/${j.id}`,children:["View change request"," ",j.id]})},j.id))})]})}),t.jsx(b,{condition:d,show:t.jsxs("p",{children:["You're not allowed to move the feature to project"," ",t.jsx(Q,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},Oc=()=>{const{hasAccess:e}=g.useContext(mt),n=A("projectId"),s=A("featureId"),{feature:r,refetchFeature:a}=M(n,s),[o,i]=g.useState(!1),{changeFeatureProject:c}=Ke(),{setToastData:l,setToastApiError:d}=U(),[u,h]=g.useState(n),{projects:m}=Ta(),j=ce(),{changeRequests:y}=_n(n,s),T=async()=>{try{u&&(await c(n,s,u),a(),l({title:"Project changed",type:"success"}),i(!1),j(`/projects/${u}/features/${s}/settings`,{replace:!0}))}catch(x){d(V(x))}},f=g.useMemo(()=>m.map(x=>x.id).filter(x=>e(Lt,x)),[m,e]);return f.length===0?null:t.jsxs(t.Fragment,{children:[t.jsx(Ea,{value:u,onChange:h,label:"Project",filter:x=>f.includes(x),enabled:!0}),t.jsx(pe,{permission:Lt,onClick:()=>i(!0),disabled:u===n,projectId:n,children:"Save"}),t.jsx(Pc,{changeRequests:y,projectId:u,open:o,feature:r,onClose:()=>i(!1),onClick:T})]})},Bc=p("div")({display:"flex",alignItems:"center"}),Lc=p(W)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),_c=({projectId:e,featureId:n})=>{var o;const{feature:s}=M(e,n),r=ce(),a=()=>{r(`/projects/${e}/features/${n}/edit`)};return t.jsxs(t.Fragment,{children:[t.jsxs(Bc,{children:[t.jsx(Lc,{children:"Feature information"}),t.jsx(re,{permission:Ce,projectId:e,"data-loading":!0,onClick:a,tooltipProps:{title:"Edit"},children:t.jsx(we,{})})]}),t.jsxs(W,{children:["Name: ",t.jsx("strong",{children:s.name})]}),t.jsxs(W,{children:["Description:"," ",t.jsx("strong",{children:(o=s.description)!=null&&o.length?s.description:"no description"})]}),t.jsxs(W,{children:["Type: ",t.jsx("strong",{children:s.type})]}),t.jsxs(W,{children:["Impression Data:"," ",t.jsx("strong",{children:s.impressionData?"enabled":"disabled"})]})]})},Le="metadata",dt="project",Mc=p("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),qc=p("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,"& > *":{margin:e.spacing(1,0)}})),zc=()=>{const e=A("projectId"),n=A("featureId"),[s,r]=g.useState(Le),{uiConfig:a}=fe();return t.jsx(At,{header:"Settings",sx:{padding:0},children:t.jsxs(K,{sx:{display:"flex"},children:[t.jsx(Mc,{children:t.jsxs(wt,{children:[t.jsx(ve,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(Le),selected:s===Le,children:"Metadata"},0),t.jsx(ve,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>r(dt),selected:s===dt,hidden:!a.flags.P,children:"Project"},1)]})}),t.jsxs(qc,{children:[t.jsx(b,{condition:s===Le,show:t.jsx(_c,{projectId:e,featureId:n})}),t.jsx(b,{condition:s===dt&&a.flags.P,show:t.jsx(Oc,{})})]})]})})},Nc=({stale:e,showActive:n=!0})=>{if(!e&&!n)return null;const s=e?"Feature toggle is deprecated.":"Feature toggle is active.",r=e?"Stale":"Active";return t.jsx("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t.jsx(Ee,{color:e?"error":"success",title:s,children:r})})},sn=p("strong")({wordBreak:"break-all"}),Vc=()=>{const e=A("projectId"),n=A("featureId"),{archivedFeatures:s}=Aa(),r=Da(e,{name:n});return s?s.some(o=>o.name===n)?t.jsxs("p",{children:["The feature ",t.jsx(sn,{children:n})," has been archived. You can find it on the"," ",t.jsx(Q,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):t.jsxs("p",{children:["The feature ",t.jsx(sn,{children:n})," does not exist. Would you like to"," ",t.jsx(Q,{to:r,children:"create it"}),"?"]}):null},Hc=p(Q)(({theme:e})=>({textDecoration:"none",color:e.palette.primary.main,fontWeight:e.fontWeight.bold})),Wc=({isOpen:e,onClose:n,features:s,project:r})=>t.jsxs(oe,{title:"You can't archive a feature that other features depend on",open:e,primaryButtonText:"OK",onClick:n,children:[t.jsx("p",{children:"The following features depend on your feature:"}),t.jsx("ul",{children:s.map(a=>t.jsx("li",{children:t.jsx(Hc,{to:`/projects/${r}/features/${a}`,target:"_blank",rel:"noopener noreferrer",children:a})},a))})]}),Uc=e=>g.createElement("svg",{fill:"none",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},g.createElement("path",{d:"M1 12a5 5 0 0 1 5-5h4a5 5 0 0 1 4.584 7H14a1.993 1.993 0 0 1-1.375-.547A3 3 0 0 0 10 9H6a3 3 0 1 0 0 6h2.803a6.03 6.03 0 0 0 1.822 1.961A5.033 5.033 0 0 1 10 17H6a5 5 0 0 1-5-5Z",fill:"#202021"}),g.createElement("path",{d:"M9 12c0-.711.148-1.387.416-2H10c.532 0 1.016.208 1.375.547A3 3 0 0 0 14 15h4a3 3 0 1 0 0-6h-2.803a6.03 6.03 0 0 0-1.822-1.961C13.58 7.013 13.788 7 14 7h4a5 5 0 0 1 0 10h-4a5 5 0 0 1-5-5Z",fill:"#202021"})),Yc=e=>g.createElement("svg",{fill:"none",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},g.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M1 8a5 5 0 0 1 5-5h4a5 5 0 0 1 4.584 7H14a1.993 1.993 0 0 1-1.375-.547A3 3 0 0 0 10 5H6a3 3 0 0 0 0 6h2.803a6.03 6.03 0 0 0 1.822 1.961A5.033 5.033 0 0 1 10 13H8v3a1 1 0 0 0 1 1h1.17A3.001 3.001 0 0 1 13 15h7a3 3 0 1 1 0 6h-7a3.001 3.001 0 0 1-2.83-2H9a3 3 0 0 1-3-3v-3a5 5 0 0 1-5-5Zm8 0c0-.711.148-1.388.416-2H10c.532 0 1.016.208 1.375.547A3 3 0 0 0 14 11h4a3 3 0 1 0 0-6h-2.803a6.03 6.03 0 0 0-1.822-1.961C13.58 3.013 13.788 3 14 3h4a5 5 0 0 1 0 10h-4a5 5 0 0 1-5-5Z",fill:"#202021"})),Gc=p("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),Kc=p("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),an=p("div")({display:"flex",alignItems:"center"}),rn=p("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1),marginTop:e.spacing(1),fontSize:e.fontSizes.smallBody,padding:e.spacing(.75,1.5),backgroundColor:e.palette.background.elevation2,borderRadius:`${e.shape.borderRadiusMedium}px`,width:"max-content"}));p(Uc)(({theme:e})=>({width:e.fontSizes.smallBody,height:e.fontSizes.smallBody}));p(Yc)(({theme:e})=>({width:e.fontSizes.smallBody,height:e.fontSizes.smallBody}));const Jc=p("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),Qc=p("div")({flexShrink:0,display:"flex"}),Zc=p("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),Xc=p("div")(({theme:e})=>({padding:e.spacing(0,4)})),el=p(Fa)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),tl=p(Q)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),nl=()=>{var S,k;const e=A("projectId"),n=A("featureId"),{refetch:s}=$n(e),{favorite:r,unfavorite:a}=Ra(),{refetchFeature:o}=M(e,n),{setToastData:i,setToastApiError:c}=U(),[l,d]=g.useState(!1),[u,h]=g.useState(!1),[m,j]=g.useState(!1),[y,T]=g.useState(!1),f=Ie("(max-width:500px)"),{feature:x,loading:R,error:L,status:q}=M(e,n),z=ce(),{pathname:v}=$a(),C=ka(R),$=`/projects/${e}/features/${n}`,O=[{title:"Overview",path:`${$}`,name:"overview"},{title:"Metrics",path:`${$}/metrics`,name:"Metrics"},{title:"Variants",path:`${$}/variants`,name:"Variants"},{title:"Settings",path:`${$}/settings`,name:"Settings"},{title:"Event log",path:`${$}/logs`,name:"Event log"}],N=O.find(w=>w.path===v)??O[0],G=async()=>{try{x!=null&&x.favorite?await a(e,x.name):await r(e,x.name),o()}catch{c("Something went wrong, could not update favorite")}};if(q===404)return t.jsx(Vc,{});if(L!==void 0)return t.jsx("div",{ref:C});const Y=()=>{try{qa(x.name),T(!0),setTimeout(()=>{T(!1)},3e3)}catch{i({type:"error",title:"Could not copy feature name"})}};return t.jsxs("div",{ref:C,children:[t.jsxs(Gc,{children:[t.jsxs(Kc,{children:[t.jsxs(an,{children:[t.jsx(Ia,{onClick:G,isFavorite:x==null?void 0:x.favorite}),t.jsxs("div",{children:[t.jsxs(an,{children:[t.jsxs(Jc,{"data-loading":!0,children:[x.name," "]}),t.jsx(ee,{title:y?"Copied!":"Copy name",arrow:!0,children:t.jsx($e,{onClick:Y,style:{marginLeft:8},children:y?t.jsx(Pa,{style:{fontSize:16}}):t.jsx(Oa,{style:{fontSize:16}})})}),t.jsx(b,{condition:!f,show:t.jsx(Nc,{stale:x==null?void 0:x.stale})})]}),t.jsx(b,{condition:x.dependencies.length>0,show:t.jsxs(rn,{children:[t.jsx("b",{children:"Has parent: "}),t.jsx(tl,{to:`/projects/${x.project}/features/${(S=x==null?void 0:x.dependencies[0])==null?void 0:S.feature}`,children:(k=x==null?void 0:x.dependencies[0])==null?void 0:k.feature})]})}),t.jsx(b,{condition:x.children.length>0,show:t.jsxs(rn,{children:[t.jsx("b",{children:"Has children:"}),t.jsx(Yn,{childFeatures:x.children,project:x.project})]})})]})]}),t.jsxs(Qc,{children:[t.jsx(re,{permission:Ba,projectId:e,"data-loading":!0,component:Q,to:`/projects/${e}/features/${n}/copy`,tooltipProps:{title:"Clone"},children:t.jsx(er,{})}),t.jsx(re,{permission:La,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>h(!0),children:t.jsx(Za,{})}),t.jsx(re,{onClick:()=>j(!0),permission:Ce,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t.jsx(Ga,{})}),t.jsx(re,{onClick:()=>d(!0),permission:Ce,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t.jsx(_a,{})})]})]}),t.jsx(Zc,{}),t.jsx(Xc,{children:t.jsx(Ma,{value:N.path,indicatorColor:"primary",textColor:"primary",children:O.map(w=>t.jsx(el,{label:w.title,value:w.path,onClick:()=>z(w.path),"data-testid":`TAB-${w.title}`},w.title))})})]}),t.jsxs(Fn,{children:[t.jsx(xe,{path:"metrics",element:t.jsx(Fc,{})}),t.jsx(xe,{path:"logs",element:t.jsx(nr,{})}),t.jsx(xe,{path:"variants",element:t.jsx(uc,{})}),t.jsx(xe,{path:"settings",element:t.jsx(zc,{})}),t.jsx(xe,{path:"*",element:t.jsx($i,{})})]}),t.jsx(b,{condition:x.children.length>0,show:t.jsx(Wc,{features:x.children,project:e,isOpen:u,onClose:()=>h(!1)}),elseShow:t.jsx(Ka,{isOpen:u,onConfirm:()=>{s(),z(`/projects/${e}`)},onClose:()=>h(!1),projectId:e,featureIds:[n]})}),t.jsx(Ja,{isStale:x.stale,isOpen:m,onClose:()=>{j(!1),o()},featureId:n,projectId:e}),t.jsx(Kn,{open:l,setOpen:d})]})},ol=Object.freeze(Object.defineProperty({__proto__:null,default:nl},Symbol.toStringTag,{value:"Module"}));export{ol as F,uo as d};
20
20
  function __vite__mapDeps(indexes) {
21
21
  if (!__vite__mapDeps.viteFileDeps) {
22
22
  __vite__mapDeps.viteFileDeps = []