unleash-server 5.6.2 → 5.6.3

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 (24) hide show
  1. package/frontend/build/index.html +1 -1
  2. package/frontend/build/static/{AdvancedPlayground-b7bccfbe.js → AdvancedPlayground-16873e2b.js} +1 -1
  3. package/frontend/build/static/{CreateProject-556f9c57.js → CreateProject-301a70d0.js} +1 -1
  4. package/frontend/build/static/{Error-db0d1d33.js → Error-e318eb3d.js} +1 -1
  5. package/frontend/build/static/{FeatureArchiveDialog-9165a49c.js → FeatureArchiveDialog-37e2bf5f.js} +1 -1
  6. package/frontend/build/static/{FeatureMetricsChart-c575d046.js → FeatureMetricsChart-99739e53.js} +1 -1
  7. package/frontend/build/static/{FeatureViewLazyExport-e2d57dd1.js → FeatureViewLazyExport-b7e0c05f.js} +2 -2
  8. package/frontend/build/static/{LazyAdminExport-d83c093e.js → LazyAdminExport-cefc037c.js} +2 -2
  9. package/frontend/build/static/{LazyProjectExport-9d441d13.js → LazyProjectExport-d124dbbf.js} +1 -1
  10. package/frontend/build/static/{NetworkOverview-0d48bf0d.js → NetworkOverview-9d3e2075.js} +2 -2
  11. package/frontend/build/static/{NetworkTraffic-0aa8a7ac.js → NetworkTraffic-48e5c2df.js} +1 -1
  12. package/frontend/build/static/{ReactJSONEditor-693b261e.js → ReactJSONEditor-8c920758.js} +1 -1
  13. package/frontend/build/static/{RoleCell-900af983.js → RoleCell-8209535b.js} +1 -1
  14. package/frontend/build/static/{StrategyItemContainer-ec516690.js → StrategyItemContainer-bb9f1a81.js} +1 -1
  15. package/frontend/build/static/{chartjs-adapter-date-fns.esm-9887b8bf.js → chartjs-adapter-date-fns.esm-76abe251.js} +1 -1
  16. package/frontend/build/static/{flowchart-elk-definition-170a3958-44f11932.js → flowchart-elk-definition-170a3958-1cbddeed.js} +1 -1
  17. package/frontend/build/static/{index-97019f83.js → index-f848dd08.js} +4 -4
  18. package/frontend/build/static/{is_dark-bae6928c.js → is_dark-d8173a33.js} +1 -1
  19. package/frontend/build/static/{mindmap-definition-44684416-9154286a.js → mindmap-definition-44684416-2e94ada0.js} +1 -1
  20. package/frontend/build/static/{timeline-definition-8e5a9bc6-6cd8c6b1.js → timeline-definition-8e5a9bc6-f407e743.js} +1 -1
  21. package/frontend/build/static/{unknownify-470ee1ff.js → unknownify-5a51f235.js} +1 -1
  22. package/frontend/build/static/{useApiTokens-9215ec27.js → useApiTokens-0654f105.js} +1 -1
  23. package/frontend/build/static/{useProjectForm-5dd2ec50.js → useProjectForm-b9260dd5.js} +1 -1
  24. package/package.json +1 -1
@@ -1,7 +1,7 @@
1
- import{c as Gt,j as t,s as u,aG as A,aH as j,aI as Fn,d as r,aJ as $n,C as b,aK as te,aL as ye,aM as G,aN as Se,aO as In,aP as Ve,r as f,aQ as de,aR as we,aS as ut,aT as Pn,aU as Bn,aV as On,aW as Mn,f as K,aX as ue,aY as ae,h as z,T as q,aZ as Re,a_ as ke,a$ as Kt,b0 as X,b1 as be,w as Q,z as qe,b2 as _n,b3 as Ln,b4 as Fe,M as re,b5 as ve,b6 as Jt,b7 as le,b8 as ne,aA as pe,L as he,b9 as Zt,ba as jn,bb as zn,bc as Vn,bd as qn,be as it,bf as Nn,bg as Wn,J as P,B as J,bh as Hn,bi as Un,bj as Yn,bk as Gn,bl as Kn,bm as Jn,bn as Zn,bo as Qn,bp as Xn,bq as ea,N as ta,b as Qt,ae as Ne,H as Ee,br as pt,i as Te,W as ht,bs as Xt,al as xe,$ as na,bt as gt,bu as me,bv as ie,bw as en,a3 as tn,bx as aa,by as se,bz as oa,bA as sa,Z as ra,bB as nn,bC as ia,bD as ca,bE as la,bF as an,bG as da,bH as ua,u as pa,bI as on,bJ as ft,bK as ha,bL as ga,bM as fa,bN as vt,bO as sn,t as mt,az as We,bP as rn,bQ as ma,bR as cn,bS as ya,bT as Sa,bU as ba,bV as yt,bW as va,bX as He,bY as Ca,V as ln,D as De,bZ as wa,b_ as Ta,b$ as xa,c0 as Ea,c1 as dn,c2 as un,c3 as ce,c4 as ct,c5 as Da,c6 as pn,c7 as Aa,c8 as Ra,g as ka,c9 as Fa,ca as Ge,cb as Ct,ax as $a,aC as Ia,cc as fe,cd as wt,ce as Pa,cf as Ba,m as Oa,av as St,aw as Ma,aq as Tt,cg as _a,ch as La,ci as ja,cj as xt,ad as hn,ck as za,a5 as Ke,ah as Va,a7 as qa,a8 as Na,a9 as Wa,aa as Ha,ab as Ua,ac as Ya,cl as Ga,cm as Ka,cn as Et,co as Ja,cp as gn,cq as Za,v as Qa,cr as Dt,cs as Xa,ct as eo,cu as to,cv as no,cw as ao,cx as oo,an as so,cy as ro,cz as io,cA as co,cB as lo,cC as uo,cD as po}from"./index-97019f83.js";import{C as fn,f as mn,E as ho,F as go,V as fo,a as mo,u as yo,b as So,T as bo,c as vo,d as Co,W as wo,e as To,g as xo}from"./FeatureArchiveDialog-9165a49c.js";import{S as Eo}from"./StrategyItemContainer-ec516690.js";const Do=Gt(t("path",{d:"m20.54 5.23-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5 6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z"}),"Archive"),Ao=Gt(t("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"}),"Assessment"),Ro=u("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),ko=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=j(e,n);return a.name?t(Ro,{children:t(Fn,{title:"Event log",feature:n,displayInline:!0})}):null},Fo=u("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"}})),$o=u("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Io=u("div")({display:"flex",alignItems:"center"}),Po=u("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),Bo=u("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),At=u("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize})),Rt=u("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),Oo=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=j(e,n),{project:s,description:o,type:i}=a,c=In(i);return t(Fo,{children:r($o,{children:[r(Io,{"data-loading":!0,children:[t(c,{sx:l=>({marginRight:l.spacing(2),height:"40px",width:"40px",fill:l.palette.primary.contrastText})})," ",r(Po,{children:[$n(i||"")," toggle"]})]}),r(Bo,{children:[r(At,{"data-loading":!0,children:["Project: ",s]}),t(b,{condition:!!o,show:r(At,{"data-loading":!0,children:[t("div",{children:"Description:"}),r(Rt,{children:[t("p",{children:o}),t(te,{projectId:e,permission:ye,component:G,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(Se,{sx:l=>({color:l.palette.primary.contrastText})})})]})]}),elseShow:t("span",{"data-loading":!0,children:r(Rt,{children:["No description."," ",t(te,{projectId:e,permission:ye,component:G,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(Se,{sx:l=>({color:l.palette.primary.contrastText})})})]})})})]})]})})},kt={lastHourUsage:[],seenApplications:[]},Mo=(e,n,a={})=>{const s=async()=>{const h=de(`api/admin/client-metrics/features/${n}`),m=await fetch(h,{method:"GET"}).then(we("feature metrics"));return m.ok?m.json():kt},o=`${e}_${n}_metrics`,{data:i,error:c}=Ve(o,s,{...a}),[l,d]=f.useState(!c&&!i),p=()=>{ut(o)};return f.useEffect(()=>{d(!c&&!i)},[i,c]),{metrics:i||kt,error:c,loading:l,refetch:p,FEATURE_METRICS_CACHE_KEY:o}},_o=e=>({yes:0,no:0,environment:e,timestamp:""}),Lo=(e,n)=>e.map(a=>n.lastHourUsage.find(o=>o.environment===a.name)||_o(a.name)),jo=e=>(n,a,s)=>(s.revalidateOnFocus=!1,s.revalidateIfStale=!1,s.revalidateOnReconnect=!1,e(n,a,s)),zo=Pn(Ve,jo),yn=(e,n)=>{const{refetchFeature:a}=j(e,n),s=Bn(e,n),{data:o,error:i,mutate:c}=zo(["useFeatureImmutable",s],()=>On(s)),l=f.useCallback(async()=>{await c(),await a()},[c,a]);return{feature:(o==null?void 0:o.body)||Mn,refetchFeature:l,loading:!i&&!o,status:o==null?void 0:o.status,error:i}},Sn=(e,n,a)=>{const{setToastData:s,setToastApiError:o}=K(),{addChange:i}=ue(),{refetch:c}=ae(e),[l,d]=f.useState({isOpen:!1}),p=f.useCallback((g,E,y)=>{d({featureName:n,environment:g,fromEnvironment:y,strategy:E,isOpen:!0})},[]),h=f.useCallback((g,E,y)=>{d({featureName:n,environment:g,fromEnvironment:y,strategies:E,isOpen:!0})},[]),m=f.useCallback(()=>{d({isOpen:!1})},[]),S=f.useCallback(async()=>{try{await i(e,l.environment,{feature:l.featureName,action:a,payload:l.strategy}),c(),d({isOpen:!1}),s({type:"success",title:"Changes added to the draft!"})}catch(g){o(z(g)),d({isOpen:!1})}},[i]),C=f.useCallback(async()=>{try{await Promise.all(l.strategies.map(g=>i(e,l.environment,{feature:l.featureName,action:a,payload:g}))),c(),d({isOpen:!1}),s({type:"success",title:"Changes added to the draft!"})}catch(g){o(z(g)),d({isOpen:!1})}},[i]);return{onChangeRequestAddStrategy:p,onChangeRequestAddStrategies:h,onChangeRequestAddStrategyClose:m,onChangeRequestAddStrategyConfirm:S,onChangeRequestAddStrategiesConfirm:C,changeRequestDialogDetails:l}},Vo=({payload:e,fromEnvironment:n,environment:a})=>r(q,{children:[r("strong",{children:["Copy ",Re((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),qo=({environmentId:e,environments:n,strategy:a})=>{const s=A("projectId"),o=A("featureId"),[i,c]=f.useState(null),l=!!i,{addStrategyToFeature:d}=ke(),{setToastData:p,setToastApiError:h}=K(),{refetchFeature:m}=j(s,o),{refetchFeature:S}=yn(s,o),C=()=>{c(null)},g=Kt(s),{isChangeRequestConfigured:E}=X(s),{changeRequestDialogDetails:y,onChangeRequestAddStrategyClose:w,onChangeRequestAddStrategy:$,onChangeRequestAddStrategyConfirm:M}=Sn(s,o,"addStrategy"),V=async v=>{const{id:R,...B}={...a,targetEnvironment:v};if(E(v)){await $(v,{id:R,...B},e);return}try{await d(s,o,v,a),m(),S(),p({title:"Strategy created",text:`Successfully copied a strategy to ${v}`,type:"success"})}catch(N){h(z(N))}C()},_=n.some(v=>g(be,v));return r("div",{children:[t(fn,{isOpen:y.isOpen,onClose:w,environment:y==null?void 0:y.environment,onConfirm:M,messageComponent:t(Vo,{fromEnvironment:y.fromEnvironment,payload:y.strategy})}),t(Q,{title:`Copy to another environment${_?"":" (Access denied)"}`,children:t("div",{children:t(qe,{size:"large",id:`copy-strategy-icon-menu-${a.id}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,onClick:v=>{c(v.currentTarget)},"data-testid":_n,disabled:!_,children:t(Ln,{})})})}),t(Fe,{id:"basic-menu",anchorEl:i,open:l,onClose:C,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(v=>{const R=g(be,v);return t(Q,{title:R?"":"You don't have access to add a strategy to this environment",children:t("div",{children:r(re,{onClick:()=>V(v),disabled:!R,children:[t(b,{condition:!R,show:t(ve,{children:t(Jt,{fontSize:"small"})})}),r(le,{children:["Copy to ",v]})]})})},v)})})]})},bn=()=>t(he,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),No=({onRemove:e,onClose:n,isOpen:a})=>t(ne,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(bn,{})}),Wo=u("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),Ho=({onRemove:e,onClose:n,isOpen:a})=>r(ne,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(bn,{}),t(Wo,{children:t(q,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(q,{fontWeight:"bold",children:"Remove strategy"})]}),Uo=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{deleteStrategyFromFeature:o}=ke(),{setToastData:i,setToastApiError:c}=K(),l=pe(),{refetchFeature:d}=j(e,n);return async h=>{try{h.preventDefault(),await o(e,n,a,s),i({title:"Strategy deleted",type:"success"}),d(),l(Zt(e,n))}catch(m){c(z(m))}}},Yo=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{addChange:o}=ue(),{refetch:i}=ae(e),{setToastData:c,setToastApiError:l}=K();return async p=>{try{p.preventDefault(),await o(e,a,{action:"deleteStrategy",feature:n,payload:{id:s}}),c({title:"Changes added to the draft!",type:"success"}),await i()}catch(h){l(z(h))}}},Go=({projectId:e,featureId:n,environmentId:a,strategyId:s,text:o,isOpen:i,onClose:c})=>{const{isChangeRequestConfigured:l}=X(e),d=Uo({featureId:n,projectId:e,strategyId:s,environmentId:a}),p=Yo({featureId:n,projectId:e,strategyId:s,environmentId:a});return l(a)?t(Ho,{isOpen:i,onClose:()=>c(),onRemove:async h=>{await p(h),c()}}):t(No,{isOpen:i,onClose:()=>c(),onRemove:d})},Ko=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{refetchFeature:o}=j(e,a),{setStrategyDisabledState:i}=ke(),{setToastData:c,setToastApiError:l}=K(),d=p=>async()=>{try{await i(e,a,n,s.id,!p),c({title:`Strategy ${p?"enabled":"disabled"}`,type:"success"}),o()}catch(h){l(z(h))}};return{onDisable:d(!1),onEnable:d(!0)}},Jo=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{addChange:o}=ue(),{refetch:i}=ae(e),{setToastData:c,setToastApiError:l}=K(),d=p=>async()=>{try{await o(e,n,{action:"updateStrategy",feature:a,payload:{...s,disabled:!p}}),c({title:"Changes added to the draft!",type:"success"}),await i()}catch(h){l(z(h))}};return{onSuggestDisable:d(!1),onSuggestEnable:d(!0)}},Zo=({isOpen:e,onClose:n,...a})=>{var C;const{projectId:s,environmentId:o}=a,{isChangeRequestConfigured:i}=X(s),c=i(o),{onSuggestEnable:l,onSuggestDisable:d}=Jo({...a}),{onEnable:p,onDisable:h}=Ko({...a}),m=!!((C=a.strategy)!=null&&C.disabled);return t(ne,{title:c?`Add ${m?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${m?"enable":"disable"} this strategy?`,open:e,primaryButtonText:c?"Add to draft":`${m?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:g=>{g.preventDefault(),c?m?l():d():m?p():h(),n()},onClose:()=>n(),children:t(b,{condition:c,show:t(jn,{environment:o}),elseShow:r(he,{severity:"error",children:[m?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})};var bt={},Qo=Vn;Object.defineProperty(bt,"__esModule",{value:!0});var vn=bt.default=void 0,Xo=Qo(zn()),es=qn,ts=(0,Xo.default)((0,es.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");vn=bt.default=ts;const ns=({projectId:e,strategy:n,featureId:a,environmentId:s})=>{const[o,i]=f.useState(null),[c,l]=f.useState(!1),[d,p]=f.useState(!1),h=!!o,m=E=>{i(E.currentTarget)},S=E=>{i(null),E.stopPropagation()},C=it(Nn,e,s),g=it(Wn,e,s);return r(P,{children:[t(J,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t(Q,{title:"More actions",children:t(qe,{onClick:m,size:"small","aria-controls":h?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":h?"true":void 0,"data-testid":Hn,children:t(Un,{sx:{width:32,height:32}})})})}),r(Fe,{anchorEl:o,id:"actions-menu",open:h,onClose:S,onClick:S,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":Yn,children:[t(Q,{title:n.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:r(re,{disabled:!C,onClick:()=>l(!0),children:[t(ve,{children:n.disabled?t(Gn,{}):t(Kn,{})}),t(le,{children:n.disabled?"Enable":"Disable"})]})}),t(Q,{title:"Remove strategy",arrow:!0,placement:"left",children:r(re,{disabled:!g,onClick:()=>p(!0),"data-testid":Jn,children:[t(ve,{children:t(vn,{})}),t(le,{children:"Remove"})]})})]}),t(Zo,{isOpen:c,onClose:()=>l(!1),projectId:e,featureId:a,environmentId:s,strategy:n}),t(Go,{isOpen:d,onClose:()=>p(!1),projectId:e,featureId:a,environmentId:s,strategyId:n.id})]})},as=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:s,otherEnvironments:o,orderNumber:i,headerChildren:c})=>{const l=A("projectId"),d=A("featureId"),p=Zn(l,d,e,n.id);return r(Eo,{strategy:n,onDragStart:a,onDragEnd:s,orderNumber:i,actions:r(P,{children:[c,t(b,{condition:!!(o&&(o==null?void 0:o.length)>0),show:()=>t(qo,{environmentId:e,environments:o,strategy:n})}),t(te,{permission:Qn,environmentId:e,projectId:l,component:G,to:p,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t(Se,{})}),t(ns,{projectId:l,featureId:d,environmentId:e,strategy:n})]}),children:[t(Xn,{strategy:n}),n.variants?t(ea,{variants:n.variants}):null]})},os=(e,n,a,s)=>{const{data:o}=ae(e),i=o==null?void 0:o.find(d=>d.environment===a),c=i==null?void 0:i.features.find(d=>d.name===n);return c==null?void 0:c.changes.find(d=>d.action==="updateStrategy"||d.action==="deleteStrategy"?d.payload.id===s:!1)},ss=({strategy:e,index:n,environmentName:a,otherEnvironments:s,isDragging:o,onDragStartRef:i,onDragOver:c,onDragEnd:l})=>{const d=A("projectId"),p=A("featureId"),h=f.useRef(null),m=os(d,p,a,e.id);return r(J,{ref:h,onDragOver:c(h,n),sx:{opacity:o?"0.5":"1"},children:[t(b,{condition:n>0,show:t(ta,{text:"OR"})}),t(as,{strategy:e,environmentId:a,otherEnvironments:s,onDragStart:i(h,n),onDragEnd:l,orderNumber:n+1,headerChildren:t(rs,{change:m})})]},e.id)},rs=({change:e})=>{const n=Qt();return Ne(n.breakpoints.down("sm"))?null:r(J,{sx:{mr:1.5},children:[t(b,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(Ee,{color:"warning",children:"Modified in draft"})}),t(b,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(Ee,{color:"error",children:"Deleted in draft"})})]})},is=({environmentId:e,environments:n,onClick:a})=>{const s=A("projectId"),[o,i]=f.useState(null),c=!!o,{hasAccess:l}=f.useContext(pt),d=n.some(p=>l(be,s,p));return r("div",{children:[t(Q,{title:d?"":"(Access denied)",children:t("div",{children:t(Te,{id:`copy-all-strategies-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:p=>{i(p.currentTarget)},disabled:!d,variant:"outlined",children:"Copy from another environment"})})}),t(Fe,{id:"basic-menu",anchorEl:o,open:c,onClose:()=>{i(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(p=>{const h=l(be,s,p);return t(Q,{title:h?"":"You don't have access to add a strategy to this environment",children:t("div",{children:r(re,{onClick:()=>a(p),disabled:!h,children:[t(b,{condition:!h,show:t(ve,{children:t(Jt,{fontSize:"small"})})}),r(le,{children:["Copy from ",p]})]})})},p)})})]})},cs=u("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),ls=({payload:e,fromEnvironment:n,environment:a})=>r(cs,{children:[t(q,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(s=>r(q,{children:[r("strong",{children:[Re((s==null?void 0:s.name)||"")," strategy"," "]})," "]})),r(q,{children:["from ",n," to ",a]})]}),ds=u("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}})),us=u("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),ps=u(ht)(({theme:e})=>({fontWeight:e.fontWeight.bold})),hs=u(G)(({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}})),Je=({projectId:e,featureId:n,environmentId:a,strategy:s,defaultStrategy:o})=>{const i=Xt(s.name),c=Re(s.name),{trackEvent:l}=xe(),d=mn(e,n,a,s.name,o);return r(hs,{to:d,onClick:()=>{l("strategy-add",{props:{buttonTitle:s.displayName||c}})},children:[t(ds,{children:t(i,{})}),r("div",{children:[t(ps,{text:s.displayName||c,maxWidth:"200",maxLength:25}),t(us,{children:s.description})]})]})},Ze=u(q)(({theme:e})=>({fontSize:e.fontSizes.smallBody,padding:e.spacing(1,2)})),gs=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:s}=na(),o=s.filter(l=>!l.deprecated&&!l.editable),i=s.filter(l=>!l.deprecated&&l.editable),c={name:"flexibleRollout",displayName:"Default strategy",description:"This is the default strategy defined for this environment in the project"};return r(gt,{dense:!0,children:[r(P,{children:[r(Ze,{color:"textSecondary",children:[a," environment default strategy"]}),t(me,{children:t(Je,{projectId:e,featureId:n,environmentId:a,strategy:c,defaultStrategy:!0})},c.name)]}),t(Ze,{color:"textSecondary",children:"Predefined strategy types"}),o.map(l=>t(me,{children:t(Je,{projectId:e,featureId:n,environmentId:a,strategy:l})},l.name)),t(b,{condition:i.length>0,show:r(P,{children:[t(Ze,{color:"textSecondary",children:"Custom strategies"}),i.map(l=>t(me,{children:t(Je,{projectId:e,featureId:n,environmentId:a,strategy:l})},l.name))]})})]})},fs=u("div")({flexShrink:0}),ms=u(ie)(({theme:e})=>({minWidth:0,width:e.spacing(4.5),alignItems:"center",justifyContent:"center",align:"center",flexDirection:"column",marginLeft:e.spacing(1)})),lt=({label:e,projectId:n,featureId:a,environmentId:s,variant:o,size:i,matchWidth:c})=>{const[l,d]=f.useState(),p=pe(),{trackEvent:h}=xe(),m=!!l,S=m?"FeatureStrategyMenuPopover":void 0,C=()=>{d(void 0)},g=w=>{h("strategy-add",{props:{buttonTitle:e}}),p(y)},E=w=>{d(w.currentTarget)},y=mn(n,a,s,"flexibleRollout",!0);return r(fs,{onClick:w=>w.stopPropagation(),children:[t(ie,{permission:be,projectId:n,environmentId:s,onClick:g,"aria-labelledby":S,variant:o,size:i,sx:{minWidth:c?"282px":"auto"},children:e}),t(ms,{permission:be,projectId:n,environmentId:s,onClick:E,"aria-labelledby":S,variant:"outlined",size:i,hideLockIcon:!0,tooltipProps:{title:"More strategies"},children:t(en,{sx:w=>({margin:w.spacing(.25,0)})})}),t(tn,{id:S,open:m,anchorEl:l,onClose:C,onClick:C,PaperProps:{sx:w=>({paddingBottom:w.spacing(1)})},children:t(gs,{projectId:n,featureId:a,environmentId:s})})]})},ys=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Ss=u("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),bs=u("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),vs=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:s}=ke(),{setToastData:o,setToastApiError:i}=K(),{refetchFeature:c}=j(e,n),{refetchFeature:l}=yn(e,n),{feature:d}=j(e,n),p=d==null?void 0:d.environments.filter($=>$.name!==a&&$.strategies&&$.strategies.length>0),{isChangeRequestConfigured:h}=X(e),{changeRequestDialogDetails:m,onChangeRequestAddStrategies:S,onChangeRequestAddStrategiesConfirm:C,onChangeRequestAddStrategyClose:g}=Sn(e,n,"addStrategy"),E=($=!1)=>{c(),l(),o({title:$?"Strategies created":"Strategy created",text:$?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},y=async $=>{var V;const M=((V=p==null?void 0:p.find(_=>_.name===$))==null?void 0:V.strategies)||[];if(h(a)){await S(a,M,$);return}try{await Promise.all(M.map(_=>{const{id:v,...R}={..._,environment:a};return s(e,n,a,R)})),E(!0)}catch(_){i(z(_))}},w=p&&p.length>0;return r(P,{children:[t(fn,{isOpen:m.isOpen,onClose:g,environment:m==null?void 0:m.environment,onConfirm:C,messageComponent:t(ls,{fromEnvironment:m.fromEnvironment,payload:m.strategies})}),r(ys,{children:[t(Ss,{children:"You have not defined any strategies yet."}),r(bs,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(G,{to:"/admin/api",children:"API key configured"})," for this environment."]}),r(J,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t(lt,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:w}),t(b,{condition:w,show:t(is,{environmentId:a,environments:p.map($=>$.name),onClick:y})})]})]})]})},Cs=u("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ws=u("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),Ts=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const s=A("projectId"),o=A("featureId"),{setStrategiesSortOrder:i}=ke(),{addChange:c}=ue(),{isChangeRequestConfigured:l}=X(s),{refetch:d}=ae(s),{setToastData:p,setToastApiError:h}=K(),{refetchFeature:m}=j(s,o),[S,C]=f.useState((e==null?void 0:e.strategies)||[]),[g,E]=f.useState(null);if(f.useEffect(()=>{C((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const y=async v=>{try{await i(s,o,e.name,v),m(),p({title:"Order of strategies updated",type:"success"})}catch(R){h(z(R))}},w=async v=>{await c(s,e.name,{action:"reorderStrategy",feature:o,payload:v}),p({title:"Strategy execution order added to draft",type:"success",confetti:!0}),d()},$=async v=>{try{l(e.name)?await w(v):await y(v)}catch(R){h(z(R))}},M=(v,R)=>B=>{var N;E({id:S[R].id,index:R,height:((N=v.current)==null?void 0:N.offsetHeight)||0}),v!=null&&v.current&&(B.dataTransfer.effectAllowed="move",B.dataTransfer.setData("text/html",v.current.outerHTML),B.dataTransfer.setDragImage(v.current,20,20))},V=v=>(R,B)=>N=>{if(g===null||R.current===null||g.index===B||v===g.id)return;const{top:Z,bottom:U}=R.current.getBoundingClientRect(),oe=N.clientY-Z<g.height,x=U-N.clientY<g.height,I=g.index>B;if(oe&&I||x&&!I){const F=[...S],T=F.splice(g.index,1)[0];F.splice(B,0,T),C(F),E({...g,index:B})}},_=()=>{E(null),$(S.map((v,R)=>({id:v.id,sortOrder:R})))};return t(Cs,{children:r(ws,{children:[t(b,{condition:S.length>0&&n,show:()=>t(he,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(b,{condition:S.length>0,show:t(P,{children:S.map((v,R)=>t(ss,{strategy:v,index:R,environmentName:e.name,otherEnvironments:a,isDragging:(g==null?void 0:g.id)===v.id,onDragStartRef:M,onDragOver:V(v.id),onDragEnd:_},v.id))}),elseShow:t(vs,{projectId:s,featureId:o,environmentId:e.name})})]})})},Cn=(e,n)=>e===0?0:Math.round(n/e*100);var Ue={},Ye={};Object.defineProperty(Ye,"__esModule",{value:!0});Ye.defaultOptions=void 0;Ye.defaultOptions={lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var ee={};Object.defineProperty(ee,"__esModule",{value:!0});ee.getLocales=ee.getFractionDigits=ee.roundTo=ee.parseValue=void 0;function xs(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}ee.parseValue=xs;function Es(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))}ee.roundTo=Es;function Ds(e){var n;if(Number.isInteger(e))return 0;const a=e.toString().split(".")[1];return(n=a==null?void 0:a.length)!==null&&n!==void 0?n:0}ee.getFractionDigits=Ds;function As(){var e;return typeof navigator>"u"?[]:Array.from((e=navigator.languages)!==null&&e!==void 0?e:[])}ee.getLocales=As;Object.defineProperty(Ue,"__esModule",{value:!0});Ue.millify=void 0;const Ft=Ye,Be=ee,$t=1e3;function*It(e){let n=$t;for(;;){const a=e/n;if(a<1)return;yield a,n*=$t}}function wn(e,n){var a,s;const o=n?{...Ft.defaultOptions,...n}:Ft.defaultOptions;if(!Array.isArray(o.units)||!o.units.length)throw new Error("Option `units` must be a non-empty array");let i;try{i=Be.parseValue(e)}catch(g){return g instanceof Error&&console.warn(`WARN: ${g.message} (millify)`),String(e)}const c=i<0?"-":"";i=Math.abs(i);let l=0;for(const g of It(i))i=g,l+=1;if(l>=o.units.length)return e.toString();let p=Be.roundTo(i,o.precision);for(const g of It(p))p=g,l+=1;const h=(a=o.units[l])!==null&&a!==void 0?a:"",m=o.lowercase?h.toLowerCase():h,S=o.space?" ":"",C=p.toLocaleString((s=o.locales)!==null&&s!==void 0?s:Be.getLocales(),{minimumFractionDigits:Be.getFractionDigits(p)});return`${c}${C}${S}${m}`}Ue.millify=wn;var Rs=Ue.default=wn;const ze=({value:e,threshold:n=1e6,precision:a=2})=>{let s,o=!1;e<n?s=e.toLocaleString():(s=Rs(e,{precision:a}),o=!0);const i=t("span",{"data-testid":aa,children:s});return t(b,{condition:o,show:t(Q,{title:e.toLocaleString(),arrow:!0,children:i}),elseShow:i})},Qe=u("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),Xe=u("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),et=u("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),tt=u("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})),Tn=({totalYes:e,totalNo:n,hoursBack:a,statsSectionId:s,tableSectionId:o})=>{const i=a===1?"in the last hour":`in the last ${a} hours`;return r(se,{container:!0,spacing:2,id:s,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t(se,{item:!0,xs:12,sm:4,children:r(Qe,{children:[t(Xe,{children:"Exposure"}),t(et,{children:t(ze,{value:e})}),r(tt,{children:["Total exposure of the feature in the environment"," ",i,"."]})]})}),t(se,{item:!0,xs:12,sm:4,children:r(Qe,{children:[t(Xe,{children:"Exposure %"}),r(et,{children:[Cn(e+n,e),"%"]}),r(tt,{children:["% total exposure of the feature in the environment"," ",i,"."]})]})}),t(se,{item:!0,xs:12,sm:4,children:r(Qe,{children:[t(Xe,{children:"Requests"}),t(et,{children:t(ze,{value:e+n})}),r(tt,{children:["Total requests for the feature in the environment"," ",i,"."]})]})})]})},ks=u("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}})),Fs=u("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})),$s=({children:e})=>t(ks,{children:t(Fs,{children:e})}),Is=({environmentMetric:e})=>e?r(P,{children:[t($s,{children:"Feature toggle exposure"}),t("div",{children:t(Tn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Pt=u("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),Bt=u("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Ot=u("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Mt=u("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),Ps=u(oa)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),Bs=u("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),Os=({environmentMetric:e,disabled:n=!1})=>{const a=sa();if(!e)return null;const s=e.yes+e.no,o=Cn(s,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?r(Pt,{children:[r(Bt,{children:[r(Ot,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),r(Mt,{style:{color:n?a.palette.text.secondary:a.palette.text.primary},"data-loading":!0,children:["The feature has been requested ",t("b",{children:"0 times"})," and exposed",t("b",{children:" 0 times"})," in the last hour"]})]}),t(Ps,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):r(Pt,{children:[r(Bt,{children:[r(Ot,{children:[o,"%"]}),r(Mt,{children:["The feature has been requested"," ",r("b",{children:[t(ze,{value:s})," times"]})," ","and exposed"," ",r("b",{children:[t(ze,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(Bs,{"data-loading":!0,children:t(ra,{percentage:o,size:"3rem"})})]})},nt=({strategy:e})=>{const n=Xt(e.name);return t(Q,{title:Re(e.name)+(e.title?` - ${e.title}`:""),arrow:!0,children:t(Ms,{children:t(n,{})})})},Ms=u("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)}})),_t=u("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),at=u("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),_s=u("div")(({theme:e})=>({display:"flex",flexDirection:"row",alignItems:"center",gap:e.spacing(1)})),Oe=5,Ls=({strategies:e})=>e!=null&&e.length?e.length>Oe+1?r(_t,{"aria-label":"Feature strategies",children:[e.slice(0,Oe).map(n=>t(at,{children:t(nt,{strategy:n})},n.id)),r(nn,{tooltip:e.slice(Oe).map(n=>t(at,{children:r(_s,{children:[t(nt,{strategy:n})," ",Re(n.name)+(n.title?` - ${n.title}`:"")]})},n.id)),children:["(+",e.length-Oe,")"]})]}):t(_t,{"aria-label":"Feature strategies",children:e.map(n=>t(at,{children:t(nt,{strategy:n})},n.id))}):null,js=u("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})),zs=u(ia)({boxShadow:"none",background:"none"}),Vs=u(ca)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),qs=u(la,{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)}})),Ns=u(Ts)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Ws=u("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})),Hs=u("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Us=u(ho)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Ys=u(ht)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Gs=u("div")(({theme:e})=>({display:"flex",alignItems:"center",marginTop:e.spacing(2),gap:e.spacing(2),flexWrap:"wrap",[e.breakpoints.down(560)]:{flexDirection:"column"}})),Ks=({env:e})=>{var p;const n=A("projectId"),a=A("featureId"),{metrics:s}=Mo(n,a),{feature:o}=j(n,a),{value:i}=an(),l=Lo(o==null?void 0:o.environments,s).find(h=>h.environment===e.name),d=o==null?void 0:o.environments.find(h=>h.name===e.name);return t(b,{condition:!new Set(i.hiddenEnvironments).has(e.name),show:t(js,{enabled:e.enabled,children:r(zs,{TransitionProps:{mountOnEnter:!0},"data-testid":`${da}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[r(Vs,{expandIcon:t(ua,{titleAccess:"Toggle"}),children:[r(Ws,{"data-loading":!0,enabled:e.enabled,children:[r(Hs,{children:[t(Us,{enabled:e.enabled}),t("div",{children:t(Ys,{text:e.name,maxWidth:"100",maxLength:15})}),t(b,{condition:!e.enabled,show:t(Ee,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),r(Gs,{children:[t(lt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"outlined",size:"small"}),t(Ls,{strategies:d==null?void 0:d.strategies})]})]}),t(Os,{environmentMetric:l,disabled:!e.enabled})]}),r(qs,{enabled:e.enabled,children:[t(Ns,{featureEnvironment:d,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:h})=>h).filter(h=>h!==e.name)}),t(b,{condition:(((p=d==null?void 0:d.strategies)==null?void 0:p.length)||0)>0,show:r(P,{children:[t(J,{sx:{display:"flex",justifyContent:"center",py:1},children:t(lt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(Is,{environmentMetric:l})]})})]})]})})})},Js=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=j(e,n);if(!a)return null;const{environments:s}=a;return t(P,{children:s==null?void 0:s.map(o=>t(Ks,{env:o},o.name))})},xn=e=>{const{makeRequest:n,createRequest:a,errors:s,loading:o}=pa({propagateErrors:!0}),i=async(p,h)=>{const m=a(`/api/admin/projects/${e}/features/${p}/dependencies`,{method:"POST",body:JSON.stringify(h)});await n(m.caller,m.id)},c=async(p,h)=>{const m=a(`/api/admin/projects/${e}/features/${p}/dependencies/${h}`,{method:"DELETE"});await n(m.caller,m.id)},l=async p=>{const h=a(`/api/admin/projects/${e}/features/${p}/dependencies`,{method:"DELETE"});await n(h.caller,h.id)},d=[a,n,z,e];return{addDependency:f.useCallback(i,d),removeDependency:f.useCallback(c,d),removeDependencies:f.useCallback(l,d),errors:s,loading:o}},Zs=(e,n,a={})=>{const s=de(`/api/admin/projects/${e}/features/${n}/parents`),{data:o,error:i,mutate:c}=Ve(s,Qs,a);return{parentOptions:o,error:i,loading:!i&&!o}},Qs=async e=>await(await fetch(e).then(we("Parent Options"))).json(),Xs=()=>r(he,{severity:"warning",children:["Remember to update your Unleash client! Feature dependencies require new SDK versions. Read more about ",t(er,{}),"."]}),er=()=>t("a",{href:"https://docs.getunleash.io/reference/dependent-features#client-sdk-support",target:"_blank",rel:"noreferrer",children:"Client SDK support for feature dependencies"}),tr=u(on)(({theme:e})=>({marginTop:e.spacing(2),marginBottom:e.spacing(1.5)})),Ce={key:"none (remove dependency)",label:"none (remove dependency)"},nr=({project:e,featureId:n,parent:a,onSelect:s})=>{const{parentOptions:o,loading:i}=Zs(e,n),c=o?[Ce,...o.map(l=>({key:l,label:l}))]:[Ce];return t(tr,{fullWidth:!0,options:c,value:a,onChange:s})},ar=(e,n,a,s)=>{const{trackEvent:o}=xe(),{addChange:i}=ue(),{refetch:c}=ae(e),{setToastData:l,setToastApiError:d}=K(),{refetchFeature:p}=j(e,n),h=ft(e)(),{isChangeRequestConfiguredInAnyEnv:m}=X(e),{addDependency:S,removeDependencies:C}=xn(e),g=async y=>{if(!h){console.error("No change request environment");return}y==="addDependency"&&(await i(e,h,[{action:y,feature:n,payload:{feature:a}}]),o("dependent_features",{props:{eventType:"dependency added"}})),y==="deleteDependency"&&await i(e,h,[{action:y,feature:n,payload:void 0}]),c(),l({text:y==="addDependency"?`${n} will depend on ${a}`:`${n} dependency will be removed`,type:"success",title:"Change added to a draft"})};return async()=>{try{if(m()){const y=a===Ce.key?"deleteDependency":"addDependency";await g(y),o("dependent_features",{props:{eventType:y==="addDependency"?"add dependency added to change request":"delete dependency added to change request"}})}else a===Ce.key?(await C(n),o("dependent_features",{props:{eventType:"dependency removed"}}),l({title:"Dependency removed",type:"success"})):(await S(n,{feature:a}),o("dependent_features",{props:{eventType:"dependency added"}}),l({title:"Dependency added",type:"success"}))}catch(y){d(z(y))}await p(),s()}},or=({project:e,featureId:n,showDependencyDialogue:a,onClose:s})=>{const[o,i]=f.useState(Ce.key),c=ar(e,n,o,s),{isChangeRequestConfiguredInAnyEnv:l}=X(e);return t(ne,{open:a,title:"Add parent feature dependency",onClose:s,onClick:c,primaryButtonText:l()?"Add change to draft":o===Ce.key?"Remove":"Add",secondaryButtonText:"Cancel",children:r(J,{children:[t(Xs,{}),t(J,{sx:{mt:2,mb:4},children:"Your feature will be evaluated only when the selected parent feature is enabled in the same environment."}),t(q,{children:"What feature do you want to depend on?"}),t(b,{condition:a,show:t(nr,{project:e,featureId:n,parent:o,onSelect:i})})]})})},_e=u("div")({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}),Le=u("div")(({theme:e})=>({justifyContent:"center",paddingTop:e.spacing(.75),...ha})),je=u("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),En=u(G)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),sr=u(tn)(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,padding:e.spacing(1,1.5)})),rr=({feature:e,onEdit:n,onDelete:a})=>{const s=`dependency-${e}-actions`,o=`${s}-menu`,[i,c]=f.useState(null),l=!!i,d=h=>{c(h.currentTarget)},p=()=>{c(null)};return r("span",{children:[t(Q,{title:"Dependency actions",arrow:!0,describeChild:!0,children:t(qe,{id:s,"aria-controls":l?o:void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,onClick:d,type:"button",children:t(en,{})})}),t(sr,{id:o,anchorEl:i,open:l,onClose:p,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},disableScrollLock:!0,children:r(ga,{"aria-labelledby":s,children:[t(b,{condition:!0,show:r(re,{onClick:()=>{n(),p()},children:[t(ve,{children:t(Se,{})}),t(le,{children:t(q,{variant:"body2",children:"Edit"})})]})}),t(b,{condition:!0,show:r(re,{onClick:()=>{a(),p()},children:[t(ve,{children:t(fa,{})}),t(le,{children:t(q,{variant:"body2",children:"Delete"})})]})})]})})]})},Dn=({childFeatures:e,project:n})=>t(nn,{tooltip:t(P,{children:e.map(a=>t(En,{to:`/projects/${n}/features/${a}`,children:t("div",{children:a})},`${n}-${a}`))}),children:e.length===1?"1 feature":`${e.length} features`}),ir=(e,n)=>{const{trackEvent:a}=xe(),{addChange:s}=ue(),{refetch:o}=ae(e),{setToastData:i,setToastApiError:c}=K(),{refetchFeature:l}=j(e,n),d=ft(e)(),{isChangeRequestConfiguredInAnyEnv:p}=X(e),{removeDependencies:h}=xn(e),m=async()=>{if(!d){console.error("No change request environment");return}await s(e,d,[{action:"deleteDependency",feature:n,payload:void 0}])};return async()=>{try{p()?(await m(),a("dependent_features",{props:{eventType:"delete dependency added to change request"}}),i({text:`${n} dependency will be removed`,type:"success",title:"Change added to a draft"}),await o()):(await h(n),a("dependent_features",{props:{eventType:"dependency removed"}}),i({title:"Dependency removed",type:"success"}),await l())}catch(C){c(z(C))}}},cr=({feature:e})=>{var p,h;const[n,a]=f.useState(!1),s=!!e.project&&e.dependencies.length===0&&e.children.length===0,o=!!e.project&&e.dependencies.length>0,i=!!e.project&&e.children.length>0,c=ft(e.project)(),l=Kt(e.project),d=ir(e.project,e.name);return r(P,{children:[t(b,{condition:s,show:t(_e,{children:r(Le,{children:[t(je,{children:"Dependency:"}),t(ie,{permission:vt,projectId:e.project,variant:"text",onClick:()=>{a(!0)},children:"Add parent feature"})]})})}),t(b,{condition:o,show:r(_e,{children:[r(Le,{children:[t(je,{children:"Dependency:"}),t(En,{to:`/projects/${e.project}/features/${(p=e.dependencies[0])==null?void 0:p.feature}`,children:(h=e.dependencies[0])==null?void 0:h.feature})]}),t(b,{condition:l(vt,c),show:t(rr,{feature:e.name,onEdit:()=>a(!0),onDelete:d})})]})}),t(b,{condition:i,show:t(_e,{children:r(Le,{children:[t(je,{children:"Children:"}),t(Dn,{childFeatures:e.children,project:e.project})]})})}),t(b,{condition:!!e.project,show:t(or,{project:e.project,featureId:e.name,onClose:()=>a(!1),showDependencyDialogue:n})})]})},lr=(e,n={})=>{const a=de(`/api/admin/projects/${e}/dependencies`),{data:s,error:o}=sn(e,!1,a,dr,n);return{dependenciesExist:s,error:o,loading:!o&&!s}},dr=async e=>await(await fetch(e).then(we("Dependencies exist check"))).json(),ur=e=>{const n=mt("dependentFeatures"),{dependenciesExist:a}=lr(e),{isOss:s}=We();return!!(s()?a&&n:n)},pr=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",justifyItems:"center",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),hr=({feature:e,header:n})=>{var l;const{locationSettings:a}=rn(),{uiConfig:s}=We(),o=ur(e.project),i=!!s.flags.lastSeenByEnvironment,c=(l=e.environments)==null?void 0:l.map(d=>({name:d.name,lastSeenAt:d.lastSeenAt,enabled:d.enabled}));return r(pr,{children:[n,r(_e,{children:[r(Le,{children:[t(je,{children:"Created at:"}),t("span",{children:ma(cn(e.createdAt),a.locale)})]}),i&&t(ya,{featureLastSeen:e.lastSeenAt,environments:c,sx:{p:0}})]}),t(b,{condition:o,show:t(cr,{feature:e})})]})},gr=u(qe,{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}})),fr=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(gr,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(b,{condition:n.has(e.name),show:t(Sa,{}),elseShow:t(ba,{})})}),mr=u("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),yr=u("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),Sr=({environment:e,callback:n,showInfoBox:a,children:s,hiddenEnvironments:o,setHiddenEnvironments:i})=>{const{name:c,enabled:l}=e,d=A("projectId"),p=A("featureId"),{feature:h,refetchFeature:m}=j(d,p),S=r(P,{children:[" ",r("span",{"data-loading":!0,children:[l?"enabled":"disabled"," in"]})," ",t(ht,{text:c,maxWidth:"120",maxLength:15})]}),C=()=>{m(),n&&n()};return r(mr,{children:[r(yr,{children:[t(go,{featureId:h.name,projectId:d,environmentName:e.name,onToggle:C,onError:a,value:l}),s??S]}),t(fr,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:i})]})},br=u("div")(({theme:e})=>({padding:e.spacing(3)})),vr=u("div")(()=>({display:"flex",flexDirection:"column"})),Cr=u("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),wr=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Lt=u("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),Tr=u(yt)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),xr=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:s})=>{const[o,i]=f.useState(!1),[c,l]=f.useState(""),d=e.environments.some(p=>{var h;return p.enabled&&((h=p.variants)==null?void 0:h.length)});return r(br,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(p=>{const h=p.strategies.length===1?"1 strategy":`${p.strategies.length} strategies`,m=p.variants??[],S=m.length>0&&r(P,{children:[t(Lt,{}),t(Q,{title:"View variants",arrow:!0,describeChild:!0,children:t(Tr,{component:G,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:m.length===1?"1 variant":`${m.length} variants`})})]}),C=p.enabled&&m.length===0&&d;return t(Sr,{environment:p,hiddenEnvironments:a,setHiddenEnvironments:s,showInfoBox:()=>{l(p.name),i(!0)},children:r(vr,{children:[t(Cr,{children:p.name}),r(wr,{children:[h,S,t(b,{condition:C,show:r(P,{children:[t(Lt,{}),t(fo,{})]})})]})]})},p.name)}),t(mo,{open:o,onClose:()=>i(!1),projectId:e.project,featureId:e.name,environmentName:c})]})},An=(e,n={})=>{const a=async()=>{const p=de(`api/admin/features/${e}/tags`);return(await fetch(p,{method:"GET"}).then(we("Tags"))).json()},s=`api/admin/features/${e}/tags`,{data:o,error:i}=sn(!!e,{tags:[]},s,a,n),[c,l]=f.useState(!i&&!o),d=()=>{ut(s)};return f.useEffect(()=>{l(!i&&!o)},[o,i]),{tags:(o==null?void 0:o.tags)||[],error:i,loading:c,refetch:d}},Er=u("section")(({theme:e})=>({"& > *":{margin:e.spacing(1,0)}})),ot=e=>e.map(n=>({title:n.value})),jt=(e,n)=>e.map(a=>({value:a.title,type:n})),Rn=({open:e,setOpen:n})=>{const{tagTypes:a}=va(),s=A("featureId"),{createTag:o}=yo(),{updateFeatureTags:i,loading:c}=He(),{tags:l,refetch:d,loading:p}=An(s),{setToastData:h}=K(),m=a&&a.length>0?a[0]:{name:"simple",description:"Simple tag to get you started",icon:""},[S,C]=f.useState(m),g=c||p,[E,y]=f.useState(0),{trackEvent:w}=xe(),[$,M]=f.useState(ot(l.filter(T=>T.type===S.name))),{tags:V,refetch:_}=So(S.name),v=f.useMemo(()=>ot(V),[V]);f.useEffect(()=>{l&&S&&M(ot(l.filter(T=>T.type===S.name)))},[JSON.stringify(l),S]);const R=()=>{n(!1),M([])};function B(T,k){const O=T.filter(L=>L.type===S.name).filter(L=>!k.find(W=>L.value===W.value&&L.type===W.type)),H=k.filter(L=>L.type===S.name).filter(L=>!T.find(W=>L.value===W.value&&L.type===W.type));return y(O.length+H.length),{added:O,removed:H}}const N=T=>T.filter(k=>!k.title.startsWith("Create")),Z=async(T,k)=>{try{await i(s,{addedTags:T,removedTags:k}),await d()}catch(O){const H=z(O);h({type:"error",title:"Failed to add tag",text:H,confetti:!1})}},U=(T,k)=>{let O="We successfully";return T>0&&(O=O.concat(` added ${T} new tag${T>1?"s":""}`)),T>0&&k>0&&(O=O.concat(" and ")),k>0&&(O=O.concat(` removed ${k} tag${k>1?"s":""}`)),O},oe=async T=>{T.preventDefault();const k=jt(N($),S.name),{added:O,removed:H}=B(k,l);E>0&&(await Z(O,H),E>1&&w("suggest_tags",{props:{eventType:"multiple_tags_added"}}),E>0&&h({type:"success",title:`Updated tag${O.length>1?"s":""} to toggle`,text:U(O.length,H.length),confetti:!0})),y(0),M([]),n(!1)},x=(T,k)=>{k!=null&&typeof k!="string"&&(T.preventDefault(),C(k),M([]),y(0))},I=(T,k,O)=>{const H=Ca(k);O==="selectOption"&&k.forEach((W,$e)=>{if(typeof W!="string"&&W.inputValue&&W.inputValue!==""){const Ie={value:W.inputValue,type:S.name};o(Ie).then(()=>{w("suggest_tags",{props:{eventType:"tag_created"}}),_()}),W.title=W.inputValue,W.inputValue="",H[$e]=W}});const L=jt(N(H),S.name);B(L,l),M(H)},F="add-tag-form";return t(ne,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update tags to feature toggle",onClick:oe,disabledPrimaryButton:g||E===0,onClose:R,formId:F,children:r(P,{children:[t(q,{paragraph:!0,sx:{marginBottom:T=>T.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:F,onSubmit:oe,children:r(Er,{children:[t(bo,{options:a,value:S,onChange:x}),t(vo,{options:v,existingTags:l,tagType:S,selectedOptions:$,onChange:I})]})})]})})},Dr=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),Ar=u("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Rr=u(ln)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),kr=u(De)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),Fr=u(Te)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),$r=({feature:e,header:n})=>{const{tags:a,refetch:s}=An(e.name),{deleteTagFromFeature:o}=He(),[i,c]=f.useState(!1),[l,d]=f.useState(!1),[p,h]=f.useState(),{setToastData:m,setToastApiError:S}=K(),{hasAccess:C}=f.useContext(pt),g=C(ye,e.project),E=async()=>{if(p)try{await o(e.name,p.type,p.value),s(),m({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(y){S(z(y))}};return r(Dr,{children:[n,t(Ar,{children:a.map(y=>{const w=`${y.type}:${y.value}`;return t(Rr,{label:w,deleteIcon:t(wa,{titleAccess:"Remove"}),onDelete:g?()=>{d(!0),h(y)}:void 0},w)})}),t(b,{condition:g,show:r(P,{children:[t(b,{condition:a.length>0,show:t(kr,{})}),t(Fr,{"data-loading":!0,variant:"outlined",startIcon:t(Ta,{}),onClick:()=>c(!0),children:"Add new tag"})]})}),t(Rn,{open:i,setOpen:c}),r(ne,{open:l,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{d(!1),h(void 0)},onClick:()=>{d(!1),E(),h(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",r("strong",{children:[p==null?void 0:p.type,":",p==null?void 0:p.value]})]})]})},Ir=u(xa)(({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"}})),st=u("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}})),Pr=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=A("projectId"),s=A("featureId"),{feature:o}=j(a,s);return r(Ir,{children:[t(xr,{header:r(st,{"data-loading":!0,children:["Enabled in environments (",o.environments.filter(({enabled:i})=>i).length,")",t(Ea,{tooltip:"When a feature is switched off in an environment, it will always return false. When switched on, it will return true or false depending on its strategies.",placement:"top"})]}),feature:o,hiddenEnvironments:e,setHiddenEnvironments:n}),t(De,{}),t(hr,{header:t(st,{"data-loading":!0,children:"Feature toggle details"}),feature:o}),t(De,{}),t($r,{header:t(st,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:o})]})},Br=()=>{const{trackEvent:e}=xe(),{value:n,setValue:a}=an(),[s,o]=f.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:s,setHiddenEnvironments:c=>{a(l=>{const d=new Set(l.hiddenEnvironments);return d.has(c)?(d.delete(c),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(d.add(c),e("hidden_environment",{props:{eventType:"environment hidden"}})),o(d),{...n,hiddenEnvironments:d}})}}},Or=u("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),Mr=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),_r=()=>{const e=pe(),n=A("projectId"),a=A("featureId"),s=Zt(n,a),{hiddenEnvironments:o,setHiddenEnvironments:i}=Br(),c=()=>e(s);return dn(a),r(Or,{children:[r("div",{children:[t(Oo,{}),t(Pr,{hiddenEnvironments:o,setHiddenEnvironments:i})]}),t(Mr,{children:t(Js,{})}),r(un,{children:[t(ce,{path:"strategies/create",element:t(ct,{label:"Create feature strategy",onClose:c,open:!0,children:t(Co,{})})}),t(ce,{path:"strategies/edit",element:t(ct,{label:"Edit feature strategy",onClose:c,open:!0,children:t(Da,{})})})]})]})},Lr=u("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"},marginTop:e.spacing(-3.5),marginBottom:e.spacing(2),backgroundColor:e.palette.background.default,paddingTop:e.spacing(2),paddingBottom:e.spacing(2),position:"sticky",top:0,zIndex:2})),jr=u(pn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),zr=u("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontSize:e.fontSizes.mainHeader,fontWeight:e.fontWeight.bold})),Vr=u("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),qr=u(he)(({theme:e})=>({marginBottom:e.spacing(2)})),Nr=u(he)(({theme:e})=>({marginTop:e.spacing(4)})),Wr=u("div")({display:"flex",flexDirection:"column"}),Hr=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),zt=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Ur=u(De)(({theme:e})=>({margin:e.spacing(4,0)})),Yr=u(Aa)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),Gr=u("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),Kr=u(Te)(({theme:e})=>({marginLeft:e.spacing(3)})),Jr=f.memo(Ra),Zr=({environment:e,open:n,setOpen:a,getApiPayload:s,getCrPayload:o,onConfirm:i})=>{const c=A("projectId"),l=A("featureId"),{uiConfig:d}=We(),{context:p}=ka(),{defaultStickiness:h,loading:m}=Fa(c),{isChangeRequestConfigured:S}=X(c),{data:C}=ae(c),{changeRequestInReviewOrApproved:g,alert:E}=Pa(C),y=(e==null?void 0:e.variants)||[],[w,$]=f.useState([]),[M,V]=f.useState();f.useEffect(()=>{m||$(y.length?y.map(D=>({...D,isValid:!0,new:!1,id:Ge()})):[{name:"",weightType:Ct.VARIABLE,weight:0,overrides:[],stickiness:(w==null?void 0:w.length)>0?w[0].stickiness:h,new:!0,isValid:!1,id:Ge()}])},[n,m]);const _=(D,Y)=>{$(ge=>wt(ge.map(Pe=>Pe.id===Y?D:Pe),1e3))},v=()=>{const D=Ge();$(Y=>[...Y,{name:"",weightType:Ct.VARIABLE,weight:0,overrides:[],stickiness:(Y==null?void 0:Y.length)>0?Y[0].stickiness:h,new:!0,isValid:!1,id:D}]),V(D)};f.useEffect(()=>{if(M){const D=document.getElementById(`variant-name-input-${M}`);D==null||D.scrollIntoView({behavior:"smooth",block:"center"}),D==null||D.focus({preventScroll:!0}),V(void 0)}},[M]);const R=w.map(({new:D,isValid:Y,id:ge,...Pe})=>Pe),B=s(y,R),N=o(R),Z=async D=>{D.preventDefault(),i(R)},U=()=>F?`curl --location --request POST '${d.unleashUrl}/api/admin/projects/${c}/environments/${e==null?void 0:e.name}/change-requests' \\
1
+ import{c as Gt,j as t,s as u,aG as A,aH as j,aI as Fn,d as r,aJ as $n,C as b,aK as te,aL as ye,aM as G,aN as Se,aO as In,aP as Ve,r as f,aQ as de,aR as we,aS as ut,aT as Pn,aU as Bn,aV as On,aW as Mn,f as K,aX as ue,aY as ae,h as z,T as q,aZ as Re,a_ as ke,a$ as Kt,b0 as X,b1 as be,w as Q,z as qe,b2 as _n,b3 as Ln,b4 as Fe,M as re,b5 as ve,b6 as Jt,b7 as le,b8 as ne,aA as pe,L as he,b9 as Zt,ba as jn,bb as zn,bc as Vn,bd as qn,be as it,bf as Nn,bg as Wn,J as P,B as J,bh as Hn,bi as Un,bj as Yn,bk as Gn,bl as Kn,bm as Jn,bn as Zn,bo as Qn,bp as Xn,bq as ea,N as ta,b as Qt,ae as Ne,H as Ee,br as pt,i as Te,W as ht,bs as Xt,al as xe,$ as na,bt as gt,bu as me,bv as ie,bw as en,a3 as tn,bx as aa,by as se,bz as oa,bA as sa,Z as ra,bB as nn,bC as ia,bD as ca,bE as la,bF as an,bG as da,bH as ua,u as pa,bI as on,bJ as ft,bK as ha,bL as ga,bM as fa,bN as vt,bO as sn,t as mt,az as We,bP as rn,bQ as ma,bR as cn,bS as ya,bT as Sa,bU as ba,bV as yt,bW as va,bX as He,bY as Ca,V as ln,D as De,bZ as wa,b_ as Ta,b$ as xa,c0 as Ea,c1 as dn,c2 as un,c3 as ce,c4 as ct,c5 as Da,c6 as pn,c7 as Aa,c8 as Ra,g as ka,c9 as Fa,ca as Ge,cb as Ct,ax as $a,aC as Ia,cc as fe,cd as wt,ce as Pa,cf as Ba,m as Oa,av as St,aw as Ma,aq as Tt,cg as _a,ch as La,ci as ja,cj as xt,ad as hn,ck as za,a5 as Ke,ah as Va,a7 as qa,a8 as Na,a9 as Wa,aa as Ha,ab as Ua,ac as Ya,cl as Ga,cm as Ka,cn as Et,co as Ja,cp as gn,cq as Za,v as Qa,cr as Dt,cs as Xa,ct as eo,cu as to,cv as no,cw as ao,cx as oo,an as so,cy as ro,cz as io,cA as co,cB as lo,cC as uo,cD as po}from"./index-f848dd08.js";import{C as fn,f as mn,E as ho,F as go,V as fo,a as mo,u as yo,b as So,T as bo,c as vo,d as Co,W as wo,e as To,g as xo}from"./FeatureArchiveDialog-37e2bf5f.js";import{S as Eo}from"./StrategyItemContainer-bb9f1a81.js";const Do=Gt(t("path",{d:"m20.54 5.23-1.39-1.68C18.88 3.21 18.47 3 18 3H6c-.47 0-.88.21-1.16.55L3.46 5.23C3.17 5.57 3 6.02 3 6.5V19c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V6.5c0-.48-.17-.93-.46-1.27zM12 17.5 6.5 12H10v-2h4v2h3.5L12 17.5zM5.12 5l.81-1h12l.94 1H5.12z"}),"Archive"),Ao=Gt(t("path",{d:"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z"}),"Assessment"),Ro=u("div")(({theme:e})=>({borderRadius:e.spacing(1.5),backgroundColor:e.palette.background.paper,padding:e.spacing(4)})),ko=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=j(e,n);return a.name?t(Ro,{children:t(Fn,{title:"Event log",feature:n,displayInline:!0})}):null},Fo=u("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"}})),$o=u("div")({padding:"1.5rem 1.5rem 0 1.5rem"}),Io=u("div")({display:"flex",alignItems:"center"}),Po=u("h2")(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:"normal",margin:0})),Bo=u("div")(({theme:e})=>({margin:e.spacing(2,0),display:"flex",flexDirection:"column"})),At=u("span")(({theme:e})=>({margin:e.spacing(1,0),fontSize:e.fontSizes.bodySize})),Rt=u("div")(({theme:e})=>({display:"flex",alignItems:"center",color:e.palette.primary.contrastText})),Oo=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=j(e,n),{project:s,description:o,type:i}=a,c=In(i);return t(Fo,{children:r($o,{children:[r(Io,{"data-loading":!0,children:[t(c,{sx:l=>({marginRight:l.spacing(2),height:"40px",width:"40px",fill:l.palette.primary.contrastText})})," ",r(Po,{children:[$n(i||"")," toggle"]})]}),r(Bo,{children:[r(At,{"data-loading":!0,children:["Project: ",s]}),t(b,{condition:!!o,show:r(At,{"data-loading":!0,children:[t("div",{children:"Description:"}),r(Rt,{children:[t("p",{children:o}),t(te,{projectId:e,permission:ye,component:G,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(Se,{sx:l=>({color:l.palette.primary.contrastText})})})]})]}),elseShow:t("span",{"data-loading":!0,children:r(Rt,{children:["No description."," ",t(te,{projectId:e,permission:ye,component:G,to:`/projects/${e}/features/${n}/settings`,tooltipProps:{title:"Edit description"},children:t(Se,{sx:l=>({color:l.palette.primary.contrastText})})})]})})})]})]})})},kt={lastHourUsage:[],seenApplications:[]},Mo=(e,n,a={})=>{const s=async()=>{const h=de(`api/admin/client-metrics/features/${n}`),m=await fetch(h,{method:"GET"}).then(we("feature metrics"));return m.ok?m.json():kt},o=`${e}_${n}_metrics`,{data:i,error:c}=Ve(o,s,{...a}),[l,d]=f.useState(!c&&!i),p=()=>{ut(o)};return f.useEffect(()=>{d(!c&&!i)},[i,c]),{metrics:i||kt,error:c,loading:l,refetch:p,FEATURE_METRICS_CACHE_KEY:o}},_o=e=>({yes:0,no:0,environment:e,timestamp:""}),Lo=(e,n)=>e.map(a=>n.lastHourUsage.find(o=>o.environment===a.name)||_o(a.name)),jo=e=>(n,a,s)=>(s.revalidateOnFocus=!1,s.revalidateIfStale=!1,s.revalidateOnReconnect=!1,e(n,a,s)),zo=Pn(Ve,jo),yn=(e,n)=>{const{refetchFeature:a}=j(e,n),s=Bn(e,n),{data:o,error:i,mutate:c}=zo(["useFeatureImmutable",s],()=>On(s)),l=f.useCallback(async()=>{await c(),await a()},[c,a]);return{feature:(o==null?void 0:o.body)||Mn,refetchFeature:l,loading:!i&&!o,status:o==null?void 0:o.status,error:i}},Sn=(e,n,a)=>{const{setToastData:s,setToastApiError:o}=K(),{addChange:i}=ue(),{refetch:c}=ae(e),[l,d]=f.useState({isOpen:!1}),p=f.useCallback((g,E,y)=>{d({featureName:n,environment:g,fromEnvironment:y,strategy:E,isOpen:!0})},[]),h=f.useCallback((g,E,y)=>{d({featureName:n,environment:g,fromEnvironment:y,strategies:E,isOpen:!0})},[]),m=f.useCallback(()=>{d({isOpen:!1})},[]),S=f.useCallback(async()=>{try{await i(e,l.environment,{feature:l.featureName,action:a,payload:l.strategy}),c(),d({isOpen:!1}),s({type:"success",title:"Changes added to the draft!"})}catch(g){o(z(g)),d({isOpen:!1})}},[i]),C=f.useCallback(async()=>{try{await Promise.all(l.strategies.map(g=>i(e,l.environment,{feature:l.featureName,action:a,payload:g}))),c(),d({isOpen:!1}),s({type:"success",title:"Changes added to the draft!"})}catch(g){o(z(g)),d({isOpen:!1})}},[i]);return{onChangeRequestAddStrategy:p,onChangeRequestAddStrategies:h,onChangeRequestAddStrategyClose:m,onChangeRequestAddStrategyConfirm:S,onChangeRequestAddStrategiesConfirm:C,changeRequestDialogDetails:l}},Vo=({payload:e,fromEnvironment:n,environment:a})=>r(q,{children:[r("strong",{children:["Copy ",Re((e==null?void 0:e.name)||"")," strategy"," "]})," ","from ",n," to ",a]}),qo=({environmentId:e,environments:n,strategy:a})=>{const s=A("projectId"),o=A("featureId"),[i,c]=f.useState(null),l=!!i,{addStrategyToFeature:d}=ke(),{setToastData:p,setToastApiError:h}=K(),{refetchFeature:m}=j(s,o),{refetchFeature:S}=yn(s,o),C=()=>{c(null)},g=Kt(s),{isChangeRequestConfigured:E}=X(s),{changeRequestDialogDetails:y,onChangeRequestAddStrategyClose:w,onChangeRequestAddStrategy:$,onChangeRequestAddStrategyConfirm:M}=Sn(s,o,"addStrategy"),V=async v=>{const{id:R,...B}={...a,targetEnvironment:v};if(E(v)){await $(v,{id:R,...B},e);return}try{await d(s,o,v,a),m(),S(),p({title:"Strategy created",text:`Successfully copied a strategy to ${v}`,type:"success"})}catch(N){h(z(N))}C()},_=n.some(v=>g(be,v));return r("div",{children:[t(fn,{isOpen:y.isOpen,onClose:w,environment:y==null?void 0:y.environment,onConfirm:M,messageComponent:t(Vo,{fromEnvironment:y.fromEnvironment,payload:y.strategy})}),t(Q,{title:`Copy to another environment${_?"":" (Access denied)"}`,children:t("div",{children:t(qe,{size:"large",id:`copy-strategy-icon-menu-${a.id}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,onClick:v=>{c(v.currentTarget)},"data-testid":_n,disabled:!_,children:t(Ln,{})})})}),t(Fe,{id:"basic-menu",anchorEl:i,open:l,onClose:C,MenuListProps:{"aria-labelledby":`copy-strategy-icon-menu-${a.id}`},children:n.map(v=>{const R=g(be,v);return t(Q,{title:R?"":"You don't have access to add a strategy to this environment",children:t("div",{children:r(re,{onClick:()=>V(v),disabled:!R,children:[t(b,{condition:!R,show:t(ve,{children:t(Jt,{fontSize:"small"})})}),r(le,{children:["Copy to ",v]})]})})},v)})})]})},bn=()=>t(he,{severity:"error",children:"Removing the strategy will change which users receive access to the feature."}),No=({onRemove:e,onClose:n,isOpen:a})=>t(ne,{title:"Are you sure you want to delete this strategy?",open:a,primaryButtonText:"Remove strategy",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:t(bn,{})}),Wo=u("div")(({theme:e})=>({marginTop:e.spacing(3),marginBottom:e.spacing(1)})),Ho=({onRemove:e,onClose:n,isOpen:a})=>r(ne,{title:"Suggest changes",open:a,primaryButtonText:"Add suggestion to draft",secondaryButtonText:"Cancel",onClick:e,onClose:n,children:[t(bn,{}),t(Wo,{children:t(q,{variant:"body2",color:"text.secondary",children:"Your suggestion:"})}),t(q,{fontWeight:"bold",children:"Remove strategy"})]}),Uo=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{deleteStrategyFromFeature:o}=ke(),{setToastData:i,setToastApiError:c}=K(),l=pe(),{refetchFeature:d}=j(e,n);return async h=>{try{h.preventDefault(),await o(e,n,a,s),i({title:"Strategy deleted",type:"success"}),d(),l(Zt(e,n))}catch(m){c(z(m))}}},Yo=({projectId:e,featureId:n,environmentId:a,strategyId:s})=>{const{addChange:o}=ue(),{refetch:i}=ae(e),{setToastData:c,setToastApiError:l}=K();return async p=>{try{p.preventDefault(),await o(e,a,{action:"deleteStrategy",feature:n,payload:{id:s}}),c({title:"Changes added to the draft!",type:"success"}),await i()}catch(h){l(z(h))}}},Go=({projectId:e,featureId:n,environmentId:a,strategyId:s,text:o,isOpen:i,onClose:c})=>{const{isChangeRequestConfigured:l}=X(e),d=Uo({featureId:n,projectId:e,strategyId:s,environmentId:a}),p=Yo({featureId:n,projectId:e,strategyId:s,environmentId:a});return l(a)?t(Ho,{isOpen:i,onClose:()=>c(),onRemove:async h=>{await p(h),c()}}):t(No,{isOpen:i,onClose:()=>c(),onRemove:d})},Ko=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{refetchFeature:o}=j(e,a),{setStrategyDisabledState:i}=ke(),{setToastData:c,setToastApiError:l}=K(),d=p=>async()=>{try{await i(e,a,n,s.id,!p),c({title:`Strategy ${p?"enabled":"disabled"}`,type:"success"}),o()}catch(h){l(z(h))}};return{onDisable:d(!1),onEnable:d(!0)}},Jo=({projectId:e,environmentId:n,featureId:a,strategy:s})=>{const{addChange:o}=ue(),{refetch:i}=ae(e),{setToastData:c,setToastApiError:l}=K(),d=p=>async()=>{try{await o(e,n,{action:"updateStrategy",feature:a,payload:{...s,disabled:!p}}),c({title:"Changes added to the draft!",type:"success"}),await i()}catch(h){l(z(h))}};return{onSuggestDisable:d(!1),onSuggestEnable:d(!0)}},Zo=({isOpen:e,onClose:n,...a})=>{var C;const{projectId:s,environmentId:o}=a,{isChangeRequestConfigured:i}=X(s),c=i(o),{onSuggestEnable:l,onSuggestDisable:d}=Jo({...a}),{onEnable:p,onDisable:h}=Ko({...a}),m=!!((C=a.strategy)!=null&&C.disabled);return t(ne,{title:c?`Add ${m?"enable":"disable"} strategy to change request?`:`Are you sure you want to ${m?"enable":"disable"} this strategy?`,open:e,primaryButtonText:c?"Add to draft":`${m?"Enable":"Disable"} strategy`,secondaryButtonText:"Cancel",onClick:g=>{g.preventDefault(),c?m?l():d():m?p():h(),n()},onClose:()=>n(),children:t(b,{condition:c,show:t(jn,{environment:o}),elseShow:r(he,{severity:"error",children:[m?"Enabling":"Disabling"," the strategy will change which users receive access to the feature."]})})})};var bt={},Qo=Vn;Object.defineProperty(bt,"__esModule",{value:!0});var vn=bt.default=void 0,Xo=Qo(zn()),es=qn,ts=(0,Xo.default)((0,es.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");vn=bt.default=ts;const ns=({projectId:e,strategy:n,featureId:a,environmentId:s})=>{const[o,i]=f.useState(null),[c,l]=f.useState(!1),[d,p]=f.useState(!1),h=!!o,m=E=>{i(E.currentTarget)},S=E=>{i(null),E.stopPropagation()},C=it(Nn,e,s),g=it(Wn,e,s);return r(P,{children:[t(J,{sx:{display:"flex",alignItems:"center",textAlign:"center"},children:t(Q,{title:"More actions",children:t(qe,{onClick:m,size:"small","aria-controls":h?"actions-menu":void 0,"aria-haspopup":"true","aria-expanded":h?"true":void 0,"data-testid":Hn,children:t(Un,{sx:{width:32,height:32}})})})}),r(Fe,{anchorEl:o,id:"actions-menu",open:h,onClose:S,onClick:S,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},"data-testid":Yn,children:[t(Q,{title:n.disabled?"Enable strategy":"Disable strategy",arrow:!0,placement:"left",children:r(re,{disabled:!C,onClick:()=>l(!0),children:[t(ve,{children:n.disabled?t(Gn,{}):t(Kn,{})}),t(le,{children:n.disabled?"Enable":"Disable"})]})}),t(Q,{title:"Remove strategy",arrow:!0,placement:"left",children:r(re,{disabled:!g,onClick:()=>p(!0),"data-testid":Jn,children:[t(ve,{children:t(vn,{})}),t(le,{children:"Remove"})]})})]}),t(Zo,{isOpen:c,onClose:()=>l(!1),projectId:e,featureId:a,environmentId:s,strategy:n}),t(Go,{isOpen:d,onClose:()=>p(!1),projectId:e,featureId:a,environmentId:s,strategyId:n.id})]})},as=({environmentId:e,strategy:n,onDragStart:a,onDragEnd:s,otherEnvironments:o,orderNumber:i,headerChildren:c})=>{const l=A("projectId"),d=A("featureId"),p=Zn(l,d,e,n.id);return r(Eo,{strategy:n,onDragStart:a,onDragEnd:s,orderNumber:i,actions:r(P,{children:[c,t(b,{condition:!!(o&&(o==null?void 0:o.length)>0),show:()=>t(qo,{environmentId:e,environments:o,strategy:n})}),t(te,{permission:Qn,environmentId:e,projectId:l,component:G,to:p,tooltipProps:{title:"Edit strategy"},"data-testid":`STRATEGY_EDIT-${n.name}`,children:t(Se,{})}),t(ns,{projectId:l,featureId:d,environmentId:e,strategy:n})]}),children:[t(Xn,{strategy:n}),n.variants?t(ea,{variants:n.variants}):null]})},os=(e,n,a,s)=>{const{data:o}=ae(e),i=o==null?void 0:o.find(d=>d.environment===a),c=i==null?void 0:i.features.find(d=>d.name===n);return c==null?void 0:c.changes.find(d=>d.action==="updateStrategy"||d.action==="deleteStrategy"?d.payload.id===s:!1)},ss=({strategy:e,index:n,environmentName:a,otherEnvironments:s,isDragging:o,onDragStartRef:i,onDragOver:c,onDragEnd:l})=>{const d=A("projectId"),p=A("featureId"),h=f.useRef(null),m=os(d,p,a,e.id);return r(J,{ref:h,onDragOver:c(h,n),sx:{opacity:o?"0.5":"1"},children:[t(b,{condition:n>0,show:t(ta,{text:"OR"})}),t(as,{strategy:e,environmentId:a,otherEnvironments:s,onDragStart:i(h,n),onDragEnd:l,orderNumber:n+1,headerChildren:t(rs,{change:m})})]},e.id)},rs=({change:e})=>{const n=Qt();return Ne(n.breakpoints.down("sm"))?null:r(J,{sx:{mr:1.5},children:[t(b,{condition:(e==null?void 0:e.action)==="updateStrategy",show:t(Ee,{color:"warning",children:"Modified in draft"})}),t(b,{condition:(e==null?void 0:e.action)==="deleteStrategy",show:t(Ee,{color:"error",children:"Deleted in draft"})})]})},is=({environmentId:e,environments:n,onClick:a})=>{const s=A("projectId"),[o,i]=f.useState(null),c=!!o,{hasAccess:l}=f.useContext(pt),d=n.some(p=>l(be,s,p));return r("div",{children:[t(Q,{title:d?"":"(Access denied)",children:t("div",{children:t(Te,{id:`copy-all-strategies-${e}`,"aria-controls":c?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":c?"true":void 0,onClick:p=>{i(p.currentTarget)},disabled:!d,variant:"outlined",children:"Copy from another environment"})})}),t(Fe,{id:"basic-menu",anchorEl:o,open:c,onClose:()=>{i(null)},MenuListProps:{"aria-labelledby":`copy-all-strategies-${e}`},children:n.map(p=>{const h=l(be,s,p);return t(Q,{title:h?"":"You don't have access to add a strategy to this environment",children:t("div",{children:r(re,{onClick:()=>a(p),disabled:!h,children:[t(b,{condition:!h,show:t(ve,{children:t(Jt,{fontSize:"small"})})}),r(le,{children:["Copy from ",p]})]})})},p)})})]})},cs=u("div")(({theme:e})=>({"&>*:nth-child(n)":{margin:e.spacing(1,0)}})),ls=({payload:e,fromEnvironment:n,environment:a})=>r(cs,{children:[t(q,{children:t("strong",{children:"Copy: "})}),e==null?void 0:e.map(s=>r(q,{children:[r("strong",{children:[Re((s==null?void 0:s.name)||"")," strategy"," "]})," "]})),r(q,{children:["from ",n," to ",a]})]}),ds=u("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}})),us=u("div")(({theme:e})=>({fontSize:e.fontSizes.smallBody})),ps=u(ht)(({theme:e})=>({fontWeight:e.fontWeight.bold})),hs=u(G)(({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}})),Je=({projectId:e,featureId:n,environmentId:a,strategy:s,defaultStrategy:o})=>{const i=Xt(s.name),c=Re(s.name),{trackEvent:l}=xe(),d=mn(e,n,a,s.name,o);return r(hs,{to:d,onClick:()=>{l("strategy-add",{props:{buttonTitle:s.displayName||c}})},children:[t(ds,{children:t(i,{})}),r("div",{children:[t(ps,{text:s.displayName||c,maxWidth:"200",maxLength:25}),t(us,{children:s.description})]})]})},Ze=u(q)(({theme:e})=>({fontSize:e.fontSizes.smallBody,padding:e.spacing(1,2)})),gs=({projectId:e,featureId:n,environmentId:a})=>{const{strategies:s}=na(),o=s.filter(l=>!l.deprecated&&!l.editable),i=s.filter(l=>!l.deprecated&&l.editable),c={name:"flexibleRollout",displayName:"Default strategy",description:"This is the default strategy defined for this environment in the project"};return r(gt,{dense:!0,children:[r(P,{children:[r(Ze,{color:"textSecondary",children:[a," environment default strategy"]}),t(me,{children:t(Je,{projectId:e,featureId:n,environmentId:a,strategy:c,defaultStrategy:!0})},c.name)]}),t(Ze,{color:"textSecondary",children:"Predefined strategy types"}),o.map(l=>t(me,{children:t(Je,{projectId:e,featureId:n,environmentId:a,strategy:l})},l.name)),t(b,{condition:i.length>0,show:r(P,{children:[t(Ze,{color:"textSecondary",children:"Custom strategies"}),i.map(l=>t(me,{children:t(Je,{projectId:e,featureId:n,environmentId:a,strategy:l})},l.name))]})})]})},fs=u("div")({flexShrink:0}),ms=u(ie)(({theme:e})=>({minWidth:0,width:e.spacing(4.5),alignItems:"center",justifyContent:"center",align:"center",flexDirection:"column",marginLeft:e.spacing(1)})),lt=({label:e,projectId:n,featureId:a,environmentId:s,variant:o,size:i,matchWidth:c})=>{const[l,d]=f.useState(),p=pe(),{trackEvent:h}=xe(),m=!!l,S=m?"FeatureStrategyMenuPopover":void 0,C=()=>{d(void 0)},g=w=>{h("strategy-add",{props:{buttonTitle:e}}),p(y)},E=w=>{d(w.currentTarget)},y=mn(n,a,s,"flexibleRollout",!0);return r(fs,{onClick:w=>w.stopPropagation(),children:[t(ie,{permission:be,projectId:n,environmentId:s,onClick:g,"aria-labelledby":S,variant:o,size:i,sx:{minWidth:c?"282px":"auto"},children:e}),t(ms,{permission:be,projectId:n,environmentId:s,onClick:E,"aria-labelledby":S,variant:"outlined",size:i,hideLockIcon:!0,tooltipProps:{title:"More strategies"},children:t(en,{sx:w=>({margin:w.spacing(.25,0)})})}),t(tn,{id:S,open:m,anchorEl:l,onClose:C,onClick:C,PaperProps:{sx:w=>({paddingBottom:w.spacing(1)})},children:t(gs,{projectId:n,featureId:a,environmentId:s})})]})},ys=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",paddingTop:e.spacing(2)})),Ss=u("div")(({theme:e})=>({fontSize:e.fontSizes.bodySize,textAlign:"center",color:e.palette.text.primary,marginBottom:e.spacing(1)})),bs=u("p")(({theme:e})=>({color:e.palette.text.secondary,fontSize:e.fontSizes.smallBody,textAlign:"center",marginBottom:e.spacing(3),a:{color:e.palette.links}})),vs=({projectId:e,featureId:n,environmentId:a})=>{const{addStrategyToFeature:s}=ke(),{setToastData:o,setToastApiError:i}=K(),{refetchFeature:c}=j(e,n),{refetchFeature:l}=yn(e,n),{feature:d}=j(e,n),p=d==null?void 0:d.environments.filter($=>$.name!==a&&$.strategies&&$.strategies.length>0),{isChangeRequestConfigured:h}=X(e),{changeRequestDialogDetails:m,onChangeRequestAddStrategies:S,onChangeRequestAddStrategiesConfirm:C,onChangeRequestAddStrategyClose:g}=Sn(e,n,"addStrategy"),E=($=!1)=>{c(),l(),o({title:$?"Strategies created":"Strategy created",text:$?"Successfully copied from another environment":"Successfully created strategy",type:"success"})},y=async $=>{var V;const M=((V=p==null?void 0:p.find(_=>_.name===$))==null?void 0:V.strategies)||[];if(h(a)){await S(a,M,$);return}try{await Promise.all(M.map(_=>{const{id:v,...R}={..._,environment:a};return s(e,n,a,R)})),E(!0)}catch(_){i(z(_))}},w=p&&p.length>0;return r(P,{children:[t(fn,{isOpen:m.isOpen,onClose:g,environment:m==null?void 0:m.environment,onConfirm:C,messageComponent:t(ls,{fromEnvironment:m.fromEnvironment,payload:m.strategies})}),r(ys,{children:[t(Ss,{children:"You have not defined any strategies yet."}),r(bs,{children:["Strategies added in this environment will only be executed if the SDK is using an"," ",t(G,{to:"/admin/api",children:"API key configured"})," for this environment."]}),r(J,{sx:{w:"100%",display:"flex",flexWrap:"wrap",gap:2,alignItems:"center",justifyContent:"center"},children:[t(lt,{label:"Add your first strategy",projectId:e,featureId:n,environmentId:a,matchWidth:w}),t(b,{condition:w,show:t(is,{environmentId:a,environments:p.map($=>$.name),onClick:y})})]})]})]})},Cs=u("div")(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),ws=u("div")(({theme:e})=>({[e.breakpoints.down(400)]:{padding:e.spacing(1)}})),Ts=({featureEnvironment:e,isDisabled:n,otherEnvironments:a})=>{const s=A("projectId"),o=A("featureId"),{setStrategiesSortOrder:i}=ke(),{addChange:c}=ue(),{isChangeRequestConfigured:l}=X(s),{refetch:d}=ae(s),{setToastData:p,setToastApiError:h}=K(),{refetchFeature:m}=j(s,o),[S,C]=f.useState((e==null?void 0:e.strategies)||[]),[g,E]=f.useState(null);if(f.useEffect(()=>{C((e==null?void 0:e.strategies)||[])},[e==null?void 0:e.strategies]),!e)return null;const y=async v=>{try{await i(s,o,e.name,v),m(),p({title:"Order of strategies updated",type:"success"})}catch(R){h(z(R))}},w=async v=>{await c(s,e.name,{action:"reorderStrategy",feature:o,payload:v}),p({title:"Strategy execution order added to draft",type:"success",confetti:!0}),d()},$=async v=>{try{l(e.name)?await w(v):await y(v)}catch(R){h(z(R))}},M=(v,R)=>B=>{var N;E({id:S[R].id,index:R,height:((N=v.current)==null?void 0:N.offsetHeight)||0}),v!=null&&v.current&&(B.dataTransfer.effectAllowed="move",B.dataTransfer.setData("text/html",v.current.outerHTML),B.dataTransfer.setDragImage(v.current,20,20))},V=v=>(R,B)=>N=>{if(g===null||R.current===null||g.index===B||v===g.id)return;const{top:Z,bottom:U}=R.current.getBoundingClientRect(),oe=N.clientY-Z<g.height,x=U-N.clientY<g.height,I=g.index>B;if(oe&&I||x&&!I){const F=[...S],T=F.splice(g.index,1)[0];F.splice(B,0,T),C(F),E({...g,index:B})}},_=()=>{E(null),$(S.map((v,R)=>({id:v.id,sortOrder:R})))};return t(Cs,{children:r(ws,{children:[t(b,{condition:S.length>0&&n,show:()=>t(he,{severity:"warning",sx:{mb:2},children:"This environment is disabled, which means that none of your strategies are executing."})}),t(b,{condition:S.length>0,show:t(P,{children:S.map((v,R)=>t(ss,{strategy:v,index:R,environmentName:e.name,otherEnvironments:a,isDragging:(g==null?void 0:g.id)===v.id,onDragStartRef:M,onDragOver:V(v.id),onDragEnd:_},v.id))}),elseShow:t(vs,{projectId:s,featureId:o,environmentId:e.name})})]})})},Cn=(e,n)=>e===0?0:Math.round(n/e*100);var Ue={},Ye={};Object.defineProperty(Ye,"__esModule",{value:!0});Ye.defaultOptions=void 0;Ye.defaultOptions={lowercase:!1,precision:1,space:!1,units:["","K","M","B","T","P","E"]};var ee={};Object.defineProperty(ee,"__esModule",{value:!0});ee.getLocales=ee.getFractionDigits=ee.roundTo=ee.parseValue=void 0;function xs(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}ee.parseValue=xs;function Es(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))}ee.roundTo=Es;function Ds(e){var n;if(Number.isInteger(e))return 0;const a=e.toString().split(".")[1];return(n=a==null?void 0:a.length)!==null&&n!==void 0?n:0}ee.getFractionDigits=Ds;function As(){var e;return typeof navigator>"u"?[]:Array.from((e=navigator.languages)!==null&&e!==void 0?e:[])}ee.getLocales=As;Object.defineProperty(Ue,"__esModule",{value:!0});Ue.millify=void 0;const Ft=Ye,Be=ee,$t=1e3;function*It(e){let n=$t;for(;;){const a=e/n;if(a<1)return;yield a,n*=$t}}function wn(e,n){var a,s;const o=n?{...Ft.defaultOptions,...n}:Ft.defaultOptions;if(!Array.isArray(o.units)||!o.units.length)throw new Error("Option `units` must be a non-empty array");let i;try{i=Be.parseValue(e)}catch(g){return g instanceof Error&&console.warn(`WARN: ${g.message} (millify)`),String(e)}const c=i<0?"-":"";i=Math.abs(i);let l=0;for(const g of It(i))i=g,l+=1;if(l>=o.units.length)return e.toString();let p=Be.roundTo(i,o.precision);for(const g of It(p))p=g,l+=1;const h=(a=o.units[l])!==null&&a!==void 0?a:"",m=o.lowercase?h.toLowerCase():h,S=o.space?" ":"",C=p.toLocaleString((s=o.locales)!==null&&s!==void 0?s:Be.getLocales(),{minimumFractionDigits:Be.getFractionDigits(p)});return`${c}${C}${S}${m}`}Ue.millify=wn;var Rs=Ue.default=wn;const ze=({value:e,threshold:n=1e6,precision:a=2})=>{let s,o=!1;e<n?s=e.toLocaleString():(s=Rs(e,{precision:a}),o=!0);const i=t("span",{"data-testid":aa,children:s});return t(b,{condition:o,show:t(Q,{title:e.toLocaleString(),arrow:!0,children:i}),elseShow:i})},Qe=u("article")(({theme:e})=>({padding:e.spacing(2),background:"transparent",borderRadius:e.spacing(2),textAlign:"center",[e.breakpoints.up("md")]:{padding:e.spacing(4)}})),Xe=u("h3")(({theme:e})=>({margin:0,fontSize:e.fontSizes.bodySize,fontWeight:e.fontWeight.thin})),et=u("p")(({theme:e})=>({fontSize:"2.25rem",fontWeight:e.fontWeight.bold,color:e.palette.primary.main})),tt=u("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})),Tn=({totalYes:e,totalNo:n,hoursBack:a,statsSectionId:s,tableSectionId:o})=>{const i=a===1?"in the last hour":`in the last ${a} hours`;return r(se,{container:!0,spacing:2,id:s,"aria-describedby":o,"aria-label":"Feature metrics summary",component:"section",children:[t(se,{item:!0,xs:12,sm:4,children:r(Qe,{children:[t(Xe,{children:"Exposure"}),t(et,{children:t(ze,{value:e})}),r(tt,{children:["Total exposure of the feature in the environment"," ",i,"."]})]})}),t(se,{item:!0,xs:12,sm:4,children:r(Qe,{children:[t(Xe,{children:"Exposure %"}),r(et,{children:[Cn(e+n,e),"%"]}),r(tt,{children:["% total exposure of the feature in the environment"," ",i,"."]})]})}),t(se,{item:!0,xs:12,sm:4,children:r(Qe,{children:[t(Xe,{children:"Requests"}),t(et,{children:t(ze,{value:e+n})}),r(tt,{children:["Total requests for the feature in the environment"," ",i,"."]})]})})]})},ks=u("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}})),Fs=u("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})),$s=({children:e})=>t(ks,{children:t(Fs,{children:e})}),Is=({environmentMetric:e})=>e?r(P,{children:[t($s,{children:"Feature toggle exposure"}),t("div",{children:t(Tn,{totalYes:e.yes,totalNo:e.no,hoursBack:1})})]}):null,Pt=u("div")({marginLeft:"auto",display:"flex",alignItems:"center"}),Bt=u("div")(({theme:e})=>({marginRight:e.spacing(1),display:"flex",flexDirection:"column"})),Ot=u("p")(({theme:e})=>({color:e.palette.primary.main,textAlign:"right",fontSize:e.fontSizes.bodySize})),Mt=u("p")(({theme:e})=>({maxWidth:"270px",marginTop:e.spacing(.5),fontSize:e.fontSizes.smallBody,textAlign:"right",[e.breakpoints.down(700)]:{display:"none"}})),Ps=u(oa)(({theme:e})=>({fill:e.palette.background.elevation2,height:"75px",width:"75px",[e.breakpoints.down(500)]:{display:"none"}})),Bs=u("div")(({theme:e})=>({margin:e.spacing(0,2),[e.breakpoints.down(500)]:{display:"none"}})),Os=({environmentMetric:e,disabled:n=!1})=>{const a=sa();if(!e)return null;const s=e.yes+e.no,o=Cn(s,e==null?void 0:e.yes);return!e||e.yes===0&&e.no===0?r(Pt,{children:[r(Bt,{children:[r(Ot,{style:{color:n?a.palette.text.secondary:void 0},"data-loading":!0,children:[o,"%"]}),r(Mt,{style:{color:n?a.palette.text.secondary:a.palette.text.primary},"data-loading":!0,children:["The feature has been requested ",t("b",{children:"0 times"})," and exposed",t("b",{children:" 0 times"})," in the last hour"]})]}),t(Ps,{style:{transform:"scale(1.1)"},"data-loading":!0})]}):r(Pt,{children:[r(Bt,{children:[r(Ot,{children:[o,"%"]}),r(Mt,{children:["The feature has been requested"," ",r("b",{children:[t(ze,{value:s})," times"]})," ","and exposed"," ",r("b",{children:[t(ze,{value:e.yes})," ","times"]})," ","in the last hour"]})]}),t(Bs,{"data-loading":!0,children:t(ra,{percentage:o,size:"3rem"})})]})},nt=({strategy:e})=>{const n=Xt(e.name);return t(Q,{title:Re(e.name)+(e.title?` - ${e.title}`:""),arrow:!0,children:t(Ms,{children:t(n,{})})})},Ms=u("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)}})),_t=u("ul")(()=>({all:"unset",display:"flex",alignItems:"center",alignContent:"center"})),at=u("li")(()=>({all:"unset",minWidth:30,textAlign:"center"})),_s=u("div")(({theme:e})=>({display:"flex",flexDirection:"row",alignItems:"center",gap:e.spacing(1)})),Oe=5,Ls=({strategies:e})=>e!=null&&e.length?e.length>Oe+1?r(_t,{"aria-label":"Feature strategies",children:[e.slice(0,Oe).map(n=>t(at,{children:t(nt,{strategy:n})},n.id)),r(nn,{tooltip:e.slice(Oe).map(n=>t(at,{children:r(_s,{children:[t(nt,{strategy:n})," ",Re(n.name)+(n.title?` - ${n.title}`:"")]})},n.id)),children:["(+",e.length-Oe,")"]})]}):t(_t,{"aria-label":"Feature strategies",children:e.map(n=>t(at,{children:t(nt,{strategy:n})},n.id))}):null,js=u("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})),zs=u(ia)({boxShadow:"none",background:"none"}),Vs=u(ca)(({theme:e})=>({boxShadow:"none",padding:e.spacing(2,4),[e.breakpoints.down(400)]:{padding:e.spacing(1,2)}})),qs=u(la,{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)}})),Ns=u(Ts)(({theme:e})=>({width:"100%",position:"relative",paddingBottom:e.spacing(2)})),Ws=u("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})),Hs=u("div")(({theme:e})=>({display:"flex",alignItems:"center",[e.breakpoints.down(560)]:{flexDirection:"column",textAlign:"center"}})),Us=u(ho)(({theme:e})=>({[e.breakpoints.down(560)]:{marginBottom:"0.5rem"}})),Ys=u(ht)(({theme:e})=>({fontSize:e.fontSizes.bodySize,fontWeight:e.typography.fontWeightMedium,[e.breakpoints.down(560)]:{textAlign:"center"}})),Gs=u("div")(({theme:e})=>({display:"flex",alignItems:"center",marginTop:e.spacing(2),gap:e.spacing(2),flexWrap:"wrap",[e.breakpoints.down(560)]:{flexDirection:"column"}})),Ks=({env:e})=>{var p;const n=A("projectId"),a=A("featureId"),{metrics:s}=Mo(n,a),{feature:o}=j(n,a),{value:i}=an(),l=Lo(o==null?void 0:o.environments,s).find(h=>h.environment===e.name),d=o==null?void 0:o.environments.find(h=>h.name===e.name);return t(b,{condition:!new Set(i.hiddenEnvironments).has(e.name),show:t(js,{enabled:e.enabled,children:r(zs,{TransitionProps:{mountOnEnter:!0},"data-testid":`${da}_${e.name}`,className:`environment-accordion ${e.enabled?"":"accordion-disabled"}`,children:[r(Vs,{expandIcon:t(ua,{titleAccess:"Toggle"}),children:[r(Ws,{"data-loading":!0,enabled:e.enabled,children:[r(Hs,{children:[t(Us,{enabled:e.enabled}),t("div",{children:t(Ys,{text:e.name,maxWidth:"100",maxLength:15})}),t(b,{condition:!e.enabled,show:t(Ee,{color:"neutral",sx:{ml:1},children:"Disabled"})})]}),r(Gs,{children:[t(lt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name,variant:"outlined",size:"small"}),t(Ls,{strategies:d==null?void 0:d.strategies})]})]}),t(Os,{environmentMetric:l,disabled:!e.enabled})]}),r(qs,{enabled:e.enabled,children:[t(Ns,{featureEnvironment:d,isDisabled:!e.enabled,otherEnvironments:o==null?void 0:o.environments.map(({name:h})=>h).filter(h=>h!==e.name)}),t(b,{condition:(((p=d==null?void 0:d.strategies)==null?void 0:p.length)||0)>0,show:r(P,{children:[t(J,{sx:{display:"flex",justifyContent:"center",py:1},children:t(lt,{label:"Add strategy",projectId:n,featureId:a,environmentId:e.name})}),t(Is,{environmentMetric:l})]})})]})]})})})},Js=()=>{const e=A("projectId"),n=A("featureId"),{feature:a}=j(e,n);if(!a)return null;const{environments:s}=a;return t(P,{children:s==null?void 0:s.map(o=>t(Ks,{env:o},o.name))})},xn=e=>{const{makeRequest:n,createRequest:a,errors:s,loading:o}=pa({propagateErrors:!0}),i=async(p,h)=>{const m=a(`/api/admin/projects/${e}/features/${p}/dependencies`,{method:"POST",body:JSON.stringify(h)});await n(m.caller,m.id)},c=async(p,h)=>{const m=a(`/api/admin/projects/${e}/features/${p}/dependencies/${h}`,{method:"DELETE"});await n(m.caller,m.id)},l=async p=>{const h=a(`/api/admin/projects/${e}/features/${p}/dependencies`,{method:"DELETE"});await n(h.caller,h.id)},d=[a,n,z,e];return{addDependency:f.useCallback(i,d),removeDependency:f.useCallback(c,d),removeDependencies:f.useCallback(l,d),errors:s,loading:o}},Zs=(e,n,a={})=>{const s=de(`/api/admin/projects/${e}/features/${n}/parents`),{data:o,error:i,mutate:c}=Ve(s,Qs,a);return{parentOptions:o,error:i,loading:!i&&!o}},Qs=async e=>await(await fetch(e).then(we("Parent Options"))).json(),Xs=()=>r(he,{severity:"warning",children:["Remember to update your Unleash client! Feature dependencies require new SDK versions. Read more about ",t(er,{}),"."]}),er=()=>t("a",{href:"https://docs.getunleash.io/reference/dependent-features#client-sdk-support",target:"_blank",rel:"noreferrer",children:"Client SDK support for feature dependencies"}),tr=u(on)(({theme:e})=>({marginTop:e.spacing(2),marginBottom:e.spacing(1.5)})),Ce={key:"none (remove dependency)",label:"none (remove dependency)"},nr=({project:e,featureId:n,parent:a,onSelect:s})=>{const{parentOptions:o,loading:i}=Zs(e,n),c=o?[Ce,...o.map(l=>({key:l,label:l}))]:[Ce];return t(tr,{fullWidth:!0,options:c,value:a,onChange:s})},ar=(e,n,a,s)=>{const{trackEvent:o}=xe(),{addChange:i}=ue(),{refetch:c}=ae(e),{setToastData:l,setToastApiError:d}=K(),{refetchFeature:p}=j(e,n),h=ft(e)(),{isChangeRequestConfiguredInAnyEnv:m}=X(e),{addDependency:S,removeDependencies:C}=xn(e),g=async y=>{if(!h){console.error("No change request environment");return}y==="addDependency"&&(await i(e,h,[{action:y,feature:n,payload:{feature:a}}]),o("dependent_features",{props:{eventType:"dependency added"}})),y==="deleteDependency"&&await i(e,h,[{action:y,feature:n,payload:void 0}]),c(),l({text:y==="addDependency"?`${n} will depend on ${a}`:`${n} dependency will be removed`,type:"success",title:"Change added to a draft"})};return async()=>{try{if(m()){const y=a===Ce.key?"deleteDependency":"addDependency";await g(y),o("dependent_features",{props:{eventType:y==="addDependency"?"add dependency added to change request":"delete dependency added to change request"}})}else a===Ce.key?(await C(n),o("dependent_features",{props:{eventType:"dependency removed"}}),l({title:"Dependency removed",type:"success"})):(await S(n,{feature:a}),o("dependent_features",{props:{eventType:"dependency added"}}),l({title:"Dependency added",type:"success"}))}catch(y){d(z(y))}await p(),s()}},or=({project:e,featureId:n,showDependencyDialogue:a,onClose:s})=>{const[o,i]=f.useState(Ce.key),c=ar(e,n,o,s),{isChangeRequestConfiguredInAnyEnv:l}=X(e);return t(ne,{open:a,title:"Add parent feature dependency",onClose:s,onClick:c,primaryButtonText:l()?"Add change to draft":o===Ce.key?"Remove":"Add",secondaryButtonText:"Cancel",children:r(J,{children:[t(Xs,{}),t(J,{sx:{mt:2,mb:4},children:"Your feature will be evaluated only when the selected parent feature is enabled in the same environment."}),t(q,{children:"What feature do you want to depend on?"}),t(b,{condition:a,show:t(nr,{project:e,featureId:n,parent:o,onSelect:i})})]})})},_e=u("div")({display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center"}),Le=u("div")(({theme:e})=>({justifyContent:"center",paddingTop:e.spacing(.75),...ha})),je=u("span")(({theme:e})=>({color:e.palette.text.secondary,marginRight:e.spacing(1)})),En=u(G)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),sr=u(tn)(({theme:e})=>({borderRadius:e.shape.borderRadiusLarge,padding:e.spacing(1,1.5)})),rr=({feature:e,onEdit:n,onDelete:a})=>{const s=`dependency-${e}-actions`,o=`${s}-menu`,[i,c]=f.useState(null),l=!!i,d=h=>{c(h.currentTarget)},p=()=>{c(null)};return r("span",{children:[t(Q,{title:"Dependency actions",arrow:!0,describeChild:!0,children:t(qe,{id:s,"aria-controls":l?o:void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,onClick:d,type:"button",children:t(en,{})})}),t(sr,{id:o,anchorEl:i,open:l,onClose:p,transformOrigin:{horizontal:"right",vertical:"top"},anchorOrigin:{horizontal:"right",vertical:"bottom"},disableScrollLock:!0,children:r(ga,{"aria-labelledby":s,children:[t(b,{condition:!0,show:r(re,{onClick:()=>{n(),p()},children:[t(ve,{children:t(Se,{})}),t(le,{children:t(q,{variant:"body2",children:"Edit"})})]})}),t(b,{condition:!0,show:r(re,{onClick:()=>{a(),p()},children:[t(ve,{children:t(fa,{})}),t(le,{children:t(q,{variant:"body2",children:"Delete"})})]})})]})})]})},Dn=({childFeatures:e,project:n})=>t(nn,{tooltip:t(P,{children:e.map(a=>t(En,{to:`/projects/${n}/features/${a}`,children:t("div",{children:a})},`${n}-${a}`))}),children:e.length===1?"1 feature":`${e.length} features`}),ir=(e,n)=>{const{trackEvent:a}=xe(),{addChange:s}=ue(),{refetch:o}=ae(e),{setToastData:i,setToastApiError:c}=K(),{refetchFeature:l}=j(e,n),d=ft(e)(),{isChangeRequestConfiguredInAnyEnv:p}=X(e),{removeDependencies:h}=xn(e),m=async()=>{if(!d){console.error("No change request environment");return}await s(e,d,[{action:"deleteDependency",feature:n,payload:void 0}])};return async()=>{try{p()?(await m(),a("dependent_features",{props:{eventType:"delete dependency added to change request"}}),i({text:`${n} dependency will be removed`,type:"success",title:"Change added to a draft"}),await o()):(await h(n),a("dependent_features",{props:{eventType:"dependency removed"}}),i({title:"Dependency removed",type:"success"}),await l())}catch(C){c(z(C))}}},cr=({feature:e})=>{var p,h;const[n,a]=f.useState(!1),s=!!e.project&&e.dependencies.length===0&&e.children.length===0,o=!!e.project&&e.dependencies.length>0,i=!!e.project&&e.children.length>0,c=ft(e.project)(),l=Kt(e.project),d=ir(e.project,e.name);return r(P,{children:[t(b,{condition:s,show:t(_e,{children:r(Le,{children:[t(je,{children:"Dependency:"}),t(ie,{permission:vt,projectId:e.project,variant:"text",onClick:()=>{a(!0)},children:"Add parent feature"})]})})}),t(b,{condition:o,show:r(_e,{children:[r(Le,{children:[t(je,{children:"Dependency:"}),t(En,{to:`/projects/${e.project}/features/${(p=e.dependencies[0])==null?void 0:p.feature}`,children:(h=e.dependencies[0])==null?void 0:h.feature})]}),t(b,{condition:l(vt,c),show:t(rr,{feature:e.name,onEdit:()=>a(!0),onDelete:d})})]})}),t(b,{condition:i,show:t(_e,{children:r(Le,{children:[t(je,{children:"Children:"}),t(Dn,{childFeatures:e.children,project:e.project})]})})}),t(b,{condition:!!e.project,show:t(or,{project:e.project,featureId:e.name,onClose:()=>a(!1),showDependencyDialogue:n})})]})},lr=(e,n={})=>{const a=de(`/api/admin/projects/${e}/dependencies`),{data:s,error:o}=sn(e,!1,a,dr,n);return{dependenciesExist:s,error:o,loading:!o&&!s}},dr=async e=>await(await fetch(e).then(we("Dependencies exist check"))).json(),ur=e=>{const n=mt("dependentFeatures"),{dependenciesExist:a}=lr(e),{isOss:s}=We();return!!(s()?a&&n:n)},pr=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",justifyItems:"center",padding:e.spacing(3),fontSize:e.fontSizes.smallBody})),hr=({feature:e,header:n})=>{var l;const{locationSettings:a}=rn(),{uiConfig:s}=We(),o=ur(e.project),i=!!s.flags.lastSeenByEnvironment,c=(l=e.environments)==null?void 0:l.map(d=>({name:d.name,lastSeenAt:d.lastSeenAt,enabled:d.enabled}));return r(pr,{children:[n,r(_e,{children:[r(Le,{children:[t(je,{children:"Created at:"}),t("span",{children:ma(cn(e.createdAt),a.locale)})]}),i&&t(ya,{featureLastSeen:e.lastSeenAt,environments:c,sx:{p:0}})]}),t(b,{condition:o,show:t(cr,{feature:e})})]})},gr=u(qe,{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}})),fr=({environment:e,hiddenEnvironments:n,setHiddenEnvironments:a})=>t(gr,{onClick:()=>{a(e.name)},visibilityOff:n.has(e.name),children:t(b,{condition:n.has(e.name),show:t(Sa,{}),elseShow:t(ba,{})})}),mr=u("div")(({theme:e})=>({marginLeft:e.spacing(-1.5),"&:not(:last-of-type)":{marginBottom:e.spacing(2)},display:"flex",alignItems:"center"})),yr=u("label")(()=>({display:"inline-flex",alignItems:"center",cursor:"pointer"})),Sr=({environment:e,callback:n,showInfoBox:a,children:s,hiddenEnvironments:o,setHiddenEnvironments:i})=>{const{name:c,enabled:l}=e,d=A("projectId"),p=A("featureId"),{feature:h,refetchFeature:m}=j(d,p),S=r(P,{children:[" ",r("span",{"data-loading":!0,children:[l?"enabled":"disabled"," in"]})," ",t(ht,{text:c,maxWidth:"120",maxLength:15})]}),C=()=>{m(),n&&n()};return r(mr,{children:[r(yr,{children:[t(go,{featureId:h.name,projectId:d,environmentName:e.name,onToggle:C,onError:a,value:l}),s??S]}),t(fr,{environment:e,hiddenEnvironments:o,setHiddenEnvironments:i})]})},br=u("div")(({theme:e})=>({padding:e.spacing(3)})),vr=u("div")(()=>({display:"flex",flexDirection:"column"})),Cr=u("p")(({theme:e})=>({fontSize:e.fontSizes.bodySize})),wr=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,display:"flex",alignItems:"center"})),Lt=u("span")(({theme:e})=>({padding:e.spacing(0,.5),"::after":{content:'"-"'}})),Tr=u(yt)(()=>({"&:hover, &:focus":{textDecoration:"underline"}})),xr=({feature:e,header:n,hiddenEnvironments:a,setHiddenEnvironments:s})=>{const[o,i]=f.useState(!1),[c,l]=f.useState(""),d=e.environments.some(p=>{var h;return p.enabled&&((h=p.variants)==null?void 0:h.length)});return r(br,{"data-testid":"feature-toggle-status",children:[n,e.environments.map(p=>{const h=p.strategies.length===1?"1 strategy":`${p.strategies.length} strategies`,m=p.variants??[],S=m.length>0&&r(P,{children:[t(Lt,{}),t(Q,{title:"View variants",arrow:!0,describeChild:!0,children:t(Tr,{component:G,to:`/projects/${e.project}/features/${e.name}/variants`,underline:"hover",children:m.length===1?"1 variant":`${m.length} variants`})})]}),C=p.enabled&&m.length===0&&d;return t(Sr,{environment:p,hiddenEnvironments:a,setHiddenEnvironments:s,showInfoBox:()=>{l(p.name),i(!0)},children:r(vr,{children:[t(Cr,{children:p.name}),r(wr,{children:[h,S,t(b,{condition:C,show:r(P,{children:[t(Lt,{}),t(fo,{})]})})]})]})},p.name)}),t(mo,{open:o,onClose:()=>i(!1),projectId:e.project,featureId:e.name,environmentName:c})]})},An=(e,n={})=>{const a=async()=>{const p=de(`api/admin/features/${e}/tags`);return(await fetch(p,{method:"GET"}).then(we("Tags"))).json()},s=`api/admin/features/${e}/tags`,{data:o,error:i}=sn(!!e,{tags:[]},s,a,n),[c,l]=f.useState(!i&&!o),d=()=>{ut(s)};return f.useEffect(()=>{l(!i&&!o)},[o,i]),{tags:(o==null?void 0:o.tags)||[],error:i,loading:c,refetch:d}},Er=u("section")(({theme:e})=>({"& > *":{margin:e.spacing(1,0)}})),ot=e=>e.map(n=>({title:n.value})),jt=(e,n)=>e.map(a=>({value:a.title,type:n})),Rn=({open:e,setOpen:n})=>{const{tagTypes:a}=va(),s=A("featureId"),{createTag:o}=yo(),{updateFeatureTags:i,loading:c}=He(),{tags:l,refetch:d,loading:p}=An(s),{setToastData:h}=K(),m=a&&a.length>0?a[0]:{name:"simple",description:"Simple tag to get you started",icon:""},[S,C]=f.useState(m),g=c||p,[E,y]=f.useState(0),{trackEvent:w}=xe(),[$,M]=f.useState(ot(l.filter(T=>T.type===S.name))),{tags:V,refetch:_}=So(S.name),v=f.useMemo(()=>ot(V),[V]);f.useEffect(()=>{l&&S&&M(ot(l.filter(T=>T.type===S.name)))},[JSON.stringify(l),S]);const R=()=>{n(!1),M([])};function B(T,k){const O=T.filter(L=>L.type===S.name).filter(L=>!k.find(W=>L.value===W.value&&L.type===W.type)),H=k.filter(L=>L.type===S.name).filter(L=>!T.find(W=>L.value===W.value&&L.type===W.type));return y(O.length+H.length),{added:O,removed:H}}const N=T=>T.filter(k=>!k.title.startsWith("Create")),Z=async(T,k)=>{try{await i(s,{addedTags:T,removedTags:k}),await d()}catch(O){const H=z(O);h({type:"error",title:"Failed to add tag",text:H,confetti:!1})}},U=(T,k)=>{let O="We successfully";return T>0&&(O=O.concat(` added ${T} new tag${T>1?"s":""}`)),T>0&&k>0&&(O=O.concat(" and ")),k>0&&(O=O.concat(` removed ${k} tag${k>1?"s":""}`)),O},oe=async T=>{T.preventDefault();const k=jt(N($),S.name),{added:O,removed:H}=B(k,l);E>0&&(await Z(O,H),E>1&&w("suggest_tags",{props:{eventType:"multiple_tags_added"}}),E>0&&h({type:"success",title:`Updated tag${O.length>1?"s":""} to toggle`,text:U(O.length,H.length),confetti:!0})),y(0),M([]),n(!1)},x=(T,k)=>{k!=null&&typeof k!="string"&&(T.preventDefault(),C(k),M([]),y(0))},I=(T,k,O)=>{const H=Ca(k);O==="selectOption"&&k.forEach((W,$e)=>{if(typeof W!="string"&&W.inputValue&&W.inputValue!==""){const Ie={value:W.inputValue,type:S.name};o(Ie).then(()=>{w("suggest_tags",{props:{eventType:"tag_created"}}),_()}),W.title=W.inputValue,W.inputValue="",H[$e]=W}});const L=jt(N(H),S.name);B(L,l),M(H)},F="add-tag-form";return t(ne,{open:e,secondaryButtonText:"Cancel",primaryButtonText:"Save tags",title:"Update tags to feature toggle",onClick:oe,disabledPrimaryButton:g||E===0,onClose:R,formId:F,children:r(P,{children:[t(q,{paragraph:!0,sx:{marginBottom:T=>T.spacing(2.5)},children:"Tags allow you to group features together"}),t("form",{id:F,onSubmit:oe,children:r(Er,{children:[t(bo,{options:a,value:S,onChange:x}),t(vo,{options:v,existingTags:l,tagType:S,selectedOptions:$,onChange:I})]})})]})})},Dr=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",padding:e.spacing(3)})),Ar=u("div")(({theme:e})=>({display:"flex",gap:e.spacing(1),flexWrap:"wrap"})),Rr=u(ln)(({theme:e})=>({fontSize:e.fontSizes.smallBody})),kr=u(De)(({theme:e})=>({margin:e.spacing(3),borderStyle:"dashed"})),Fr=u(Te)(({theme:e})=>({maxWidth:e.spacing(20),alignSelf:"center"})),$r=({feature:e,header:n})=>{const{tags:a,refetch:s}=An(e.name),{deleteTagFromFeature:o}=He(),[i,c]=f.useState(!1),[l,d]=f.useState(!1),[p,h]=f.useState(),{setToastData:m,setToastApiError:S}=K(),{hasAccess:C}=f.useContext(pt),g=C(ye,e.project),E=async()=>{if(p)try{await o(e.name,p.type,p.value),s(),m({type:"success",title:"Tag deleted",text:"Successfully deleted tag"})}catch(y){S(z(y))}};return r(Dr,{children:[n,t(Ar,{children:a.map(y=>{const w=`${y.type}:${y.value}`;return t(Rr,{label:w,deleteIcon:t(wa,{titleAccess:"Remove"}),onDelete:g?()=>{d(!0),h(y)}:void 0},w)})}),t(b,{condition:g,show:r(P,{children:[t(b,{condition:a.length>0,show:t(kr,{})}),t(Fr,{"data-loading":!0,variant:"outlined",startIcon:t(Ta,{}),onClick:()=>c(!0),children:"Add new tag"})]})}),t(Rn,{open:i,setOpen:c}),r(ne,{open:l,primaryButtonText:"Delete tag",secondaryButtonText:"Cancel",onClose:()=>{d(!1),h(void 0)},onClick:()=>{d(!1),E(),h(void 0)},title:"Delete tag?",children:["You are about to delete tag:"," ",r("strong",{children:[p==null?void 0:p.type,":",p==null?void 0:p.value]})]})]})},Ir=u(xa)(({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"}})),st=u("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}})),Pr=({hiddenEnvironments:e,setHiddenEnvironments:n})=>{const a=A("projectId"),s=A("featureId"),{feature:o}=j(a,s);return r(Ir,{children:[t(xr,{header:r(st,{"data-loading":!0,children:["Enabled in environments (",o.environments.filter(({enabled:i})=>i).length,")",t(Ea,{tooltip:"When a feature is switched off in an environment, it will always return false. When switched on, it will return true or false depending on its strategies.",placement:"top"})]}),feature:o,hiddenEnvironments:e,setHiddenEnvironments:n}),t(De,{}),t(hr,{header:t(st,{"data-loading":!0,children:"Feature toggle details"}),feature:o}),t(De,{}),t($r,{header:t(st,{"data-loading":!0,children:"Tags for this feature toggle"}),feature:o})]})},Br=()=>{const{trackEvent:e}=xe(),{value:n,setValue:a}=an(),[s,o]=f.useState(new Set(n.hiddenEnvironments));return{hiddenEnvironments:s,setHiddenEnvironments:c=>{a(l=>{const d=new Set(l.hiddenEnvironments);return d.has(c)?(d.delete(c),e("hidden_environment",{props:{eventType:"environment unhidden"}})):(d.add(c),e("hidden_environment",{props:{eventType:"environment hidden"}})),o(d),{...n,hiddenEnvironments:d}})}}},Or=u("div")(({theme:e})=>({display:"flex",width:"100%",[e.breakpoints.down(1e3)]:{flexDirection:"column"}})),Mr=u("div")(({theme:e})=>({display:"flex",flexDirection:"column",width:"calc(100% - (350px + 1rem))",[e.breakpoints.down(1e3)]:{width:"100%"}})),_r=()=>{const e=pe(),n=A("projectId"),a=A("featureId"),s=Zt(n,a),{hiddenEnvironments:o,setHiddenEnvironments:i}=Br(),c=()=>e(s);return dn(a),r(Or,{children:[r("div",{children:[t(Oo,{}),t(Pr,{hiddenEnvironments:o,setHiddenEnvironments:i})]}),t(Mr,{children:t(Js,{})}),r(un,{children:[t(ce,{path:"strategies/create",element:t(ct,{label:"Create feature strategy",onClose:c,open:!0,children:t(Co,{})})}),t(ce,{path:"strategies/edit",element:t(ct,{label:"Edit feature strategy",onClose:c,open:!0,children:t(Da,{})})})]})]})},Lr=u("div")(({theme:e})=>({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"},marginTop:e.spacing(-3.5),marginBottom:e.spacing(2),backgroundColor:e.palette.background.default,paddingTop:e.spacing(2),paddingBottom:e.spacing(2),position:"sticky",top:0,zIndex:2})),jr=u(pn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),zr=u("span",{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.text.secondary:e.palette.text.primary,marginLeft:e.spacing(1.25),fontSize:e.fontSizes.mainHeader,fontWeight:e.fontWeight.bold})),Vr=u("form")(()=>({display:"flex",flexDirection:"column",height:"100%"})),qr=u(he)(({theme:e})=>({marginBottom:e.spacing(2)})),Nr=u(he)(({theme:e})=>({marginTop:e.spacing(4)})),Wr=u("div")({display:"flex",flexDirection:"column"}),Hr=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),zt=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),Ur=u(De)(({theme:e})=>({margin:e.spacing(4,0)})),Yr=u(Aa)(({theme:e})=>({minWidth:e.spacing(20),width:"100%"})),Gr=u("div")(({theme:e})=>({marginTop:"auto",paddingTop:e.spacing(4),display:"flex",justifyContent:"flex-end"})),Kr=u(Te)(({theme:e})=>({marginLeft:e.spacing(3)})),Jr=f.memo(Ra),Zr=({environment:e,open:n,setOpen:a,getApiPayload:s,getCrPayload:o,onConfirm:i})=>{const c=A("projectId"),l=A("featureId"),{uiConfig:d}=We(),{context:p}=ka(),{defaultStickiness:h,loading:m}=Fa(c),{isChangeRequestConfigured:S}=X(c),{data:C}=ae(c),{changeRequestInReviewOrApproved:g,alert:E}=Pa(C),y=(e==null?void 0:e.variants)||[],[w,$]=f.useState([]),[M,V]=f.useState();f.useEffect(()=>{m||$(y.length?y.map(D=>({...D,isValid:!0,new:!1,id:Ge()})):[{name:"",weightType:Ct.VARIABLE,weight:0,overrides:[],stickiness:(w==null?void 0:w.length)>0?w[0].stickiness:h,new:!0,isValid:!1,id:Ge()}])},[n,m]);const _=(D,Y)=>{$(ge=>wt(ge.map(Pe=>Pe.id===Y?D:Pe),1e3))},v=()=>{const D=Ge();$(Y=>[...Y,{name:"",weightType:Ct.VARIABLE,weight:0,overrides:[],stickiness:(Y==null?void 0:Y.length)>0?Y[0].stickiness:h,new:!0,isValid:!1,id:D}]),V(D)};f.useEffect(()=>{if(M){const D=document.getElementById(`variant-name-input-${M}`);D==null||D.scrollIntoView({behavior:"smooth",block:"center"}),D==null||D.focus({preventScroll:!0}),V(void 0)}},[M]);const R=w.map(({new:D,isValid:Y,id:ge,...Pe})=>Pe),B=s(y,R),N=o(R),Z=async D=>{D.preventDefault(),i(R)},U=()=>F?`curl --location --request POST '${d.unleashUrl}/api/admin/projects/${c}/environments/${e==null?void 0:e.name}/change-requests' \\
2
2
  --header 'Authorization: INSERT_API_KEY' \\
3
3
  --header 'Content-Type: application/json' \\
4
4
  --data-raw '${JSON.stringify(N,void 0,2)}'`:`curl --location --request PATCH '${d.unleashUrl}/api/admin/projects/${c}/features/${l}/environments/${e==null?void 0:e.name}/variants' \\
5
5
  --header 'Authorization: INSERT_API_KEY' \\
6
6
  --header 'Content-Type: application/json' \\
7
- --data-raw '${JSON.stringify(B.patch,void 0,2)}'`,oe=w.every(({isValid:D})=>D),x=g((e==null?void 0:e.name)||""),I=x?"Add to existing change request":"Add change to draft",F=S((e==null?void 0:e.name)||""),T=f.useMemo(()=>{var D;return m?"":((D=R[0])==null?void 0:D.stickiness)||h},[m,h,JSON.stringify(R[0]??{})]),k=f.useMemo(()=>["default",...p.filter(D=>D.stickiness).map(D=>D.name)],[p]),O=k.map(D=>({key:D,label:D}));k.includes(T)||O.push({key:T,label:T});const H=async D=>{$(Y=>Y.map(ge=>({...ge,stickiness:D})))},L=D=>{H(D)},[W,$e]=f.useState();f.useEffect(()=>{$e(void 0),B.error&&$e(B.error)},[B.error]);const Ie=()=>{H(h),a(!1)};return m||T===""?t($a,{}):t(ct,{open:n,onClose:Ie,label:"",children:r(Ia,{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:U,loading:!n,children:[r(Lr,{children:[r("div",{children:[t(jr,{deprecated:!(e!=null&&e.enabled)}),t(zr,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(ie,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:v,variant:"outlined",permission:fe,projectId:c,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),r(Vr,{onSubmit:Z,children:[t(b,{condition:x,show:E,elseShow:t(b,{condition:!!F,show:r(qr,{severity:"info",children:[t("strong",{children:"Change requests"})," are enabled",e?` for ${e.name}`:"",". Your changes need to be approved before they will be live. All the changes you do now will be added into a draft that you can submit for review."]})})}),t(Wr,{children:w.map(D=>t(Jr,{variant:D,variants:w,updateVariant:Y=>_(Y,D.id),removeVariant:()=>$(Y=>wt(Y.filter(ge=>ge.id!==D.id),1e3)),error:B.error},D.id))}),t(ie,{onClick:v,variant:"outlined",permission:fe,projectId:c,environmentId:e==null?void 0:e.name,children:"Add variant"}),t(Ur,{}),t(b,{condition:w.length>0,show:r(P,{children:[t(Hr,{children:t("p",{children:"Stickiness"})}),r(zt,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(yt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t(Yr,{value:T,label:"",editable:!0,onChange:D=>L(D.target.value)})})]}),elseShow:t(zt,{children:"This environment has no variants. Get started by adding a variant."})}),r(Nr,{severity:"error",hidden:!W,children:[t("strong",{children:"Error: "}),W]}),r(Gr,{children:[t(Te,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!oe,children:F?I:"Save variants"}),t(Kr,{onClick:Ie,children:"Cancel"})]})]})]})})},Qr=u("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.divider}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),Xr=u("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),ei=u(pn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),ti=u("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})),ni=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),ai=u("div")(({theme:e})=>({margin:e.spacing(3,0)})),oi=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),si=({environment:e,searchValue:n,children:a})=>{var i;const s=e.variants??[],o=((i=s[0])==null?void 0:i.stickiness)||"default";return r(Qr,{children:[r(Xr,{children:[r("div",{children:[t(ei,{deprecated:!e.enabled}),t(ti,{deprecated:!e.enabled,children:e.name})]}),a]}),t(b,{condition:s.length>0,show:r(P,{children:[t(ai,{children:t(Ba,{variants:s,searchValue:n})}),t(b,{condition:s.length>1,show:r(P,{children:[r(oi,{children:[t("p",{children:"Stickiness:"}),t(Ee,{children:o})]}),r(ni,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(yt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},ri=u(le)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),ii=({environment:e,permission:n,projectId:a,environmentId:s,onCopyVariantsFrom:o,otherEnvsWithVariants:i})=>{const[c,l]=f.useState(null),d=!!c,p=e.variants??[];return t(b,{condition:i.length>0&&p.length===0,show:r(P,{children:[t(ie,{onClick:h=>{l(h.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":d?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":d?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:s,children:"Copy variants from"}),t(Fe,{anchorEl:c,open:d,onClose:()=>l(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:i.map(h=>t(re,{onClick:()=>o(h,e),children:t(ri,{children:`Copy from ${h.name}`})},h.name))})]})})},ci=({permission:e,projectId:n,environment:a,checked:s,onClick:o,...i})=>{const c=it(e,n,a);return r(re,{disabled:!c,onClick:o,...i,children:[t(Oa,{checked:s}),a]})},li=u(Fe)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),di=u("div")(({theme:e})=>({margin:e.spacing(1,2)})),ui=u(Te)(({theme:e})=>({marginTop:e.spacing(2)})),pi=({current:e,environments:n,permission:a,projectId:s,onSubmit:o})=>{var E;const[i,c]=f.useState(null),l=!!i,[d,p]=f.useState([]),h=y=>{p(w=>[...w,y])},m=y=>{p(w=>w.filter(({name:$})=>$!==y.name))},S=y=>{d.includes(y)?m(y):h(y)},C=()=>{p([]),c(null)},g=((E=n.find(y=>y.name===e))==null?void 0:E.variants)??[];return t(b,{condition:g.length>0&&n.length>1,show:r(P,{children:[t(Te,{onClick:y=>{c(y.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,variant:"outlined",children:"Copy to environment"}),r(li,{anchorEl:i,open:l,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(y=>y.name!==e).map(y=>t(ci,{projectId:s,permission:a,environment:y.name,checked:d.includes(y),onClick:()=>S(y)},y.name)),r(di,{children:[t(De,{}),r(ui,{variant:"outlined",onClick:()=>{o(d),C()},disabled:d.length===0,children:["Push to selected (",d.length,")"]})]})]})]})})},hi=u("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),gi=()=>{const{setToastData:e,setToastApiError:n}=K(),a=Qt(),s=Ne(a.breakpoints.down("md")),o=A("projectId"),i=A("featureId"),{feature:c,refetchFeature:l,loading:d}=j(o,i),{patchFeatureEnvironmentVariants:p,overrideVariantsInEnvironments:h}=He(),{refetch:m}=ae(o),{addChange:S}=ue(),{isChangeRequestConfigured:C}=X(o),[g,E]=f.useState(""),[y,w]=f.useState(),[$,M]=f.useState(!1),V=f.useMemo(()=>{var x;return((x=c==null?void 0:c.environments)==null?void 0:x.map(I=>({...I,crEnabled:C(I.name)})))||[]},[c.environments]),_=(x,I)=>ja(x,I),v=(x,I)=>{try{const F=La(I,1e3);return{patch:_(x,F)}}catch(F){return{patch:[],error:z(F)}}},R=x=>({feature:i,action:"patchVariant",payload:{variants:x}}),B=async(x,I)=>{if(x.crEnabled)await S(o,x.name,R(I)),m();else{const F=x.variants??[],{patch:T,error:k}=v(F,I);if(T.length===0)return;if(k){e({type:"error",title:k});return}await p(o,i,x.name,T)}l()},N=async(x,I)=>{try{const F=I.filter(({crEnabled:L})=>L),T=I.filter(({crEnabled:L})=>!L);F.length&&await Promise.all(F.map(L=>S(o,L.name,R(x)))),T.length&&await h(o,i,x,T.map(({name:L})=>L)),m(),l();const k=T.length?`Variants pushed to ${T.length===1?T[0].name:`${T.length} environments`}`:"",O=F.length?`Variants push added to ${F.length===1?`${F[0].name} draft`:`${F.length} drafts`}`:"",H=`${k}${k&&O?". ":""}${O}`;e({title:H,type:"success"})}catch(F){n(z(F))}},Z=x=>{w(x),M(!0)},U=async x=>{if(y)try{await B(y,x),M(!1),e({title:y.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(I){n(z(I))}},oe=async(x,I)=>{try{const F=x.variants??[];await B(I,F),e({title:I.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(F){n(z(F))}};return r(St,{isLoading:d,header:t(Ma,{title:"Variants",actions:t(b,{condition:!s,show:t(P,{children:t(Tt,{initialValue:g,onChange:E})})}),children:t(b,{condition:s,show:t(Tt,{initialValue:g,onChange:E})})}),children:[t(_a,{}),V.map(x=>{var F;const I=V.filter(({name:T,variants:k})=>T!==x.name&&(k==null?void 0:k.length));return t(si,{environment:x,searchValue:g,children:r(hi,{children:[t(pi,{current:x.name,environments:V,permission:fe,projectId:o,onSubmit:T=>N(x.variants??[],T)}),t(ii,{environment:x,permission:fe,projectId:o,environmentId:x.name,onCopyVariantsFrom:oe,otherEnvsWithVariants:I}),t(b,{condition:!!((F=x.variants)!=null&&F.length),show:t(te,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>Z(x),permission:fe,projectId:o,environmentId:x.name,tooltipProps:{title:"Edit variants"},children:t(Se,{})}),elseShow:t(ie,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>Z(x),variant:"outlined",permission:fe,projectId:o,environmentId:x.name,children:"Add variant"})})]})},x.name)}),t(Zr,{environment:y,open:$,setOpen:M,getApiPayload:v,getCrPayload:R,onConfirm:U})]})},fi=de("api/admin/client-metrics/features"),kn=(e,n)=>{const a=de(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:s,error:o}=Ve(a,()=>mi(a)),i=f.useCallback(()=>{ut(fi).catch(console.warn)},[]);return{featureMetrics:s==null?void 0:s.data,loading:!o&&!s,refetchFeatureMetrics:i,error:o}},mi=e=>fetch(e).then(we("Features")).then(n=>n.json()).then(),yi=u("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ae=48,Si=({hoursBack:e,setHoursBack:n})=>{const a=s=>{n(bi(s))};return r("div",{children:[t(yi,{children:"Period"}),t(on,{name:"feature-metrics-period",id:"feature-metrics-period",options:vi,value:String(e),onChange:a,fullWidth:!0})]})},bi=e=>{switch(e){case"1":return 1;case"24":return 24;default:return Ae}},vi=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${Ae}`,label:`Last ${Ae} hours`}],Ci=({value:e})=>{const{locationSettings:n}=rn(),a=e?e instanceof Date?xt(e,n.locale):xt(cn(e),n.locale):void 0;return t(hn,{lineClamp:1,children:a})},wi=({metrics:e,tableSectionId:n})=>{const a=Ne(za.breakpoints.down("md")),s=f.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:o,getTableBodyProps:i,headerGroups:c,rows:l,prepareRow:d,setHiddenColumns:p}=Ke.useTable({initialState:s,columns:Vt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:hn}},Ke.useGlobalFilter,Ke.useSortBy);return Va([{condition:a,columns:["appName","environment"]}],p,Vt),e.length===0?null:r(qa,{...o(),rowHeight:"standard",id:n,children:[t(Na,{headerGroups:c}),t(Wa,{...i(),children:l.map(h=>(d(h),t(Ha,{hover:!0,...h.getRowProps(),children:h.cells.map(m=>t(Ua,{...m.getCellProps(),children:m.render("Cell")}))})))})]})},Vt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Ya,{icon:t(Ao,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(Ci,{value:e.row.original.timestamp})},{Header:"Application",accessor:"appName"},{Header:"Environment",accessor:"environment"},{id:"requested",Header:"Requested",accessor:e=>e.yes+e.no},{Header:"Exposed",accessor:"yes"}],Ti=({metrics:e,...n})=>{const a=f.useMemo(()=>e.reduce((o,i)=>o+i.yes,0),[e]),s=f.useMemo(()=>e.reduce((o,i)=>o+i.no,0),[e]);return t(Tn,{...n,totalYes:a,totalNo:s})},xi=({metrics:e,hoursBack:n})=>{const a=Et(),s=Et();return e.length===0?r(J,{mt:6,children:[t(q,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(q,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):r(f.Suspense,{fallback:null,children:[t(J,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t(Ei,{metrics:e,hoursBack:n,statsSectionId:a})}),t(J,{mt:4,children:t(Ti,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:s})}),t(J,{mt:4,children:t(wi,{metrics:e,tableSectionId:s})})]})},Ei=Ga.lazy(()=>Ka(()=>import("./FeatureMetricsChart-c575d046.js"),[])),dt=e=>{const{search:n}=window.location,a=pe(),s=f.useMemo(()=>new URLSearchParams(n),[n]),o=f.useCallback(i=>{const c=new URLSearchParams(n);c.set(e,i),a({search:c.toString()},{replace:!0})},[e,n,a]);return[s.get(e)||void 0,o]},Di=e=>{const[n,a]=dt(e),s=f.useCallback(o=>a(String(o)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,s]},Ai=u("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ri=u("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),ki=u("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}})),qt=({title:e,values:n,value:a,setValue:s})=>{const o=c=>()=>{n.has(c)&&s(c)},i=f.useMemo(()=>Array.from(n).sort((c,l)=>c.localeCompare(l)),[n]);return r("div",{children:[t(Ai,{children:e}),t(Ri,{children:i.map(c=>t(ki,{children:t(ln,{label:c,onClick:o(c),"aria-pressed":c===a,sx:Ja})},c))})]})},Fi=()=>{const e=A("projectId"),n=A("featureId"),a=$i(e,n),s=Ii(n);dn("Metrics");const[o=Ae,i]=Di("hoursBack"),{featureMetrics:c}=kn(n,o),[l,d]=f.useState(c);f.useEffect(()=>{c&&d(c)},[c]);const p=Array.from(a)[0],h=Array.from(s)[0],[m=p,S]=dt("environment"),[C=h,g]=dt("application"),E=f.useMemo(()=>l==null?void 0:l.filter(y=>y.environment===m).filter(y=>y.appName===C),[l,m,C]);return E?r(St,{children:[r(se,{container:!0,component:"header",spacing:2,children:[t(se,{item:!0,xs:12,md:5,children:t(b,{condition:a.size>0,show:t(qt,{title:"Environments",values:a,value:m,setValue:S})})}),t(se,{item:!0,xs:12,md:5,children:t(b,{condition:s.size>0,show:t(qt,{title:"Applications",values:s,value:C,setValue:g})})}),t(se,{item:!0,xs:12,md:2,children:t(Si,{hoursBack:o,setHoursBack:i})})]}),t(xi,{metrics:E,hoursBack:o})]}):null},$i=(e,n)=>{const{feature:a}=j(e,n),s=a.environments.map(o=>o.name);return new Set(s)},Ii=e=>{const{featureMetrics:n=[]}=kn(e,Ae),a=n.map(s=>s.appName);return new Set(a)},Pi=(e,n)=>{const a=new Set(e),s=new Set(n);return a.size!==s.size?!1:[...a].every(o=>s.has(o))},Nt=u("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Wt=u(he)(({theme:e})=>({marginBottom:e.spacing(1)})),Bi=u(gt)({padding:0}),Oi=({projectId:e,open:n,onClose:a,onClick:s,feature:o,changeRequests:i})=>{const c=mt("dependentFeatures"),l=A("projectId"),{project:d}=gn(e),{isChangeRequestConfiguredInAnyEnv:p}=X(e),h=p(),m=f.useMemo(()=>Pi(o.environments.map(g=>g.name),d.environments.map(g=>g.environment)),[o,d]),S=i?i.length>0:!1,C=c&&(o.dependencies.length>0||o.children.length>0);return t(b,{condition:m&&!C&&!S&&!h,show:t(ne,{open:n,onClose:a,onClick:s,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:r(Nt,{children:[t(Wt,{severity:"success",children:"This feature toggle is compatible with the new project."}),t("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t(ne,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"Close",children:r(Nt,{children:[t(Wt,{severity:"warning",children:"Cannot proceed with the move"}),t(b,{condition:C,show:r("p",{children:[t("span",{children:"The feature toggle must not have any dependencies."})," ",t("br",{}),t("span",{children:"Please remove feature dependencies first."})]})}),t(b,{condition:!m,show:t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t(b,{condition:S,show:r(P,{children:[t("p",{children:"The feature toggle must not have any pending change requests. This feature toggle is currently referenced in the following change requests:"}),t(Bi,{children:i==null?void 0:i.map(g=>t(me,{children:r(G,{to:`/projects/${l}/change-requests/${g.id}`,children:["View change request"," ",g.id]})},g.id))})]})}),t(b,{condition:h,show:r("p",{children:["You're not allowed to move the feature to project"," ",t(G,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},Mi=e=>fetch(e).then(we("ChangeRequest")).then(n=>n.json()),_i=(e,n)=>{const{data:a,error:s,mutate:o}=Za([],de(`api/admin/projects/${e}/change-requests/pending/${n}`),Mi);return{changeRequests:a,loading:!s&&!a,refetch:o,error:s}},Li=()=>{const{hasAccess:e}=f.useContext(pt),n=A("projectId"),a=A("featureId"),{feature:s,refetchFeature:o}=j(n,a),[i,c]=f.useState(!1),{changeFeatureProject:l}=He(),{setToastData:d,setToastApiError:p}=K(),[h,m]=f.useState(n),{projects:S}=Qa(),C=pe(),{changeRequests:g}=_i(n,a),E=async()=>{try{h&&(await l(n,a,h),o(),d({title:"Project changed",type:"success"}),c(!1),C(`/projects/${h}/features/${a}/settings`,{replace:!0}))}catch(w){p(z(w))}},y=f.useMemo(()=>S.map(w=>w.id).filter(w=>e(Dt,w)),[S,e]);return y.length===0?null:r(P,{children:[t(Xa,{value:h,onChange:m,label:"Project",filter:w=>y.includes(w),enabled:!0}),t(ie,{permission:Dt,onClick:()=>c(!0),disabled:h===n,projectId:n,children:"Save"}),t(Oi,{changeRequests:g,projectId:h,open:i,feature:s,onClose:()=>c(!1),onClick:E})]})},ji=u("div")({display:"flex",alignItems:"center"}),zi=u(q)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),Vi=({projectId:e,featureId:n})=>{var i;const{feature:a}=j(e,n),s=pe();return r(P,{children:[r(ji,{children:[t(zi,{children:"Feature information"}),t(te,{permission:ye,projectId:e,"data-loading":!0,onClick:()=>{s(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(Se,{})})]}),r(q,{children:["Name: ",t("strong",{children:a.name})]}),r(q,{children:["Description:"," ",t("strong",{children:(i=a.description)!=null&&i.length?a.description:"no description"})]}),r(q,{children:["Type: ",t("strong",{children:a.type})]}),r(q,{children:["Impression Data:"," ",t("strong",{children:a.impressionData?"enabled":"disabled"})]})]})},Me="metadata",rt="project",qi=u("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),Ni=u("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,"& > *":{margin:e.spacing(1,0)}})),Wi=()=>{const e=A("projectId"),n=A("featureId"),[a,s]=f.useState(Me),{uiConfig:o}=We();return t(St,{header:"Settings",sx:{padding:0},children:r(J,{sx:{display:"flex"},children:[t(qi,{children:r(gt,{children:[t(me,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(Me),selected:a===Me,children:"Metadata"},0),t(me,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(rt),selected:a===rt,hidden:!o.flags.P,children:"Project"},1)]})}),r(Ni,{children:[t(b,{condition:a===Me,show:t(Vi,{projectId:e,featureId:n})}),t(b,{condition:a===rt&&o.flags.P,show:t(Li,{})})]})]})})},Hi=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(Ee,{color:e?"error":"success",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",children:e?"Stale":"Active"})}),Ht=u("strong")({wordBreak:"break-all"}),Ui=()=>{const e=A("projectId"),n=A("featureId"),{archivedFeatures:a}=eo(),s=to(e,{name:n});return a?a.some(i=>i.name===n)?r("p",{children:["The feature ",t(Ht,{children:n})," has been archived. You can find it on the"," ",t(G,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):r("p",{children:["The feature ",t(Ht,{children:n})," does not exist. Would you like to"," ",t(G,{to:s,children:"create it"}),"?"]}):null},Yi=u(G)(({theme:e})=>({textDecoration:"none",color:e.palette.primary.main,fontWeight:e.fontWeight.bold})),Gi=({isOpen:e,onClose:n,features:a,project:s})=>r(ne,{title:"You can't archive a feature that other features depend on",open:e,primaryButtonText:"OK",onClick:n,children:[t("p",{children:"The following features depend on your feature:"}),t("ul",{children:a.map(o=>t("li",{children:t(Yi,{to:`/projects/${s}/features/${o}`,target:"_blank",rel:"noopener noreferrer",children:o})},o))})]}),Ki=e=>f.createElement("svg",{fill:"none",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},f.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"}),f.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"})),Ji=e=>f.createElement("svg",{fill:"none",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},f.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"})),Zi=u("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),Qi=u("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),Ut=u("div")({display:"flex",alignItems:"center"}),Yt=u("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"}));u(Ki)(({theme:e})=>({width:e.fontSizes.smallBody,height:e.fontSizes.smallBody}));u(Ji)(({theme:e})=>({width:e.fontSizes.smallBody,height:e.fontSizes.smallBody}));const Xi=u("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),ec=u("div")({flexShrink:0,display:"flex"}),tc=u("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),nc=u("div")(({theme:e})=>({padding:e.spacing(0,4)})),ac=u(no)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),oc=u(G)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),cc=()=>{var N,Z;const e=A("projectId"),n=A("featureId"),{refetch:a}=gn(e),{favorite:s,unfavorite:o}=ao(),{refetchFeature:i}=j(e,n),c=mt("dependentFeatures"),[l,d]=f.useState(!1),[p,h]=f.useState(!1),[m,S]=f.useState(!1),C=Ne("(max-width:500px)"),{feature:g,loading:E,error:y,status:w}=j(e,n),$=pe(),{pathname:M}=oo(),V=so(E),_=`/projects/${e}/features/${n}`,v=[{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"}],R=v.find(U=>U.path===M)??v[0],B=async()=>{g!=null&&g.favorite?await o(e,g.name):await s(e,g.name),i()};return w===404?t(Ui,{}):y!==void 0?t("div",{ref:V}):r("div",{ref:V,children:[r(Zi,{children:[r(Qi,{children:[r(Ut,{children:[t(ro,{onClick:B,isFavorite:g==null?void 0:g.favorite}),r("div",{children:[r(Ut,{children:[r(Xi,{"data-loading":!0,children:[g.name," "]}),t(b,{condition:!C,show:t(Hi,{stale:g==null?void 0:g.stale})})]}),t(b,{condition:c&&g.dependencies.length>0,show:r(Yt,{children:[t("b",{children:"Has parent: "}),t(oc,{to:`/projects/${g.project}/features/${(N=g==null?void 0:g.dependencies[0])==null?void 0:N.feature}`,children:(Z=g==null?void 0:g.dependencies[0])==null?void 0:Z.feature})]})}),t(b,{condition:c&&g.children.length>0,show:r(Yt,{children:[t("b",{children:"Has children:"}),t(Dn,{childFeatures:g.children,project:g.project})]})})]})]}),r(ec,{children:[t(te,{permission:io,projectId:e,"data-loading":!0,component:G,to:`/projects/${e}/features/${n}/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(co,{})}),t(te,{permission:lo,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>h(!0),children:t(Do,{})}),t(te,{onClick:()=>S(!0),permission:ye,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(wo,{})}),t(te,{onClick:()=>d(!0),permission:ye,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(uo,{})})]})]}),t(tc,{}),t(nc,{children:t(po,{value:R.path,indicatorColor:"primary",textColor:"primary",children:v.map(U=>t(ac,{label:U.title,value:U.path,onClick:()=>$(U.path),"data-testid":`TAB-${U.title}`},U.title))})})]}),r(un,{children:[t(ce,{path:"metrics",element:t(Fi,{})}),t(ce,{path:"logs",element:t(ko,{})}),t(ce,{path:"variants",element:t(gi,{})}),t(ce,{path:"settings",element:t(Wi,{})}),t(ce,{path:"*",element:t(_r,{})})]}),t(b,{condition:g.children.length>0,show:t(Gi,{features:g.children,project:e,isOpen:p,onClose:()=>h(!1)}),elseShow:t(To,{isOpen:p,onConfirm:()=>{a(),$(`/projects/${e}`)},onClose:()=>h(!1),projectId:e,featureIds:[n]})}),t(xo,{isStale:g.stale,isOpen:m,onClose:()=>{S(!1),i()},featureId:n,projectId:e}),t(Rn,{open:l,setOpen:d})]})};export{cc as default};
7
+ --data-raw '${JSON.stringify(B.patch,void 0,2)}'`,oe=w.every(({isValid:D})=>D),x=g((e==null?void 0:e.name)||""),I=x?"Add to existing change request":"Add change to draft",F=S((e==null?void 0:e.name)||""),T=f.useMemo(()=>{var D;return m?"":((D=R[0])==null?void 0:D.stickiness)||h},[m,h,JSON.stringify(R[0]??{})]),k=f.useMemo(()=>["default",...p.filter(D=>D.stickiness).map(D=>D.name)],[p]),O=k.map(D=>({key:D,label:D}));k.includes(T)||O.push({key:T,label:T});const H=async D=>{$(Y=>Y.map(ge=>({...ge,stickiness:D})))},L=D=>{H(D)},[W,$e]=f.useState();f.useEffect(()=>{$e(void 0),B.error&&$e(B.error)},[B.error]);const Ie=()=>{H(h),a(!1)};return m||T===""?t($a,{}):t(ct,{open:n,onClose:Ie,label:"",children:r(Ia,{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:U,loading:!n,children:[r(Lr,{children:[r("div",{children:[t(jr,{deprecated:!(e!=null&&e.enabled)}),t(zr,{deprecated:!(e!=null&&e.enabled),children:e==null?void 0:e.name})]}),t(ie,{"data-testid":"MODAL_ADD_VARIANT_BUTTON",onClick:v,variant:"outlined",permission:fe,projectId:c,environmentId:e==null?void 0:e.name,children:"Add variant"})]}),r(Vr,{onSubmit:Z,children:[t(b,{condition:x,show:E,elseShow:t(b,{condition:!!F,show:r(qr,{severity:"info",children:[t("strong",{children:"Change requests"})," are enabled",e?` for ${e.name}`:"",". Your changes need to be approved before they will be live. All the changes you do now will be added into a draft that you can submit for review."]})})}),t(Wr,{children:w.map(D=>t(Jr,{variant:D,variants:w,updateVariant:Y=>_(Y,D.id),removeVariant:()=>$(Y=>wt(Y.filter(ge=>ge.id!==D.id),1e3)),error:B.error},D.id))}),t(ie,{onClick:v,variant:"outlined",permission:fe,projectId:c,environmentId:e==null?void 0:e.name,children:"Add variant"}),t(Ur,{}),t(b,{condition:w.length>0,show:r(P,{children:[t(Hr,{children:t("p",{children:"Stickiness"})}),r(zt,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(yt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]}),t("div",{children:t(Yr,{value:T,label:"",editable:!0,onChange:D=>L(D.target.value)})})]}),elseShow:t(zt,{children:"This environment has no variants. Get started by adding a variant."})}),r(Nr,{severity:"error",hidden:!W,children:[t("strong",{children:"Error: "}),W]}),r(Gr,{children:[t(Te,{"data-testid":"DIALOGUE_CONFIRM_ID",type:"submit",variant:"contained",color:"primary",disabled:!oe,children:F?I:"Save variants"}),t(Kr,{onClick:Ie,children:"Cancel"})]})]})]})})},Qr=u("div")(({theme:e})=>({padding:e.spacing(3),borderRadius:e.shape.borderRadiusLarge,border:`1px solid ${e.palette.divider}`,"&:not(:last-child)":{marginBottom:e.spacing(3)}})),Xr=u("div")({display:"flex",alignItems:"center",justifyContent:"space-between","& > div":{display:"flex",alignItems:"center"}}),ei=u(pn,{shouldForwardProp:e=>e!=="deprecated"})(({theme:e,deprecated:n})=>({color:n?e.palette.neutral.border:e.palette.primary.main})),ti=u("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})),ni=u("p")(({theme:e})=>({fontSize:e.fontSizes.smallBody,color:e.palette.text.secondary,marginBottom:e.spacing(1.5)})),ai=u("div")(({theme:e})=>({margin:e.spacing(3,0)})),oi=u("div")(({theme:e})=>({display:"flex",alignItems:"center",gap:e.spacing(1.5),marginBottom:e.spacing(.5)})),si=({environment:e,searchValue:n,children:a})=>{var i;const s=e.variants??[],o=((i=s[0])==null?void 0:i.stickiness)||"default";return r(Qr,{children:[r(Xr,{children:[r("div",{children:[t(ei,{deprecated:!e.enabled}),t(ti,{deprecated:!e.enabled,children:e.name})]}),a]}),t(b,{condition:s.length>0,show:r(P,{children:[t(ai,{children:t(Ba,{variants:s,searchValue:n})}),t(b,{condition:s.length>1,show:r(P,{children:[r(oi,{children:[t("p",{children:"Stickiness:"}),t(Ee,{children:o})]}),r(ni,{children:["By overriding the stickiness you can control which parameter is used to ensure consistent traffic allocation across variants."," ",t(yt,{href:"https://docs.getunleash.io/reference/feature-toggle-variants",target:"_blank",rel:"noreferrer",children:"Read more"})]})]})})]})})]})},ri=u(le)(({theme:e})=>({"& span":{fontSize:e.fontSizes.smallBody}})),ii=({environment:e,permission:n,projectId:a,environmentId:s,onCopyVariantsFrom:o,otherEnvsWithVariants:i})=>{const[c,l]=f.useState(null),d=!!c,p=e.variants??[];return t(b,{condition:i.length>0&&p.length===0,show:r(P,{children:[t(ie,{onClick:h=>{l(h.currentTarget)},id:`copy-from-menu-${e.name}`,"aria-controls":d?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":d?"true":void 0,variant:"outlined",permission:n,projectId:a,environmentId:s,children:"Copy variants from"}),t(Fe,{anchorEl:c,open:d,onClose:()=>l(null),MenuListProps:{"aria-labelledby":`copy-from-menu-${e.name}`},children:i.map(h=>t(re,{onClick:()=>o(h,e),children:t(ri,{children:`Copy from ${h.name}`})},h.name))})]})})},ci=({permission:e,projectId:n,environment:a,checked:s,onClick:o,...i})=>{const c=it(e,n,a);return r(re,{disabled:!c,onClick:o,...i,children:[t(Oa,{checked:s}),a]})},li=u(Fe)(({theme:e})=>({"& > div > ul":{display:"flex",flexDirection:"column",justifyContent:"center","& > li":{padding:e.spacing(0,1)}}})),di=u("div")(({theme:e})=>({margin:e.spacing(1,2)})),ui=u(Te)(({theme:e})=>({marginTop:e.spacing(2)})),pi=({current:e,environments:n,permission:a,projectId:s,onSubmit:o})=>{var E;const[i,c]=f.useState(null),l=!!i,[d,p]=f.useState([]),h=y=>{p(w=>[...w,y])},m=y=>{p(w=>w.filter(({name:$})=>$!==y.name))},S=y=>{d.includes(y)?m(y):h(y)},C=()=>{p([]),c(null)},g=((E=n.find(y=>y.name===e))==null?void 0:E.variants)??[];return t(b,{condition:g.length>0&&n.length>1,show:r(P,{children:[t(Te,{onClick:y=>{c(y.currentTarget)},id:`push-to-menu-${e}`,"aria-controls":l?"basic-menu":void 0,"aria-haspopup":"true","aria-expanded":l?"true":void 0,variant:"outlined",children:"Copy to environment"}),r(li,{anchorEl:i,open:l,onClose:()=>c(null),MenuListProps:{"aria-labelledby":`push-to-menu-${e}`},children:[n.filter(y=>y.name!==e).map(y=>t(ci,{projectId:s,permission:a,environment:y.name,checked:d.includes(y),onClick:()=>S(y)},y.name)),r(di,{children:[t(De,{}),r(ui,{variant:"outlined",onClick:()=>{o(d),C()},disabled:d.length===0,children:["Push to selected (",d.length,")"]})]})]})]})})},hi=u("div")(({theme:e})=>({display:"flex",gap:e.spacing(1.5)})),gi=()=>{const{setToastData:e,setToastApiError:n}=K(),a=Qt(),s=Ne(a.breakpoints.down("md")),o=A("projectId"),i=A("featureId"),{feature:c,refetchFeature:l,loading:d}=j(o,i),{patchFeatureEnvironmentVariants:p,overrideVariantsInEnvironments:h}=He(),{refetch:m}=ae(o),{addChange:S}=ue(),{isChangeRequestConfigured:C}=X(o),[g,E]=f.useState(""),[y,w]=f.useState(),[$,M]=f.useState(!1),V=f.useMemo(()=>{var x;return((x=c==null?void 0:c.environments)==null?void 0:x.map(I=>({...I,crEnabled:C(I.name)})))||[]},[c.environments]),_=(x,I)=>ja(x,I),v=(x,I)=>{try{const F=La(I,1e3);return{patch:_(x,F)}}catch(F){return{patch:[],error:z(F)}}},R=x=>({feature:i,action:"patchVariant",payload:{variants:x}}),B=async(x,I)=>{if(x.crEnabled)await S(o,x.name,R(I)),m();else{const F=x.variants??[],{patch:T,error:k}=v(F,I);if(T.length===0)return;if(k){e({type:"error",title:k});return}await p(o,i,x.name,T)}l()},N=async(x,I)=>{try{const F=I.filter(({crEnabled:L})=>L),T=I.filter(({crEnabled:L})=>!L);F.length&&await Promise.all(F.map(L=>S(o,L.name,R(x)))),T.length&&await h(o,i,x,T.map(({name:L})=>L)),m(),l();const k=T.length?`Variants pushed to ${T.length===1?T[0].name:`${T.length} environments`}`:"",O=F.length?`Variants push added to ${F.length===1?`${F[0].name} draft`:`${F.length} drafts`}`:"",H=`${k}${k&&O?". ":""}${O}`;e({title:H,type:"success"})}catch(F){n(z(F))}},Z=x=>{w(x),M(!0)},U=async x=>{if(y)try{await B(y,x),M(!1),e({title:y.crEnabled?"Variant changes added to draft":"Variants updated successfully",type:"success"})}catch(I){n(z(I))}},oe=async(x,I)=>{try{const F=x.variants??[];await B(I,F),e({title:I.crEnabled?"Variants copy added to draft":"Variants copied successfully",type:"success"})}catch(F){n(z(F))}};return r(St,{isLoading:d,header:t(Ma,{title:"Variants",actions:t(b,{condition:!s,show:t(P,{children:t(Tt,{initialValue:g,onChange:E})})}),children:t(b,{condition:s,show:t(Tt,{initialValue:g,onChange:E})})}),children:[t(_a,{}),V.map(x=>{var F;const I=V.filter(({name:T,variants:k})=>T!==x.name&&(k==null?void 0:k.length));return t(si,{environment:x,searchValue:g,children:r(hi,{children:[t(pi,{current:x.name,environments:V,permission:fe,projectId:o,onSubmit:T=>N(x.variants??[],T)}),t(ii,{environment:x,permission:fe,projectId:o,environmentId:x.name,onCopyVariantsFrom:oe,otherEnvsWithVariants:I}),t(b,{condition:!!((F=x.variants)!=null&&F.length),show:t(te,{"data-testid":"EDIT_VARIANTS_BUTTON",onClick:()=>Z(x),permission:fe,projectId:o,environmentId:x.name,tooltipProps:{title:"Edit variants"},children:t(Se,{})}),elseShow:t(ie,{"data-testid":"ADD_VARIANT_BUTTON",onClick:()=>Z(x),variant:"outlined",permission:fe,projectId:o,environmentId:x.name,children:"Add variant"})})]})},x.name)}),t(Zr,{environment:y,open:$,setOpen:M,getApiPayload:v,getCrPayload:R,onConfirm:U})]})},fi=de("api/admin/client-metrics/features"),kn=(e,n)=>{const a=de(`api/admin/client-metrics/features/${e}/raw?hoursBack=${n}`),{data:s,error:o}=Ve(a,()=>mi(a)),i=f.useCallback(()=>{ut(fi).catch(console.warn)},[]);return{featureMetrics:s==null?void 0:s.data,loading:!o&&!s,refetchFeatureMetrics:i,error:o}},mi=e=>fetch(e).then(we("Features")).then(n=>n.json()).then(),yi=u("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ae=48,Si=({hoursBack:e,setHoursBack:n})=>{const a=s=>{n(bi(s))};return r("div",{children:[t(yi,{children:"Period"}),t(on,{name:"feature-metrics-period",id:"feature-metrics-period",options:vi,value:String(e),onChange:a,fullWidth:!0})]})},bi=e=>{switch(e){case"1":return 1;case"24":return 24;default:return Ae}},vi=[{key:"1",label:"Last hour"},{key:"24",label:"Last 24 hours"},{key:`${Ae}`,label:`Last ${Ae} hours`}],Ci=({value:e})=>{const{locationSettings:n}=rn(),a=e?e instanceof Date?xt(e,n.locale):xt(cn(e),n.locale):void 0;return t(hn,{lineClamp:1,children:a})},wi=({metrics:e,tableSectionId:n})=>{const a=Ne(za.breakpoints.down("md")),s=f.useMemo(()=>({sortBy:[{id:"timestamp"}]}),[]),{getTableProps:o,getTableBodyProps:i,headerGroups:c,rows:l,prepareRow:d,setHiddenColumns:p}=Ke.useTable({initialState:s,columns:Vt,data:e,autoResetHiddenColumns:!1,disableSortRemove:!0,defaultColumn:{Cell:hn}},Ke.useGlobalFilter,Ke.useSortBy);return Va([{condition:a,columns:["appName","environment"]}],p,Vt),e.length===0?null:r(qa,{...o(),rowHeight:"standard",id:n,children:[t(Na,{headerGroups:c}),t(Wa,{...i(),children:l.map(h=>(d(h),t(Ha,{hover:!0,...h.getRowProps(),children:h.cells.map(m=>t(Ua,{...m.getCellProps(),children:m.render("Cell")}))})))})]})},Vt=[{id:"Icon",width:"1%",disableSortBy:!0,Cell:()=>t(Ya,{icon:t(Ao,{color:"disabled"})})},{Header:"Time",accessor:"timestamp",Cell:e=>t(Ci,{value:e.row.original.timestamp})},{Header:"Application",accessor:"appName"},{Header:"Environment",accessor:"environment"},{id:"requested",Header:"Requested",accessor:e=>e.yes+e.no},{Header:"Exposed",accessor:"yes"}],Ti=({metrics:e,...n})=>{const a=f.useMemo(()=>e.reduce((o,i)=>o+i.yes,0),[e]),s=f.useMemo(()=>e.reduce((o,i)=>o+i.no,0),[e]);return t(Tn,{...n,totalYes:a,totalNo:s})},xi=({metrics:e,hoursBack:n})=>{const a=Et(),s=Et();return e.length===0?r(J,{mt:6,children:[t(q,{variant:"body1",paragraph:!0,children:"We have yet to receive any metrics for this feature toggle in the selected time period."}),t(q,{variant:"body1",paragraph:!0,children:"Please note that, since the SDKs send metrics on an interval, it might take some time before metrics appear."})]}):r(f.Suspense,{fallback:null,children:[t(J,{borderTop:1,pt:2,mt:3,borderColor:"divider",children:t(Ei,{metrics:e,hoursBack:n,statsSectionId:a})}),t(J,{mt:4,children:t(Ti,{metrics:e,hoursBack:n,statsSectionId:a,tableSectionId:s})}),t(J,{mt:4,children:t(wi,{metrics:e,tableSectionId:s})})]})},Ei=Ga.lazy(()=>Ka(()=>import("./FeatureMetricsChart-99739e53.js"),[])),dt=e=>{const{search:n}=window.location,a=pe(),s=f.useMemo(()=>new URLSearchParams(n),[n]),o=f.useCallback(i=>{const c=new URLSearchParams(n);c.set(e,i),a({search:c.toString()},{replace:!0})},[e,n,a]);return[s.get(e)||void 0,o]},Di=e=>{const[n,a]=dt(e),s=f.useCallback(o=>a(String(o)),[a]);return[Number.isFinite(Number(n))?Number(n):void 0,s]},Ai=u("h2")(({theme:e})=>({margin:0,marginBottom:e.spacing(1.5),fontSize:e.fontSizes.smallBody,fontWeight:e.fontWeight.thin,color:e.palette.text.secondary})),Ri=u("ul")(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),listStyleType:"none",padding:0,minHeight:"100%"})),ki=u("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}})),qt=({title:e,values:n,value:a,setValue:s})=>{const o=c=>()=>{n.has(c)&&s(c)},i=f.useMemo(()=>Array.from(n).sort((c,l)=>c.localeCompare(l)),[n]);return r("div",{children:[t(Ai,{children:e}),t(Ri,{children:i.map(c=>t(ki,{children:t(ln,{label:c,onClick:o(c),"aria-pressed":c===a,sx:Ja})},c))})]})},Fi=()=>{const e=A("projectId"),n=A("featureId"),a=$i(e,n),s=Ii(n);dn("Metrics");const[o=Ae,i]=Di("hoursBack"),{featureMetrics:c}=kn(n,o),[l,d]=f.useState(c);f.useEffect(()=>{c&&d(c)},[c]);const p=Array.from(a)[0],h=Array.from(s)[0],[m=p,S]=dt("environment"),[C=h,g]=dt("application"),E=f.useMemo(()=>l==null?void 0:l.filter(y=>y.environment===m).filter(y=>y.appName===C),[l,m,C]);return E?r(St,{children:[r(se,{container:!0,component:"header",spacing:2,children:[t(se,{item:!0,xs:12,md:5,children:t(b,{condition:a.size>0,show:t(qt,{title:"Environments",values:a,value:m,setValue:S})})}),t(se,{item:!0,xs:12,md:5,children:t(b,{condition:s.size>0,show:t(qt,{title:"Applications",values:s,value:C,setValue:g})})}),t(se,{item:!0,xs:12,md:2,children:t(Si,{hoursBack:o,setHoursBack:i})})]}),t(xi,{metrics:E,hoursBack:o})]}):null},$i=(e,n)=>{const{feature:a}=j(e,n),s=a.environments.map(o=>o.name);return new Set(s)},Ii=e=>{const{featureMetrics:n=[]}=kn(e,Ae),a=n.map(s=>s.appName);return new Set(a)},Pi=(e,n)=>{const a=new Set(e),s=new Set(n);return a.size!==s.size?!1:[...a].every(o=>s.has(o))},Nt=u("div")(({theme:e})=>({display:"grid",gap:e.spacing(2)})),Wt=u(he)(({theme:e})=>({marginBottom:e.spacing(1)})),Bi=u(gt)({padding:0}),Oi=({projectId:e,open:n,onClose:a,onClick:s,feature:o,changeRequests:i})=>{const c=mt("dependentFeatures"),l=A("projectId"),{project:d}=gn(e),{isChangeRequestConfiguredInAnyEnv:p}=X(e),h=p(),m=f.useMemo(()=>Pi(o.environments.map(g=>g.name),d.environments.map(g=>g.environment)),[o,d]),S=i?i.length>0:!1,C=c&&(o.dependencies.length>0||o.children.length>0);return t(b,{condition:m&&!C&&!S&&!h,show:t(ne,{open:n,onClose:a,onClick:s,title:"Confirm change project",primaryButtonText:"Change project",secondaryButtonText:"Cancel",children:r(Nt,{children:[t(Wt,{severity:"success",children:"This feature toggle is compatible with the new project."}),t("p",{children:"Are you sure you want to change the project for this toggle?"})]})}),elseShow:t(ne,{open:n,onClick:a,title:"Confirm change project",primaryButtonText:"Close",children:r(Nt,{children:[t(Wt,{severity:"warning",children:"Cannot proceed with the move"}),t(b,{condition:C,show:r("p",{children:[t("span",{children:"The feature toggle must not have any dependencies."})," ",t("br",{}),t("span",{children:"Please remove feature dependencies first."})]})}),t(b,{condition:!m,show:t("p",{children:"In order to move a feature toggle between two projects, both projects must have the exact same environments enabled."})}),t(b,{condition:S,show:r(P,{children:[t("p",{children:"The feature toggle must not have any pending change requests. This feature toggle is currently referenced in the following change requests:"}),t(Bi,{children:i==null?void 0:i.map(g=>t(me,{children:r(G,{to:`/projects/${l}/change-requests/${g.id}`,children:["View change request"," ",g.id]})},g.id))})]})}),t(b,{condition:h,show:r("p",{children:["You're not allowed to move the feature to project"," ",t(G,{to:`/projects/${e}/settings/change-requests`,children:e}),". This project has change requests enabled."]})})]})})})},Mi=e=>fetch(e).then(we("ChangeRequest")).then(n=>n.json()),_i=(e,n)=>{const{data:a,error:s,mutate:o}=Za([],de(`api/admin/projects/${e}/change-requests/pending/${n}`),Mi);return{changeRequests:a,loading:!s&&!a,refetch:o,error:s}},Li=()=>{const{hasAccess:e}=f.useContext(pt),n=A("projectId"),a=A("featureId"),{feature:s,refetchFeature:o}=j(n,a),[i,c]=f.useState(!1),{changeFeatureProject:l}=He(),{setToastData:d,setToastApiError:p}=K(),[h,m]=f.useState(n),{projects:S}=Qa(),C=pe(),{changeRequests:g}=_i(n,a),E=async()=>{try{h&&(await l(n,a,h),o(),d({title:"Project changed",type:"success"}),c(!1),C(`/projects/${h}/features/${a}/settings`,{replace:!0}))}catch(w){p(z(w))}},y=f.useMemo(()=>S.map(w=>w.id).filter(w=>e(Dt,w)),[S,e]);return y.length===0?null:r(P,{children:[t(Xa,{value:h,onChange:m,label:"Project",filter:w=>y.includes(w),enabled:!0}),t(ie,{permission:Dt,onClick:()=>c(!0),disabled:h===n,projectId:n,children:"Save"}),t(Oi,{changeRequests:g,projectId:h,open:i,feature:s,onClose:()=>c(!1),onClick:E})]})},ji=u("div")({display:"flex",alignItems:"center"}),zi=u(q)(({theme:e})=>({fontSize:e.fontSizes.mainHeader})),Vi=({projectId:e,featureId:n})=>{var i;const{feature:a}=j(e,n),s=pe();return r(P,{children:[r(ji,{children:[t(zi,{children:"Feature information"}),t(te,{permission:ye,projectId:e,"data-loading":!0,onClick:()=>{s(`/projects/${e}/features/${n}/edit`)},tooltipProps:{title:"Edit"},children:t(Se,{})})]}),r(q,{children:["Name: ",t("strong",{children:a.name})]}),r(q,{children:["Description:"," ",t("strong",{children:(i=a.description)!=null&&i.length?a.description:"no description"})]}),r(q,{children:["Type: ",t("strong",{children:a.type})]}),r(q,{children:["Impression Data:"," ",t("strong",{children:a.impressionData?"enabled":"disabled"})]})]})},Me="metadata",rt="project",qi=u("div")(({theme:e})=>({width:"20%",borderRight:`1px solid ${e.palette.divider}`,padding:e.spacing(2,0),[e.breakpoints.down("md")]:{width:"35%"}})),Ni=u("div")(({theme:e})=>({padding:e.spacing(4),display:"flex",flexDirection:"column",width:400,"& > *":{margin:e.spacing(1,0)}})),Wi=()=>{const e=A("projectId"),n=A("featureId"),[a,s]=f.useState(Me),{uiConfig:o}=We();return t(St,{header:"Settings",sx:{padding:0},children:r(J,{sx:{display:"flex"},children:[t(qi,{children:r(gt,{children:[t(me,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(Me),selected:a===Me,children:"Metadata"},0),t(me,{sx:{padding:"0.75rem 2rem"},button:!0,onClick:()=>s(rt),selected:a===rt,hidden:!o.flags.P,children:"Project"},1)]})}),r(Ni,{children:[t(b,{condition:a===Me,show:t(Vi,{projectId:e,featureId:n})}),t(b,{condition:a===rt&&o.flags.P,show:t(Li,{})})]})]})})},Hi=({stale:e,showActive:n=!0})=>!e&&!n?null:t("div",{"data-loading":!0,style:{marginLeft:"8px"},children:t(Ee,{color:e?"error":"success",title:e?"Feature toggle is deprecated.":"Feature toggle is active.",children:e?"Stale":"Active"})}),Ht=u("strong")({wordBreak:"break-all"}),Ui=()=>{const e=A("projectId"),n=A("featureId"),{archivedFeatures:a}=eo(),s=to(e,{name:n});return a?a.some(i=>i.name===n)?r("p",{children:["The feature ",t(Ht,{children:n})," has been archived. You can find it on the"," ",t(G,{to:`/projects/${e}/archive`,children:"project archive page"}),"."]}):r("p",{children:["The feature ",t(Ht,{children:n})," does not exist. Would you like to"," ",t(G,{to:s,children:"create it"}),"?"]}):null},Yi=u(G)(({theme:e})=>({textDecoration:"none",color:e.palette.primary.main,fontWeight:e.fontWeight.bold})),Gi=({isOpen:e,onClose:n,features:a,project:s})=>r(ne,{title:"You can't archive a feature that other features depend on",open:e,primaryButtonText:"OK",onClick:n,children:[t("p",{children:"The following features depend on your feature:"}),t("ul",{children:a.map(o=>t("li",{children:t(Yi,{to:`/projects/${s}/features/${o}`,target:"_blank",rel:"noopener noreferrer",children:o})},o))})]}),Ki=e=>f.createElement("svg",{fill:"none",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},f.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"}),f.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"})),Ji=e=>f.createElement("svg",{fill:"none",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",...e},f.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"})),Zi=u("div")(({theme:e})=>({backgroundColor:e.palette.background.paper,borderRadius:e.shape.borderRadiusLarge,marginBottom:e.spacing(2)})),Qi=u("div")(({theme:e})=>({padding:e.spacing(2,4,2,2),display:"flex",justifyContent:"space-between",alignItems:"center",[e.breakpoints.down(500)]:{flexDirection:"column"}})),Ut=u("div")({display:"flex",alignItems:"center"}),Yt=u("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"}));u(Ki)(({theme:e})=>({width:e.fontSizes.smallBody,height:e.fontSizes.smallBody}));u(Ji)(({theme:e})=>({width:e.fontSizes.smallBody,height:e.fontSizes.smallBody}));const Xi=u("h1")(({theme:e})=>({fontSize:e.fontSizes.mainHeader,fontWeight:"normal",display:"flex",alignItems:"center",wordBreak:"break-all"})),ec=u("div")({flexShrink:0,display:"flex"}),tc=u("div")(({theme:e})=>({width:"100%",backgroundColor:e.palette.divider,height:"1px"})),nc=u("div")(({theme:e})=>({padding:e.spacing(0,4)})),ac=u(no)(({theme:e})=>({textTransform:"none",width:"auto",fontSize:e.fontSizes.bodySize,padding:"0 !important",[e.breakpoints.up("md")]:{minWidth:160}})),oc=u(G)(({theme:e})=>({maxWidth:"100%",textDecoration:"none","&:hover, &:focus":{textDecoration:"underline"}})),cc=()=>{var N,Z;const e=A("projectId"),n=A("featureId"),{refetch:a}=gn(e),{favorite:s,unfavorite:o}=ao(),{refetchFeature:i}=j(e,n),c=mt("dependentFeatures"),[l,d]=f.useState(!1),[p,h]=f.useState(!1),[m,S]=f.useState(!1),C=Ne("(max-width:500px)"),{feature:g,loading:E,error:y,status:w}=j(e,n),$=pe(),{pathname:M}=oo(),V=so(E),_=`/projects/${e}/features/${n}`,v=[{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"}],R=v.find(U=>U.path===M)??v[0],B=async()=>{g!=null&&g.favorite?await o(e,g.name):await s(e,g.name),i()};return w===404?t(Ui,{}):y!==void 0?t("div",{ref:V}):r("div",{ref:V,children:[r(Zi,{children:[r(Qi,{children:[r(Ut,{children:[t(ro,{onClick:B,isFavorite:g==null?void 0:g.favorite}),r("div",{children:[r(Ut,{children:[r(Xi,{"data-loading":!0,children:[g.name," "]}),t(b,{condition:!C,show:t(Hi,{stale:g==null?void 0:g.stale})})]}),t(b,{condition:c&&g.dependencies.length>0,show:r(Yt,{children:[t("b",{children:"Has parent: "}),t(oc,{to:`/projects/${g.project}/features/${(N=g==null?void 0:g.dependencies[0])==null?void 0:N.feature}`,children:(Z=g==null?void 0:g.dependencies[0])==null?void 0:Z.feature})]})}),t(b,{condition:c&&g.children.length>0,show:r(Yt,{children:[t("b",{children:"Has children:"}),t(Dn,{childFeatures:g.children,project:g.project})]})})]})]}),r(ec,{children:[t(te,{permission:io,projectId:e,"data-loading":!0,component:G,to:`/projects/${e}/features/${n}/copy`,tooltipProps:{title:"Copy feature toggle"},children:t(co,{})}),t(te,{permission:lo,projectId:e,tooltipProps:{title:"Archive feature toggle"},"data-loading":!0,onClick:()=>h(!0),children:t(Do,{})}),t(te,{onClick:()=>S(!0),permission:ye,projectId:e,tooltipProps:{title:"Toggle stale state"},"data-loading":!0,children:t(wo,{})}),t(te,{onClick:()=>d(!0),permission:ye,projectId:e,tooltipProps:{title:"Add tag"},"data-loading":!0,children:t(uo,{})})]})]}),t(tc,{}),t(nc,{children:t(po,{value:R.path,indicatorColor:"primary",textColor:"primary",children:v.map(U=>t(ac,{label:U.title,value:U.path,onClick:()=>$(U.path),"data-testid":`TAB-${U.title}`},U.title))})})]}),r(un,{children:[t(ce,{path:"metrics",element:t(Fi,{})}),t(ce,{path:"logs",element:t(ko,{})}),t(ce,{path:"variants",element:t(gi,{})}),t(ce,{path:"settings",element:t(Wi,{})}),t(ce,{path:"*",element:t(_r,{})})]}),t(b,{condition:g.children.length>0,show:t(Gi,{features:g.children,project:e,isOpen:p,onClose:()=>h(!1)}),elseShow:t(To,{isOpen:p,onConfirm:()=>{a(),$(`/projects/${e}`)},onClose:()=>h(!1),projectId:e,featureIds:[n]})}),t(xo,{isStale:g.stale,isOpen:m,onClose:()=>{S(!1),i()},featureId:n,projectId:e}),t(Rn,{open:l,setOpen:d})]})};export{cc as default};